com.horstmann.violet.framework
Class AbstractNode

java.lang.Object
  extended by com.horstmann.violet.framework.AbstractNode
All Implemented Interfaces:
Node, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
PointNode, RectangularNode

public abstract class AbstractNode
extends java.lang.Object
implements Node

A class that supplies convenience implementations for a number of methods in the Node interface

See Also:
Serialized Form

Field Summary
static int SHADOW_GAP
           
 
Constructor Summary
AbstractNode()
          Constructs a node with no parents or children.
 
Method Summary
 void addChild(int index, Node node)
          Adds a child node.
 void addChild(Node node)
           
 boolean addEdge(Edge e, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
          Adds an edge that originates at this node.
 boolean addNode(Node n, java.awt.geom.Point2D p)
          Adds a node as a child node to this node.
 java.lang.Object clone()
           
 void draw(java.awt.Graphics2D g2)
          Draw the node.
 java.util.List getChildren()
          Gets the children of this node.
 Node getParent()
          Gets the parent of this node.
 java.awt.Shape getShape()
           
 void layout(Graph g, java.awt.Graphics2D g2, Grid grid)
          Lays out the node and its children.
 void removeChild(Node node)
          Removes a child node.
 void removeEdge(Graph g, Edge e)
          Notifies this node that an edge is being removed.
 void removeNode(Graph g, Node e)
          Notifies this node that a node is being removed.
 void setParent(Node node)
          Sets the parent of this node.
static void setPersistenceDelegate(java.beans.Encoder encoder)
          Adds a persistence delegate to a given encoder that encodes the child nodes of this node.
 void translate(double dx, double dy)
          Translates the node by a given amount
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.horstmann.violet.framework.Node
contains, getBounds, getConnectionPoint
 

Field Detail

SHADOW_GAP

public static final int SHADOW_GAP
See Also:
Constant Field Values
Constructor Detail

AbstractNode

public AbstractNode()
Constructs a node with no parents or children.

Method Detail

clone

public java.lang.Object clone()
Specified by:
clone in interface Node
Overrides:
clone in class java.lang.Object

translate

public void translate(double dx,
                      double dy)
Description copied from interface: Node
Translates the node by a given amount

Specified by:
translate in interface Node
Parameters:
dx - the amount to translate in the x-direction
dy - the amount to translate in the y-direction

addEdge

public boolean addEdge(Edge e,
                       java.awt.geom.Point2D p1,
                       java.awt.geom.Point2D p2)
Description copied from interface: Node
Adds an edge that originates at this node.

Specified by:
addEdge in interface Node
Parameters:
e - the edge to add
Returns:
true if the edge was added

removeEdge

public void removeEdge(Graph g,
                       Edge e)
Description copied from interface: Node
Notifies this node that an edge is being removed.

Specified by:
removeEdge in interface Node
Parameters:
g - the ambient graph
e - the edge to be removed

removeNode

public void removeNode(Graph g,
                       Node e)
Description copied from interface: Node
Notifies this node that a node is being removed.

Specified by:
removeNode in interface Node
Parameters:
g - the ambient graph
e - the node to be removed

layout

public void layout(Graph g,
                   java.awt.Graphics2D g2,
                   Grid grid)
Description copied from interface: Node
Lays out the node and its children.

Specified by:
layout in interface Node
Parameters:
g - the ambient graph
g2 - the graphics context
grid - the grid to snap to

addNode

public boolean addNode(Node n,
                       java.awt.geom.Point2D p)
Description copied from interface: Node
Adds a node as a child node to this node.

Specified by:
addNode in interface Node
Parameters:
n - the child node
p - the point at which the node is being added
Returns:
true if this node accepts the given node as a child

getParent

public Node getParent()
Description copied from interface: Node
Gets the parent of this node.

Specified by:
getParent in interface Node
Returns:
the parent node, or null if the node has no parent

setParent

public void setParent(Node node)
Description copied from interface: Node
Sets the parent of this node.

Specified by:
setParent in interface Node
Parameters:
node - the parent node, or null if the node has no parent

getChildren

public java.util.List getChildren()
Description copied from interface: Node
Gets the children of this node.

Specified by:
getChildren in interface Node
Returns:
an unmodifiable list of the children

addChild

public void addChild(int index,
                     Node node)
Description copied from interface: Node
Adds a child node.

Specified by:
addChild in interface Node
Parameters:
index - the position at which to add the child
node - the child node to add

addChild

public void addChild(Node node)

removeChild

public void removeChild(Node node)
Description copied from interface: Node
Removes a child node.

Specified by:
removeChild in interface Node
Parameters:
node - the child to remove.

draw

public void draw(java.awt.Graphics2D g2)
Description copied from interface: Node
Draw the node.

Specified by:
draw in interface Node
Parameters:
g2 - the graphics context

getShape

public java.awt.Shape getShape()
Returns:
the shape to be used for computing the drop shadow

setPersistenceDelegate

public static void setPersistenceDelegate(java.beans.Encoder encoder)
Adds a persistence delegate to a given encoder that encodes the child nodes of this node.

Parameters:
encoder - the encoder to which to add the delegate