JHotDraw 6.0b1

org.jhotdraw.standard
Class AbstractFigure

java.lang.Object
  extended by org.jhotdraw.standard.AbstractFigure
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Figure, Storable
Direct Known Subclasses:
AttributeFigure, CompositeFigure, DecoratorFigure, NullFigure, PolyLineFigure

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

AbstractFigure provides default implementations for the Figure interface.


Design Patterns

 o Template Method
Template Methods implement default and invariant behavior for figure subclasses.


See Also:
Figure, Handle, Serialized Form

Constructor Summary
protected AbstractFigure()
           
 
Method Summary
 void addDependendFigure(Figure newDependendFigure)
          Add a dependent figure.
 void addFigureChangeListener(FigureChangeListener l)
          Adds a listener for this figure.
 void addToContainer(FigureChangeListener c)
          Sets the Figure's container and registers the container as a figure change listener.
abstract  void basicDisplayBox(java.awt.Point origin, java.awt.Point corner)
          Sets the display box of a figure.
protected abstract  void basicMoveBy(int dx, int dy)
          Moves the figure.
 boolean canConnect()
          Checks if this figure can be connected.
 java.awt.Point center()
          Gets the center of a figure.
 void changed()
          Informs that a figure changed the area of its display box.
 java.lang.Object clone()
          Clones a figure.
 Locator connectedTextLocator(Figure text)
          Returns the locator used to located connected text.
 java.awt.Insets connectionInsets()
          Returns the connection inset.
 Connector connectorAt(int x, int y)
          Returns the Figures connector for the specified location.
 void connectorVisibility(boolean isVisible, ConnectionFigure connector)
          Sets whether the connectors should be visible.
 boolean containsPoint(int x, int y)
          Checks if a point is inside the figure.
 FigureEnumeration decompose()
          Decomposes a figure into its parts.
abstract  java.awt.Rectangle displayBox()
          Gets the display box of a figure.
 void displayBox(java.awt.Point origin, java.awt.Point corner)
          Changes the display box of a figure.
 void displayBox(java.awt.Rectangle r)
          Changes the display box of a figure.
 FigureEnumeration figures()
          Returns an Enumeration of the figures contained in this figure.
 Figure findFigureInside(int x, int y)
          Returns the figure that contains the given point.
 java.lang.Object getAttribute(FigureAttributeConstant attributeConstant)
          Returns the named attribute or null if a a figure doesn't have an attribute.
 java.lang.Object getAttribute(java.lang.String name)
          Deprecated. use getAttribute(FigureAttributeConstant) instead
 Figure getDecoratedFigure()
          Get the underlying figure in case the figure has been decorated.
 FigureEnumeration getDependendFigures()
          Get an enumeration of all dependent figures.
 TextHolder getTextHolder()
          Some figures have the ability to hold text.
 int getZValue()
          Gets the z value (back-to-front ordering) of this figure.
abstract  HandleEnumeration handles()
          Returns the handles of a Figure that can be used to manipulate some of its attributes.
 boolean includes(Figure figure)
          Checks whether the given figure is contained in this figure.
 void invalidate()
          Invalidates the figure.
protected  java.awt.Rectangle invalidateRectangle(java.awt.Rectangle r)
          Hook method to change the rectangle that will be invalidated
 boolean isEmpty()
          Checks if the figure is empty.
 FigureChangeListener listener()
          Gets the figure's listners.
 void moveBy(int dx, int dy)
          Moves the figure by the given offset.
 void read(StorableInput dr)
          Reads the Figure from a StorableInput.
 void release()
          A figure is released from the drawing.
 void removeDependendFigure(Figure oldDependendFigure)
          Remove a dependent figure.
 void removeFigureChangeListener(FigureChangeListener l)
          Removes a listener for this figure.
 void removeFromContainer(FigureChangeListener c)
          Removes a figure from the given container and unregisters it as a change listener.
 void setAttribute(FigureAttributeConstant attributeConstant, java.lang.Object value)
          Sets the named attribute to the new value.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Deprecated. use setAttribute(FigureAttributeConstant, Object) instead
 void setZValue(int z)
          Sets the z value (back-to-front ordering) of this figure.
 java.awt.Dimension size()
          Gets the size of the figure.
 void visit(FigureVisitor visitor)
           
 void willChange()
          Informes that a figure is about to change something that affects the contents of its display box.
 void write(StorableOutput dw)
          Stores the Figure to a StorableOutput.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jhotdraw.framework.Figure
