java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.TreeUI
javax.swing.plaf.basic.BasicTreeUI
- Direct Known Subclasses:
MetalTreeUI
,SynthTreeUI
The basic L&F for a hierarchical data structure.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Listener responsible for getting cell editing events and updating the tree accordingly.class
Updates the preferred size when scrolling (if necessary).class
Repaints the lead selection row when focus is lost/gained.class
This is used to get multiple key down events to appropriately generate events.class
TreeMouseListener is responsible for updating the selection based on mouse events.class
MouseInputHandler handles passing all mouse events, including mouse motion events, until the mouse is released to the destination it is constructed with.class
Class responsible for getting size of node, method is forwarded to BasicTreeUI method.class
PropertyChangeListener for the tree.class
Listener on the TreeSelectionModel, resets the row selection if any of the properties of the model change.class
ActionListener that invokes cancelEditing when action performed.class
Updates the TreeState in response to nodes expanding/collapsing.class
TreeHomeAction is used to handle end/home actions.class
TreeIncrementAction is used to handle up/down actions.class
Forwards all TreeModel events to the TreeState.class
TreePageAction handles page up and page down events.class
Listens for changes in the selection model and updates the display accordingly.class
For the first selected row expandedness will be toggled.class
TreeTraverseAction
is the action used for left/right keys. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TreeCellEditor
Editor for the tree.protected Icon
The collapsed icon.protected boolean
Set to true if editor that is currently in the tree was created by this instance.protected boolean
Set to true if the renderer that is currently in the tree was created by this instance.protected TreeCellRenderer
Renderer that is being used to do the actual cell drawing.protected int
How much the depth should be offset to properly calculate x locations.Used for minimizing the drawing of vertical lines.protected Component
When editing, this will be the Component that is doing the actual editing.protected TreePath
Path that is being edited.protected int
Row that is being edited.protected boolean
Set to true if the editor has a different size than the renderer.protected Icon
The expanded icon.protected boolean
True if doing optimizations for a largeModel.protected int
Index of the row that was last selected.protected int
Distance between left margin and where vertical dashes will be drawn.protected AbstractLayoutCache.NodeDimensions
Reponsible for telling the TreeState the size needed for a node.protected Dimension
Minimum preferred size.protected Dimension
Size needed to completely display all the nodes.protected CellRendererPane
Used to paint the TreeCellRenderer.protected int
Distance to add to leftChildIndent to determine where cell contents will be drawn.protected boolean
Set to false when editing and shouldSelectCell() returns true meaning the node should be selected before editing, used in completeEditing.protected int
Total distance that will be indented.protected JTree
Component that we're going to be drawing into.protected TreeModel
Used to determine what to display.protected TreeSelectionModel
Model maintaining the selection.protected AbstractLayoutCache
Object responsible for handling sizing and expanded issues.protected boolean
Is the preferredSize valid? -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancelEditing(JTree tree)
Cancels the current editing session.protected void
checkForClickInExpandControl(TreePath path, int mouseX, int mouseY)
If themouseX
andmouseY
are in the expand/collapse region of therow
, this will toggle the row.protected void
Messages to stop the editing session.protected void
completeEditing(boolean messageStop, boolean messageCancel, boolean messageTree)
Stops the editing session.protected void
Invoked from installUI after all the defaults/listeners have been installed.protected void
Uninstalls UI.protected void
Resets the TreeState instance based on the tree we're providing the look and feel for.protected CellEditorListener
Creates a listener to handle events from the current editor.protected CellRendererPane
Returns the renderer pane that renderer components are placed in.protected ComponentListener
Creates and returns a new ComponentHandler.protected TreeCellEditor
Creates a default cell editor.protected TreeCellRenderer
Returns the default cell renderer that is used to do the stamping of each node.protected FocusListener
Creates a listener that is responsible for updating the display when focus is lost/gained.protected KeyListener
Creates the listener responsible for getting key events from the tree.protected AbstractLayoutCache
Creates the object responsible for managing what is expanded, as well as the size of nodes.protected MouseListener
Creates the listener responsible for updating the selection based on mouse events.protected AbstractLayoutCache.NodeDimensions
Creates an instance ofNodeDimensions
that is able to determine the size of a given node in the tree.protected PropertyChangeListener
Creates a listener that is responsible that updates the UI based on how the tree changes.protected PropertyChangeListener
Creates the listener responsible for getting property change events from the selection model.protected TreeExpansionListener
Creates and returns the object responsible for updating the treestate when nodes expanded state changes.protected TreeModelListener
Returns a listener that can update the tree when the model changes.protected TreeSelectionListener
Creates the listener that updates the display based on selection change methods.static ComponentUI
createUI(JComponent x)
Constructs a new instance ofBasicTreeUI
.protected void
drawCentered(Component c, Graphics graphics, Icon icon, int x, int y)
Draws theicon
centered at (x,y).protected void
drawDashedHorizontalLine(Graphics g, int y, int x1, int x2)
Draws a horizontal dashed line.protected void
drawDashedVerticalLine(Graphics g, int x, int y1, int y2)
Draws a vertical dashed line.protected void
ensureRowsAreVisible(int beginRow, int endRow)
Ensures that the rows identified bybeginRow
throughendRow
are visible.int
getBaseline(JComponent c, int width, int height)
Returns the baseline.Returns an enum indicating how the baseline of the component changes as the size changes.protected TreeCellEditor
Returns the editor used to edit entries in the drawn tree component, ornull
if the tree cannot be edited.protected TreeCellRenderer
Returns the current instance of theTreeCellRenderer
that is rendering each cell.getClosestPathForLocation(JTree tree, int x, int y)
Returns the path to the node that is closest to x,y.Returns the collapsed icon.protected Rectangle
Returns a unbounding box for the drop line.getEditingPath(JTree tree)
Returns the path to the element that is being edited.Returns the expanded icon.protected Color
Returns the hash color.protected int
The horizontal element of legs between nodes starts at the right of the left-hand side of the child node by default.protected TreePath
getLastChildPath(TreePath parent)
Returns a path to the last child ofparent
.protected int
Returns the lead row of the selection.int
Returns the left child indent.Returns the maximum size for this component, which will be the preferred size if the instance is currently in a JTree, or 0, 0.Returns the minimum size for this component.protected TreeModel
getModel()
Returns the tree model.getPathBounds(JTree tree, TreePath path)
Returns the Rectangle enclosing the label portion that the last item in path will be drawn into.getPathForRow(JTree tree, int row)
Returns the path for passed in row.Returns the minimum preferred size.Returns the preferred size to properly display the tree, this is a cover method forgetPreferredSize(c, true)
.getPreferredSize(JComponent c, boolean checkConsistency)
Returns the preferred size to represent the tree in c.int
Returns the right child indent.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.protected int
Returns the height of each row in the drawn tree component.protected int
getRowX(int row, int depth)
Returns the location, along the x-axis, to render a particular row at.protected TreeSelectionModel
Returns the current instance of theTreeSelectionModel
which is the model for selections.protected boolean
Returnstrue
if the root handles are to be displayed.protected int
The vertical element of legs between nodes starts at the bottom of the parent node by default.protected void
handleExpandControlClick(TreePath path, int mouseX, int mouseY)
Messaged when the user clicks the particular row, this invokestoggleExpandState
.protected void
Intalls the subcomponents of the tree, which is the renderer pane.protected void
Installs default properties.protected void
Registers keyboard actions.protected void
Registers listeners.protected boolean
isDropLine(JTree.DropLocation loc)
Tells if aDropLocation
should be indicated by a line between nodes.protected boolean
Returns whether the drawn tree component should be enabled for editing.boolean
Returns true if the tree is being edited.protected boolean
Returnstrue
if large model is set.protected boolean
isLeaf(int row)
Returnstrue
if the node atrow
is a leaf.protected boolean
isLocationInExpandControl(TreePath path, int mouseX, int mouseY)
Returnstrue
ifmouseX
andmouseY
fall in the area of row that is used to expand/collapse the node and the node atrow
does not represent a leaf.protected boolean
isMultiSelectEvent(MouseEvent event)
Returningtrue
signifies a mouse event on the node should select from the anchor point.protected boolean
Returns whether the root node of the drawn tree component should be displayed.protected boolean
isToggleEvent(MouseEvent event)
Returningtrue
indicates the row under the mouse should be toggled based on the event.protected boolean
isToggleSelectionEvent(MouseEvent event)
Returningtrue
signifies a mouse event on the node should toggle the selection of only the row under mouse.protected void
Paints the drop line.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.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.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.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.protected void
pathWasCollapsed(TreePath path)
Messaged from theVisibleTreeNode
after it has collapsed.protected void
pathWasExpanded(TreePath path)
Messaged from theVisibleTreeNode
after it has been expanded.protected void
Invoked after thetree
instance variable has been set, but before any defaults/listeners have been installed.protected void
Invoked before unstallation of UI.protected void
selectPathForEvent(TreePath path, MouseEvent event)
Messaged to update the selection based on aMouseEvent
over a particular row.protected void
setCellEditor(TreeCellEditor editor)
Sets the cell editor.protected void
Sets theTreeCellRenderer
totcr
.void
setCollapsedIcon(Icon newG)
Sets the collapsed icon.protected void
setEditable(boolean newValue)
Configures the receiver to allow, or not allow, editing.void
setExpandedIcon(Icon newG)
Sets the expanded icon.protected void
setHashColor(Color color)
Sets the hash color.protected void
setLargeModel(boolean largeModel)
Sets thelargeModel
.void
setLeftChildIndent(int newAmount)
Sets the left child indent.protected void
Sets theTreeModel
.void
setPreferredMinSize(Dimension newSize)
Sets the preferred minimum size.void
setRightChildIndent(int newAmount)
Sets the right child indent.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.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)
Returnstrue
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 acellEditor
andshouldSelectCell
returnstrue
.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.protected void
toggleExpandState(TreePath path)
Expands path if it is not expanded, or collapses row if it is expanded.protected void
Uninstalls the renderer pane.protected void
Uninstalls default properties.protected void
Unregisters keyboard actions.protected void
Unregisters listeners.protected void
Updates thepreferredSize
instance variable, which is returned fromgetPreferredSize()
.protected void
Updates the cellEditor based on the editability of the JTree that we're contained in.protected void
Updates how much each depth should be offset by.protected void
Updates the expanded state of all the descendants ofpath
by getting the expanded descendants from the tree and forwarding to the tree state.protected void
Makes all the nodes that are expanded in JTree expanded in LayoutCache.protected void
Updates the lead row of the selection.protected void
Messaged from the tree we're in when the renderer has changed.protected void
Marks the cached size as being invalid, and messages the tree withtreeDidChange
.Methods declared in class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, installUI, paint, uninstallUI, update
-
Field Details
-
collapsedIcon
The collapsed icon. -
expandedIcon
The expanded icon. -
leftChildIndent
protected int leftChildIndentDistance between left margin and where vertical dashes will be drawn. -
rightChildIndent
protected int rightChildIndentDistance to add to leftChildIndent to determine where cell contents will be drawn. -
totalChildIndent
protected int totalChildIndentTotal distance that will be indented. The sum of leftChildIndent and rightChildIndent. -
preferredMinSize
Minimum preferred size. -
lastSelectedRow
protected int lastSelectedRowIndex of the row that was last selected. -
tree
Component that we're going to be drawing into. -
currentCellRenderer
Renderer that is being used to do the actual cell drawing. -
createdRenderer
protected boolean createdRendererSet to true if the renderer that is currently in the tree was created by this instance. -
cellEditor
Editor for the tree. -
createdCellEditor
protected boolean createdCellEditorSet to true if editor that is currently in the tree was created by this instance. -
stopEditingInCompleteEditing
protected boolean stopEditingInCompleteEditingSet to false when editing and shouldSelectCell() returns true meaning the node should be selected before editing, used in completeEditing. -
rendererPane
Used to paint the TreeCellRenderer. -
preferredSize
Size needed to completely display all the nodes. -
validCachedPreferredSize
protected boolean validCachedPreferredSizeIs the preferredSize valid? -
treeState
Object responsible for handling sizing and expanded issues. -
drawingCache
Used for minimizing the drawing of vertical lines. -
largeModel
protected 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. -
nodeDimensions
Reponsible for telling the TreeState the size needed for a node. -
treeModel
Used to determine what to display. -
treeSelectionModel
Model maintaining the selection. -
depthOffset
protected 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. -
editingComponent
When editing, this will be the Component that is doing the actual editing. -
editingPath
Path that is being edited. -
editingRow
protected int editingRowRow that is being edited. Should only be referenced if editingComponent is not null. -
editorHasDifferentSize
protected boolean editorHasDifferentSizeSet to true if the editor has a different size than the renderer.
-
-
Constructor Details
-
BasicTreeUI
public BasicTreeUI()Constructs a new instance ofBasicTreeUI
.
-
-
Method Details
-
createUI
Constructs a new instance ofBasicTreeUI
.- Parameters:
x
- a component- Returns:
- a new instance of
BasicTreeUI
-
getHashColor
Returns the hash color.- Returns:
- the hash color
-
setHashColor
Sets the hash color.- Parameters:
color
- the hash color
-
setLeftChildIndent
public void setLeftChildIndent(int newAmount)Sets the left child indent.- Parameters:
newAmount
- the left child indent
-
getLeftChildIndent
public int getLeftChildIndent()Returns the left child indent.- Returns:
- the left child indent
-
setRightChildIndent
public void setRightChildIndent(int newAmount)Sets the right child indent.- Parameters:
newAmount
- the right child indent
-
getRightChildIndent
public int getRightChildIndent()Returns the right child indent.- Returns:
- the right child indent
-
setExpandedIcon
Sets the expanded icon.- Parameters:
newG
- the expanded icon
-
getExpandedIcon
Returns the expanded icon.- Returns:
- the expanded icon
-
setCollapsedIcon
Sets the collapsed icon.- Parameters:
newG
- the collapsed icon
-
getCollapsedIcon
Returns the collapsed icon.- Returns:
- the collapsed icon
-
setLargeModel
protected void setLargeModel(boolean largeModel)Sets thelargeModel
. Called when thelargeModel
property is changed in the drawn tree component.- Parameters:
largeModel
- the new value of thelargeModel
property
-
isLargeModel
protected boolean isLargeModel()Returnstrue
if large model is set.- Returns:
true
if large model is set
-
setRowHeight
protected void setRowHeight(int rowHeight)Sets the row height, this is forwarded to the treeState. Called when therowHeight
property is changed in the drawn tree component.- Parameters:
rowHeight
- the new value of therowHeight
property
-
getRowHeight
protected int getRowHeight()Returns the height of each row in the drawn tree component. If the returned value is less than or equal to 0 the height for each row is determined by the renderer.- Returns:
- the height of each row, in pixels
-
setCellRenderer
Sets theTreeCellRenderer
totcr
. This invokesupdateRenderer
. Called when thecellRenderer
property is changed in the drawn tree component.- Parameters:
tcr
- the new value of thecellRenderer
property
-
getCellRenderer
Returns the current instance of theTreeCellRenderer
that is rendering each cell.- Returns:
- the
TreeCellRenderer
instance
-
setModel
Sets theTreeModel
.- Parameters:
model
- the new value
-
getModel
Returns the tree model.- Returns:
- the tree model
-
setRootVisible
protected void setRootVisible(boolean newValue)Sets the root to being visible. Called when therootVisible
property is changed in the drawn tree component.- Parameters:
newValue
- the new value of therootVisible
property
-
isRootVisible
protected boolean isRootVisible()Returns whether the root node of the drawn tree component should be displayed.- Returns:
true
if the root node of the tree is displayed
-
setShowsRootHandles
protected void setShowsRootHandles(boolean newValue)Determines whether the node handles are to be displayed. Called when theshowsRootHandles
property is changed in the drawn tree component.- Parameters:
newValue
- the new value of theshowsRootHandles
property
-
getShowsRootHandles
protected boolean getShowsRootHandles()Returnstrue
if the root handles are to be displayed.- Returns:
true
if the root handles are to be displayed
-
setCellEditor
Sets the cell editor. Called when thecellEditor
property is changed in the drawn tree component.- Parameters:
editor
- the new value of thecellEditor
property
-
getCellEditor
Returns the editor used to edit entries in the drawn tree component, ornull
if the tree cannot be edited.- Returns:
- the
TreeCellEditor
instance, ornull
-
setEditable
protected void setEditable(boolean newValue)Configures the receiver to allow, or not allow, editing. Called when theeditable
property is changed in the drawn tree component.- Parameters:
newValue
- the new value of theeditable
property
-
isEditable
protected boolean isEditable()Returns whether the drawn tree component should be enabled for editing.- Returns:
true
if the tree is editable
-
setSelectionModel
Resets the selection model. The appropriate listener are installed on the model. Called when theselectionModel
property is changed in the drawn tree component.- Parameters:
newLSM
- the new value of theselectionModel
property
-
getSelectionModel
Returns the current instance of theTreeSelectionModel
which is the model for selections.- Returns:
- the
TreeSelectionModel
instance
-
getPathBounds
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.- Specified by:
getPathBounds
in classTreeUI
- Parameters:
tree
- theJTree
forpath
path
- theTreePath
identifying the node- Returns:
- the
Rectangle
enclosing the label portion that the last item in path will be drawn into,null
if any component in path is currently valid.
-
getPathForRow
Returns the path for passed in row. If row is not visible null is returned.- Specified by:
getPathForRow
in classTreeUI
- Parameters:
tree
- aJTree
objectrow
- an integer specifying a row- Returns:
- the
path
forrow
ornull
ifrow
is not visible
-
getRowForPath
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.- Specified by:
getRowForPath
in classTreeUI
- Parameters:
tree
- theJTree
forpath
path
- theTreePath
object to look in- Returns:
- an integer specifying the row at which the last item
identified is visible, -1 if any of the elements in
path
are not currently visible
-
getRowCount
Returns the number of rows that are being displayed.- Specified by:
getRowCount
in classTreeUI
- Parameters:
tree
- theJTree
for which to count rows- Returns:
- an integer specifying the number of row being displayed
-
getClosestPathForLocation
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.- Specified by:
getClosestPathForLocation
in classTreeUI
- Parameters:
tree
- aJTree
objectx
- an integer giving the number of pixels horizontally from the left edge of the display areay
- an integer giving the number of pixels vertically from the top of the display area, minus any top margin- Returns:
- the
TreePath
node closest tox,y
ornull
if there is nothing currently visible
-
isEditing
Returns true if the tree is being edited. The item that is being edited can be returned by getEditingPath(). -
stopEditing
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.- Specified by:
stopEditing
in classTreeUI
- Parameters:
tree
- aJTree
object- Returns:
- true if the editor allows the editing session to stop
-
cancelEditing
Cancels the current editing session.- Specified by:
cancelEditing
in classTreeUI
- Parameters:
tree
- aJTree
object
-
startEditingAtPath
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.- Specified by:
startEditingAtPath
in classTreeUI
- Parameters:
tree
- theJTree
being editedpath
- theTreePath
to be edited
-
getEditingPath
-