Graphics2D Actor API

g2d.graph
Class IOPEdge

java.lang.Object
  extended by g2d.glyph.Identifiable
      extended by g2d.glyph.Attributable
          extended by g2d.glyph.Glyphish
              extended by g2d.graph.GraphItem
                  extended by g2d.graph.IOPEdge
All Implemented Interfaces:
KeyListener, MouseListener, MouseMotionListener, EventListener

public class IOPEdge
extends GraphItem

An edge object for IOPGraph. Edges are defined by their source and sink given as IOPNodes. These two nodes are given at object construction time and must be non-null.

An edge manifests itself as a spline and two arrow heads. Similar to the implementation of IOPNode, these glyphish things are instantiated at construction time and remain non-null. The interface of this class allows then to change the appearance of the edge, which will propagate into changing the sub-glyphs accordingly.

Since:
August 2004
Author:
Ben Funnell, Linda (rewriting and more documentation)

Field Summary
static String BOLD
          Style of a bold line (twice current stroke width) for this edge.
static String DASHED
          Style of a dashed line for this edge.
static String DOTTED
          Style of a dotted line for this edge.
static String INVIS
          Style of a invisible line for this edge.
static String SOLID
          Style of a solid line for this edge.
 
Fields inherited from class g2d.graph.GraphItem
antiAliased, HIGHLIGHT, HIGHLIGHT_OFFSET
 
Fields inherited from class g2d.glyph.Glyphish
DEBUG
 
Fields inherited from class g2d.glyph.Identifiable
uid
 
Constructor Summary
IOPEdge(IOPEdge clone, IOPNode newSource, IOPNode newSink)
          Constructs a new edge cloning the given edge with the new endpoints of given nodes.
IOPEdge(IOPNode source, IOPNode sink)
          Constructs a bare edge (no arrow heads) between two given nodes.
IOPEdge(IOPNode source, IOPNode sink, Color c)
          Constructs a bare edge (no arrow heads) between two given nodes with the given color.
 
Method Summary
 void dehighlight()
          Revert highlighting to previous state (if any).
 double distanceTo(Point2D p)
          Calculate distance from this edge to given point.
 boolean equals(Object o)
          Two edges are equal if their source and sink nodes are equal.
 Color getColor()
          Obtain current color of edge.
 IOPNode getSink()
          Obtain sink node of this edge.
 IOPNode getSource()
          Obtain source node of this edge.
 float getStrokeWidth()
          Obtain current stroke width.
 String getStyle()
          Obtain String describing current style.
 int hashCode()
          Overriding method to comply with equals(Object).
 void highlight()
          Highlight this edge by drawing it in GraphItem.HIGHLIGHT color.
 boolean isDoubleEnded()
          Query current setting of being double ended (i.e., having two arrow heads, one at each end).
 void setColor(Color c)
          Set color of edge to given value.
 void setDoubleEnded(boolean value)
          Set whether this edge has arrow heads on both ends or not.
 void setStrokeWidth(float width)
          Set current stroke width to the given value.
 void setStyle(String style)
          Set current style to one described by given String.
 String toString()
          The String representation conforming to DOT format of edges, for example: "20 -> 4".
 void updatePoints(List points, Point2D arrowTipSource, Point2D arrowTipSink)
          Update the curve of this edge using given list of points.
 
Methods inherited from class g2d.graph.GraphItem
getBounds, inside, intersects, paint, transform
 
Methods inherited from class g2d.glyph.Glyphish
keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, paint, rotate, rotate, scale, setKeyAction, setMouseAction, shear, translate
 
Methods inherited from class g2d.glyph.Attributable
getAttribute, getAttributeAsBoolean, getAttributeAsByte, getAttributeAsChar, getAttributeAsDouble, getAttributeAsFloat, getAttributeAsInt, getAttributeAsShort, getAttributeAsString, getKeys, getStaticAttribute, getStaticKeys, isAttribute, isStaticAttribute, setAttribute, setStaticAttribute
 
Methods inherited from class g2d.glyph.Identifiable
getObject, getUID, setUID
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SOLID

public static final String SOLID
Style of a solid line for this edge.

See Also:
setStyle(java.lang.String), Constant Field Values

DASHED

public static final String DASHED
Style of a dashed line for this edge.

See Also:
setStyle(java.lang.String), Constant Field Values

DOTTED

public static final String DOTTED
Style of a dotted line for this edge.

See Also:
setStyle(java.lang.String), Constant Field Values

BOLD

public static final String BOLD
Style of a bold line (twice current stroke width) for this edge.

See Also:
setStyle(java.lang.String), Constant Field Values

INVIS

public static final String INVIS
Style of a invisible line for this edge.

See Also:
setStyle(java.lang.String), Constant Field Values
Constructor Detail

IOPEdge

public IOPEdge(IOPNode source,
               IOPNode sink)
Constructs a bare edge (no arrow heads) between two given nodes. If not changing appearance of this edge using e.g. updatePoints(java.util.List, java.awt.geom.Point2D, java.awt.geom.Point2D), this will be a straight line between the center points of the two nodes.

