JHotDraw 7.0.6

org.jhotdraw.draw
Class AbstractFigure

java.lang.Object
  extended by org.jhotdraw.draw.AbstractFigure
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Figure, DOMStorable
Direct Known Subclasses:
AbstractCompositeFigure, AttributedFigure

public abstract class AbstractFigure
extends java.lang.Object
implements Figure

AbstractFigure provides the functionality for managing listeners for a Figure.

See Also:
Serialized Form

Field Summary
protected  int changingDepth
          We increase this number on each invocation of willChange() and decrease it on each invocation of changed().
protected  Figure decorator
           
protected  javax.swing.event.EventListenerList listenerList
           
 
Constructor Summary
AbstractFigure()
          Creates a new instance.
 
Method Summary
 void addFigureListener(FigureListener l)
          Adds a listener for FigureEvent's.
 void addNotify(Drawing d)
          Informs a figure, that it has been added to the specified drawing.
 void addUndoableEditListener(javax.swing.event.UndoableEditListener l)
          Adds a listener for UndoableEdit events.
 AbstractFigure basicClone(java.util.HashMap<Figure,Figure> oldToNew)
           
abstract  void basicTransform(java.awt.geom.AffineTransform ty)
          Moves the figure.
 boolean canConnect()
          Checks if this figure can be connected.
 void changed()
          Informs that a figure changed the area of its display box.
 AbstractFigure clone()
          Returns a clone of 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 and its decorator figure.
protected  void drawDecorator(java.awt.Graphics2D g)
           
protected abstract  void drawFigure(java.awt.Graphics2D g)
           
 Connector findCompatibleConnector(Connector c, boolean isStart)
          Gets a compatible connector.
 Connector findConnector(java.awt.geom.Point2D.Double p, ConnectionFigure prototype)
          Returns the Figures connector for the specified location.
 Figure findFigureInside(java.awt.geom.Point2D.Double p)
          Returns the figure that contains the given point.
 void fireAreaInvalidated()
          Notify all listenerList that have registered interest for notification on this event type.
protected  void fireAreaInvalidated(java.awt.geom.Rectangle2D.Double invalidatedArea)
          Notify all listenerList that have registered interest for notification on this event type.
protected  void fireAttributeChanged(AttributeKey attribute, java.lang.Object oldValue, java.lang.Object newValue)
          Notify all listenerList that have registered interest for notification on this event type.
protected  void fireFigureAdded()
          Notify all listenerList that have registered interest for notification on this event type.
 void fireFigureChanged()
           
protected  void fireFigureChanged(FigureEvent event)
           
protected  void fireFigureChanged(java.awt.geom.Rectangle2D.Double changedArea)
          Notify all listenerList that have registered interest for notification on this event type.
protected  void fireFigureRemoved()
          Notify all listenerList that have registered interest for notification on this event type.
protected  void fireFigureRequestRemove()
          Notify all listenerList that have registered interest for notification on this event type.
protected  void fireUndoableEditHappened(javax.swing.undo.UndoableEdit edit)
          Notify all listenerList that have registered interest for notification on this event type.
 java.util.Collection<javax.swing.Action> getActions(java.awt.geom.Point2D.Double p)
          Returns a collection of actions which are presented to the user in a popup menu.
protected  int getChangingDepth()
           
protected  ConnectionFigure getCourtingConnection()
           
 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.
 Figure getDecorator()
          Gets the decorator figure.
 java.awt.geom.Rectangle2D.Double getDrawBounds()
          Returns the drawing bounding box of the figure and of its decorator figure.
protected  Drawing getDrawing()
           
 java.awt.geom.Point2D.Double getEndPoint()
          Returns the end point of the bounds.
protected abstract  java.awt.geom.Rectangle2D.Double getFigureDrawBounds()
           
protected  java.awt.font.FontRenderContext getFontRenderContext()
           
 int getLayer()
          Gets the layer of the figure.
protected  java.lang.Object getLock()
           
 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 start point of the bounds.
 Tool getTool(java.awt.geom.Point2D.Double p)
          Returns a specialized tool for the given coordinate.
 java.lang.String getTooltip(java.awt.geom.Point2D.Double p)
          Returns a tooltip for the specified location.
 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.
 void invalidate()
          Informs that a figure needs to be redrawn.
