projectviewer.vpt
Class VPTNode

java.lang.Object
  extended byjavax.swing.tree.DefaultMutableTreeNode
      extended byprojectviewer.vpt.VPTNode
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, javax.swing.tree.MutableTreeNode, java.io.Serializable, javax.swing.tree.TreeNode
Direct Known Subclasses:
VFSFile, VPTDirectory, VPTFile, VPTGroup, VPTProject

public abstract class VPTNode
extends javax.swing.tree.DefaultMutableTreeNode
implements java.lang.Comparable

Node implementation for the Virtual Project Tree. Keeps track of children and provides basic functionality for the nodes.

Based on the TreeNode class from the VirtualProjectTree plugin by Shad Stafford.

Version:
$Id: VPTNode.java 9179 2007-03-21 04:02:57Z vanza $
Author:
Marcelo Vanzin
See Also:
Serialized Form

Field Summary
protected  java.lang.String name
           
protected static java.awt.Color treeNoSelectionBackground
           
protected static java.awt.Color treeNoSelectionForeground
           
protected static java.awt.Color treeSelectionBackground
           
protected static java.awt.Color treeSelectionForeground
           
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
protected VPTNode(java.lang.String name)
          Deprecated. Use VPTNode(String,boolean)
protected VPTNode(java.lang.String name, boolean allowsChildren)
           
 
Method Summary
 boolean canOpen()
          This method should return whether it makes sense to "open" the node.
 boolean canWrite()
          Returns whether the underlying resource can be written to.
 void close()
          "Closes" the node.
protected  int compareName(VPTNode other)
           
 int compareTo(java.lang.Object o)
          Implementation of the Comparable interface.
 int compareToNode(VPTNode node)
          This method is used to sort the nodes in the trees.
 boolean delete()
          The "delete()" method should remove the resource from the the disk, if applicable.
 int findIndexForChild(VPTNode child)
          Do a binary search with the goal of finding in what index of the child array of this node the given child would be inserted to maintain order according to the comparison rules defined by the compareToNode() methods.
static VPTProject findProjectFor(VPTNode node)
          Returns the project associated with the node, or null if the node is the root of the project tree.
 java.awt.Color getBackgroundColor(boolean sel)
          Returns the node's background color.
 VPTNode getChildWithName(java.lang.String name)
          Returns the child directly under this node that has the given name.
 int getClipType()
          This method controls how the CellRenderer implementation will clip the name of the node when it doesn't fit in the tree.
 java.awt.Color getForegroundColor(boolean sel)
          Returns the node's foreground color.
abstract  javax.swing.Icon getIcon(boolean expanded)
          Returns the icon to be shown on the tree next to the node name.
 java.lang.String getName()
          Returns the name of this node.
abstract  java.lang.String getNodePath()
          Returns a String representing a "path" for this node.
 boolean isDirectory()
          Returns true if this node is a VPTDirectory.
 boolean isFile()
          Returns true if this node is a VPTFile.
 boolean isGroup()
          Whether this instance if a VPTGroup or any subclass of it.
 boolean isOpened()
          Tells if the resource is currently opened in jEdit.
 boolean isProject()
          Returns true if this node is a VPTProject.
 boolean isRoot()
          Returns whether this node is the root node.
 void open()
          "Opens" the node.
 boolean persistChildren()
          This method should return whether the children of this node should be persisted when the node is saved to the project config file.
 void setName(java.lang.String name)
          Changes the name of the node.
 void setParent(javax.swing.tree.MutableTreeNode newParent)
          Sets the parent for the node.
 void sortChildren()
          Sort the children list for this node using the default node comparator.
 void sortChildren(boolean recurse)
          Sort the children list for this node using the default node comparator.
 java.lang.String toString()
          Returns a string representation of the current node.
 
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, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setUserObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

treeSelectionForeground

protected static final java.awt.Color treeSelectionForeground

treeNoSelectionForeground

protected static final java.awt.Color treeNoSelectionForeground

treeSelectionBackground

protected static final java.awt.Color treeSelectionBackground

treeNoSelectionBackground

protected static final java.awt.Color treeNoSelectionBackground

name

protected java.lang.String name
Constructor Detail

VPTNode

protected VPTNode(java.lang.String name)
Deprecated. Use VPTNode(String,boolean)


VPTNode

protected VPTNode(java.lang.String name,
                  boolean allowsChildren)
Method Detail

findProjectFor

public static VPTProject findProjectFor(VPTNode node)
Returns the project associated with the node, or null if the node is the root of the project tree.


sortChildren

public void sortChildren()
Sort the children list for this node using the default node comparator. The trees containing the node are not notified of the update.


