Class MapTextItem
- All Implemented Interfaces:
IFeedbackProvider,IDrawable,ITextEditable,EventListener
Distinction from TextItem
TextItem anchors its bounding box to a world-space (projection-space)
point. When the map projection changes or the view recenters, the text box
drifts because the anchor is in a coordinate system that moves relative to the
Earth's surface. MapTextItem stores the anchor as a geographic point;
the anchor is re-projected on every draw so the label stays above the same
geographic feature regardless of the active projection.
Rendering model
The text box is always axis-aligned in screen space. Only the anchor moves
with the projection; the box itself is a screen-space rectangle computed from
font metrics on each draw, exactly as in TextItem. This means rotation
of the text box is not supported (and is meaningless for a geographic label).
Drag
Drag converts both the start and current mouse positions independently to geographic coordinates and moves the anchor by the difference. This is exact at all latitudes (no raw lon/lat approximation).
Resize
Not applicable — the box size is determined by the font and text content.
ResizePolicy.SCALEONLY is set so that shift+drag scales rather than
attempting a shape-preserving reshape.
Rotation
Not supported. Geographic labels are conventionally upright; rotating a text label relative to the map surface has no standard geographic meaning.
Focus
AItem._focus holds the geographic anchor (x = longitude, y = latitude
in radians). AMapItem.getFocusPoint(edu.cnu.mdi.container.IContainer) projects it to device pixels for
the selection indicator. The bounding box is then built screen-space around
that pixel anchor, matching TextItem's screen-space round-trip.
-
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
ConstructorsConstructorDescriptionMapTextItem(Layer layer, Point2D.Double location, Font font, String text, Color lineColor, Color fillColor, Color textColor) Creates a map-native text label. -
Method Summary
Modifier and TypeMethodDescriptionvoiddrawItem(Graphics2D g2, IContainer container) Projects the geographic anchor to device pixels and draws the text box (background fill, border, and text) in screen space around that pixel.voidedit()Opens the text-edit dialog and applies the result.intgetBounds(IContainer container) Returns the screen-space bounding rectangle of the text box.voidgetFeedbackStrings(IContainer container, Point pp, Point2D.Double wp, List<String> feedbackStrings) Populate the feedback string list with information about this item.getFont()Returns the current display font.getText()Returns the full text content as a single string with embedded newlines.Return the world-coordinate bounding rectangle of this item.voidmodify()Update this item's geometry in response to a mouse movement during an active modification.voidsetAlignment(int align) voidsetFocus(Point2D.Double location) Set the world-coordinate focus of this item.voidSets the display font.voidSets the text content, replacing special characters viaUnicodeUtils.specialCharReplace(java.lang.String).booleanshouldDraw(Graphics2D g2, IContainer container) Returntrueif this item should be drawn on the current frame.voidClassify and begin a drag, resize, or rotate modification.voidtranslateWorld(double dx, double dy) Translate this item by(dx, dy)in world coordinates.Methods inherited from class edu.cnu.mdi.mapping.item.AMapItem
getFocusPoint, updateFocusMethods inherited from class edu.cnu.mdi.item.AItem
acceptModification, applyGeometryProperties, applyProperties, applyStyleProperties, contains, createPopupMenu, doubleClicked, draw, drawSelections, enclosed, equals, focusFill, geometryChanged, getAzimuth, getContainer, getDisplayName, getFocus, getItemModification, getLastDrawnPolygon, getLayer, getLine, getPath, getPopupMenu, getResizePolicy, getRotatePoint, 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, setLocked, setModification, setResizable, setResizePolicy, setRightClickable, setRotatable, setSelectable, setSelected, setStyle, setStyleEditable, setVisible, 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
-
MapTextItem
public MapTextItem(Layer layer, Point2D.Double location, Font font, String text, Color lineColor, Color fillColor, Color textColor) Creates a map-native text label.- Parameters:
layer- the layer; must not benulllocation- geographic anchor in radians (x = longitude, y = latitude)font- font to use; ifnullthe default font is usedtext- text to display; must not benullor emptylineColor- border color;nullfor no borderfillColor- background color;nullfor transparent backgroundtextColor- text foreground color;nulldefaults to black
-
-
Method Details
-
drawItem
Projects the geographic anchor to device pixels and draws the text box (background fill, border, and text) in screen space around that pixel.Returns immediately if the anchor is off-map (non-finite projection). No path-based geometry is maintained; the bounding box is rebuilt from font metrics on every draw.
- Specified by:
drawItemin classAItem- Parameters:
g2- the graphics contextcontainer- the rendering container; must be aMapContainer
-
shouldDraw
Returntrueif this item should be drawn on the current frame.This is a secondary visibility check beyond the simple
AItem._visibleflag. A typical implementation checks whether the item's screen bounds intersect the current clip rectangle.Returns
falseif the anchor is unplaced or the bounding rectangle does not intersect the visible component area.- Specified by:
shouldDrawin classAItem- Parameters:
g2- the graphics context (may be used to read clip bounds)container- the container being rendered- Returns:
trueifAItem.drawItem(java.awt.Graphics2D, edu.cnu.mdi.container.IContainer)should be called
-
getBounds
Returns the screen-space bounding rectangle of the text box.Computed from font metrics centred on the projected anchor. Returns
nullif the anchor is off-map. -
getWorldBounds
Return the world-coordinate bounding rectangle of this item.Returns
null— a geographic label has no world-space extent.- Specified by:
getWorldBoundsin classAItem- Returns:
- the world-coordinate bounding rectangle
-
startModification
public void startModification()Classify and begin a drag, resize, or rotate modification.Priority: rotate (if start point is in rotation handle) → resize (if start point is in a selection handle) → drag (otherwise).
This method is a no-op if
AItem._modificationisnull.Records the geographic start anchor and its screen projection for subsequent drag computation.
- Overrides:
startModificationin classAItem
-
modify
public void modify()Update this item's geometry in response to a mouse movement during an active modification.Called repeatedly while the user is dragging, resizing, or rotating. The current mouse position is available through
AItem._modification.DRAG: independently inverse-projects the start and current mouse positions to geographic coordinates and shifts the anchor by the difference. This is exact at all latitudes. RESIZE / ROTATE: silently ignored.
-
translateWorld
public void translateWorld(double dx, double dy) Translate this item by(dx, dy)in world coordinates.Moves the geographic anchor by raw lon/lat offsets. See
MapLineItemfor the high-latitude caveat. A no-op if the anchor is unplaced.- Specified by:
translateWorldin classAItem- Parameters:
dx- the world-coordinate offset along the X axisdy- the world-coordinate offset along the Y axis
-
setFocus
Set the world-coordinate focus of this item.Stores the geographic location directly. NaN coordinates represent an unplaced label.
-
edit
public void edit()Opens the text-edit dialog and applies the result.Rebuilding the path (as
TextItemdoes for rotation) is unnecessary here becauseMapTextItemhas no stored path. -
getFeedbackStrings
public void getFeedbackStrings(IContainer container, Point pp, Point2D.Double wp, List<String> feedbackStrings) Populate the feedback string list with information about this item. The default implementation is a no-op.Reports the text content and geographic anchor when the cursor is over the label.
- Specified by:
getFeedbackStringsin interfaceIFeedbackProvider- Overrides:
getFeedbackStringsin classAItem- Parameters:
container- the container rendering this itempp- the current mouse position in screen coordinateswp- the corresponding world-coordinate positionfeedbackStrings- the list to add strings to
-
getAlignment
public int getAlignment()- Returns:
- the current text alignment
-
setAlignment
public void setAlignment(int align) - Parameters:
align- text alignment constant fromSwingConstants
-
getFont
Description copied from interface:ITextEditableReturns the current display font.- Specified by:
getFontin interfaceITextEditable- Returns:
- the current font
-
setFont
Sets the display font.- Specified by:
setFontin interfaceITextEditable- Parameters:
font- the font to use; ifnullthe default font is restored
-
getText
Returns the full text content as a single string with embedded newlines.- Specified by:
getTextin interfaceITextEditable- Returns:
- the text; never
null
-
setText
Sets the text content, replacing special characters viaUnicodeUtils.specialCharReplace(java.lang.String).- Specified by:
setTextin interfaceITextEditable- Parameters:
text- the new text;nullis treated as an empty string
-