All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jumbo.xml.XTree

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----com.sun.java.swing.JComponent
                           |
                           +----com.sun.java.swing.JTree
                                   |
                                   +----jumbo.xml.XTree

public class XTree
extends JTree
implements ActionListener
an XML-based Tree view, (a forerunner of the DOM). Unlike XNode (which represents the model), XTree is a JTree which is a view of the tree. The tree model can be extracted from XTree if required. (If this is all new to you, don't worry - it took me some time - ignore it for now.)
XTree can be constructed from the rootNode of a tree based on XNodes. (The example main() program shows the logic:
XNode rootNode = new XNode("root");
XNode xNode = new XNode("Chapter a");
XNode x0 = null;
rootNode.add(xNode);
xNode.addAttribute("ID", "chapA", Attribute.CDATA);
xNode.addAttribute("foo", "bar", Attribute.CDATA);
xNode.add(x0 = new XNode("Section a1"));
x0.add(new PCDATANode("This is a section a1 string"));
xNode.add(x0 = new XNode("Section a2"));
x0.add(new PCDATANode("This is a section a2 string"));
xNode.add(x0 = new XNode("Section a3"));
x0.add(new PCDATANode("This is a section a3 string"));
xNode = new XNode("Chapter b");
rootNode.add(xNode);
xNode.add(new XNode("Section b1"));
xNode.add(new XNode("Section b2"));
xNode.add(new XNode("Section b3"));
XTree xTree = new XTree(rootNode);
xTree.display();
The tree is fully contained in the XNode structure and the XTree is primarily used to render it. Run:
java  jumbo.xml.XTree foo 
to show the effect.
The default display uses an XSplitPanePanel with the XTree on the left, but the XTree can be embdedded in any JComponent if required. The tree has several options set by XTreeOptions, which in principle allows for TreeCellRenderer. Unfortunately although I got this working nicely, it's rebelled for a bit and so shouldn't be used.
Program and logic is highly derivative from SwingSet example.

Author:
P.Murray-Rust, 1998

Variable Index

 o ALLNODES
all nodes analysis
 o ELEMENT
element analysis
 o helpTree
the current help tree
 o helpUrl
the helpfile - don't know how to locate this...
 o jFrame
the frame in which all is displayed
 o jMessage
the message area in it
 o jURLPanel
a box for the URL
 o jURLTextField
textField for the URL
 o options
the options for tree display
 o outputFormat
the current output format; default is TAGGED event stream
 o parserClassName
the current parserClassName
 o PCDATA
PCDATA analysis
 o rootNode
the root of the tree
 o treeModel
the tree model (default if not specified)
 o urlString
the URL
 o xNodePanel
the panel for rendering of the XNode components (e.g.
 o xNodePanelContainer
a container for the XNodePanel

Constructor Index

 o XTree()
the simplest way of creating an XTree.
 o XTree(String)
Create a single node tree .
 o XTree(String, boolean)
Create a single node tree .
 o XTree(XNode)
the next simplest way of creating an XTree.
 o XTree(XNode, boolean)
Create a tree from a root node .

Method Index

 o actionPerformed(ActionEvent)
 o addMenu()
 o display()
display the tree.
 o displayWait(boolean)
displays a clock cursor if true, else default.
 o getRootNode()
gets root node (probably better Swing ways :-)
 o getSelectedNode()
gets the (first) selected node
 o getSelectedNodes()
gets all selected nodes (null if none)
 o getTree(XNode)
find tree that an XNode belongs to (shopuld be previously registered)
 o getXNodePanel()
gets the panel into which XNodes can be displayed
 o main(String[])
a test program, see above
 o numberNodes(XNode, String)
numbers nodes by levels (e.g.
 o postMessage(String)
post a message to the JMessage message area
 o resetTree()
 o resetTree(XNode)
if node structure has been changed, reload root Node and highlight node
 o saveXML(Vector, int, String)
saves nodes to a file selected by the user.
 o saveXML(XNode, int, String)
saves node to a file selected by the user.
 o search(XNode, String, String, String, int)
search for a given element, attribute, value
 o selectAndHighlight(XNode)
doesn't yet work
 o selectNode(XNode)
selects a node and highlights it
 o selectNodes(Vector)
selects nodes and highlights them
 o setOptions(XTreeOptions)
set the tree options by cloning an existing XTreeOptions

Variables

 o treeModel
 protected DefaultTreeModel treeModel
the tree model (default if not specified)

 o rootNode
 protected XNode rootNode
the root of the tree

 o xNodePanelContainer
 protected JComponent xNodePanelContainer
a container for the XNodePanel

 o xNodePanel
 protected XNodePanel xNodePanel
the panel for rendering of the XNode components (e.g. Attributes)

 o options
 protected XTreeOptions options
the options for tree display

 o jFrame
 protected JFrame jFrame
the frame in which all is displayed

 o jMessage
 protected JLabel jMessage
the message area in it

 o jURLPanel
 protected JPanel jURLPanel
a box for the URL

 o jURLTextField
 protected JTextField jURLTextField
textField for the URL

 o urlString
 protected String urlString
the URL

 o parserClassName
 protected String parserClassName
the current parserClassName

 o outputFormat
 protected int outputFormat
the current output format; default is TAGGED event stream

 o helpTree
 protected XTree helpTree
the current help tree

 o helpUrl
 protected static String helpUrl
the helpfile - don't know how to locate this...

 o ALLNODES
 public static final int ALLNODES
all nodes analysis

 o ELEMENT
 public static final int ELEMENT
element analysis

 o PCDATA
 public static final int PCDATA
PCDATA analysis

Constructors

 o XTree
 public XTree()
the simplest way of creating an XTree. Create the tree with a default rootNode

 o XTree
 public XTree(XNode rootNode)
the next simplest way of creating an XTree. Create the tree using XNode.add(XNode) first.

Parameters:
XNode - rootNode the root node of the tree
 o XTree
 public XTree(String name,
              boolean askAllowsChildren)
Create a single node tree .

Parameters:
String - name the name of the root node of the tree
boolean - askAllowsChildren see DefaultMutableTreeNode for this. I use true so far.
 o XTree
 public XTree(String name)
Create a single node tree .

Parameters:
String - name the name of the root node of the tree
 o XTree
 public XTree(XNode rootNode,
              boolean askAllowsChildren)
Create a tree from a root node .

Parameters:
String - name the name of the root node of the tree
boolean - askAllowsChildren see DefaultMutableTreeNode for this. I use true so far.

Methods

 o getTree
 public static XTree getTree(XNode node)
find tree that an XNode belongs to (shopuld be previously registered)

 o addMenu
 public void addMenu()
 o setOptions
 public void setOptions(XTreeOptions options)
set the tree options by cloning an existing XTreeOptions

Parameters:
XTreeOptions - tree display options
 o displayWait
 public void displayWait(boolean onOff)
displays a clock cursor if true, else default. Could be extended to lock the frame when I know how

 o display
 public void display()
display the tree. Can be controlled by XTreeOptions, the default being to use an XSplitPanePanel in a JFrame. It adds a MouseListener which can be customised for different types of clicks. It also sets toolTips.

 o getRootNode
 public XNode getRootNode()
gets root node (probably better Swing ways :-)

Returns:
XNode the root node
 o getSelectedNode
 public XNode getSelectedNode()
gets the (first) selected node

Returns:
XNode the selected node
 o getSelectedNodes
 public Vector getSelectedNodes()
gets all selected nodes (null if none)

Returns:
Vector the selected nodes (null if none);
 o getXNodePanel
 public XNodePanel getXNodePanel()
gets the panel into which XNodes can be displayed

 o selectAndHighlight
 public void selectAndHighlight(XNode node)
doesn't yet work

Parameters:
XNode - node the node to highlight
 o actionPerformed
 public void actionPerformed(ActionEvent e)
 o numberNodes
 public void numberNodes(XNode node,
                         String prefix)
numbers nodes by levels (e.g. 1.2.3). omitting PCDATA and PI. The numbering adds digits to the title field. At present it cannot be saved (although we might generate a TITLE attribute??).

Parameters:
XNode - node the node to start numbering at (only the node and the subtree)
String - prefix. Numbers will be of form Prefix.1.2.3: title, where title was the original title
 o saveXML
 public void saveXML(XNode node,
                     int control,
                     String urlString) throws Exception
saves node to a file selected by the user.

Parameters:
XNode - node the node and its subtree are written to file
int - control XNode.TAGGED, XNode.PRETTY, etc.
Throws: Exception
almost anything - probably mainly java.io
 o saveXML
 public void saveXML(Vector nodeVector,
                     int control,
                     String urlString) throws Exception
saves nodes to a file selected by the user. Output format ignored at present

Parameters:
Vector - nodeVector vector of nodes to be saved;
Throws: Exception
almost anything - probably mainly java.io
 o resetTree
 public void resetTree()
 o resetTree
 public void resetTree(XNode node)
if node structure has been changed, reload root Node and highlight node

 o selectNode
 public void selectNode(XNode xNode)
selects a node and highlights it

Parameters:
XNode - xNode the node to highlight
 o selectNodes
 public void selectNodes(Vector nodeVector)
selects nodes and highlights them

Parameters:
Vector - xNode the node to highlight
 o search
 public Vector search(XNode topNode,
                      String elementName,
                      String attributeName,
                      String attributeValue,
                      int sensitivity)
search for a given element, attribute, value

Parameters:
XNode - topNode Node to start at (all descendants are searched)
String - elementName (if null matches any)
String - attributeName (if null matches any, regardless of attributeValue)
String - attributeValue(if null matches any)
int - sensitivity XNode.CASE or XNode.IGNORECASE (applies to all params)
 o postMessage
 public void postMessage(String message)
post a message to the JMessage message area

Parameters:
String - message the message
 o main
 public static void main(String args[])
a test program, see above


All Packages  Class Hierarchy  This Package  Previous  Next  Index