home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

Book Home Java Enterprise in a Nutshell Search this book

Chapter 34. The javax.swing.tree Package

The javax.swing.tree package defines classes and interfaces used with the javax.swing.JTree component. The TreeModel interface defines the data to be displayed by a JTree component. DefaultTreeModel provides a commonly used implementation of this interface; it is implemented in terms of the TreeNode and MutableTreeNode interfaces. The TreeCellRenderer and TreeCellEditor interfaces are implemented by objects that can display or edit cells in the tree, using a Swing component as a template. Figure 34-1 shows the class hierarchy of this package. See Chapter 3, "Swing Programming Topics", for a discussion of and example using JTree and the javax.swing.tree package.

figure

Figure 34-1. The javax.swing.tree package

AbstractLayoutCacheJava 1.2
javax.swing.tree

This abstract class defines the methods that must be implemented by a class that wants to cache a JTree layout. This class is used by the JTree UI delegate. Applications never need to use or subclass this class.

public abstract class AbstractLayoutCache implements RowMapper {
// Public Constructors
public AbstractLayoutCache ();
// Inner Classes
;
// Property Accessor Methods (by property name)
public TreeModel getModel ();
public void setModel (TreeModel newModel);
public AbstractLayoutCache.NodeDimensions getNodeDimensions ();
public void setNodeDimensions (AbstractLayoutCache.NodeDimensions nd);
public int getPreferredHeight ();
public boolean isRootVisible ();
public void setRootVisible (boolean rootVisible); bound
public abstract int getRowCount ();
public int getRowHeight ();
public void setRowHeight (int rowHeight); bound
public TreeSelectionModel getSelectionModel ();
public void setSelectionModel (TreeSelectionModel newLSM);
// Public Instance Methods
public abstract java.awt.Rectangle getBounds (TreePath path, java.awt.Rectangle placeIn);
public abstract boolean getExpandedState (TreePath path);
public abstract TreePath getPathClosestTo (int x, int y);
public abstract TreePath getPathForRow (int row);
public int getPreferredWidth (java.awt.Rectangle bounds);
public abstract int getRowForPath (TreePath path);
public abstract int getVisibleChildCount (TreePath path);
public abstract java.util.Enumeration getVisiblePathsFrom (TreePath path);
public abstract void invalidatePathBounds (TreePath path);
public abstract void invalidateSizes ();
public abstract boolean isExpanded (TreePath path);
public abstract void setExpandedState (TreePath path, boolean isExpanded);
public abstract void treeNodesChanged (javax.swing.event.TreeModelEvent e);
public abstract void treeNodesInserted (javax.swing.event.TreeModelEvent e);
public abstract void treeNodesRemoved (javax.swing.event.TreeModelEvent e);
public abstract void treeStructureChanged (javax.swing.event.TreeModelEvent e);
// Methods Implementing RowMapper
public int[ ] getRowsForPaths (TreePath[ ] paths);
// Protected Instance Methods
protected java.awt.Rectangle getNodeDimensions (Object value, int row, int depth, boolean expanded, java.awt.Rectangle placeIn);
protected boolean isFixedRowHeight ();
// Protected Instance Fields
protected AbstractLayoutCache.NodeDimensions nodeDimensions ;
protected boolean rootVisible ;
protected int rowHeight ;
protected TreeModel treeModel ;
protected TreeSelectionModel treeSelectionModel ;
}

Hierarchy: Object-->AbstractLayoutCache(RowMapper)

Subclasses: FixedHeightLayoutCache, VariableHeightLayoutCache

AbstractLayoutCache.NodeDimensionsJava 1.2
javax.swing.tree

This class defines a method that can compute the dimensions of a node in a JTree. It is used internally by AbstractLayoutCache and its subclasses and by the JTree UI delegate. Applications never need to use it.

public abstract static class AbstractLayoutCache.NodeDimensions {
// Public Constructors
public NodeDimensions ();
// Public Instance Methods
public abstract java.awt.Rectangle getNodeDimensions (Object value, int row, int depth, boolean expanded, java.awt.Rectangle bounds);
}

Passed To: AbstractLayoutCache.setNodeDimensions(), VariableHeightLayoutCache.setNodeDimensions()

Returned By: AbstractLayoutCache.getNodeDimensions()

Type Of: AbstractLayoutCache.nodeDimensions

DefaultMutableTreeNodeJava 1.2
javax.swing.treecloneable serializable

This class implements the MutableTreeNode interface and adds a number of useful tree-manipulation methods. When you create a DefaultMutableTreeNode, you can optionally specify a user object--the data associated with the node--and a boolean value that specifies whether the node is allowed to have children. DefaultMutableTreeNode implements the MutableTreeNode methods that allow the parent and children of the node to be set and the TreeNode methods that allow the parent and children to be queried. In addition to these basic methods, DefaultMutableTreeNode includes a number of useful tree-manipulation methods, such as breadthFirstEnumeration() and depthFirstEnumeration(), which recursively enumerate the children of a node in breadth-first or depth-first order, respectively. See also DefaultTreeModel, the class with which DefaultMutableTreeNode is designed to work.

