org.jivesoftware.spark.component
Class JiveTreeNode

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by org.jivesoftware.spark.component.JiveTreeNode
All Implemented Interfaces:
java.awt.datatransfer.Transferable, java.io.Serializable, java.lang.Cloneable, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode
Direct Known Subclasses:
CheckNode

public class JiveTreeNode
extends javax.swing.tree.DefaultMutableTreeNode
implements java.awt.datatransfer.Transferable

JiveTreeNode class is a better implementation than using the DefaultMutableTree node. This allows better searching of children/parents as well as handling of icons and drag and drop events.

Author:
Derek DeMoro
See Also:
Serialized Form

Field Summary
static java.awt.datatransfer.DataFlavor[] DATA_FLAVORS
          Default Drag and Drop to use for Node detection.
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
JiveTreeNode(java.lang.Object o, boolean allowsChildren)
          Creates a new JiveTreeNode.
JiveTreeNode(java.lang.String userobject)
          Creates a new JiveTreeNode.
JiveTreeNode(java.lang.String name, boolean allowsChildren)
          Create parent node.
JiveTreeNode(java.lang.String userObject, boolean allowChildren, javax.swing.Icon icon)
          Creates a new JiveTreeNode.
JiveTreeNode(TreeFolder folder)
           
JiveTreeNode(TreeFolder folder, javax.swing.Icon img)
          Creates a new JiveTreeNode from a TreeFolder.
JiveTreeNode(TreeItem item)
          Creates a new JiveTreeNode from a TreeItem.
JiveTreeNode(TreeItem item, javax.swing.Icon img)
          Createa new JiveTreeNode from a TreeItem and Image.
 
Method Summary
 java.lang.Object getAssociatedObject()
          Returns the associated object used.
 javax.swing.Icon getClosedIcon()
          Returns the icon that is displayed when the node is collapsed.
 javax.swing.Icon getIcon()
          Returns the default image used.
 javax.swing.Icon getOpenIcon()
          Return the icon that is displayed when the node is expanded.
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
           
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
          Transferable implementation
 boolean hasParent(java.lang.String parentName)
          Returns true if a parent with the specified name is found.
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
           
 void setAssociatedObject(java.lang.Object o)
          Returns the associated object.
 void setIcon(javax.swing.Icon icon)
          Sets the default icon.
 
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
 

Field Detail

DATA_FLAVORS

public static final java.awt.datatransfer.DataFlavor[] DATA_FLAVORS
Default Drag and Drop to use for Node detection.

Constructor Detail

JiveTreeNode

public JiveTreeNode(TreeFolder folder)

JiveTreeNode

public JiveTreeNode(java.lang.String name,
                    boolean allowsChildren)
Create parent node.

Parameters:
name - the name of the node.
allowsChildren - true if the node allows children.

JiveTreeNode

public JiveTreeNode(java.lang.Object o,
                    boolean allowsChildren)
Creates a new JiveTreeNode.

Parameters:
o - the object to use.
allowsChildren - true if it allows children.

JiveTreeNode

public JiveTreeNode(TreeItem item)
Creates a new JiveTreeNode from a TreeItem.

Parameters:
item - the TreeItem

JiveTreeNode

public JiveTreeNode(TreeFolder folder,
                    javax.swing.Icon img)
Creates a new JiveTreeNode from a TreeFolder.

Parameters:
folder - the TreeFolder.
img - the image to use in the node.

JiveTreeNode

public JiveTreeNode(TreeItem item,
                    javax.swing.Icon img)
Createa new JiveTreeNode from a TreeItem and Image.

Parameters:
item - the TreeItem to use.
img - the image to use in the node.

JiveTreeNode

public JiveTreeNode(java.lang.String userobject)
Creates a new JiveTreeNode.

Parameters:
userobject - the object to use in the node. Note: By default, the node will not allow children.

JiveTreeNode

public JiveTreeNode(java.lang.String userObject,
                    boolean allowChildren,
                    javax.swing.Icon icon)
Creates a new JiveTreeNode.

Parameters:
userObject - the userObject to use.
allowChildren - true if it allows children.
icon - the image to use in the node.
Method Detail

getIcon

public javax.swing.Icon getIcon()
Returns the default image used.

Returns:
the default image used.

getOpenIcon

public javax.swing.Icon getOpenIcon()
Return the icon that is displayed when the node is expanded.

Returns:
the open icon.

getClosedIcon

public javax.swing.Icon getClosedIcon()
Returns the icon that is displayed when the node is collapsed.

Returns:
the closed icon.

setIcon

public void setIcon(javax.swing.Icon icon)
Sets the default icon.

Parameters:
icon - the icon.

getAssociatedObject

public java.lang.Object getAssociatedObject()
Returns the associated object used. The associated object is used to store associated data objects along with the node.

Returns:
the object.

setAssociatedObject

public void setAssociatedObject(java.lang.Object o)
Returns the associated object.

Parameters:
o - the associated object.

hasParent

public final boolean hasParent(java.lang.String parentName)
Returns true if a parent with the specified name is found.

Parameters:
parentName - the name of the parent.
Returns:
true if parent found.

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Transferable implementation

Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
                                 throws java.awt.datatransfer.UnsupportedFlavorException,
                                        java.io.IOException
Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
Throws:
java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException