public class

BasicTreeUI

extends TreeUI
java.lang.Object
   ↳ javax.swing.plaf.ComponentUI
     ↳ javax.swing.plaf.TreeUI
       ↳ javax.swing.plaf.basic.BasicTreeUI
Known Direct Subclasses

Class Overview

The basic L&F for a hierarchical data structure.

Summary

Nested Classes
class BasicTreeUI.CellEditorHandler Listener responsible for getting cell editing events and updating the tree accordingly. 
class BasicTreeUI.ComponentHandler Updates the preferred size when scrolling (if necessary). 
class BasicTreeUI.FocusHandler Repaints the lead selection row when focus is lost/gained. 
class BasicTreeUI.KeyHandler This is used to get mutliple key down events to appropriately generate events. 
class BasicTreeUI.MouseHandler TreeMouseListener is responsible for updating the selection based on mouse events. 
class BasicTreeUI.MouseInputHandler MouseInputHandler handles passing all mouse events, including mouse motion events, until the mouse is released to the destination it is constructed with. 
class BasicTreeUI.NodeDimensionsHandler Class responsible for getting size of node, method is forwarded to BasicTreeUI method. 
class BasicTreeUI.PropertyChangeHandler PropertyChangeListener for the tree. 
class BasicTreeUI.SelectionModelPropertyChangeHandler Listener on the TreeSelectionModel, resets the row selection if any of the properties of the model change. 
class BasicTreeUI.TreeCancelEditingAction ActionListener that invokes cancelEditing when action performed. 
class BasicTreeUI.TreeExpansionHandler Updates the TreeState in response to nodes expanding/collapsing. 
class BasicTreeUI.TreeHomeAction TreeHomeAction is used to handle end/home actions. 
class BasicTreeUI.TreeIncrementAction TreeIncrementAction is used to handle up/down actions. 
class BasicTreeUI.TreeModelHandler Forwards all TreeModel events to the TreeState. 
class BasicTreeUI.TreePageAction TreePageAction handles page up and page down events. 
class BasicTreeUI.TreeSelectionHandler Listens for changes in the selection model and updates the display accordingly. 
class BasicTreeUI.TreeToggleAction For the first selected row expandedness will be toggled. 
class BasicTreeUI.TreeTraverseAction TreeTraverseAction is the action used for left/right keys. 
Fields
protected TreeCellEditor cellEditor Editor for the tree.
protected Icon collapsedIcon
protected boolean createdCellEditor Set to true if editor that is currently in the tree was created by this instance.
protected boolean createdRenderer Set to true if the renderer that is currently in the tree was created by this instance.
protected TreeCellRenderer currentCellRenderer Renderer that is being used to do the actual cell drawing.
protected int depthOffset How much the depth should be offset to properly calculate x locations.
protected Hashtable<TreePathBoolean> drawingCache Used for minimizing the drawing of vertical lines.
protected Component editingComponent When editing, this will be the Component that is doing the actual editing.
protected TreePath editingPath Path that is being edited.
protected int editingRow Row that is being edited.
protected boolean editorHasDifferentSize Set to true if the editor has a different size than the renderer.
protected Icon expandedIcon
protected boolean largeModel True if doing optimizations for a largeModel.
protected int lastSelectedRow Index of the row that was last selected.
protected int leftChildIndent Distance between left margin and where vertical dashes will be drawn.
protected AbstractLayoutCache.NodeDimensions nodeDimensions Reponsible for telling the TreeState the size needed for a node.
protected Dimension preferredMinSize Minimum preferred size.
protected Dimension preferredSize Size needed to completely display all the nodes.
protected CellRendererPane rendererPane Used to paint the TreeCellRenderer.
protected int rightChildIndent Distance to add to leftChildIndent to determine where cell contents will be drawn.
protected boolean stopEditingInCompleteEditing Set to false when editing and shouldSelectCell() returns true meaning the node should be selected before editing, used in completeEditing.
protected int totalChildIndent Total distance that will be indented.
protected JTree tree Component that we're going to be drawing into.
protected TreeModel treeModel Used to determine what to display.
protected TreeSelectionModel treeSelectionModel Model maintaing the selection.
protected AbstractLayoutCache treeState Object responsible for handling sizing and expanded issues.
protected boolean validCachedPreferredSize Is the preferredSize valid?
Public Constructors
BasicTreeUI()
Public Methods
void cancelEditing(JTree tree)
Cancels the current editing session.
static ComponentUI createUI(JComponent x)
int getBaseline(JComponent c, int width, int height)
Returns the baseline.
Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
Returns an enum indicating how the baseline of the component changes as the size changes.
TreePath getClosestPathForLocation(JTree tree, int x, int y)
Returns the path to the node that is closest to x,y.
Icon getCollapsedIcon()
TreePath getEditingPath(JTree tree)
Returns the path to the element that is being edited.
Icon getExpandedIcon()
int getLeftChildIndent()
Dimension getMaximumSize(JComponent c)
Returns the maximum size for this component, which will be the preferred size if the instance is currently in a JTree, or 0, 0.
Dimension getMinimumSize(JComponent c)
Returns the minimum size for this component.
Rectangle getPathBounds(JTree tree, TreePath path)
Returns the Rectangle enclosing the label portion that the last item in path will be drawn into.
TreePath getPathForRow(JTree tree, int row)
Returns the path for passed in row.
Dimension getPreferredMinSize()
Returns the minimum preferred size.
Dimension getPreferredSize(JComponent c)
Returns the preferred size to properly display the tree, this is a cover method for getPreferredSize(c, false).
Dimension getPreferredSize(JComponent c, boolean checkConsistancy)
Returns the preferred size to represent the tree in c.
int getRightChildIndent()
int getRowCount(JTree tree)
Returns the number of rows that are being displayed.
int getRowForPath(JTree tree, TreePath path)
Returns the row that the last item identified in path is visible at.
void installUI(JComponent c)
Configures the specified component appropriate for the look and feel.
boolean isEditing(JTree tree)
Returns true if the tree is being edited.
void paint(Graphics g, JComponent c)
Paints the specified component appropriate for the look and feel.
void setCollapsedIcon(Icon newG)
void setExpandedIcon(Icon newG)
void setLeftChildIndent(int newAmount)
void setPreferredMinSize(Dimension newSize)
Sets the preferred minimum size.
void setRightChildIndent(int newAmount)
void startEditingAtPath(JTree tree, TreePath path)
Selects the last item in path and tries to edit it.
boolean stopEditing(JTree tree)
Stops the current editing session.
void uninstallUI(JComponent c)
Reverses configuration which was done on the specified component during installUI.
Protected Methods
void checkForClickInExpandControl(TreePath path, int mouseX, int mouseY)
If the mouseX and mouseY are in the expand/collapse region of the row, this will toggle the row.
void completeEditing()
Messages to stop the editing session.
void completeEditing(boolean messageStop, boolean messageCancel, boolean messageTree)
Stops the editing session.
void completeUIInstall()
Invoked from installUI after all the defaults/listeners have been installed.
void completeUIUninstall()
void configureLayoutCache()
Resets the TreeState instance based on the tree we're providing the look and feel for.
CellEditorListener createCellEditorListener()
Creates a listener to handle events from the current editor.
CellRendererPane createCellRendererPane()
Returns the renderer pane that renderer components are placed in.
ComponentListener createComponentListener()
Creates and returns a new ComponentHandler.
TreeCellEditor createDefaultCellEditor()
Creates a default cell editor.
TreeCellRenderer createDefaultCellRenderer()
Returns the default cell renderer that is used to do the stamping of each node.
FocusListener createFocusListener()
Creates a listener that is responsible for updating the display when focus is lost/gained.
KeyListener createKeyListener()
Creates the listener reponsible for getting key events from the tree.
AbstractLayoutCache createLayoutCache()
Creates the object responsible for managing what is expanded, as well as the size of nodes.
MouseListener createMouseListener()
Creates the listener responsible for updating the selection based on mouse events.
AbstractLayoutCache.NodeDimensions createNodeDimensions()
Creates an instance of NodeDimensions that is able to determine the size of a given node in the tree.
PropertyChangeListener createPropertyChangeListener()
Creates a listener that is responsible that updates the UI based on how the tree changes.
PropertyChangeListener createSelectionModelPropertyChangeListener()
Creates the listener responsible for getting property change events from the selection model.
TreeExpansionListener createTreeExpansionListener()
Creates and returns the object responsible for updating the treestate when nodes expanded state changes.
TreeModelListener createTreeModelListener()
Returns a listener that can update the tree when the model changes.
TreeSelectionListener createTreeSelectionListener()
Creates the listener that updates the display based on selection change methods.
void drawCentered(Component c, Graphics graphics, Icon icon, int x, int y)
void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2)
void drawDashedVerticalLine(Graphics g, int x, int y1, int y2)
void ensureRowsAreVisible(int beginRow, int endRow)
Ensures that the rows identified by beginRow through endRow are visible.
TreeCellEditor getCellEditor()
TreeCellRenderer getCellRenderer()
Return currentCellRenderer, which will either be the trees renderer, or defaultCellRenderer, which ever wasn't null.
Color getHashColor()
int getHorizontalLegBuffer()
The horizontal element of legs between nodes starts at the right of the left-hand side of the child node by default.
TreePath getLastChildPath(TreePath parent)
Returns a path to the last child of parent.
TreeModel getModel()
int getRowHeight()
int getRowX(int row, int depth)
Returns the location, along the x-axis, to render a particular row at.
TreeSelectionModel getSelectionModel()
boolean getShowsRootHandles()
int getVerticalLegBuffer()
The vertical element of legs between nodes starts at the bottom of the parent node by default.
void handleExpandControlClick(TreePath path, int mouseX, int mouseY)
Messaged when the user clicks the particular row, this invokes toggleExpandState.
void installComponents()
Intalls the subcomponents of the tree, which is the renderer pane.
void installDefaults()
void installKeyboardActions()
void installListeners()
boolean isEditable()
boolean isLargeModel()
boolean isLeaf(int row)
boolean isLocationInExpandControl(TreePath path, int mouseX, int mouseY)
Returns true if mouseX and mouseY fall in the area of row that is used to expand/collapse the node and the node at row does not represent a leaf.
boolean isMultiSelectEvent(MouseEvent event)
Returning true signifies a mouse event on the node should select from the anchor point.
boolean isRootVisible()
boolean isToggleEvent(MouseEvent event)
Returning true indicates the row under the mouse should be toggled based on the event.
boolean isToggleSelectionEvent(MouseEvent event)
Returning true signifies a mouse event on the node should toggle the selection of only the row under mouse.
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.
void paintHorizontalLine(Graphics g, JComponent c, int y, int left, int right)
Paints a horizontal line.
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.
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.
void paintVerticalLine(Graphics g, JComponent c, int x, int top, int bottom)
Paints a vertical line.
void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path)
Paints the vertical part of the leg.
void pathWasCollapsed(TreePath path)
Messaged from the VisibleTreeNode after it has collapsed.
void pathWasExpanded(TreePath path)
Messaged from the VisibleTreeNode after it has been expanded.
void prepareForUIInstall()
Invoked after the tree instance variable has been set, but before any defaults/listeners have been installed.
void prepareForUIUninstall()
void selectPathForEvent(TreePath path, MouseEvent event)
Messaged to update the selection based on a MouseEvent over a particular row.
void setCellEditor(TreeCellEditor editor)
Sets the cell editor.
void setCellRenderer(TreeCellRenderer tcr)
Sets the TreeCellRenderer to tcr.
void setEditable(boolean newValue)
Configures the receiver to allow, or not allow, editing.
void setHashColor(Color color)
void setLargeModel(boolean largeModel)
Updates the componentListener, if necessary.
void setModel(TreeModel model)
Sets the TreeModel.
void setRootVisible(boolean newValue)
Sets the root to being visible.
void setRowHeight(int rowHeight)
Sets the row height, this is forwarded to the treeState.
void setSelectionModel(TreeSelectionModel newLSM)
Resets the selection model.
void setShowsRootHandles(boolean newValue)
Determines whether the node handles are to be displayed.
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.
boolean startEditing(TreePath path, MouseEvent event)
Will start editing for node if there is a cellEditor and shouldSelectCell returns true.
void toggleExpandState(TreePath path)
Expands path if it is not expanded, or collapses row if it is expanded.
void uninstallComponents()
Uninstalls the renderer pane.
void uninstallDefaults()
void uninstallKeyboardActions()
void uninstallListeners()
void updateCachedPreferredSize()
Updates the preferredSize instance variable, which is returned from getPreferredSize().
void updateCellEditor()
Updates the cellEditor based on the editability of the JTree that we're contained in.
void updateDepthOffset()
Updates how much each depth should be offset by.
void updateExpandedDescendants(TreePath path)
Updates the expanded state of all the descendants of path by getting the expanded descendants from the tree and forwarding to the tree state.
void updateLayoutCacheExpandedNodes()
Makes all the nodes that are expanded in JTree expanded in LayoutCache.
void updateRenderer()
Messaged from the tree we're in when the renderer has changed.
void updateSize()
Marks the cached size as being invalid, and messages the tree with treeDidChange.
[Expand]
Inherited Methods
From class javax.swing.plaf.TreeUI
From class javax.swing.plaf.ComponentUI
From class java.lang.Object

