Package diva.canvas
Class AbstractFigure
- java.lang.Object
-
- 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
,RelativeLinkFigure
,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$
- Author:
- John Reekie
- Pt.AcceptedRating:
- Yellow
-
-
Constructor Summary
Constructors Constructor Description AbstractFigure()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
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.
-
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.
-
getInteractor
public Interactor getInteractor()
Return the interactor of this figure. Return null if there isn't one.- Specified by:
getInteractor
in interfaceFigure
- Returns:
- the interactor of this figure or null.
- See Also:
Figure.setInteractor(Interactor)
-
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.
-
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 interfaceFigure
- 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 interfaceCanvasComponent
- Specified by:
getParent
in interfaceFigure
- Returns:
- the parent of this figure.
- See Also:
Figure.setParent(CanvasComponent)
-
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.
-
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 interfaceCanvasComponent
- Returns:
- The transform context of this component.
-
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 interfaceFigure
- Returns:
- the tooltip string for this figure.
- See Also:
Figure.setToolTipText(String)
-
getUserObject
public java.lang.Object getUserObject()
Get the user object of this figure. Return null if there is none.- Specified by:
getUserObject
in interfaceUserObjectContainer
- Returns:
- The user object.
- See Also:
UserObjectContainer.setUserObject(Object)
-
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.
-
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 interfaceFigure
- Parameters:
r
- The rectangle to be checked.- Returns:
- truen if the figure intersects the given rectangle.
-
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 interfaceVisibleComponent
- Returns:
- true if the object is visible.
-
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 interfaceVisibleComponent
- Parameters:
g
- The 2D graphics object that this object it to be painted upon.
-
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 interfaceVisibleComponent
- Parameters:
g
- The 2D graphics object that this object it to be painted upon.r
- The region.
-
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 interfaceCanvasComponent
-
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 interfaceCanvasComponent
- Parameters:
d
- The region where a repaint has occurred.
-
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 interfaceFigure
- Parameters:
interactor
- The interactor.- See Also:
Figure.getInteractor()
-
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 interfaceFigure
- Parameters:
fc
- The parent of the figure.- See Also:
Figure.getParent()
-
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 interfaceUserObjectContainer
- Parameters:
o
- The user object.- See Also:
UserObjectContainer.getUserObject()
-
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 interfaceFigure
- Parameters:
s
- The tool tip text.- See Also:
Figure.getToolTipText()
-
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 interfaceVisibleComponent
- Parameters:
flag
- True if this object is to be visible.
-
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.
-
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.
-
-