org.geotoolkit.gui.swing.tree
Class Trees

Object
  extended by Static
      extended by Trees

public final class Trees
extends Static

Convenience static methods for trees operations. This class provides methods for performing a copy of a tree and for converting from XML. It can also print a tree in a format like the following example:

Node #1
├───Node #2
│   └───Node #4
└───Node #3

Since:
2.0
Version:
3.18
Author:
Martin Desruisseaux (IRD, Geomatys)
See Also:
TreeFormat
Module:
utility/geotk-utility (download)    View source code for this class

Method Summary
static MutableTreeNode copy(TreeNode node)
          Returns a copy of the tree starting at the given node.
static MutableTreeNode copy(TreeNode node, TreeNodeFilter filter)
          Returns a copy of a subset of the tree starting at the given node.
static TreePath[] getPathsToUserObject(TreeModel model, Object value)
          Returns the path to the specified user object.
static Object getUserObject(TreeNode node)
          Returns the user object from the given tree node.
static MutableTreeNode objectToSwing(Object object)
          Returns a tree representation of the given object.
static void print(TreeModel tree)
          Prints the specified tree model to the standard output stream.
static void print(TreeNode node)
          Prints the specified tree to the standard output stream.
static void show(TreeModel tree, String title)
          Display the given tree in a Swing frame.
static void show(TreeNode node, String title)
          Display the given tree in a Swing frame.
static String toString(String root, Iterable<?> nodes)
          Returns a graphical representation of the specified nodes.
static String toString(TreeModel tree)
          Returns a graphical representation of the specified tree model.
static String toString(TreeNode node)
          Returns a graphical representation of the specified tree.
static MutableTreeNode xmlToSwing(Node node)
          Creates a Swing root tree node from a XML root tree node.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getUserObject

public static Object getUserObject(TreeNode node)
Returns the user object from the given tree node. If the given node is an instance of Geotk TreeNode, then its getUserObject() method is invoked. Otherwise if the given node is an instance of Java DefaultMutableTreeNode, then its getUserObject() method is invoked. Otherwise this method returns null.

Parameters:
node - The node for which to get the user object, or null.
Returns:
The user object, or null if none.
Since:
3.00

getPathsToUserObject

public static TreePath[] getPathsToUserObject(TreeModel model,
                                              Object value)
Returns the path to the specified user object. For each tree node which are actually instance of Geotk TreeNode, this method compares the specified value against the user object returned by the TreeNode.getUserObject() method.

Parameters:
model - The tree model to inspect.
value - User object to compare to TreeNode.getUserObject().
Returns:
The paths to the specified value, or an empty array if none.

objectToSwing

public static MutableTreeNode objectToSwing(Object object)
Returns a tree representation of the given object. This method processes the following types especially:

Together with toString(TreeNode), this method provides a convenient way to print the content of a XML document for debugging purpose.

Parameters:
object - The array, collection or single object to format.
Returns:
The given object as a Swing tree.
Since:
3.17

xmlToSwing

public static MutableTreeNode xmlToSwing(Node node)
Creates a Swing root tree node from a XML root tree node. Together with toString(TreeNode), this method provides a convenient way to print the content of a XML document for debugging purpose.

Parameters:
node - The XML root node.
Returns:
The given XML node as a Swing node.

copy

public static MutableTreeNode copy(TreeNode node)
Returns a copy of the tree starting at the given node. The references to the user objects (if any) and the string representations are copied verbalism.

Parameters:
node - The tree to copy (may be null).
Returns:
A mutable copy of the given tree, or null if the given tree was null.
Since:
2.5

copy

public static MutableTreeNode copy(TreeNode node,
                                   TreeNodeFilter filter)
Returns a copy of a subset of the tree starting at the given node. The references to the user objects in the copied nodes can be modified by the filter.

Parameters:
node - The tree to copy (may be null).
filter - An object filtering the node to copy, or null if none.
Returns:
A mutable copy of the given tree, or null if the given tree was null or if the given node is not accepted by the filter.
Since:
3.04

toString

public static String toString(TreeModel tree)
Returns a graphical representation of the specified tree model. This representation can be printed to the standard output stream (for example) if it uses a monospaced font and supports unicode.

This convenience method delegates to TreeFormat.format(TreeModel, Appendable). Users are encouraged to use TreeFormat directly if they want more control on the formatting process.

Parameters:
tree - The tree to format.
Returns:
A string representation of the tree.

toString

public static String toString(TreeNode node)
Returns a graphical representation of the specified tree. This representation can be printed to the standard output stream (for example) if it uses a monospaced font and supports unicode.

This convenience method delegates to TreeFormat.format(TreeNode, Appendable). Users are encouraged to use TreeFormat directly if they want more control on the formatting process.

Parameters:
node - The root node of the tree to format.
Returns:
A string representation of the tree.

toString

public static String toString(String root,
                              Iterable<?> nodes)
Returns a graphical representation of the specified nodes. This representation can be printed to the standard output stream (for example) if it uses a monospaced font and supports unicode.

This convenience method delegates to TreeFormat.format(Iterable, Appendable). Users are encouraged to use TreeFormat directly if they want more control on the formatting process.

Recursivity
This method does not perform any check on the element types. In particular, elements of type TreeModel, TreeNode or inner Iterable are not processed recursively. It is up to the toString() implementation of each element to invoke this toString method recursively if they wish (this method is safe for this purpose).

Parameters:
root - The root name of the tree to format.
nodes - The nodes to format.
Returns:
A string representation of the tree.
Since:
3.18

print

@Debug
public static void print(TreeModel tree)
Prints the specified tree model to the standard output stream. This method is mostly a convenience for debugging purpose.

Parameters:
tree - The tree to print.
Since:
2.4

print

@Debug
public static void print(TreeNode node)
Prints the specified tree to the standard output stream. This method is mostly a convenience for debugging purpose.

Parameters:
node - The root node of the tree to print.
Since:
2.4

show

@Debug
public static void show(TreeNode node,
                              String title)
Display the given tree in a Swing frame. This is a convenience method for debugging purpose only.

Parameters:
node - The root of the tree to display in a Swing frame.
title - The frame title, or null if none.
Since:
2.5

show

@Debug
public static void show(TreeModel tree,
                              String title)
Display the given tree in a Swing frame. This is a convenience method for debugging purpose only.

Parameters:
tree - The tree to display in a Swing frame.
title - The frame title, or null if none.
Since:
2.5


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.