templates.diagram
Class Connector

java.lang.Object
  extended by templates.diagram.DiagramElement
      extended by templates.diagram.Connector

public class Connector
extends DiagramElement

Class to maintain the graphical representation of TemplateLinks.

Author:
Lenko Grigorov

Nested Class Summary
protected  class Connector.EventBox
          Encapsulation of a graphical element which displays the events linked through a Connector.
 
Field Summary
protected static java.awt.Color BACKGROUND_COLOR
          Background color for the event boxes at the ends of the connector.
protected  Connector.EventBox centerEventBox
          The event box in the center of the connector, displaying the event pairs linked by the connector.
protected static int LABEL_SPACING
          Offset of the event boxes in pixels, to produce spacing around the event boxes.
protected  Entity left
          The "left" component linked by the connector.
protected  Connector.EventBox leftEventBox
          The event box listing the events of the "left" component which are linked by the connector.
protected  java.awt.geom.Line2D line
          The line that represents the connector.
protected  java.util.Collection<TemplateLink> links
          The TemplateLinks visualized by this connector.
static int ON_LABEL
          Constant to say mouse cursor is over the event box in the center of the connector.
static int ON_LINE
          Constant to say mouse cursor is over the line of the connector.
static int ON_NADA
          Constant to say mouse cursor is not over any part of the connector.
protected  Entity right
          The "right" component linked by the connector.
protected  Connector.EventBox rightEventBox
          The event box listing the events of the "right" component which are linked by the connector.
 
Fields inherited from class templates.diagram.DiagramElement
COLOR_INCONSIST, COLOR_NORM, COLOR_SELECT, COLOR_SELECT_INCONSIST, FAT_LINE_STROKE, globalFont, globalFontRenderer, highlight, inconsistent, LINE_STROKE, MARKER_STROKE, selected
 
Constructor Summary
Connector(Entity left, Entity right, java.util.Collection<TemplateLink> links)
          Construct a connector with the given parameters.
 
Method Summary
 void addLink(TemplateLink link)
          Add a TemplateLink to the collection of links represented by the connector.
protected  void computeBounds()
          Computes the bounds of the connector (smallest rectangle containing all elements of the connector) and caches the result.
 boolean contains(java.awt.Point p)
          Checks if the diagram element contains the given point.
 void draw(java.awt.Graphics2D g2d)
          Render the diagram element in the given graphical context, disregarding the inconsistency setting.
 void draw(java.awt.Graphics2D g2d, boolean showInconsistency)
          Render the diagram element in the given graphical context, according to the choice of differentiating or not inconsistent diagram elements.
 java.awt.Rectangle getBounds()
          Retrieve the bounds of the diagram element.
 Entity[] getEntities()
          Retrieve the two Entitys linked by the connector.
 Entity getLeftEntity()
          Retrieve the "left" Entity linked by the connector.
 java.util.Collection<TemplateLink> getLinks()
          Retrieve the TemplateLinks encapsulated by the connector.
 Entity getRightEntity()
          Retrieve the "right" Entity linked by the connector.
 boolean intersects(java.awt.Rectangle r)
          Checks if the given rectangle intersects the diagram element.
 void removeLink(TemplateLink link)
          Remove a TemplateLink from the collection of links represented by this connector.
 void translate(java.awt.Point delta)
          NOTE: Do not use this method directly.
 void update()
          Updates the connector to reflect any changes to the location of the linked Entitys and/or the events being linked.
 int whereisPoint(java.awt.Point p)
          Checks on which part of the connector a given point lies.
 
Methods inherited from class templates.diagram.DiagramElement
getGlobalFont, getGlobalFontMetrics, getGlobalFontRenderer, setGlobalFont, setGlobalFontRenderer, setHighlight, setInconsistent, setSelected
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BACKGROUND_COLOR

protected static java.awt.Color BACKGROUND_COLOR
Background color for the event boxes at the ends of the connector.


LABEL_SPACING

protected static final int LABEL_SPACING
Offset of the event boxes in pixels, to produce spacing around the event boxes.

See Also:
Constant Field Values

ON_NADA

public static final int ON_NADA
Constant to say mouse cursor is not over any part of the connector.

See Also:
whereisPoint(Point), Constant Field Values

ON_LINE

public static final int ON_LINE
Constant to say mouse cursor is over the line of the connector.

See Also:
whereisPoint(Point), Constant Field Values

ON_LABEL

public static final int ON_LABEL
Constant to say mouse cursor is over the event box in the center of the connector.

See Also:
whereisPoint(Point), Constant Field Values

links

protected java.util.Collection<TemplateLink> links
The TemplateLinks visualized by this connector.


left

protected Entity left
The "left" component linked by the connector.

A connector is symmetric. "Left" and "right" are used only to enable addressing the two linked components separately.


right

protected Entity right
The "right" component linked by the connector.

A connector is symmetric. "Left" and "right" are used only to enable addressing the two linked components separately.


line

protected java.awt.geom.Line2D line
The line that represents the connector.


leftEventBox

protected Connector.EventBox leftEventBox
The event box listing the events of the "left" component which are linked by the connector.

A connector is symmetric. "Left" and "right" are used only to enable addressing the two linked components separately.


rightEventBox

protected Connector.EventBox rightEventBox
The event box listing the events of the "right" component which are linked by the connector.