Fields

protected TreeCellEditor cellEditor

Editor for the tree.

protected Icon collapsedIcon

protected boolean createdCellEditor

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

protected boolean createdRenderer

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

protected TreeCellRenderer currentCellRenderer

Renderer that is being used to do the actual cell drawing.

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.

protected Hashtable<TreePathBoolean> drawingCache

Used for minimizing the drawing of vertical lines.

protected Component editingComponent

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

protected TreePath editingPath

Path that is being edited.

protected int editingRow

Row that is being edited. Should only be referenced if editingComponent is not null.

protected boolean editorHasDifferentSize

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

protected Icon expandedIcon

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.

protected int lastSelectedRow

Index of the row that was last selected.

protected int leftChildIndent

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

protected AbstractLayoutCache.NodeDimensions nodeDimensions

Reponsible for telling the TreeState the size needed for a node.

protected Dimension preferredMinSize

Minimum preferred size.

protected Dimension preferredSize

Size needed to completely display all the nodes.

protected CellRendererPane rendererPane

Used to paint the TreeCellRenderer.

protected int rightChildIndent

Distance to add to leftChildIndent to determine where cell contents will be drawn.

protected boolean stopEditingInCompleteEditing

Set to false when editing and shouldSelectCell() returns true meaning the node should be selected before editing, used in completeEditing.

