java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.TreeUI
javax.swing.plaf.basic.BasicTreeUI
- Direct Known Subclasses:
- MetalTreeUI,- SynthTreeUI
public class BasicTreeUI extends TreeUI
The basic L&F for a hierarchical data structure.
- 
Nested Class SummaryNested Classes Modifier and Type Class Description classBasicTreeUI.CellEditorHandlerListener responsible for getting cell editing events and updating the tree accordingly.classBasicTreeUI.ComponentHandlerUpdates the preferred size when scrolling (if necessary).classBasicTreeUI.FocusHandlerRepaints the lead selection row when focus is lost/gained.classBasicTreeUI.KeyHandlerThis is used to get multiple key down events to appropriately generate events.classBasicTreeUI.MouseHandlerTreeMouseListener is responsible for updating the selection based on mouse events.classBasicTreeUI.MouseInputHandlerMouseInputHandler handles passing all mouse events, including mouse motion events, until the mouse is released to the destination it is constructed with.classBasicTreeUI.NodeDimensionsHandlerClass responsible for getting size of node, method is forwarded to BasicTreeUI method.classBasicTreeUI.PropertyChangeHandlerPropertyChangeListener for the tree.classBasicTreeUI.SelectionModelPropertyChangeHandlerListener on the TreeSelectionModel, resets the row selection if any of the properties of the model change.classBasicTreeUI.TreeCancelEditingActionActionListener that invokes cancelEditing when action performed.classBasicTreeUI.TreeExpansionHandlerUpdates the TreeState in response to nodes expanding/collapsing.classBasicTreeUI.TreeHomeActionTreeHomeAction is used to handle end/home actions.classBasicTreeUI.TreeIncrementActionTreeIncrementAction is used to handle up/down actions.classBasicTreeUI.TreeModelHandlerForwards all TreeModel events to the TreeState.classBasicTreeUI.TreePageActionTreePageAction handles page up and page down events.classBasicTreeUI.TreeSelectionHandlerListens for changes in the selection model and updates the display accordingly.classBasicTreeUI.TreeToggleActionFor the first selected row expandedness will be toggled.classBasicTreeUI.TreeTraverseActionTreeTraverseActionis the action used for left/right keys.
- 
Field SummaryFields Modifier and Type Field Description protected TreeCellEditorcellEditorEditor for the tree.protected IconcollapsedIconThe collapsed icon.protected booleancreatedCellEditorSet to true if editor that is currently in the tree was created by this instance.protected booleancreatedRendererSet to true if the renderer that is currently in the tree was created by this instance.protected TreeCellRenderercurrentCellRendererRenderer that is being used to do the actual cell drawing.protected intdepthOffsetHow much the depth should be offset to properly calculate x locations.protected Hashtable<TreePath,Boolean>drawingCacheUsed for minimizing the drawing of vertical lines.protected ComponenteditingComponentWhen editing, this will be the Component that is doing the actual editing.protected TreePatheditingPathPath that is being edited.protected inteditingRowRow that is being edited.protected booleaneditorHasDifferentSizeSet to true if the editor has a different size than the renderer.protected IconexpandedIconThe expanded icon.protected booleanlargeModelTrue if doing optimizations for a largeModel.protected intlastSelectedRowIndex of the row that was last selected.protected intleftChildIndentDistance between left margin and where vertical dashes will be drawn.protected AbstractLayoutCache.NodeDimensionsnodeDimensionsReponsible for telling the TreeState the size needed for a node.protected DimensionpreferredMinSizeMinimum preferred size.protected DimensionpreferredSizeSize needed to completely display all the nodes.protected CellRendererPanerendererPaneUsed to paint the TreeCellRenderer.protected intrightChildIndentDistance to add to leftChildIndent to determine where cell contents will be drawn.protected booleanstopEditingInCompleteEditingSet to false when editing and shouldSelectCell() returns true meaning the node should be selected before editing, used in completeEditing.protected inttotalChildIndentTotal distance that will be indented.protected JTreetreeComponent that we're going to be drawing into.protected TreeModeltreeModelUsed to determine what to display.protected TreeSelectionModeltreeSelectionModelModel maintaining the selection.protected AbstractLayoutCachetreeStateObject responsible for handling sizing and expanded issues.protected booleanvalidCachedPreferredSizeIs the preferredSize valid?
- 
Constructor SummaryConstructors Constructor Description BasicTreeUI()Constructs a new instance ofBasicTreeUI.
- 
Method SummaryModifier and Type Method Description voidcancelEditing(JTree tree)Cancels the current editing session.protected voidcheckForClickInExpandControl(TreePath path, int mouseX, int mouseY)If themouseXandmouseYare in the expand/collapse region of therow, 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()Uninstalls UI.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 a listener that is responsible for updating the display when focus is lost/gained.protected KeyListenercreateKeyListener()Creates the listener responsible 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 ofNodeDimensionsthat is able to determine the size of a given node in the tree.protected PropertyChangeListenercreatePropertyChangeListener()Creates a listener that is responsible that 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 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 x)Constructs a new instance ofBasicTreeUI.protected voiddrawCentered(Component c, Graphics graphics, Icon icon, int x, int y)Draws theiconcentered at (x,y).protected voiddrawDashedHorizontalLine(Graphics g, int y, int x1, int x2)Draws a horizontal dashed line.protected voiddrawDashedVerticalLine(Graphics g, int x, int y1, int y2)Draws a vertical dashed line.protected voidensureRowsAreVisible(int beginRow, int endRow)Ensures that the rows identified bybeginRowthroughendRoware visible.intgetBaseline(JComponent c, int width, int height)Returns the baseline.Component.BaselineResizeBehaviorgetBaselineResizeBehavior(JComponent c)Returns an enum indicating how the baseline of the component changes as the size changes.protected TreeCellEditorgetCellEditor()Returns an instance ofTreeCellEditor.protected TreeCellRenderergetCellRenderer()ReturncurrentCellRenderer, which will either be the trees renderer, ordefaultCellRenderer, which ever wasn't null.TreePathgetClosestPathForLocation(JTree tree, int x, int y)Returns the path to the node that is closest to x,y.IcongetCollapsedIcon()Returns the collapsed icon.protected RectanglegetDropLineRect(JTree.DropLocation loc)Returns a unbounding box for the drop line.TreePathgetEditingPath(JTree tree)Returns the path to the element that is being edited.IcongetExpandedIcon()Returns the 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 ofparent.protected intgetLeadSelectionRow()Returns the lead row of the selection.intgetLeftChildIndent()Returns the left child indent.DimensiongetMaximumSize(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.DimensiongetMinimumSize(JComponent c)Returns the minimum size for this component.protected TreeModelgetModel()Returns the tree model.RectanglegetPathBounds(JTree tree, TreePath path)Returns the Rectangle enclosing the label portion that the last item in path will be drawn into.TreePathgetPathForRow(JTree tree, int row)Returns the path for passed in row.DimensiongetPreferredMinSize()Returns the minimum preferred size.DimensiongetPreferredSize(JComponent c)Returns the preferred size to properly display the tree, this is a cover method forgetPreferredSize(c, true).DimensiongetPreferredSize(JComponent c, boolean checkConsistency)Returns the preferred size to represent the tree in c.intgetRightChildIndent()Returns the right child indent.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 row height.protected intgetRowX(int row, int depth)Returns the location, along the x-axis, to render a particular row at.protected TreeSelectionModelgetSelectionModel()Returns the tree selection model.protected booleangetShowsRootHandles()Returnstrueif the root 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 invokestoggleExpandState.protected voidinstallComponents()Intalls the subcomponents of the tree, which is the renderer pane.protected voidinstallDefaults()Installs default properties.protected voidinstallKeyboardActions()Registers keyboard actions.protected voidinstallListeners()Registers listeners.protected booleanisDropLine(JTree.DropLocation loc)Tells if aDropLocationshould be indicated by a line between nodes.protected booleanisEditable()Returnstrueif the tree is editable.booleanisEditing(JTree tree)Returns true if the tree is being edited.protected booleanisLargeModel()Returnstrueif large model is set.protected booleanisLeaf(int row)Returnstrueif the node atrowis a leaf.protected booleanisLocationInExpandControl(TreePath path, int mouseX, int mouseY)ReturnstrueifmouseXandmouseYfall in the area of row that is used to expand/collapse the node and the node atrowdoes not represent a leaf.protected booleanisMultiSelectEvent(MouseEvent event)Returningtruesignifies a mouse event on the node should select from the anchor point.protected booleanisRootVisible()Returnstrueif the tree root is visible.protected booleanisToggleEvent(MouseEvent event)Returningtrueindicates the row under the mouse should be toggled based on the event.protected booleanisToggleSelectionEvent(MouseEvent event)Returningtruesignifies a mouse event on the node should toggle the selection of only the row under mouse.protected voidpaintDropLine(Graphics g)Paints the drop line.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)Paints a horizontal line.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)Paints a vertical line.protected voidpaintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path)Paints the vertical part of the leg.protected voidpathWasCollapsed(TreePath path)Messaged from theVisibleTreeNodeafter it has collapsed.protected voidpathWasExpanded(TreePath path)Messaged from theVisibleTreeNodeafter it has been expanded.protected voidprepareForUIInstall()Invoked after thetreeinstance variable has been set, but before any defaults/listeners have been installed.protected voidprepareForUIUninstall()Invoked before unstallation of UI.protected voidselectPathForEvent(TreePath path, MouseEvent event)Messaged to update the selection based on aMouseEventover a particular row.protected voidsetCellEditor(TreeCellEditor editor)Sets the cell editor.protected voidsetCellRenderer(TreeCellRenderer tcr)Sets theTreeCellRenderertotcr.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 indent.protected voidsetModel(TreeModel model)Sets theTreeModel.voidsetPreferredMinSize(Dimension newSize)Sets the preferred minimum size.voidsetRightChildIndent(int newAmount)Sets the right child indent.protected voidsetRootVisible(boolean newValue)Sets the root to being visible.protected voidsetRowHeight(int rowHeight)Sets the row height, this is forwarded to the treeState.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)Returnstrueif 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 acellEditorandshouldSelectCellreturnstrue.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()Uninstalls the renderer pane.protected voiduninstallDefaults()Uninstalls default properties.protected voiduninstallKeyboardActions()Unregisters keyboard actions.protected voiduninstallListeners()Unregisters listeners.protected voidupdateCachedPreferredSize()Updates thepreferredSizeinstance variable, which is returned fromgetPreferredSize().protected voidupdateCellEditor()Updates the cellEditor based on the 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 ofpathby getting the expanded descendants from the tree and forwarding to the tree state.protected voidupdateLayoutCacheExpandedNodes()Makes all the nodes that are expanded in JTree expanded in LayoutCache.protected voidupdateLeadSelectionRow()Updates the lead row of the selection.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 withtreeDidChange.Methods declared in class javax.swing.plaf.ComponentUIcontains, getAccessibleChild, getAccessibleChildrenCount, installUI, paint, uninstallUI, update
- 
Field Details- 
collapsedIconThe collapsed icon.
- 
expandedIconThe expanded icon.
- 
leftChildIndentprotected int leftChildIndentDistance between left margin and where vertical dashes will be drawn.
- 
rightChildIndentprotected int rightChildIndentDistance to add to leftChildIndent to determine where cell contents will be drawn.
- 
totalChildIndentprotected int totalChildIndentTotal distance that will be indented. The sum of leftChildIndent and rightChildIndent.
- 
preferredMinSizeMinimum preferred size.
- 
lastSelectedRowprotected int lastSelectedRowIndex of the row that was last selected.
- 
treeComponent that we're going to be drawing into.
- 
currentCellRendererRenderer that is being used to do the actual cell drawing.
- 
createdRendererprotected boolean createdRendererSet to true if the renderer that is currently in the tree was created by this instance.
- 
cellEditorEditor for the tree.
- 
createdCellEditorprotected boolean createdCellEditorSet to true if editor that is currently in the tree was created by this instance.
- 
stopEditingInCompleteEditingprotected boolean stopEditingInCompleteEditingSet to false when editing and shouldSelectCell() returns true meaning the node should be selected before editing, used in completeEditing.
- 
rendererPaneUsed to paint the TreeCellRenderer.
- 
preferredSizeSize needed to completely display all the nodes.
- 
validCachedPreferredSizeprotected boolean validCachedPreferredSizeIs the preferredSize valid?
- 
treeStateObject responsible for handling sizing and expanded issues.
- 
drawingCacheUsed for minimizing the drawing of vertical lines.
- 
largeModelprotected boolean largeModelTrue if doing optimizations for a largeModel. Subclasses that don't support this may wish to override createLayoutCache to not return a FixedHeightLayoutCache instance.
- 
nodeDimensionsReponsible for telling the TreeState the size needed for a node.
- 
treeModelUsed to determine what to display.
- 
treeSelectionModelModel maintaining the selection.
- 
depthOffsetprotected int depthOffsetHow 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.
- 
editingComponentWhen editing, this will be the Component that is doing the actual editing.
- 
editingPathPath that is being edited.
- 
editingRowprotected int editingRowRow that is being edited. Should only be referenced if editingComponent is not null.
- 
editorHasDifferentSizeprotected boolean editorHasDifferentSizeSet to true if the editor has a different size than the renderer.
 
