This patch fixes part of JTree regressions, summarised in 28061.
In JTree, the setModel assumed that EXPANDED and COLLAPSED are
Boolean.TRUE and Boolean.FALSE. In reality, it were just two newly
instantiated objects, so putting Boolean.TRUE in JTree.setModel did not
work as expected. I made this consistent (using Booleans seems a good
idea). The BasicTreeUI.toggleExpandState could call tree.isExpanded now
(this is tested), but is faster to obtain this value from the layout cache.
In BasicTreeUI.CompleteUIInstall, the configureLayoutCache() was called
after setting the current treeState value as rowmapper for the selection
model. However the configureLayoutCache() newly initialises the
treeState variable, leaving tree selection model in the broken state.
Also, the root visibility property was not set.
With this path, the tree respects the root node visibility property and
it is possible to expand and collapse the nodes with mouse. Other
features are not yet revived.
2006-07-04 Audrius Meskauskas <[EMAIL PROTECTED]>
PR 28061
* javax/swing/JTree.java (COLLAPSED): Initialise to Boolean.FALSE.
(EXPANDED): Initialise to Boolean.TRUE.
* javax/swing/plaf/basic/BasicTreeUI.java (completeUIInstall):
First configure layout cache and then set the assigned value
as row mapper. Set the root visibility property.
(toggleExpandState): Obtains expansion state from the layout cache.
Index: swing/JTree.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JTree.java,v
retrieving revision 1.69
diff -u -r1.69 JTree.java
--- swing/JTree.java 7 Jun 2006 14:36:02 -0000 1.69
+++ swing/JTree.java 3 Jul 2006 22:06:40 -0000
@@ -1392,9 +1392,9 @@
public static final String EXPANDS_SELECTED_PATHS_PROPERTY =
"expandsSelectedPaths";
- private static final Object EXPANDED = new Object();
+ private static final Object EXPANDED = Boolean.TRUE;
- private static final Object COLLAPSED = new Object();
+ private static final Object COLLAPSED = Boolean.FALSE;
private boolean dragEnabled;
Index: swing/plaf/basic/BasicTreeUI.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.144
diff -u -r1.144 BasicTreeUI.java
--- swing/plaf/basic/BasicTreeUI.java 13 Jun 2006 09:28:57 -0000 1.144
+++ swing/plaf/basic/BasicTreeUI.java 3 Jul 2006 22:06:49 -0000
@@ -845,9 +845,9 @@
updateRenderer();
updateDepthOffset();
setSelectionModel(tree.getSelectionModel());
- treeState = createLayoutCache();
- treeSelectionModel.setRowMapper(treeState);
configureLayoutCache();
+ treeState.setRootVisible(tree.isRootVisible());
+ treeSelectionModel.setRowMapper(treeState);
updateSize();
}
@@ -1848,7 +1848,8 @@
*/
protected void toggleExpandState(TreePath path)
{
- if (tree.isExpanded(path))
+ // tree.isExpanded(path) would do the same, but treeState knows faster.
+ if (treeState.isExpanded(path))
tree.collapsePath(path);
else
tree.expandPath(path);