Package edu.cnu.mdi.item
Class TextItem
java.lang.Object
edu.cnu.mdi.item.AItem
edu.cnu.mdi.item.PathBasedItem
edu.cnu.mdi.item.PolygonItem
edu.cnu.mdi.item.RectangleItem
edu.cnu.mdi.item.TextItem
- All Implemented Interfaces:
IFeedbackProvider,IDrawable,ITextEditable,EventListener
A drawable item that renders text with a rectangular background/border.
Key invariants:
AItem._focusis 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.
-
Field Summary
Fields inherited from class edu.cnu.mdi.item.AItem
_connectable, _deletable, _dirty, _displayName, _doubleClickable, _draggable, _enabled, _focus, _FOCUSFILL, _lastDrawnPolygon, _layer, _line, _locked, _modification, _path, _popupMenu, _resizable, _resizePolicy, _rightClickable, _rotatable, _selectable, _selected, _style, _styleEditable, _visible, rotateIcon, RPSIZE, RPSIZE2, SPSIZE, SPSIZE2 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddrawItem(Graphics2D g2, IContainer container) Custom drawer for the item.voidedit()Open the text-edit dialog and rebuild the path at the current azimuth.intgetFont()Returns the current display font.getRotatedPoints(double azimuthDegrees) Four rotated world corners, using the natural text/font bounds.getText()Returns the current text content.voidmodify()Override ROTATE so the bounding-box path is rebuilt via a screen-space rotation rather than a world-space affine rotation.voidsetAlignment(int align) voidSets the display font.voidSets the displayed text, replacing any prior content.Methods inherited from class edu.cnu.mdi.item.RectangleItem
reshapeMethods inherited from class edu.cnu.mdi.item.PolygonItem
setPathMethods inherited from class edu.cnu.mdi.item.PathBasedItem
contains, getBounds, getRotatePoint, getWorldBounds, rotate, scale, shouldDraw, singlePointBounds, threePointAngle, translateWorld, updateFocusMethods inherited from class edu.cnu.mdi.item.AItem
acceptModification, applyGeometryProperties, applyProperties, applyStyleProperties, createPopupMenu, doubleClicked, draw, drawSelections, enclosed, equals, focusFill, geometryChanged, getAzimuth, getContainer, getDisplayName, getFeedbackStrings, getFocus, getFocusPoint, getItemModification, getLastDrawnPolygon, getLayer, getLine, getPath, getPopupMenu, getResizePolicy, getSelectionPoints, getStyle, getStyleSafe, getView, hashCode, inASelectRect, inRotatePoint, inSelectPoint, isConnectable, isDeletable, isDirty, isDoubleClickable, isDraggable, isEnabled, isLocked, isResizable, isRightClickable, isRotatable, isSelectable, isSelected, isStyleEditable, isTrackable, isVisible, modificationRejected, prepareForPopup, prepareForRemoval, setAzimuth, setConnectable, setDeletable, setDirty, setDisplayName, setDoubleClickable, setDraggable, setEnabled, setFillFocus, setFocus, setLocked, setModification, setResizable, setResizePolicy, setRightClickable, setRotatable, setSelectable, setSelected, setStyle, setStyleEditable, setVisible, startModification, stopModification, translateLocalMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.cnu.mdi.item.ITextEditable
getStyle, setStyle
-
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 tolocation- world-coordinate center of the text boxfont- font to usetext- text to displaylineColor- border colorfillColor- background colortextColor- text foreground color
-
-
Method Details
-
drawItem
Description copied from class:PathBasedItemCustom drawer for the item.- Overrides:
drawItemin classPathBasedItem- 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:
modifyin classPathBasedItem
-
getRotatedPoints
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
Description copied from interface:ITextEditableReturns the current display font.- Specified by:
getFontin interfaceITextEditable- Returns:
- the current font
-
setFont
Description copied from interface:ITextEditableSets the display font.- Specified by:
setFontin interfaceITextEditable- Parameters:
font- the new font, ornullto fall back to the default font
-
getText
Description copied from interface:ITextEditableReturns the current text content.Multi-line text is represented with embedded
'\n'characters. Implementations must never returnnull; an empty string is the correct representation of no content.- Specified by:
getTextin interfaceITextEditable- Returns:
- the current text, with lines joined by
'\n'
-
setText
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 (viaString.lines()).- Specified by:
setTextin interfaceITextEditable- Parameters:
text- the new text; must not benull- Throws:
NullPointerException- iftextisnull
-