Class TextElement


public class TextElement extends AnnotationElement
A text element is an annotation element the renders text strings. The element specifies various text properties such as the text string value, position, orientation, alignment, and so on. The text is rendered in the annotation foreground color, and a drop shadow in the background color.
Since:
3.1.1
Author:
Peter Hollemans
  • Field Details

    • DEFAULT_FONT

      public static final Font DEFAULT_FONT
      The default font.
  • Constructor Details

    • TextElement

      public TextElement(String text, Point2D base)
      Creates a new text element with the specified string and base point. The font is initialized to the default 12 point plain font, the alignment to [0,0], and the angle to 0.
      Parameters:
      text - the text string.
      base - the text base point.
    • TextElement

      public TextElement(String text, Font font, Point2D base, double[] align, double angle)
      Creates a new text element with the specified properties.
      Parameters:
      text - the text string.
      font - the text font.
      base - the base point.
      align - the text alignment as [horizontal, vertical]. The alignment is a set of normalized values in the range [0..1] which represent where in the bounding box of the text string the base point is located. For example if the alignment is [0,0], then the base point is at the lower-left corner of the text string. If the alignment is [0.5, 0], then the base point is at the bottom-center of the text string. If null, the alignment is set to [0,0].
      angle - the orientation angle. The angle is measured in degrees and represents the angle between the horizontal and the text string baseline direction. For example, and angle of 45 would draw text from lower-left to upper-right.
  • Method Details

    • getLayout

      public TextLayout getLayout(Graphics2D g)
      Gets the text layout object for this element.
      Parameters:
      g - the graphics device for drawing.
    • getText

      public String getText()
      Gets the text string.
    • setText

      public void setText(String text)
      Sets the text string.
    • setBasePoint

      public void setBasePoint(Point2D base)
      Sets the text base point.
    • getBasePoint

      public Point2D getBasePoint()
      Gets the text base point.
    • setAngle

      public void setAngle(double angle)
      Sets the text orientation angle.
    • setFont

      public void setFont(Font font)
      Sets the text font.
    • getFont

      public Font getFont()
      Gets the text font.
    • setAlignment

      public void setAlignment(double[] align)
      Sets the text alignment.
    • render

      public void render(Graphics2D g2, Color foreground, Color background)
      Description copied from class: AnnotationElement
      Renders the element graphics.
      Specified by:
      render in class AnnotationElement
      Parameters:
      g2 - the graphics object for drawing.
      foreground - the foreground element color.
      background - the background element color or null for no background.
    • getArea

      public Area getArea(Graphics2D g)
      Description copied from class: AnnotationElement
      Gets the element bounding area.
      Specified by:
      getArea in class AnnotationElement
      Parameters:
      g - the graphics object for drawing.