/** * Paints the bevel image for the specified component with the specified position and size. * * @param c the component for which this border is being painted * @param gr the paint graphics * @param x the x position of the painted border * @param y the y position of the painted border * @param width the width of the painted border * @param height the height of the painted border */ public void paintBorder(Component c, Graphics gr, int x, int y, int width, int height) { if (image == null) return; if (gr.getClipBounds() != null && !gr.getClipBounds().intersects(x, y, width, height)) { return; } paint(c, gr, x, y, width, height, args); }
public void paintIcon(Graphics g) { final BufferedImage image = new BufferedImage( myIcon.getIconWidth(), myIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D gg = image.createGraphics(); myIcon.paintIcon(this, gg, 0, 0); final Rectangle bounds = g.getClipBounds(); int y = myIcon.getIconHeight() - 1; while (y < bounds.y + bounds.height) { g.drawImage( image, bounds.x, y, bounds.x + bounds.width, y + 1, 0, myIcon.getIconHeight() - 1, bounds.width, myIcon.getIconHeight(), this); y++; } g.drawImage(image, 0, 0, this); }
/** * Renders using the given rendering surface and area on that surface. * * @param g the rendering surface to use * @param allocation the allocated region to render into * @see View#paint */ public void paint(Graphics g, Shape allocation) { super.paint(g, allocation); Rectangle alloc = allocation.getBounds(); Rectangle clip = g.getClipBounds(); // Since listPainter paints in the insets we have to check for the // case where the child is not painted because the paint region is // to the left of the child. This assumes the ListPainter paints in // the left margin. if ((clip.x + clip.width) < (alloc.x + getLeftInset())) { Rectangle childRect = alloc; alloc = getInsideAllocation(allocation); int n = getViewCount(); int endY = clip.y + clip.height; for (int i = 0; i < n; i++) { childRect.setBounds(alloc); childAllocation(i, childRect); if (childRect.y < endY) { if ((childRect.y + childRect.height) >= clip.y) { listPainter.paint( g, childRect.x, childRect.y, childRect.width, childRect.height, this, i); } } else { break; } } } }
/** * 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); } } } }
public void paint(Graphics graphics, long time) { // Clear the background. Color outsideColor = outsideClipColor.getColor(time); Rectangle clip = graphics.getClipBounds(); graphics.setPaintMode(); graphics.setColor(outsideColor); graphics.fillRect(0, 0, clip.width, clip.height); // Draw the sprite in XOR mode. OverrideGraphics2D g = new OverrideGraphics2D((Graphics2D) graphics); Color insideColor = insideClipColor.getColor(time); g.setOverrideXORMode(insideColor); sprite.paint(g, time); g.setOverrideXORMode(null); // Clear the clip area. g.setOverrideColor(insideColor); clipSprite.paint(g, time); g.setOverrideColor(null); // Draw the sprite in XOR mode. g.setOverrideXORMode(insideColor); sprite.paint(g, time); g.setOverrideXORMode(null); }
public void paint(Graphics g) { MetalBumps usedBumps; if (splitPane.hasFocus()) { usedBumps = focusBumps; g.setColor(primaryControlColor); } else { usedBumps = bumps; g.setColor(controlColor); } Rectangle clip = g.getClipBounds(); Insets insets = getInsets(); g.fillRect(clip.x, clip.y, clip.width, clip.height); Dimension size = getSize(); size.width -= inset * 2; size.height -= inset * 2; int drawX = inset; int drawY = inset; if (insets != null) { size.width -= (insets.left + insets.right); size.height -= (insets.top + insets.bottom); drawX += insets.left; drawY += insets.top; } usedBumps.setBumpArea(size); usedBumps.paintIcon(this, g, drawX, drawY); super.paint(g); }
/** * Paint each <code>Lite</code> object in turn after testing if it is inside the clip of the * Graphics. This is the right way to do it if the repainting time of <code>Lite</code> objects is * much greater than the time required to compute its bounds. * * @see excentric.LiteGroup#paintAll(java.awt.Graphics) */ public void paint(Graphics g) { Rectangle clip = g.getClipBounds(); for (Enumeration e = lites.elements(); e.hasMoreElements(); ) { Lite l = (Lite) e.nextElement(); // if (l.getBounds().intersects(clip)) l.paint(g); } }
public void paintComponent(Graphics g) { Rectangle clipBounds = g.getClipBounds(); // paint background gray g.setColor(backgroundColor); g.fillRect(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); // paint selection box super.paintComponent(g); }
@Override public void paint(Graphics g) { Rectangle clipBounds = g.getClipBounds(); paintBackgroundAndFoldingLine(g, clipBounds); paintTextColumns(g, clipBounds); paintIconRenderers(g, clipBounds); paintFoldingArea(g, clipBounds); }
public BorderEffect( EditorImpl editor, Graphics graphics, int clipStartOffset, int clipEndOffset) { myEditor = editor; myGraphics = graphics; myStartOffset = clipStartOffset; myEndOffset = clipEndOffset; myRange = new TextRange(myStartOffset, myEndOffset); myClipDetector = new ClipDetector(editor, graphics.getClipBounds()); }
/** * This method will draw the axes. * * @param gc the graphics * @return the (clipped) graphics for the line */ Graphics paintAxis(Graphics gc) { int originx = 0; int originy = 0; Rectangle space = gc.getClipBounds(); int yTickLen = (int) (space.width * axispercent / 100.0); if (yTickLen < 2) { yTickLen = 2; } else if (yTickLen > 5) { yTickLen = 5; } int xTickLen = (int) (space.height * axispercent / 100.0); if (xTickLen < 2) { xTickLen = 2; } else if (xTickLen > 5) { xTickLen = 5; } originx = yTickLen; originy = space.height - xTickLen; // do the Y axis int tickoff = space.height / (numYTicks - 1); int x1 = 0; int x2 = originx; int y1 = originy; for (int tick = 0; tick < numYTicks; tick++) { gc.drawLine(x1, y1, x2, y1); y1 -= tickoff; } gc.drawLine(originx, originy, originx, y1 + tickoff); // do the X axis tickoff = space.width / (numXTicks - 1); x1 = originx; y1 = space.height; int y2 = originy; for (int tick = 0; tick < numXTicks; tick++) { gc.drawLine(x1, y1, x1, y2); x1 += tickoff; } // now draw the X axis gc.drawLine(originx, originy, space.width, originy); gc = gc.create(originx + 1, 0, space.width - originx - 1, originy); return gc; }
/** * 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(); } }
public void paint(Graphics g, JComponent c) { if (grid.getRowCount() <= 0 || grid.getColumnCount() <= 0) { return; // nothing to paint } Rectangle clip = g.getClipBounds(); Point minLocation = clip.getLocation(); Point maxLocation = new Point(clip.x + clip.width - 1, clip.y + clip.height - 1); int rowMin = grid.rowAtPoint(minLocation); int rowMax = grid.rowAtPoint(maxLocation); // This should never happen. if (rowMin == -1) { rowMin = 0; } // If the spread does not have enough rows to fill the view we'll get -1. // Replace this with the index of the last row. if (rowMax == -1) { rowMax = grid.getRowCount() - 1; } int colMin = grid.columnAtPoint(minLocation); int colMax = grid.columnAtPoint(maxLocation); // This should never happen. if (colMin == -1) { colMin = 0; } // If the spread does not have enough columns to fill the view we'll get -1. // Replace this with the index of the last column. if (colMax == -1) { colMax = grid.getColumnCount() - 1; } // Paint cells paintCells(g, rowMin, rowMax, colMin, colMax); // Paint grid paintGrid(g, rowMin, rowMax, colMin, colMax); // Paint spans paintSpans(g, rowMin, rowMax, colMin, colMax); // Paint borders paintBorders(g, rowMin, rowMax, colMin, colMax); // Paint editor paintEditor(g); }
@Override protected void paintTrack(Graphics g, JComponent c, Rectangle bounds) { g.setColor(TRACK_BACKGROUND); g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); g.setColor(TRACK_BORDER); int border = isMirrored() ? bounds.x + bounds.width - 1 : bounds.x; g.drawLine(border, bounds.y, border, bounds.y + bounds.height); ((ApplicationImpl) ApplicationManager.getApplication()).editorPaintStart(); try { Rectangle clipBounds = g.getClipBounds(); repaint(g, ERROR_ICON_WIDTH - 1, clipBounds); } finally { ((ApplicationImpl) ApplicationManager.getApplication()).editorPaintFinish(); } }
public void paint(Graphics g) { // repaint the whole transformer in case the view component was repainted Rectangle clipBounds = g.getClipBounds(); if (clipBounds != null && !clipBounds.equals(visibleRect)) { repaint(); } // clear the background g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); if (view != null && at.getDeterminant() != 0) { Graphics2D g2 = (Graphics2D) g.create(); Insets insets = getInsets(); Rectangle bounds = getBounds(); // don't forget about insets bounds.x += insets.left; bounds.y += insets.top; bounds.width -= insets.left + insets.right; bounds.height -= insets.top + insets.bottom; double centerX1 = bounds.getCenterX(); double centerY1 = bounds.getCenterY(); Rectangle tb = getTransformedSize(); double centerX2 = tb.getCenterX(); double centerY2 = tb.getCenterY(); // set antialiasing by default g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (renderingHints != null) { g2.addRenderingHints(renderingHints); } // translate it to the center of the view component again double tx = centerX1 - centerX2 - getX(); double ty = centerY1 - centerY2 - getY(); g2.translate((int) tx, (int) ty); g2.transform(at); view.paint(g2); g2.dispose(); } // paint the border paintBorder(g); }
/** special paint handler for merged cell regions */ protected void paintSpans(Graphics g, int rowMin, int rowMax, int colMin, int colMax) { Rectangle clip = g.getClipBounds(); Iterator cell = grid.getSpanModel().getSpanIterator(); while (cell.hasNext()) { CellSpan span = (CellSpan) cell.next(); Rectangle cellBounds = grid.getCellBounds(span.getRow(), span.getColumn()); // Only paint cell if visible if (span.getLastRow() >= rowMin && span.getLastColumn() >= colMin && span.getFirstRow() <= rowMax && span.getFirstColumn() <= colMax) { paintCell(g, cellBounds, span.getRow(), span.getColumn()); // Paint grid line around cell if (grid.getShowGrid()) { g.setColor(grid.getGridColor()); g.drawRect(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height); } } } }
public void paint(Graphics g, JComponent c) { paintBackground(g, c); recalculateIfInsetsChanged(); recalculateIfOrientationChanged(); Rectangle clip = g.getClipBounds(); if (slider.getPaintTrack() && clip.intersects(trackRect)) { paintTrack(g); } if (slider.getPaintTicks() && clip.intersects(tickRect)) { paintTicks(g); } if (slider.getPaintLabels() && clip.intersects(labelRect)) { paintLabels(g); } if (slider.hasFocus() && clip.intersects(focusRect)) { paintFocus(g); } if (clip.intersects(thumbRect)) { paintThumb(g); } }
/** * 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; } } }
public void paint(Graphics g) { Rectangle r = g.getClipBounds(); showStatus("x: " + r.x + " y: " + r.y + " w: " + r.width + " h: " + r.height); for (int i = 0; i < numRects; i++) { Point lhc = randomPoint(); // left hand corner Dimension size = randomDimension(); g.setColor(colors[(int) (Math.random() * 10)]); if (round) { if (fill) g.fillRoundRect( lhc.x, lhc.y, size.width, size.height, (int) (Math.random() * 250), (int) (Math.random() * 250)); else g.drawRoundRect( lhc.x, lhc.y, size.width, size.height, (int) (Math.random() * 250), (int) (Math.random() * 250)); } else if (threeD) { g.setColor(Color.lightGray); if (fill) g.fill3DRect(lhc.x, lhc.y, size.width, size.height, raise); else g.draw3DRect(lhc.x, lhc.y, size.width, size.height, raise); } else { if (fill) g.fillRect(lhc.x, lhc.y, size.width, size.height); else g.drawRect(lhc.x, lhc.y, size.width, size.height); } raise = raise ? false : true; } }
/** * 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); } } } }
/* (non-Javadoc) * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) */ protected void paintComponent(Graphics arg0) { // long time1 = System.currentTimeMillis(); try { super.paintComponent(arg0); if (this.isOpaque()) { Rectangle clipBounds = arg0.getClipBounds(); arg0.setColor(this.getBackground()); arg0.fillRect(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); } this.rblock.paint(arg0); // Paint FrameContext selection RenderablePoint start = this.startSelection; RenderablePoint end = this.endSelection; if (start != null && end != null && !start.equals(end)) { this.rblock.paintSelection(arg0, false, start, end); } } finally { // long time2 = System.currentTimeMillis(); // System.out.println("NonScrollableHtmlPanel.paintComponent(): numRenderables=" + // numRenderables + ",time=" + (time2 - time1) + " ms."); } }
/** * Paint the image onto a Graphics object. The painting is performed tile-by-tile, and includes a * grey region covering the unused portion of image tiles as well as the general background. At * this point the image must be byte data. */ public synchronized void paintComponent(Graphics g) { Graphics2D g2D = null; if (g instanceof Graphics2D) { g2D = (Graphics2D) g; } else { return; } // if source is null, it's just a component if (source == null) { g2D.setColor(getBackground()); g2D.fillRect(0, 0, componentWidth, componentHeight); return; } int transX = -originX; int transY = -originY; // Get the clipping rectangle and translate it into image coordinates. Rectangle clipBounds = g.getClipBounds(); if (clipBounds == null) { clipBounds = new Rectangle(0, 0, componentWidth, componentHeight); } // clear the background (clip it) [minimal optimization here] if (transX > 0 || transY > 0 || transX < (componentWidth - source.getWidth()) || transY < (componentHeight - source.getHeight())) { g2D.setColor(getBackground()); g2D.fillRect(0, 0, componentWidth, componentHeight); } clipBounds.translate(-transX, -transY); // Determine the extent of the clipping region in tile coordinates. int txmin, txmax, tymin, tymax; int ti, tj; txmin = XtoTileX(clipBounds.x); txmin = Math.max(txmin, minTileX); txmin = Math.min(txmin, maxTileX); txmax = XtoTileX(clipBounds.x + clipBounds.width - 1); txmax = Math.max(txmax, minTileX); txmax = Math.min(txmax, maxTileX); tymin = YtoTileY(clipBounds.y); tymin = Math.max(tymin, minTileY); tymin = Math.min(tymin, maxTileY); tymax = YtoTileY(clipBounds.y + clipBounds.height - 1); tymax = Math.max(tymax, minTileY); tymax = Math.min(tymax, maxTileY); Insets insets = getInsets(); // Loop over tiles within the clipping region for (tj = tymin; tj <= tymax; tj++) { for (ti = txmin; ti <= txmax; ti++) { int tx = TileXtoX(ti); int ty = TileYtoY(tj); Raster tile = source.getTile(ti, tj); if (tile != null) { DataBuffer dataBuffer = tile.getDataBuffer(); WritableRaster wr = tile.createWritableRaster(sampleModel, dataBuffer, null); BufferedImage bi = new BufferedImage(colorModel, wr, colorModel.isAlphaPremultiplied(), null); // correctly handles band offsets if (brightnessEnabled == true) { SampleModel sm = sampleModel.createCompatibleSampleModel(tile.getWidth(), tile.getHeight()); WritableRaster raster = RasterFactory.createWritableRaster(sm, null); BufferedImage bimg = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null); // don't move this code ByteLookupTable lutTable = new ByteLookupTable(0, lutData); LookupOp lookup = new LookupOp(lutTable, null); lookup.filter(bi, bimg); g2D.drawImage(bimg, biop, tx + transX + insets.left, ty + transY + insets.top); } else { AffineTransform transform; transform = AffineTransform.getTranslateInstance( tx + transX + insets.left, ty + transY + insets.top); g2D.drawRenderedImage(bi, transform); } } } } }
@Override @SuppressWarnings({"AssignmentToForLoopParameter"}) public void paint( @NotNull Editor editor, @NotNull RangeHighlighter highlighter, @NotNull Graphics g) { int startOffset = highlighter.getStartOffset(); final Document doc = highlighter.getDocument(); if (startOffset >= doc.getTextLength()) return; final int endOffset = highlighter.getEndOffset(); final int endLine = doc.getLineNumber(endOffset); int off; int startLine = doc.getLineNumber(startOffset); IndentGuideDescriptor descriptor = editor.getIndentsModel().getDescriptor(startLine, endLine); final CharSequence chars = doc.getCharsSequence(); do { int start = doc.getLineStartOffset(startLine); int end = doc.getLineEndOffset(startLine); off = CharArrayUtil.shiftForward(chars, start, end, " \t"); startLine--; } while (startLine > 1 && off < doc.getTextLength() && chars.charAt(off) == '\n'); final VisualPosition startPosition = editor.offsetToVisualPosition(off); int indentColumn = startPosition.column; // It's considered that indent guide can cross not only white space but comments, javadocs // etc. Hence, there is a possible // case that the first indent guide line is, say, single-line comment where comment // symbols ('//') are located at the first // visual column. We need to calculate correct indent guide column then. int lineShift = 1; if (indentColumn <= 0 && descriptor != null) { indentColumn = descriptor.indentLevel; lineShift = 0; } if (indentColumn <= 0) return; final FoldingModel foldingModel = editor.getFoldingModel(); if (foldingModel.isOffsetCollapsed(off)) return; final FoldRegion headerRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineEndOffset(doc.getLineNumber(off))); final FoldRegion tailRegion = foldingModel.getCollapsedRegionAtOffset( doc.getLineStartOffset(doc.getLineNumber(endOffset))); if (tailRegion != null && tailRegion == headerRegion) return; final boolean selected; final IndentGuideDescriptor guide = editor.getIndentsModel().getCaretIndentGuide(); if (guide != null) { final CaretModel caretModel = editor.getCaretModel(); final int caretOffset = caretModel.getOffset(); selected = caretOffset >= off && caretOffset < endOffset && caretModel.getLogicalPosition().column == indentColumn; } else { selected = false; } Point start = editor.visualPositionToXY( new VisualPosition(startPosition.line + lineShift, indentColumn)); final VisualPosition endPosition = editor.offsetToVisualPosition(endOffset); Point end = editor.visualPositionToXY(new VisualPosition(endPosition.line, endPosition.column)); int maxY = end.y; if (endPosition.line == editor.offsetToVisualPosition(doc.getTextLength()).line) { maxY += editor.getLineHeight(); } Rectangle clip = g.getClipBounds(); if (clip != null) { if (clip.y >= maxY || clip.y + clip.height <= start.y) { return; } maxY = Math.min(maxY, clip.y + clip.height); } final EditorColorsScheme scheme = editor.getColorsScheme(); g.setColor( selected ? scheme.getColor(EditorColors.SELECTED_INDENT_GUIDE_COLOR) : scheme.getColor(EditorColors.INDENT_GUIDE_COLOR)); // There is a possible case that indent line intersects soft wrap-introduced text. // Example: // this is a long line <soft-wrap> // that| is soft-wrapped // | // | <- vertical indent // // Also it's possible that no additional intersections are added because of soft wrap: // this is a long line <soft-wrap> // | that is soft-wrapped // | // | <- vertical indent // We want to use the following approach then: // 1. Show only active indent if it crosses soft wrap-introduced text; // 2. Show indent as is if it doesn't intersect with soft wrap-introduced text; if (selected) { g.drawLine(start.x + 2, start.y, start.x + 2, maxY); } else { int y = start.y; int newY = start.y; SoftWrapModel softWrapModel = editor.getSoftWrapModel(); int lineHeight = editor.getLineHeight(); for (int i = Math.max(0, startLine + lineShift); i < endLine && newY < maxY; i++) { List<? extends SoftWrap> softWraps = softWrapModel.getSoftWrapsForLine(i); int logicalLineHeight = softWraps.size() * lineHeight; if (i > startLine + lineShift) { logicalLineHeight += lineHeight; // We assume that initial 'y' value points just below the target // line. } if (!softWraps.isEmpty() && softWraps.get(0).getIndentInColumns() < indentColumn) { if (y < newY || i > startLine + lineShift) { // There is a possible case that soft wrap is located on // indent start line. g.drawLine(start.x + 2, y, start.x + 2, newY + lineHeight); } newY += logicalLineHeight; y = newY; } else { newY += logicalLineHeight; } FoldRegion foldRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineEndOffset(i)); if (foldRegion != null && foldRegion.getEndOffset() < doc.getTextLength()) { i = doc.getLineNumber(foldRegion.getEndOffset()); } } if (y < maxY) { g.drawLine(start.x + 2, y, start.x + 2, maxY); } } }
/** Overrides <code>Graphics.getClipBounds</code>. */ public Rectangle getClipBounds() { return graphics.getClipBounds(); }
public void update(Graphics g) { offScreenGraphics.setClip(g.getClipBounds()); paint(offScreenGraphics); g.drawImage(offScreenImage, 0, 0, this); // paint(g); }
/** * 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); }
public void paintComponent(Graphics g) { Rectangle selection = g.getClipBounds(); // clear out the image Graphics2D g2 = (Graphics2D) g; g2.setBackground(backgroundColor); g2.clearRect( (int) selection.getX(), (int) selection.getY(), (int) selection.getWidth(), (int) selection.getHeight()); // draw the selection if it exists if (selBeginPixel != -1 && selEndPixel != -1) { g2.setBackground(selectionColor); g2.clearRect(selBeginPixel, 0, selEndPixel - selBeginPixel + 1, this.getHeight()); } if (this.points.size() > 0) { g2.setColor(waveColor); // draw the lines if (this.points.size() > stemThresh) { if (points.size() > frameWidth) { // draw contour // g2.setStroke(thickerStroke); for (int i = 0; i < this.points.size() - 1; i += 4) { Point2D.Float pt1 = points.get(i).getDispPoint(); // Point2D.Float pt2 = new Point2D.Float(pt1.x, pt1.y/2); Point2D.Float pt2 = points.get(i + 1).getDispPoint(); Point2D.Float pt3 = points.get(i + 2).getDispPoint(); Point2D.Float pt4 = points.get(i + 3).getDispPoint(); // //Point2D.Float pt4 = new Point2D.Float(pt2.x, pt2.y/2); g2.draw(new Line2D.Float(pt1, pt2)); // g2.setColor(waveLiteColor); g.setColor(waveLiteColor); g2.draw(new Line2D.Float(pt2, pt3)); g2.setColor(waveColor); g2.draw(new Line2D.Float(pt3, pt4)); // g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(), // this.points.get(i+1).getDispPoint())); // g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(), // this.points.get(i+1).getDispPoint())); // g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(), // this.points.get(i+1).getDispPoint())); } } else { // draw line g2.setStroke(stroke); for (int i = 0; i < this.points.size() - 1; i++) { g2.draw( new Line2D.Float( this.points.get(i).getDispPoint(), this.points.get(i + 1).getDispPoint())); } } } else { // stem plot for (int i = 0; i < this.points.size(); i++) { // draw the stem SoundSample sample = this.points.get(i); g2.setStroke(thickerStroke); Point2D.Double base = new Point2D.Double( sample.getDispPoint().getX() + 10, Math.floor(this.getHeight()) / 2); Point2D.Double pt = new Point2D.Double(sample.getDispPoint().getX() + 10, sample.getDispPoint().getY()); g2.draw(new Line2D.Float(base, pt)); if (this.points.size() < zoomThresh) { // draw the sample value float sampleValue = (float) sample.getSampleValue(); float y = (float) sample.getDispPoint().getY(); g2.setFont(textFont); if (y < Math.floor(this.getHeight()) / 2) y = y - 10; else y = y + 10; // if (sample.getDispPoint().getX() > 0) g2.drawString(formatter.format(sampleValue), (float) sample.getDispPoint().getX(), y); } // draw the vertical bar in the array // g2.setStroke(thickerStroke); // base = new Point2D.Double(base.getX()-8, this.getHeight() - 10); // pt = new Point2D.Double(base.getX(), this.getHeight() - 50); // g2.draw(new Line2D.Double(base, pt)); // g2.drawString(formatter.format(points.get(i).getSampleIndex()), // (float)base.getX(), (float)base.getY() - 10 ); } // // g2.setStroke(wideStroke); // //draw the array cells // g2.draw(new Line2D.Double(selection.getX(), // Math.floor(this.getHeight() - 30), // selection.getX()+selection.getWidth()-1, // Math.floor(this.getHeight() - 30))); // //draw the array cells // g2.draw(new Line2D.Double(selection.getX(), // Math.floor(this.getHeight() - 10), // selection.getX()+selection.getWidth()-1, // Math.floor(this.getHeight() - 10))); } } // draw the center line g2.setColor(barColor); g2.setStroke(new BasicStroke(1)); g2.draw( new Line2D.Double( selection.getX(), Math.floor(this.getHeight() / 2), selection.getX() + selection.getWidth() - 1, Math.floor(this.getHeight() / 2))); // //draw the current position // if (selection.getX()<currentPixelPosition && // currentPixelPosition<(selection.getX()+selection.getWidth()-1)) // { // g2.setColor(barColor); // g2.setStroke(new BasicStroke(1)); // g2.draw(new Line2D.Double(currentPixelPosition, 0, // currentPixelPosition, frameHeight)); // } }
/** * Basic drawing implementation for the game. * * <p>Fills the background (white) and calls Level's drawing method. * * @param g A Graphics context. */ protected void paintComponent(Graphics g) { Rectangle size = g.getClipBounds(); g.setColor(Color.white); g.fillRect(size.x, size.y, size.width, size.height); game.getLevel().draw(g); }
public static void showBounds(Graphics g) { g.setColor(Color.red); drawRect(g, g.getClipBounds()); }
public void paint(Graphics g, JComponent c) { if ((header == null) || (header.getTable() == null) || header.getColumnModel().getColumnCount() <= 0) { return; } boolean ltr = header.getComponentOrientation().isLeftToRight(); Rectangle clip = g.getClipBounds(); Point left = clip.getLocation(); Point right = new Point(clip.x + clip.width - 1, clip.y); TableColumnModel cm = header.getColumnModel(); int cMin = header.columnAtPoint(ltr ? left : right); int cMax = header.columnAtPoint(ltr ? right : left); // This should never happen. if (cMin == -1) { cMin = 0; } // If the table does not have enough columns to fill the view we'll get -1. // Replace this with the index of the last column. if (cMax == -1) { cMax = cm.getColumnCount() - 1; } TableColumn draggedColumn = header.getDraggedColumn(); Rectangle cellRect = header.getHeaderRect(ltr ? cMin : cMax); int columnWidth; TableColumn aColumn; if (ltr) { for (int column = cMin; column <= cMax; column++) { aColumn = cm.getColumn(column); columnWidth = aColumn.getWidth(); cellRect.width = columnWidth; if (aColumn != draggedColumn) { paintCell(g, cellRect, column); } cellRect.x += columnWidth; } } else { for (int column = cMax; column >= cMin; column--) { aColumn = cm.getColumn(column); columnWidth = aColumn.getWidth(); cellRect.width = columnWidth; if (aColumn != draggedColumn) { paintCell(g, cellRect, column); } cellRect.x += columnWidth; } } // Paint the dragged column if we are dragging. if (draggedColumn != null) { int draggedColumnIndex = viewIndexForColumn(draggedColumn); Rectangle draggedCellRect = header.getHeaderRect(draggedColumnIndex); // Draw a gray well in place of the moving column. g.setColor(header.getParent().getBackground()); g.fillRect( draggedCellRect.x, draggedCellRect.y, draggedCellRect.width, draggedCellRect.height); draggedCellRect.x += header.getDraggedDistance(); // Fill the background. g.setColor(header.getBackground()); g.fillRect( draggedCellRect.x, draggedCellRect.y, draggedCellRect.width, draggedCellRect.height); paintCell(g, draggedCellRect, draggedColumnIndex); } // Remove all components in the rendererPane. rendererPane.removeAll(); }