protected int totalChildIndent

Total distance that will be indented. The sum of leftChildIndent and rightChildIndent.

protected JTree tree

Component that we're going to be drawing into.

protected TreeModel treeModel

Used to determine what to display.

protected TreeSelectionModel treeSelectionModel

Model maintaing the selection.

protected AbstractLayoutCache treeState

Object responsible for handling sizing and expanded issues.

protected boolean validCachedPreferredSize

Is the preferredSize valid?

Public Constructors

public BasicTreeUI ()

Public Methods

public void cancelEditing (JTree tree)

Cancels the current editing session.

public static ComponentUI createUI (JComponent x)

public int getBaseline (JComponent c, int width, int height)

Returns the baseline.

Parameters
c JComponent baseline is being requested for
width the width to get the baseline for
height the height to get the baseline for
Returns
  • baseline or a value < 0 indicating there is no reasonable baseline

public Component.BaselineResizeBehavior getBaselineResizeBehavior (JComponent c)

Returns an enum indicating how the baseline of the component changes as the size changes.

Parameters
c JComponent to return baseline resize behavior for
Returns
  • an enum indicating how the baseline changes as the component size changes

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.

public Icon getCollapsedIcon ()

public TreePath getEditingPath (JTree tree)

Returns the path to the element that is being edited.

