JHotDraw 7.5.1

org.jhotdraw.draw
Class GraphicalCompositeFigure

java.lang.Object
  extended by org.jhotdraw.beans.AbstractBean
      extended by org.jhotdraw.draw.AbstractFigure
          extended by org.jhotdraw.draw.AbstractCompositeFigure
              extended by org.jhotdraw.draw.GraphicalCompositeFigure
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, CompositeFigure, Figure, DOMStorable
Direct Known Subclasses:
ListFigure, TaskFigure

public class GraphicalCompositeFigure
extends AbstractCompositeFigure

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 a 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 to lay out its child figures.

Version:
$Id: GraphicalCompositeFigure.java 647 2010-01-24 22:52:59Z rawcoder $
Author:
Wolfram Kaiser (original code), Werner Randelshofer (this derived version)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jhotdraw.draw.AbstractCompositeFigure
AbstractCompositeFigure.EventHandler
 
Field Summary
protected  java.util.HashMap<AttributeKey,java.lang.Object> attributes
           
 
Fields inherited from class org.jhotdraw.draw.AbstractCompositeFigure
cachedBounds, cachedDrawingArea, children, eventHandler, layouter
 
Fields inherited from class org.jhotdraw.draw.AbstractFigure
changingDepth, listenerList
 
Fields inherited from class org.jhotdraw.beans.AbstractBean
propertySupport
 
Fields inherited from interface org.jhotdraw.draw.CompositeFigure
LAYOUT_INSETS
 
Fields inherited from interface org.jhotdraw.draw.Figure
CONNECTABLE_PROPERTY, REMOVABLE_PROPERTY, SELECTABLE_PROPERTY, TRANSFORMABLE_PROPERTY
 
Constructor Summary
GraphicalCompositeFigure()
          Default constructor which uses nothing as presentation figure.
GraphicalCompositeFigure(Figure newPresentationFigure)
          Constructor which creates a GraphicalCompositeFigure with a given graphical figure for presenting it.
 
Method Summary
 void addNotify(Drawing drawing)
          Informs a figure, that it has been added to a drawing.
protected  void applyAttributesTo(Figure that)
          Applies all attributes of this figure to that figure.
protected  void basicSetPresentationFigureBounds(java.awt.geom.Point2D.Double anchor, java.awt.geom.Point2D.Double lead)
           
 java.awt.geom.Point2D.Double chop(java.awt.geom.Point2D.Double from)
          This is a default implementation that chops the point at the rectangle returned by getBounds() of the figure.
 GraphicalCompositeFigure 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)
          Return default handles from the presentation figure.
 void draw(java.awt.Graphics2D g)
          Draw the figure.
protected  void drawPresentationFigure(java.awt.Graphics2D g)
           
<T> T
get(AttributeKey<T> key)
          Gets an attribute from the figure.
protected  AttributeKey getAttributeKey(java.lang.String name)
           
 java.util.Map<AttributeKey,java.lang.Object> getAttributes()
          Returns a view to all attributes of this figure.
 java.awt.geom.Rectangle2D.Double getBounds()
          Return the logcal display area.
 java.awt.geom.Rectangle2D.Double getDrawingArea()
          Return the draw area.
 Figure getPresentationFigure()
          Get a figure which renders this BasicCompositeFigure.
 void read(DOMInput in)
           
protected  void readAttributes(DOMInput in)
           
 void remap(java.util.HashMap<Figure,Figure> oldToNew, boolean disconnectIfNotInMap)
           
 void removeNotify(Drawing drawing)
          Informs a figure, that it has been removed from a drawing.
<T> void
set(AttributeKey<T> key, T newValue)
          Sets an attribute of the figure.
 void setAttributeEnabled(AttributeKey key, boolean b)
           
 void setBounds(java.awt.geom.Point2D.Double anchor, java.awt.geom.Point2D.Double lead)
          Moves the figure.
 void setPresentationFigure(Figure newPresentationFigure)
          Set a figure which renders this BasicCompositeFigure.
