Spec-Zone .ru
спецификации, руководства, описания, API
Java

JTree

Other Swing Changes

New JTree toggleClickCount Property

JTree now provides a property for configuring how many mouse clicks are needed to expand/collapse a node. See:

New JTree Properties: Anchor, LeadSelectionPath

The TreeSelectionModel maintains a set of selected paths. Most UIs also provide the notion of the lead path and the anchor path. The anchor path is used for gestures that extend the selection, and the lead is usually the path that was last added to the selection. The lead may also be manipulated independently such that it isn't always selected. Motif does this, as do the control modifiers with the Java Look and Feel (aka Metal). Support for this was previously added in a private manner such that developers were not able to determine what the anchor/lead were. The new API will expose this to developers so that they can get the lead/anchor as well as programmatically modify it. Exposing methods will also make it so that developers are free to override the behavior in any way they see fit.

See:

Exposed DefaultTreeCellRenderer.hasFocus as a Protected Field

DefaultTreeCellRenderer exposes almost all of the arguments passed in via the getTreeCellRendererComponent method as protected instance variables. This makes it easy for a subclass that wishes to only change painting, as the subclass only has to override paint, and not getTreeCellRendererComponent to track all the arguments themselves. The hasFocus argument (last argument) was private. The hasFocus instance variable is now protected vs private.

In javax.swing.tree.DefaultTreeCellRenderer see:

Added TreeSelectionEvent.isAddedPath()

TreeSelectionEvent encapsulates the delta of how the TreeSelectionModel changed. That is, it will contain any paths that have been added to the selection, as well as paths that have been removed. To determine if a particular path is new to the selection model the isAddedPath(TreePath) method is provided. The valueChanged(TreeSelectionEvent) listener method usually takes the form of:
  
TreePath[] paths = event.getPaths();
for (int counter = paths.length - 1; counter >= 0; counter--) {
    if (event.isAddedPath(paths[counter])) ...
}
    

TreeSelectionEvent.isAddedPath(TreePath) has to iterate through the TreePaths to determine the index of the TreePath in its internal TreePath array, and then map that to a boolean to determine if it is a new path. To avoid the step of isAddedPath(TreePath) iterating through its TreePath array, isAddedPath(int) has been added.

In javax.swing.event.TreeSelectionEvent see:

New JTree expandsSelectedPaths Property and removeDescendantSelectedPaths Method

When the selection is programatically changed in a JTree, the selected items are made visible (visible meaning all the parent items are expanded). For certain applications this behavior is not desirable, eg say all nodes of a certain type should be selected regardless of their visibility. This behavior is implemented across JTree and BasicTreeUI, making it tricky to override this behavior. The public methods get/setExpandsSelectedPaths have been added to JTree. If set to false, when the selection changes the nodes are not made visible, the default is true.

The protected method removeDescendantSelectedPaths has also been added. This method is called whenever a node is removed/collapsed to remove any descendant selected paths. This provides a simple place for subclassers to override should they not want the selection to change when a node is removed/collapsed.

See:

DefaultTreeSelectionModel.insureUniqueness now Obsolete

DefaultTreeSelectionModel has the protected method insureUniqueness. It would go through an array of TreePaths making sure there were no duplicates. The implementation has changed such that a Hashtable is used and this method is no longer needed, it has marked obsolete. The implementation is now empty, but still invoked as before.

Here's the API and spec for the changes to javax.swing.tree.DefaultTreeSelectionModel

    /**
     * This method is obsolete and its implementation is now a noop. It's
     * still called by setSelectionPaths and addSelectionPaths, but only
     * for backwards compatibility.
     */
    protected void insureUniqueness()
    

Copyright © 1995-98 Sun Microsystems, Inc. All Rights Reserved.

Please send comments to: swing-feedback@java.sun.com. This is not a subscription list.
Sun
Java Software