- 
- 
Constructor Details- 
BasicTreeUIpublic BasicTreeUI()Constructs a new instance ofBasicTreeUI.
 
- 
- 
Method Details- 
createUIConstructs a new instance ofBasicTreeUI.- Parameters:
- x- a component
- Returns:
- a new instance of BasicTreeUI
 
- 
getHashColorReturns the hash color.- Returns:
- the hash color
 
- 
setHashColorSets the hash color.- Parameters:
- color- the hash color
 
- 
setLeftChildIndentpublic void setLeftChildIndent(int newAmount)Sets the left child indent.- Parameters:
- newAmount- the left child indent
 
- 
getLeftChildIndentpublic int getLeftChildIndent()Returns the left child indent.- Returns:
- the left child indent
 
- 
setRightChildIndentpublic void setRightChildIndent(int newAmount)Sets the right child indent.- Parameters:
- newAmount- the right child indent
 
- 
getRightChildIndentpublic int getRightChildIndent()Returns the right child indent.- Returns:
- the right child indent
 
- 
setExpandedIconSets the expanded icon.- Parameters:
- newG- the expanded icon
 
- 
getExpandedIconReturns the expanded icon.- Returns:
- the expanded icon
 
- 
setCollapsedIconSets the collapsed icon.- Parameters:
- newG- the collapsed icon
 