draw
 

Constructor Detail

AbstractFigure

protected AbstractFigure()
Method Detail

moveBy

public void moveBy(int dx,
                   int dy)
Moves the figure by the given offset.

Specified by:
moveBy in interface Figure
Parameters:
dx - the x delta
dy - the y delta

basicMoveBy

protected abstract void basicMoveBy(int dx,
                                    int dy)
Moves the figure. This is the method that subclassers override. Clients usually call displayBox.

See Also:
moveBy(int, int)

displayBox

public void displayBox(java.awt.Point origin,
                       java.awt.Point corner)
Changes the display box of a figure. Clients usually call this method. It changes the display box and announces the corresponding change.

Specified by:
displayBox in interface Figure
Parameters:
origin - the new origin
corner - the new corner
See Also:
displayBox(java.awt.Point, java.awt.Point)

basicDisplayBox

public abstract void basicDisplayBox(java.awt.Point origin,
                                     java.awt.Point corner)
Sets the display box of a figure. This is the method that subclassers override. Clients usually call displayBox.

Specified by:
basicDisplayBox in interface Figure
Parameters:
origin - the new origin
corner - the new corner
See Also:
displayBox(java.awt.Point, java.awt.Point)

displayBox

public abstract java.awt.Rectangle displayBox()
Gets the display box of a figure.

Specified by:
displayBox in interface Figure
See Also:
Figure.basicDisplayBox(java.awt.Point, java.awt.Point)

handles

public abstract HandleEnumeration handles()
Returns the handles of a Figure that can be used to manipulate some of its attributes.

Specified by:
handles in interface Figure
Returns:
a type-safe iterator of handles
See Also:
Handle

figures

public FigureEnumeration figures()
Returns an Enumeration of the figures contained in this figure.

Specified by:
figures in interface Figure
See Also:
CompositeFigure

size

public java.awt.Dimension size()
Gets the size of the figure. A convenience method.

Specified by:
size in interface Figure

isEmpty

public boolean isEmpty()
Checks if the figure is empty. The default implementation returns true if the width or height of its display box is < 3

Specified by:
isEmpty in interface Figure
See Also:
Figure.isEmpty()

findFigureInside

public Figure findFigureInside(int x,
                               int y)
Returns the figure that contains the given point. In contrast to containsPoint it returns its innermost figure that contains the point.

Specified by:
findFigureInside in interface Figure
See Also:
containsPoint(int, int)

containsPoint

public boolean containsPoint(int x,
                             int y)
Checks if a point is inside the figure.

Specified by:
containsPoint in interface Figure

displayBox

public void displayBox(java.awt.Rectangle r)
Changes the display box of a figure. This is a convenience method. Implementors should only have to override basicDisplayBox

Specified by:
displayBox in interface Figure
See Also:
displayBox(java.awt.Point, java.awt.Point)

includes

public boolean includes(Figure figure)
Checks whether the given figure is contained in this figure.

Specified by:
includes in interface Figure

decompose

public FigureEnumeration decompose()
Decomposes a figure into its parts. It returns a FigureEnumeration that contains itself.

Specified by:
decompose in interface Figure
Returns:
an Enumeration with itself as the only element.

addToContainer

public void addToContainer(FigureChangeListener c)
Sets the Figure's container and registers the container as a figure change listener. A figure's container can be any kind of FigureChangeListener. A figure is not restricted to have a single container.

Specified by:
addToContainer in interface Figure

removeFromContainer

public void removeFromContainer(FigureChangeListener c)
Removes a figure from the given container and unregisters it as a change listener.

Specified by:
removeFromContainer in interface Figure

addFigureChangeListener

public void addFigureChangeListener(FigureChangeListener l)
Adds a listener for this figure.

Specified by:
addFigureChangeListener in interface Figure

removeFigureChangeListener

public void removeFigureChangeListener(FigureChangeListener l)
Removes a listener for this figure.

Specified by:
removeFigureChangeListener in interface Figure

listener

public FigureChangeListener listener()
Gets the figure's listners.

Specified by:
listener in interface Figure

release

public void release()
A figure is released from the drawing. You never call this method directly. Release notifies its listeners.

Specified by:
release in interface Figure
See Also:
Figure.release()

invalidate

public void invalidate()
Invalidates the figure. This method informs the listeners that the figure's current display box is invalid and should be refreshed.