protected  void superBasicSetBounds(java.awt.geom.Point2D.Double anchor, java.awt.geom.Point2D.Double lead)
           
 void transform(java.awt.geom.AffineTransform tx)
          Standard presentation method which is delegated to the encapsulated presentation figure.
 void write(DOMOutput out)
           
protected  void writeAttributes(DOMOutput out)
           
 
Methods inherited from class org.jhotdraw.draw.AbstractCompositeFigure
add, add, addAll, addAll, addCompositeFigureListener, basicAdd, basicAdd, basicAddAll, basicRemove, basicRemoveAll, basicRemoveAllChildren, basicRemoveChild, bringToFront, changed, contains, createEventHandler, findChild, findChildIndex, findFigureInside, fireFigureAdded, fireFigureRemoved, getAttributesRestoreData, getChild, getChildCount, getChildren, getChildrenFrontToBack, getDecomposition, getLayouter, getPreferredSize, getTransformRestoreData, indexOf, invalidate, layout, remove, removeAll, removeAllChildren, removeChild, removeCompositeFigureListener, restoreAttributesTo, restoreTransformTo, sendToBack, setLayouter, validate, willChange
 
Methods inherited from class org.jhotdraw.draw.AbstractFigure
addFigureListener, basicClone, findCompatibleConnector, findConnector, fireAreaInvalidated, fireAreaInvalidated, fireAreaInvalidated, fireAttributeChanged, fireFigureAdded, fireFigureChanged, fireFigureChanged, fireFigureChanged, fireFigureHandlesChanged, fireFigureRemoved, fireFigureRequestRemove, fireUndoableEditHappened, getActions, getChangingDepth, getConnectors, getCursor, getDrawing, getEndPoint, getFontRenderContext, getLayer, getLock, getStartPoint, getTool, getToolTipText, handleDrop, handleMouseClick, includes, isChanging, isConnectable, isRemovable, isSelectable, isTransformable, isVisible, remap, removeFigureListener, requestRemove, setBounds, setConnectable, setRemovable, setSelectable, setTransformable, setVisible, toString
 
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jhotdraw.draw.Figure
addFigureListener, addPropertyChangeListener, findCompatibleConnector, findConnector, getActions, getConnectors, getCursor, getEndPoint, getLayer, getStartPoint, getTool, getToolTipText, handleDrop, handleMouseClick, includes, isConnectable, isRemovable, isSelectable, isTransformable, isVisible, remap, removeFigureListener, removePropertyChangeListener, requestRemove
 

Field Detail

attributes

protected java.util.HashMap<AttributeKey,java.lang.Object> attributes
Constructor Detail

GraphicalCompositeFigure

public GraphicalCompositeFigure()
Default constructor which uses nothing 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

getBounds

public java.awt.geom.Rectangle2D.Double getBounds()
Return the logcal display area. This method is delegated to the encapsulated presentation figure.

Specified by:
getBounds in interface Figure
Overrides:
getBounds in class AbstractCompositeFigure

contains

public boolean contains(java.awt.geom.Point2D.Double p)
Description copied from interface: Figure
Checks if a point is contained by the figure.

This is used for hit testing by Tool's.

Specified by:
contains in interface Figure
Overrides:
contains in class AbstractCompositeFigure

addNotify

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

Specified by:
addNotify in interface Figure
Overrides:
addNotify in class AbstractCompositeFigure

removeNotify

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

Specified by:
removeNotify in interface Figure
Overrides:
removeNotify in class AbstractCompositeFigure

getDrawingArea

public java.awt.geom.Rectangle2D.Double getDrawingArea()
Return the draw area. This method is delegated to the encapsulated presentation figure.

Specified by:
getDrawingArea in interface Figure
Overrides:
getDrawingArea in class AbstractCompositeFigure

setBounds

public void setBounds(java.awt.geom.Point2D.Double anchor,
                      java.awt.geom.Point2D.Double lead)
Moves the figure. This is the method that subclassers override. Clients usually call displayBox.

Specified by:
setBounds in interface Figure
Overrides:
setBounds in class AbstractCompositeFigure
Parameters:
anchor - the start point of the bounds
lead - the end point of the bounds
See Also:
Figure.getBounds()

