java.lang.Object | |
↳ | javax.swing.tree.DefaultTreeSelectionModel |
![]() |
Default implementation of TreeSelectionModel. Listeners are notified whenever the paths in the selection change, not the rows. In order to be able to track row changes you may wish to become a listener for expansion events on the tree and test for changes from there.
resetRowSelection is called from any of the methods that update
the selected paths. If you subclass any of these methods to
filter what is allowed to be selected, be sure and message
resetRowSelection
if you do not message super.
Warning:
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 JavaBeansTM
has been added to the java.beans
package.
Please see XMLEncoder
.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | SELECTION_MODE_PROPERTY | Property name for selectionMode. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
changeSupport | Used to messaged registered listeners. | ||||||||||
leadIndex | Index of the lead path in selection. | ||||||||||
leadPath | Last path that was added. | ||||||||||
leadRow | Lead row. | ||||||||||
listSelectionModel | Handles maintaining the list selection model. | ||||||||||
listenerList | Event listener list. | ||||||||||
rowMapper | Provides a row for a given path. | ||||||||||
selection | Paths that are currently selected. | ||||||||||
selectionMode | Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new instance of DefaultTreeSelectionModel that is
empty, with a selection mode of DISCONTIGUOUS_TREE_SELECTION.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a PropertyChangeListener to the listener list.
| |||||||||||
Adds path to the current selection.
| |||||||||||
Adds paths to the current selection.
| |||||||||||
Adds x to the list of listeners that are notified each time the
set of selected TreePaths changes.
| |||||||||||
Empties the current selection.
| |||||||||||
Returns a clone of this object with the same selection.
| |||||||||||
Returns the last path that was added.
| |||||||||||
Returns the lead selection index.
| |||||||||||
Returns an array of all the objects currently registered
as
FooListener s
upon this model. | |||||||||||
Returns the largest value obtained from the RowMapper for the
current set of selected TreePaths.
| |||||||||||
Returns the smallest value obtained from the RowMapper for the
current set of selected TreePaths.
| |||||||||||
Returns an array of all the property change listeners
registered on this
DefaultTreeSelectionModel . | |||||||||||
Returns the RowMapper instance that is able to map a TreePath to a
row.
| |||||||||||
Returns the number of paths that are selected.
| |||||||||||
Returns the selection mode, one of
SINGLE_TREE_SELECTION ,
DISCONTIGUOUS_TREE_SELECTION or
CONTIGUOUS_TREE_SELECTION . | |||||||||||
Returns the first path in the selection.
| |||||||||||
Returns the paths in the selection.
| |||||||||||
Returns all of the currently selected rows.
| |||||||||||
Returns an array of all the tree selection listeners
registered on this model.
| |||||||||||
Returns true if the path,
path ,
is in the current selection. | |||||||||||
Returns true if the row identified by
row is selected. | |||||||||||
Returns true if the selection is currently empty.
| |||||||||||
Removes a PropertyChangeListener from the listener list.
| |||||||||||
Removes path from the selection.
| |||||||||||
Removes paths from the selection.
| |||||||||||
Removes x from the list of listeners that are notified each time
the set of selected TreePaths changes.
| |||||||||||
Updates this object's mapping from TreePath to rows.
| |||||||||||
Sets the RowMapper instance.
| |||||||||||
Sets the selection model, which must be one of SINGLE_TREE_SELECTION,
CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
| |||||||||||
Sets the selection to path.
| |||||||||||
Sets the selection to the paths in paths.
| |||||||||||
Returns a string that displays and identifies this
object's properties.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns true if the paths are contiguous,
or this object has no RowMapper.
| |||||||||||
Used to test if a particular set of
TreePath s can
be added. | |||||||||||
Returns true if the paths can be removed without breaking the
continuity of the model.
| |||||||||||
Notifies all listeners that are registered for
tree selection events on this object.
| |||||||||||
Makes sure the currently selected
TreePath s are valid
for the current selection mode. | |||||||||||
This method is obsolete and its implementation is now a noop.
| |||||||||||
Notifies listeners of a change in path.
| |||||||||||
Updates the leadIndex instance variable.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Property name for selectionMode.
Index of the lead path in selection.
Lead row.
Handles maintaining the list selection model. The RowMapper is used to map from a TreePath to a row, and the value is then placed here.
Paths that are currently selected. Will be null if nothing is currently selected.
Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
Creates a new instance of DefaultTreeSelectionModel that is empty, with a selection mode of DISCONTIGUOUS_TREE_SELECTION.
Adds a PropertyChangeListener to the listener list. The listener is registered for all properties.
A PropertyChangeEvent will get fired when the selection mode changes.
listener | the PropertyChangeListener to be added |
---|
Adds path to the current selection. If path is not currently
in the selection the TreeSelectionListeners are notified. This has
no effect if path
is null.
path | the new path to add to the current selection |
---|
Adds paths to the current selection. If any of the paths in
paths are not currently in the selection the TreeSelectionListeners
are notified. This has
no effect if paths
is null.
The lead path is set to the last element in paths
.
If the selection mode is CONTIGUOUS_TREE_SELECTION
,
and adding the new paths would make the selection discontiguous.
Then two things can result: if the TreePaths in paths
are contiguous, then the selection becomes these TreePaths,
otherwise the TreePaths aren't contiguous and the selection becomes
the first TreePath in paths
.
paths | the new path to add to the current selection |
---|
Adds x to the list of listeners that are notified each time the set of selected TreePaths changes.
x | the new listener to be added |
---|
Empties the current selection. If this represents a change in the current selection, the selection listeners are notified.
Returns a clone of this object with the same selection. This method does not duplicate selection listeners and property listeners.
CloneNotSupportedException | never thrown by instances of this class |
---|
Returns the last path that was added. This may differ from the leadSelectionPath property maintained by the JTree.
Returns the lead selection index. That is the last index that was added.
Returns an array of all the objects currently registered
as FooListener
s
upon this model.
FooListener
s are registered using the
addFooListener
method.
You can specify the listenerType
argument
with a class literal,
such as
FooListener.class
.
For example, you can query a
DefaultTreeSelectionModel
m
for its tree selection listeners with the following code:
TreeSelectionListener[] tsls = (TreeSelectionListener[])(m.getListeners(TreeSelectionListener.class));If no such listeners exist, this method returns an empty array.
listenerType | the type of listeners requested; this parameter
should specify an interface that descends from
java.util.EventListener |
---|
FooListener
s on this component,
or an empty array if no such
listeners have been addedClassCastException | if listenerType
doesn't specify a class or interface that implements
java.util.EventListener |
---|
Returns the largest value obtained from the RowMapper for the current set of selected TreePaths. If nothing is selected, or there is no RowMapper, this will return -1.
Returns the smallest value obtained from the RowMapper for the current set of selected TreePaths. If nothing is selected, or there is no RowMapper, this will return -1.
Returns an array of all the property change listeners
registered on this DefaultTreeSelectionModel
.
PropertyChangeListener
s
or an empty
array if no property change listeners are currently registeredReturns the RowMapper instance that is able to map a TreePath to a row.
Returns the number of paths that are selected.
Returns the selection mode, one of SINGLE_TREE_SELECTION
,
DISCONTIGUOUS_TREE_SELECTION
or
CONTIGUOUS_TREE_SELECTION
.
Returns the first path in the selection. This is useful if there if only one item currently selected.
Returns the paths in the selection. This will return null (or an empty array) if nothing is currently selected.
Returns all of the currently selected rows. This will return null (or an empty array) if there are no selected TreePaths or a RowMapper has not been set. This may return an array of length less that than of the selected TreePaths if some of the rows are not visible (that is the RowMapper returned -1 for the row corresponding to the TreePath).
Returns an array of all the tree selection listeners registered on this model.
TreeSelectionListener
s
or an empty
array if no tree selection listeners are currently registeredReturns true if the path, path
,
is in the current selection.
Returns true if the row identified by row
is selected.
Returns true if the selection is currently empty.
Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.
listener | the PropertyChangeListener to be removed |
---|
Removes path from the selection. If path is in the selection
The TreeSelectionListeners are notified. This has no effect if
path
is null.
path | the path to remove from the selection |
---|
Removes paths from the selection. If any of the paths in paths
are in the selection the TreeSelectionListeners are notified.
This has no effect if paths
is null.
paths | the paths to remove from the selection |
---|
Removes x from the list of listeners that are notified each time the set of selected TreePaths changes.
x | the listener to remove |
---|
Updates this object's mapping from TreePath to rows. This should be invoked when the mapping from TreePaths to integers has changed (for example, a node has been expanded).
You do not normally have to call this, JTree and its associated Listeners will invoke this for you. If you are implementing your own View class, then you will have to invoke this.
This will invoke insureRowContinuity
to make sure
the currently selected TreePaths are still valid based on the
selection mode.
Sets the RowMapper instance. This instance is used to determine the row for a particular TreePath.
Sets the selection model, which must be one of SINGLE_TREE_SELECTION,
CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION. If mode
is not one of the defined value,
DISCONTIGUOUS_TREE_SELECTION
is assumed.
This may change the selection if the current selection is not valid
for the new mode. For example, if three TreePaths are
selected when the mode is changed to SINGLE_TREE_SELECTION
,
only one TreePath will remain selected. It is up to the particular
implementation to decide what TreePath remains selected.
Setting the mode to something other than the defined types will
result in the mode becoming DISCONTIGUOUS_TREE_SELECTION
.
Sets the selection to path. If this represents a change, then
the TreeSelectionListeners are notified. If path
is
null, this has the same effect as invoking clearSelection
.
path | new path to select |
---|
Sets the selection to the paths in paths. If this represents a change the TreeSelectionListeners are notified. Potentially paths will be held by this object; in other words don't change any of the objects in the array once passed in.
If paths
is
null, this has the same effect as invoking clearSelection
.
The lead path is set to the last path in pPaths
.
If the selection mode is CONTIGUOUS_TREE_SELECTION
,
and adding the new paths would make the selection discontiguous,
the selection is reset to the first TreePath in paths
.
pPaths | new selection |
---|
Returns a string that displays and identifies this object's properties.
Returns true if the paths are contiguous, or this object has no RowMapper.
Used to test if a particular set of TreePath
s can
be added. This will return true if paths
is null (or
empty), or this object has no RowMapper, or nothing is currently selected,
or the selection mode is DISCONTIGUOUS_TREE_SELECTION
, or
adding the paths to the current selection still results in a
contiguous set of TreePath
s.
Returns true if the paths can be removed without breaking the continuity of the model. This is rather expensive.
Notifies all listeners that are registered for tree selection events on this object.
Makes sure the currently selected TreePath
s are valid
for the current selection mode.
If the selection mode is CONTIGUOUS_TREE_SELECTION
and a RowMapper
exists, this will make sure all
the rows are contiguous, that is, when sorted all the rows are
in order with no gaps.
If the selection isn't contiguous, the selection is
reset to contain the first set, when sorted, of contiguous rows.
If the selection mode is SINGLE_TREE_SELECTION
and
more than one TreePath is selected, the selection is reset to
contain the first path currently selected.
This method is obsolete and its implementation is now a noop. It's still called by setSelectionPaths and addSelectionPaths, but only for backwards compatability.
Notifies listeners of a change in path. changePaths should contain instances of PathPlaceHolder.
Updates the leadIndex instance variable.