JHotDraw 6.0b1

org.jhotdraw.contrib
Class GraphicalCompositeFigure

java.lang.Object
  extended by org.jhotdraw.standard.AbstractFigure
      extended by org.jhotdraw.standard.CompositeFigure
          extended by org.jhotdraw.contrib.GraphicalCompositeFigure
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.EventListener, Layoutable, Figure, FigureChangeListener, Storable

public class GraphicalCompositeFigure
extends CompositeFigure
implements Layoutable

The GraphicalCompositeFigure fills in the gap between a CompositeFigure and other figures which mainly have a presentation purpose. The GraphicalCompositeFigure can be configured with any Figure which takes over the task for rendering the graphical presentation for a CompositeFigure. Therefore, the GraphicalCompositeFigure manages contained figures like the CompositeFigure does, but delegates its graphical presentation to another (graphical) figure which purpose it is to draw the container for all contained figures. The GraphicalCompositeFigure adds to the CompositeFigure by containing a presentation figure by default which can not be removed. Normally, the CompositeFigure can not be seen without containing a figure because it has no mechanism to draw itself. It instead relies on its contained figures to draw themselves thereby giving the CompositeFigure its appearance. However, the GraphicalCompositeFigure's presentation figure can draw itself even when the GraphicalCompositeFigure contains no other figures. The GraphicalCompositeFigure also uses a Layouter or layout its contained figures.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jhotdraw.standard.CompositeFigure
_nHighestZ, _nLowestZ, fFigures
 
Constructor Summary
GraphicalCompositeFigure()
          Default constructor which uses a RectangleFigure as presentation figure.
GraphicalCompositeFigure(Figure newPresentationFigure)
          Constructor which creates a GraphicalCompositeFigure with a given graphical figure for presenting it.
 
Method Summary
 void basicDisplayBox(java.awt.Point origin, java.awt.Point corner)
          Standard presentation method which is delegated to the encapsulated presentation figure.
protected  void basicMoveBy(int dx, int dy)
          Standard presentation method which is delegated to the encapsulated presentation figure.
protected  void change()
          Notify the registered change listener if an exlicit change to the component (or one of its child components has occurred).
 java.lang.Object clone()
          Clones a figure and initializes it
 java.awt.Rectangle displayBox()
          Return the display area.
 void draw(java.awt.Graphics g)
          Draw the figure.
 void figureRequestRemove(FigureChangeEvent e)
          Propagates the removeFromDrawing request up to the container.
 java.lang.Object getAttribute(FigureAttributeConstant attributeConstant)
          Delegate capabilities for storing and retrieving attributes to a CompositeFigure if the encapsulated presentation figure.
 java.lang.Object getAttribute(java.lang.String name)
          Deprecated. use getAttribute(FigureAttributeConstant) instead
 Layouter getLayouter()
          Get a Layouter object which encapsulated a layout algorithm for this figure.
 Figure getPresentationFigure()
          Get a figure which renders this CompositeFigure.
 HandleEnumeration handles()
          Return default handles from the presentation figure.
protected  void initialize()
          This method performs additional initialization operations, in this case setting the Layouter.
 void layout()
          A layout algorithm is used to define how the child components should be laid out in relation to each other.
 void read(StorableInput dr)
          Reads the contained figures from StorableInput.
 void setAttribute(FigureAttributeConstant attributeConstant, java.lang.Object value)
          Delegate capabilities for storing and retrieving attributes to a CompositeFigure if the encapsulated presentation figure.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Deprecated. use setAttribute(FigureAttributeConstant, Object) instead
 void setLayouter(Layouter newLayouter)
          Set a Layouter object which encapsulated a layout algorithm for this figure.
 void setPresentationFigure(Figure newPresentationFigure)
          Set a figure which renders this CompositeFigure.
 void update()
          Explicit update: an updated involves a layout for all contained figures.
 void write(StorableOutput dw)
          Writes the contained figures to the StorableOutput.
 
Methods inherited from class org.jhotdraw.standard.CompositeFigure
add, addAll, addAll, bringToFront, containsFigure, draw, figureAt, figureChanged, figureCount, figureInvalidated, figureRemoved, figureRequestUpdate, figures, figures, figuresReverse, findFigure, findFigure, findFigure, findFigureInside, findFigureInsideWithout, findFigureWithout, getFigureFromLayer, getLayer, includes, init, orphan, orphanAll, orphanAll, release, remove, removeAll, removeAll, removeAll, replace, sendToBack, sendToLayer
 
Methods inherited from class org.jhotdraw.standard.AbstractFigure
addDependendFigure, addFigureChangeListener, addToContainer, canConnect, center, changed, connectedTextLocator, connectionInsets, connectorAt, connectorVisibility, containsPoint, decompose, displayBox, displayBox, getDecoratedFigure, getDependendFigures, getTextHolder, getZValue, invalidate, invalidateRectangle, isEmpty, listener, moveBy, removeDependendFigure, removeFigureChangeListener, removeFromContainer, setZValue, size, visit, willChange
 
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
addDependendFigure, addFigureChangeListener, addToContainer, canConnect, center, changed, connectedTextLocator, connectionInsets, connectorAt, connectorVisibility, containsPoint, decompose, displayBox, displayBox, figures, findFigureInside, getDecoratedFigure, getDependendFigures, getTextHolder, getZValue, includes, invalidate, isEmpty, listener, moveBy, release, removeDependendFigure, removeFigureChangeListener, removeFromContainer, setZValue, size, visit, willChange
 

Constructor Detail

GraphicalCompositeFigure

public GraphicalCompositeFigure()
Default constructor which uses a RectangleFigure as presentation figure. This constructor is needed by the Storable mechanism.


GraphicalCompositeFigure