protected  boolean isChanging()
           
 boolean isConnectorsVisible()
          Returns true, if this figure draws its connectors.
 boolean isDrawDecoratorFirst()
           
 boolean isInteractive()
          Returns true, if the user can manipulate this figure.
 boolean isVisible()
          A Figure is only drawn by a Drawing and by CompositeFigure, if it is visible.
 void remap(java.util.HashMap<Figure,Figure> oldToNew)
           
 void remap(java.util.Map oldToNew)
          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 the specified drawing.
 void removeUndoableEditListener(javax.swing.event.UndoableEditListener l)
          Removes a listener for UndoableEdit events.
 void requestRemove()
          Fires a FigureListener.figureRequestRemove event.
 void setBounds(java.awt.geom.Point2D.Double anchor, java.awt.geom.Point2D.Double lead)
           
 void setBounds(java.awt.geom.Rectangle2D.Double bounds)
           
 void setConnectorsVisible(boolean isVisible, ConnectionFigure connection)
          Sets whether the connectors should be visible for the specified courting connector.
 void setDecorator(Figure newValue)
          Sets a decorator figure.
 void setDrawDecoratorFirst(boolean newValue)
           
 void setInteractive(boolean b)
           
 void setVisible(boolean newValue)
          Changes the visible state of the Figure.
 java.lang.String toString()
           
 void transform(java.awt.geom.AffineTransform tx)
          Transforms the geometry of the figure.
protected  void updateDecoratorBounds()
           
protected  void validate()
           
 void willChange()
          Informs that a figure is about to change something that affects the contents of its display box.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jhotdraw.draw.Figure
basicSetAttribute, basicSetBounds, contains, getAttribute, getAttributes, getBounds, getRestoreData, restoreTo, setAttribute
 
Methods inherited from interface org.jhotdraw.xml.DOMStorable
read, write
 

Field Detail

listenerList

protected javax.swing.event.EventListenerList listenerList

decorator

protected Figure decorator

changingDepth

protected int changingDepth
We increase this number on each invocation of willChange() and decrease it on each invocation of changed().

Constructor Detail

AbstractFigure

public AbstractFigure()
Creates a new instance.

Method Detail

addFigureListener

public void addFigureListener(FigureListener l)
Description copied from interface: Figure
Adds a listener for FigureEvent's.

Specified by:
addFigureListener in interface Figure

removeFigureListener

public void removeFigureListener(FigureListener l)
Description copied from interface: Figure
Removes a listener for FigureEvent's.

Specified by:
removeFigureListener in interface Figure

addUndoableEditListener

public void addUndoableEditListener(javax.swing.event.UndoableEditListener l)
Description copied from interface: Figure
Adds a listener for UndoableEdit events.

Specified by:
addUndoableEditListener in interface Figure

removeUndoableEditListener

public void removeUndoableEditListener(javax.swing.event.UndoableEditListener l)
Description copied from interface: Figure
Removes a listener for UndoableEdit events.

Specified by:
removeUndoableEditListener in interface Figure

addNotify

public void addNotify(Drawing d)
Description copied from interface: Figure
Informs a figure, that it has been added to the specified drawing. The figure must inform all FigureListeners that it has been added.

Specified by:
addNotify in interface Figure

removeNotify

public void removeNotify(Drawing d)
Description copied from interface: Figure
Informs a figure, that it has been removed from the specified drawing. The figure must inform all FigureListeners that it has been removed.

Specified by:
removeNotify in interface Figure

getDrawing

protected Drawing getDrawing()

getLock

protected java.lang.Object getLock()

setDrawDecoratorFirst

public void setDrawDecoratorFirst(boolean newValue)

isDrawDecoratorFirst

public boolean isDrawDecoratorFirst()

fireAreaInvalidated

public void fireAreaInvalidated()
Notify all listenerList that have registered interest for notification on this event type.


fireAreaInvalidated

protected void fireAreaInvalidated(java.awt.geom.Rectangle2D.Double invalidatedArea)
Notify all listenerList that have registered interest for notification on this event type.


fireFigureRequestRemove

protected void fireFigureRequestRemove()
Notify all listenerList that have registered interest for notification on this event type.


fireFigureAdded

protected void fireFigureAdded()
Notify all listenerList that have registered interest for notification on this event type.


fireFigureRemoved

protected void fireFigureRemoved()
Notify all listenerList that have registered interest for notification on this event type.


fireFigureChanged

public void fireFigureChanged()

fireFigureChanged

protected void fireFigureChanged(java.awt.geom.Rectangle2D.Double changedArea)
Notify all listenerList that have registered interest for notification on this event type.


fireFigureChanged

protected void fireFigureChanged(FigureEvent event)

fireAttributeChanged

protected void fireAttributeChanged(AttributeKey attribute,
                                    java.lang.Object oldValue,
                                    java.lang.Object newValue)
Notify all listenerList that have registered interest for notification on this event type.


fireUndoableEditHappened

protected void fireUndoableEditHappened(javax.swing.undo.UndoableEdit edit)
Notify all listenerList that have registered interest for notification on this event type.


clone

public AbstractFigure clone()
Description copied from interface: Figure
Returns a clone of the figure.

