Graphics2D Actor API

g2d.graph
Class IOPNode

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.IOPNode
All Implemented Interfaces:
KeyListener, MouseListener, MouseMotionListener, EventListener

public class IOPNode
extends GraphItem

A node object for IOPGraph. Nodes are distinguished uniquely by their name. The name is set at construction time and is used for testing of equality. The name must be non-null otherwise runtime exceptions are thrown.

A node consists of a rectangular base glyph and a label (if not "") that is drawn as text above the base glyph. The label is always centered on top of the base. The base can have the shape of a rectangle/box or an ellipse. Following is a table showing which methods pertain to the base, label, and whole node.

rectangular base
textual label
whole node

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

Field Summary
 
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
IOPNode(IOPNode clone)
          Construct a node cloning the given node.
IOPNode(String name)
          Construct default node with given name and no label.
IOPNode(String name, String label, String shape, Color borderColor, Color fillColor)
          Construct node with given name and label and use given attributes to create node base.
 
Method Summary
 void dehighlight()
          Remove background shapes used for highlighting.
 double distanceTo(Point2D p)
          Calculate distance from this node to given point.
 boolean equals(Object o)
          Two nodes are equal if their name is the same.
 Rectangle2D getBaseFrame()
          Get rectangle of frame that defines shape of node base.
 Color getBorderColor()
          Get the border color of the node base.
 Point2D getCenter()
          Obtain center point of this node in double precision.
 Color getFillColor()
          Get color used for filling the node base.
 double getHeight()
          Get height of node (including base and label) in double precision.
 String getLabel()
          Get text of node label.
 String getName()
          Get the name of this node.
 String getNodeShape()
          Get a string describing the shape of the node base.
 Point2D getPosition()
          Get position of node as the top-left corner.
 double getWidth()
          Get width of node (including base and label) in double precision.
 int hashCode()
          Overriding method to comply with equals(Object).
 void highlight()
          Highlight this node by drawing a background shape in GraphItem.HIGHLIGHT color overlapping by GraphItem.HIGHLIGHT_OFFSET pixels.
 void paint(Graphics2D g2d)
           
 void setBaseCenter(Point2D center)
          Set position of node base to given center point.
 void setBaseDimension(double width, double height)
          Set size of node base.
 void setBorderColor(Color color)
          Set the border color of the node base.
 void setCenter(Point2D center)
          Move this node to given center point.
 void setFillColor(Color color)
          Set the fill color of the node base.
 void setLabel(String label)
          Set the text of node label.
 void setNodeShape(String shape)
          Set the shape of the node base.
 String toString()
           
 
Methods inherited from class g2d.graph.GraphItem
getBounds, inside, intersects, 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
 

Constructor Detail

IOPNode

public IOPNode(String name)
Construct default node with given name and no label.

Parameters:
name - String identifying node

IOPNode

public IOPNode(String name,
               String label,
               String shape,
               Color borderColor,
               Color fillColor)
Construct node with given name and label and use given attributes to create node base.

Parameters:
name - String identifying node
label - String with label for node
shape - String defining shape of node base (such as "box", "rectangle", or "ellipse" [default value])
borderColor - Color of node base border
fillColor - Color used for filling node base

IOPNode

public IOPNode(IOPNode clone)
Construct a node cloning the given node. The resulting new node will have the same name, same label, and same node base (w.r.t. shape, colors, size, position) of the given node to clone. It also inherits all attributes from the clone.

Parameters:
clone - IOPNode to be cloned
Method Detail

getName

public String getName()
Get the name of this node. Will never return null.

Returns:
String with name of this node

getCenter

public Point2D getCenter()
Obtain center point of this node in double precision.

Returns:
Point that denotes center of this node
See Also:
setCenter(java.awt.geom.Point2D)

setCenter

public void setCenter(Point2D center)
Move this node to given center point.

Parameters:
center - Point that denotes new center of this node
See Also:
getCenter()

setNodeShape

public void setNodeShape(String shape)
Set the shape of the node base. If shape is either "box" or "rectangle" the node base will be rectangular. Otherwise, the node shape is an ellipse.

The change will become visible once the container of this node repaints.

Parameters:
shape - String describing the shape of node base
See Also:
getNodeShape()

getNodeShape

public String getNodeShape()
Get a string describing the shape of the node base.

Returns:
String describing the shape of node base
See Also:
setNodeShape(java.lang.String)

setFillColor

public void setFillColor(Color color)
Set the fill color of the node base.

The change will become visible once the container of this node repaints.

Parameters:
color - Color used for filling node base
See Also:
getFillColor()

getFillColor

public Color getFillColor()
Get color used for filling the node base.

Returns:
Color used for filling node base
See Also:
setFillColor(java.awt.Color)

setBorderColor

public void setBorderColor(Color color)
Set the border color of the node base.

The change will become visible once the container of this node repaints.

Parameters:
color - Color used for border of node base
See Also:
getBorderColor()

getBorderColor

public Color getBorderColor()
Get the border color of the node base.

Returns:
Color used for border of node base
See Also:
setBorderColor(java.awt.Color)

setBaseDimension

public void setBaseDimension(double width,
                             double height)
Set size of node base.

The change will become visible once the container of this node repaints.

Parameters:
width - Width of node base in double precision
height - Height of node base in double precision

setBaseCenter

public void setBaseCenter(Point2D center)
Set position of node base to given center point.

The change will become visible once the container of this node repaints.

Parameters:
center - Point denoting center of node base

getBaseFrame

public Rectangle2D getBaseFrame()
Get rectangle of frame that defines shape of node base.

Returns:
Rectangle that is frame of node base

setLabel

public void setLabel(String label)
Set the text of node label. Passing null or an empty string results in label not drawn.

The change will become visible once the container of this node repaints.

Parameters:
label - Text of node label
See Also:
getLabel()

getLabel

public String getLabel()
Get text of node label.

Returns:
String with text of node label (will not be NULL)
See Also:
setLabel(java.lang.String)

getWidth

public double getWidth()
Get width of node (including base and label) in double precision.

Returns:
width of node

getHeight

public double getHeight()
Get height of node (including base and label) in double precision.

Returns:
height of node

getPosition

public Point2D getPosition()
Get position of node as the top-left corner.

Returns:
point denoting position of node

distanceTo

public double distanceTo(Point2D p)
Calculate distance from this node to given point. If point is inside this shape, returns 0.0. Otherwise, uses distance to center point of bounds.

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

highlight

public void highlight()
Highlight this node by drawing a background shape in GraphItem.HIGHLIGHT color overlapping by GraphItem.HIGHLIGHT_OFFSET pixels.

Specified by:
highlight in class GraphItem

dehighlight

public void dehighlight()
Remove background shapes used for highlighting.

Specified by:
dehighlight in class GraphItem

paint

public void paint(Graphics2D g2d)
Overrides:
paint in class GraphItem

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object o)
Two nodes are equal if their name is the same.

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

hashCode

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

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

Graphics2D Actor API