diva.canvas.connector
Class TerminalFigure

java.lang.Object
  extended by diva.canvas.AbstractFigure
      extended by 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: TerminalFigure.java 39592 2005-10-24 19:09:12Z cxh $
Author:
Steve Neuendorffer

Field Summary
(package private)  Site _attachSite
           
protected  Site _connectSite
           
(package private)  Figure _figure
           
 
Constructor Summary
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
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_attachSite

Site _attachSite

_connectSite

protected Site _connectSite

_figure

Figure _figure
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 interface Figure
Overrides:
contains in class AbstractFigure

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 interface Figure
Overrides:
getBounds in class AbstractFigure

getAttachSite

public Site getAttachSite()
Get the site that the terminal is attached to.

Specified by:
getAttachSite in interface Terminal

getConnectSite

public Site getConnectSite()
Get the site that a connector can connect to.

Specified by:
getConnectSite in interface Terminal

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 interface Figure
Overrides:
getInteractor in class AbstractFigure

getLayer

public CanvasLayer getLayer()
Get the most immediate layer containing this figure.

Specified by:
getLayer in interface Figure
Overrides:
getLayer in class AbstractFigure

getOrigin

public java.awt.geom.Point2D getOrigin()
Return the origin of the wrapped figure in the enclosing transform context.

Specified by:
getOrigin in interface Figure
Overrides:
getOrigin in class AbstractFigure
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 interface CanvasComponent
Specified by:
getParent in interface Figure
Overrides:
getParent in class AbstractFigure

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 interface CanvasComponent
Overrides:
getTransformContext in class AbstractFigure

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 interface Figure
Specified by:
getShape in class AbstractFigure

getToolTipText

public java.lang.String getToolTipText()
Return the tooltip for this figure.

Specified by:
getToolTipText in interface Figure
Overrides:
getToolTipText in class AbstractFigure

getUserObject

public java.lang.Object getUserObject()
Return the user object.

Specified by:
getUserObject in interface UserObjectContainer
Overrides:
getUserObject in class AbstractFigure

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 interface Figure
Overrides:
hit in class AbstractFigure

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 interface Figure
Overrides:
intersects in class AbstractFigure

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 interface VisibleComponent
Overrides:
isVisible in class AbstractFigure

paint

public void paint(java.awt.Graphics2D g)
Paint the figure.

Specified by:
paint in interface VisibleComponent
Specified by:
paint in class AbstractFigure

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 interface VisibleComponent
Overrides:
paint in class AbstractFigure

relocate

public void relocate()
Tell the terminal to relocate itself because the attachment site (or the figure that owns it) has moved.

Specified by:
relocate in interface Terminal

repaint

public void repaint()
Schedule a repaint of the component. This should be called after performing modifications on the component.

Specified by:
repaint in interface CanvasComponent
Overrides:
repaint in class AbstractFigure

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 interface CanvasComponent
Overrides:
repaint in class AbstractFigure

setAttachSite

public void setAttachSite(Site s)
Set the site that the terminal is attached to.

Specified by:
setAttachSite in interface Terminal

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 interface Figure
Overrides:
setInteractor in class AbstractFigure

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 interface Figure
Overrides:
setParent in class AbstractFigure

setToolTipText

public void setToolTipText(java.lang.String tip)
Set the tool tip for this figure.

Specified by:
setToolTipText in interface Figure
Overrides:
setToolTipText in class AbstractFigure

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 interface Figure
Specified by:
transform in class AbstractFigure

translate

public void translate(double x,
                      double y)
Move the figure the indicated distance.

Specified by:
translate in interface Figure
Overrides:
translate in class AbstractFigure

setUserObject

public void setUserObject(java.lang.Object o)
Set the user object.

Specified by:
setUserObject in interface UserObjectContainer
Overrides:
setUserObject in class AbstractFigure

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 interface VisibleComponent
Overrides:
setVisible in class AbstractFigure