Specified by:
clone in interface Figure
Overrides:
clone in class java.lang.Object

basicClone

public final AbstractFigure basicClone(java.util.HashMap<Figure,Figure> oldToNew)

remap

public void remap(java.util.HashMap<Figure,Figure> oldToNew)

createHandles

public java.util.Collection<Handle> createHandles(int detailLevel)
Description copied from interface: Figure
Creates handles used to manipulate the figure.

Specified by:
createHandles in interface Figure
Parameters:
detailLevel - The detail level of the handles. Usually this is 0 for bounding box handles and 1 for point handles.
Returns:
a Collection of handles
See Also:
Handle

getCursor

public java.awt.Cursor getCursor(java.awt.geom.Point2D.Double p)
Description copied from interface: Figure
Returns a cursor for the specified location.

Specified by:
getCursor in interface Figure

setBounds

public final void setBounds(java.awt.geom.Rectangle2D.Double bounds)

setBounds

public void setBounds(java.awt.geom.Point2D.Double anchor,
                      java.awt.geom.Point2D.Double lead)

canConnect

public boolean canConnect()
Checks if this figure can be connected. By default AbstractFigures can be connected.

Specified by:
canConnect in interface Figure

invalidate

public void invalidate()
Informs that a figure needs to be redrawn.

Specified by:
invalidate in interface Figure

isChanging

protected boolean isChanging()

getChangingDepth

protected int getChangingDepth()

willChange

public void willChange()
Informs that a figure is about to change something that affects the contents of its display box.

Specified by:
willChange in interface Figure

validate

protected void validate()

changed

public void changed()
Informs that a figure changed the area of its display box.

Specified by:
changed in interface Figure
See Also:
Figure.willChange()

transform

public void transform(java.awt.geom.AffineTransform tx)
Transforms the geometry of the figure.


basicTransform

public abstract void basicTransform(java.awt.geom.AffineTransform ty)
Moves the figure. This is the method that subclasses override.

This is a basic operation for which no events are fired.

Specified by:
basicTransform in interface Figure
Parameters:
ty - The transformation.

findConnector

public Connector findConnector(java.awt.geom.Point2D.Double p,
                               ConnectionFigure prototype)
Returns the Figures connector for the specified location. By default a ChopBoxConnector is returned.

Specified by:
findConnector in interface Figure
Parameters:
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.
See Also:
ChopBoxConnector

includes

public boolean includes(Figure figure)
Description copied from interface: Figure
Checks whether the given figure is contained in this figure. A figure includes itself.

Specified by:
includes in interface Figure

findFigureInside

public Figure findFigureInside(java.awt.geom.Point2D.Double p)
Description copied from interface: Figure
Returns the figure that contains the given point.

Specified by:
findFigureInside in interface Figure

findCompatibleConnector

public Connector findCompatibleConnector(Connector c,
                                         boolean isStart)
Description copied from interface: Figure
Gets a compatible connector. If the provided connector is part of this figure, return the connector. If the provided connector is part of another figure, return a connector with the same semantics for this figure. Return null, if no compatible connector is available.

Specified by:
findCompatibleConnector in interface Figure

getActions

public java.util.Collection<javax.swing.Action> getActions(java.awt.geom.Point2D.Double p)
Returns a collection of actions which are presented to the user in a popup menu.

The collection may contain null entries. These entries are used interpreted as separators in the popup menu.

Specified by:
getActions in interface Figure

getTool

public Tool getTool(java.awt.geom.Point2D.Double p)
Returns a specialized tool for the given coordinate.

Returns null, if no specialized tool is available.

Specified by:
getTool in interface Figure

handleMouseClick

public boolean handleMouseClick(java.awt.geom.Point2D.Double p,
                                java.awt.event.MouseEvent evt,
                                DrawingView view)
Handles a mouse click.

Specified by:
handleMouseClick in interface Figure
Parameters:
p - The location of the mouse event.
evt - The mouse event.
view - The drawing view which is the source of the mouse event.
Returns:
Returns true, if the figure consumed the mouse click.

handleDrop

public boolean handleDrop(java.awt.geom.Point2D.Double p,
                          java.util.Collection<Figure> droppedFigures,
                          DrawingView view)
Description copied from interface: Figure
Handles a drop.

Specified by:
handleDrop in interface Figure
Parameters:
p - The location of the mouse event.
droppedFigures - The dropped figures.
view - The drawing view which is the source of the mouse event.
Returns:
Returns true, if the figures should snap back to the location they were dragged from.

getEndPoint

public java.awt.geom.Point2D.Double getEndPoint()
Description copied from interface: Figure
Returns the end point of the bounds.

Specified by:
getEndPoint in interface Figure
See Also:
Figure.basicSetBounds(java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double)

getStartPoint