public GraphicalCompositeFigure(Figure newPresentationFigure)
Constructor which creates a GraphicalCompositeFigure with a given graphical figure for presenting it.

Parameters:
newPresentationFigure - figure which renders the container
Method Detail

initialize

protected void initialize()
This method performs additional initialization operations, in this case setting the Layouter. It is called from the constructors and the clone() method. A StandardLayouter is set.


clone

public java.lang.Object clone()
Clones a figure and initializes it

Specified by:
clone in interface Figure
Overrides:
clone in class AbstractFigure
See Also:
Figure.clone()

displayBox

public java.awt.Rectangle displayBox()
Return the display area. This method is delegated to the encapsulated presentation figure.

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

basicDisplayBox

public void basicDisplayBox(java.awt.Point origin,
                            java.awt.Point corner)
Standard presentation method which is delegated to the encapsulated presentation figure.

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

basicMoveBy

protected void basicMoveBy(int dx,
                           int dy)
Standard presentation method which is delegated to the encapsulated presentation figure. The presentation figure is moved as well as all contained figures.

Overrides:
basicMoveBy in class CompositeFigure
See Also:
AbstractFigure.moveBy(int, int)

update

public void update()
Explicit update: an updated involves a layout for all contained figures.


draw

public void draw(java.awt.Graphics g)
Draw the figure. This method is delegated to the encapsulated presentation figure.

Specified by:
draw in interface Figure
Overrides:
draw in class CompositeFigure
Parameters:
g - the Graphics to draw into
See Also:
Figure.draw(java.awt.Graphics)

handles

public HandleEnumeration handles()
Return default handles from the presentation figure.

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

getAttribute

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

Delegate capabilities for storing and retrieving attributes to a CompositeFigure if the encapsulated presentation figure. If no presentation figure is found then the superclass' getAttribute() will be invoked (which currently returns always "null").

Specified by:
getAttribute in interface Figure
Overrides:
getAttribute in class AbstractFigure
Parameters:
name - name of the attribute whose value should be returned
Returns:
value of the attribute with the given name

getAttribute

public java.lang.Object getAttribute(FigureAttributeConstant attributeConstant)
Delegate capabilities for storing and retrieving attributes to a CompositeFigure if the encapsulated presentation figure. If no presentation figure is found then the superclass' getAttribute() will be invoked (which currently returns always "null").

Specified by:
getAttribute in interface Figure
Overrides:
getAttribute in class AbstractFigure
Parameters:
attributeConstant - attribute constant whose value should be returned
Returns:
value of the attribute with the given name

setAttribute

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

Delegate capabilities for storing and retrieving attributes to a CompositeFigure if the encapsulated presentation figure. If no presentation figure is found then the superclass' setAttribute() will be invoked (which currently does not set an attribute).

Specified by:
setAttribute in interface Figure
Overrides:
setAttribute in class AbstractFigure
Parameters:
name - name of the attribute
value - value associated with this attribute

setAttribute

public void setAttribute(FigureAttributeConstant attributeConstant,
                         java.lang.Object value)
Delegate capabilities for storing and retrieving attributes to a CompositeFigure if the encapsulated presentation figure. If no presentation figure is found then the superclass' setAttribute() will be invoked (which currently does not set an attribute).

Specified by:
setAttribute in interface Figure
Overrides:
setAttribute in class AbstractFigure
Parameters:
attributeConstant - attribute constant
value - value associated with this attribute

setPresentationFigure

public void setPresentationFigure(Figure newPresentationFigure)
Set a figure which renders this CompositeFigure. The presentation tasks for the CompositeFigure are delegated to this presentation figure.

Parameters:
newPresentationFigure - figure takes over the presentation tasks

getPresentationFigure

public Figure getPresentationFigure()
Get a figure which renders this CompositeFigure. The presentation tasks for the CompositeFigure are delegated to this presentation figure.

Returns:
figure takes over the presentation tasks

layout

public void layout()
A layout algorithm is used to define how the child components should be laid out in relation to each other. The task for layouting the child components for presentation is delegated to a Layouter which can be plugged in at runtime.

Specified by:
layout in interface Layoutable

setLayouter

public void setLayouter(Layouter newLayouter)
Set a Layouter object which encapsulated a layout algorithm for this figure. Typically, a Layouter accesses the child components of this figure and arranges their graphical presentation. It is a good idea to set the Layouter in the protected initialize() method so it can be recreated if a GraphicalCompositeFigure is read and restored from a StorableInput stream.

Specified by:
setLayouter in interface Layoutable
Parameters:
newLayouter - encapsulation of a layout algorithm.

getLayouter

public Layouter getLayouter()
Get a Layouter object which encapsulated a layout algorithm for this figure. Typically, a Layouter accesses the child components of this figure and arranges their graphical presentation.

Specified by:
getLayouter in interface Layoutable
Returns:
layout strategy used by this figure

change

protected void change()
Notify the registered change listener if an exlicit change to the component (or one of its child components has occurred).


figureRequestRemove

public void figureRequestRemove(FigureChangeEvent e)
Propagates the removeFromDrawing request up to the container.

Specified by:
figureRequestRemove in interface FigureChangeListener
Overrides:
figureRequestRemove in class CompositeFigure
See Also:
FigureChangeListener

read

public void read(StorableInput dr)
          throws java.io.IOException
Reads the contained figures from StorableInput. The figure responsible for graphical presentation is read together with all child components. The Layouter is not stored and therefore not read.

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

write

public void write(StorableOutput dw)
Writes the contained figures to the StorableOutput. The figure responsible for graphical presentation is written together with all child components. The Layouter is not written.

Specified by:
write in interface Storable
Overrides:
write in class CompositeFigure

JHotDraw 6.0b1