- 
getCollapsedIconReturns the collapsed icon.- Returns:
- the collapsed icon
 
- 
setLargeModelprotected void setLargeModel(boolean largeModel)Updates the componentListener, if necessary.- Parameters:
- largeModel- the new value
 
- 
isLargeModelprotected boolean isLargeModel()Returnstrueif large model is set.- Returns:
- trueif large model is set
 
- 
setRowHeightprotected void setRowHeight(int rowHeight)Sets the row height, this is forwarded to the treeState.- Parameters:
- rowHeight- the row height
 
- 
getRowHeightprotected int getRowHeight()Returns the row height.- Returns:
- the row height
 
- 
setCellRendererSets theTreeCellRenderertotcr. This invokesupdateRenderer.- Parameters:
- tcr- the new value
 
- 
getCellRendererReturncurrentCellRenderer, which will either be the trees renderer, ordefaultCellRenderer, which ever wasn't null.- Returns:
- an instance of TreeCellRenderer
 
- 
setModelSets theTreeModel.- Parameters:
- model- the new value
 
- 
getModelReturns the tree model.- Returns:
- the tree model
 
- 
setRootVisibleprotected void setRootVisible(boolean newValue)Sets the root to being visible.- Parameters:
- newValue- the new value
 
- 
isRootVisibleprotected boolean isRootVisible()Returnstrueif the tree root is visible.- Returns:
- trueif the tree root is visible
 
