edu.iastate.metnet.metaomgraph
Class ExtendedInfoTree

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by edu.iastate.metnet.metaomgraph.ExtendedInfoTree
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode

public class ExtendedInfoTree
extends javax.swing.tree.DefaultMutableTreeNode

Class for storing the extended information of a MetaOmProject. The extended information is initialized from an XML file and stored as a tree of DefaultMutableTreeNodes with the ExtendedInfoTree node as the root. The user object of each child node is an ExtendedInfoTree.InfoNode.

This class also contains two Hashtables that can be used to track Plant Ontology information. The keys of the Hashtable returned by getPONumberHash are full plant ontology strings (such as "PO:0009046: flower"), while the keys of the getPONameHash() table are only the name part of the string (the "flower" part of "PO:0009046: flower"). When loading the extended info, if an Element whose text is a plant ontology string is encountered, the name of the parent Element is added to a Vector, which is then added to the tables. The tables can then be used to determine which branches of the ExtendedInfoTree correspond to certain plant ontology values.

Author:
Nick Ransom
See Also:
Serialized Form

Nested Class Summary
 class ExtendedInfoTree.InfoNode
          Class that stores information for nodes in an ExtendedInfoTree.
 
Field Summary
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
ExtendedInfoTree()
          Default constructor.
 
Method Summary
 void addChildren(javax.swing.tree.DefaultMutableTreeNode parent, org.jdom.Element thisElement)
          Adds the given Element and its children to the given parent.
 javax.swing.tree.TreeNode[] findPath(java.lang.String findMe)
          Finds the first node in this tree whose name starts with the given String.
 java.lang.String getData(java.lang.String nodeName)
          Retrieves the metadata for a given node.
 java.lang.String[] getFields()
          Retrieves a list of leaf node names in this tree.
 java.util.Hashtable<java.lang.String,java.util.Vector<java.lang.String>> getPONameHash()
          Fetches a Hashtable whose keys are plant ontology names and whose values are Vectors of names of nodes that have the plant ontology name as one of its children.
 java.util.Hashtable<java.lang.String,java.util.Vector<java.lang.String>> getPONumberHash()
          Fetches a Hashtable whose keys are plant ontology strings and whose values are Vectors of names of nodes that have the complete plant ontology string as one of its children.
 boolean initData()
          Prompts the user to select an XML file, the initializes this tree from the selected file.
 boolean initData(org.jdom.Element rootNode)
           
 boolean initData(java.io.File source)
          Initializes this tree from a given XML file.
 boolean initData(java.io.InputStream source)
          Initializes this tree from the given InputStream.
 void outputTree(java.io.OutputStream outstream)
          Outputs this ExtendedInfoTree to the given OutputStream.
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExtendedInfoTree

public ExtendedInfoTree()
Default constructor. Does nothing.

Method Detail

initData

public boolean initData()
Prompts the user to select an XML file, the initializes this tree from the selected file.

Returns:
true if the tree was initialized successfully, false if the user canceled the file chooser, or if the tree could not be initialized from the selected file.

initData

public boolean initData(java.io.InputStream source)
Initializes this tree from the given InputStream.

Parameters:
source - An InputStream with an XML source.
Returns:
true if the tree was initialized successfully, false otherwise.

initData

public boolean initData(java.io.File source)
Initializes this tree from a given XML file.

Parameters:
source - An XML file
Returns:
true if this tree was initialized successfully, false otherwise.

initData

public boolean initData(org.jdom.Element rootNode)

addChildren

public void addChildren(javax.swing.tree.DefaultMutableTreeNode parent,
                        org.jdom.Element thisElement)
Adds the given Element and its children to the given parent. Children are added as DefaultMutableTreeNodes with ExtendedInfoTree.InfoNodes as their user objects.

Parameters:
parent - The parent node.
thisElement - The XML Element to add to the parent.

getFields

public java.lang.String[] getFields()
Retrieves a list of leaf node names in this tree. In a proper ExtendedInfoTree, the leaf nodes are the only ones that have information associated with them. Names are only listed once, no matter how many times they appear in the tree. The returned array is not sorted in any particular order.

Returns:
the names of the leaf nodes

findPath

public javax.swing.tree.TreeNode[] findPath(java.lang.String findMe)
Finds the first node in this tree whose name starts with the given String. The first cell in the returned array is the root node of this tree, and the last is the "found" node.

Parameters:
findMe - the start of the desired node's name
Returns:
the path from the root to the found node, or null if no match was found.

outputTree

public void outputTree(java.io.OutputStream outstream)
Outputs this ExtendedInfoTree to the given OutputStream. Output is in "pretty" XML format, with \n as the line separator.

Parameters:
outstream - the OutputStream to receive this ExtendedInfoTree's XML output.

getPONameHash

public java.util.Hashtable<java.lang.String,java.util.Vector<java.lang.String>> getPONameHash()
Fetches a Hashtable whose keys are plant ontology names and whose values are Vectors of names of nodes that have the plant ontology name as one of its children. See the class description for details

Returns:
a Hashtable in whose values are node names with the key as a child

getPONumberHash

public java.util.Hashtable<java.lang.String,java.util.Vector<java.lang.String>> getPONumberHash()
Fetches a Hashtable whose keys are plant ontology strings and whose values are Vectors of names of nodes that have the complete plant ontology string as one of its children. See the class description for details

Returns:
a Hashtable in whose values are node names with the key as a child

getData

public java.lang.String getData(java.lang.String nodeName)
Retrieves the metadata for a given node.

Parameters:
nodeName - the name of the node
Returns:
the metadata for the given node, or null if the node was not found