public java.awt.geom.Point2D.Double getStartPoint()
Description copied from interface: Figure
Returns the start point of the bounds.

Specified by:
getStartPoint in interface Figure
See Also:
Figure.basicSetBounds(java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double)

getPreferredSize

public Dimension2DDouble getPreferredSize()
Description copied from interface: Figure
The preferred size is used by Layouter to determine the preferred size of a Figure. For most Figure's this is the same as the dimensions returned by getBounds.

Specified by:
getPreferredSize in interface Figure

remap

public void remap(java.util.Map oldToNew)
Description copied from interface: Figure
After cloning a collection of figures, the ConnectionFigures contained in this collection still connect to the original figures instead of to the clones. Using This operation and providing a map, which maps from the original collection of figures to the new collection, connections can be remapped to the new figures.

Specified by:
remap in interface Figure

isInteractive

public boolean isInteractive()
Description copied from interface: Figure
Returns true, if the user can manipulate this figure. If this operation returns false, Tool's should not interact with this figure.

Specified by:
isInteractive in interface Figure

setInteractive

public void setInteractive(boolean b)

isVisible

public boolean isVisible()
Description copied from interface: Figure
A Figure is only drawn by a Drawing and by CompositeFigure, if it is visible. Layouter's should ignore invisible figures too.

Specified by:
isVisible in interface Figure

setVisible

public void setVisible(boolean newValue)
Description copied from interface: Figure
Changes the visible state of the Figure.

The Figure fires FigureListener.figureChanged and UndoableEditListener.undoableEditHappened, if this operation changed its visible state.

Specified by:
setVisible in interface Figure

setConnectorsVisible

public void setConnectorsVisible(boolean isVisible,
                                 ConnectionFigure connection)
Description copied from interface: Figure
Sets whether the connectors should be visible for the specified courting connector. Connectors can be optionally visible.

Specified by:
setConnectorsVisible in interface Figure

isConnectorsVisible

public boolean isConnectorsVisible()
Description copied from interface: Figure
Returns true, if this figure draws its connectors.

Specified by:
isConnectorsVisible in interface Figure

getCourtingConnection

protected ConnectionFigure getCourtingConnection()

getDecomposition

public java.util.Collection<Figure> getDecomposition()
Description copied from interface: Figure
Returns a decompositon of a figure into its parts. A figure is considered as a part of itself.

Specified by:
getDecomposition in interface Figure

getFontRenderContext

protected java.awt.font.FontRenderContext getFontRenderContext()

requestRemove

public void requestRemove()
Description copied from interface: Figure
Fires a FigureListener.figureRequestRemove event.

Specified by:
requestRemove in interface Figure

getLayer

public int getLayer()
Description copied from interface: Figure
Gets the layer of the figure. The layer is used to determine the z-ordering of a figure inside of a drawing. Figures with a higher layer number are drawn after figures with a lower number. The z-order of figures within the same layer is determined by the sequence the figures were added to a drawing. Figures added later to a drawn after figures which have been added before. If a figure changes its layer, it must fire a FigureListener.figureChanged event to its figure listeners. FIXME - Replace int value by a Layer object.

Specified by:
getLayer in interface Figure

getTooltip

public java.lang.String getTooltip(java.awt.geom.Point2D.Double p)
Description copied from interface: Figure
Returns a tooltip for the specified location.

Specified by:
getTooltip in interface Figure

setDecorator

public void setDecorator(Figure newValue)
Description copied from interface: Figure
Sets a decorator figure. Set this to null, if no decorator is desired. The decorator will use the same logical bounds as this figure. It will be drawn when the figure is drawn.

Specified by:
setDecorator in interface Figure

getDecorator

public Figure getDecorator()
Description copied from interface: Figure
Gets the decorator figure.

Specified by:
getDecorator in interface Figure

draw

public final void draw(java.awt.Graphics2D g)
Description copied from interface: Figure
Draws the figure and its decorator figure.

Specified by:
draw in interface Figure
Parameters:
g - The Graphics2D to draw to.

drawFigure

protected abstract void drawFigure(java.awt.Graphics2D g)

drawDecorator

protected void drawDecorator(java.awt.Graphics2D g)

updateDecoratorBounds

protected void updateDecoratorBounds()

getDrawBounds

public final java.awt.geom.Rectangle2D.Double getDrawBounds()
Description copied from interface: Figure
Returns the drawing bounding box of the figure and of its decorator figure. This takes line width, line caps and other decorations into account. Note: getDrawBounds must include the logical bounds of the figure.

Specified by:
getDrawBounds in interface Figure

getFigureDrawBounds

protected abstract java.awt.geom.Rectangle2D.Double getFigureDrawBounds()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

Copyright 1996-2006 © JHotDraw.org