- 
setShowsRootHandlesprotected void setShowsRootHandles(boolean newValue)Determines whether the node handles are to be displayed.- Parameters:
- newValue- the new value
 
- 
getShowsRootHandlesprotected boolean getShowsRootHandles()Returnstrueif the root handles are to be displayed.- Returns:
- trueif the root handles are to be displayed
 
- 
setCellEditorSets the cell editor.- Parameters:
- editor- the new cell editor
 
- 
getCellEditorReturns an instance ofTreeCellEditor.- Returns:
- an instance of TreeCellEditor
 
- 
setEditableprotected void setEditable(boolean newValue)Configures the receiver to allow, or not allow, editing.- Parameters:
- newValue- the new value
 
- 
isEditableprotected boolean isEditable()Returnstrueif the tree is editable.- Returns:
- trueif the tree is editable
 
- 
setSelectionModelResets the selection model. The appropriate listener are installed on the model.- Parameters:
- newLSM- new selection model
 
- 
getSelectionModelReturns the tree selection model.- Returns:
- the tree selection model
 
- 
getPathBoundsReturns 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.- Specified by:
- getPathBoundsin class- TreeUI
- Parameters:
- tree- the- JTreefor- path
- path- the- TreePathidentifying the node
- Returns:
- the Rectangleenclosing the label portion that the last item in path will be drawn into,nullif any component in path is currently valid.
 