public Icon getExpandedIcon ()

public int getLeftChildIndent ()

public Dimension getMaximumSize (JComponent c)

Returns the maximum size for this component, which will be the preferred size if the instance is currently in a JTree, or 0, 0.

Parameters
c the component whose maximum 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
  • a Dimension object or null

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 minimum 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
  • a Dimension object or null

public Rectangle getPathBounds (JTree tree, TreePath path)

Returns the Rectangle enclosing the label portion that the last item in path will be drawn into. Will return null if any component in path is currently valid.

public TreePath getPathForRow (JTree tree, int row)

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

public Dimension getPreferredMinSize ()

Returns the minimum preferred size.

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

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.

public int getRightChildIndent ()

public int getRowCount (JTree tree)

Returns the number of rows that are being displayed.

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 elements in path are not currently visible.

public void installUI (JComponent c)

Configures the specified component appropriate for the look and feel. This method is invoked when the ComponentUI instance is being installed as the UI delegate on the specified component. This method should completely configure the component for the look and feel, including the following:

  1. Install any default property values for color, fonts, borders, icons, opacity, etc. on the component. Whenever possible, property values initialized by the client program should not be overridden.
  2. Install a LayoutManager on the component if necessary.
  3. Create/add any required sub-components to the component.
  4. Create/install event listeners on the component.
  5. Create/install a PropertyChangeListener on the component in order to detect and respond to component property changes appropriately.
  6. Install keyboard UI (mnemonics, traversal, etc.) on the component.
  7. Initialize any appropriate instance data.