public class DefaultMutableTreeNode implements Cloneable, MutableTreeNode, Serializable {
// Public Constructors
public DefaultMutableTreeNode ();
public DefaultMutableTreeNode (Object userObject);
public DefaultMutableTreeNode (Object userObject, boolean allowsChildren);
// Public Constants
public static final java.util.Enumeration EMPTY_ENUMERATION ;
// Property Accessor Methods (by property name)
public boolean getAllowsChildren (); Implements:TreeNode default:true
public void setAllowsChildren (boolean allows);
public int getChildCount (); Implements:TreeNode default:0
public int getDepth (); default:0
public TreeNode getFirstChild ();
public DefaultMutableTreeNode getFirstLeaf ();
public TreeNode getLastChild ();
public DefaultMutableTreeNode getLastLeaf ();
public boolean isLeaf (); Implements:TreeNode default:true
public int getLeafCount (); default:1
public int getLevel (); default:0
public DefaultMutableTreeNode getNextLeaf (); default:null
public DefaultMutableTreeNode getNextNode (); default:null
public DefaultMutableTreeNode getNextSibling (); default:null
public TreeNode getParent (); Implements:TreeNode default:null
public void setParent (MutableTreeNode newParent); Implements:MutableTreeNode
public TreeNode[ ] getPath ();
public DefaultMutableTreeNode getPreviousLeaf (); default:null
public DefaultMutableTreeNode getPreviousNode (); default:null
public DefaultMutableTreeNode getPreviousSibling (); default:null
public TreeNode getRoot (); default:DefaultMutableTreeNode
public boolean isRoot (); default:true
public int getSiblingCount (); default:1
public Object getUserObject (); default:null
public void setUserObject (Object userObject); Implements:MutableTreeNode
public Object[ ] getUserObjectPath ();
// Public Instance Methods
public void add (MutableTreeNode newChild);
public java.util.Enumeration breadthFirstEnumeration ();
public java.util.Enumeration depthFirstEnumeration ();
public TreeNode getChildAfter (TreeNode aChild);
public TreeNode getChildBefore (TreeNode aChild);
public TreeNode getSharedAncestor (DefaultMutableTreeNode aNode);
public boolean isNodeAncestor (TreeNode anotherNode);
public boolean isNodeChild (TreeNode aNode);
public boolean isNodeDescendant (DefaultMutableTreeNode anotherNode);
public boolean isNodeRelated (DefaultMutableTreeNode aNode);
public boolean isNodeSibling (TreeNode anotherNode);
public java.util.Enumeration pathFromAncestorEnumeration (TreeNode ancestor);
public java.util.Enumeration postorderEnumeration ();
public java.util.Enumeration preorderEnumeration ();
public void removeAllChildren ();
// Methods Implementing MutableTreeNode
public void insert (MutableTreeNode newChild, int childIndex);
public void remove (MutableTreeNode aChild);
public void remove (int childIndex);
public void removeFromParent ();
public void setParent (MutableTreeNode newParent);
public void setUserObject (Object userObject);
// Methods Implementing TreeNode
public java.util.Enumeration children ();
public boolean getAllowsChildren (); default:true
public TreeNode getChildAt (int index);
public int getChildCount (); default:0
public int getIndex (TreeNode aChild);
public TreeNode getParent (); default:null
public boolean isLeaf (); default:true
// Public Methods Overriding Object
public Object clone ();
public String toString ();
// Protected Instance Methods
protected TreeNode[ ] getPathToRoot (TreeNode aNode, int depth);
// Protected Instance Fields
protected boolean allowsChildren ;
protected java.util.Vector children ;
protected MutableTreeNode parent ;
protected transient Object userObject ;
}

Hierarchy: Object-->DefaultMutableTreeNode(Cloneable,MutableTreeNode(TreeNode),Serializable)

Subclasses: JTree.DynamicUtilTreeNode

Passed To: JTree.DynamicUtilTreeNode.createChildren(), DefaultMutableTreeNode.{getSharedAncestor(), isNodeDescendant(), isNodeRelated()}

Returned By: DefaultMutableTreeNode.{getFirstLeaf(), getLastLeaf(), getNextLeaf(), getNextNode(), getNextSibling(), getPreviousLeaf(), getPreviousNode(), getPreviousSibling()}

DefaultTreeCellEditorJava 1.2
javax.swing.tree

This TreeCellEditor implementation is the default editor for editing simple tree node values. By default, it displays the standard icons for the tree node and allows the user to edit the node using a JTextField. When you create a DefaultTreeCellEditor, you supply a DefaultTreeCellRenderer and a TreeCellEditor. The DefaultTreeCellEditor combines the icon display capability of the renderer with the editing capability of the TreeCellEditor into a single functional TreeCellEditor. Often, you can use a javax.swing.DefaultCellEditor as the internal TreeCellEditor. Or, if you do not specify a TreeCellEditor, a default one that allows the user to edit text values is used. DefaultTreeCellEditor allows the user to edit a cell by triple-clicking on the node. You can change this behavior by subclassing and overriding the canEditImmediately() method.

