nodeNet
Class Node

java.lang.Object
  |
  +--nodeNet.Node

public class Node
extends java.lang.Object
implements NodeNetElement, java.io.Serializable

This class implements NodeNetElement. It is responsible for the GUI and maintains its own thread. It relies on a class that implements NodeBehavior to do anything. It repeatedly calls that class's act method from within a while(true) {} loop.

Copyright (c) 1998 Massachusetts Institute of Technology

See Also:
NodeNetElement, NodeBehavior, Serialized Form

Field Summary
static int GUISIZE
          Diameter of the circle used to paint nodes.
static java.awt.Color HIGHLIGHT_COLOR
           
 
Constructor Summary
Node(NodeBehavior nb, java.awt.Color c)
           
 
Method Summary
 void addInputChannel(InputChannel c)
          Adds a new InputChannel.
 void addOutputChannel(OutputChannel c)
          Adds a new OutputChannel.
 void configure()
          Nodes cannot currently be configured.
 void destroy()
          Destroy the Node.
 boolean equals(java.lang.Object o)
           
protected  void finalize()
           
static java.util.Enumeration getBehaviors()
          Gets an Enumeration of all currently known NodeBehaviors.
static java.awt.Color getColorFromBehavior(java.lang.String behavior)
          Returns the current Color associated with the given NodeBehavior.
 java.lang.String getName()
           
 java.awt.Point getPos()
           
 boolean isDestroyed()
           
 boolean isEditable()
           
 boolean isEnabled()
           
 boolean isInside(int x, int y)
           
 boolean isInside(java.awt.Point p)
           
 boolean isSelected()
           
 void notifyOfDestruction(NodeNetElement bse)
          Notify this that a NodeNetElement has been destroyed.
 void paint(java.awt.Graphics g)
           
 void removeInputChannel(InputChannel c)
          Removes an InputChannel.
 void removeOutputChannel(OutputChannel c)
          Removes an OutputChannel.
 void run()
          Repeatedly calls the transmitPacket method for the associated NodeBehavior.
 void setEnabled(boolean b)
           
 void setName(java.lang.String n)
           
 void setPos(int a, int b)
           
 void setPos(java.awt.Point p)
           
 void setSelected(boolean newState)
           
 void start()
          Starts the node running.
 void stop()
          Stops the node.
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GUISIZE

public static final int GUISIZE
Diameter of the circle used to paint nodes.

HIGHLIGHT_COLOR

public static final java.awt.Color HIGHLIGHT_COLOR
Constructor Detail

Node

public Node(NodeBehavior nb,
            java.awt.Color c)
Method Detail

getColorFromBehavior

public static java.awt.Color getColorFromBehavior(java.lang.String behavior)
Returns the current Color associated with the given NodeBehavior. If a mapping does not currently exist, a new one is created.
Parameters:
behavior - the NodeBehavior whose Color will be returned

getBehaviors

public static java.util.Enumeration getBehaviors()
Gets an Enumeration of all currently known NodeBehaviors.

setPos

public void setPos(java.awt.Point p)

setPos

public void setPos(int a,
                   int b)

getPos

public java.awt.Point getPos()

setSelected

public void setSelected(boolean newState)
Specified by:
setSelected in interface NodeNetElement

isSelected

public boolean isSelected()
Specified by:
isSelected in interface NodeNetElement

setEnabled

public void setEnabled(boolean b)
Specified by:
setEnabled in interface NodeNetElement

isEnabled

public boolean isEnabled()
Specified by:
isEnabled in interface NodeNetElement

setName

public void setName(java.lang.String n)
Specified by:
setName in interface NodeNetElement

getName

public java.lang.String getName()
Specified by:
getName in interface NodeNetElement

isInside

public boolean isInside(java.awt.Point p)
Specified by:
isInside in interface NodeNetElement

isInside

public boolean isInside(int x,
                        int y)
Specified by:
isInside in interface NodeNetElement

isEditable

public boolean isEditable()

configure

public void configure()
Nodes cannot currently be configured.
Specified by:
configure in interface NodeNetElement

addInputChannel

public void addInputChannel(InputChannel c)
Adds a new InputChannel. If the specified InputChannel already exists (as determined by the equals method), it is not added again. This condition is silently ignored.
Parameters:
c - the InputChannel to connect

removeInputChannel

public void removeInputChannel(InputChannel c)
Removes an InputChannel. If the specified InputChannel is not a current InputChannel for this Node (as determined by the equals method), this method does nothing.
Parameters:
c - the InputChannel to disconnect

addOutputChannel

public void addOutputChannel(OutputChannel c)
Adds a new OutputChannel. If the specified OutputChannel already exists (as determined by the equals method), it is not added again. This condition is silently ignored.
Parameters:
c - the OutputChannel to connect

removeOutputChannel

public void removeOutputChannel(OutputChannel c)
Removes an OutputChannel. If the specified OutputChannel is not a current OutputChannel for this Node (as determined by the equals method), this method does nothing.
Parameters:
c - the OutputChannel to disconnect

destroy

public void destroy()
Destroy the Node. destroy() should be called whenever a Node will no longer be used. When destroyed, Nodes notify all connected input and output channels of the impending destruction and remove refrences to those channels. Typically, this will force their destruction as well. Note: Node.finalize() automatically calls destroy().
Specified by:
destroy in interface NodeNetElement

isDestroyed

public boolean isDestroyed()
Specified by:
isDestroyed in interface NodeNetElement

notifyOfDestruction

public void notifyOfDestruction(NodeNetElement bse)
Notify this that a NodeNetElement has been destroyed. Typically, this method will be called by an input or output channel connected to the node. Once notified of destruction, all references to the element are removed.
Specified by:
notifyOfDestruction in interface NodeNetElement

paint

public void paint(java.awt.Graphics g)
Specified by:
paint in interface NodeNetElement

start

public void start()
Starts the node running. Once running, a node will repeatedly call the act method for it's associated NodeBehavior.
Specified by:
start in interface NodeNetElement

stop

public void stop()
Stops the node.
Specified by:
stop in interface NodeNetElement

run

public void run()
Repeatedly calls the transmitPacket method for the associated NodeBehavior. Note: This method should never be called directly. Instead, use the start() method.

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

finalize

protected void finalize()
                 throws java.io.IOException
Overrides:
finalize in class java.lang.Object