javax.swing.plaf.basic

Class BasicTreeUI

public class BasicTreeUI extends TreeUI

A delegate providing the user interface for JTree according to the Basic look and feel.

See Also: JTree

Nested Class Summary
classBasicTreeUI.CellEditorHandler
Listener responsible for getting cell editing events and updating the tree accordingly.
classBasicTreeUI.ComponentHandler
Updates the preferred size when scrolling, if necessary.
classBasicTreeUI.FocusHandler
Repaints the lead selection row when focus is lost/grained.
classBasicTreeUI.KeyHandler
This is used to get multiple key down events to appropriately genereate events.
classBasicTreeUI.MouseHandler
MouseListener is responsible for updating the selection based on mouse events.
classBasicTreeUI.MouseInputHandler
MouseInputHandler handles passing all mouse events, including mouse motion events, until the mouse is released to the destination it is constructed with.
classBasicTreeUI.NodeDimensionsHandler
Class responsible for getting size of node, method is forwarded to BasicTreeUI method.
classBasicTreeUI.PropertyChangeHandler
PropertyChangeListener for the tree.
classBasicTreeUI.SelectionModelPropertyChangeHandler
Listener on the TreeSelectionModel, resets the row selection if any of the properties of the model change.
classBasicTreeUI.TreeCancelEditingAction
The action to cancel editing on this tree.
classBasicTreeUI.TreeExpansionHandler
Updates the TreeState in response to nodes expanding/collapsing.
classBasicTreeUI.TreeHomeAction
TreeHomeAction is used to handle end/home actions.
classBasicTreeUI.TreeIncrementAction
TreeIncrementAction is used to handle up/down actions.
classBasicTreeUI.TreeModelHandler
Forwards all TreeModel events to the TreeState.
classBasicTreeUI.TreePageAction
TreePageAction handles page up and page down events.
classBasicTreeUI.TreeSelectionHandler
Listens for changes in the selection model and updates the display accordingly.
classBasicTreeUI.TreeToggleAction
For the first selected row expandedness will be toggled.
classBasicTreeUI.TreeTraverseAction
TreeTraverseAction is the action used for left/right keys.
Field Summary
protected TreeCellEditorcellEditor
Editor for the tree.
protected IconcollapsedIcon
Collapse Icon for the tree.
protected booleancreatedCellEditor
Set to true if editor that is currently in the tree was created by this instance.
protected booleancreatedRenderer
Set to true if the renderer that is currently in the tree was created by this instance.
protected TreeCellRenderercurrentCellRenderer
Renderer that is being used to do the actual cell drawing.
protected intdepthOffset
How much the depth should be offset to properly calculate x locations.
protected Hashtable<TreePath,Boolean>drawingCache
Used for minimizing the drawing of vertical lines.
protected ComponenteditingComponent
When editing, this will be the Component that is doing the actual editing.
protected TreePatheditingPath
Path that is being edited.
protected inteditingRow
Row that is being edited.
protected booleaneditorHasDifferentSize
Set to true if the editor has a different size than the renderer.
protected IconexpandedIcon
Expanded Icon for the tree.
protected booleanlargeModel
True if doing optimizations for a largeModel.
protected intlastSelectedRow
Index of the row that was last selected.
protected intleftChildIndent
Distance between left margin and where vertical dashes will be drawn.
protected AbstractLayoutCache.NodeDimensionsnodeDimensions
Responsible for telling the TreeState the size needed for a node.
protected DimensionpreferredMinSize
Minimum size needed to completely display all the nodes.
protected DimensionpreferredSize
Size needed to completely display all the nodes.
protected CellRendererPanerendererPane
Used to paint the TreeCellRenderer.
protected intrightChildIndent
Distance between leftChildIndent and where cell contents will be drawn.
protected booleanstopEditingInCompleteEditing
Set to false when editing and shouldSelectCall() returns true meaning the node should be selected before editing, used in completeEditing.
protected inttotalChildIndent
Total fistance that will be indented.
protected JTreetree
Component that we're going to be drawing onto.
protected TreeModeltreeModel
Used to determine what to display.
protected TreeSelectionModeltreeSelectionModel
Model maintaining the selection.
protected AbstractLayoutCachetreeState
Object responsible for handling sizing and expanded issues.
protected booleanvalidCachedPreferredSize
Is the preferredSize valid?
Constructor Summary
BasicTreeUI()
Creates a new BasicTreeUI object.
Method Summary
voidcancelEditing(JTree tree)
Cancels the current editing session.
protected voidcheckForClickInExpandControl(TreePath path, int mouseX, int mouseY)
If the mouseX and mouseY are in the expand or collapse region of the row, this will toggle the row.
protected voidcompleteEditing()
Messages to stop the editing session.
protected voidcompleteEditing(boolean messageStop, boolean messageCancel, boolean messageTree)
Stops the editing session.
protected voidcompleteUIInstall()
Invoked from installUI after all the defaults/listeners have been installed.
protected voidcompleteUIUninstall()
Invoked from uninstallUI after all the defaults/listeners have been uninstalled.
protected voidconfigureLayoutCache()
Resets the treeState instance based on the tree we're providing the look and feel for.
protected CellEditorListenercreateCellEditorListener()
Creates a listener to handle events from the current editor
protected CellRendererPanecreateCellRendererPane()
Returns the renderer pane that renderer components are placed in.
protected ComponentListenercreateComponentListener()
Creates and returns a new ComponentHandler.
protected TreeCellEditorcreateDefaultCellEditor()
Creates a default cell editor.
protected TreeCellRenderercreateDefaultCellRenderer()
Returns the default cell renderer that is used to do the stamping of each node.
protected FocusListenercreateFocusListener()
Creates the listener that is responsible for updating the display when focus is lost/grained.
protected KeyListenercreateKeyListener()
Creates the listener reponsible for getting key events from the tree.
protected AbstractLayoutCachecreateLayoutCache()
Creates the object responsible for managing what is expanded, as well as the size of nodes.
protected MouseListenercreateMouseListener()
Creates the listener responsible for updating the selection based on mouse events.
protected AbstractLayoutCache.NodeDimensionscreateNodeDimensions()
Creates an instance of NodeDimensions that is able to determine the size of a given node in the tree.
protected PropertyChangeListenercreatePropertyChangeListener()
Creates a listener that is reponsible for the updates the UI based on how the tree changes.
protected PropertyChangeListenercreateSelectionModelPropertyChangeListener()
Creates the listener responsible for getting property change events from the selection model.
protected TreeExpansionListenercreateTreeExpansionListener()
Creates and returns the object responsible for updating the treestate when a nodes expanded state changes.
protected TreeModelListenercreateTreeModelListener()
Returns a listener that can update the tree when the model changes.
protected TreeSelectionListenercreateTreeSelectionListener()
Creates the listener that updates the display based on selection change methods.
static ComponentUIcreateUI(JComponent c)
Returns an instance of the UI delegate for the specified component.
protected voiddrawCentered(Component c, Graphics g, Icon icon, int x, int y)
Draws an icon at around a specific position
protected voiddrawDashedHorizontalLine(Graphics g, int y, int x1, int x2)
Draws a dashed horizontal line.
protected voiddrawDashedVerticalLine(Graphics g, int x, int y1, int y2)
Draws a dashed vertical line.
protected voidensureRowsAreVisible(int beginRow, int endRow)
Ensures that the rows identified by beginRow through endRow are visible.
protected TreeCellEditorgetCellEditor()
Returns the TreeCellEditor for this tree.
protected TreeCellRenderergetCellRenderer()
Return currentCellRenderer, which will either be the trees renderer, or defaultCellRenderer, which ever was not null.
TreePathgetClosestPathForLocation(JTree tree, int x, int y)
Returns the path to the node that is closest to x,y.
IcongetCollapsedIcon()
Returns the current collapsed icon.
TreePathgetEditingPath(JTree tree)
Returns the path to the element that is being editted.
IcongetExpandedIcon()
Returns the current expanded icon.
protected ColorgetHashColor()
Returns the Hash color.
protected intgetHorizontalLegBuffer()
The horizontal element of legs between nodes starts at the right of the left-hand side of the child node by default.
protected TreePathgetLastChildPath(TreePath parent)
Returns a path to the last child of parent
intgetLeftChildIndent()
Returns the indent value for the left child.
DimensiongetMaximumSize(JComponent c)
Returns the maximum size for the component, which will be the preferred size if the instance is currently in JTree or (0,0).
DimensiongetMinimumSize(JComponent c)
Returns the minimum size for this component.
protected TreeModelgetModel()
Returns the tree's model
RectanglegetPathBounds(JTree tree, TreePath path)
Returns the Rectangle enclosing the label portion that the last item in path will be drawn to.
TreePathgetPathForRow(JTree tree, int row)
Returns the path for passed in row.
DimensiongetPreferredMinSize()
Gets the preferred minimum size.
DimensiongetPreferredSize(JComponent c)
Returns the preferred size to properly display the tree, this is a cover method for getPreferredSize(c, false).
DimensiongetPreferredSize(JComponent c, boolean checkConsistancy)
Returns the preferred size to represent the tree in c.
intgetRightChildIndent()
Returns the indent value for the right child.
intgetRowCount(JTree tree)
Returns the number of rows that are being displayed.
intgetRowForPath(JTree tree, TreePath path)
Returns the row that the last item identified in path is visible at.
protected intgetRowHeight()
Returns the current row height.
protected intgetRowX(int row, int depth)
Returns the amount to indent the given row
protected TreeSelectionModelgetSelectionModel()
Returns the current selection model.
protected booleangetShowsRootHandles()
Returns true if the node handles are to be displayed.
protected intgetVerticalLegBuffer()
The vertical element of legs between nodes starts at the bottom of the parent node by default.
protected voidhandleExpandControlClick(TreePath path, int mouseX, int mouseY)
Messaged when the user clicks the particular row, this invokes toggleExpandState.
protected voidinstallComponents()
Installs the subcomponents of the tree, which is the renderer pane.
protected voidinstallDefaults()
Install all defaults for the tree.
protected voidinstallKeyboardActions()
Install all keyboard actions for this
protected voidinstallListeners()
Install all listeners for this
voidinstallUI(JComponent c)
Install the UI for the component
protected booleanisEditable()
Returns true if the receiver allows editing.
booleanisEditing(JTree tree)
Returns true if the tree is being edited.
protected booleanisLargeModel()
Returns true if largeModel is set
protected booleanisLeaf(int row)
Returns true if the node at row is a leaf.
protected booleanisLocationInExpandControl(TreePath path, int mouseX, int mouseY)
Returns true if the mouseX and mouseY fall in the area of row that is used to expand/collpse the node and the node at row does not represent a leaf.
protected booleanisMultiSelectEvent(MouseEvent event)
Returning true signifies a mouse event on the node should select from the anchor point.
protected booleanisRootVisible()
Returns true if the root is visible.
protected booleanisToggleEvent(MouseEvent event)
Returning true indicates the row under the mouse should be toggled based on the event.
protected booleanisToggleSelectionEvent(MouseEvent event)
Returning true signifies a mouse event on the node should toggle the selection of only the row under the mouse.
voidpaint(Graphics g, JComponent c)
Paints the specified component appropriate for the look and feel.
protected voidpaintExpandControl(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
Paints the expand (toggle) part of a row.
protected voidpaintHorizontalLine(Graphics g, JComponent c, int y, int left, int right)
Draws a horizontal line using the given graphic context
protected voidpaintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
Paints the horizontal part of the leg.
protected voidpaintRow(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
Paints the renderer part of a row.
protected voidpaintVerticalLine(Graphics g, JComponent c, int x, int top, int bottom)
Draws a vertical line using the given graphic context
protected voidpaintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path)
Paints the vertical part of the leg.
protected voidpathWasCollapsed(TreePath path)
Messaged from the VisibleTreeNode after it has collapsed
protected voidpathWasExpanded(TreePath path)
Messaged from the VisibleTreeNode after it has been expanded.
protected voidprepareForUIInstall()
Invoked after the tree instance variable has been set, but before any default/listeners have been installed.
protected voidprepareForUIUninstall()
Prepares for the UI to uninstall.
protected voidselectPathForEvent(TreePath path, MouseEvent event)
Messaged to update the selection based on a MouseEvent over a particular row.
protected voidsetCellEditor(TreeCellEditor editor)
Sets the cell editor.
protected voidsetCellRenderer(TreeCellRenderer tcr)
Sets the TreeCellRenderer to tcr.
voidsetCollapsedIcon(Icon newG)
Sets the collapsed icon.
protected voidsetEditable(boolean newValue)
Configures the receiver to allow, or not allow, editing.
voidsetExpandedIcon(Icon newG)
Sets the expanded icon.
protected voidsetHashColor(Color color)
Sets the Hash color.
protected voidsetLargeModel(boolean largeModel)
Updates the componentListener, if necessary.
voidsetLeftChildIndent(int newAmount)
Sets the left child's indent value.
protected voidsetModel(TreeModel model)
Sets the tree's model.
voidsetPreferredMinSize(Dimension newSize)
Sets the preferred minimum size.
voidsetRightChildIndent(int newAmount)
Sets the right child's indent value.
protected voidsetRootVisible(boolean newValue)
Sets the root to being visible.
protected voidsetRowHeight(int rowHeight)
Sets the row height.
protected voidsetSelectionModel(TreeSelectionModel newLSM)
Resets the selection model.
protected voidsetShowsRootHandles(boolean newValue)
Determines whether the node handles are to be displayed.
protected booleanshouldPaintExpandControl(TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
Returns true if the expand (toggle) control should be drawn for the specified row.
protected booleanstartEditing(TreePath path, MouseEvent event)
Will start editing for node if there is a cellEditor and shouldSelectCall returns true.
voidstartEditingAtPath(JTree tree, TreePath path)
Selects the last item in path and tries to edit it.
booleanstopEditing(JTree tree)
Stops the current editing session.
protected voidtoggleExpandState(TreePath path)
Expands path if it is not expanded, or collapses row if it is expanded.
protected voiduninstallComponents()
Uninstall the rendererPane.
protected voiduninstallDefaults()
Uninstall the defaults for the tree
protected voiduninstallKeyboardActions()
Uninstall all keyboard actions.
protected voiduninstallListeners()
Uninstall all registered listeners
voiduninstallUI(JComponent c)
Uninstall the UI for the component
protected voidupdateCachedPreferredSize()
Updates the preferredSize instance variable, which is returned from getPreferredSize().
protected voidupdateCellEditor()
Updates the cellEditor based on editability of the JTree that we're contained in.
protected voidupdateDepthOffset()
Updates how much each depth should be offset by.
protected voidupdateExpandedDescendants(TreePath path)
Updates the expanded state of all the descendants of the path by getting the expanded descendants from the tree and forwarding to the tree state.
protected voidupdateLayoutCacheExpandedNodes()
Make all the nodes that are expanded in JTree expanded in LayoutCache.
protected voidupdateRenderer()
Messaged from the tree we're in when the renderer has changed.
protected voidupdateSize()
Marks the cached size as being invalid, and messages the tree with treeDidChange.

Field Detail

cellEditor

protected transient TreeCellEditor cellEditor
Editor for the tree.

collapsedIcon

protected transient Icon collapsedIcon
Collapse Icon for the tree.

createdCellEditor

protected boolean createdCellEditor
Set to true if editor that is currently in the tree was created by this instance.

createdRenderer

protected boolean createdRenderer
Set to true if the renderer that is currently in the tree was created by this instance.

currentCellRenderer

protected transient TreeCellRenderer currentCellRenderer
Renderer that is being used to do the actual cell drawing.

depthOffset

protected int depthOffset
How much the depth should be offset to properly calculate x locations. This is based on whether or not the root is visible, and if the root handles are visible.

drawingCache

protected Hashtable<TreePath,Boolean> drawingCache
Used for minimizing the drawing of vertical lines.

editingComponent

protected Component editingComponent
When editing, this will be the Component that is doing the actual editing.

editingPath

protected TreePath editingPath
Path that is being edited.

editingRow

protected int editingRow
Row that is being edited. Should only be referenced if editingComponent is null.

editorHasDifferentSize

protected boolean editorHasDifferentSize
Set to true if the editor has a different size than the renderer.

expandedIcon

protected transient Icon expandedIcon
Expanded Icon for the tree.

largeModel

protected boolean largeModel
True if doing optimizations for a largeModel. Subclasses that don't support this may wish to override createLayoutCache to not return a FixedHeightLayoutCache instance.

lastSelectedRow

protected int lastSelectedRow
Index of the row that was last selected.

leftChildIndent

protected int leftChildIndent
Distance between left margin and where vertical dashes will be drawn.

nodeDimensions

protected AbstractLayoutCache.NodeDimensions nodeDimensions
Responsible for telling the TreeState the size needed for a node.

preferredMinSize

protected Dimension preferredMinSize
Minimum size needed to completely display all the nodes.

preferredSize

protected Dimension preferredSize
Size needed to completely display all the nodes.

rendererPane

protected CellRendererPane rendererPane
Used to paint the TreeCellRenderer.

rightChildIndent

protected int rightChildIndent
Distance between leftChildIndent and where cell contents will be drawn.

stopEditingInCompleteEditing

protected boolean stopEditingInCompleteEditing
Set to false when editing and shouldSelectCall() returns true meaning the node should be selected before editing, used in completeEditing. GNU Classpath editing is implemented differently, so this value is not actually read anywhere. However it is always set correctly to maintain interoperability with the derived classes that read this field.

totalChildIndent

protected int totalChildIndent
Total fistance that will be indented. The sum of leftChildIndent and rightChildIndent .

tree

protected JTree tree
Component that we're going to be drawing onto.

treeModel

protected TreeModel treeModel
Used to determine what to display.

treeSelectionModel

protected TreeSelectionModel treeSelectionModel
Model maintaining the selection.

treeState

protected AbstractLayoutCache treeState
Object responsible for handling sizing and expanded issues.

validCachedPreferredSize

protected boolean validCachedPreferredSize
Is the preferredSize valid?

Constructor Detail

BasicTreeUI

public BasicTreeUI()
Creates a new BasicTreeUI object.

Method Detail

cancelEditing

public void cancelEditing(JTree tree)
Cancels the current editing session.

Parameters: tree is the tree to cancel the editing session on.

checkForClickInExpandControl

protected void checkForClickInExpandControl(TreePath path, int mouseX, int mouseY)
If the mouseX and mouseY are in the expand or collapse region of the row, this will toggle the row.

Parameters: path the path we are concerned with mouseX is the cursor's x position mouseY is the cursor's y position

completeEditing

protected void completeEditing()
Messages to stop the editing session. If the UI the receiver is providing the look and feel for returns true from getInvokesStopCellEditing, stopCellEditing will be invoked on the current editor. Then completeEditing will be messaged with false, true, false to cancel any lingering editing.

completeEditing

protected void completeEditing(boolean messageStop, boolean messageCancel, boolean messageTree)
Stops the editing session. If messageStop is true, the editor is messaged with stopEditing, if messageCancel is true the editor is messaged with cancelEditing. If messageTree is true, the treeModel is messaged with valueForPathChanged.

Parameters: messageStop message to stop editing messageCancel message to cancel editing messageTree message to treeModel

completeUIInstall

protected void completeUIInstall()
Invoked from installUI after all the defaults/listeners have been installed.

completeUIUninstall

protected void completeUIUninstall()
Invoked from uninstallUI after all the defaults/listeners have been uninstalled.

configureLayoutCache

protected void configureLayoutCache()
Resets the treeState instance based on the tree we're providing the look and feel for. The node dimensions handler is required and must be created in advance.

createCellEditorListener

protected CellEditorListener createCellEditorListener()
Creates a listener to handle events from the current editor

Returns: the CellEditorListener that handles events from the current editor

createCellRendererPane

protected CellRendererPane createCellRendererPane()
Returns the renderer pane that renderer components are placed in.

Returns: the rendererpane that render components are placed in.

createComponentListener

protected ComponentListener createComponentListener()
Creates and returns a new ComponentHandler. This is used for the large model to mark the validCachedPreferredSize as invalid when the component moves.

Returns: a new ComponentHandler.

createDefaultCellEditor

protected TreeCellEditor createDefaultCellEditor()
Creates a default cell editor.

Returns: the default cell editor.

createDefaultCellRenderer

protected TreeCellRenderer createDefaultCellRenderer()
Returns the default cell renderer that is used to do the stamping of each node.

Returns: the default cell renderer that is used to do the stamping of each node.

createFocusListener

protected FocusListener createFocusListener()
Creates the listener that is responsible for updating the display when focus is lost/grained.

Returns: the FocusListener responsible for updating.

createKeyListener

protected KeyListener createKeyListener()
Creates the listener reponsible for getting key events from the tree.

Returns: the KeyListener responsible for getting key events.

createLayoutCache

protected AbstractLayoutCache createLayoutCache()
Creates the object responsible for managing what is expanded, as well as the size of nodes.

Returns: the object responsible for managing what is expanded.

createMouseListener

protected MouseListener createMouseListener()
Creates the listener responsible for updating the selection based on mouse events.

Returns: the MouseListener responsible for updating.

createNodeDimensions

protected AbstractLayoutCache.NodeDimensions createNodeDimensions()
Creates an instance of NodeDimensions that is able to determine the size of a given node in the tree. The node dimensions must be created before configuring the layout cache.

Returns: the NodeDimensions of a given node in the tree

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Creates a listener that is reponsible for the updates the UI based on how the tree changes.

Returns: the PropertyChangeListener that is reposnsible for the updates

createSelectionModelPropertyChangeListener

protected PropertyChangeListener createSelectionModelPropertyChangeListener()
Creates the listener responsible for getting property change events from the selection model.

UNKNOWN: the PropertyChangeListener reponsible for getting property change events from the selection model.

createTreeExpansionListener

protected TreeExpansionListener createTreeExpansionListener()
Creates and returns the object responsible for updating the treestate when a nodes expanded state changes.

Returns: the TreeExpansionListener responsible for updating the treestate

createTreeModelListener

protected TreeModelListener createTreeModelListener()
Returns a listener that can update the tree when the model changes.

Returns: a listener that can update the tree when the model changes.

createTreeSelectionListener

protected TreeSelectionListener createTreeSelectionListener()
Creates the listener that updates the display based on selection change methods.

Returns: the TreeSelectionListener responsible for updating.

createUI

public static ComponentUI createUI(JComponent c)
Returns an instance of the UI delegate for the specified component.

Parameters: c the JComponent for which we need a UI delegate for.

Returns: the ComponentUI for c.

drawCentered

protected void drawCentered(Component c, Graphics g, Icon icon, int x, int y)
Draws an icon at around a specific position

Parameters: c is the component the new line will belong to g is the graphic context icon is the icon which will be drawn x is the center position in x-direction y is the center position in y-direction

drawDashedHorizontalLine

protected void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2)
Draws a dashed horizontal line.

Parameters: g - the graphics configuration. y - the y location to start drawing at x1 - the x location to start drawing at x2 - the x location to finish drawing at

drawDashedVerticalLine

protected void drawDashedVerticalLine(Graphics g, int x, int y1, int y2)
Draws a dashed vertical line.

Parameters: g - the graphics configuration. x - the x location to start drawing at y1 - the y location to start drawing at y2 - the y location to finish drawing at

ensureRowsAreVisible

protected void ensureRowsAreVisible(int beginRow, int endRow)
Ensures that the rows identified by beginRow through endRow are visible.

Parameters: beginRow is the first row endRow is the last row

getCellEditor

protected TreeCellEditor getCellEditor()
Returns the TreeCellEditor for this tree.

Returns: the cellEditor for this tree.

getCellRenderer

protected TreeCellRenderer getCellRenderer()
Return currentCellRenderer, which will either be the trees renderer, or defaultCellRenderer, which ever was not null.

Returns: the current Cell Renderer

getClosestPathForLocation

public TreePath getClosestPathForLocation(JTree tree, int x, int y)
Returns the path to the node that is closest to x,y. If there is nothing currently visible this will return null, otherwise it'll always return a valid path. If you need to test if the returned object is exactly at x,y you should get the bounds for the returned path and test x,y against that.

Parameters: tree the tree to search for the closest path x is the x coordinate of the location to search y is the y coordinate of the location to search

Returns: the tree path closes to x,y.

getCollapsedIcon

public Icon getCollapsedIcon()
Returns the current collapsed icon.

Returns: the current collapsed icon.

getEditingPath

public TreePath getEditingPath(JTree tree)
Returns the path to the element that is being editted.

Parameters: tree is the tree to get the editing path from.

Returns: the path that is being edited.

getExpandedIcon

public Icon getExpandedIcon()
Returns the current expanded icon.

Returns: the current expanded icon.

getHashColor

protected Color getHashColor()
Returns the Hash color.

Returns: the Color of the Hash.

getHorizontalLegBuffer

protected int getHorizontalLegBuffer()
The horizontal element of legs between nodes starts at the right of the left-hand side of the child node by default. This method makes the leg end before that.

Returns: the horizontal leg buffer

getLastChildPath

protected TreePath getLastChildPath(TreePath parent)
Returns a path to the last child of parent

Parameters: parent is the topmost path to specified

Returns: a path to the last child of parent

getLeftChildIndent

public int getLeftChildIndent()
Returns the indent value for the left child.

Returns: the indent value for the left child.

getMaximumSize

public Dimension getMaximumSize(JComponent c)
Returns the maximum size for the component, which will be the preferred size if the instance is currently in JTree or (0,0).

Parameters: c the component whose preferred size is being queried

Returns: the max size or null

getMinimumSize

public Dimension getMinimumSize(JComponent c)
Returns the minimum size for this component. Which will be the min preferred size or (0,0).

Parameters: c the component whose min size is being queried.

UNKNOWN: the preferred size or null

getModel

protected TreeModel getModel()
Returns the tree's model

Returns: treeModel

getPathBounds

public Rectangle getPathBounds(JTree tree, TreePath path)
Returns the Rectangle enclosing the label portion that the last item in path will be drawn to. Will return null if any component in path is currently valid.

Parameters: tree is the current tree the path will be drawn to. path is the current path the tree to draw to.

Returns: the Rectangle enclosing the label portion that the last item in the path will be drawn to.

getPathForRow

public TreePath getPathForRow(JTree tree, int row)
Returns the path for passed in row. If row is not visible null is returned.

Parameters: tree is the current tree to return path for. row is the row number of the row to return.

Returns: the path for passed in row. If row is not visible null is returned.

getPreferredMinSize

public Dimension getPreferredMinSize()
Gets the preferred minimum size.

UNKNOWN: the preferred minimum size.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Returns the preferred size to properly display the tree, this is a cover method for getPreferredSize(c, false).

Parameters: c the component whose preferred size is being queried; this argument is often ignored but might be used if the UI object is stateless and shared by multiple components

Returns: the preferred size

getPreferredSize

public Dimension getPreferredSize(JComponent c, boolean checkConsistancy)
Returns the preferred size to represent the tree in c. If checkConsistancy is true, checkConsistancy is messaged first.

Parameters: c the component whose preferred size is being queried. checkConsistancy if true must check consistancy

Returns: the preferred size

getRightChildIndent

public int getRightChildIndent()
Returns the indent value for the right child.

Returns: the indent value for the right child.

getRowCount

public int getRowCount(JTree tree)
Returns the number of rows that are being displayed.

Parameters: tree is the current tree to return the number of rows for.

Returns: the number of rows being displayed.

getRowForPath

public int getRowForPath(JTree tree, TreePath path)
Returns the row that the last item identified in path is visible at. Will return -1 if any of the elments in the path are not currently visible.

Parameters: tree is the current tree to return the row for. path is the path used to find the row.

Returns: the row that the last item identified in path is visible at. Will return -1 if any of the elments in the path are not currently visible.

getRowHeight

protected int getRowHeight()
Returns the current row height.

Returns: current row height.

getRowX

protected int getRowX(int row, int depth)
Returns the amount to indent the given row

Returns: amount to indent the given row.

getSelectionModel

protected TreeSelectionModel getSelectionModel()
Returns the current selection model.

Returns: the current selection model.

getShowsRootHandles

protected boolean getShowsRootHandles()
Returns true if the node handles are to be displayed.

Returns: true if the node handles are to be displayed.

getVerticalLegBuffer

protected int getVerticalLegBuffer()
The vertical element of legs between nodes starts at the bottom of the parent node by default. This method makes the leg start below that.

Returns: the vertical leg buffer

handleExpandControlClick

protected void handleExpandControlClick(TreePath path, int mouseX, int mouseY)
Messaged when the user clicks the particular row, this invokes toggleExpandState.

Parameters: path the path we are concerned with mouseX is the cursor's x position mouseY is the cursor's y position

installComponents

protected void installComponents()
Installs the subcomponents of the tree, which is the renderer pane.

installDefaults

protected void installDefaults()
Install all defaults for the tree.

installKeyboardActions

protected void installKeyboardActions()
Install all keyboard actions for this

installListeners

protected void installListeners()
Install all listeners for this

installUI

public void installUI(JComponent c)
Install the UI for the component

Parameters: c the component to install UI for

isEditable

protected boolean isEditable()
Returns true if the receiver allows editing.

Returns: true if the receiver allows editing.

isEditing

public boolean isEditing(JTree tree)
Returns true if the tree is being edited. The item that is being edited can be returned by getEditingPath().

Parameters: tree is the tree to check for editing.

Returns: true if the tree is being edited.

isLargeModel

protected boolean isLargeModel()
Returns true if largeModel is set

Returns: true if largeModel is set, otherwise false.

isLeaf

protected boolean isLeaf(int row)
Returns true if the node at row is a leaf.

Parameters: row is the row we are concerned with.

Returns: true if the node at row is a leaf.

isLocationInExpandControl

protected boolean isLocationInExpandControl(TreePath path, int mouseX, int mouseY)
Returns true if the mouseX and mouseY fall in the area of row that is used to expand/collpse the node and the node at row does not represent a leaf.

Parameters: path the path we are concerned with mouseX is the cursor's x position mouseY is the cursor's y position

Returns: true if the mouseX and mouseY fall in the area of row that is used to expand/collpse the node and the node at row does not represent a leaf.

isMultiSelectEvent

protected boolean isMultiSelectEvent(MouseEvent event)
Returning true signifies a mouse event on the node should select from the anchor point. The BasisTreeUI treats the event as "multiple selection event" if the SHIFT button was pressed while clicking. The event is not counted as multiple selection event if the associated tree does not support the multiple selection.

Parameters: event is the MouseEvent performed on the node.

Returns: true signifies a mouse event on the node should select from the anchor point.

isRootVisible

protected boolean isRootVisible()
Returns true if the root is visible.

Returns: true if the root is visible.

isToggleEvent

protected boolean isToggleEvent(MouseEvent event)
Returning true indicates the row under the mouse should be toggled based on the event. This is invoked after checkForClickInExpandControl, implying the location is not in the expand (toggle) control.

Parameters: event is the MouseEvent performed on the row.

Returns: true indicates the row under the mouse should be toggled based on the event.

isToggleSelectionEvent

protected boolean isToggleSelectionEvent(MouseEvent event)
Returning true signifies a mouse event on the node should toggle the selection of only the row under the mouse. The BasisTreeUI treats the event as "toggle selection event" if the CTRL button was pressed while clicking. The event is not counted as toggle event if the associated tree does not support the multiple selection.

Parameters: event is the MouseEvent performed on the row.

Returns: true signifies a mouse event on the node should toggle the selection of only the row under the mouse.

paint

public void paint(Graphics g, JComponent c)
Paints the specified component appropriate for the look and feel. This method is invoked from the ComponentUI.update method when the specified component is being painted. Subclasses should override this method and use the specified Graphics object to render the content of the component.

Parameters: g the Graphics context in which to paint c the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components

paintExpandControl

protected void paintExpandControl(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
Paints the expand (toggle) part of a row. The receiver should NOT modify clipBounds, or insets.

Parameters: g - the graphics configuration clipBounds - insets - bounds - bounds of expand control path - path to draw control for row - row to draw control for isExpanded - is the row expanded hasBeenExpanded - has the row already been expanded isLeaf - is the path a leaf

paintHorizontalLine

protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left, int right)
Draws a horizontal line using the given graphic context

Parameters: g is the graphic context c is the component the new line will belong to y is the vertical position left specifies the left point of the line right specifies the right point of the line

paintHorizontalPartOfLeg

protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
Paints the horizontal part of the leg. The receiver should NOT modify clipBounds, or insets. NOTE: parentRow can be -1 if the root is not visible.

Parameters: g - the graphics configuration clipBounds - insets - bounds - bounds of the cell path - path to draw leg for row - row to start drawing at isExpanded - is the row expanded hasBeenExpanded - has the row already been expanded isLeaf - is the path a leaf

paintRow

protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
Paints the renderer part of a row. The receiver should NOT modify clipBounds, or insets.

Parameters: g - the graphics configuration clipBounds - insets - bounds - bounds of expand control path - path to draw control for row - row to draw control for isExpanded - is the row expanded hasBeenExpanded - has the row already been expanded isLeaf - is the path a leaf

paintVerticalLine

protected void paintVerticalLine(Graphics g, JComponent c, int x, int top, int bottom)
Draws a vertical line using the given graphic context

Parameters: g is the graphic context c is the component the new line will belong to x is the horizonal position top specifies the top of the line bottom specifies the bottom of the line

paintVerticalPartOfLeg

protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path)
Paints the vertical part of the leg. The receiver should NOT modify clipBounds, insets.