public class DefaultTreeCellEditor implements java.awt.event.ActionListener, TreeCellEditor, javax.swing.event.TreeSelectionListener {
// Public Constructors
public DefaultTreeCellEditor (JTree tree, DefaultTreeCellRenderer renderer);
public DefaultTreeCellEditor (JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor);
// Inner Classes
;
;
// Event Registration Methods (by event name)
public void addCellEditorListener (javax.swing.event.CellEditorListener l); Implements:CellEditor
public void removeCellEditorListener (javax.swing.event.CellEditorListener l); Implements:CellEditor
// Public Instance Methods
public java.awt.Color getBorderSelectionColor ();
public java.awt.Font getFont ();
public void setBorderSelectionColor (java.awt.Color newColor);
public void setFont (java.awt.Font font);
// Methods Implementing ActionListener
public void actionPerformed (java.awt.event.ActionEvent e);
// Methods Implementing CellEditor
public void addCellEditorListener (javax.swing.event.CellEditorListener l);
public void cancelCellEditing ();
public Object getCellEditorValue ();
public boolean isCellEditable (java.util.EventObject event);
public void removeCellEditorListener (javax.swing.event.CellEditorListener l);
public boolean shouldSelectCell (java.util.EventObject event);
public boolean stopCellEditing ();
// Methods Implementing TreeCellEditor
public Component getTreeCellEditorComponent (JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row);
// Methods Implementing TreeSelectionListener
public void valueChanged (javax.swing.event.TreeSelectionEvent e);
// Protected Instance Methods
protected boolean canEditImmediately (java.util.EventObject event);
protected Container createContainer ();
protected TreeCellEditor createTreeCellEditor ();
protected void determineOffset (JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row);
protected boolean inHitRegion (int x, int y);
protected void prepareForEditing ();
protected void setTree (JTree newTree);
protected boolean shouldStartEditingTimer (java.util.EventObject event);
protected void startEditingTimer ();
// Protected Instance Fields
protected java.awt.Color borderSelectionColor ;
protected boolean canEdit ;
protected transient Component editingComponent ;
protected Container editingContainer ;
protected transient Icon editingIcon ;
protected java.awt.Font font ;
protected transient TreePath lastPath ;
protected transient int lastRow ;
protected transient int offset ;
protected TreeCellEditor realEditor ;
protected DefaultTreeCellRenderer renderer ;
protected transient Timer timer ;
protected transient JTree tree ;
}

Hierarchy: Object-->DefaultTreeCellEditor(java.awt.event.ActionListener(java.util.EventListener),TreeCellEditor(CellEditor),javax.swing.event.TreeSelectionListener(java.util.EventListener))

DefaultTreeCellEditor.DefaultTextFieldJava 1.2
javax.swing.treeserializable accessible(text) swing component

This class is a customized version of JTextField used by DefaultTreeCellEditor if no custom TreeCellEditor is supplied. Applications never need to use it.

public class DefaultTreeCellEditor.DefaultTextField extends JTextField {
// Public Constructors
public DefaultTextField (javax.swing.border.Border border);
// Property Accessor Methods (by property name)
public javax.swing.border.Border getBorder (); Overrides:JComponent
public java.awt.Font getFont (); Overrides:Component
public java.awt.Dimension getPreferredSize (); Overrides:JTextField
// Protected Instance Fields
protected javax.swing.border.Border border ;
}
DefaultTreeCellEditor.EditorContainerJava 1.2
javax.swing.treeserializable swing component

This simple container implementation is used internally by DefaultTreeCellEditor to combine the icons of its DefaultTreeCellRenderer with the editing component of the supplied TreeCellRenderer or the default text field. Applications never need to use this class.

public class DefaultTreeCellEditor.EditorContainer extends Container {
// Public Constructors
public EditorContainer ();
// Property Accessor Methods (by property name)
public java.awt.Dimension getPreferredSize (); Overrides:Container
// Public Instance Methods
public void EditorContainer ();
// Public Methods Overriding Container
public void doLayout ();
public void paint (java.awt.Graphics g);
}
DefaultTreeCellRendererJava 1.2
javax.swing.treeserializable accessible swing component

This JLabel subclass implements the TreeCellRenderer methods and is the default cell renderer used by JTree. It displays an icon for the node and the string that results from calling the toString() method of the node value. The various properties of this class exist primarily to allow customization of node colors and icons.

