JHotDraw 7.5.1

org.jhotdraw.draw
Interface CompositeFigure

All Superinterfaces:
java.lang.Cloneable, Figure, java.io.Serializable
All Known Subinterfaces:
Drawing
All Known Implementing Classes:
AbstractAttributedCompositeFigure, AbstractCompositeFigure, AbstractDrawing, DefaultDrawing, GraphicalCompositeFigure, GroupFigure, LabeledLineConnectionFigure, ListFigure, ODGDrawing, ODGGroupFigure, ODGPathFigure, QuadTreeCompositeFigure, QuadTreeDrawing, SVGGroupFigure, SVGPathFigure, TaskFigure

@NotNull
public interface CompositeFigure
extends Figure

A composite figure is composed of several child Figures.

A composite figure can be laid out using a Layouter.

CompositeFigure listens to requestRemove events sent by its child figures, and then removes the child figure which sent the event.


Design Patterns

Composite
Composite figures can be composed of other figures.
Component: Figure; Composite: CompositeFigure.

Observer
State changes of figures can be observed by other objects. Specifically CompositeFigure observes area invalidations and remove requests of its child figures. DrawingView also observes area invalidations of its drawing object.
Subject: Figure; Observer: FigureListener; Event: FigureEvent; Concrete Observer: CompositeFigure, DrawingView.

Observer
Changes in the composition of a composite figure can be observed.
Subject: CompositeFigure; Observer: CompositeFigureListener; Event: CompositeFigureEvent.

Strategy
Composite figures can be laid out using different layout algorithms which are implemented by layouters.
Context: CompositeFigure; Strategy: Layouter.


Version:
$Id: CompositeFigure.java 654 2010-06-25 13:27:08Z rawcoder $
Author:
Werner Randelshofer

Field Summary
static AttributeKey<Insets2D.Double> LAYOUT_INSETS
          The value of this attribute is a Insets2D.Double object.
 
Fields inherited from interface org.jhotdraw.draw.Figure
CONNECTABLE_PROPERTY, REMOVABLE_PROPERTY, SELECTABLE_PROPERTY, TRANSFORMABLE_PROPERTY
 
Method Summary
 boolean add(Figure child)
          Adds a child to the figure.
 void add(int index, Figure child)
          Adds a child to the figure at the specified index.
 void addCompositeFigureListener(CompositeFigureListener listener)
          Adds a listener for this composite figure.
 void basicAdd(Figure child)
          Adds a child to the figure without firing events.
 void basicAdd(int index, Figure child)
          Adds a child to the figure at the specified index without firing events.
 int basicRemove(Figure child)
          Removes the specified child without firing events.
 void basicRemoveAllChildren()
          Removes all children from the composite figure without firing events.
 Figure basicRemoveChild(int index)
          Removes the child at the specified index without firing events.
 boolean contains(Figure f)
          Returns true if this composite figure contains the specified figure.
 Figure getChild(int index)
          Returns the child figure at the specified index.
 int getChildCount()
          Returns the number of children.
 java.util.List<Figure> getChildren()
          Returns an unchangeable list view on the children.
 Layouter getLayouter()
          Get a Layouter object which encapsulated a layout algorithm for this figure.
 int indexOf(Figure child)
          Returns the index of the specified child.
 void layout()
          A layout algorithm is used to define how the child components should be laid out in relation to each other.
 boolean remove(Figure child)
          Removes the specified child.
 void removeAllChildren()
          Removes all children from the composite figure.
 Figure removeChild(int index)
          Removes the child at the specified index.
 void removeCompositeFigureListener(CompositeFigureListener listener)
          Removes a listener from this composite figure.
 void setLayouter(Layouter newValue)
          Set a Layouter object which encapsulated a layout algorithm for this figure.
 
Methods inherited from interface org.jhotdraw.draw.Figure
addFigureListener, addNotify, addPropertyChangeListener, changed, clone, contains, createHandles, draw, findCompatibleConnector, findConnector, findFigureInside, get, getActions, getAttributes, getAttributesRestoreData, getBounds, getConnectors, getCursor, getDecomposition, getDrawingArea, getEndPoint, getLayer, getPreferredSize, getStartPoint, getTool, getToolTipText, getTransformRestoreData, handleDrop, handleMouseClick, includes, isConnectable, isRemovable, isSelectable, isTransformable, isVisible, remap, removeFigureListener, removeNotify, removePropertyChangeListener, requestRemove, restoreAttributesTo, restoreTransformTo, set, setBounds, transform, willChange
 

