Пример #1
0
 @Override
 protected void drawText(java.awt.Graphics2D g) {
   if (getText() != null || isEditable()) {
     TextLayout layout = getTextLayout();
     layout.draw(g, (float) origin.x, (float) (origin.y + layout.getAscent()));
   }
 }
Пример #2
0
 @Override
 public Rectangle2D.Double getBounds() {
   TextLayout layout = getTextLayout();
   Rectangle2D.Double r =
       new Rectangle2D.Double(
           origin.x, origin.y, layout.getAdvance(), layout.getAscent() + layout.getDescent());
   return r;
 }
Пример #3
0
 /** Gets the drawing area without taking the decorator into account. */
 @Override
 protected Rectangle2D.Double getFigureDrawingArea() {
   if (getText() == null) {
     return getBounds();
   } else {
     TextLayout layout = getTextLayout();
     Rectangle2D.Double r =
         new Rectangle2D.Double(origin.x, origin.y, layout.getAdvance(), layout.getAscent());
     Rectangle2D lBounds = layout.getBounds();
     if (!lBounds.isEmpty() && !Double.isNaN(lBounds.getX())) {
       r.add(
           new Rectangle2D.Double(
               lBounds.getX() + origin.x,
               (lBounds.getY() + origin.y + layout.getAscent()),
               lBounds.getWidth(),
               lBounds.getHeight()));
     }
     // grow by two pixels to take antialiasing into account
     Geom.grow(r, 2d, 2d);
     return r;
   }
 }
Пример #4
0
  private Shape getTextShape() {
    if (cachedTextShape == null) {
      String text = getText();
      if (text == null || text.length() == 0) {
        text = " ";
      }

      FontRenderContext frc = getFontRenderContext();
      HashMap<TextAttribute, Object> textAttributes = new HashMap<TextAttribute, Object>();
      textAttributes.put(TextAttribute.FONT, getFont());
      if (FONT_UNDERLINE.get(this)) {
        textAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
      }
      TextLayout textLayout = new TextLayout(text, textAttributes, frc);

      AffineTransform tx = new AffineTransform();
      tx.translate(coordinates[0].x, coordinates[0].y);
      switch (TEXT_ANCHOR.get(this)) {
        case END:
          tx.translate(-textLayout.getAdvance(), 0);
          break;
        case MIDDLE:
          tx.translate(-textLayout.getAdvance() / 2d, 0);
          break;
        case START:
          break;
      }
      tx.rotate(rotates[0]);

      /*
      if (TRANSFORM.get(this) != null) {
          tx.preConcatenate(TRANSFORM.get(this));
      }*/

      cachedTextShape = tx.createTransformedShape(textLayout.getOutline(tx));
      cachedTextShape = textLayout.getOutline(tx);
    }
    return cachedTextShape;
  }
Пример #5
0
 @Override
 public double getBaseline() {
   TextLayout layout = getTextLayout();
   return origin.y + layout.getAscent() - getBounds().y;
 }