public class DefaultTreeCellRenderer extends JLabel implements TreeCellRenderer {
// Public Constructors
public DefaultTreeCellRenderer ();
// Property Accessor Methods (by property name)
public java.awt.Color getBackgroundNonSelectionColor (); default:ColorUIResource
public void setBackgroundNonSelectionColor (java.awt.Color newColor);
public java.awt.Color getBackgroundSelectionColor (); default:ColorUIResource
public void setBackgroundSelectionColor (java.awt.Color newColor);
public java.awt.Color getBorderSelectionColor (); default:ColorUIResource
public void setBorderSelectionColor (java.awt.Color newColor);
public Icon getClosedIcon ();
public void setClosedIcon (Icon newIcon);
public Icon getDefaultClosedIcon ();
public Icon getDefaultLeafIcon ();
public Icon getDefaultOpenIcon ();
public Icon getLeafIcon ();
public void setLeafIcon (Icon newIcon);
public Icon getOpenIcon ();
public void setOpenIcon (Icon newIcon);
public java.awt.Dimension getPreferredSize (); Overrides:JComponent
public java.awt.Color getTextNonSelectionColor (); default:ColorUIResource
public void setTextNonSelectionColor (java.awt.Color newColor);
public java.awt.Color getTextSelectionColor (); default:ColorUIResource
public void setTextSelectionColor (java.awt.Color newColor);
// Methods Implementing TreeCellRenderer
public Component getTreeCellRendererComponent (JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus);
// Public Methods Overriding JComponent
public void paint (java.awt.Graphics g);
public void setBackground (java.awt.Color color);
public void setFont (java.awt.Font font);
// Protected Instance Fields
protected java.awt.Color backgroundNonSelectionColor ;
protected java.awt.Color backgroundSelectionColor ;
protected java.awt.Color borderSelectionColor ;
protected transient Icon closedIcon ;
protected transient Icon leafIcon ;
protected transient Icon openIcon ;
protected boolean selected ;
protected java.awt.Color textNonSelectionColor ;
protected java.awt.Color textSelectionColor ;
}

Hierarchy: Object-->Component(java.awt.image.ImageObserver,java.awt.MenuContainer,Serializable)-->Container-->JComponent(Serializable)-->JLabel(Accessible,SwingConstants)-->DefaultTreeCellRenderer(TreeCellRenderer)

Passed To: DefaultTreeCellEditor.DefaultTreeCellEditor()

Type Of: DefaultTreeCellEditor.renderer

DefaultTreeModelJava 1.2
javax.swing.treeserializable model

This class implements the TreeModel interface for TreeNode or MutableTreeNode objects. When you create a DefaultTreeModel, you specify the TreeNode at the root of the tree. You also can specify how the tree distinguishes leaf nodes from nonleaf nodes. Usually, DefaultTreeModel calls the isLeaf() method of a TreeNode to determine whether it is a leaf. For the commonly used DefaultMutableTreeNode class, isLeaf() returns true if the node has no children. On the other hand, if the asksAllowsChildren property is set to true, DefaultTreeModel calls the getAllowsChildren() method of a TreeNode instead.

The TreeModel interface allows registration of javax.swing.event.TreeModelListener objects that are notified when the tree data or structure is changed. DefaultTreeModel provides a number of methods that make this notification simple. If you modify any of the TreeNode objects contained within a DefaultTreeModel after that model is in use, call one of the methods beginning with "node" or "nodes". These methods send out the appropriate javax.swing.event.TreeModelEvent notifications. If your modifications consist solely of inserting and removing nodes, you can use insertNodeInto() and removeNodeFromParent(). These methods make the appropriate modifications to the specified MutableTreeNode objects and also send out notification events.

public class DefaultTreeModel implements Serializable, TreeModel {
// Public Constructors
public DefaultTreeModel (TreeNode root);
public DefaultTreeModel (TreeNode root, boolean asksAllowsChildren);
// Event Registration Methods (by event name)
public void addTreeModelListener (javax.swing.event.TreeModelListener l); Implements:TreeModel
public void removeTreeModelListener (javax.swing.event.TreeModelListener l); Implements:TreeModel
// Public Instance Methods
public boolean asksAllowsChildren ();
public TreeNode[ ] getPathToRoot (TreeNode aNode);
public void insertNodeInto (MutableTreeNode newChild, MutableTreeNode parent, int index);
public void nodeChanged (TreeNode node);
public void nodesChanged (TreeNode node, int[ ] childIndices);
public void nodeStructureChanged (TreeNode node);
public void nodesWereInserted (TreeNode node, int[ ] childIndices);
public void nodesWereRemoved (TreeNode node, int[ ] childIndices, Object[ ] removedChildren);
public void reload ();
public void reload (TreeNode node);
public void removeNodeFromParent (MutableTreeNode node);
public void setAsksAllowsChildren (boolean newValue);
public void setRoot (TreeNode root);
// Methods Implementing TreeModel
public void addTreeModelListener (javax.swing.event.TreeModelListener l);
public Object getChild (Object parent, int index);
public int getChildCount (Object parent);
public int getIndexOfChild (Object parent, Object child);
public Object getRoot ();
public boolean isLeaf (Object node);
public void removeTreeModelListener (javax.swing.event.TreeModelListener l);
public void valueForPathChanged (TreePath path, Object newValue);
// Protected Instance Methods
protected void fireTreeNodesChanged (Object source, Object[ ] path, int[ ] childIndices, Object[ ] children);
protected void fireTreeNodesInserted (Object source, Object[ ] path, int[ ] childIndices, Object[ ] children);
protected void fireTreeNodesRemoved (Object source, Object[ ] path, int[ ] childIndices, Object[ ] children);
protected void fireTreeStructureChanged (Object source, Object[ ] path, int[ ] childIndices, Object[ ] children);
protected TreeNode[ ] getPathToRoot (TreeNode aNode, int depth);
// Protected Instance Fields
protected boolean asksAllowsChildren ;
protected javax.swing.event.EventListenerList listenerList ;
protected TreeNode root ;
}

