public interface Figure
extends java.lang.Cloneable, java.io.Serializable
Drawing
. A figure
can be only in one drawing at a time.
Figure
provides the following functionality:
Figure
knows its bounds and it can draw itself.AttributeKey
.Connector
s that define how to locate a
connection point on the figure.Handle
s which can interactively
manipulate aspects of the figure.Figure
interface usually also
implements the CompositeFigure
interface.Framework
The following interfaces define the contracts of a framework for structured
drawing editors:
Contract: Drawing
, Figure
, DrawingView
,
DrawingEditor
, Handle
and
Tool
.
Composite
Composite figures can be composed of other figures.
Component: Figure
; Composite: CompositeFigure
.
Framework
Two figures can be connected using a connection figure. The location of
the start or end point of the connection is handled by a connector object
at each connected figure.
Contract: Figure
,
ConnectionFigure
,
Connector
.
Decorator
Decorated figures can be adorned with another figure.
Component: DecoratedFigure
; Decorator: Figure
.
Observer
State changes of figures can be observed by other objects. Specifically
CompositeFigure
observes area invalidations of its child figures. And
DrawingView
observers area invalidations of its drawing object.
Subject: Figure
; Observer:
FigureListener
; Event: FigureEvent
; Concrete Observer:
CompositeFigure
, DrawingView
.
Prototype
The creation tool creates new figures by cloning a prototype figure object.
That's the reason why Figure
extends the Cloneable
interface.
Prototype: Figure
; Client: CreationTool
.
Strategy
The location of the start and end points of a connection figure are determined
by Connector
s which are owned by the connected figures.
Context: Figure
, ConnectionFigure
;
Strategy: Connector
.
Strategy
Locator
encapsulates a strategy for locating a point on a
Figure
.
Strategy: Locator
; Context: Figure
.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CONNECTABLE_PROPERTY
The name of the "connectable" property.
|
static java.lang.String |
REMOVABLE_PROPERTY
The name of the "removable" property.
|
static java.lang.String |
SELECTABLE_PROPERTY
The name of the "selectable" property.
|
static java.lang.String |
TRANSFORMABLE_PROPERTY
The name of the "transformable" property.
|
Modifier and Type | Method and Description |
---|---|
void |
addFigureListener(FigureListener l)
Adds a listener for FigureEvent's.
|
void |
addNotify(Drawing d)
Informs a figure, that it has been added to a drawing.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a
PropertyChangeListener which can optionally be wrapped
into a WeakPropertyChangeListener . |
void |
changed()
Informs that a Figure changed its visual representation and needs to
be redrawn.
|
Figure |
clone()
Returns a clone of the figure, with clones of all aggregated figures,
such as children and decorators.
|
boolean |
contains(java.awt.geom.Point2D.Double p)
Checks if a point is contained by the figure.
|
java.util.Collection<Handle> |
createHandles(int detailLevel)
Creates handles used to manipulate the figure.
|
void |
draw(java.awt.Graphics2D g)
Draws the figure.
|
Connector |
findCompatibleConnector(Connector c,
boolean isStartConnector)
Gets a compatible connector.
|
Connector |
findConnector(java.awt.geom.Point2D.Double p,
ConnectionFigure prototype)
Gets a connector for this figure at the given location.
|
Figure |
findFigureInside(java.awt.geom.Point2D.Double p)
Finds the innermost figure at the specified location.
|
<T> T |
get(AttributeKey<T> key)
Gets an attribute from the Figure.
|
java.util.Collection<javax.swing.Action> |
getActions(java.awt.geom.Point2D.Double p)
Returns a collection of Action's for the specified location on the figure.
|
java.util.Map<AttributeKey,java.lang.Object> |
getAttributes()
Returns a view to all attributes of this figure.
|
java.lang.Object |
getAttributesRestoreData()
Gets data which can be used to restore the attributes of the figure
after a set has been applied to it.
|
java.awt.geom.Rectangle2D.Double |
getBounds()
Returns the untransformed logical bounds of the figure as a Rectangle.
|
java.util.Collection<Connector> |
getConnectors(ConnectionFigure prototype)
Returns all connectors of this Figure for the specified prototype of
a ConnectionFigure.
|
java.awt.Cursor |
getCursor(java.awt.geom.Point2D.Double p)
Returns a cursor for the specified location.
|
java.util.Collection<Figure> |
getDecomposition()
Returns a decompositon of a figure into its parts.
|
java.awt.geom.Rectangle2D.Double |
getDrawingArea()
Returns the drawing area of the figure as a Rectangle.
|
java.awt.geom.Point2D.Double |
getEndPoint()
Returns the untransformed logical end point of the bounds.
|
int |
getLayer()
Gets the layer number of the figure.
|
Dimension2DDouble |
getPreferredSize()
The preferred size is used by Layouter to determine the preferred
size of a Figure.
|
java.awt.geom.Point2D.Double |
getStartPoint()
Returns the untransformed logical start point of the bounds.
|
Tool |
getTool(java.awt.geom.Point2D.Double p)
Returns a specialized tool for the specified location.
|
java.lang.String |
getToolTipText(java.awt.geom.Point2D.Double p)
Returns a tooltip for the specified location on the figure.
|
java.lang.Object |
getTransformRestoreData()
Gets data which can be used to restore the transformation of the figure
without loss of precision, after a transform has been applied to it.
|
boolean |
handleDrop(java.awt.geom.Point2D.Double p,
java.util.Collection<Figure> droppedFigures,
DrawingView view)
Handles a drop.
|
boolean |
handleMouseClick(java.awt.geom.Point2D.Double p,
java.awt.event.MouseEvent evt,
DrawingView view)
Handles a mouse click.
|
boolean |
includes(Figure figure)
Checks whether the given figure is contained in this figure.
|
boolean |
isConnectable()
Returns true if this Figure can be connected to a
ConnectionFigure . |
boolean |
isRemovable()
Returns true, if the user may remove this figure.
|
boolean |
isSelectable()
Returns true, if the user may select this figure.
|
boolean |
isTransformable()
Returns true, if the user may transform this figure.
|
boolean |
isVisible()
A Figure is only drawn by a CompositeFigure, if it is visible.
|
void |
remap(java.util.Map<Figure,Figure> oldToNew,
boolean disconnectIfNotInMap)
After cloning a collection of figures, the ConnectionFigures contained
in this collection still connect to the original figures instead of
to the clones.
|
void |
removeFigureListener(FigureListener l)
Removes a listener for FigureEvent's.
|
void |
removeNotify(Drawing d)
Informs a figure, that it has been removed from a drawing.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a
PropertyChangeListener . |
void |
requestRemove()
Fires a
FigureListener.figureRequestRemove event. |
void |
restoreAttributesTo(java.lang.Object restoreData)
Restores the attributes of the figure to a previously stored state.
|
void |
restoreTransformTo(java.lang.Object restoreData)
Restores the transform of the figure to a previously stored state.
|
<T> void |
set(AttributeKey<T> key,
T value)
Sets an attribute on the figure and calls
attributeChanged
on all registered FigureListener s if the attribute value
has changed. |
void |
setBounds(java.awt.geom.Point2D.Double start,
java.awt.geom.Point2D.Double end)
Sets the logical and untransformed bounds of the figure.
|
void |
transform(java.awt.geom.AffineTransform tx)
Transforms the shape of the Figure.
|
void |
willChange()
Informs that the figure is about to change its visual representation
(for example, its shape, or its color).
|
static final java.lang.String CONNECTABLE_PROPERTY
static final java.lang.String REMOVABLE_PROPERTY
static final java.lang.String SELECTABLE_PROPERTY
static final java.lang.String TRANSFORMABLE_PROPERTY
void draw(java.awt.Graphics2D g)
g
- The Graphics2D to draw to.int getLayer()
FigureListener.figureChanged
event to
its figure listeners.boolean isVisible()
void setBounds(java.awt.geom.Point2D.Double start, java.awt.geom.Point2D.Double end)
This is used by Tool's which create a new Figure and by Tool's which connect a Figure to another Figure.
This is a basic operation which does not fire events. Use the following code sequence, if you need event firing:
figure.willChange(); figure.setBounds(...); figure.changed();
start
- the start point of the boundsend
- the end point of the boundsgetBounds()
java.awt.geom.Point2D.Double getStartPoint()
java.awt.geom.Point2D.Double getEndPoint()
java.awt.geom.Rectangle2D.Double getBounds()
The bounds are used by Handle objects for adjusting the figure and for aligning the figure on a grid.
java.awt.geom.Rectangle2D.Double getDrawingArea()
The drawing area is used to inform DrawingView
about the
area that is needed to draw this figure.
The drawing area needs to be large enough, to take line width, line caps and other decorations into account that exceed the bounds of the Figure.
Dimension2DDouble getPreferredSize()
boolean contains(java.awt.geom.Point2D.Double p)
This is used for hit testing by Tool's.
java.lang.Object getTransformRestoreData()
transform(AffineTransform)
void restoreTransformTo(java.lang.Object restoreData)
void transform(java.awt.geom.AffineTransform tx)
This is a basic operation which does not fire events. Use the following code sequence, if you need event firing:
figure.willChange(); figure.transform(...); figure.changed();
tx
- The transformation.getTransformRestoreData()
,
restoreTransformTo(java.lang.Object)
<T> void set(AttributeKey<T> key, T value)
attributeChanged
on all registered FigureListener
s if the attribute value
has changed.
For efficiency reasons, the drawing is not automatically repainted.
If you want the drawing to be repainted when the attribute is changed,
you can either use key.set(figure, value);
or
figure.willChange(); figure.set(...); figure.changed();
<T> T get(AttributeKey<T> key)
AttributeKey.get(org.jhotdraw.draw.Figure)
java.util.Map<AttributeKey,java.lang.Object> getAttributes()
java.lang.Object getAttributesRestoreData()
void restoreAttributesTo(java.lang.Object restoreData)
boolean isSelectable()
Please note, that even if this method returns false, the Figure may become part of a selection for other reasons. For example, if the Figure is part of a GroupFigure, then the Figure is indirectly part of the selection, when the user selects the GroupFigure.
boolean isRemovable()
Please note, that even if this method returns false, the Figure may be removed from the Drawing for other reasons. For example, if the Figure is used to display a warning message, the Figure can be removed from the Drawing, when the warning message is no longer relevant.
boolean isTransformable()
Please note, that even if this method returns false, the Figure may be transformed for other reasons. For example, if the Figure takes part in an animation.
transform(java.awt.geom.AffineTransform)
java.util.Collection<Handle> createHandles(int detailLevel)
detailLevel
- The detail level of the handles. Usually this is 0 for
bounding box handles and 1 for point handles. The value -1 is used
by the SelectAreaTracker and the HandleTracker to highlight figures, over which the mouse
pointer is hovering.Handle
java.awt.Cursor getCursor(java.awt.geom.Point2D.Double p)
java.util.Collection<javax.swing.Action> getActions(java.awt.geom.Point2D.Double p)
The collection may contain null entries. These entries are used interpreted as separators in the popup menu.
Actions can use the property Figure.ACTION_SUBMENU to specify a submenu.
Tool getTool(java.awt.geom.Point2D.Double p)
Returns null, if no specialized tool is available.
java.lang.String getToolTipText(java.awt.geom.Point2D.Double p)
boolean isConnectable()
ConnectionFigure
.Connector findConnector(java.awt.geom.Point2D.Double p, ConnectionFigure prototype)
p
- the location of the connector.prototype
- The prototype used to create a connection or null if
unknown. This allows for specific connectors for different
connection figures.Connector findCompatibleConnector(Connector c, boolean isStartConnector)
java.util.Collection<Connector> getConnectors(ConnectionFigure prototype)
This is used by connection tools and connection handles to visualize the connectors when the user is about to create a ConnectionFigure to this Figure.
prototype
- The prototype used to create a connection or null if
unknown. This allows for specific connectors for different
connection figures.boolean includes(Figure figure)
Figure findFigureInside(java.awt.geom.Point2D.Double p)
In case of a CompositeFigure
, this method descends into its
children and into its children's children until the innermost figure is
found.
This functionality is implemented using the Chain of Responsibility design pattern. A figure which is not composed of other figures returns itself if the point is contained by the figure. Composed figures pass the method call down to their children.
p
- A location on the drawing.java.util.Collection<Figure> getDecomposition()
Figure clone()
void remap(java.util.Map<Figure,Figure> oldToNew, boolean disconnectIfNotInMap)
void addNotify(Drawing d)
void removeNotify(Drawing d)
void willChange()
Note: willChange
and changed
are typically used
as pairs before and after invoking one or multiple basic-methods on
the Figure.
changed()
void changed()
This fires a FigureListener.figureChanged
event for the current display bounds of the figure.
Note: willChange
and changed
are typically used
as pairs before and after invoking one or multiple basic-methods on
the Figure.
willChange()
void requestRemove()
FigureListener.figureRequestRemove
event.boolean handleDrop(java.awt.geom.Point2D.Double p, java.util.Collection<Figure> droppedFigures, DrawingView view)
p
- The location of the mouse event.droppedFigures
- The dropped figures.view
- The drawing view which is the source of the mouse event.boolean handleMouseClick(java.awt.geom.Point2D.Double p, java.awt.event.MouseEvent evt, DrawingView view)
p
- The location of the mouse event.evt
- The mouse event.view
- The drawing view which is the source of the mouse event.void addFigureListener(FigureListener l)
void removeFigureListener(FigureListener l)
void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
PropertyChangeListener
which can optionally be wrapped
into a WeakPropertyChangeListener
.listener
- void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
PropertyChangeListener
. If the listener was added
wrapped into a WeakPropertyChangeListener
, the
WeakPropertyChangeListener
is removed.listener
-