Parameters
c the component where this UI delegate is being installed

public boolean isEditing (JTree tree)

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

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

public void setCollapsedIcon (Icon newG)

public void setExpandedIcon (Icon newG)

public void setLeftChildIndent (int newAmount)

public void setPreferredMinSize (Dimension newSize)

Sets the preferred minimum size.

public void setRightChildIndent (int newAmount)

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.

public boolean stopEditing (JTree tree)

Stops the current editing session. This has no effect if the tree isn't being edited. Returns true if the editor allows the editing session to stop.

public void uninstallUI (JComponent c)

Reverses configuration which was done on the specified component during installUI. This method is invoked when this UIComponent instance is being removed as the UI delegate for the specified component. This method should undo the configuration performed in installUI, being careful to leave the JComponent instance in a clean state (no extraneous listeners, look-and-feel-specific property objects, etc.). This should include the following:

  1. Remove any UI-set borders from the component.
  2. Remove any UI-set layout managers on the component.
  3. Remove any UI-added sub-components from the component.
  4. Remove any UI-added event/property listeners from the component.
  5. Remove any UI-installed keyboard UI from the component.
  6. Nullify any allocated instance data objects to allow for GC.

Parameters
c the component from which this UI delegate is being removed; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components

Protected Methods

protected void checkForClickInExpandControl (TreePath path, int mouseX, int mouseY)

If the mouseX and mouseY are in the expand/collapse region of the row, this will toggle the row.

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 invoked on the current editor. Then completeEditing will be messaged with false, true, false to cancel any lingering editing.

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.

protected void completeUIInstall ()

Invoked from installUI after all the defaults/listeners have been installed.

protected void completeUIUninstall ()

protected void configureLayoutCache ()

Resets the TreeState instance based on the tree we're providing the look and feel for.

protected CellEditorListener createCellEditorListener ()

Creates a listener to handle events from the current editor.

protected CellRendererPane createCellRendererPane ()

Returns the renderer pane that renderer components are placed in.

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.

protected TreeCellEditor createDefaultCellEditor ()

Creates a default cell editor.

protected TreeCellRenderer createDefaultCellRenderer ()

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

protected FocusListener createFocusListener ()

Creates a listener that is responsible for updating the display when focus is lost/gained.

protected KeyListener createKeyListener ()

Creates the listener reponsible for getting key events from the tree.

protected AbstractLayoutCache createLayoutCache ()

Creates the object responsible for managing what is expanded, as well as the size of nodes.

protected MouseListener createMouseListener ()

Creates the listener responsible for updating the selection based on mouse events.

protected AbstractLayoutCache.NodeDimensions createNodeDimensions ()

Creates an instance of NodeDimensions that is able to determine the size of a given node in the tree.

protected PropertyChangeListener createPropertyChangeListener ()

Creates a listener that is responsible that updates the UI based on how the tree changes.

protected PropertyChangeListener createSelectionModelPropertyChangeListener ()

Creates the listener responsible for getting property change events from the selection model.

protected TreeExpansionListener createTreeExpansionListener ()

Creates and returns the object responsible for updating the treestate when nodes expanded state changes.

protected TreeModelListener createTreeModelListener ()

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

protected TreeSelectionListener createTreeSelectionListener ()

Creates the listener that updates the display based on selection change methods.

protected void drawCentered (Component c, Graphics graphics, Icon icon, int x, int y)

protected void drawDashedHorizontalLine (Graphics g, int y, int x1, int x2)

protected void drawDashedVerticalLine (Graphics g, int x, int y1, int y2)

protected void ensureRowsAreVisible (int beginRow, int endRow)

Ensures that the rows identified by beginRow through endRow are visible.

protected TreeCellEditor getCellEditor ()

protected TreeCellRenderer getCellRenderer ()

Return currentCellRenderer, which will either be the trees renderer, or defaultCellRenderer, which ever wasn't null.

