javax.swing.tree
Class FixedHeightLayoutCache

java.lang.Object
  extended by javax.swing.tree.AbstractLayoutCache
      extended by javax.swing.tree.VariableHeightLayoutCache
          extended by javax.swing.tree.FixedHeightLayoutCache
All Implemented Interfaces:
RowMapper

public class FixedHeightLayoutCache
extends VariableHeightLayoutCache

The fixed height tree layout. This class assumes that all cells in the tree have the same fixed height. This may be not the case, for instance, if leaves and branches have different height, of if the tree rows may have arbitrary variable height. This class will also work if the NodeDimensions are not set.


Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.tree.AbstractLayoutCache
AbstractLayoutCache.NodeDimensions
 
Field Summary
 
Fields inherited from class javax.swing.tree.AbstractLayoutCache
nodeDimensions, rootVisible, rowHeight, treeModel, treeSelectionModel
 
Constructor Summary
FixedHeightLayoutCache()
          Creates the unitialised instance.
 
Method Summary
 Rectangle getBounds(TreePath path, Rectangle rect)
          Get bounds for the given tree path.
 boolean getExpandedState(TreePath path)
          Return the expansion state of the given tree path.
 TreePath getPathClosestTo(int x, int y)
          Get the path, closest to the given point.
 TreePath getPathForRow(int row)
          Get the path, the last element of that is displayed in the given row.
 int getPreferredHeight()
          Get the sum of heights for all rows.
 int getPreferredWidth(Rectangle value)
          Get the maximal width.
 int getRowCount()
          Get the total number of rows in the tree.
 int getRowForPath(TreePath path)
          Get the row, displaying the last node of the given path.
 int getVisibleChildCount(TreePath path)
          Get the number of the visible childs for the given tree path.
 Enumeration<TreePath> getVisiblePathsFrom(TreePath parentPath)
          Get the enumeration over all visible pathes that start from the given parent path.
 void invalidatePathBounds(TreePath path)
          Discard the bound information for the given path.
 void invalidateSizes()
          Mark all cached information as invalid.
 boolean isExpanded(TreePath path)
          Get the expanded state for the given tree path.
protected  boolean isFixedRowHeight()
          Returns true if this layout supposes that all rows have the fixed height.
 void setExpandedState(TreePath path, boolean isExpanded)
          Set the expanded state of the given path.
 void setModel(TreeModel newModel)
          Set the tree model that will provide the data.
 void setRootVisible(boolean visible)
          Inform the instance if the tree root node is visible.
 void treeNodesChanged(TreeModelEvent event)
          The listener method, called when the tree nodes are changed.
 void treeNodesInserted(TreeModelEvent event)
          The listener method, called when the tree nodes are inserted.
 void treeNodesRemoved(TreeModelEvent event)
          The listener method, called when the tree nodes are removed.
 void treeStructureChanged(TreeModelEvent event)
          Called when the tree structure has been changed.
 
Methods inherited from class javax.swing.tree.VariableHeightLayoutCache
setNodeDimensions, setRowHeight
 
Methods inherited from class javax.swing.tree.AbstractLayoutCache
getModel, getNodeDimensions, getNodeDimensions, getRowHeight, getRowsForPaths, getSelectionModel, isRootVisible, setSelectionModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedHeightLayoutCache

public FixedHeightLayoutCache()
Creates the unitialised instance. Before using the class, the row height must be set with the VariableHeightLayoutCache.setRowHeight(int) and the model must be set with setModel(TreeModel). The node dimensions may not be set.

Method Detail

getRowCount

public int getRowCount()
Get the total number of rows in the tree. Every displayed node occupies the single row. The root node row is included if the root node is set as visible (false by default).

Overrides:
getRowCount in class VariableHeightLayoutCache
Returns:
int the number of the displayed rows.

invalidatePathBounds

public void invalidatePathBounds(TreePath path)
Discard the bound information for the given path.

Overrides:
invalidatePathBounds in class VariableHeightLayoutCache
Parameters:
path - the path, for that the bound information must be recomputed.

invalidateSizes

public void invalidateSizes()
Mark all cached information as invalid.

Overrides:
invalidateSizes in class VariableHeightLayoutCache

setExpandedState

public void setExpandedState(TreePath path,
                             boolean isExpanded)
Set the expanded state of the given path. The expansion states must be always updated when expanding and colapsing the tree nodes. Otherwise other methods will not work correctly after the nodes are collapsed or expanded.

Overrides:
setExpandedState in class VariableHeightLayoutCache
Parameters:
path - the tree path, for that the state is being set.
isExpanded - the expanded state of the given path.