Hierarchy: Object-->DefaultTreeModel(Serializable,TreeModel)

DefaultTreeSelectionModelJava 1.2
javax.swing.treecloneable serializable model

This class is used by default to maintain the selection state for the JTree component. Methods such as addSelectionPaths(), removeSelectionPaths(), setSelectionPaths(), getSelectionPaths(), clearSelection(), isPathSelected(), and isSelectionEmpty() can be used to manipulate and query the selection state. However, application programmers generally call similarly named methods of JTree, rather than interacting with the DefaultTreeSelectionModel directly. setSelectionMode() is an important method that does not have a JTree analog. Its argument should be one of the three constants defined by the TreeSelectionModel interface. These three constants allow a single item to be selected, a single contiguous range of items to be selected, or any number of possibly discontiguous items to be selected. DefaultTreeSelectionModel has methods for setting and querying the selection in terms of rows. These methods are intended for internal use by JTree and its UI delegate object. They typically are not useful to application programmers.

public class DefaultTreeSelectionModel implements Cloneable, Serializable, TreeSelectionModel {
// Public Constructors
public DefaultTreeSelectionModel ();
// Public Constants
public static final String SELECTION_MODE_PROPERTY ; ="selectionMode"
// Event Registration Methods (by event name)
public void addPropertyChangeListener (java.beans.PropertyChangeListener listener); Implements:TreeSelectionModel synchronized
public void removePropertyChangeListener (java.beans.PropertyChangeListener listener); Implements:TreeSelectionModel synchronized
public void addTreeSelectionListener (javax.swing.event.TreeSelectionListener x); Implements:TreeSelectionModel
public void removeTreeSelectionListener (javax.swing.event.TreeSelectionListener x); Implements:TreeSelectionModel
// Methods Implementing TreeSelectionModel
public void addPropertyChangeListener (java.beans.PropertyChangeListener listener); synchronized
public void addSelectionPath (TreePath path);
public void addSelectionPaths (TreePath[ ] paths);
public void addTreeSelectionListener (javax.swing.event.TreeSelectionListener x);
public void clearSelection ();
public TreePath getLeadSelectionPath (); default:null
public int getLeadSelectionRow (); default:-1
public int getMaxSelectionRow (); default:-1
public int getMinSelectionRow (); default:-1
public RowMapper getRowMapper (); default:null
public int getSelectionCount (); default:0
public int getSelectionMode (); default:4
public TreePath getSelectionPath (); default:null
public TreePath[ ] getSelectionPaths (); default:null
public int[ ] getSelectionRows (); default:null
public boolean isPathSelected (TreePath path);
public boolean isRowSelected (int row);
public boolean isSelectionEmpty (); default:true
public void removePropertyChangeListener (java.beans.PropertyChangeListener listener); synchronized
public void removeSelectionPath (TreePath path);
public void removeSelectionPaths (TreePath[ ] paths);
public void removeTreeSelectionListener (javax.swing.event.TreeSelectionListener x);
public void resetRowSelection ();
public void setRowMapper (RowMapper newMapper);
public void setSelectionMode (int mode);
public void setSelectionPath (TreePath path);
public void setSelectionPaths (TreePath[ ] pPaths);
// Public Methods Overriding Object
public Object clone () throws CloneNotSupportedException;
public String toString ();
// Protected Instance Methods
protected boolean arePathsContiguous (TreePath[ ] paths);
protected boolean canPathsBeAdded (TreePath[ ] paths);
protected boolean canPathsBeRemoved (TreePath[ ] paths);
protected void fireValueChanged (javax.swing.event.TreeSelectionEvent e);
protected void insureRowContinuity ();
protected void insureUniqueness ();
protected void notifyPathChange (java.util.Vector changedPaths, TreePath oldLeadSelection);
protected void updateLeadIndex ();
// Protected Instance Fields
protected javax.swing.event.SwingPropertyChangeSupport changeSupport ;
protected int leadIndex ;
protected TreePath leadPath ;
protected int leadRow ;
protected javax.swing.event.EventListenerList listenerList ;
protected DefaultListSelectionModel listSelectionModel ;
protected transient RowMapper rowMapper ;
protected TreePath[ ] selection ;
protected int selectionMode ;
}

Hierarchy: Object-->DefaultTreeSelectionModel(Cloneable,Serializable,TreeSelectionModel)

Subclasses: JTree.EmptySelectionModel

ExpandVetoExceptionJava 1.2
javax.swing.treeserializable checked

Thrown by one of the methods of a TreeWillExpandListener object to veto a proposed expansion or collapse of a node.