Parameters: g - the graphics configuration. clipBounds - insets - path - the path to draw the vertical part for.

pathWasCollapsed

protected void pathWasCollapsed(TreePath path)
Messaged from the VisibleTreeNode after it has collapsed

pathWasExpanded

protected void pathWasExpanded(TreePath path)
Messaged from the VisibleTreeNode after it has been expanded.

Parameters: path is the path that has been expanded.

prepareForUIInstall

protected void prepareForUIInstall()
Invoked after the tree instance variable has been set, but before any default/listeners have been installed.

prepareForUIUninstall

protected void prepareForUIUninstall()
Prepares for the UI to uninstall.

selectPathForEvent

protected void selectPathForEvent(TreePath path, MouseEvent event)
Messaged to update the selection based on a MouseEvent over a particular row. If the even is a toggle selection event, the row is either selected, or deselected. If the event identifies a multi selection event, the selection is updated from the anchor point. Otherwise, the row is selected, and the previous selection is cleared.

Parameters: path is the path selected for an event event is the MouseEvent performed on the path.

See Also: isToggleSelectionEvent isMultiSelectEvent

setCellEditor

protected void setCellEditor(TreeCellEditor editor)
Sets the cell editor.

Parameters: editor to set the cellEditor to.

setCellRenderer

protected void setCellRenderer(TreeCellRenderer tcr)
Sets the TreeCellRenderer to tcr. This invokes updateRenderer.

