Diva
Home
About
Demos
Downloads
Packages
Forum
Mail lists

The figure classes

The Figure interface roots a small tree of abstract and concrete classes that provide the framework for defining figures.

The root class is AbstractFigure, which provides default implementations of all methods defined in Figure and its ancestor interfaces except for the getShape(), paint(), and transform() methods. AbstractFigure is the correct class to extend for user-defined leaf figures. Diva provides examples of this in diva.canvas.toolbox and diva.canvas.tutorial, of which one, BasicFigure, is shown on the class diagram.

BasicFigure is a useful concrete figure that, in effect, allows you to turn a Shape into a Figure. As such, it has setShape() and getShape() methods, and several properties (accessed through JavaBeans-style setter and getter methods) for the outline paint and line style, and for the fill paint and transparency. Note that this class only draws a single shape; for more complex figures, clients are expected to create their own concrete subclasses of AbstractFigure.

FigureWrapper is a Figure with the sole purpose of wrapping other figures. Sometimes, you will need to define a Figure class that has some kind of application-specific behavior, but you don't want to tie the visual representation too closely to the application. In that case, subclass FigureWrapper and give your subclass the application-specific methods needed, and in your client code, set the child of the wrapper to provide the visual appearance. FigureWrapper overrides several methods in AbstractFigure to forward requests to the child figure.

AbstractFigureContainer extends AbstractFigure, and is the root class for figures that contain other figures. It provides default implementations of paint(), transform(), and translate(), all of which forward the call to each of the children. It also provides default implementations of some of the methods defined in the FigureContainer interface, excepting contains(), figures(), figuresFromFront(), figuresFromBack(), and getFigureCount(). In addition, it defines an abstract protected method swapChild(Figure, Figure), which subclasses must override to replace a child with another (this is used by the decorate() and undecorate() methods.)

There are two subclasses of AbstractFigureContainer. CompositeFigure is a container that contains its children in a z-list, and implements a slew of methods that add, remove, and find child figures. The z-list can be accessed by the getChildren() method. It also defines a new transform context, so that its children are positioned relative to that context. CompositeFigure is thus the most general form of composite figure. If you require a composite figure that restricts access to its children, then you should subclass AbstractFigureContainer directly and implement your own child management.

Finally, FigureDecorator is a special kind of figure container that contains exactly one child, and is described in the next section.


Top: The Diva Canvas Design Reference Previous: Damage regions Up: The JCanvas architecture Next: Figure decorators

Send feedback to cxh at eecs berkeley edu
Contact 
©2002-2018 U.C. Regents