- 
getPathForRowReturns the path for passed in row. If row is not visible null is returned.- Specified by:
- getPathForRowin class- TreeUI
- Parameters:
- tree- a- JTreeobject
- row- an integer specifying a row
- Returns:
- the pathforrowornullifrowis not visible
 
- 
getRowForPathReturns 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.- Specified by:
- getRowForPathin class- TreeUI
- Parameters:
- tree- the- JTreefor- path
- path- the- TreePathobject to look in
- Returns:
- an integer specifying the row at which the last item
         identified is visible, -1 if any of the elements in
         pathare not currently visible
 
- 
getRowCountReturns the number of rows that are being displayed.- Specified by:
- getRowCountin class- TreeUI
- Parameters:
- tree- the- JTreefor which to count rows
- Returns:
- an integer specifying the number of row being displayed
 
- 
getClosestPathForLocationReturns 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.- Specified by:
- getClosestPathForLocationin class- TreeUI
- Parameters:
- tree- a- JTreeobject
- x- an integer giving the number of pixels horizontally from the left edge of the display area
- y- an integer giving the number of pixels vertically from the top of the display area, minus any top margin
- Returns:
- the TreePathnode closest tox,yornullif there is nothing currently visible
 
- 
isEditingReturns true if the tree is being edited. The item that is being edited can be returned by getEditingPath().
- 
stopEditingStops 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.- Specified by:
- stopEditingin class- TreeUI
- Parameters:
- tree- a- JTreeobject
- Returns:
- true if the editor allows the editing session to stop
 
- 
cancelEditingCancels the current editing session.- Specified by:
- cancelEditingin class- TreeUI
- Parameters:
- tree- a- JTreeobject
 
- 
startEditingAtPathSelects the last item in path and tries to edit it. Editing will fail if the CellEditor won't allow it for the selected item.- Specified by:
- startEditingAtPathin class- TreeUI
- Parameters:
- tree- the- JTreebeing edited
- path- the- TreePathto be edited
 
- 
getEditingPathReturns the path to the element that is being edited.- Specified by:
- getEditingPathin class- TreeUI
- Parameters:
- tree- the- JTreefor which to return a path
- Returns:
- a TreePathcontaining the path totree
 
- 
prepareForUIInstallprotected void prepareForUIInstall()Invoked after thetreeinstance variable has been set, but before any defaults/listeners have been installed.
- 
completeUIInstallprotected void completeUIInstall()Invoked from installUI after all the defaults/listeners have been installed.
- 
installDefaultsprotected void installDefaults()Installs default properties.
- 
installListenersprotected void installListeners()Registers listeners.
- 
installKeyboardActionsprotected void installKeyboardActions()Registers keyboard actions.
- 
installComponentsprotected void installComponents()Intalls the subcomponents of the tree, which is the renderer pane.
- 
createNodeDimensionsCreates an instance ofNodeDimensionsthat is able to determine the size of a given node in the tree.- Returns:
- an instance of NodeDimensions
 
- 
createPropertyChangeListenerCreates a listener that is responsible that updates the UI based on how the tree changes.- Returns:
- an instance of the PropertyChangeListener
 
- 
createMouseListenerCreates the listener responsible for updating the selection based on mouse events.- Returns:
- an instance of the MouseListener
 
- 
createFocusListenerCreates a listener that is responsible for updating the display when focus is lost/gained.- Returns:
- an instance of the FocusListener
 
- 
createKeyListenerCreates the listener responsible for getting key events from the tree.- Returns:
- an instance of the KeyListener
 
- 
createSelectionModelPropertyChangeListenerCreates the listener responsible for getting property change events from the selection model.- Returns:
- an instance of the PropertyChangeListener
 
- 
createTreeSelectionListenerCreates the listener that updates the display based on selection change methods.- Returns:
- an instance of the TreeSelectionListener
 
- 
createCellEditorListenerCreates a listener to handle events from the current editor.- Returns:
- an instance of the CellEditorListener
 
- 
createComponentListenerCreates and returns a new ComponentHandler. This is used for the large model to mark the validCachedPreferredSize as invalid when the component moves.- Returns:
- an instance of the ComponentListener
 