superBasicSetBounds

protected void superBasicSetBounds(java.awt.geom.Point2D.Double anchor,
                                   java.awt.geom.Point2D.Double lead)

basicSetPresentationFigureBounds

protected void basicSetPresentationFigureBounds(java.awt.geom.Point2D.Double anchor,
                                                java.awt.geom.Point2D.Double lead)

transform

public void transform(java.awt.geom.AffineTransform tx)
Standard presentation method which is delegated to the encapsulated presentation figure. The presentation figure is moved as well as all contained figures.

Specified by:
transform in interface Figure
Overrides:
transform in class AbstractCompositeFigure
Parameters:
tx - The transformation.
See Also:
Figure.getTransformRestoreData(), Figure.restoreTransformTo(java.lang.Object)

draw

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

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

drawPresentationFigure

protected void drawPresentationFigure(java.awt.Graphics2D g)

createHandles

public java.util.Collection<Handle> createHandles(int detailLevel)
Return default handles from the presentation figure.

Specified by:
createHandles in interface Figure
Overrides:
createHandles in class AbstractCompositeFigure
Parameters:
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.
Returns:
a Collection of handles
See Also:
Handle

setPresentationFigure

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

Parameters:
newPresentationFigure - figure takes over the presentation tasks

getPresentationFigure

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

Returns:
figure takes over the presentation tasks

clone

public GraphicalCompositeFigure clone()
Description copied from interface: Figure
Returns a clone of the figure, with clones of all aggregated figures, such as children and decorators. The cloned figure does not clone the list of FigureListeners from its original.

Specified by:
clone in interface Figure
Overrides:
clone in class AbstractCompositeFigure

remap

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

set

public <T> void set(AttributeKey<T> key,
                    T newValue)
Sets an attribute of the figure. AttributeKey name and semantics are defined by the class implementing the figure interface.

Specified by:
set in interface Figure
Overrides:
set in class AbstractCompositeFigure
See Also:
AttributeKey.set(org.jhotdraw.draw.Figure, T)

setAttributeEnabled

public void setAttributeEnabled(AttributeKey key,
                                boolean b)

get

public <T> T get(AttributeKey<T> key)
Gets an attribute from the figure.

Specified by:
get in interface Figure
Overrides:
get in class AbstractCompositeFigure
Returns:
Returns the attribute value. If the Figure does not have an attribute with the specified key, returns key.getDefaultValue().
See Also:
AttributeKey.get(org.jhotdraw.draw.Figure)

applyAttributesTo

protected void applyAttributesTo(Figure that)
Applies all attributes of this figure to that figure.


writeAttributes

protected void writeAttributes(DOMOutput out)
                        throws java.io.IOException
Throws:
java.io.IOException

readAttributes

protected void readAttributes(DOMInput in)
                       throws java.io.IOException
Throws:
java.io.IOException

read

public void read(DOMInput in)
          throws java.io.IOException
Specified by:
read in interface DOMStorable
Overrides:
read in class AbstractCompositeFigure
Throws:
java.io.IOException

write

public void write(DOMOutput out)
           throws java.io.IOException
Specified by:
write in interface DOMStorable
Overrides:
write in class AbstractCompositeFigure
Throws:
java.io.IOException

getAttributeKey

protected AttributeKey getAttributeKey(java.lang.String name)

getAttributes

public java.util.Map<AttributeKey,java.lang.Object> getAttributes()
Description copied from interface: Figure
Returns a view to all attributes of this figure. By convention, an unmodifiable map is returned.

Specified by:
getAttributes in interface Figure
Overrides:
getAttributes in class AbstractCompositeFigure

chop

public java.awt.geom.Point2D.Double chop(java.awt.geom.Point2D.Double from)
This is a default implementation that chops the point at the rectangle returned by getBounds() of the figure.

Figures which have a non-rectangular shape need to override this method.

This method takes the following attributes into account: AttributeKeys.STROKE_COLOR, AttributeKeys.STROKE_PLACEMENT, and AttributeKeys.StrokeTotalWidth.


Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.