Parameters:
source - IOPNode that is source (or start/tail) of this edge
sink - IOPNode that is sink (or end/head) of this edge

IOPEdge

public IOPEdge(IOPNode source,
               IOPNode sink,
               Color c)
Constructs a bare edge (no arrow heads) between two given nodes with the given color. If not changing appearance of this edge using e.g. updatePoints(java.util.List, java.awt.geom.Point2D, java.awt.geom.Point2D), this will be a straight line between the center points of the two nodes.

Parameters:
source - IOPNode that is source (or start/tail) of this edge
sink - IOPNode that is sink (or end/head) of this edge
c - Color of this edge

IOPEdge

public IOPEdge(IOPEdge clone,
               IOPNode newSource,
               IOPNode newSink)
Constructs a new edge cloning the given edge with the new endpoints of given nodes. The resulting edge has the same color, stroke width, style, and points defining spline and arrow heads. It also inherits all attributes from the clone.

Parameters:
clone - IOPEdge to be cloned
newSource - IOPNode used as the new source node of this edge
newSink - IOPNode used as the new sink of this edge
Method Detail

getSource

public IOPNode getSource()
Obtain source node of this edge.

Returns:
IOPNode that is the source of this edge

getSink

public IOPNode getSink()
Obtain sink node of this edge.

Returns:
IOPNode that is the sink of this edge

updatePoints

public void updatePoints(List points,
                         Point2D arrowTipSource,
                         Point2D arrowTipSink)
Update the curve of this edge using given list of points. The list must have at least 2 points. Throws an exception if given points are null or the list is less than 2 points long.

The two points given denote the arrow tips of arrows at start and end of edge, respectively. If any of these is null then no arrow at that part of edge is drawn.

Parameters:
points - Ordered list of 3n+1 points to be used to define the cubic curve segments of the edge
arrowTipSource - Point2D of arrow tip at start of edge (if any)
arrowTipSink - Point2D of arrow tip at end of edge (if any)

getColor

public Color getColor()
Obtain current color of edge.

Returns:
Color of edge
See Also:
setColor(java.awt.Color)

setColor

public void setColor(Color c)
Set color of edge to given value.

Note, to have change take effect visually need to issue repainting of container.

Parameters:
c - Color used for edge
See Also:
getColor()

setDoubleEnded

public void setDoubleEnded(boolean value)
Set whether this edge has arrow heads on both ends or not. May override current setting, which is also influenced by the updatePoints(java.util.List, java.awt.geom.Point2D, java.awt.geom.Point2D) method. In case of overriding the setting with true, the angle of the arrow head at the source is estimated by the first line segment of the edge.

Parameters:
value - Boolean denoting whether this edge has two arrow heads or not

isDoubleEnded

public boolean isDoubleEnded()
Query current setting of being double ended (i.e., having two arrow heads, one at each end).

Returns:
true if this edge shows two arrow heads and false otherwise.

getStyle

public String getStyle()
Obtain String describing current style.

Returns:
String describing current style
See Also:
setStyle(java.lang.String), SOLID, DASHED, DOTTED, BOLD, INVIS

setStyle

public void setStyle(String style)
Set current style to one described by given String.

Note, to have change take effect visually need to issue repainting of container.

Parameters:
style - String describing style
See Also:
getStyle(), SOLID, DASHED, DOTTED, BOLD, INVIS

getStrokeWidth

public float getStrokeWidth()
Obtain current stroke width.

Returns:
current stroke width as a float
See Also:
setStrokeWidth(float)

setStrokeWidth

public void setStrokeWidth(float width)
Set current stroke width to the given value.

Note, to have change take effect visually need to issue repainting of container.

Parameters:
width - Value of stroke width
See Also:
getStrokeWidth()

distanceTo

public double distanceTo(Point2D p)
Calculate distance from this edge to given point. Uses approximate distance to spline representing the line in the arrow and neglects the arrow head.

Specified by:
distanceTo in class GraphItem
Parameters:
p - Point to compute distance to
Returns:
distance to point

highlight

public void highlight()
Highlight this edge by drawing it in GraphItem.HIGHLIGHT color.

Specified by:
highlight in class GraphItem

dehighlight

public void dehighlight()
Revert highlighting to previous state (if any).

Specified by:
dehighlight in class GraphItem

toString

public String toString()
The String representation conforming to DOT format of edges, for example: "20 -> 4".

Overrides:
toString in class Object
Returns:
String representation of edge conforming to DOT format

hashCode

public int hashCode()
Overriding method to comply with equals(Object).

Overrides:
hashCode in class Object
Returns:
hash value of this IOPNode

equals

public boolean equals(Object o)
Two edges are equal if their source and sink nodes are equal.

Overrides:
equals in class Object
Parameters:
o - Object to test equality with this IOPEdge
Returns:
true if this IOPEdge is equal to given Object, false otherwise
See Also:
Object.equals(java.lang.Object)

Graphics2D Actor API