- 
createTreeExpansionListenerCreates and returns the object responsible for updating the treestate when nodes expanded state changes.- Returns:
- an instance of the TreeExpansionListener
 
- 
createLayoutCacheCreates the object responsible for managing what is expanded, as well as the size of nodes.- Returns:
- the object responsible for managing what is expanded
 
- 
createCellRendererPaneReturns the renderer pane that renderer components are placed in.- Returns:
- an instance of the CellRendererPane
 
- 
createDefaultCellEditorCreates a default cell editor.- Returns:
- a default cell editor
 
- 
createDefaultCellRendererReturns the default cell renderer that is used to do the stamping of each node.- Returns:
- an instance of TreeCellRenderer
 
- 
createTreeModelListenerReturns a listener that can update the tree when the model changes.- Returns:
- an instance of the TreeModelListener.
 
- 
prepareForUIUninstallprotected void prepareForUIUninstall()Invoked before unstallation of UI.
- 
completeUIUninstallprotected void completeUIUninstall()Uninstalls UI.
- 
uninstallDefaultsprotected void uninstallDefaults()Uninstalls default properties.
- 
uninstallListenersprotected void uninstallListeners()Unregisters listeners.
- 
uninstallKeyboardActionsprotected void uninstallKeyboardActions()Unregisters keyboard actions.
- 
uninstallComponentsprotected void uninstallComponents()Uninstalls the renderer pane.
- 
getBaselineReturns the baseline.- Overrides:
- getBaselinein class- ComponentUI
- Parameters:
- c-- JComponentbaseline 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
- Throws:
- NullPointerException- if- cis- null
- IllegalArgumentException- if width or height is < 0
- Since:
- 1.6
- See Also:
- JComponent.getBaseline(int, int)
 
- 
getBaselineResizeBehaviorReturns an enum indicating how the baseline of the component changes as the size changes.- Overrides:
- getBaselineResizeBehaviorin class- ComponentUI
- Parameters:
- c-- JComponentto return baseline resize behavior for
- Returns:
- an enum indicating how the baseline changes as the component size changes
- Throws:
- NullPointerException- if- cis- null
- Since:
- 1.6
- See Also:
- JComponent.getBaseline(int, int)
 
- 
isDropLineTells if aDropLocationshould be indicated by a line between nodes. This is meant forjavax.swing.DropMode.INSERTandjavax.swing.DropMode.ON_OR_INSERTdrop modes.- Parameters:
- loc- a- DropLocation
- Returns:
- trueif the drop location should be shown as a line
- Since:
- 1.7
 
- 
paintDropLinePaints the drop line.- Parameters:
- g-- Graphicsobject to draw on
- Since:
- 1.7
 
- 
getDropLineRectReturns a unbounding box for the drop line.- Parameters:
- loc- a- DropLocation
- Returns:
- bounding box for the drop line
- Since:
- 1.7
 
- 
paintHorizontalPartOfLegprotected 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 modifyclipBounds, orinsets.NOTE: parentRowcan be -1 if the root is not visible.- Parameters:
- g- a graphics context
- clipBounds- a clipped rectangle
- insets- insets
- bounds- a bounding rectangle
- path- a tree path
- row- a row
- isExpanded-- trueif the path is expanded
- hasBeenExpanded-- trueif the path has been expanded
- isLeaf-- trueif the path is leaf
 
- 
paintVerticalPartOfLegprotected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path)Paints the vertical part of the leg. The receiver should NOT modifyclipBounds,insets.- Parameters:
- g- a graphics context
- clipBounds- a clipped rectangle
- insets- insets
- path- a tree path
 
- 
paintExpandControlprotected 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 modifyclipBounds, orinsets.- Parameters:
- g- a graphics context
- clipBounds- a clipped rectangle
- insets- insets
- bounds- a bounding rectangle
- path- a tree path
- row- a row
- isExpanded-- trueif the path is expanded
- hasBeenExpanded-- trueif the path has been expanded
- isLeaf-- trueif the row is leaf
 
- 
paintRowprotected 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 modifyclipBounds, orinsets.- Parameters:
- g- a graphics context
- clipBounds- a clipped rectangle
- insets- insets
- bounds- a bounding rectangle
- path- a tree path
- row- a row
- isExpanded-- trueif the path is expanded
- hasBeenExpanded-- trueif the path has been expanded
- isLeaf-- trueif the path is leaf
 
