com.threerings.swing
Class PrefsTreeNode

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by com.threerings.swing.PrefsTreeNode
All Implemented Interfaces:
Exportable, Serializable, Cloneable, MutableTreeNode, TreeNode

public class PrefsTreeNode
extends DefaultMutableTreeNode
implements Exportable

A node in a PrefsTree. Nodes are either internal nodes with null values (representing Preferences nodes) or leaf nodes with non-null values (representing properties set in the parent Preferences node).

See Also:
Serialized Form

Field Summary
protected  boolean _expanded
          Whether or not this node is expanded in the tree.
protected  Object _value
          The value of this node, if it is a leaf.
protected static String EMPTY_NAME
          Our replacement for the empty name.
protected static String EXPANDED
          The name of the expanded property.
protected static String SLASH_REPLACEMENT
          Replacement for slashes, which are not allowed in names.
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
PrefsTreeNode()
          No-arg constructor for deserialization.
PrefsTreeNode(Preferences prefs)
          Creates a new preferences node from the supplied preferences.
PrefsTreeNode(String name, Object value)
          Creates a new preferences node.
 
Method Summary
 void addToPreferences(Preferences prefs)
          Adds the contents of this node to the supplied preferences.
protected static String decode(String name)
          Decodes the supplied name encoded with encode(java.lang.String).
protected static String encode(String name)
          Encodes the supplied name, making it safe for use as a Preferences name.
 void expandPaths(JTree tree)
          Expands paths according to the _expanded field.
 String findNameForChild(String base)
          Finds a unique name for a new child node derived from the supplied base.
 PrefsTreeNode getChild(String name)
          Returns the child with the supplied name, if it exists.
 int getInsertionIndex(PrefsTreeNode child)
          Returns the index at which the specified child should be inserted.
protected  String getName()
          Returns the (encoded) name of this node.
protected  String getNodeName()
          Returns the name of the node relative to the preferences.
protected  Preferences getPreferenceNode(Preferences prefs)
          Returns the preference node corresponding to this node.
 Object getValue()
          Returns a reference to the decoded value of this node.
protected  boolean haveChildNamed(String name)
          Determines whether the node has a child with the given name.
protected  void insertSorted(PrefsTreeNode child)
          Inserts the specified node in sorted order.
 void readFields(Importer in)
          Custom field read method.
 void removeFromPreferences(Preferences prefs)
          Removes the contents of this node from the supplied preferences.
 void setExpanded(JTree tree, Preferences prefs, boolean expanded)
          Sets whether or not this node is expanded in the tree.
 void writeFields(Exporter out)
          Custom field write method.
 
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

_value

protected Object _value
The value of this node, if it is a leaf.


_expanded

protected boolean _expanded
Whether or not this node is expanded in the tree.


EXPANDED

protected static final String EXPANDED
The name of the expanded property.

See Also:
Constant Field Values

EMPTY_NAME

protected static final String EMPTY_NAME
Our replacement for the empty name.

See Also:
Constant Field Values

SLASH_REPLACEMENT

protected static final String SLASH_REPLACEMENT
Replacement for slashes, which are not allowed in names.

See Also:
Constant Field Values
Constructor Detail

PrefsTreeNode

public PrefsTreeNode(Preferences prefs)
Creates a new preferences node from the supplied preferences.


PrefsTreeNode

public PrefsTreeNode(String name,
                     Object value)
Creates a new preferences node.


PrefsTreeNode

public PrefsTreeNode()
No-arg constructor for deserialization.

Method Detail

getValue

public Object getValue()
Returns a reference to the decoded value of this node.


getChild

public PrefsTreeNode getChild(String name)
Returns the child with the supplied name, if it exists.


setExpanded

public void setExpanded(JTree tree,
                        Preferences prefs,
                        boolean expanded)
Sets whether or not this node is expanded in the tree.


findNameForChild

public String findNameForChild(String base)
Finds a unique name for a new child node derived from the supplied base.


addToPreferences

public void addToPreferences(Preferences prefs)
Adds the contents of this node to the supplied preferences.


removeFromPreferences

public void removeFromPreferences(Preferences prefs)
Removes the contents of this node from the supplied preferences.


getInsertionIndex

public int getInsertionIndex(PrefsTreeNode child)
Returns the index at which the specified child should be inserted.


expandPaths

public void expandPaths(JTree tree)
Expands paths according to the _expanded field.


writeFields

public void writeFields(Exporter out)
                 throws IOException
Custom field write method.

Throws:
IOException

readFields

public void readFields(Importer in)
                throws IOException
Custom field read method.

Throws:
IOException

haveChildNamed

protected boolean haveChildNamed(String name)
Determines whether the node has a child with the given name.


getPreferenceNode

protected Preferences getPreferenceNode(Preferences prefs)
Returns the preference node corresponding to this node.


getNodeName

protected String getNodeName()
Returns the name of the node relative to the preferences.


getName

protected String getName()
Returns the (encoded) name of this node.


insertSorted

protected void insertSorted(PrefsTreeNode child)
Inserts the specified node in sorted order.


encode

protected static String encode(String name)
Encodes the supplied name, making it safe for use as a Preferences name.


decode

protected static String decode(String name)
Decodes the supplied name encoded with encode(java.lang.String).