public void paint(Graphics g, Shape a) { Graphics2D g2 = (Graphics2D) g; Rectangle2D abounds = a.getBounds2D(); AffineTransform saveTransform = g2.getTransform(); Paint savePaint = g2.getPaint(); try { g2.translate(abounds.getX() - bounds.getX(), abounds.getY() - bounds.getY()); g2.setPaint(Color.BLACK); // FIXME p.paint(g2); } finally { g2.setTransform(saveTransform); g2.setPaint(savePaint); } }
public void render(int w, int h, Graphics2D g2) { FontRenderContext frc = g2.getFontRenderContext(); for (int i = 0; i < 2; i++) { layouts[i] = new TextLayout(text[i], fonts[i], frc); float rw = layouts[i].getAdvance(); float rh = layouts[i].getAscent() + layouts[i].getDescent(); float rx = (float) ((w - rw) / 2); float ry = (float) ((i == 0) ? h / 3 : h * 0.75f); // draw highlighted shape Shape hilite = layouts[i].getLogicalHighlightShape(0, curPos[i]); AffineTransform at = AffineTransform.getTranslateInstance(rx, ry); hilite = at.createTransformedShape(hilite); float hy = (float) hilite.getBounds2D().getY(); float hh = (float) hilite.getBounds2D().getHeight(); g2.setColor(colors[i]); g2.fill(hilite); // get caret shape Shape[] shapes = layouts[i].getCaretShapes(curPos[i]); Shape caret = at.createTransformedShape(shapes[0]); g2.setColor(Color.black); layouts[i].draw(g2, rx, ry); g2.draw(caret); g2.draw(new Rectangle2D.Float(rx, hy, rw, hh)); // Display character advances. for (int j = 0; j <= layouts[i].getCharacterCount(); j++) { float[] cInfo = layouts[i].getCaretInfo(TextHitInfo.leading(j)); String str = String.valueOf((int) cInfo[0]); TextLayout tl = new TextLayout(str, smallF, frc); tl.draw(g2, (float) rx + cInfo[0] - tl.getAdvance() / 2, hy + hh + tl.getAscent() + 1.0f); } } }