Class TLcdLayerTree

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
Direct Known Subclasses:
TLcdGXYLayerTree

public class TLcdLayerTree extends JTree

JTree, set up to render the layers tree structure of a view. The assumptions this layer tree makes, that are not made by a standard JTree, are that objects present in the tree model are:

  • Unique, they are only used once in the tree model
  • Never change, e.g. if the tree model is reorganized, it is ok to look at the object instances to know what went where.

Note that these assumptions hold when using TLcdLayerTreeModel or TLcdFlatListTreeModel.

For performance reasons, it also sets large model to true, which means all rows should have equal height. If a cell renderer is used that has different row heights for different values, this property must be set to false. This assumption is ok in combination with for example a TLcdLayerTreeNodeCellRenderer.

When the used TreeCellRenderer for this tree contains an AbstractButton mouse clicks on this button will be passed on to the button after the TreeCellRenderer#getTreeCellRendererComponent has been called.

Since:
9.0
See Also:
  • Constructor Details

    • TLcdLayerTree

      public TLcdLayerTree()

      Create a new tree with the default JTree cell renderer and with the default JTree model.

    • TLcdLayerTree

      public TLcdLayerTree(ILcdTreeLayered aView)

      Create a new tree set up to render the layer tree structure of the ILcdTreeLayered aView. A TreeModel, representing the hierarchical layer structure of the view, and an adjusted TreeCellRenderer are set on the tree.

      Parameters:
      aView - the ILcdTreeLayered containing all the layers
      See Also:
  • Method Details

    • createTreeModelListener

      protected TreeModelListener createTreeModelListener()
      Overrides:
      createTreeModelListener in class JTree
    • storeSelectedNodes

      public List<Object> storeSelectedNodes()
      Returns a list containing all the nodes which are currently selected in the tree. When no objects are selected, this method returns an empty list
      Returns:
      a list containing all the nodes which are currently selected in the tree
      See Also:
    • restoreSelectedNodes

      public void restoreSelectedNodes(List<Object> aOldSelection)
      Sets the selection of the tree to the tree model objects in aOldSelection if those objects are a part of this tree. When no nodes should be selected, an empty list can be passed
      Parameters:
      aOldSelection - a list containing the nodes which should be selected, or an empty list when no nodes should be selected
      See Also:
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JTree
    • setLargeModel

      public void setLargeModel(boolean newValue)
      This method of JTree specifies if a large tree model can be expected, and adapts its caching strategy accordingly. If set to true, this TLcdLayerTree assumes that the row height of all rows is identical, and automatically sets it based on the height of the cell renderer of a single model value.
      Overrides:
      setLargeModel in class JTree
      Parameters:
      newValue - true to suggest a large model, false otherwise.
    • setCellRenderer

      public void setCellRenderer(TreeCellRenderer x)
      Overrides:
      setCellRenderer in class JTree
    • getPreferredScrollableViewportSize

      public Dimension getPreferredScrollableViewportSize()
      Specified by:
      getPreferredScrollableViewportSize in interface Scrollable
      Overrides:
      getPreferredScrollableViewportSize in class JTree
    • getMinimumVisibleRowCount

      public int getMinimumVisibleRowCount()
      Returns the minimum visible row count, see setMinimumVisibleRowCount(int).
      Returns:
      the minimum visible row count.
    • setMinimumVisibleRowCount

      public void setMinimumVisibleRowCount(int aMinimumVisibleRowCount)

      Sets the minimum visible row count, which affects the preferred size of this JTree when in a scroll pane. This behavior is especially useful when overlaying a JTree on a map, where you want to avoid unused empty space but allow it to grow when needed.

      When added to a scroll pane, a JTree defines its preferred size based on JTree.getVisibleRowCount(). This sub-class defines an additional minimum visible row count. The preferred size is then kept between minimum and normal row count, based on the amount of data currently being displayed. Suppose a minimum row count of 5 and a normal row count of 10. If the tree currently shows 2 rows, space is made available for 5. If it is displaying 7 rows, space for 7 rows is available. If it is showing 50 rows, space is available for 10 rows. If you make the minimum and regular visible row count equal, you get the default JTree behavior.

      Note: this property is currently only respected when using fixed row heights (the default setting for this class).

      Parameters:
      aMinimumVisibleRowCount - The minimum visible row count.
    • hasBeenExpanded

      public boolean hasBeenExpanded(TreePath path)
      Overrides:
      hasBeenExpanded in class JTree