- 
shouldPaintExpandControlprotected boolean shouldPaintExpandControl(TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)Returnstrueif the expand (toggle) control should be drawn for the specified row.- Parameters:
- path- a tree path
- row- a row
- isExpanded-- trueif the path is expanded
- hasBeenExpanded-- trueif the path has been expanded
- isLeaf-- trueif the row is leaf
- Returns:
- trueif the expand (toggle) control should be drawn for the specified row
 
- 
paintVerticalLinePaints a vertical line.- Parameters:
- g- a graphics context
- c- a component
- x- an X coordinate
- top- an Y1 coordinate
- bottom- an Y2 coordinate
 
- 
paintHorizontalLinePaints a horizontal line.- Parameters:
- g- a graphics context
- c- a component
- y- an Y coordinate
- left- an X1 coordinate
- right- an X2 coordinate
 
- 
getVerticalLegBufferprotected 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
 
- 
getHorizontalLegBufferprotected 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
 
- 
drawCenteredDraws theiconcentered at (x,y).- Parameters:
- c- a component
- graphics- a graphics context
- icon- an icon
- x- an X coordinate
- y- an Y coordinate
 
- 
drawDashedHorizontalLineDraws a horizontal dashed line. It is assumedx1<=x2. Ifx1is greater thanx2, the method draws nothing.- Parameters:
- g- an instance of- Graphics
- y- an Y coordinate
- x1- an X1 coordinate
- x2- an X2 coordinate
 
- 
drawDashedVerticalLineDraws a vertical dashed line. It is assumedy1<=y2. Ify1is greater thany2, the method draws nothing.- Parameters:
- g- an instance of- Graphics
- x- an X coordinate
- y1- an Y1 coordinate
- y2- an Y2 coordinate
 
- 
getRowXprotected 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.
- Since:
- 1.5
 
- 
updateLayoutCacheExpandedNodesprotected void updateLayoutCacheExpandedNodes()Makes all the nodes that are expanded in JTree expanded in LayoutCache. This invokes updateExpandedDescendants with the root path.
- 
updateExpandedDescendantsUpdates the expanded state of all the descendants ofpathby getting the expanded descendants from the tree and forwarding to the tree state.- Parameters:
- path- a tree path
 
- 
getLastChildPathReturns a path to the last child ofparent.- Parameters:
- parent- a tree path
- Returns:
- a path to the last child of parent
 
- 
updateDepthOffsetprotected void updateDepthOffset()Updates how much each depth should be offset by.
- 
updateCellEditorprotected 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.
- 
updateRendererprotected void updateRenderer()Messaged from the tree we're in when the renderer has changed.
- 
configureLayoutCacheprotected void configureLayoutCache()Resets the TreeState instance based on the tree we're providing the look and feel for.
- 
updateSizeprotected void updateSize()Marks the cached size as being invalid, and messages the tree withtreeDidChange.
- 
updateCachedPreferredSizeprotected void updateCachedPreferredSize()Updates thepreferredSizeinstance variable, which is returned fromgetPreferredSize().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. 
- 
pathWasExpandedMessaged from theVisibleTreeNodeafter it has been expanded.- Parameters:
- path- a tree path
 
- 
pathWasCollapsedMessaged from theVisibleTreeNodeafter it has collapsed.- Parameters:
- path- a tree path
 
- 
ensureRowsAreVisibleprotected void ensureRowsAreVisible(int beginRow, int endRow)Ensures that the rows identified bybeginRowthroughendRoware visible.- Parameters:
- beginRow- the begin row
- endRow- the end row
 
- 
setPreferredMinSizeSets the preferred minimum size.- Parameters:
- newSize- the new preferred size
 
- 
getPreferredMinSizeReturns the minimum preferred size.- Returns:
- the minimum preferred size
 
- 
getPreferredSizeReturns the preferred size to properly display the tree, this is a cover method forgetPreferredSize(c, true).- Overrides:
- getPreferredSizein class- ComponentUI
- Parameters:
- c- a component
- Returns:
- the preferred size to represent the tree in the component
- See Also:
- JComponent.getPreferredSize(),- LayoutManager.preferredLayoutSize(java.awt.Container)
 