Parameters: tcr is the new TreeCellRenderer.

setCollapsedIcon

public void setCollapsedIcon(Icon newG)
Sets the collapsed icon.

Parameters: newG is the new collapsed icon.

setEditable

protected void setEditable(boolean newValue)
Configures the receiver to allow, or not allow, editing.

Parameters: newValue sets the receiver to allow editing if true.

setExpandedIcon

public void setExpandedIcon(Icon newG)
Sets the expanded icon.

Parameters: newG is the new expanded icon.

setHashColor

protected void setHashColor(Color color)
Sets the Hash color.

Parameters: color the Color to set the Hash to.

setLargeModel

protected void setLargeModel(boolean largeModel)
Updates the componentListener, if necessary.

Parameters: largeModel sets this.largeModel to it.

setLeftChildIndent

public void setLeftChildIndent(int newAmount)
Sets the left child's indent value.

Parameters: newAmount is the new indent value for the left child.

setModel

protected void setModel(TreeModel model)
Sets the tree's model.

Parameters: model to set the treeModel to.

setPreferredMinSize

public void setPreferredMinSize(Dimension newSize)
Sets the preferred minimum size.

Parameters: newSize is the new preferred minimum size.

setRightChildIndent

public void setRightChildIndent(int newAmount)
Sets the right child's indent value.