protected Color getHashColor ()

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.

protected TreePath getLastChildPath (TreePath parent)

Returns a path to the last child of parent.

protected TreeModel getModel ()

protected int getRowHeight ()

protected int getRowX (int row, int depth)

Returns the location, along the x-axis, to render a particular row at. The return value does not include any Insets specified on the JTree. This does not check for the validity of the row or depth, it is assumed to be correct and will not throw an Exception if the row or depth doesn't match that of the tree.

Parameters
row Row to return x location for
depth Depth of the row
Returns
  • amount to indent the given row.

protected TreeSelectionModel getSelectionModel ()

protected boolean getShowsRootHandles ()

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.

protected void handleExpandControlClick (TreePath path, int mouseX, int mouseY)

Messaged when the user clicks the particular row, this invokes toggleExpandState.

protected void installComponents ()

Intalls the subcomponents of the tree, which is the renderer pane.

protected void installDefaults ()

protected void installKeyboardActions ()

protected void installListeners ()

protected boolean isEditable ()

protected boolean isLargeModel ()

protected boolean isLeaf (int row)

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

protected boolean isLocationInExpandControl (TreePath path, int mouseX, int mouseY)

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

protected boolean isMultiSelectEvent (MouseEvent event)

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

protected boolean isRootVisible ()

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

protected boolean isToggleSelectionEvent (MouseEvent event)

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

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.

protected void paintHorizontalLine (Graphics g, JComponent c, int y, int left, int right)

Paints a horizontal line.

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.

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.

protected void paintVerticalLine (Graphics g, JComponent c, int x, int top, int bottom)

Paints a vertical line.

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.

protected void pathWasCollapsed (TreePath path)

Messaged from the VisibleTreeNode after it has collapsed.

protected void pathWasExpanded (TreePath path)

Messaged from the VisibleTreeNode after it has been expanded.

protected void prepareForUIInstall ()

Invoked after the tree instance variable has been set, but before any defaults/listeners have been installed.

protected void prepareForUIUninstall ()

protected void selectPathForEvent (TreePath path, MouseEvent event)

Messaged to update the selection based on a MouseEvent over a particular row. If the event 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 if the event specified a toggle event the row is expanded/collapsed.

protected void setCellEditor (TreeCellEditor editor)

Sets the cell editor.

protected void setCellRenderer (TreeCellRenderer tcr)

Sets the TreeCellRenderer to tcr. This invokes updateRenderer.

protected void setEditable (boolean newValue)

Configures the receiver to allow, or not allow, editing.

protected void setHashColor (Color color)

protected void setLargeModel (boolean largeModel)

Updates the componentListener, if necessary.

protected void setModel (TreeModel model)

Sets the TreeModel.

protected void setRootVisible (boolean newValue)

Sets the root to being visible.

protected void setRowHeight (int rowHeight)

Sets the row height, this is forwarded to the treeState.

protected void setSelectionModel (TreeSelectionModel newLSM)

Resets the selection model. The appropriate listener are installed on the model.

protected void setShowsRootHandles (boolean newValue)

Determines whether the node handles are to be displayed.

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.

protected boolean startEditing (TreePath path, MouseEvent event)

Will start editing for node if there is a cellEditor and shouldSelectCell returns true.

This assumes that path is valid and visible.

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 scrolls 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).

protected void uninstallComponents ()

Uninstalls the renderer pane.

protected void uninstallDefaults ()

protected void uninstallKeyboardActions ()

protected void uninstallListeners ()

protected void updateCachedPreferredSize ()

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

For left to right orientations, the size is determined from the current AbstractLayoutCache. For RTL orientations, the preferred size becomes the width minus the minimum x position.

protected void updateCellEditor ()

Updates the cellEditor based on the 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.

protected void updateDepthOffset ()

Updates how much each depth should be offset by.

protected void updateExpandedDescendants (TreePath path)

Updates the expanded state of all the descendants of path by getting the expanded descendants from the tree and forwarding to the tree state.

protected void updateLayoutCacheExpandedNodes ()

Makes all the nodes that are expanded in JTree expanded in LayoutCache. This invokes updateExpandedDescendants with the root path.

protected void updateRenderer ()

Messaged from the tree we're in when the renderer has changed.

protected void updateSize ()

Marks the cached size as being invalid, and messages the tree with treeDidChange.