java.lang.Object
javax.swing.tree.AbstractLayoutCache
javax.swing.tree.VariableHeightLayoutCache
public class VariableHeightLayoutCache
extends AbstractLayoutCache
VariableHeightLayoutCache()
boolean
getExpandedState(TreePath path)
TreePath
getPathClosestTo(int x, int y)
TreePath
getPathForRow(int row)
int
getPreferredHeight()
int
getPreferredWidth(Rectangle value)
int
getRowCount()
int
getRowForPath(TreePath path)
int
getVisibleChildCount(TreePath path)
Enumeration 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.
void
setExpandedState(TreePath path, boolean isExpanded)
- Set the expanded state of the given path.
void
setNodeDimensions(AbstractLayoutCache.NodeDimensions dim)
- Sets the node dimensions and invalidates the cached layout.
void
setRootVisible(boolean visible)
- Inform the instance if the tree root node is visible.
void
setRowHeight(int height)
- Sets the row height and marks the layout as invalid.
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.AbstractLayoutCache
getBounds
, getExpandedState
, getModel
, getNodeDimensions
, getNodeDimensions
, getPathClosestTo
, getPathForRow
, getPreferredHeight
, getPreferredWidth
, getRowCount
, getRowForPath
, getRowHeight
, getRowsForPaths
, getSelectionModel
, getVisibleChildCount
, getVisiblePathsFrom
, invalidatePathBounds
, invalidateSizes
, isExpanded
, isFixedRowHeight
, isRootVisible
, setExpandedState
, setModel
, setNodeDimensions
, setRootVisible
, setRowHeight
, setSelectionModel
, treeNodesChanged
, treeNodesInserted
, treeNodesRemoved
, treeStructureChanged
-
Methods inherited from class java.lang.Object
Constructor Details
VariableHeightLayoutCache
public VariableHeightLayoutCache()
Creates the unitialised instance. Before using the class, the row height
must be set with the setRowHeight(int)
and the model must be set
with setModel(TreeModel)
. The node dimensions may not be set.
Method Details
getBounds
public Rectangle getBounds(TreePath path,
Rectangle rect)
Get bounds for the given tree path.
- Overrides:
- getBounds in interface AbstractLayoutCache
- Parameters:
path
- the tree pathrect
- 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
setExpandedState(TreePath,boolean)
- Overrides:
- getExpandedState in interface AbstractLayoutCache
- 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.
- Overrides:
- getPathClosestTo in interface AbstractLayoutCache
- Parameters:
x
- the point x coordinatey
- 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.
- Overrides:
- getPathForRow in interface AbstractLayoutCache
- Parameters:
row
- the row
- Returns:
- TreePath the path
getPreferredHeight
public int getPreferredHeight()
Get the sum of heights for all rows.
- Overrides:
- getPreferredHeight in interface AbstractLayoutCache
getPreferredWidth
public int getPreferredWidth(Rectangle value)
Get the maximal width.
- Overrides:
- getPreferredWidth in interface AbstractLayoutCache
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 interface AbstractLayoutCache
- 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.
- Overrides:
- getRowForPath in interface AbstractLayoutCache
- 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.
- Overrides:
- getVisibleChildCount in interface AbstractLayoutCache
- Parameters:
path
- the tree path
- Returns:
- int the number of the visible childs (for row).
getVisiblePathsFrom
public Enumeration getVisiblePathsFrom(TreePath parentPath) Get the enumeration over all visible pathes that start from the given
parent path.
- Overrides:
- getVisiblePathsFrom in interface AbstractLayoutCache
- Parameters:
parentPath
- the parent path
- Returns:
- the enumeration over pathes
invalidatePathBounds
public void invalidatePathBounds(TreePath path)
Discard the bound information for the given path.
- Overrides:
- invalidatePathBounds in interface AbstractLayoutCache
- 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 interface AbstractLayoutCache
isExpanded
public boolean isExpanded(TreePath path)
Get the expanded state for the given tree path.
- Overrides:
- isExpanded in interface AbstractLayoutCache
- 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.
- Overrides:
- setExpandedState in interface AbstractLayoutCache
- 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.
- Overrides:
- setModel in interface AbstractLayoutCache
setNodeDimensions
public void setNodeDimensions(AbstractLayoutCache.NodeDimensions dim)
Sets the node dimensions and invalidates the cached layout.
- Overrides:
- setNodeDimensions in interface AbstractLayoutCache
- 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.
- Overrides:
- setRootVisible in interface AbstractLayoutCache
- 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.
- Overrides:
- setRowHeight in interface AbstractLayoutCache
- Parameters:
height
- the row height to set
treeNodesChanged
public void treeNodesChanged(TreeModelEvent event)
The listener method, called when the tree nodes are changed.
- Overrides:
- treeNodesChanged in interface AbstractLayoutCache
- Parameters:
event
- the change event
treeNodesInserted
public void treeNodesInserted(TreeModelEvent event)
The listener method, called when the tree nodes are inserted.
- Overrides:
- treeNodesInserted in interface AbstractLayoutCache
- Parameters:
event
- the change event
treeNodesRemoved
public void treeNodesRemoved(TreeModelEvent event)
The listener method, called when the tree nodes are removed.
- Overrides:
- treeNodesRemoved in interface AbstractLayoutCache
- Parameters:
event
- the change event
treeStructureChanged
public void treeStructureChanged(TreeModelEvent event)
Called when the tree structure has been changed.
- Overrides:
- treeStructureChanged in interface AbstractLayoutCache
- Parameters:
event
- the change event
VariableHeightLayoutCache.java --
Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
GNU Classpath (0.95)