Package edu.cnu.mdi.item
Class PathBasedItem
java.lang.Object
edu.cnu.mdi.item.AItem
edu.cnu.mdi.item.PathBasedItem
- All Implemented Interfaces:
IFeedbackProvider,IDrawable,EventListener
- Direct Known Subclasses:
PolygonItem,PolylineItem
Base class for items whose geometry is a
Path2D.Double in world
coordinates, stored in AItem._path.
Implements AItem.modify() for all three
ItemModification.ModificationType kinds:
DRAG— translates the path (and the item's focus, if any) by the world-coordinate delta between the modification's start and current mouse points.ROTATE— rotates the path about the modification's anchor point by the signed angle between the start and current mouse points (seethreePointAngle(java.awt.Point, java.awt.Point, java.awt.Point)), and updates the item's azimuth.RESIZE— delegates toscale()whenshift/controlis held or the item'sResizePolicyisSCALEONLY; otherwise delegates toreshape(), which subclasses may override to keep a type-specific shape (e.g. a rectangle item resizing without shearing into a general quadrilateral). The defaultreshape()just callsscale().
Concrete subclasses are expected to build _path in their own
constructors/setters and typically only need to override
reshape() (and occasionally getBounds(edu.cnu.mdi.container.IContainer)) to specialize
resize behavior; drawItem(java.awt.Graphics2D, edu.cnu.mdi.container.IContainer), contains(edu.cnu.mdi.container.IContainer, java.awt.Point), modify(),
and rotate(double) are already implemented generically in terms
of _path.
-
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
ConstructorsConstructorDescriptionPathBasedItem(Layer layer) Create an object that is based on a java Path2D object.PathBasedItem(Layer layer, Object... keyVals) Create an object that is based on a java Path2D object. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(IContainer container, Point screenPoint) Check whether the (rendered) item contains the given screen point.voiddrawItem(Graphics2D g2, IContainer container) Custom drawer for the item.getBounds(IContainer container) get the bounding rect.getRotatePoint(IContainer container) Get the rotation pointGet the world bounding rectangle of the item.voidmodify()A modification such as a drag, resize or rotate is continuing.protected voidreshape()Reshape the items based on the modification.voidrotate(double angle) Rotate the itemprotected voidscale()Simple scaling of the object.booleanshouldDraw(Graphics2D g2, IContainer container) Checks whether the item should be drawn.protected RectanglesinglePointBounds(IContainer container) Get the bounds if the path contains only a single pointprotected doublethreePointAngle(Point p1, Point vertex, Point p2) Give two points (presumably the start and current mouse positions) and a vertex (presumable the focus as a pixel point) this computes and angle.voidtranslateWorld(double dx, double dy) Translate this item by(dx, dy)in world coordinates.protected voidHook called when geometry changes and the focus should be recomputed.Methods 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
-
PathBasedItem
Create an object that is based on a java Path2D object.- Parameters:
layer- the z layer this item is on.
-
PathBasedItem
Create an object that is based on a java Path2D object.- Parameters:
layer- the z layer this item is on.keyVals- optional key value pairs to set properties of the item. SeeAItem(Layer, Object...)for details.
-
-
Method Details
-
drawItem
Custom drawer for the item. -
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.- Specified by:
shouldDrawin classAItem- Parameters:
g2- the graphics context.container- the graphical container being rendered.- Returns:
trueif the item passes any and all tests, and should be drawn.
-
contains
Check whether the (rendered) item contains the given screen point. -
getBounds
get the bounding rect. -
getRotatePoint
Get the rotation point- Overrides:
getRotatePointin classAItem- Parameters:
container- the container bing rendered- Returns:
- the rotation point where rotations are initiated
-
modify
public void modify()A modification such as a drag, resize or rotate is continuing. -
rotate
public void rotate(double angle) Rotate the item- Parameters:
angle- the angle in degrees
-
scale
protected void scale()Simple scaling of the object. -
reshape
protected void reshape()Reshape the items based on the modification. This is type dependent-- for example a rectangle will want to keep looking like a rectangle. The default implementation is to scale -
updateFocus
protected void updateFocus()Description copied from class:AItemHook called when geometry changes and the focus should be recomputed. The default implementation is a no-op.- Overrides:
updateFocusin classAItem
-
threePointAngle
Give two points (presumably the start and current mouse positions) and a vertex (presumable the focus as a pixel point) this computes and angle. Give the assumptions above, it is how much the original path will need to be rotated.- Parameters:
p1- one end pointvertex- the vertex pointp2- the other end point- Returns:
- the angle in degrees.
-
getWorldBounds
Get the world bounding rectangle of the item.- Specified by:
getWorldBoundsin classAItem- Returns:
- the world box containing the item.
-
singlePointBounds
Get the bounds if the path contains only a single point- Parameters:
container- the container being rendered.- Returns:
- the bounds if the path contains only a single point
-
translateWorld
public void translateWorld(double dx, double dy) Description copied from class:AItemTranslate this item by(dx, dy)in world coordinates.- Specified by:
translateWorldin classAItem- Parameters:
dx- the world-coordinate offset along the X axisdy- the world-coordinate offset along the Y axis
-