A connector is symmetric. "Left" and "right" are used only to enable addressing the two linked components separately.


centerEventBox

protected Connector.EventBox centerEventBox
The event box in the center of the connector, displaying the event pairs linked by the connector.

Constructor Detail

Connector

public Connector(Entity left,
                 Entity right,
                 java.util.Collection<TemplateLink> links)
Construct a connector with the given parameters.

Parameters:
left - the "left" component to be linked by the connector
right - the "right" component to be linked by the connector
links - a collection of the TemplateLinks to be encapsulated by the connector (can be empty)

A connector is symmetric. "Left" and "right" are used only to enable addressing the two linked components separately.

Method Detail

getLinks

public java.util.Collection<TemplateLink> getLinks()
Retrieve the TemplateLinks encapsulated by the connector. If there are no links associated with this connector, the returned collection is empty.

Returns:
the TemplateLinks encapsulated by the connector

getLeftEntity

public Entity getLeftEntity()
Retrieve the "left" Entity linked by the connector.

A connector is symmetric. "Left" and "right" are used only to enable addressing the two linked components separately.

Returns:
the "left" Entity linked by the connector

getRightEntity

public Entity getRightEntity()
Retrieve the "right" Entity linked by the connector.

A connector is symmetric. "Left" and "right" are used only to enable addressing the two linked components separately.

Returns:
the "right" Entity linked by the connector

getEntities

public Entity[] getEntities()
Retrieve the two Entitys linked by the connector.

Returns:
the two Entitys linked by the connector

addLink

public void addLink(TemplateLink link)
Add a TemplateLink to the collection of links represented by the connector. The link must be between the two TemplateComponents already linked by the connector.

NOTE: Do not use this method directly. Use TemplateDiagram.addLink(Connector, TemplateLink) instead.

Parameters:
link - the TemplateLink to be added to the collection of links represented by the connector
Throws:
InconsistentModificationException - if the TemplateLink to be added does not link the same TemplateComponents linked by the connector

removeLink

public void removeLink(TemplateLink link)
Remove a TemplateLink from the collection of links represented by this connector. If the link is not part of the collection, the method does nothing.

NOTE: Do not use this method directly. Use TemplateDiagram.removeLink(Connector, TemplateLink) instead.

Parameters:
link - the TemplateLink to remove from the collection of links represented by this connector

draw

public void draw(java.awt.Graphics2D g2d)
Description copied from class: DiagramElement
Render the diagram element in the given graphical context, disregarding the inconsistency setting. I.e., inconsistent diagram elements should be rendered as if they were consistent.

Specified by:
draw in class DiagramElement
Parameters:
g2d - the graphical context where the diagram element has to be rendered

draw

public void draw(java.awt.Graphics2D g2d,
                 boolean showInconsistency)
Description copied from class: DiagramElement
Render the diagram element in the given graphical context, according to the choice of differentiating or not inconsistent diagram elements.

Specified by:
draw in class DiagramElement
Parameters:
g2d - the graphical context where the diagram element has to be rendered
showInconsistency - choice for rendering inconsistent diagram elements differently or not; if true, inconsistent diagram elements have to be rendered differently; iffalse, inconsistent diagram elements should be rendered as if they were consistent

translate

public void translate(java.awt.Point delta)
NOTE: Do not use this method directly. Use TemplateDiagram.translate(Collection, Point) instead.

Specified by:
translate in class DiagramElement
Parameters:
delta - the displacement in the x and y direction

getBounds

public java.awt.Rectangle getBounds()
Description copied from class: DiagramElement
Retrieve the bounds of the diagram element.

Specified by:
getBounds in class DiagramElement
Returns:
the smallest rectangle containing all parts of the diagram element

computeBounds

protected void computeBounds()
Computes the bounds of the connector (smallest rectangle containing all elements of the connector) and caches the result.

See Also:
bounds

update

public void update()
Updates the connector to reflect any changes to the location of the linked Entitys and/or the events being linked. In essence, recomputes how the connector should be rendered. The layout of connectors is computed in its entirety, no layout information needs to be preserved between sessions.


contains

public boolean contains(java.awt.Point p)
Description copied from class: DiagramElement
Checks if the diagram element contains the given point.

With non-rectangular diagram elements, this is different from checking if the point is contained within the bounds of the element. More specifically, a point may be contained within the bounds, but this method may still return false.

Specified by:
contains in class DiagramElement
Parameters:
p - the point to be checked
Returns:
true if the diagram element contains the point; false otherwise

intersects

public boolean intersects(java.awt.Rectangle r)
Description copied from class: DiagramElement
Checks if the given rectangle intersects the diagram element.

With non-rectangular diagram elements, this is different from checking if the rectangle intersects the bounds of the element. More specifically, a rectangle may intersect the bounds, but this method may still return false.

Specified by:
intersects in class DiagramElement
Parameters:
r - the rectangle to be checked
Returns:
true if the rectangle intersects the diagram element; false otherwise

whereisPoint

public int whereisPoint(java.awt.Point p)
Checks on which part of the connector a given point lies. The answer can be the line representing the connector, the event box in the center of the connector, or nothing (i.e., the point does not lie on the connector).

Parameters:
p - the point to be checked
Returns:
which part of the connector the point lies on (ON_LINE, ON_LABEL or ON_NADA)