protected void paintSyntaxLine( Graphics gfx, TokenMarker tokenMarker, int line, Font defaultFont, Color defaultColor, int x, int y) { textArea.getLineText(currentLineIndex, currentLine); currentLineTokens = tokenMarker.markTokens(currentLine, currentLineIndex); paintHighlight(gfx, line, y); gfx.setFont(defaultFont); gfx.setColor(defaultColor); y += fm.getHeight(); x = SyntaxUtilities.paintSyntaxLine(currentLine, currentLineTokens, styles, this, gfx, x, y); /* * Draw characters via input method. */ if (compositionTextPainter != null && compositionTextPainter.hasComposedTextLayout()) { compositionTextPainter.draw(gfx, lineHighlightColor); } if (eolMarkers) { gfx.setColor(eolMarkerColor); gfx.drawString(".", x, y); } }
protected void paintLineHighlight(Graphics gfx, int line, int y) { int height = fm.getHeight(); y += fm.getLeading() + fm.getMaxDescent(); int selectionStart = textArea.getSelectionStart(); int selectionEnd = textArea.getSelectionStop(); if (selectionStart == selectionEnd) { if (lineHighlight) { gfx.setColor(lineHighlightColor); gfx.fillRect(0, y, getWidth(), height); } } else { gfx.setColor(selectionColor); int selectionStartLine = textArea.getSelectionStartLine(); int selectionEndLine = textArea.getSelectionStopLine(); int lineStart = textArea.getLineStartOffset(line); int x1, x2; if (textArea.isSelectionRectangular()) { int lineLen = textArea.getLineLength(line); x1 = textArea._offsetToX( line, Math.min( lineLen, selectionStart - textArea.getLineStartOffset(selectionStartLine))); x2 = textArea._offsetToX( line, Math.min(lineLen, selectionEnd - textArea.getLineStartOffset(selectionEndLine))); if (x1 == x2) x2++; } else if (selectionStartLine == selectionEndLine) { x1 = textArea._offsetToX(line, selectionStart - lineStart); x2 = textArea._offsetToX(line, selectionEnd - lineStart); } else if (line == selectionStartLine) { x1 = textArea._offsetToX(line, selectionStart - lineStart); x2 = getWidth(); } else if (line == selectionEndLine) { // x1 = 0; // hack from stendahl to avoid doing weird side selection thing x1 = textArea._offsetToX(line, 0); // attempt at getting the gutter too, but doesn't seem to work // x1 = textArea._offsetToX(line, -textArea.getHorizontalOffset()); x2 = textArea._offsetToX(line, selectionEnd - lineStart); } else { // x1 = 0; // hack from stendahl to avoid doing weird side selection thing x1 = textArea._offsetToX(line, 0); // attempt at getting the gutter too, but doesn't seem to work // x1 = textArea._offsetToX(line, -textArea.getHorizontalOffset()); x2 = getWidth(); } // "inlined" min/max() gfx.fillRect(x1 > x2 ? x2 : x1, y, x1 > x2 ? (x1 - x2) : (x2 - x1), height); } }
@Override protected void paintContentBorderBottomEdge( Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { if (tabPane.getTabCount() < 1) return; g.setColor(shadow); g.drawLine(x + 1, y + h - 3, x + w - 2, y + h - 3); g.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2); g.setColor(shadow.brighter()); g.drawLine(x + 2, y + h - 1, x + w - 1, y + h - 1); }
public void paint(Graphics g) { super.paint(g); if (!isEditing) return; Dimension psize = getPreferredSize(); if (isFocused) g.setColor(Color.yellow); else g.setColor(Color.green); g.drawLine(0, 0, psize.width, 0); g.drawLine(0, 0, 0, psize.height); g.drawLine(0, psize.height - 1, psize.width - 1, psize.height - 1); g.drawLine(psize.width - 1, 0, psize.width - 1, psize.height - 1); }
protected void paintLineHighlight(Graphics gfx, int line, int y) { int height = fm.getHeight(); y += fm.getLeading() + fm.getMaxDescent(); int selectionStart = textArea.getSelectionStart(); int selectionEnd = textArea.getSelectionEnd(); if (selectionStart == selectionEnd) { if (lineHighlight) { gfx.setColor(lineHighlightColor); gfx.fillRect(0, y, getWidth(), height); } } else { gfx.setColor(selectionColor); int selectionStartLine = textArea.getSelectionStartLine(); int selectionEndLine = textArea.getSelectionEndLine(); int lineStart = textArea.getLineStartOffset(line); int x1, x2; if (textArea.isSelectionRectangular()) { int lineLen = textArea.getLineLength(line); x1 = textArea._offsetToX( line, Math.min( lineLen, selectionStart - textArea.getLineStartOffset(selectionStartLine))); x2 = textArea._offsetToX( line, Math.min(lineLen, selectionEnd - textArea.getLineStartOffset(selectionEndLine))); if (x1 == x2) x2++; } else if (selectionStartLine == selectionEndLine) { x1 = textArea._offsetToX(line, selectionStart - lineStart); x2 = textArea._offsetToX(line, selectionEnd - lineStart); } else if (line == selectionStartLine) { x1 = textArea._offsetToX(line, selectionStart - lineStart); x2 = getWidth(); } else if (line == selectionEndLine) { x1 = 0; x2 = textArea._offsetToX(line, selectionEnd - lineStart); } else { x1 = 0; x2 = getWidth(); } // "inlined" min/max() gfx.fillRect(x1 > x2 ? x2 : x1, y, x1 > x2 ? (x1 - x2) : (x2 - x1), height); } }
protected void paintBackgroundSafely(final Graphics g) { final JTextComponent c = getComponent(); final int width = c.getWidth(); final int height = c.getHeight(); // a delegate takes precedence if (delegate != null) { delegate.paint(c, g, 0, 0, width, height); return; } final boolean isOpaque = c.isOpaque(); if (!(c.getBorder() instanceof AquaTextFieldBorder)) { // developer must have set a custom border if (!isOpaque && AquaUtils.hasOpaqueBeenExplicitlySet(c)) return; // must fill whole region with background color if opaque g.setColor(c.getBackground()); g.fillRect(0, 0, width, height); return; } // using our own border g.setColor(c.getBackground()); if (isOpaque) { g.fillRect(0, 0, width, height); return; } final Insets margin = c.getMargin(); Insets insets = c.getInsets(); if (insets == null) insets = new Insets(0, 0, 0, 0); if (margin != null) { insets.top -= margin.top; insets.left -= margin.left; insets.bottom -= margin.bottom; insets.right -= margin.right; } // the common case final int shrinkage = AquaTextFieldBorder.getShrinkageFor(c, height); g.fillRect( insets.left - 2, insets.top - shrinkage - 1, width - insets.right - insets.left + 4, height - insets.bottom - insets.top + shrinkage * 2 + 2); }
protected void paintCaret(Graphics gfx, int line, int y) { // System.out.println("painting caret " + line + " " + y); if (textArea.isCaretVisible()) { // System.out.println("caret is visible"); int offset = textArea.getCaretPosition() - textArea.getLineStartOffset(line); int caretX = textArea._offsetToX(line, offset); int caretWidth = ((blockCaret || textArea.isOverwriteEnabled()) ? fm.charWidth('w') : 1); y += fm.getLeading() + fm.getMaxDescent(); int height = fm.getHeight(); // System.out.println("caretX, width = " + caretX + " " + caretWidth); gfx.setColor(caretColor); if (textArea.isOverwriteEnabled()) { gfx.fillRect(caretX, y + height - 1, caretWidth, 1); } else { // some machines don't like the drawRect for the single // pixel caret.. this caused a lot of hell because on that // minority of machines, the caret wouldn't show up past // the first column. the fix is to use drawLine() in // those cases, as a workaround. if (caretWidth == 1) { gfx.drawLine(caretX, y, caretX, y + height - 1); } else { gfx.drawRect(caretX, y, caretWidth - 1, height - 1); } // gfx.drawRect(caretX, y, caretWidth, height - 1); } } }
/** * Paints the word-wrapped text. * * @param g The graphics context in which to paint. * @param a The shape (usually a rectangle) in which to paint. */ public void paint(Graphics g, Shape a) { Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds(); tabBase = alloc.x; Graphics2D g2d = (Graphics2D) g; host = (RSyntaxTextArea) getContainer(); int ascent = host.getMaxAscent(); int fontHeight = host.getLineHeight(); FoldManager fm = host.getFoldManager(); TokenPainter painter = host.getTokenPainter(); Element root = getElement(); // Whether token styles should always be painted, even in selections int selStart = host.getSelectionStart(); int selEnd = host.getSelectionEnd(); boolean useSelectedTextColor = host.getUseSelectedTextColor(); int n = getViewCount(); // Number of lines. int x = alloc.x + getLeftInset(); tempRect.y = alloc.y + getTopInset(); Rectangle clip = g.getClipBounds(); for (int i = 0; i < n; i++) { tempRect.x = x + getOffset(X_AXIS, i); // tempRect.y = y + getOffset(Y_AXIS, i); tempRect.width = getSpan(X_AXIS, i); tempRect.height = getSpan(Y_AXIS, i); // System.err.println("For line " + i + ": tempRect==" + tempRect); if (tempRect.intersects(clip)) { Element lineElement = root.getElement(i); int startOffset = lineElement.getStartOffset(); int endOffset = lineElement.getEndOffset() - 1; // Why always "-1"? View view = getView(i); if (!useSelectedTextColor || selStart == selEnd || (startOffset >= selEnd || endOffset < selStart)) { drawView(painter, g2d, alloc, view, fontHeight, tempRect.y + ascent); } else { // System.out.println("Drawing line with selection: " + i); drawViewWithSelection( painter, g2d, alloc, view, fontHeight, tempRect.y + ascent, selStart, selEnd); } } tempRect.y += tempRect.height; Fold possibleFold = fm.getFoldForLine(i); if (possibleFold != null && possibleFold.isCollapsed()) { i += possibleFold.getCollapsedLineCount(); // Visible indicator of collapsed lines Color c = RSyntaxUtilities.getFoldedLineBottomColor(host); if (c != null) { g.setColor(c); g.drawLine(x, tempRect.y - 1, alloc.width, tempRect.y - 1); } } } }
protected void paintPlainLine( Graphics gfx, int line, Font defaultFont, Color defaultColor, int x, int y) { paintHighlight(gfx, line, y); textArea.getLineText(line, currentLine); gfx.setFont(defaultFont); gfx.setColor(defaultColor); y += fm.getHeight(); x = Utilities.drawTabbedText(currentLine, x, y, gfx, this, 0); if (eolMarkers) { gfx.setColor(eolMarkerColor); gfx.drawString(".", x, y); } }
@Override protected void paintContentBorderTopEdge( Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { if (tabPane.getTabCount() < 1) return; g.setColor(shadow); g.drawLine(x, y, x + w - 2, y); }
protected void paintRoundedBottomTabBorder( int tabIndex, Graphics g, int x1, int y1, int x2, int y2, boolean isSelected) { Graphics2D g2D = (Graphics2D) g; Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int d = 2 * GAP; if (isSelected) { g.setColor(AbstractLookAndFeel.getTheme().getFrameColor()); } else { g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getTheme().getFrameColor(), 40)); } g.drawLine(x1 + GAP, y2, x2 - GAP, y2); g.drawArc(x1, y2 - d, d, d, 180, 90); g.drawArc(x2 - d, y2 - d, d, d, -90, 90); g.drawLine(x1, y1, x1, y2 - GAP - 1); g.drawLine(x2, y1, x2, y2 - GAP - 1); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); }
protected void paintPlainLine( Graphics gfx, int line, Font defaultFont, Color defaultColor, int x, int y) { paintHighlight(gfx, line, y); textArea.getLineText(line, currentLine); gfx.setFont(defaultFont); gfx.setColor(defaultColor); y += fm.getHeight(); x = Utilities.drawTabbedText(currentLine, x, y, gfx, this, 0); // Draw characters via input method. if (compositionTextPainter != null && compositionTextPainter.hasComposedTextLayout()) { compositionTextPainter.draw(gfx, lineHighlightColor); } if (eolMarkers) { gfx.setColor(eolMarkerColor); gfx.drawString(".", x, y); } }
protected void paintBracketHighlight(Graphics gfx, int line, int y) { int position = textArea.getBracketPosition(); if (position == -1) return; y += fm.getLeading() + fm.getMaxDescent(); int x = textArea._offsetToX(line, position); gfx.setColor(bracketHighlightColor); // Hack!!! Since there is no fast way to get the character // from the bracket matching routine, we use ( since all // brackets probably have the same width anyway gfx.drawRect(x, y, fm.charWidth('(') - 1, fm.getHeight() - 1); }
/** * Draw the line numbers * * @param g */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); ((Graphics2D) g) .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Determine the width of the space available to draw the line number FontMetrics fontMetrics = component.getFontMetrics(component.getFont()); Insets insets = getInsets(); int availableWidth = getSize().width - insets.left - insets.right; // Determine the rows to draw within the clipped bounds. Rectangle clip = g.getClipBounds(); int rowStartOffset = component.viewToModel(new Point(0, clip.y)); int endOffset = component.viewToModel(new Point(0, clip.y + clip.height)); while (rowStartOffset <= endOffset) { try { if (isCurrentLine(rowStartOffset)) g.setColor(getCurrentLineForeground()); else g.setColor(getForeground()); // Get the line number as a string and then determine the // "X" and "Y" offsets for drawing the string. String lineNumber = getTextLineNumber(rowStartOffset); int stringWidth = fontMetrics.stringWidth(lineNumber); int x = getOffsetX(availableWidth, stringWidth) + insets.left; int y = getOffsetY(rowStartOffset, fontMetrics); g.drawString(lineNumber, x, y); // Move to the next row rowStartOffset = Utilities.getRowEnd(component, rowStartOffset) + 1; } catch (Exception e) { break; } } }
protected void paintSyntaxLine( Graphics gfx, TokenMarker tokenMarker, int line, Font defaultFont, Color defaultColor, int x, int y) { textArea.getLineText(currentLineIndex, currentLine); currentLineTokens = tokenMarker.markTokens(currentLine, currentLineIndex); paintHighlight(gfx, line, y); gfx.setFont(defaultFont); gfx.setColor(defaultColor); y += fm.getHeight(); x = SyntaxUtilities.paintSyntaxLine(currentLine, currentLineTokens, styles, this, gfx, x, y); if (eolMarkers) { gfx.setColor(eolMarkerColor); gfx.drawString(".", x, y); } }
public void paint(Graphics g) { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); for (int i = 0; i < numImages; i++) { if (x[i] > 3 * i) { nudge(i); squish(g, icon[i], xh[i], yh[i], scale[i]); } else { x[i] += .05; y[i] += .05; } } }
/** @{inheritDoc} */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); g = g.create(); try { AntialiasingManager.activateAntialiasing(g); g.setColor(Color.DARK_GRAY); g.fillRoundRect(0, 0, this.getWidth(), this.getHeight(), 10, 10); } finally { g.dispose(); } }
protected void paintCaret(Graphics gfx, int line, int y) { if (textArea.isCaretVisible()) { int offset = textArea.getCaretPosition() - textArea.getLineStartOffset(line); int caretX = textArea._offsetToX(line, offset); int caretWidth = ((blockCaret || textArea.isOverwriteEnabled()) ? fm.charWidth('w') : 1); y += fm.getLeading() + fm.getMaxDescent(); int height = fm.getHeight(); gfx.setColor(caretColor); if (textArea.isOverwriteEnabled()) { gfx.fillRect(caretX, y + height - 1, caretWidth, 1); } else { gfx.drawRect(caretX, y, caretWidth - 1, height - 1); } } }
public synchronized void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(Color.white); g.fillRect(0, 0, c.getWidth(), c.getHeight()); if (getImageObserver() == null) { g.drawImage( getImage(), c.getWidth() / 2 - getIconWidth() / 2, c.getHeight() / 2 - getIconHeight() / 2, c); } else { g.drawImage( getImage(), c.getWidth() / 2 - getIconWidth() / 2, c.getHeight() / 2 - getIconHeight() / 2, getImageObserver()); } }
/** * Repaints the text. * * @param gfx The graphics context */ public void paint(Graphics gfx) { Graphics2D g2 = (Graphics2D) gfx; g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, antialias ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); tabSize = fm.charWidth(' ') * ((Integer) textArea.getDocument().getProperty(PlainDocument.tabSizeAttribute)) .intValue(); Rectangle clipRect = gfx.getClipBounds(); gfx.setColor(getBackground()); gfx.fillRect(clipRect.x, clipRect.y, clipRect.width, clipRect.height); // We don't use yToLine() here because that method doesn't // return lines past the end of the document int height = fm.getHeight(); int firstLine = textArea.getFirstLine(); int firstInvalid = firstLine + clipRect.y / height; // Because the clipRect's height is usually an even multiple // of the font height, we subtract 1 from it, otherwise one // too many lines will always be painted. int lastInvalid = firstLine + (clipRect.y + clipRect.height - 1) / height; try { TokenMarker tokenMarker = textArea.getDocument().getTokenMarker(); int x = textArea.getHorizontalOffset(); for (int line = firstInvalid; line <= lastInvalid; line++) { paintLine(gfx, tokenMarker, line, x); } if (tokenMarker != null && tokenMarker.isNextLineRequested()) { int h = clipRect.y + clipRect.height; repaint(0, h, getWidth(), getHeight() - h); } } catch (Exception e) { System.err.println( "Error repainting line" + " range {" + firstInvalid + "," + lastInvalid + "}:"); e.printStackTrace(); } }
/** * Paints the word-wrapped text. * * @param g The graphics context in which to paint. * @param a The shape (usually a rectangle) in which to paint. */ public void paint(Graphics g, Shape a) { Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds(); tabBase = alloc.x; Graphics2D g2d = (Graphics2D) g; host = (RSyntaxTextArea) getContainer(); int ascent = host.getMaxAscent(); int fontHeight = host.getLineHeight(); FoldManager fm = host.getFoldManager(); int n = getViewCount(); // Number of lines. int x = alloc.x + getLeftInset(); tempRect.y = alloc.y + getTopInset(); Rectangle clip = g.getClipBounds(); for (int i = 0; i < n; i++) { tempRect.x = x + getOffset(X_AXIS, i); // tempRect.y = y + getOffset(Y_AXIS, i); tempRect.width = getSpan(X_AXIS, i); tempRect.height = getSpan(Y_AXIS, i); // System.err.println("For line " + i + ": tempRect==" + tempRect); if (tempRect.intersects(clip)) { View view = getView(i); drawView(g2d, alloc, view, fontHeight, tempRect.y + ascent); } tempRect.y += tempRect.height; Fold possibleFold = fm.getFoldForLine(i); if (possibleFold != null && possibleFold.isCollapsed()) { i += possibleFold.getCollapsedLineCount(); // Visible indicator of collapsed lines Color c = RSyntaxUtilities.getFoldedLineBottomColor(host); if (c != null) { g.setColor(c); g.drawLine(x, tempRect.y - 1, alloc.width, tempRect.y - 1); } } } }
/** * Paints the image. * * @param g the rendering surface to use * @param a the allocated region to render into * @see View#paint */ public void paint(Graphics g, Shape a) { Color oldColor = g.getColor(); fBounds = a.getBounds(); int border = getBorder(); int x = fBounds.x + border + getSpace(X_AXIS); int y = fBounds.y + border + getSpace(Y_AXIS); int width = fWidth; int height = fHeight; int sel = getSelectionState(); // Make sure my Component is in the right place: /* if( fComponent == null ) { fComponent = new Component() { }; fComponent.addMouseListener(this); fComponent.addMouseMotionListener(this); fComponent.setCursor(Cursor.getDefaultCursor()); // use arrow cursor fContainer.add(fComponent); } fComponent.setBounds(x,y,width,height); */ // If no pixels yet, draw gray outline and icon: if (!hasPixels(this)) { g.setColor(Color.lightGray); g.drawRect(x, y, width - 1, height - 1); g.setColor(oldColor); loadIcons(); Icon icon = fImage == null ? sMissingImageIcon : sPendingImageIcon; if (icon != null) icon.paintIcon(getContainer(), g, x, y); } // Draw image: if (fImage != null) { g.drawImage(fImage, x, y, width, height, this); // Use the following instead of g.drawImage when // BufferedImageGraphics2D.setXORMode is fixed (4158822). // Use Xor mode when selected/highlighted. // ! Could darken image instead, but it would be more expensive. /* if( sel > 0 ) g.setXORMode(Color.white); g.drawImage(fImage,x, y, width,height,this); if( sel > 0 ) g.setPaintMode(); */ } // If selected exactly, we need a black border & grow-box: Color bc = getBorderColor(); if (sel == 2) { // Make sure there's room for a border: int delta = 2 - border; if (delta > 0) { x += delta; y += delta; width -= delta << 1; height -= delta << 1; border = 2; } bc = null; g.setColor(Color.black); // Draw grow box: g.fillRect(x + width - 5, y + height - 5, 5, 5); } // Draw border: if (border > 0) { if (bc != null) g.setColor(bc); // Draw a thick rectangle: for (int i = 1; i <= border; i++) g.drawRect(x - i, y - i, width - 1 + i + i, height - 1 + i + i); g.setColor(oldColor); } }
@Override protected void paintText( Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) { g.setFont(font); int titleWidth = SwingUtilities.computeStringWidth(metrics, title); int preferredWidth = 0; if (isOneActionButtonEnabled()) { preferredWidth = calculateTabWidth(tabPlacement, tabIndex, metrics) - WIDTHDELTA - 15; if (isCloseEnabled()) preferredWidth -= BUTTONSIZE; if (isMaxEnabled()) preferredWidth -= BUTTONSIZE; } else { preferredWidth = titleWidth; } while (titleWidth > preferredWidth) { if (title.endsWith("...")) title = title.substring(0, title.indexOf("...") - 1).concat("..."); else title = title.substring(0, title.length() - 4).concat("..."); titleWidth = SwingUtilities.computeStringWidth(metrics, title); } textRect.width = titleWidth; View v = getTextViewForTab(tabIndex); if (v != null) { // html v.paint(g, textRect); } else { // plain text int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex); if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) { if (isSelected) g.setColor(TAB_SELECTED_FOREGROUND_COLOR); else { if (this.isTabHighlighted(tabIndex)) { g.setColor(TAB_HIGHLIGHT_FOREGROUND_COLOR); } else g.setColor(tabPane.getForegroundAt(tabIndex)); } BasicGraphicsUtils.drawString( g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent()); } else { // tab disabled g.setColor(tabPane.getBackgroundAt(tabIndex).brighter()); BasicGraphicsUtils.drawStringUnderlineCharAt( g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent()); g.setColor(tabPane.getBackgroundAt(tabIndex).darker()); BasicGraphicsUtils.drawStringUnderlineCharAt( g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1); } } }
@Override public void paint(Graphics g) { Color origColor; boolean isPressed, isRollOver, isEnabled; int w, h, size; w = getWidth(); h = getHeight(); origColor = g.getColor(); isPressed = getModel().isPressed(); isRollOver = getModel().isRollover(); isEnabled = isEnabled(); g.setColor(getBackground()); g.fillRect(0, 0, w, h); g.setColor(shadow); // Using the background color set above if (direction == WEST) { g.drawLine(0, 0, 0, h - 1); // left g.drawLine(w - 1, 0, w - 1, 0); // right } else g.drawLine(w - 2, h - 1, w - 2, 0); // right g.drawLine(0, 0, w - 2, 0); // top if (isRollOver) { // do highlights or shadows Color color1; Color color2; if (isPressed) { color2 = Color.WHITE; color1 = shadow; } else { color1 = Color.WHITE; color2 = shadow; } g.setColor(color1); if (direction == WEST) { g.drawLine(1, 1, 1, h - 1); // left g.drawLine(1, 1, w - 2, 1); // top g.setColor(color2); g.drawLine(w - 1, h - 1, w - 1, 1); // right } else { g.drawLine(0, 1, 0, h - 1); g.drawLine(0, 1, w - 3, 1); // top g.setColor(color2); g.drawLine(w - 3, h - 1, w - 3, 1); // right } } // g.drawLine(0, h - 1, w - 1, h - 1); //bottom // If there's no room to draw arrow, bail if (h < 5 || w < 5) { g.setColor(origColor); return; } if (isPressed) { g.translate(1, 1); } // Draw the arrow size = Math.min((h - 4) / 3, (w - 4) / 3); size = Math.max(size, 2); boolean highlight = false; if (!highlightedTabs.isEmpty() && ((direction == WEST && tabScroller.scrollBackwardButton.isEnabled()) || (direction == EAST && tabScroller.scrollForwardButton.isEnabled()))) { Rectangle viewRect = tabScroller.viewport.getViewRect(); if (direction == WEST) { int leadingTabIndex = getClosestTab(viewRect.x, viewRect.y); for (int i = 0; i < leadingTabIndex; i++) { if (highlightedTabs.contains(i) && !isScrollTabVisible(i)) { highlight = true; break; } } } else { int leadingTabIndex = getClosestTab(viewRect.x + viewRect.y, viewRect.y); for (int i = leadingTabIndex; i < tabPane.getTabCount(); i++) { if (highlightedTabs.contains(i) && !isScrollTabVisible(i)) { highlight = true; break; } } } if (highlight) { Image img = DesktopUtilActivator.getImage( direction == WEST ? "service.gui.icons.TAB_UNREAD_BACKWARD_ICON" : "service.gui.icons.TAB_UNREAD_FORWARD_ICON"); int wi = img.getWidth(null); g.drawImage(img, (w - wi) / 2, (h - size) / 2 - 2 /* 2 borders 1px width*/, null); } } if (!highlight) paintTriangle(g, (w - size) / 2, (h - size) / 2, size, direction, isEnabled); // Reset the Graphics back to it's original settings if (isPressed) { g.translate(-1, -1); } g.setColor(origColor); }
/** * Actually paints the text area. Only lines that have been damaged are repainted. * * @param g The graphics context with which to paint. * @param a The allocated region in which to render. */ @Override public void paint(Graphics g, Shape a) { RSyntaxDocument document = (RSyntaxDocument) getDocument(); Rectangle alloc = a.getBounds(); tabBase = alloc.x; host = (RSyntaxTextArea) getContainer(); Rectangle clip = g.getClipBounds(); // An attempt to speed things up for files with long lines. Note that // this will actually slow things down a bit for the common case of // regular-length lines, but it doesn't make a perceivable difference. clipStart = clip.x; clipEnd = clipStart + clip.width; lineHeight = host.getLineHeight(); ascent = host.getMaxAscent(); // metrics.getAscent(); int heightAbove = clip.y - alloc.y; int linesAbove = Math.max(0, heightAbove / lineHeight); FoldManager fm = host.getFoldManager(); linesAbove += fm.getHiddenLineCountAbove(linesAbove, true); Rectangle lineArea = lineToRect(a, linesAbove); int y = lineArea.y + ascent; int x = lineArea.x; Element map = getElement(); int lineCount = map.getElementCount(); // Whether token styles should always be painted, even in selections int selStart = host.getSelectionStart(); int selEnd = host.getSelectionEnd(); RSyntaxTextAreaHighlighter h = (RSyntaxTextAreaHighlighter) host.getHighlighter(); Graphics2D g2d = (Graphics2D) g; Token token; // System.err.println("Painting lines: " + linesAbove + " to " + (endLine-1)); TokenPainter painter = host.getTokenPainter(); int line = linesAbove; // int count = 0; while (y < clip.y + clip.height + ascent && line < lineCount) { Fold fold = fm.getFoldForLine(line); Element lineElement = map.getElement(line); int startOffset = lineElement.getStartOffset(); // int endOffset = (line==lineCount ? lineElement.getEndOffset()-1 : // lineElement.getEndOffset()-1); int endOffset = lineElement.getEndOffset() - 1; // Why always "-1"? h.paintLayeredHighlights(g2d, startOffset, endOffset, a, host, this); // Paint a line of text. token = document.getTokenListForLine(line); if (selStart == selEnd || startOffset >= selEnd || endOffset < selStart) { drawLine(painter, token, g2d, x, y, line); } else { // System.out.println("Drawing line with selection: " + line); drawLineWithSelection(painter, token, g2d, x, y, selStart, selEnd); } if (fold != null && fold.isCollapsed()) { // Visible indicator of collapsed lines Color c = RSyntaxUtilities.getFoldedLineBottomColor(host); if (c != null) { g.setColor(c); g.drawLine(x, y + lineHeight - ascent - 1, host.getWidth(), y + lineHeight - ascent - 1); } // Skip to next line to paint, taking extra care for lines with // block ends and begins together, e.g. "} else {" do { int hiddenLineCount = fold.getLineCount(); if (hiddenLineCount == 0) { // Fold parser identified a zero-line fold region. // This is really a bug, but we'll be graceful here // and avoid an infinite loop. break; } line += hiddenLineCount; fold = fm.getFoldForLine(line); } while (fold != null && fold.isCollapsed()); } y += lineHeight; line++; // count++; } // System.out.println("SyntaxView: lines painted=" + count); }
protected void paintText( Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) { g.setFont(font); View v = getTextViewForTab(tabIndex); if (v != null) { // html Graphics2D g2D = (Graphics2D) g; Object savedRenderingHint = null; if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) { savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2D.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint()); } v.paint(g, textRect); if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) { g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint); } } else { // plain text int mnemIndex = -1; if (JTattooUtilities.getJavaVersion() >= 1.4) { mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex); } if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) { if (isSelected && (tabPane.getBackgroundAt(tabIndex) instanceof UIResource)) { Color shadowColor = ColorHelper.darker(AcrylLookAndFeel.getWindowTitleColorDark(), 30); g.setColor(shadowColor); JTattooUtilities.drawStringUnderlineCharAt( tabPane, g, title, mnemIndex, textRect.x - 1, textRect.y - 1 + metrics.getAscent()); JTattooUtilities.drawStringUnderlineCharAt( tabPane, g, title, mnemIndex, textRect.x - 1, textRect.y + 1 + metrics.getAscent()); JTattooUtilities.drawStringUnderlineCharAt( tabPane, g, title, mnemIndex, textRect.x + 1, textRect.y - 1 + metrics.getAscent()); JTattooUtilities.drawStringUnderlineCharAt( tabPane, g, title, mnemIndex, textRect.x + 1, textRect.y + 1 + metrics.getAscent()); g.setColor(AbstractLookAndFeel.getTheme().getWindowTitleForegroundColor()); } else { g.setColor(tabPane.getForegroundAt(tabIndex)); } JTattooUtilities.drawStringUnderlineCharAt( tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent()); } else { // tab disabled g.setColor(tabPane.getBackgroundAt(tabIndex).brighter()); JTattooUtilities.drawStringUnderlineCharAt( tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent()); g.setColor(tabPane.getBackgroundAt(tabIndex).darker()); JTattooUtilities.drawStringUnderlineCharAt( tabPane, g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1); } } }