public class ExpandVetoException extends Exception {
// Public Constructors
public ExpandVetoException (javax.swing.event.TreeExpansionEvent event);
public ExpandVetoException (javax.swing.event.TreeExpansionEvent event, String message);
// Protected Instance Fields
protected javax.swing.event.TreeExpansionEvent event ;
}

Hierarchy: Object-->Throwable(Serializable)-->Exception-->ExpandVetoException

Thrown By: JTree.{fireTreeWillCollapse(), fireTreeWillExpand()}, javax.swing.event.TreeWillExpandListener.{treeWillCollapse(), treeWillExpand()}

FixedHeightLayoutCacheJava 1.2
javax.swing.tree

This class caches the layout of nodes in a JTree. It makes the simplifying assumption that all nodes in the tree have the same height. This class is used by the JTree UI delegate; applications never need to use it.

public class FixedHeightLayoutCache extends AbstractLayoutCache {
// Public Constructors
public FixedHeightLayoutCache ();
// Public Methods Overriding AbstractLayoutCache
public java.awt.Rectangle getBounds (TreePath path, java.awt.Rectangle placeIn);
public boolean getExpandedState (TreePath path);
public int getRowCount (); default:0
public TreePath getPathClosestTo (int x, int y);
public TreePath getPathForRow (int row);
public int getRowForPath (TreePath path);
public int getVisibleChildCount (TreePath path);
public java.util.Enumeration getVisiblePathsFrom (TreePath path);
public void invalidatePathBounds (TreePath path); empty
public void invalidateSizes ();
public boolean isExpanded (TreePath path);
public void setExpandedState (TreePath path, boolean isExpanded);
public void setModel (TreeModel newModel);
public void setRootVisible (boolean rootVisible);
public void setRowHeight (int rowHeight);
public void treeNodesChanged (javax.swing.event.TreeModelEvent e);
public void treeNodesInserted (javax.swing.event.TreeModelEvent e);
public void treeNodesRemoved (javax.swing.event.TreeModelEvent e);
public void treeStructureChanged (javax.swing.event.TreeModelEvent e);
}

Hierarchy: Object-->AbstractLayoutCache(RowMapper)-->FixedHeightLayoutCache

MutableTreeNodeJava 1.2
javax.swing.tree

This interface extends TreeNode and adds methods for inserting and removing children of a node and for setting the parent of a node. Additionally, it defines a method for associating an arbitrary object with a node. This user object is the data associated with the node, data that is displayed in some way by the JTree component.

public abstract interface MutableTreeNode extends TreeNode {
// Public Instance Methods
public abstract void insert (MutableTreeNode child, int index);
public abstract void remove (MutableTreeNode node);
public abstract void remove (int index);
public abstract void removeFromParent ();
public abstract void setParent (MutableTreeNode newParent);
public abstract void setUserObject (Object object);
}

Hierarchy: (MutableTreeNode(TreeNode))

Implementations: DefaultMutableTreeNode

Passed To: DefaultMutableTreeNode.{add(), insert(), remove(), setParent()}, DefaultTreeModel.{insertNodeInto(), removeNodeFromParent()}, MutableTreeNode.{insert(), remove(), setParent()}

Type Of: DefaultMutableTreeNode.parent

RowMapperJava 1.2
javax.swing.tree

This interface defines a method that maps from TreePath nodes in a JTree to numerical rows in the tree presentation. Because the arrangement of items in a tree is specific to the look-and-feel, RowMapper implementations are private to the look-and-feel. Application programmers never have to use or implement this interface.

public abstract interface RowMapper {
// Public Instance Methods
public abstract int[ ] getRowsForPaths (TreePath[ ] path);
}

Implementations: AbstractLayoutCache

Passed To: DefaultTreeSelectionModel.setRowMapper(), TreeSelectionModel.setRowMapper()

Returned By: DefaultTreeSelectionModel.getRowMapper(), TreeSelectionModel.getRowMapper()

Type Of: DefaultTreeSelectionModel.rowMapper

TreeCellEditorJava 1.2
javax.swing.tree

This interface extends the javax.swing.CellEditor interface to make it specific to the JTree component. getTreeCellEditorComponent() should initialize and return a shared component or container (typically a JComponent) that is to be used for editing the value of a tree node. The second argument to getTreeCellEditorComponent() is the tree node that is to be edited. If you use the DefaultTreeModel, this argument is a TreeNode. Note that this argument is the node itself, not the user object associated with the TreeNode. The additional arguments passed to getTreeCellEditorComponent() can be used to further configure the cell editor component, as desired. A TreeCellEditor must also implement all the methods defined by CellEditor, and it must correctly implement the protocol for communication between a JComponent and its cell editor. Most importantly, it must generate a javax.swing.event.ChangeEvent when editing is done.

public abstract interface TreeCellEditor extends CellEditor {
// Public Instance Methods
public abstract Component getTreeCellEditorComponent (JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row);
}

Hierarchy: (TreeCellEditor(CellEditor))

Implementations: DefaultCellEditor, DefaultTreeCellEditor

