@Override public void paint(Graphics g, Shape allocation) { Rectangle r = (allocation instanceof Rectangle) ? (Rectangle) allocation : allocation.getBounds(); Color oldColor = g.getColor(); Integer lineNumber = getLineNumber(); Color highlightColor = highlight.getHighlight(lineNumber); if (highlightColor != null) { g.setColor(highlightColor); g.fillRect(r.x, r.y, r.width, r.height); g.setColor(oldColor); } // r.x += NUMBERS_WIDTH; super.paint(g, r); FontMetrics metrics = g.getFontMetrics(); g.setColor(Color.GRAY); String lineNumberString = lineNumber.toString(); int width = metrics.stringWidth(lineNumberString); int numberX = r.x - width - 9 + NUMBERS_WIDTH; int numberY = r.y + metrics.getAscent(); g.drawString(lineNumberString, numberX, numberY); g.setColor(oldColor); // System.out.println("Drawing line for " + lineNumber + " @ " + numberX // +"," + numberY); // r.x -= NUMBERS_WIDTH; }
/** * Renders using the given rendering surface and area on that surface. * The view may need to do layout and create child views to enable * itself to render into the given allocation. * * @param g the rendering surface to use * @param a the allocated region to render into * * @see View#paint */ @Override public void paint(Graphics g, Shape a) { Rectangle r = (Rectangle) a; g.clipRect(r.x, r.y, r.width, r.height); super.paint(g, adjustAllocation(a)); }
@Override public void paint(Graphics g, Shape a) { boolean isEmpty = getDocument().getLength() < 2; Color bgColor = (Color)getAttributes().getAttribute(Attribute.CUSTOM_BACKGROUND); if (bgColor == null && getAttributes().containsAttribute(Attribute.HIGHLIGHT_LINE, true)) { bgColor = MyStyleConstants.getHighlightBackground(getAttributes()); } if (bgColor == null && getAttributes().containsAttribute(Attribute.EVEN, true)) { bgColor = MyStyleConstants.getBackground2(getAttributes()); } if (bgColor != null && !isEmpty) { g.setColor(bgColor); Rectangle r = a.getBounds(); g.fillRect(0, r.y, getContainer().getWidth(), r.height); } Color separatorColor = MyStyleConstants.getSeparatorColor(getAttributes()); if (separatorColor != null && !isEmpty) { g.setColor(separatorColor); Rectangle r = a.getBounds(); g.drawLine(0, r.y, getContainer().getWidth(), r.y); if (bgColor != null) { g.drawLine(0, r.y+r.height, getContainer().getWidth(), r.y+r.height); } } super.paint(g, a); }