torero.gui
Class GrammarNode

java.lang.Object
  |
  +--torero.gui.GrammarNode
All Implemented Interfaces:
TreeNode
Direct Known Subclasses:
GrammarRoot

public class GrammarNode
extends Object
implements TreeNode

This class is an hybrid class betweem gui and model components. It is derived from a gui class, the TreeNode which is used by the JTree per default, and encapsulates the model information (a symbol with attributes) for a node in a tree view. Accutally a tree in torero is build up from NodeWrapper classes, but they hold a referece to a grammar node. Note that there is a specialized class for the root grammar node (GrammarRoot). Implementation details: Grammar node hold a lookup cache (destlookup) with an entry for every assignment which has this GrammarNode as its destination. The keys (destination) are of type Attribute, the values (sources) are of type SrcAtt (encapsulating a GrammarNode and an Attribute. This information is used for an (efficient) routing algorithm of attribute connections.

See Also:
GrammarRoot, MyTreeUI, NodeWrapper

Field Summary
protected  int chldcnt
          Number of sources of assignments from children to this node.
protected  OneToManyMap destlookup
          A lookup cache containing all destinations of assignments from this node to other nodes.
protected  int parcnt
          Number of sources of assignments from the nodes parent to this node.
protected  int sibcnt
          Number of sources of assignments from siblings to this node.
protected  int slfcnt
          Number of sources of assignments from the nodes itself to the node itself.
 
Constructor Summary
GrammarNode(AttributeGrammar ag, Derivat derivat, Production.ListElement node, GrammarNode parent)
          Creates a new grammar node.
 
Method Summary
protected  void ACDCacheInit()
           
protected  GrammarNode checkIfChildSource(GrammarNode mgtn)
          For every assignment from the given GrammarNode mgtn (which must be a child of this) to itself (this), it put's an entry in the destination lookup chache.
protected  void checkIfParentSource()
          For every assignment from the node's parent to itself (this), it put's an entry in the destination lookup chache.
protected  void checkIfSelfTraversalSource()
          For every assignment (with destination of type traversal) from the node to itself (this), it put's an entry in the destination lookup chache.
protected  GrammarNode checkIfSiblingSource(GrammarNode mgtn)
          For every assignment from the given GrammarNode mgtn (which must be a "sibling" of this, or the node itself (mgtn=this)) to itself (this), it put's an entry in the destination lookup chache.
 Enumeration children()
          Tells this node to produce its children acording to the derivat object.
 void clearDestLookupCache()
          Empties the destination lookup cache.
protected  int getACDPos(Attribute atr)
          Get the position of the given attribute (traversal).
 int getACDSize()
          Get the number of attributes+traversals assigned to this node.
 Iterator getAllDests()
          Get all destination (key values) from the destination lookup cache (see class description of GrammarNode).
 boolean getAllowsChildren()
          See if this node can procduce children.
 int getAttribHeigh()
          Get the height of the attributes+traversals displayed by this node. return the height of the attriubtes+traversals [pixel].
 int getAttribPosY(Attribute a)
          Get the relative y position of the given attribute (traversal).
 Object[] getAttributeCellDataArray()
          Get all ACDCache entries as object arrray.
 AttributeGrammar getAttributeGrammar()
          Get the referenced AttributeGrammar.
 int getAttribWidth()
          Get the width of the attribute (traversal) part of this node, it's the maximum of all attributes in the node.
 TreeNode getChildAt(int childIndex)
          Get the child object at the given position (from left to right).
 int getChildCount()
          Get the actual (none are produced by this call) number of children.
 Derivat getDerivat()
          Get the referenced derivat.
 int getDestCnt()
          Get the number of displayed attributes+traversals of this node.
 int getIndex(TreeNode tn)
          Get the position of the given (child) object.
 Derivat getItsSubDerivation()
          Get the derivat object that can be produced by extending this node in the tree.
 Production.ListElement getListElement()
          Get the referenced listelement.
 int getNodeWidth()
          Get the width of the node, actually this is the width of the symbol.
 TreeNode getParent()
          Get the parent TreeNode of the this node.
 int getselectedAttrib()
          Get the selected attribute (traversal).
 Iterator getSources(Attribute destattrib)
          Get all source values for a given key attribute (destination) from the destination lookup cache (see class description of GrammarNode).
 int getSymbolHeigh()
          Get the height of the referenced symbol [pixel]
 boolean isLeaf()
          See if this node can be expanded.
 boolean isRoot()
          Returns false for this class.
protected  void NodeInit()
          Initializes the GrammarNode, is called by the constructior, after ACDCacheInit().
 void processMouseEvent(int xrel, int yrel, MouseEvent e, DefaultTreeModel tm)
          Tells the node that a mouseevent has occured in it's area of interest.
 void setAttribHeight(int h)
          Do not use this function.
protected  void setAttribWidth(int w)
          Do not use this function.
 void setNodeWidth(int w)
          Do not use this function.
 void setSymbolHeight(int h)
          Do not use this function.
 String toString()
          Get a textual representation of this node, actually calls the toString method on the referenced Symbol.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

destlookup

protected OneToManyMap destlookup
A lookup cache containing all destinations of assignments from this node to other nodes.

sibcnt

protected int sibcnt
Number of sources of assignments from siblings to this node.

chldcnt

protected int chldcnt
Number of sources of assignments from children to this node.

parcnt

protected int parcnt
Number of sources of assignments from the nodes parent to this node.

slfcnt

protected int slfcnt
Number of sources of assignments from the nodes itself to the node itself.
Constructor Detail

GrammarNode

public GrammarNode(AttributeGrammar ag,
                   Derivat derivat,
                   Production.ListElement node,
                   GrammarNode parent)
Creates a new grammar node.
Parameters:
ag - a reference to the attribute grammar
derivat - this node can be expanded by using this derivat
node - the listelement this grammar node encapsulates
parent - the parent of this grammar node
See Also:
Production.ListElement
Method Detail

ACDCacheInit

protected void ACDCacheInit()

getACDSize

public int getACDSize()
Get the number of attributes+traversals assigned to this node.
Returns:
the number of attributes+traversals assigned to this node.

NodeInit

protected void NodeInit()
Initializes the GrammarNode, is called by the constructior, after ACDCacheInit().

isRoot

public boolean isRoot()
Returns false for this class.
See Also:
GrammarRoot

toString

public String toString()
Get a textual representation of this node, actually calls the toString method on the referenced Symbol.
Overrides:
toString in class Object

getListElement

public Production.ListElement getListElement()
Get the referenced listelement.
Returns:
referenced listelement.

getDerivat

public Derivat getDerivat()
Get the referenced derivat.
Returns:
referenced derivat.

getAttributeGrammar

public AttributeGrammar getAttributeGrammar()
Get the referenced AttributeGrammar.
Returns:
the referenced AttributeGrammar.

getItsSubDerivation

public Derivat getItsSubDerivation()
Get the derivat object that can be produced by extending this node in the tree. If it doesn't exist it is created.

getChildAt

public TreeNode getChildAt(int childIndex)
Get the child object at the given position (from left to right). If the child doen't exist yet, but the node is expandable a new child is created.
Specified by:
getChildAt in interface TreeNode
Returns:
the child at the given index or null if the node doesn't have and cannot produce children. If the index is out of range null is returned.

getChildCount

public int getChildCount()
Get the actual (none are produced by this call) number of children.
Specified by:
getChildCount in interface TreeNode

getParent

public TreeNode getParent()
Get the parent TreeNode of the this node. Note: In the GrammarRoot class, this method returns null.
Specified by:
getParent in interface TreeNode
Returns:
the parent TreeNode of this node.
See Also:
GrammarRoot

getIndex

public int getIndex(TreeNode tn)
Get the position of the given (child) object. If there are no children, or child is not a child of this node -1 is returned.
Specified by:
getIndex in interface TreeNode
Returns:
the index of the given child or -1 if there are no children or child is not a child of this node.

getAllowsChildren

public boolean getAllowsChildren()
See if this node can procduce children.
Specified by:
getAllowsChildren in interface TreeNode
Returns:
true if this node is not a leaf, false otherwise.

isLeaf

public boolean isLeaf()
See if this node can be expanded.
Specified by:
isLeaf in interface TreeNode
Returns:
true if this node cannot be expanded.

children

public Enumeration children()
Tells this node to produce its children acording to the derivat object. Hint: Call this method only once, on a grammar node!
Specified by:
children in interface TreeNode
Returns:
an enumeration of the produced children.

processMouseEvent

public void processMouseEvent(int xrel,
                              int yrel,
                              MouseEvent e,
                              DefaultTreeModel tm)
Tells the node that a mouseevent has occured in it's area of interest. This method should only be called by the MyTreeUI class.
Parameters:
xrel, - yrel the relative [pixel] coordinates between the nodes x and y position and the mouseclick's position.
e - the mouseevent
tm - a reference to the treemodel used, for callback functionality

getselectedAttrib

public int getselectedAttrib()
Get the selected attribute (traversal).
Returns:
the selected attribute (traversal).

getDestCnt

public int getDestCnt()
Get the number of displayed attributes+traversals of this node.
Returns:
the number of displayed attributes+traversals.

getSymbolHeigh

public int getSymbolHeigh()
Get the height of the referenced symbol [pixel]

setSymbolHeight

public void setSymbolHeight(int h)
Do not use this function.

getAttribHeigh

public int getAttribHeigh()
Get the height of the attributes+traversals displayed by this node. return the height of the attriubtes+traversals [pixel].

setAttribHeight

public void setAttribHeight(int h)
Do not use this function.

setNodeWidth

public void setNodeWidth(int w)
Do not use this function.

getNodeWidth

public int getNodeWidth()
Get the width of the node, actually this is the width of the symbol.
Returns:
the with of the node.

getACDPos

protected int getACDPos(Attribute atr)
Get the position of the given attribute (traversal).
Returns:
the index of the given attribute or -1 if this node doesn't display this attribute

getAttribPosY

public int getAttribPosY(Attribute a)
Get the relative y position of the given attribute (traversal).
Returns:
the relative y position or a negative number if this attribute is not displayed the node.

setAttribWidth

protected void setAttribWidth(int w)
Do not use this function.

getAttribWidth

public int getAttribWidth()
Get the width of the attribute (traversal) part of this node, it's the maximum of all attributes in the node.
Returns:
the with of attribute part.

getAllDests

public Iterator getAllDests()
Get all destination (key values) from the destination lookup cache (see class description of GrammarNode).
Returns:
an iterator, elements are of type Attribute.

getSources

public Iterator getSources(Attribute destattrib)
Get all source values for a given key attribute (destination) from the destination lookup cache (see class description of GrammarNode).
Returns:
an iterator, elements are of type SrcAtt.

clearDestLookupCache

public void clearDestLookupCache()
Empties the destination lookup cache.

checkIfParentSource

protected void checkIfParentSource()
For every assignment from the node's parent to itself (this), it put's an entry in the destination lookup chache.

checkIfSiblingSource

protected GrammarNode checkIfSiblingSource(GrammarNode mgtn)
For every assignment from the given GrammarNode mgtn (which must be a "sibling" of this, or the node itself (mgtn=this)) to itself (this), it put's an entry in the destination lookup chache. If mgtn==this and this is not the root node, also checkIfSelfTraversalSource() is called.
Parameters:
mgtn - the given node (source) to test.
Returns:
mgtn

checkIfSelfTraversalSource

protected void checkIfSelfTraversalSource()
For every assignment (with destination of type traversal) from the node to itself (this), it put's an entry in the destination lookup chache.

checkIfChildSource

protected GrammarNode checkIfChildSource(GrammarNode mgtn)
For every assignment from the given GrammarNode mgtn (which must be a child of this) to itself (this), it put's an entry in the destination lookup chache.
Parameters:
mgtn - the given node (source) to test.

getAttributeCellDataArray

public Object[] getAttributeCellDataArray()
Get all ACDCache entries as object arrray.
Returns:
an object array, elements are of type AttributeCellData.