javax.swing.tree

Class VariableHeightLayoutCache

public class VariableHeightLayoutCache extends AbstractLayoutCache

The fixed height tree layout. This class requires the NodeDimensions to be set and ignores the row height property.

UNKNOWN: the methods, of this class, returning TreePath, actually returns the derived class GnuPath that provides additional information for optimized painting. See the GnuPath code for details.

Constructor Summary
VariableHeightLayoutCache()
Creates the unitialised instance.
Method Summary
RectanglegetBounds(TreePath path, Rectangle rect)
Get bounds for the given tree path.
booleangetExpandedState(TreePath path)
Return the expansion state of the given tree path.
TreePathgetPathClosestTo(int x, int y)
Get the path, closest to the given point.
TreePathgetPathForRow(int row)
Get the path, the last element of that is displayed in the given row.
intgetPreferredHeight()
Get the sum of heights for all rows.
intgetPreferredWidth(Rectangle value)
Get the maximal width.
intgetRowCount()
Get the total number of rows in the tree.
intgetRowForPath(TreePath path)
Get the row, displaying the last node of the given path.
intgetVisibleChildCount(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.
voidinvalidatePathBounds(TreePath path)
Discard the bound information for the given path.
voidinvalidateSizes()
Mark all cached information as invalid.
booleanisExpanded(TreePath path)
Get the expanded state for the given tree path.
voidsetExpandedState(TreePath path, boolean isExpanded)
Set the expanded state of the given path.
voidsetModel(TreeModel newModel)
Set the tree model that will provide the data.
voidsetNodeDimensions(NodeDimensions dim)
Sets the node dimensions and invalidates the cached layout.
voidsetRootVisible(boolean visible)
Inform the instance if the tree root node is visible.
voidsetRowHeight(int height)
Sets the row height and marks the layout as invalid.
voidtreeNodesChanged(TreeModelEvent event)
The listener method, called when the tree nodes are changed.
voidtreeNodesInserted(TreeModelEvent event)
The listener method, called when the tree nodes are inserted.
voidtreeNodesRemoved(TreeModelEvent event)
The listener method, called when the tree nodes are removed.
voidtreeStructureChanged(TreeModelEvent event)
Called when the tree structure has been changed.

Constructor Detail

VariableHeightLayoutCache

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

Method Detail

getBounds

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

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.

getExpandedState

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

Parameters: path the path being checked

Returns: true if the last node of the path is expanded, false otherwise.

getPathClosestTo

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

Parameters: x the point x coordinate y the point y coordinate

Returns: the tree path, closest to the the given point

getPathForRow

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

Parameters: row the row

Returns: TreePath the path

getPreferredHeight

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

getPreferredWidth

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

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).

Returns: int the number of the displayed rows.

getRowForPath

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

Parameters: path the path

Returns: int the row number or -1 if the end of the path is not visible.

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.

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.

Parameters: parentPath the parent path

Returns: the enumeration over pathes

invalidatePathBounds

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

Parameters: path the path, for that the bound information must be recomputed.

invalidateSizes

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

isExpanded

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

Returns: true if the given path is expanded, false otherwise.

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.

Parameters: path the tree path, for that the state is being set. isExpanded the expanded state of the given path.

setModel

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

setNodeDimensions

public void setNodeDimensions(NodeDimensions dim)
Sets the node dimensions and invalidates the cached layout.

Parameters: dim the dimensions to set

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.

Parameters: visible true if the tree root node is visible, false otherwise.

setRowHeight

public void setRowHeight(int height)
Sets the row height and marks the layout as invalid.

Parameters: height the row height to set

treeNodesChanged

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

Parameters: event the change event

treeNodesInserted

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

Parameters: event the change event

treeNodesRemoved

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

Parameters: event the change event

treeStructureChanged

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

Parameters: event the change event