diva.canvas
Class AbstractFigure

java.lang.Object
  extended by diva.canvas.AbstractFigure
All Implemented Interfaces:
CanvasComponent, Figure, VisibleComponent, UserObjectContainer
Direct Known Subclasses:
AbstractConnector, AbstractFigureContainer, BasicFigure, FigureTutorial.CustomRectangle, FigureWrapper, IconFigure, ImageFigure, LabelFigure, LabelWrapper, PaintedFigure, PaneWrapper, StateBubble, StraightTerminal, SwingWrapper, TerminalFigure, TransformedFigureTutorial.CloudFigure, VectorFigure

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

AbstractFigure is an abstract superclass implementing the Figure interface. Each subclass is assumed to have some persistent screen representation. They are responsible for knowing how to repaint themselves on the screen and find out where they and how to move themselves. They are not required to know when to repaint, as that is done by the canvas they are drawn on.

Version:
$Id: AbstractFigure.java 38798 2005-07-08 20:00:01Z cxh $
Author:
John Reekie
Accepted Rating:
Yellow

Field Summary
private  Interactor _interactor
          The interactor
private  CanvasComponent _parent
          This figure's parent
private  java.lang.String _toolTipText
          The tooltip
private  java.lang.Object _userObject
          The user object
private  boolean _visibility
          The visibility flag.
 
Constructor Summary
AbstractFigure()
           
 
Method Summary
 boolean contains(java.awt.geom.Point2D p)
          Test whether this figure contains the point given.
 java.awt.geom.Rectangle2D getBounds()
          Get the bounding box of this figure.
 Interactor getInteractor()
          Return the interactor of this figure.
 CanvasLayer getLayer()
          Get the most immediate layer containing this figure.
 java.awt.geom.Point2D getOrigin()
          Return the origin of the figure in the enclosing transform context, which in this base class is the center of the bounds returned by getBounds().
 CanvasComponent getParent()
          Return the parent of this figure.
abstract  java.awt.Shape getShape()
          Get the outline shape of this figure.
 java.lang.String getToolTipText()
          Return the tooltip string for this figure, or null if the figure does not have a tooltip.
 TransformContext getTransformContext()
          Return the transform context of the figure.
 java.lang.Object getUserObject()
          Get the user object of this figure.
 boolean hit(java.awt.geom.Rectangle2D r)
          Test if this figure intersects the given rectangle, and the interior of the figure is not transparent to hits.
 boolean intersects(java.awt.geom.Rectangle2D r)
          Test if this figure intersects the given rectangle.
 boolean isVisible()
          Test the visibility flag of this figure.
abstract  void paint(java.awt.Graphics2D g)
          Paint the figure.
 void paint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r)
          Repaint the figure in the given rectangle.
 void repaint()
          Schedule a repaint of the figure.
 void repaint(DamageRegion d)
          Schedule a repaint of the figure within the given damage region.
 void setInteractor(Interactor interactor)
          Set the interactor of this figure.
 void setParent(CanvasComponent fc)
          Set the parent of this figure.
 void setToolTipText(java.lang.String s)
          Set the tooltip string for this figure.
 void setUserObject(java.lang.Object o)
          Set the user object.
 void setVisible(boolean flag)
          Set the visibility flag of this figure.
abstract  void transform(java.awt.geom.AffineTransform at)
          Transform the figure with the supplied transform.
 void translate(double x, double y)
          Move the figure the indicated distance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_interactor

private Interactor _interactor
The interactor


_userObject

private java.lang.Object _userObject
The user object


_visibility

private boolean _visibility
The visibility flag.


_parent

private CanvasComponent _parent
This figure's parent


_toolTipText

private java.lang.String _toolTipText
The tooltip

Constructor Detail

AbstractFigure

public AbstractFigure()
Method Detail

contains

public boolean contains(java.awt.geom.Point2D p)
Test whether this figure contains the point given. This default implementation tests using the figure's shape.

Specified by:
contains in interface Figure

getBounds

public java.awt.geom.Rectangle2D getBounds()
Get the bounding box of this figure. This default implementation returns the bounding box of the figure's outline shape.

Specified by:
getBounds in interface Figure

getInteractor

public Interactor getInteractor()
Return the interactor of this figure. Return null if there isn't one.

Specified by:
getInteractor in interface Figure

getLayer

public CanvasLayer getLayer()
Get the most immediate layer containing this figure. Returns null if this figure is not in a layer, either directly or as one of its ancestors.

Specified by:
getLayer in interface Figure

getOrigin

public java.awt.geom.Point2D getOrigin()
Return the origin of the figure in the enclosing transform context, which in this base class is the center of the bounds returned by getBounds().

Specified by:
getOrigin in interface Figure
Returns:
The origin of the figure.
See Also:
getBounds()

getParent