isExpanded

public boolean isExpanded(TreePath path)
Get the expanded state for the given tree path.

Overrides:
isExpanded in class VariableHeightLayoutCache
Parameters:
path - TODO
Returns:
true if the given path is expanded, false otherwise.

getBounds

public Rectangle getBounds(TreePath path,
                           Rectangle rect)
Get bounds for the given tree path.

Overrides:
getBounds in class VariableHeightLayoutCache
Parameters:
path - the tree path
rect - the rectangle that will be reused to return the result.
Returns:
Rectangle the bounds of the last line, defined by the given path.

getPathForRow

public TreePath getPathForRow(int row)
Get the path, the last element of that is displayed in the given row.

Overrides:
getPathForRow in class VariableHeightLayoutCache
Parameters:
row - the row
Returns:
TreePath the path

getRowForPath

public int getRowForPath(TreePath path)
Get the row, displaying the last node of the given path.

Overrides:
getRowForPath in class VariableHeightLayoutCache
Parameters:
path - the path
Returns:
int the row number or -1 if the end of the path is not visible.

getPathClosestTo

public TreePath getPathClosestTo(int x,
                                 int y)
Get the path, closest to the given point.

Overrides:
getPathClosestTo in class VariableHeightLayoutCache
Parameters:
x - the point x coordinate
y - the point y coordinate
Returns:
the tree path, closest to the the given point

getVisibleChildCount

public int getVisibleChildCount(TreePath path)
Get the number of the visible childs for the given tree path. If the node is not expanded, 0 is returned. Otherwise, the number of children is obtained from the model as the number of children for the last path component.

Overrides:
getVisibleChildCount in class VariableHeightLayoutCache
Parameters:
path - the tree path
Returns:
int the number of the visible childs (for row).

getVisiblePathsFrom

public Enumeration<TreePath> getVisiblePathsFrom(TreePath parentPath)
Get the enumeration over all visible pathes that start from the given parent path.

Overrides:
getVisiblePathsFrom in class VariableHeightLayoutCache
Parameters:
parentPath - the parent path
Returns:
the enumeration over pathes

getExpandedState

public boolean getExpandedState(TreePath path)
Return the expansion state of the given tree path. The expansion state must be previously set with the setExpandedState(TreePath, boolean)

Overrides:
getExpandedState in class VariableHeightLayoutCache
Parameters:
path - the path being checked
Returns:
true if the last node of the path is expanded, false otherwise.

treeNodesChanged

public void treeNodesChanged(TreeModelEvent event)
The listener method, called when the tree nodes are changed.

Overrides:
treeNodesChanged in class VariableHeightLayoutCache
Parameters:
event - the change event

treeNodesInserted

public void treeNodesInserted(TreeModelEvent event)
The listener method, called when the tree nodes are inserted.

Overrides:
treeNodesInserted in class VariableHeightLayoutCache
Parameters:
event - the change event

treeNodesRemoved

public void treeNodesRemoved(TreeModelEvent event)
The listener method, called when the tree nodes are removed.

Overrides:
treeNodesRemoved in class VariableHeightLayoutCache
Parameters:
event - the change event

treeStructureChanged

public void treeStructureChanged(TreeModelEvent event)
Called when the tree structure has been changed.

Overrides:
treeStructureChanged in class VariableHeightLayoutCache
Parameters:
event - the change event

setModel

public void setModel(TreeModel newModel)
Set the tree model that will provide the data.

Overrides:
setModel in class VariableHeightLayoutCache
Parameters:
newModel - the model

setRootVisible

public void setRootVisible(boolean visible)
Inform the instance if the tree root node is visible. If this method is not called, it is assumed that the tree root node is not visible.

Overrides:
setRootVisible in class VariableHeightLayoutCache
Parameters:
visible - true if the tree root node is visible, false otherwise.

getPreferredHeight

public int getPreferredHeight()
Get the sum of heights for all rows.

Overrides:
getPreferredHeight in class VariableHeightLayoutCache

getPreferredWidth

public int getPreferredWidth(Rectangle value)
Get the maximal width.

Overrides:
getPreferredWidth in class VariableHeightLayoutCache
Parameters:
value - the rectangle that is used during the method work

isFixedRowHeight

protected boolean isFixedRowHeight()
Returns true if this layout supposes that all rows have the fixed height.

Overrides:
isFixedRowHeight in class AbstractLayoutCache
Returns:
boolean true if all rows in the tree must have the fixed height (true by default).