- 
getPreferredSizeReturns the preferred size to represent the tree in c. If checkConsistency istruecheckConsistency is messaged first.- Parameters:
- c- a component
- checkConsistency- if- trueconsistency is checked
- Returns:
- the preferred size to represent the tree in the component
 
- 
getMinimumSizeReturns the minimum size for this component. Which will be the min preferred size or 0, 0.- Overrides:
- getMinimumSizein class- ComponentUI
- 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 Dimensionobject ornull
- See Also:
- JComponent.getMinimumSize(),- LayoutManager.minimumLayoutSize(java.awt.Container),- ComponentUI.getPreferredSize(javax.swing.JComponent)
 
- 
getMaximumSizeReturns the maximum size for this component, which will be the preferred size if the instance is currently in a JTree, or 0, 0.- Overrides:
- getMaximumSizein class- ComponentUI
- 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 Dimensionobject ornull
- See Also:
- JComponent.getMaximumSize(),- LayoutManager2.maximumLayoutSize(java.awt.Container)
 
- 
completeEditingprotected void completeEditing()Messages to stop the editing session. If the UI the receiver is providing the look and feel for returns true fromgetInvokesStopCellEditing, stopCellEditing will invoked on the current editor. Then completeEditing will be messaged with false, true, false to cancel any lingering editing.
- 
completeEditingprotected void completeEditing(boolean messageStop, boolean messageCancel, boolean messageTree)Stops the editing session. IfmessageStopistruethe editor is messaged withstopEditing, ifmessageCancelistruethe editor is messaged withcancelEditing. IfmessageTreeistruethetreeModelis messaged withvalueForPathChanged.- Parameters:
- messageStop- message to stop editing
- messageCancel- message to cancel editing
- messageTree- message to tree
 
- 
startEditingWill start editing for node if there is acellEditorandshouldSelectCellreturnstrue.This assumes that path is valid and visible. - Parameters:
- path- a tree path
- event- a mouse event
- Returns:
- trueif the editing is successful
 
- 
checkForClickInExpandControlIf themouseXandmouseYare in the expand/collapse region of therow, this will toggle the row.- Parameters:
- path- a tree path
- mouseX- an X coordinate
- mouseY- an Y coordinate
 
- 
isLocationInExpandControlReturnstrueifmouseXandmouseYfall in the area of row that is used to expand/collapse the node and the node atrowdoes not represent a leaf.- Parameters:
- path- a tree path
- mouseX- an X coordinate
- mouseY- an Y coordinate
- Returns:
- trueif the mouse cursor fall in the area of row that is used to expand/collapse the node and the node is not a leaf.
 
- 
handleExpandControlClickMessaged when the user clicks the particular row, this invokestoggleExpandState.- Parameters:
- path- a tree path
- mouseX- an X coordinate
- mouseY- an Y coordinate
 
- 
toggleExpandStateExpands path if it is not expanded, or collapses row if it is expanded. If expanding a path andJTreescrolls on expand,ensureRowsAreVisibleis invoked to scroll as many of the children to visible as possible (tries to scroll to last visible descendant of path).- Parameters:
- path- a tree path
 
- 
isToggleSelectionEventReturningtruesignifies a mouse event on the node should toggle the selection of only the row under mouse.- Parameters:
- event- a mouse event
- Returns:
- trueif a mouse event on the node should toggle the selection
 
- 
isMultiSelectEventReturningtruesignifies a mouse event on the node should select from the anchor point.- Parameters:
- event- a mouse event
- Returns:
- trueif a mouse event on the node should select from the anchor point
 
- 
isToggleEventReturningtrueindicates the row under the mouse should be toggled based on the event. This is invoked aftercheckForClickInExpandControl, implying the location is not in the expand (toggle) control.- Parameters:
- event- a mouse event
- Returns:
- trueif the row under the mouse should be toggled
 
- 
selectPathForEventMessaged to update the selection based on aMouseEventover 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.- Parameters:
- path- the selected path
- event- the mouse event
 
- 
isLeafprotected boolean isLeaf(int row)Returnstrueif the node atrowis a leaf.- Parameters:
- row- a row
- Returns:
- trueif the node at- rowis a leaf
 
- 
updateLeadSelectionRowprotected void updateLeadSelectionRow()Updates the lead row of the selection.- Since:
- 1.7
 
- 
getLeadSelectionRowprotected int getLeadSelectionRow()Returns the lead row of the selection.- Returns:
- selection lead row
- Since:
- 1.7
 
 
-