Package diva.canvas.connector
Class TerminalFigure
- java.lang.Object
-
- diva.canvas.AbstractFigure
-
- diva.canvas.connector.TerminalFigure
-
- All Implemented Interfaces:
CanvasComponent
,Terminal
,Figure
,VisibleComponent
,UserObjectContainer
- Direct Known Subclasses:
PortTerminal
public class TerminalFigure extends AbstractFigure implements Terminal
A TerminalFigure decorates a figure to be a terminal as well. Using this class, any Figure can be made a terminal. As per the decorator pattern, the Figure should be not be accessed externally to this class.- Version:
- $Id$
- Author:
- Steve Neuendorffer
-
-
Field Summary
Fields Modifier and Type Field Description protected Site
_connectSite
-
Constructor Summary
Constructors Modifier Constructor Description protected
TerminalFigure(Figure figure)
Create a new TerminalFigure for the given figure.TerminalFigure(Figure figure, Site connectSite)
Create a new TerminalFigure for the given figure, with the given site for connections.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(java.awt.geom.Point2D p)
Test whether this figure contains the point given.Site
getAttachSite()
Get the site that the terminal is attached to.java.awt.geom.Rectangle2D
getBounds()
Get the bounding box of this figure.Site
getConnectSite()
Get the site that a connector can connect to.Figure
getFigure()
Get the figure that this terminal figure is wrapping.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 wrapped figure in the enclosing transform context.CanvasComponent
getParent()
Return the parent of this component.java.awt.Shape
getShape()
Get the outline shape of this figure.java.lang.String
getToolTipText()
Return the tooltip for this figure.TransformContext
getTransformContext()
Return the transform context of the component.java.lang.Object
getUserObject()
Return the user object.boolean
hit(java.awt.geom.Rectangle2D r)
Test if this figure is "hit" by the given rectangle.boolean
intersects(java.awt.geom.Rectangle2D r)
Test if this figure intersects the given rectangle.boolean
isVisible()
Test the visibility flag of this object.void
paint(java.awt.Graphics2D g)
Paint the figure.void
paint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D region)
Paint this object onto a 2D graphics object, within the given region.void
relocate()
Tell the terminal to relocate itself because the attachment site (or the figure that owns it) has moved.void
repaint()
Schedule a repaint of the component.void
repaint(DamageRegion d)
Accept notification that a repaint has occurred somewhere in the tree below this component.void
setAttachSite(Site s)
Set the site that the terminal is attached to.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 tip)
Set the tool tip for this figure.void
setUserObject(java.lang.Object o)
Set the user object.void
setVisible(boolean flag)
Set the visibility flag of this object.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.
-
-
-
Field Detail
-
_connectSite
protected Site _connectSite
-
-
Constructor Detail
-
TerminalFigure
public TerminalFigure(Figure figure, Site connectSite)
Create a new TerminalFigure for the given figure, with the given site for connections.
-
TerminalFigure
protected TerminalFigure(Figure figure)
Create a new TerminalFigure for the given figure. This is intended for use by derived classes that will provide their own connect site or sites.
-
-
Method Detail
-
contains
public boolean contains(java.awt.geom.Point2D p)
Test whether this figure contains the point given. The point given is in the enclosing transform context.- Specified by:
contains
in interfaceFigure
- Overrides:
contains
in classAbstractFigure
- Parameters:
p
- The given point- Returns:
- true if the point is contained by this figure.
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
Get the bounding box of this figure. The result rectangle is given in the enclosing transform context.- Specified by:
getBounds
in interfaceFigure
- Overrides:
getBounds
in classAbstractFigure
- Returns:
- the bounding box of this figure.
-
getAttachSite
public Site getAttachSite()
Get the site that the terminal is attached to.- Specified by:
getAttachSite
in interfaceTerminal
-
getConnectSite
public Site getConnectSite()
Get the site that a connector can connect to.- Specified by:
getConnectSite
in interfaceTerminal
-
getFigure
public Figure getFigure()
Get the figure that this terminal figure is wrapping. Note usage of this figure must be considered extremely carefully to avoid breaking the decorator pattern.
-
getInteractor
public Interactor getInteractor()
Return the interactor of this figure. Return null if there isn't one.- Specified by:
getInteractor
in interfaceFigure
- Overrides:
getInteractor
in classAbstractFigure
- 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.- Specified by:
getLayer
in interfaceFigure
- Overrides:
getLayer
in classAbstractFigure
- Returns:
- the most immediate layer containing this figure.
-
getOrigin
public java.awt.geom.Point2D getOrigin()
Return the origin of the wrapped figure in the enclosing transform context.- Specified by:
getOrigin
in interfaceFigure
- Overrides:
getOrigin
in classAbstractFigure
- Returns:
- The origin of the background figure.
- See Also:
AbstractFigure.getBounds()
-
getParent
public CanvasComponent getParent()
Return the parent of this component. Return null if the component does not have a parent.- Specified by:
getParent
in interfaceCanvasComponent
- Specified by:
getParent
in interfaceFigure
- Overrides:
getParent
in classAbstractFigure
- Returns:
- the parent of this figure.
- See Also:
Figure.setParent(CanvasComponent)
-
getTransformContext
public TransformContext getTransformContext()
Return the transform context of the component. If the component has its own transform context, this method should return it, otherwise it should return the transform context of its parent.- Specified by:
getTransformContext
in interfaceCanvasComponent
- Overrides:
getTransformContext
in classAbstractFigure
- Returns:
- The transform context of this component.
-
getShape
public java.awt.Shape getShape()
Get the outline shape of this figure. The outline shape is used for things like highlighting. The result shape is given in the enclosing transform context.- Specified by:
getShape
in interfaceFigure
- Specified by:
getShape
in classAbstractFigure
- Returns:
- the outline shape of this figure
-
getToolTipText
public java.lang.String getToolTipText()
Return the tooltip for this figure.- Specified by:
getToolTipText
in interfaceFigure
- Overrides:
getToolTipText
in classAbstractFigure
- Returns:
- the tooltip string for this figure.
- See Also:
Figure.setToolTipText(String)
-
getUserObject
public java.lang.Object getUserObject()
Return the user object.- Specified by:
getUserObject
in interfaceUserObjectContainer
- Overrides:
getUserObject
in classAbstractFigure
- Returns:
- The user object.
- See Also:
UserObjectContainer.setUserObject(Object)
-
hit
public boolean hit(java.awt.geom.Rectangle2D r)
Test if this figure is "hit" by the given rectangle. This is the same as intersects if the interior of the figure is not transparent. The rectangle is given in the enclosing transform context. If the figure is not visible, it must return false. The default implementation is the same as intersects if the figure is visible.(This method would be better named hits, but the name hit is consistent with java.awt.Graphics2D.)
- Specified by:
hit
in interfaceFigure
- Overrides:
hit
in classAbstractFigure
- Parameters:
r
- The rectangle to be checked.- Returns:
- true if the figure is hit by the given rectangle.
-
intersects
public boolean intersects(java.awt.geom.Rectangle2D r)
Test if this figure intersects the given rectangle. The rectangle is given in the enclosing transform context.- Specified by:
intersects
in interfaceFigure
- Overrides:
intersects
in classAbstractFigure
- 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 object. Note that this flag does not indicate whether the object is actually visible on the screen, as one of its ancestors may not be visible.- Specified by:
isVisible
in interfaceVisibleComponent
- Overrides:
isVisible
in classAbstractFigure
- Returns:
- true if the object is visible.
-
paint
public void paint(java.awt.Graphics2D g)
Paint the figure.- Specified by:
paint
in interfaceVisibleComponent
- Specified by:
paint
in classAbstractFigure
- 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 region)
Paint this object onto a 2D graphics object, within the given region. Implementors should first test if the visibility flag is set, and paint the object if it is. The provided region can be used to optimize the paint, but implementors can assume that the clip region is correctly set beforehand.- Specified by:
paint
in interfaceVisibleComponent
- Overrides:
paint
in classAbstractFigure
- Parameters:
g
- The 2D graphics object that this object it to be painted upon.region
- The region.
-
relocate
public void relocate()
Tell the terminal to relocate itself because the attachment site (or the figure that owns it) has moved.
-
repaint
public void repaint()
Schedule a repaint of the component. This should be called after performing modifications on the component.- Specified by:
repaint
in interfaceCanvasComponent
- Overrides:
repaint
in classAbstractFigure
-
repaint
public void repaint(DamageRegion d)
Accept notification that a repaint has occurred somewhere in the tree below this component. The component must clear any cached data that depends on its children and forward the notification upwards.- Specified by:
repaint
in interfaceCanvasComponent
- Overrides:
repaint
in classAbstractFigure
- Parameters:
d
- The region where a repaint has occurred.
-
setAttachSite
public void setAttachSite(Site s)
Set the site that the terminal is attached to.- Specified by:
setAttachSite
in interfaceTerminal
-
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 canvas, in the ways determined by the interactor.- Specified by:
setInteractor
in interfaceFigure
- Overrides:
setInteractor
in classAbstractFigure
- 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. This method is not intended for public use, and should never be called by client code.- Specified by:
setParent
in interfaceFigure
- Overrides:
setParent
in classAbstractFigure
- Parameters:
fc
- The parent of the figure.- See Also:
Figure.getParent()
-
setToolTipText
public void setToolTipText(java.lang.String tip)
Set the tool tip for this figure.- Specified by:
setToolTipText
in interfaceFigure
- Overrides:
setToolTipText
in classAbstractFigure
- Parameters:
tip
- The tool tip text.- See Also:
Figure.getToolTipText()
-
transform
public 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 interfaceFigure
- Specified by:
transform
in classAbstractFigure
- Parameters:
at
- The transform to be used.
-
translate
public void translate(double x, double y)
Move the figure the indicated distance.- Specified by:
translate
in interfaceFigure
- Overrides:
translate
in classAbstractFigure
- Parameters:
x
- The x value to be moved.y
- The y value to be moved.
-
setUserObject
public void setUserObject(java.lang.Object o)
Set the user object.- Specified by:
setUserObject
in interfaceUserObjectContainer
- Overrides:
setUserObject
in classAbstractFigure
- Parameters:
o
- The user object.- See Also:
UserObjectContainer.getUserObject()
-
setVisible
public void setVisible(boolean flag)
Set the visibility flag of this object. If the flag is false, then the object will not be painted on the screen.- Specified by:
setVisible
in interfaceVisibleComponent
- Overrides:
setVisible
in classAbstractFigure
- Parameters:
flag
- True if this object is to be visible.
-
-