javax.swing.plaf
Class TreeUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by javax.swing.plaf.TreeUI
Direct Known Subclasses:
BasicTreeUI, MultiTreeUI

public abstract class TreeUI
extends ComponentUI

An abstract base class for delegates that provide the user interface for JTree.

See Also:
JTree

Constructor Summary
TreeUI()
          Constructs a new TreeUI.
 
Method Summary
abstract  void cancelEditing(JTree tree)
          Cancels editing a tree cell, discarding any entered value.
abstract  TreePath getClosestPathForLocation(JTree tree, int x, int y)
          Finds the path that is closest to the specified position.
abstract  TreePath getEditingPath(JTree tree)
          Retrieves the tree cell that is currently being edited.
abstract  Rectangle getPathBounds(JTree tree, TreePath path)
          Determines the geometric extent of the label that is drawn for a path.
abstract  TreePath getPathForRow(JTree tree, int row)
          Creates a TreePath for the specified row.
abstract  int getRowCount(JTree tree)
          Counts how many rows are currently displayed.
abstract  int getRowForPath(JTree tree, TreePath path)
          Determines in which row a TreePath is currently being displayed.
abstract  boolean isEditing(JTree tree)
          Determines whether the user is currently editing a tree cell.
abstract  void startEditingAtPath(JTree tree, TreePath path)
          Starts a session to edit a tree cell.
abstract  boolean stopEditing(JTree tree)
          Stops editing a tree cell, committing the entered value into the tree’s model.
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeUI

public TreeUI()
Constructs a new TreeUI.

Method Detail

getPathBounds

public abstract Rectangle getPathBounds(JTree tree,
                                        TreePath path)
Determines the geometric extent of the label that is drawn for a path.

Parameters:
tree - the JTree for which this delegate object provides the user interface.
path - the path whose label extent is requested.
Returns:
a rectangle enclosing the label, or null if path contains invalid nodes.

getPathForRow

public abstract TreePath getPathForRow(JTree tree,
                                       int row)
Creates a TreePath for the specified row.

Parameters:
tree - the JTree for which this delegate object provides the user interface.
row - the index of the row, which should be a number in the range [0, getRowCount(tree) - 1].
Returns:
a TreePath for the specified row, or null if row is outside the valid range.

getRowForPath

public abstract int getRowForPath(JTree tree,
                                  TreePath path)
Determines in which row a TreePath is currently being displayed.

Parameters:
tree - the JTree for which this delegate object provides the user interface.
path - the path for which the caller wants to know in which row it is being displayed.
Returns:
a number in the range [0, getRowCount(tree) - 1] if the path is currently on display; -1 if the path is not shown to the user.

getRowCount

public abstract int getRowCount(JTree tree)
Counts how many rows are currently displayed.

Parameters:
tree - the JTree for which this delegate object provides the user interface.
Returns:
the number of visible rows.

getClosestPathForLocation

public abstract TreePath getClosestPathForLocation(JTree tree,
                                                   int x,
                                                   int y)
Finds the path that is closest to the specified position.

[A screen shot of a JTree]

As shown by the above illustration, the bounds of the closest path do not necessarily need to contain the passed location.

Parameters:
tree - the JTree for which this delegate object provides the user interface.
x - the horizontal location, relative to the origin of tree.
y - the vertical location, relative to the origin of tree.
Returns:
the closest path, or null if the tree is currenlty not displaying any paths at all.

isEditing

public abstract boolean isEditing(JTree tree)
Determines whether the user is currently editing a tree cell.

Parameters:
tree - the JTree for which this delegate object provides the user interface.
See Also:
getEditingPath(javax.swing.JTree)

stopEditing

public abstract boolean stopEditing(JTree tree)
Stops editing a tree cell, committing the entered value into the tree’s model. If no editing session is active, or if the active editor does not agree to stopping, nothing happens. In some look and feels, this action happens when the user has pressed the enter key.

Parameters:
tree - the JTree for which this delegate object provides the user interface.
Returns:
false if the editing still goes on because the cell editor has objected to stopping the session; true if editing has been stopped.

cancelEditing

public abstract void cancelEditing(JTree tree)
Cancels editing a tree cell, discarding any entered value. If no editing session is active, nothing happens. The cell editor is not given an opportunity to veto the canceling. In some look and feels, this action happens when the user has pressed the escape key.

Parameters:
tree - the JTree for which this delegate object provides the user interface.

startEditingAtPath

public abstract void startEditingAtPath(JTree tree,
                                        TreePath path)
Starts a session to edit a tree cell. If the cell editor rejects editing the cell, it will just be selected.

Parameters:
tree - the JTree for which this delegate object provides the user interface.
path - the cell to edit.

getEditingPath

public abstract TreePath getEditingPath(JTree tree)
Retrieves the tree cell that is currently being edited.

Returns:
the currently edited path, or null if no editing session is currently active.