Parameters: newAmount is the new indent value for the right child.

setRootVisible

protected void setRootVisible(boolean newValue)
Sets the root to being visible.

Parameters: newValue sets the visibility of the root

setRowHeight

protected void setRowHeight(int rowHeight)
Sets the row height.

Parameters: rowHeight is the height to set this.rowHeight to.

setSelectionModel

protected void setSelectionModel(TreeSelectionModel newLSM)
Resets the selection model. The appropriate listeners are installed on the model.

Parameters: newLSM resets the selection model.

setShowsRootHandles

protected void setShowsRootHandles(boolean newValue)
Determines whether the node handles are to be displayed.

Parameters: newValue sets whether or not node handles should be displayed.

shouldPaintExpandControl

protected boolean shouldPaintExpandControl(TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
Returns true if the expand (toggle) control should be drawn for the specified row.

Parameters: path - current path to check for. row - current row to check for. isExpanded - true if the path is expanded hasBeenExpanded - true if the path has been expanded already isLeaf - true if the row is a lead

startEditing

protected boolean startEditing(TreePath path, MouseEvent event)
Will start editing for node if there is a cellEditor and shouldSelectCall returns true. This assumes that path is valid and visible.

Parameters: path is the path to start editing event is the MouseEvent performed on the path

Returns: true if successful

startEditingAtPath

public void startEditingAtPath(JTree tree, TreePath path)
Selects the last item in path and tries to edit it. Editing will fail if the CellEditor won't allow it for the selected item.

Parameters: tree is the tree to edit on. path is the path in tree to edit on.

stopEditing

public boolean stopEditing(JTree tree)
Stops the current editing session. This has no effect if the tree is not being edited. Returns true if the editor allows the editing session to stop.

Parameters: tree is the tree to stop the editing on

Returns: true if the editor allows the editing session to stop.

toggleExpandState

protected void toggleExpandState(TreePath path)
Expands path if it is not expanded, or collapses row if it is expanded. If expanding a path and JTree scroll on expand, ensureRowsAreVisible is invoked to scroll as many of the children to visible as possible (tries to scroll to last visible descendant of path).

Parameters: path the path we are concerned with

uninstallComponents

protected void uninstallComponents()
Uninstall the rendererPane.

uninstallDefaults

protected void uninstallDefaults()
Uninstall the defaults for the tree

uninstallKeyboardActions

protected void uninstallKeyboardActions()
Uninstall all keyboard actions.

uninstallListeners

protected void uninstallListeners()
Uninstall all registered listeners

uninstallUI

public void uninstallUI(JComponent c)
Uninstall the UI for the component

Parameters: c the component to uninstall UI for

updateCachedPreferredSize

protected void updateCachedPreferredSize()
Updates the preferredSize instance variable, which is returned from getPreferredSize().

updateCellEditor

protected void updateCellEditor()
Updates the cellEditor based on editability of the JTree that we're contained in. If the tree is editable but doesn't have a cellEditor, a basic one will be used.

updateDepthOffset

protected void updateDepthOffset()
Updates how much each depth should be offset by.

updateExpandedDescendants

protected void updateExpandedDescendants(TreePath path)
Updates the expanded state of all the descendants of the path by getting the expanded descendants from the tree and forwarding to the tree state.

Parameters: path the path used to update the expanded states

updateLayoutCacheExpandedNodes

protected void updateLayoutCacheExpandedNodes()
Make all the nodes that are expanded in JTree expanded in LayoutCache. This invokes updateExpandedDescendants with the root path.

updateRenderer

protected void updateRenderer()
Messaged from the tree we're in when the renderer has changed.

updateSize

protected void updateSize()
Marks the cached size as being invalid, and messages the tree with treeDidChange.