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
-
ALLNODES
- all nodes analysis
-
ELEMENT
- element analysis
-
helpTree
- the current help tree
-
helpUrl
- the helpfile - don't know how to locate this...
-
jFrame
- the frame in which all is displayed
-
jMessage
- the message area in it
-
jURLPanel
- a box for the URL
-
jURLTextField
- textField for the URL
-
options
- the options for tree display
-
outputFormat
- the current output format; default is TAGGED event stream
-
parserClassName
- the current parserClassName
-
PCDATA
- PCDATA analysis
-
rootNode
- the root of the tree
-
treeModel
- the tree model (default if not specified)
-
urlString
- the URL
-
xNodePanel
- the panel for rendering of the XNode components (e.g.
-
xNodePanelContainer
- a container for the XNodePanel
-
XTree()
- the simplest way of creating an XTree.
-
XTree(String)
-
Create a single node tree .
-
XTree(String, boolean)
-
Create a single node tree .
-
XTree(XNode)
- the next simplest way of creating an XTree.
-
XTree(XNode, boolean)
-
Create a tree from a root node .
-
actionPerformed(ActionEvent)
-
-
addMenu()
-
-
display()
- display the tree.
-
displayWait(boolean)
- displays a clock cursor if true, else default.
-
getRootNode()
- gets root node (probably better Swing ways :-)
-
getSelectedNode()
- gets the (first) selected node
-
getSelectedNodes()
- gets all selected nodes (null if none)
-
getTree(XNode)
- find tree that an XNode belongs to (shopuld be previously registered)
-
getXNodePanel()
- gets the panel into which XNodes can be displayed
-
main(String[])
- a test program, see above
-
numberNodes(XNode, String)
- numbers nodes by levels (e.g.
-
postMessage(String)
- post a message to the JMessage message area
-
resetTree()
-
-
resetTree(XNode)
- if node structure has been changed, reload root Node
and highlight node
-
saveXML(Vector, int, String)
- saves nodes to a file selected by the user.
-
saveXML(XNode, int, String)
- saves node to a file selected by the user.
-
search(XNode, String, String, String, int)
- search for a given element, attribute, value
-
selectAndHighlight(XNode)
- doesn't yet work
-
selectNode(XNode)
- selects a node and highlights it
-
selectNodes(Vector)
- selects nodes and highlights them
-
setOptions(XTreeOptions)
- set the tree options by cloning an existing XTreeOptions
treeModel
protected DefaultTreeModel treeModel
- the tree model (default if not specified)
rootNode
protected XNode rootNode
- the root of the tree
xNodePanelContainer
protected JComponent xNodePanelContainer
- a container for the XNodePanel
xNodePanel
protected XNodePanel xNodePanel
- the panel for rendering of the XNode components (e.g. Attributes)
options
protected XTreeOptions options
- the options for tree display
jFrame
protected JFrame jFrame
- the frame in which all is displayed
jMessage
protected JLabel jMessage
- the message area in it
jURLPanel
protected JPanel jURLPanel
- a box for the URL
jURLTextField
protected JTextField jURLTextField
- textField for the URL
urlString
protected String urlString
- the URL
parserClassName
protected String parserClassName
- the current parserClassName
outputFormat
protected int outputFormat
- the current output format; default is TAGGED event stream
helpTree
protected XTree helpTree
- the current help tree
helpUrl
protected static String helpUrl
- the helpfile - don't know how to locate this...
ALLNODES
public static final int ALLNODES
- all nodes analysis
ELEMENT
public static final int ELEMENT
- element analysis
PCDATA
public static final int PCDATA
- PCDATA analysis
XTree
public XTree()
- the simplest way of creating an XTree.
Create the tree with a default rootNode
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
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.
XTree
public XTree(String name)
- Create a single node tree .
- Parameters:
- String - name the name of the root node of the tree
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.
getTree
public static XTree getTree(XNode node)
- find tree that an XNode belongs to (shopuld be previously registered)
addMenu
public void addMenu()
setOptions
public void setOptions(XTreeOptions options)
- set the tree options by cloning an existing XTreeOptions
- Parameters:
- XTreeOptions - tree display options
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
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.
getRootNode
public XNode getRootNode()
- gets root node (probably better Swing ways :-)
- Returns:
- XNode the root node
getSelectedNode
public XNode getSelectedNode()
- gets the (first) selected node
- Returns:
- XNode the selected node
getSelectedNodes
public Vector getSelectedNodes()
- gets all selected nodes (null if none)
- Returns:
- Vector the selected nodes (null if none);
getXNodePanel
public XNodePanel getXNodePanel()
- gets the panel into which XNodes can be displayed
selectAndHighlight
public void selectAndHighlight(XNode node)
- doesn't yet work
- Parameters:
- XNode - node the node to highlight
actionPerformed
public void actionPerformed(ActionEvent e)
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
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
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
resetTree
public void resetTree()
resetTree
public void resetTree(XNode node)
- if node structure has been changed, reload root Node
and highlight node
selectNode
public void selectNode(XNode xNode)
- selects a node and highlights it
- Parameters:
- XNode - xNode the node to highlight
selectNodes
public void selectNodes(Vector nodeVector)
- selects nodes and highlights them
- Parameters:
- Vector - xNode the node to highlight
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)
postMessage
public void postMessage(String message)
- post a message to the JMessage message area
- Parameters:
- String - message the message
main
public static void main(String args[])
- a test program, see above
All Packages Class Hierarchy This Package Previous Next Index