Field Detail

LAYOUT_INSETS

static final AttributeKey<Insets2D.Double> LAYOUT_INSETS
The value of this attribute is a Insets2D.Double object.

Method Detail

add

boolean add(Figure child)
Adds a child to the figure.

This is a convenience method for add(getChildCount(), child);

This method calls figureAdded on all registered CompositeFigureListeners.

Returns:
true if this CompositeFigure changed as a result of the call

add

void add(int index,
         Figure child)
Adds a child to the figure at the specified index.

This method calls figureAdded on all registered CompositeFigureListeners.


basicAdd

void basicAdd(Figure child)
Adds a child to the figure without firing events.

This method can be used to reinsert a child figure which has been temporarily removed from this CompositeFigure (for example to reorder the sequence of the children) and to efficiently build a drawing from an InputFormat. This is a convenience method for calling basicAdd(getChildCount(), child);.


basicAdd

void basicAdd(int index,
              Figure child)
Adds a child to the figure at the specified index without firing events.

This method can be used to reinsert a child figure which has been temporarily removed from this CompositeFigure (for example to reorder the sequence of the children) and to efficiently build a drawing from an InputFormat.


remove

boolean remove(Figure child)
Removes the specified child. Returns true, if the Figure contained the removed child.

This is a convenience method for calling removeChild(getChildren().indexOf(child));

This method calls figureRemoved on all registered CompositeFigureListener's.


removeChild

Figure removeChild(int index)
Removes the child at the specified index. Returns the removed child figure.

Calls figureRemoved on all registered CompositeFigureListener's.


removeAllChildren

void removeAllChildren()
Removes all children from the composite figure.

This is a convenience method for while(getChildCount() > 0) removeChild(0);


basicRemove

int basicRemove(Figure child)
Removes the specified child without firing events.

This method can be used to temporarily remove a child from this CompositeFigure (for example to reorder the sequence of the children).

This is a convenience method for calling basicRemove(indexOf(child));.

Returns the index of the removed figure. Returns -1 if the figure was not a child of this CompositeFigure.


basicRemoveChild

Figure basicRemoveChild(int index)
Removes the child at the specified index without firing events.

This method can be used to temporarily remove a child from this CompositeFigure (for example to reorder the sequence of the children).

Returns the removed child figure.


basicRemoveAllChildren

void basicRemoveAllChildren()
Removes all children from the composite figure without firing events.

This method can be used to temporarily remove a child from this CompositeFigure (for example to reorder the sequence of the children).

This is a convenience method for while(getChildCount() > 0) basicRemoveChild(0);


getChildren

java.util.List<Figure> getChildren()
Returns an unchangeable list view on the children.


getChildCount

int getChildCount()
Returns the number of children.

This is a convenience method for calling getChildren().size();.


getChild

Figure getChild(int index)
Returns the child figure at the specified index.

This is a convenience method for calling getChildren().get(index);.


indexOf

int indexOf(Figure child)
Returns the index of the specified child.

This is a convenience method for calling getChildren().indexOf(index);.

Returns:
The index of the child, or -1 if the specified figure is not a child of this CompositeFigure.

contains

boolean contains(Figure f)
Returns true if this composite figure contains the specified figure.

This is a convenience method for calling getChildren().contains(f);.


getLayouter

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.

Returns:
layout strategy used by this figure

layout

void layout()
A layout algorithm is used to define how the child components should be laid out in relation to each other.

This method first calls layout() on all child figures which implement the CompositeFigure interface. Then the children are laid out.

The task for laying out the child figures is delegated to a Layouter which can be plugged in at runtime.


setLayouter

void setLayouter(Layouter newValue)
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 put the Layouter in the protected initialize() method so it can be recreated if a GraphicalCompositeFigure is read and restored from a StorableInput stream.

Parameters:
newValue - encapsulation of a layout algorithm.

addCompositeFigureListener

void addCompositeFigureListener(CompositeFigureListener listener)
Adds a listener for this composite figure.


removeCompositeFigureListener

void removeCompositeFigureListener(CompositeFigureListener listener)
Removes a listener from this composite figure.


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