public CanvasComponent getParent()
Return the parent of this figure. Return null if the figure does not have a parent. (Note that a figure with no parent can exist, but it will not be displayed, as it must be in a layer for the figure canvas to ever call its paint method.)

Specified by:
getParent in interface CanvasComponent
Specified by:
getParent in interface Figure

getShape

public abstract java.awt.Shape getShape()
Get the outline shape of this figure. The outline shape is used for things like highlighting. This is an abstract method, provided here since a number of other concrete methods use it.

Specified by:
getShape in interface Figure

getTransformContext

public TransformContext getTransformContext()
Return the transform context of the figure. This default implementation assumes that the figure does not implement a transform context, so just calls the same method on its parent. If it has no parent, return null.

Specified by:
getTransformContext in interface CanvasComponent

getToolTipText

public java.lang.String getToolTipText()
Return the tooltip string for this figure, or null if the figure does not have a tooltip.

Specified by:
getToolTipText in interface Figure

getUserObject

public java.lang.Object getUserObject()
Get the user object of this figure. Return null if there is none.

Specified by:
getUserObject in interface UserObjectContainer

hit

public boolean hit(java.awt.geom.Rectangle2D r)
Test if this figure intersects the given rectangle, and the interior of the figure is not transparent to hits. This is the same as intersects() if the interior of the figure is not transparent. If the figure is not visible, return false. This default implementation is the same as intersects if the figure is visible.

Specified by:
hit in interface Figure

intersects

public boolean intersects(java.awt.geom.Rectangle2D r)
Test if this figure intersects the given rectangle. This default implementation uses the figure's outline shape.

Specified by:
intersects in interface Figure

isVisible

public boolean isVisible()
Test the visibility flag of this figure. Note that this flag does not indicate whether the figure is actually visible on the screen, as one if its ancestors may not be visible.

Specified by:
isVisible in interface VisibleComponent

paint

public abstract void paint(java.awt.Graphics2D g)
Paint the figure. This is an abstract method. Implementing subclasses should note that the graphics context may already have a current transform, so if this figure needs to perform a transform, it must be cascaded with the current transform and the transform restored at the end of this method. The graphics context may also contain a clip region, so any clipping must be done with the intersection of the current clip and the clip desired by this method. and the clip restored. Other state in the graphics context, such as the stroke and fill, do not need to be preserved.

Specified by:
paint in interface VisibleComponent

paint

public void paint(java.awt.Graphics2D g,
                  java.awt.geom.Rectangle2D r)
Repaint the figure in the given rectangle. This default implementation repaints the whole figure. Subclasses should consider overriding this method to optimize redraw. See the documentation of the one-argument version of this method.

Specified by:
paint in interface VisibleComponent

repaint

public void repaint()
Schedule a repaint of the figure. This should be called after performing modifications on the figure, so that the figure is scheduled for redrawing. This default implementation creates a damage region that is the same size as this figure's bounding box, and forwards that to the parent. Subclasses only need to override this method if they need to damage a region that is different from the bounding box.

Specified by:
repaint in interface CanvasComponent

repaint

public void repaint(DamageRegion d)
Schedule a repaint of the figure within the given damage region. This default implementation forwards the damage region to this figure's parent. See the nullary version of this method.

Specified by:
repaint in interface CanvasComponent

setInteractor

public void setInteractor(Interactor interactor)
Set the interactor of this figure. Once a figure has an interactor given to it, it will respond to events on the figure canvas.

Specified by:
setInteractor in interface Figure

setParent

public void setParent(CanvasComponent fc)
Set the parent of this figure. A null argument means that the figure is being removed from its parent. No checks are performed to see if the figure already has a parent -- it is the responsibility of the caller to do this, and to change the layer reference of the figure if necessary. This method is intended only for use by classes that implement FigureContainer.

Specified by:
setParent in interface Figure

setUserObject

public void setUserObject(java.lang.Object o)
Set the user object. This object is intended for use as a reference to the semantic model.

Specified by:
setUserObject in interface UserObjectContainer

setToolTipText

public void setToolTipText(java.lang.String s)
Set the tooltip string for this figure. If the string is null, then the figure will not have a tooltip.

Specified by:
setToolTipText in interface Figure

setVisible

public void setVisible(boolean flag)
Set the visibility flag of this figure. If the flag is false, then the figure will not be drawn on the screen and it will not respond to user input events.

Specified by:
setVisible in interface VisibleComponent

transform

public abstract void transform(java.awt.geom.AffineTransform at)
Transform the figure with the supplied transform. This can be used to perform arbitrary translation, scaling, shearing, and rotation operations.

Specified by:
transform in interface Figure

translate

public void translate(double x,
                      double y)
Move the figure the indicated distance. The default implementation uses the transform method, so most subclasses can probably implement this more efficiently.

Specified by:
translate in interface Figure