Module java.desktop

Class BasicTreeUI

Direct Known Subclasses:
MetalTreeUI, SynthTreeUI

public class BasicTreeUI extends TreeUI
The basic L&F for a hierarchical data structure.
  • Field Details

    • collapsedIcon

      protected transient Icon collapsedIcon
      The collapsed icon.
    • expandedIcon

      protected transient Icon expandedIcon
      The expanded icon.
    • leftChildIndent

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

      protected int rightChildIndent
      Distance to add to leftChildIndent to determine where cell contents will be drawn.
    • totalChildIndent

      protected int totalChildIndent
      Total distance that will be indented. The sum of leftChildIndent and rightChildIndent.
    • preferredMinSize

      protected Dimension preferredMinSize
      Minimum preferred size.
    • lastSelectedRow

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

      protected JTree tree
      Component that we're going to be drawing into.
    • currentCellRenderer

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

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

      protected transient TreeCellEditor cellEditor
      Editor for the tree.
    • createdCellEditor

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

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

      protected CellRendererPane rendererPane
      Used to paint the TreeCellRenderer.
    • preferredSize

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

      protected boolean validCachedPreferredSize
      Is the preferredSize valid?
    • treeState

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

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

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

      protected AbstractLayoutCache.NodeDimensions nodeDimensions
      Reponsible for telling the TreeState the size needed for a node.
    • treeModel

      protected TreeModel treeModel
      Used to determine what to display.
    • treeSelectionModel

      protected TreeSelectionModel treeSelectionModel
      Model maintaining the selection.
    • depthOffset

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

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

      protected TreePath editingPath
      Path that is being edited.
    • editingRow

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

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

    • BasicTreeUI

      public BasicTreeUI()
      Constructs a new instance of BasicTreeUI.
  • Method Details

    • createUI

      public static ComponentUI createUI(JComponent x)
      Constructs a new instance of BasicTreeUI.
      Parameters:
      x - a component
      Returns:
      a new instance of BasicTreeUI
    • getHashColor

      protected Color getHashColor()
      Returns the hash color.
      Returns:
      the hash color
    • setHashColor

      protected void setHashColor(Color color)
      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

      public void setExpandedIcon(Icon newG)
      Sets the expanded icon.
      Parameters:
      newG - the expanded icon
    • getExpandedIcon

      public Icon getExpandedIcon()
      Returns the expanded icon.
      Returns:
      the expanded icon
    • setCollapsedIcon

      public void setCollapsedIcon(Icon newG)
      Sets the collapsed icon.
      Parameters:
      newG - the collapsed icon
    • getCollapsedIcon

      public Icon getCollapsedIcon()
      Returns the collapsed icon.
      Returns:
      the collapsed icon
    • setLargeModel

      protected void setLargeModel(boolean largeModel)
      Sets the largeModel. Called when the largeModel property is changed in the drawn tree component.
      Parameters:
      largeModel - the new value of the largeModel property
    • isLargeModel

      protected boolean isLargeModel()
      Returns true 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 the rowHeight property is changed in the drawn tree component.
      Parameters:
      rowHeight - the new value of the rowHeight 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

      protected void setCellRenderer(TreeCellRenderer tcr)
      Sets the TreeCellRenderer to tcr. This invokes updateRenderer. Called when the cellRenderer property is changed in the drawn tree component.
      Parameters:
      tcr - the new value of the cellRenderer property
    • getCellRenderer

      protected TreeCellRenderer getCellRenderer()
      Returns the current instance of the TreeCellRenderer that is rendering each cell.
      Returns:
      the TreeCellRenderer instance
    • setModel

      protected void setModel(TreeModel model)
      Sets the TreeModel.
      Parameters:
      model - the new value
    • getModel

      protected TreeModel getModel()
      Returns the tree model.
      Returns:
      the tree model
    • setRootVisible

      protected void setRootVisible(boolean newValue)
      Sets the root to being visible. Called when the rootVisible property is changed in the drawn tree component.
      Parameters:
      newValue - the new value of the rootVisible 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 the showsRootHandles property is changed in the drawn tree component.
      Parameters:
      newValue - the new value of the showsRootHandles property
    • getShowsRootHandles

      protected boolean getShowsRootHandles()
      Returns true if the root handles are to be displayed.
      Returns:
      true if the root handles are to be displayed
    • setCellEditor

      protected void setCellEditor(TreeCellEditor editor)
      Sets the cell editor. Called when the cellEditor property is changed in the drawn tree component.
      Parameters:
      editor - the new value of the cellEditor property
    • getCellEditor

      protected TreeCellEditor getCellEditor()
      Returns the editor used to edit entries in the drawn tree component, or null if the tree cannot be edited.
      Returns:
      the TreeCellEditor instance, or null
    • setEditable

      protected void setEditable(boolean newValue)
      Configures the receiver to allow, or not allow, editing. Called when the editable property is changed in the drawn tree component.
      Parameters:
      newValue - the new value of the editable property
    • isEditable

      protected boolean isEditable()
      Returns whether the drawn tree component should be enabled for editing.
      Returns:
      true if the tree is editable
    • setSelectionModel

      protected void setSelectionModel(TreeSelectionModel newLSM)
      Resets the selection model. The appropriate listener are installed on the model. Called when the selectionModel property is changed in the drawn tree component.
      Parameters:
      newLSM - the new value of the selectionModel property
    • getSelectionModel

      protected TreeSelectionModel getSelectionModel()
      Returns the current instance of the TreeSelectionModel which is the model for selections.
      Returns:
      the TreeSelectionModel instance
    • getPathBounds

      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.
      Specified by:
      getPathBounds in class TreeUI
      Parameters:
      tree - the JTree for path
      path - the TreePath 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

      public TreePath getPathForRow(JTree tree, int row)
      Returns the path for passed in row. If row is not visible null is returned.
      Specified by:
      getPathForRow in class TreeUI
      Parameters:
      tree - a JTree object
      row - an integer specifying a row
      Returns:
      the path for row or null if row is not visible
    • getRowForPath

      public int getRowForPath(JTree tree, TreePath path)
      Returns the row that the last item identified in path is visible at. Will return -1 if any of the elements in path are not currently visible.
      Specified by:
      getRowForPath in class TreeUI
      Parameters:
      tree - the JTree for path
      path - the TreePath 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

      public int getRowCount(JTree tree)
      Returns the number of rows that are being displayed.
      Specified by:
      getRowCount in class TreeUI
      Parameters:
      tree - the JTree for which to count rows
      Returns:
      an integer specifying the number of row being displayed
    • getClosestPathForLocation

      public TreePath getClosestPathForLocation(JTree tree, int x, int y)
      Returns the path to the node that is closest to x,y. If there is nothing currently visible this will return null, otherwise it'll always return a valid path. If you need to test if the returned object is exactly at x, y you should get the bounds for the returned path and test x, y against that.
      Specified by:
      getClosestPathForLocation in class TreeUI
      Parameters:
      tree - a JTree object
      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 TreePath node closest to x,y or null if there is nothing currently visible
    • isEditing

      public boolean isEditing(JTree tree)
      Returns true if the tree is being edited. The item that is being edited can be returned by getEditingPath().
      Specified by:
      isEditing in class TreeUI
      Parameters:
      tree - a JTree object
      Returns:
      true if tree is being edited
    • stopEditing

      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.
      Specified by:
      stopEditing in class TreeUI
      Parameters:
      tree - a JTree object
      Returns:
      true if the editor allows the editing session to stop
    • cancelEditing

      public void cancelEditing(JTree tree)
      Cancels the current editing session.
      Specified by:
      cancelEditing in class TreeUI
      Parameters:
      tree - a JTree object
    • startEditingAtPath

      public void startEditingAtPath(JTree tree, TreePath path)
      Selects the last item in path and tries to edit it. Editing will fail if the CellEditor won't allow it for the selected item.
      Specified by:
      startEditingAtPath in class TreeUI
      Parameters:
      tree - the JTree being edited
      path - the TreePath to be edited
    • getEditingPath

      public TreePath getEditingPath(