Class TextItem

All Implemented Interfaces:
IFeedbackProvider, IDrawable, ITextEditable, EventListener

public class TextItem extends RectangleItem implements ITextEditable
A drawable item that renders text with a rectangular background/border.

Key invariants:

  • AItem._focus is the world-coordinate center of the text box.
  • Path corners are computed via a screen-space round-trip: world focus → screen focus → pixel corners → world corners. This is required because font metrics are in pixels and the world coordinate system may have an entirely different scale.
  • Rotation is handled in screen space. A world-space affine rotation only looks correct when scaleX == scaleY. With a non-square world coordinate system, a world-space rotation shears the rectangle so it no longer matches the text drawn by TextUtils.drawRotatedText(java.awt.Graphics2D, java.awt.Point, java.lang.String, java.awt.Font, java.awt.Color, double, int), which rotates in screen space.
  • The stored font is the logical/base font. At draw time, a temporary derived font is chosen to fit the current screen-space text box. This lets text scale visually with zooming and item resizing without mutating the stored font.
  • Constructor Details

    • TextItem

      public TextItem(Layer itemList, Point2D.Double location, Font font, String text, Color lineColor, Color fillColor, Color textColor)
      Parameters:
      itemList - layer to add this item to
      location - world-coordinate center of the text box
      font - font to use
      text - text to display
      lineColor - border color
      fillColor - background color
      textColor - text foreground color
  • Method Details

    • drawItem

      public void drawItem(Graphics2D g2, IContainer container)
      Description copied from class: PathBasedItem
      Custom drawer for the item.
      Overrides:
      drawItem in class PathBasedItem
      Parameters:
      g2 - the graphics context.
      container - the graphical container being rendered.
    • modify

      public void modify()
      Override ROTATE so the bounding-box path is rebuilt via a screen-space rotation rather than a world-space affine rotation.

      DRAG and RESIZE fall through to PathBasedItem.modify().

      Overrides:
      modify in class PathBasedItem
    • getRotatedPoints

      public Point2D.Double[] getRotatedPoints(double azimuthDegrees)
      Four rotated world corners, using the natural text/font bounds.
      Parameters:
      azimuthDegrees - screen-space CW angle in degrees
    • edit

      public void edit()
      Open the text-edit dialog and rebuild the path at the current azimuth.
    • getAlignment

      public int getAlignment()
    • setAlignment

      public void setAlignment(int align)
    • getFont

      public Font getFont()
      Description copied from interface: ITextEditable
      Returns the current display font.
      Specified by:
      getFont in interface ITextEditable
      Returns:
      the current font
    • setFont

      public void setFont(Font font)
      Description copied from interface: ITextEditable
      Sets the display font.
      Specified by:
      setFont in interface ITextEditable
      Parameters:
      font - the new font, or null to fall back to the default font
    • getText

      public String getText()
      Description copied from interface: ITextEditable
      Returns the current text content.

      Multi-line text is represented with embedded '\n' characters. Implementations must never return null; an empty string is the correct representation of no content.

      Specified by:
      getText in interface ITextEditable
      Returns:
      the current text, with lines joined by '\n'
    • setText

      public void setText(String text)
      Sets the displayed text, replacing any prior content.

      LaTeX-like escapes are first rewritten to their Unicode equivalents via UnicodeUtils.specialCharReplace(String), then the result is split into display lines on line terminators (via String.lines()).

      Specified by:
      setText in interface ITextEditable
      Parameters:
      text - the new text; must not be null
      Throws:
      NullPointerException - if text is null