sortChildren

public void sortChildren(boolean recurse)
Sort the children list for this node using the default node comparator. The trees containing the node are not notified of the update.

Since:
PV 2.1.3.4

delete

public boolean delete()
The "delete()" method should remove the resource from the the disk, if applicable. This method does not call remove().

Returns:
Whether the deletion was successful or not.

isFile

public final boolean isFile()
Returns true if this node is a VPTFile.


isDirectory

public final boolean isDirectory()
Returns true if this node is a VPTDirectory.


isProject

public final boolean isProject()
Returns true if this node is a VPTProject.


isGroup

public boolean isGroup()
Whether this instance if a VPTGroup or any subclass of it.


isRoot

public final boolean isRoot()
Returns whether this node is the root node.


isOpened

public boolean isOpened()
Tells if the resource is currently opened in jEdit. This only makes sense for files, so the default just returns "false" and is overridden in the file implementation.


getName

public java.lang.String getName()
Returns the name of this node. The name is the text that will appear in the project tree.


setName

public void setName(java.lang.String name)
Changes the name of the node.


canWrite

public boolean canWrite()
Returns whether the underlying resource can be written to. It makes more sense for files and directories, for example, to check if it is possible to delete them.


toString

public java.lang.String toString()
Returns a string representation of the current node.


canOpen

public boolean canOpen()
This method should return whether it makes sense to "open" the node. For example, for file nodes, it should be reasonable to open the file in a jEdit buffer, so this method should return "true" and implement open() and close() to execute the opening and closing operations.


open

public void open()
"Opens" the node. The default implementation does nothing. If a node can be opened, it should implement the opening action in this method.


close

public void close()
"Closes" the node. This should "undo" what was done by open(), normally.


getNodePath

public abstract java.lang.String getNodePath()
Returns a String representing a "path" for this node. This can be any arbitrary String, but the idea is to have the string represent some kind of URL or file path. This makes more sense for nodes that deal with files and directories, or even URL links.


compareToNode

public int compareToNode(VPTNode node)
This method is used to sort the nodes in the trees. The rough hierarchy is Root -> Groups -> Projects -> "allows children" -> leaves, so try to keep that consistent.

IT'S VERY IMPORTANT TO IMPLEMENT THIS METHOD CORRECTLY. Especially for nodes that allow children nodes, since VPTDirectory expects nodes of these kinds to take care of the comparison themselves. There's danger of infinite recursion if you don't take this into account.


compareTo

public int compareTo(java.lang.Object o)
Implementation of the Comparable interface. Returns -1 if "o" is not another VPTNode, otherwise calls compareToNode(VPTNode).

Specified by:
compareTo in interface java.lang.Comparable
Since:
PV 2.1.0

findIndexForChild

public int findIndexForChild(VPTNode child)
Do a binary search with the goal of finding in what index of the child array of this node the given child would be inserted to maintain order according to the comparison rules defined by the compareToNode() methods.

Parameters:
child - The child to be inserted.
Returns:
The index where to put the child as to maintain the child array in ascendant order.

setParent

public void setParent(javax.swing.tree.MutableTreeNode newParent)
Sets the parent for the node. If the node is an openable node (e.g., a file), it registers itself in the parent project, or unregisters itself from the project in case the parent is being set to null.

Specified by:
setParent in interface javax.swing.tree.MutableTreeNode

persistChildren

public boolean persistChildren()
This method should return whether the children of this node should be persisted when the node is saved to the project config file. The default is "true".

Nodes that provide run time children (for example, allowing for the exploration of the contents of a JAR file) should override this method and return "false".

This only makes sense for nodes that allow children in the first place.

Since:
PV 2.1.0

getChildWithName

public VPTNode getChildWithName(java.lang.String name)
Returns the child directly under this node that has the given name. This doesn't look into the children's children.

Since:
PV 2.1.0

getIcon

public abstract javax.swing.Icon getIcon(boolean expanded)
Returns the icon to be shown on the tree next to the node name.

Parameters:
expanded - If the node is currently expanded or not.

getForegroundColor

public java.awt.Color getForegroundColor(boolean sel)
Returns the node's foreground color.

Parameters:
sel - If the node is currently selected.

getBackgroundColor

public java.awt.Color getBackgroundColor(boolean sel)
Returns the node's background color.

Parameters:
sel - If the node is currently selected.

getClipType

public int getClipType()
This method controls how the CellRenderer implementation will clip the name of the node when it doesn't fit in the tree.

Returns:
CLIP_NOCLIP in the default implementation, override to change it.
Since:
PV 2.1.0
See Also:
VPTCellRenderer

compareName

protected int compareName(VPTNode other)