The following methods are the implementations of the
methods belonging to the
IlvSDMNode interface, which are inherited by
TreeSDMNode
.
The getTag
method returns
the type (or “tag”) of the node. In this example, the
type is treenode
.
Retrieving the node type: the getTag method
public String getTag()
{
return "treenode";
}
The getID
method returns the
identifier of the node. The identifier of a node is its hash code.
Retrieving the node ID: the getID method
public String getID()
{
return String.valueOf(hashCode());
}
The getChildren
method returns
the children of the node, which are stored in the children
data member.
Retrieving the child objects: the getChildren method
public Enumeration getChildren()
{
return children.elements();
}
The getParent
method returns
the parent node of the current node.
Retrieving the parent object: the getParent method
public IlvSDMNode getParent()
{
return parent;
}
The getProperty
and getPropertyNames
methods
must be implemented to give the diagram component access to the properties
of the node. In this example, there is support for two properties, userObject
and CSSclass
:
The userObject
property
returns the sample food, color, and sports names.
The CSSclass
property
returns the type of item: food
, color,
or sport
.
Retrieving a property: the getProperty method
public Object getProperty(String property)
{
if(treeNode instanceof DefaultMutableTreeNode){
if(property.equals("userObject")){
return ((DefaultMutableTreeNode)treeNode).getUserObject();
}
if(property.equals("CSSclass") && ((DefaultMutableTreeNode)treeNode).getParent() != null){
return ((DefaultMutableTreeNode)((DefaultMutableTreeNode)treeNode).getParent()).getUserObject();
}
}
return null;
}
The getPropertyNames
method
retrieves the two property names.
Retrieving property names: the getPropertyNames method
public String[] getPropertyNames()
{
if(treeNode instanceof DefaultMutableTreeNode)
return new String[] { "userObject", "CSSclass" };
else
return new String[0];
}