CubeTwister 2.0alpha141 2011-10-13

ch.randelshofer.gui.tree
Class TreeModels

java.lang.Object
  extended by ch.randelshofer.gui.tree.TreeModels

public class TreeModels
extends java.lang.Object

TreeModels.

Version:
2.0 2008-03-21 Support for TreeModel added.
1.0 November 1, 2003 Created.
Author:
Werner Randelshofer

Method Summary
static java.awt.datatransfer.Transferable createDefaultTransferable(javax.swing.tree.TreeModel model, javax.swing.tree.MutableTreeNode[] nodes)
          Creates a transferable in a number of default formats for a ListModel.
static java.awt.datatransfer.Transferable createHTMLTransferable(javax.swing.tree.TreeModel model, javax.swing.tree.MutableTreeNode[] nodes)
          Creates a transferable in text/html format from a mutable tree model.
static java.awt.datatransfer.Transferable createLocalTransferable(javax.swing.tree.TreeModel model, javax.swing.tree.MutableTreeNode[] nodes, java.lang.Class baseclass)
          Creates a local JVM transferable from a mutable tree model.
static java.awt.datatransfer.Transferable createPlainTransferable(javax.swing.tree.TreeModel model, javax.swing.tree.MutableTreeNode[] nodes)
          Creates a transferable in text/plain format from a mutable tree model.
static javax.swing.tree.TreeNode[] getPathToRoot(javax.swing.tree.TreeNode aNode)
          Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.
static javax.swing.tree.TreeNode[] getPathToRoot(javax.swing.tree.TreeNode aNode, int depth)
          Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.
static javax.swing.tree.MutableTreeNode[] removeDescendantsFromNodeArray(javax.swing.tree.MutableTreeNode[] nodes)
          Removes all descendants from a node array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createDefaultTransferable

public static java.awt.datatransfer.Transferable createDefaultTransferable(javax.swing.tree.TreeModel model,
                                                                           javax.swing.tree.MutableTreeNode[] nodes)
Creates a transferable in a number of default formats for a ListModel.

Returns:
A transferable for a list model.

createHTMLTransferable

public static java.awt.datatransfer.Transferable createHTMLTransferable(javax.swing.tree.TreeModel model,
                                                                        javax.swing.tree.MutableTreeNode[] nodes)
Creates a transferable in text/html format from a mutable tree model.

Returns:
A transferable of type text/html

createPlainTransferable

public static java.awt.datatransfer.Transferable createPlainTransferable(javax.swing.tree.TreeModel model,
                                                                         javax.swing.tree.MutableTreeNode[] nodes)
Creates a transferable in text/plain format from a mutable tree model.

Returns:
A transferable of type java.awt.datatransfer.StringSelection

createLocalTransferable

public static java.awt.datatransfer.Transferable createLocalTransferable(javax.swing.tree.TreeModel model,
                                                                         javax.swing.tree.MutableTreeNode[] nodes,
                                                                         java.lang.Class baseclass)
Creates a local JVM transferable from a mutable tree model.

Returns:
A JVM local object transferable of type java.util.LinkedList if nodes.length > 1. A JVM local object transferable of type model.getElementAt(nodes[0]).getClass() if nodes.length = 1.

removeDescendantsFromNodeArray

public static javax.swing.tree.MutableTreeNode[] removeDescendantsFromNodeArray(javax.swing.tree.MutableTreeNode[] nodes)
Removes all descendants from a node array.

A node is removed from the array when it is a descendant from another node in the array.


getPathToRoot

public static javax.swing.tree.TreeNode[] getPathToRoot(javax.swing.tree.TreeNode aNode)
Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. The length of the returned array gives the node's depth in the tree.

Parameters:
aNode - the TreeNode to get the path for
Returns:
an array of TreeNodes giving the path from the root to the specified node.

getPathToRoot

public static javax.swing.tree.TreeNode[] getPathToRoot(javax.swing.tree.TreeNode aNode,
                                                        int depth)
Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. The length of the returned array gives the node's depth in the tree.

Parameters:
aNode - the TreeNode to get the path for
depth - an int giving the number of steps already taken towards the root (on recursive calls), used to size the returned array
Returns:
an array of TreeNodes giving the path from the root to the specified node

(c) Werner Randelshofer.
All rights reserved.