Class ConnectorItem
- All Implemented Interfaces:
IFeedbackProvider,IDrawable,EventListener
Geometry model
- Vertex 0 — anchored to
startItem. - Vertex 1 — elbow (user-draggable).
- Vertex 2 — anchored to
endItem.
Endpoints are recomputed from the connected items each time the connector's geometry needs to be validated, so the connection follows its endpoints when nodes move. The elbow vertex is preserved across anchor sync operations.
Anchor synchronisation
The connector compares the current endpoint world positions against the
last-known anchor positions (lastStart and lastEnd) before
redrawing. Synchronisation is skipped when the anchors have not moved,
preventing the connector from being perpetually marked dirty on every frame.
-
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
ConstructorsConstructorDescriptionConnectorItem(Layer layer, AItem startItem, AItem endItem) Create a connector with a single elbow between two items. -
Method Summary
Modifier and TypeMethodDescriptionvoiddrawItem(Graphics2D g2, IContainer container) Custom drawer for the item.Return the item this connector terminates at.Return the item this connector originates from.Get the world bounding rectangle of the item.voidmodify()A modification such as a drag, resize or rotate is continuing.booleanshouldDraw(Graphics2D g2, IContainer container) Checks whether the item should be drawn.Methods inherited from class edu.cnu.mdi.item.PolylineItem
reshapeMethods inherited from class edu.cnu.mdi.item.PathBasedItem
contains, getBounds, getRotatePoint, rotate, scale, 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, translateLocal
-
Constructor Details
-
ConnectorItem
Create a connector with a single elbow between two items.The initial geometry is an L-shape: start anchor → elbow at
(startAnchor.x, endAnchor.y)→ end anchor.- Parameters:
layer- the layer to add the connector to; recommended to use a connection layer drawn below node layersstartItem- the item the connector originates from; must not benullendItem- the item the connector terminates at; must not benull- Throws:
NullPointerException- if either item argument isnull
-
-
Method Details
-
shouldDraw
Checks whether the item should be drawn. This is an additional check, beyond the simple visibility flag check. For example, it might check whether the item intersects the area being drawn.Recomputes endpoint anchors before drawing if either endpoint item has moved since the last draw. Only performs the sync (and marks the item dirty) when a change is detected, avoiding a perpetual dirty-every-frame cycle.
- Overrides:
shouldDrawin classPathBasedItem- Parameters:
g2- the graphics context.container- the graphical container being rendered.- Returns:
trueif the item passes any and all tests, and should be drawn.
-
drawItem
Custom drawer for the item.Syncs anchors if needed, then delegates to
PolylineItem.- Overrides:
drawItemin classPolylineItem- Parameters:
g2- the graphics context.container- the graphical container being rendered.
-
modify
public void modify()A modification such as a drag, resize or rotate is continuing.Lets
PolylineItemreshape the elbow vertex, then forces endpoints back onto their anchored items so the connection cannot be accidentally detached by dragging a handle.- Overrides:
modifyin classPathBasedItem
-
getWorldBounds
Get the world bounding rectangle of the item.Ensures anchors are current before bounds queries are used for picking and visibility tests.
- Overrides:
getWorldBoundsin classPathBasedItem- Returns:
- the world box containing the item.
-
getStartItem
Return the item this connector originates from.- Returns:
- the start item; never
null
-
getEndItem
Return the item this connector terminates at.- Returns:
- the end item; never
null
-