< prev index next >
src/java.desktop/share/classes/javax/swing/tree/VariableHeightLayoutCache.java
Print this page
*** 42,52 ****
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans™
! * has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @author Rob Davis
* @author Ray Ryan
* @author Scott Violet
--- 42,52 ----
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans™
! * has been added to the {@code java.beans} package.
* Please see {@link java.beans.XMLEncoder}.
*
* @author Rob Davis
* @author Ray Ryan
* @author Scott Violet
*** 76,86 ****
* every time a size is needed.
*/
private Rectangle boundsBuffer;
/**
! * Maps from <code>TreePath</code> to a <code>TreeStateNode</code>.
*/
private Hashtable<TreePath, TreeStateNode> treePathMapping;
/**
* A stack of stacks.
--- 76,86 ----
* every time a size is needed.
*/
private Rectangle boundsBuffer;
/**
! * Maps from {@code TreePath} to a {@code TreeStateNode}.
*/
private Hashtable<TreePath, TreeStateNode> treePathMapping;
/**
* A stack of stacks.
*** 98,110 ****
boundsBuffer = new Rectangle();
treePathMapping = new Hashtable<TreePath, TreeStateNode>();
}
/**
! * Sets the <code>TreeModel</code> that will provide the data.
*
! * @param newModel the <code>TreeModel</code> that is to provide the data
* @beaninfo
* bound: true
* description: The TreeModel that will provide the data.
*/
public void setModel(TreeModel newModel) {
--- 98,110 ----
boundsBuffer = new Rectangle();
treePathMapping = new Hashtable<TreePath, TreeStateNode>();
}
/**
! * Sets the {@code TreeModel} that will provide the data.
*
! * @param newModel the {@code TreeModel} that is to provide the data
* @beaninfo
* bound: true
* description: The TreeModel that will provide the data.
*/
public void setModel(TreeModel newModel) {
*** 112,122 ****
rebuild(false);
}
/**
* Determines whether or not the root node from
! * the <code>TreeModel</code> is visible.
*
* @param rootVisible true if the root node of the tree is to be displayed
* @see #rootVisible
* @beaninfo
* bound: true
--- 112,122 ----
rebuild(false);
}
/**
* Determines whether or not the root node from
! * the {@code TreeModel} is visible.
*
* @param rootVisible true if the root node of the tree is to be displayed
* @see #rootVisible
* @beaninfo
* bound: true
*** 172,184 ****
invalidateSizes();
visibleNodesChanged();
}
/**
! * Marks the path <code>path</code> expanded state to
! * <code>isExpanded</code>.
! * @param path the <code>TreePath</code> of interest
* @param isExpanded true if the path should be expanded, otherwise false
*/
public void setExpandedState(TreePath path, boolean isExpanded) {
if(path != null) {
if(isExpanded)
--- 172,184 ----
invalidateSizes();
visibleNodesChanged();
}
/**
! * Marks the path {@code path} expanded state to
! * {@code isExpanded}.
! * @param path the {@code TreePath} of interest
* @param isExpanded true if the path should be expanded, otherwise false
*/
public void setExpandedState(TreePath path, boolean isExpanded) {
if(path != null) {
if(isExpanded)
*** 204,219 ****
return (node != null) ? (node.isVisible() && node.isExpanded()) :
false;
}
/**
! * Returns the <code>Rectangle</code> enclosing the label portion
! * into which the item identified by <code>path</code> will be drawn.
*
* @param path the path to be drawn
* @param placeIn the bounds of the enclosing rectangle
! * @return the bounds of the enclosing rectangle or <code>null</code>
* if the node could not be ascertained
*/
public Rectangle getBounds(TreePath path, Rectangle placeIn) {
TreeStateNode node = getNodeForPath(path, true, false);
--- 204,219 ----
return (node != null) ? (node.isVisible() && node.isExpanded()) :
false;
}
/**
! * Returns the {@code Rectangle} enclosing the label portion
! * into which the item identified by {@code path} will be drawn.
*
* @param path the path to be drawn
* @param placeIn the bounds of the enclosing rectangle
! * @return the bounds of the enclosing rectangle or {@code null}
* if the node could not be ascertained
*/
public Rectangle getBounds(TreePath path, Rectangle placeIn) {
TreeStateNode node = getNodeForPath(path, true, false);
*** 224,239 ****
}
return null;
}
/**
! * Returns the path for <code>row</code>. If <code>row</code>
! * is not visible, <code>null</code> is returned.
*
* @param row the location of interest
! * @return the path for <code>row</code>, or <code>null</code>
! * if <code>row</code> is not visible
*/
public TreePath getPathForRow(int row) {
if(row >= 0 && row < getRowCount()) {
return getNode(row).getTreePath();
}
--- 224,239 ----
}
return null;
}
/**
! * Returns the path for {@code row}. If {@code row}
! * is not visible, {@code null} is returned.
*
* @param row the location of interest
! * @return the path for {@code row}, or {@code null}
! * if {@code row} is not visible
*/
public TreePath getPathForRow(int row) {
if(row >= 0 && row < getRowCount()) {
return getNode(row).getTreePath();
}
*** 243,253 ****
/**
* Returns the row where the last item identified in path is visible.
* Will return -1 if any of the elements in path are not
* currently visible.
*
! * @param path the <code>TreePath</code> of interest
* @return the row where the last item in path is visible
*/
public int getRowForPath(TreePath path) {
if(path == null)
return -1;
--- 243,253 ----
/**
* Returns the row where the last item identified in path is visible.
* Will return -1 if any of the elements in path are not
* currently visible.
*
! * @param path the {@code TreePath} of interest
* @return the row where the last item in path is visible
*/
public int getRowForPath(TreePath path) {
if(path == null)
return -1;
*** 266,279 ****
public int getRowCount() {
return visibleNodes.size();
}
/**
! * Instructs the <code>LayoutCache</code> that the bounds for
! * <code>path</code> are invalid, and need to be updated.
*
! * @param path the <code>TreePath</code> which is now invalid
*/
public void invalidatePathBounds(TreePath path) {
TreeStateNode node = getNodeForPath(path, true, false);
if(node != null) {
--- 266,279 ----
public int getRowCount() {
return visibleNodes.size();
}
/**
! * Instructs the {@code LayoutCache} that the bounds for
! * {@code path} are invalid, and need to be updated.
*
! * @param path the {@code TreePath} which is now invalid
*/
public void invalidatePathBounds(TreePath path) {
TreeStateNode node = getNodeForPath(path, true, false);
if(node != null) {
*** 299,309 ****
return 0;
}
/**
* Returns the preferred width and height for the region in
! * <code>visibleRegion</code>.
*
* @param bounds the region being queried
*/
public int getPreferredWidth(Rectangle bounds) {
if(updateNodeSizes)
--- 299,309 ----
return 0;
}
/**
* Returns the preferred width and height for the region in
! * {@code visibleRegion}.
*
* @param bounds the region being queried
*/
public int getPreferredWidth(Rectangle bounds) {
if(updateNodeSizes)
*** 312,322 ****
return getMaxNodeWidth();
}
/**
* Returns the path to the node that is closest to x,y. If
! * there is nothing currently visible this will return <code>null</code>,
* otherwise it will 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.
*
--- 312,322 ----
return getMaxNodeWidth();
}
/**
* Returns the path to the node that is closest to x,y. If
! * there is nothing currently visible this will return {@code null},
* otherwise it will 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.
*
*** 335,350 ****
return getNode(row).getTreePath();
}
/**
! * Returns an <code>Enumerator</code> that increments over the visible paths
* starting at the passed in location. The ordering of the enumeration
* is based on how the paths are displayed.
*
! * @param path the location in the <code>TreePath</code> to start
! * @return an <code>Enumerator</code> that increments over the visible
* paths
*/
public Enumeration<TreePath> getVisiblePathsFrom(TreePath path) {
TreeStateNode node = getNodeForPath(path, true, false);
--- 335,350 ----
return getNode(row).getTreePath();
}
/**
! * Returns an {@code Enumerator} that increments over the visible paths
* starting at the passed in location. The ordering of the enumeration
* is based on how the paths are displayed.
*
! * @param path the location in the {@code TreePath} to start
! * @return an {@code Enumerator} that increments over the visible
* paths
*/
public Enumeration<TreePath> getVisiblePathsFrom(TreePath path) {
TreeStateNode node = getNodeForPath(path, true, false);
*** 353,373 ****
}
return null;
}
/**
! * Returns the number of visible children for <code>path</code>.
! * @return the number of visible children for <code>path</code>
*/
public int getVisibleChildCount(TreePath path) {
TreeStateNode node = getNodeForPath(path, true, false);
return (node != null) ? node.getVisibleChildCount() : 0;
}
/**
! * Informs the <code>TreeState</code> that it needs to recalculate
* all the sizes it is referencing.
*/
public void invalidateSizes() {
if(root != null)
root.deepMarkSizeInvalid();
--- 353,373 ----
}
return null;
}
/**
! * Returns the number of visible children for {@code path}.
! * @return the number of visible children for {@code path}
*/
public int getVisibleChildCount(TreePath path) {
TreeStateNode node = getNodeForPath(path, true, false);
return (node != null) ? node.getVisibleChildCount() : 0;
}
/**
! * Informs the {@code TreeState} that it needs to recalculate
* all the sizes it is referencing.
*/
public void invalidateSizes() {
if(root != null)
root.deepMarkSizeInvalid();
*** 375,387 ****
updateNodeSizes(true);
}
}
/**
! * Returns true if the value identified by <code>path</code> is
* currently expanded.
! * @return true if the value identified by <code>path</code> is
* currently expanded
*/
public boolean isExpanded(TreePath path) {
if(path != null) {
TreeStateNode lastNode = getNodeForPath(path, true, false);
--- 375,387 ----
updateNodeSizes(true);
}
}
/**
! * Returns true if the value identified by {@code path} is
* currently expanded.
! * @return true if the value identified by {@code path} is
* currently expanded
*/
public boolean isExpanded(TreePath path) {
if(path != null) {
TreeStateNode lastNode = getNodeForPath(path, true, false);
*** 401,417 ****
* altered their children arrays, but other attributes have
* changed and may affect presentation. Example: the name of a
* file has changed, but it is in the same location in the file
* system.
*
! * <p><code>e.path</code> returns the path the parent of the
* changed node(s).
*
! * <p><code>e.childIndices</code> returns the index(es) of the
* changed node(s).
*
! * @param e the <code>TreeModelEvent</code> of interest
*/
public void treeNodesChanged(TreeModelEvent e) {
if(e != null) {
int changedIndexs[];
TreeStateNode changedNode;
--- 401,417 ----
* altered their children arrays, but other attributes have
* changed and may affect presentation. Example: the name of a
* file has changed, but it is in the same location in the file
* system.
*
! * <p>{@code e.path} returns the path the parent of the
* changed node(s).
*
! * <p>{@code e.childIndices} returns the index(es) of the
* changed node(s).
*
! * @param e the {@code TreeModelEvent} of interest
*/
public void treeNodesChanged(TreeModelEvent e) {
if(e != null) {
int changedIndexs[];
TreeStateNode changedNode;
*** 456,470 ****
/**
* Invoked after nodes have been inserted into the tree.
*
! * <p><code>e.path</code> returns the parent of the new nodes.
! * <p><code>e.childIndices</code> returns the indices of the new nodes in
* ascending order.
*
! * @param e the <code>TreeModelEvent</code> of interest
*/
public void treeNodesInserted(TreeModelEvent e) {
if(e != null) {
int changedIndexs[];
TreeStateNode changedParentNode;
--- 456,470 ----
/**
* Invoked after nodes have been inserted into the tree.
*
! * <p>{@code e.path} returns the parent of the new nodes.
! * <p>{@code e.childIndices} returns the indices of the new nodes in
* ascending order.
*
! * @param e the {@code TreeModelEvent} of interest
*/
public void treeNodesInserted(TreeModelEvent e) {
if(e != null) {
int changedIndexs[];
TreeStateNode changedParentNode;
*** 529,544 ****
* Invoked after nodes have been removed from the tree. Note that
* if a subtree is removed from the tree, this method may only be
* invoked once for the root of the removed subtree, not once for
* each individual set of siblings removed.
*
! * <p><code>e.path</code> returns the former parent of the deleted nodes.
*
! * <p><code>e.childIndices</code> returns the indices the nodes had
* before they were deleted in ascending order.
*
! * @param e the <code>TreeModelEvent</code> of interest
*/
public void treeNodesRemoved(TreeModelEvent e) {
if(e != null) {
int changedIndexs[];
TreeStateNode changedParentNode;
--- 529,544 ----
* Invoked after nodes have been removed from the tree. Note that
* if a subtree is removed from the tree, this method may only be
* invoked once for the root of the removed subtree, not once for
* each individual set of siblings removed.
*
! * <p>{@code e.path} returns the former parent of the deleted nodes.
*
! * <p>{@code e.childIndices} returns the indices the nodes had
* before they were deleted in ascending order.
*
! * @param e the {@code TreeModelEvent} of interest
*/
public void treeNodesRemoved(TreeModelEvent e) {
if(e != null) {
int changedIndexs[];
TreeStateNode changedParentNode;
*** 617,635 ****
}
}
/**
* Invoked after the tree has drastically changed structure from a
! * given node down. If the path returned by <code>e.getPath</code>
* is of length one and the first element does not identify the
* current root node the first element should become the new root
* of the tree.
*
! * <p><code>e.path</code> holds the path to the node.
! * <p><code>e.childIndices</code> returns <code>null</code>.
*
! * @param e the <code>TreeModelEvent</code> of interest
*/
public void treeStructureChanged(TreeModelEvent e) {
if(e != null)
{
TreePath changedPath = SwingUtilities2.getTreePath(e, getModel());
--- 617,635 ----
}
}
/**
* Invoked after the tree has drastically changed structure from a
! * given node down. If the path returned by {@code e.getPath}
* is of length one and the first element does not identify the
* current root node the first element should become the new root
* of the tree.
*
! * <p>{@code e.path} holds the path to the node.
! * <p>{@code e.childIndices} returns {@code null}.
*
! * @param e the {@code TreeModelEvent} of interest
*/
public void treeStructureChanged(TreeModelEvent e) {
if(e != null)
{
TreePath changedPath = SwingUtilities2.getTreePath(e, getModel());
*** 702,721 ****
private void removeMapping(TreeStateNode node) {
treePathMapping.remove(node.getTreePath());
}
/**
! * Returns the node previously added for <code>path</code>. This may
* return null, if you to create a node use getNodeForPath.
*/
private TreeStateNode getMapping(TreePath path) {
return treePathMapping.get(path);
}
/**
! * Retursn the bounds for row, <code>row</code> by reference in
! * <code>placeIn</code>. If <code>placeIn</code> is null a new
* Rectangle will be created and returned.
*/
private Rectangle getBounds(int row, Rectangle placeIn) {
if(updateNodeSizes)
updateNodeSizes(false);
--- 702,721 ----
private void removeMapping(TreeStateNode node) {
treePathMapping.remove(node.getTreePath());
}
/**
! * Returns the node previously added for {@code path}. This may
* return null, if you to create a node use getNodeForPath.
*/
private TreeStateNode getMapping(TreePath path) {
return treePathMapping.get(path);
}
/**
! * Retursn the bounds for row, {@code row} by reference in
! * {@code placeIn}. If {@code placeIn} is null a new
* Rectangle will be created and returned.
*/
private Rectangle getBounds(int row, Rectangle placeIn) {
if(updateNodeSizes)
updateNodeSizes(false);
*** 1071,1081 ****
}
}
/**
* Messaged when this node is removed from its parent, this messages
! * <code>removedFromMapping</code> to remove all the children.
*/
public void remove(int childIndex) {
TreeStateNode node = (TreeStateNode)getChildAt(childIndex);
node.removeFromMapping();
--- 1071,1081 ----
}
}
/**
* Messaged when this node is removed from its parent, this messages
! * {@code removedFromMapping} to remove all the children.
*/
public void remove(int childIndex) {
TreeStateNode node = (TreeStateNode)getChildAt(childIndex);
node.removeFromMapping();
*** 1274,1284 ****
}
}
/**
* Makes the receiver visible, but invoking
! * <code>expandParentAndReceiver</code> on the superclass.
*/
public void makeVisible() {
TreeStateNode parent = (TreeStateNode)getParent();
if(parent != null)
--- 1274,1284 ----
}
}
/**
* Makes the receiver visible, but invoking
! * {@code expandParentAndReceiver} on the superclass.
*/
public void makeVisible() {
TreeStateNode parent = (TreeStateNode)getParent();
if(parent != null)
*** 1339,1357 ****
protected void setYOrigin(int newYOrigin) {
yOrigin = newYOrigin;
}
/**
! * Shifts the y origin by <code>offset</code>.
*/
protected void shiftYOriginBy(int offset) {
yOrigin += offset;
}
/**
* Updates the receivers preferredSize by invoking
! * <code>updatePreferredSize</code> with an argument of -1.
*/
protected void updatePreferredSize() {
updatePreferredSize(getRow());
}
--- 1339,1357 ----
protected void setYOrigin(int newYOrigin) {
yOrigin = newYOrigin;
}
/**
! * Shifts the y origin by {@code offset}.
*/
protected void shiftYOriginBy(int offset) {
yOrigin += offset;
}
/**
* Updates the receivers preferredSize by invoking
! * {@code updatePreferredSize} with an argument of -1.
*/
protected void updatePreferredSize() {
updatePreferredSize(getRow());
}
*** 1404,1414 ****
}
/**
* Returns the children of the receiver. If the children haven't
* been loaded from the model and
! * <code>createIfNeeded</code> is true, the children are first
* loaded.
*/
protected Enumeration<TreeNode> getLoadedChildren(boolean createIfNeeded) {
if(!createIfNeeded || hasBeenExpanded)
return super.children();
--- 1404,1414 ----
}
/**
* Returns the children of the receiver. If the children haven't
* been loaded from the model and
! * {@code createIfNeeded} is true, the children are first
* loaded.
*/
protected Enumeration<TreeNode> getLoadedChildren(boolean createIfNeeded) {
if(!createIfNeeded || hasBeenExpanded)
return super.children();
*** 1448,1458 ****
*/
protected void didAdjustTree() {
}
/**
! * Invokes <code>expandParentAndReceiver</code> on the parent,
* and expands the receiver.
*/
protected void expandParentAndReceiver() {
TreeStateNode parent = (TreeStateNode)getParent();
--- 1448,1458 ----
*/
protected void didAdjustTree() {
}
/**
! * Invokes {@code expandParentAndReceiver} on the parent,
* and expands the receiver.
*/
protected void expandParentAndReceiver() {
TreeStateNode parent = (TreeStateNode)getParent();
*** 1703,1714 ****
updateNextObject();
return retObject;
}
/**
! * Determines the next object by invoking <code>updateNextIndex</code>
! * and if not succesful <code>findNextValidParent</code>.
*/
protected void updateNextObject() {
if(!updateNextIndex()) {
findNextValidParent();
}
--- 1703,1714 ----
updateNextObject();
return retObject;
}
/**
! * Determines the next object by invoking {@code updateNextIndex}
! * and if not succesful {@code findNextValidParent}.
*/
protected void updateNextObject() {
if(!updateNextIndex()) {
findNextValidParent();
}
*** 1740,1750 ****
}
return false;
}
/**
! * Updates <code>nextIndex</code> returning false if it is beyond
* the number of children of parent.
*/
protected boolean updateNextIndex() {
// nextIndex == -1 identifies receiver, make sure is expanded
// before descend.
--- 1740,1750 ----
}
return false;
}
/**
! * Updates {@code nextIndex} returning false if it is beyond
* the number of children of parent.
*/
protected boolean updateNextIndex() {
// nextIndex == -1 identifies receiver, make sure is expanded
// before descend.
< prev index next >