Specified by:
invalidate in interface Figure

invalidateRectangle

protected java.awt.Rectangle invalidateRectangle(java.awt.Rectangle r)
Hook method to change the rectangle that will be invalidated


willChange

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

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

changed

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

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

center

public java.awt.Point center()
Gets the center of a figure. A convenice method that is rarely overridden.

Specified by:
center in interface Figure

canConnect

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

Specified by:
canConnect in interface Figure

connectionInsets

public java.awt.Insets connectionInsets()
Returns the connection inset. The connection inset defines the area where the display box of a figure can't be connected. By default the entire display box can be connected.

Specified by:
connectionInsets in interface Figure

connectorAt

public Connector connectorAt(int x,
                             int y)
Returns the Figures connector for the specified location. By default a ChopBoxConnector is returned.

Specified by:
connectorAt in interface Figure
See Also:
ChopBoxConnector

connectorVisibility

public void connectorVisibility(boolean isVisible,
                                ConnectionFigure connector)
Sets whether the connectors should be visible. By default they are not visible

Specified by:
connectorVisibility in interface Figure

connectedTextLocator

public Locator connectedTextLocator(Figure text)
Returns the locator used to located connected text.

Specified by:
connectedTextLocator in interface Figure

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Deprecated. use getAttribute(FigureAttributeConstant) instead

Returns the named attribute or null if a a figure doesn't have an attribute. By default figures don't have any attributes so getAttribute returns null.

Specified by:
getAttribute in interface Figure

getAttribute

public java.lang.Object getAttribute(FigureAttributeConstant attributeConstant)
Returns the named attribute or null if a a figure doesn't have an attribute. By default figures don't have any attributes getAttribute returns null.

Specified by:
getAttribute in interface Figure

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Deprecated. use setAttribute(FigureAttributeConstant, Object) instead

Sets the named attribute to the new value. By default figures don't have any attributes and the request is ignored.

Specified by:
setAttribute in interface Figure

setAttribute

public void setAttribute(FigureAttributeConstant attributeConstant,
                         java.lang.Object value)
Sets the named attribute to the new value. By default figures don't have any attributes and the request is ignored.

Specified by:
setAttribute in interface Figure

clone

public java.lang.Object clone()
Clones a figure. Creates a clone by using the storable mechanism to flatten the Figure to stream followed by resurrecting it from the same stream.

Specified by:
clone in interface Figure
Overrides:
clone in class java.lang.Object
See Also:
Figure.clone()

write

public void write(StorableOutput dw)
Stores the Figure to a StorableOutput.

Specified by:
write in interface Storable

read

public void read(StorableInput dr)
          throws java.io.IOException
Reads the Figure from a StorableInput.

Specified by:
read in interface Storable
Throws:
java.io.IOException

getZValue

public int getZValue()
Gets the z value (back-to-front ordering) of this figure.

Specified by:
getZValue in interface Figure

setZValue

public void setZValue(int z)
Sets the z value (back-to-front ordering) of this figure.

Specified by:
setZValue in interface Figure

visit

public void visit(FigureVisitor visitor)
Specified by:
visit in interface Figure

getDependendFigures

public FigureEnumeration getDependendFigures()
Description copied from interface: Figure
Get an enumeration of all dependent figures.

Specified by:
getDependendFigures in interface Figure

addDependendFigure

public void addDependendFigure(Figure newDependendFigure)
Description copied from interface: Figure
Add a dependent figure.

Specified by:
addDependendFigure in interface Figure

removeDependendFigure

public void removeDependendFigure(Figure oldDependendFigure)
Description copied from interface: Figure
Remove a dependent figure.

Specified by:
removeDependendFigure in interface Figure

getTextHolder

public TextHolder getTextHolder()
Description copied from interface: Figure
Some figures have the ability to hold text. This method returns the adjunctant TextHolder.

Specified by:
getTextHolder in interface Figure
Returns:

getDecoratedFigure

public Figure getDecoratedFigure()
Description copied from interface: Figure
Get the underlying figure in case the figure has been decorated. If the figure has not been decorated the figure itself is returned. The DecoratorFigure does not release the the decorated figure but just returns it (in contrast to org.jhotdraw.standard.DecoratorFigure.peelDecoration).

Specified by:
getDecoratedFigure in interface Figure
Returns:
underlying, "real" without DecoratorFigure
See Also:
DecoratorFigure

JHotDraw 6.0b1