Passed To: JTree.setCellEditor(), DefaultTreeCellEditor.DefaultTreeCellEditor()

Returned By: JTree.getCellEditor(), DefaultTreeCellEditor.createTreeCellEditor()

Type Of: JTree.cellEditor, DefaultTreeCellEditor.realEditor

TreeCellRendererJava 1.2
javax.swing.tree

This interface defines the getTreeCellRendererComponent() method, which is responsible for returning a component (typically a JComponent) that is fully configured to render a node of a JTree. JTree uses a default TreeCellRenderer that is suitable in most situations. If you want custom rendering of tree nodes, however, you must implement this interface. The second argument to getTreeCellRendererComponent() is the node to be rendered. If you use the DefaultTreeModel, this argument is a TreeNode object. Note that it is not the user object associated with a TreeNode. The remaining arguments specify other information about the node. The renderer may choose to use this information in its rendering of the cell or not. The renderer is responsible for highlighting any selected nodes and for drawing any icons or other desired graphics that distinguish leaf nodes from branch nodes.

public abstract interface TreeCellRenderer {
// Public Instance Methods
public abstract Component getTreeCellRendererComponent (JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus);
}

Implementations: DefaultTreeCellRenderer

Passed To: JTree.setCellRenderer()

Returned By: JTree.getCellRenderer()

Type Of: JTree.cellRenderer

TreeModelJava 1.2
javax.swing.treemodel

This interface defines the methods necessary to represent a tree of objects for display in a JTree component. getRoot() returns the object at the root of the tree. getChildCount() returns the number of children a tree node has. getChild() returns a specified child of a node. The poorly named valueForPathChanged() method sets the data value associated with a node identified by a TreePath object. When this method is called, a TreeModel should generate a javax.swing.event.TreeModelEvent and notify all registered javax.swing.event.TreeModelListener objects by invoking their treeNodesChanged() methods.

When working with objects that have an implicit tree hierarchy, such as java.io.File objects, you can directly implement TreeModel to encapsulate the details of that tree hierarchy. In other cases, it is usually easier to use the DefaultTreeModel class, which implements the TreeModel interface for TreeNode objects.

public abstract interface TreeModel {
// Event Registration Methods (by event name)
public abstract void addTreeModelListener (javax.swing.event.TreeModelListener l);
public abstract void removeTreeModelListener (javax.swing.event.TreeModelListener l);
// Public Instance Methods
public abstract Object getChild (Object parent, int index);
public abstract int getChildCount (Object parent);
public abstract int getIndexOfChild (Object parent, Object child);
public abstract Object getRoot ();
public abstract boolean isLeaf (Object node);
public abstract void valueForPathChanged (TreePath path, Object newValue);
}

Implementations: DefaultTreeModel

Passed To: JTree.{JTree(), setModel()}, AbstractLayoutCache.setModel(), FixedHeightLayoutCache.setModel(), VariableHeightLayoutCache.setModel()

Returned By: JTree.{createTreeModel(), getDefaultTreeModel(), getModel()}, AbstractLayoutCache.getModel()

Type Of: JTree.treeModel, AbstractLayoutCache.treeModel

TreeNodeJava 1.2
javax.swing.tree

This interface is used by DefaultTreeModel to represent one node in a tree. Implementations must be able both to return the parent and the children, if any, of a node, and to distinguish between leaf nodes and branch nodes in the tree. Any useful implementation must also associate some kind of data with each node. Note that the TreeNode interface is used by DefaultTreeModel, not by TreeModel or by the JTree component. If you write your own implementation of TreeModel, you do not have to use the TreeNode interface. See also MutableTreeNode and DefaultMutableTreeNode.

public abstract interface TreeNode {
// Property Accessor Methods (by property name)
public abstract boolean getAllowsChildren ();
public abstract int getChildCount ();
public abstract boolean isLeaf ();
public abstract TreeNode getParent ();
// Public Instance Methods
public abstract java.util.Enumeration children ();
public abstract TreeNode getChildAt (int childIndex);
public abstract int getIndex (TreeNode node);
}

Implementations: javax.swing.text.AbstractDocument.AbstractElement, MutableTreeNode

Passed To: Too many methods to list.

Returned By: Too many methods to list.

Type Of: DefaultTreeModel.root

TreePathJava 1.2
javax.swing.treeserializable

This class represents a node in a tree and the path of nodes between that node and the root of the tree. The TreeModel interface does not contain methods for querying the parent of a given node. Therefore, the JTree component and its related classes rely on TreePath to encapsulate the list of ancestors of a node. getLastPathComponent() returns the node represented by the path. getPath() returns an array of objects that represents the complete path. The first element in the array is the root of the tree, and the last element is the node returned by getLastPathComponent(). isDescendant() tests whether a TreePath is a descendant of this one.

