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 protectedTerminalFigure(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 booleancontains(java.awt.geom.Point2D p)Test whether this figure contains the point given.SitegetAttachSite()Get the site that the terminal is attached to.java.awt.geom.Rectangle2DgetBounds()Get the bounding box of this figure.SitegetConnectSite()Get the site that a connector can connect to.FiguregetFigure()Get the figure that this terminal figure is wrapping.InteractorgetInteractor()Return the interactor of this figure.CanvasLayergetLayer()Get the most immediate layer containing this figure.java.awt.geom.Point2DgetOrigin()Return the origin of the wrapped figure in the enclosing transform context.CanvasComponentgetParent()Return the parent of this component.java.awt.ShapegetShape()Get the outline shape of this figure.java.lang.StringgetToolTipText()Return the tooltip for this figure.TransformContextgetTransformContext()Return the transform context of the component.java.lang.ObjectgetUserObject()Return the user object.booleanhit(java.awt.geom.Rectangle2D r)Test if this figure is "hit" by the given rectangle.booleanintersects(java.awt.geom.Rectangle2D r)Test if this figure intersects the given rectangle.booleanisVisible()Test the visibility flag of this object.voidpaint(java.awt.Graphics2D g)Paint the figure.voidpaint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D region)Paint this object onto a 2D graphics object, within the given region.voidrelocate()Tell the terminal to relocate itself because the attachment site (or the figure that owns it) has moved.voidrepaint()Schedule a repaint of the component.voidrepaint(DamageRegion d)Accept notification that a repaint has occurred somewhere in the tree below this component.voidsetAttachSite(Site s)Set the site that the terminal is attached to.voidsetInteractor(Interactor interactor)Set the interactor of this figure.voidsetParent(CanvasComponent fc)Set the parent of this figure.voidsetToolTipText(java.lang.String tip)Set the tool tip for this figure.voidsetUserObject(java.lang.Object o)Set the user object.voidsetVisible(boolean flag)Set the visibility flag of this object.voidtransform(java.awt.geom.AffineTransform at)Transform the figure with the supplied transform.voidtranslate(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:
containsin interfaceFigure- Overrides:
containsin 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:
getBoundsin interfaceFigure- Overrides:
getBoundsin classAbstractFigure- Returns:
- the bounding box of this figure.
-
getAttachSite
public Site getAttachSite()
Get the site that the terminal is attached to.- Specified by:
getAttachSitein interfaceTerminal
-
getConnectSite
public Site getConnectSite()
Get the site that a connector can connect to.- Specified by:
getConnectSitein 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:
getInteractorin interfaceFigure- Overrides:
getInteractorin 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:
getLayerin interfaceFigure- Overrides:
getLayerin 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:
getOriginin interfaceFigure- Overrides:
getOriginin 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:
getParentin interfaceCanvasComponent- Specified by:
getParentin interfaceFigure- Overrides:
getParentin 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:
getTransformContextin interfaceCanvasComponent- Overrides:
getTransformContextin 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:
getShapein interfaceFigure- Specified by:
getShapein classAbstractFigure- Returns:
- the outline shape of this figure
-
getToolTipText
public java.lang.String getToolTipText()
Return the tooltip for this figure.- Specified by:
getToolTipTextin interfaceFigure- Overrides:
getToolTipTextin 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:
getUserObjectin interfaceUserObjectContainer- Overrides:
getUserObjectin 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:
hitin interfaceFigure- Overrides:
hitin 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:
intersectsin interfaceFigure- Overrides:
intersectsin 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:
isVisiblein interfaceVisibleComponent- Overrides:
isVisiblein classAbstractFigure- Returns:
- true if the object is visible.
-
paint
public void paint(java.awt.Graphics2D g)
Paint the figure.- Specified by:
paintin interfaceVisibleComponent- Specified by:
paintin 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:
paintin interfaceVisibleComponent- Overrides:
paintin 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:
repaintin interfaceCanvasComponent- Overrides:
repaintin 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:
repaintin interfaceCanvasComponent- Overrides:
repaintin 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:
setAttachSitein 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:
setInteractorin interfaceFigure- Overrides:
setInteractorin 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:
setParentin interfaceFigure- Overrides:
setParentin 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:
setToolTipTextin interfaceFigure- Overrides:
setToolTipTextin 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:
transformin interfaceFigure- Specified by:
transformin classAbstractFigure- Parameters:
at- The transform to be used.
-
translate
public void translate(double x, double y)Move the figure the indicated distance.- Specified by:
translatein interfaceFigure- Overrides:
translatein 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:
setUserObjectin interfaceUserObjectContainer- Overrides:
setUserObjectin 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:
setVisiblein interfaceVisibleComponent- Overrides:
setVisiblein classAbstractFigure- Parameters:
flag- True if this object is to be visible.
-
-