public class TreePath implements Serializable {
// Public Constructors
public TreePath (Object singlePath);
public TreePath (Object[ ] path);
// Protected Constructors
protected TreePath ();
protected TreePath (Object[ ] path, int length);
protected TreePath (TreePath parent, Object lastElement);
// Property Accessor Methods (by property name)
public Object getLastPathComponent ();
public TreePath getParentPath ();
public Object[ ] getPath ();
public int getPathCount ();
// Public Instance Methods
public Object getPathComponent (int element);
public boolean isDescendant (TreePath aTreePath);
public TreePath pathByAddingChild (Object child);
// Public Methods Overriding Object
public boolean equals (Object o);
public int hashCode ();
public String toString ();
}

Hierarchy: Object-->TreePath(Serializable)

Passed To: Too many methods to list.

Returned By: Too many methods to list.

Type Of: javax.swing.event.TreeExpansionEvent.path, javax.swing.event.TreeModelEvent.path, javax.swing.event.TreeSelectionEvent.{newLeadSelectionPath, oldLeadSelectionPath, paths}, DefaultTreeCellEditor.lastPath, DefaultTreeSelectionModel.{leadPath, selection}

TreeSelectionModelJava 1.2
javax.swing.treemodel

This interface defines the methods that must be implemented for an object to maintain the selection state of a JTree component. See the DefaultTreeSelectionModel implementation for details.

public abstract interface TreeSelectionModel {
// Public Constants
public static final int CONTIGUOUS_TREE_SELECTION ; =2
public static final int DISCONTIGUOUS_TREE_SELECTION ; =4
public static final int SINGLE_TREE_SELECTION ; =1
// Event Registration Methods (by event name)
public abstract void addPropertyChangeListener (java.beans.PropertyChangeListener listener);
public abstract void removePropertyChangeListener (java.beans.PropertyChangeListener listener);
public abstract void addTreeSelectionListener (javax.swing.event.TreeSelectionListener x);
public abstract void removeTreeSelectionListener (javax.swing.event.TreeSelectionListener x);
// Property Accessor Methods (by property name)
public abstract TreePath getLeadSelectionPath ();
public abstract int getLeadSelectionRow ();
public abstract int getMaxSelectionRow ();
public abstract int getMinSelectionRow ();
public abstract RowMapper getRowMapper ();
public abstract void setRowMapper (RowMapper newMapper);
public abstract int getSelectionCount ();
public abstract boolean isSelectionEmpty ();
public abstract int getSelectionMode ();
public abstract void setSelectionMode (int mode);
public abstract TreePath getSelectionPath ();
public abstract void setSelectionPath (TreePath path);
public abstract TreePath[ ] getSelectionPaths ();
public abstract void setSelectionPaths (TreePath[ ] paths);
public abstract int[ ] getSelectionRows ();
// Public Instance Methods
public abstract void addSelectionPath (TreePath path);
public abstract void addSelectionPaths (TreePath[ ] paths);
public abstract void clearSelection ();
public abstract boolean isPathSelected (TreePath path);
public abstract boolean isRowSelected (int row);
public abstract void removeSelectionPath (TreePath path);
public abstract void removeSelectionPaths (TreePath[ ] paths);
public abstract void resetRowSelection ();
}

Implementations: DefaultTreeSelectionModel

Passed To: JTree.setSelectionModel(), AbstractLayoutCache.setSelectionModel()

Returned By: JTree.getSelectionModel(), AbstractLayoutCache.getSelectionModel()

Type Of: JTree.selectionModel, AbstractLayoutCache.treeSelectionModel

VariableHeightLayoutCacheJava 1.2
javax.swing.tree

This class caches the layout of nodes in a JTree. It allows tree nodes to have variable heights. This class is used by the JTree UI delegate; applications never need to use it.

public class VariableHeightLayoutCache extends AbstractLayoutCache {
// Public Constructors
public VariableHeightLayoutCache ();
// Public Methods Overriding AbstractLayoutCache
public java.awt.Rectangle getBounds (TreePath path, java.awt.Rectangle placeIn);
public boolean getExpandedState (TreePath path);
public TreePath getPathClosestTo (int x, int y);
public TreePath getPathForRow (int row);
public int getPreferredWidth (java.awt.Rectangle bounds);
public int getRowCount (); default:0
public int getRowForPath (TreePath path);
public int getVisibleChildCount (TreePath path);
public java.util.Enumeration getVisiblePathsFrom (TreePath path);
public void invalidatePathBounds (TreePath path);
public void invalidateSizes ();
public boolean isExpanded (TreePath path);
public void setExpandedState (TreePath path, boolean isExpanded);
public void setModel (TreeModel newModel); bound
public void setNodeDimensions (AbstractLayoutCache.NodeDimensions nd);
public void setRootVisible (boolean rootVisible); bound
public void setRowHeight (int rowHeight); bound
public void treeNodesChanged (javax.swing.event.TreeModelEvent e);
public void treeNodesInserted (javax.swing.event.TreeModelEvent e);
public void treeNodesRemoved (javax.swing.event.TreeModelEvent e);
public void treeStructureChanged (javax.swing.event.TreeModelEvent e);
}

Hierarchy: Object-->AbstractLayoutCache(RowMapper)-->VariableHeightLayoutCache



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.







??????????????@Mail.ru