- All Implemented Interfaces:
- Serializable,- Cloneable,- TreeSelectionModel
- Direct Known Subclasses:
- JTree.EmptySelectionModel
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 JavaBeans
 has been added to the java.beans package.
 Please see XMLEncoder.
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected SwingPropertyChangeSupportUsed to messaged registered listeners.protected intIndex of the lead path in selection.protected TreePathLast path that was added.protected intLead row.protected EventListenerListEvent listener list.protected DefaultListSelectionModelHandles maintaining the list selection model.protected RowMapperProvides a row for a given path.protected TreePath[]Paths that are currently selected.static final StringProperty name for selectionMode.protected intMode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.Fields declared in interface javax.swing.tree.TreeSelectionModelCONTIGUOUS_TREE_SELECTION, DISCONTIGUOUS_TREE_SELECTION, SINGLE_TREE_SELECTION
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a new instance of DefaultTreeSelectionModel that is empty, with a selection mode of DISCONTIGUOUS_TREE_SELECTION.
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds a PropertyChangeListener to the listener list.voidaddSelectionPath(TreePath path) Adds path to the current selection.voidaddSelectionPaths(TreePath[] paths) Adds paths to the current selection.voidAdds x to the list of listeners that are notified each time the set of selected TreePaths changes.protected booleanarePathsContiguous(TreePath[] paths) Returns true if the paths are contiguous, or this object has no RowMapper.protected booleancanPathsBeAdded(TreePath[] paths) Used to test if a particular set ofTreePaths can be added.protected booleancanPathsBeRemoved(TreePath[] paths) Returns true if the paths can be removed without breaking the continuity of the model.voidEmpties the current selection.clone()Returns a clone of this object with the same selection.protected voidNotifies all listeners that are registered for tree selection events on this object.Returns the last path that was added.intReturns the lead selection index.<T extends EventListener>
 T[]getListeners(Class<T> listenerType) Returns an array of all the objects currently registered asFooListeners upon this model.intReturns the largest value obtained from the RowMapper for the current set of selected TreePaths.intReturns 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 thisDefaultTreeSelectionModel.Returns the RowMapper instance that is able to map a TreePath to a row.intReturns the number of paths that are selected.intReturns the selection mode, one ofSINGLE_TREE_SELECTION,DISCONTIGUOUS_TREE_SELECTIONorCONTIGUOUS_TREE_SELECTION.Returns the first path in the selection.TreePath[]Returns the selection.int[]Returns the selection in terms of rows.Returns an array of all the tree selection listeners registered on this model.protected voidMakes sure the currently selectedTreePaths are valid for the current selection mode.protected voidThis method is obsolete and its implementation is now a noop.booleanisPathSelected(TreePath path) Returns true if the path,path, is in the current selection.booleanisRowSelected(int row) Returns true if the row identified byrowis selected.booleanReturns true if the selection is currently empty.protected voidnotifyPathChange(Vector<?> changedPaths, TreePath oldLeadSelection) Deprecated.As of JDK version 1.7voidRemoves a PropertyChangeListener from the listener list.voidremoveSelectionPath(TreePath path) Removes path from the selection.voidremoveSelectionPaths(TreePath[] paths) Removes paths from the selection.voidRemoves x from the list of listeners that are notified each time the set of selected TreePaths changes.voidUpdates this object's mapping from TreePath to rows.voidsetRowMapper(RowMapper newMapper) Sets the RowMapper instance.voidsetSelectionMode(int mode) Sets the selection model, which must be one of SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.voidsetSelectionPath(TreePath path) Sets the selection to path.voidsetSelectionPaths(TreePath[] pPaths) Sets the selection.toString()Returns a string that displays and identifies this object's properties.protected voidUpdates the leadIndex instance variable.
- 
Field Details- 
SELECTION_MODE_PROPERTYProperty name for selectionMode.- See Also:
 
- 
changeSupportUsed to messaged registered listeners.
- 
selectionPaths that are currently selected. Will be null if nothing is currently selected.
- 
listenerListEvent listener list.
- 
rowMapperProvides a row for a given path.
- 
listSelectionModelHandles maintaining the list selection model. The RowMapper is used to map from a TreePath to a row, and the value is then placed here.
- 
selectionModeprotected int selectionModeMode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
- 
leadPathLast path that was added.
- 
leadIndexprotected int leadIndexIndex of the lead path in selection.
- 
leadRowprotected int leadRowLead row.
 
- 
- 
Constructor Details- 
DefaultTreeSelectionModelpublic DefaultTreeSelectionModel()Creates a new instance of DefaultTreeSelectionModel that is empty, with a selection mode of DISCONTIGUOUS_TREE_SELECTION.
 
- 
- 
Method Details- 
setRowMapperSets the RowMapper instance. This instance is used to determine the row for a particular TreePath.- Specified by:
- setRowMapperin interface- TreeSelectionModel
- Parameters:
- newMapper- RowMapper to be set
 
- 
getRowMapperReturns the RowMapper instance that is able to map a TreePath to a row.- Specified by:
- getRowMapperin interface- TreeSelectionModel
- Returns:
- the RowMapper instance that is able to map a TreePath to a row
 
- 
setSelectionModepublic void setSelectionMode(int mode) 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_SELECTIONis 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.- Specified by:
- setSelectionModein interface- TreeSelectionModel
- Parameters:
- mode- selection mode to be set
 
- 
getSelectionModepublic int getSelectionMode()Returns the selection mode, one ofSINGLE_TREE_SELECTION,DISCONTIGUOUS_TREE_SELECTIONorCONTIGUOUS_TREE_SELECTION.- Specified by:
- getSelectionModein interface- TreeSelectionModel
- Returns:
- the current selection mode
 
- 
setSelectionPathSets the selection to path. If this represents a change, then the TreeSelectionListeners are notified. Ifpathis null, this has the same effect as invokingclearSelection.- Specified by:
- setSelectionPathin interface- TreeSelectionModel
- Parameters:
- path- new path to select
 
- 
setSelectionPathsSets the selection. Whether the supplied paths are taken as the new selection depends upon the selection mode. If the supplied array isnull, or empty, the selection is cleared. If the selection mode isSINGLE_TREE_SELECTION, only the first path inpPathsis used. If the selection mode isCONTIGUOUS_TREE_SELECTIONand the supplied paths are not contiguous, then only the first path inpPathsis used. If the selection mode isDISCONTIGUOUS_TREE_SELECTION, then all paths are used.All nullpaths inpPathsare ignored.If this represents a change, all registered TreeSelectionListeners are notified.The lead path is set to the last unique path. The paths returned from getSelectionPathsare in the same order as those supplied to this method.- Specified by:
- setSelectionPathsin interface- TreeSelectionModel
- Parameters:
- pPaths- the new selection
 
- 
addSelectionPathAdds path to the current selection. If path is not currently in the selection the TreeSelectionListeners are notified. This has no effect ifpathis null.- Specified by:
- addSelectionPathin interface- TreeSelectionModel
- Parameters:
- path- the new path to add to the current selection
 
- 
addSelectionPathsAdds 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 ifpathsis 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 inpathsare contiguous, then the selection becomes these TreePaths, otherwise the TreePaths aren't contiguous and the selection becomes the first TreePath inpaths.- Specified by:
- addSelectionPathsin interface- TreeSelectionModel
- Parameters:
- paths- the new path to add to the current selection
 
- 
removeSelectionPathRemoves path from the selection. If path is in the selection The TreeSelectionListeners are notified. This has no effect ifpathis null.- Specified by:
- removeSelectionPathin interface- TreeSelectionModel
- Parameters:
- path- the path to remove from the selection
 
- 
removeSelectionPathsRemoves paths from the selection. If any of the paths in paths are in the selection the TreeSelectionListeners are notified. This has no effect ifpathsis null.- Specified by:
- removeSelectionPathsin interface- TreeSelectionModel
- Parameters:
- paths- the paths to remove from the selection
 
- 
getSelectionPathReturns the first path in the selection. This is useful if there if only one item currently selected.- Specified by:
- getSelectionPathin interface- TreeSelectionModel
- Returns:
- the first path in the selection
 
- 
getSelectionPathsReturns the selection.- Specified by:
- getSelectionPathsin interface- TreeSelectionModel
- Returns:
- the selection
 
- 
getSelectionCountpublic int getSelectionCount()Returns the number of paths that are selected.- Specified by:
- getSelectionCountin interface- TreeSelectionModel
- Returns:
- the number of paths that are selected
 
- 
isPathSelectedReturns true if the path,path, is in the current selection.- Specified by:
- isPathSelectedin interface- TreeSelectionModel
- Parameters:
- path- the path to be loked for
- Returns:
- whether the pathis in the current selection
 
- 
isSelectionEmptypublic boolean isSelectionEmpty()Returns true if the selection is currently empty.- Specified by:
- isSelectionEmptyin interface- TreeSelectionModel
- Returns:
- whether the selection is currently empty
 
- 
clearSelectionpublic void clearSelection()Empties the current selection. If this represents a change in the current selection, the selection listeners are notified.- Specified by:
- clearSelectionin interface- TreeSelectionModel
 
- 
addTreeSelectionListenerAdds x to the list of listeners that are notified each time the set of selected TreePaths changes.- Specified by:
- addTreeSelectionListenerin interface- TreeSelectionModel
- Parameters:
- x- the new listener to be added
 
- 
removeTreeSelectionListenerRemoves x from the list of listeners that are notified each time the set of selected TreePaths changes.- Specified by:
- removeTreeSelectionListenerin interface- TreeSelectionModel
- Parameters:
- x- the listener to remove
 
- 
getTreeSelectionListenersReturns an array of all the tree selection listeners registered on this model.- Returns:
- all of this model's TreeSelectionListeners or an empty array if no tree selection listeners are currently registered
- Since:
- 1.4
- See Also:
 
- 
fireValueChangedNotifies all listeners that are registered for tree selection events on this object.- Parameters:
- e- the event that characterizes the change
- See Also:
 
- 
getListenersReturns an array of all the objects currently registered asFooListeners upon this model.FooListeners are registered using theaddFooListenermethod.You can specify the listenerTypeargument with a class literal, such asFooListener.class. For example, you can query aDefaultTreeSelectionModelmfor 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.- Type Parameters:
- T- the listener type
- Parameters:
- listenerType- the type of listeners requested
- Returns:
- an array of all objects registered as
          FooListeners on this component, or an empty array if no such listeners have been added
- Throws:
- ClassCastException- if- listenerTypedoesn't specify a class or interface that implements- java.util.EventListener
- Since:
- 1.3
- See Also:
 
- 
getSelectionRowspublic int[] getSelectionRows()Returns the selection in terms of rows. There is not necessarily a one-to-one mapping between theTreePaths returned fromgetSelectionPathsand this method. In particular, if aTreePathis not viewable (theRowMapperreturns-1for the row corresponding to theTreePath), then the corresponding row is not included in the returned array. For example, if the selection consists of two paths,AandB, withAat row10, andBnot currently viewable, then this method returns an array with the single entry10.- Specified by:
- getSelectionRowsin interface- TreeSelectionModel
- Returns:
- the selection in terms of rows
 
- 
getMinSelectionRowpublic int getMinSelectionRow()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.- Specified by:
- getMinSelectionRowin interface- TreeSelectionModel
- Returns:
- the smallest value obtained from the RowMapper for the current set of selected TreePaths
 
- 
getMaxSelectionRowpublic int getMaxSelectionRow()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.- Specified by:
- getMaxSelectionRowin interface- TreeSelectionModel
- Returns:
- the largest value obtained from the RowMapper for the current set of selected TreePaths
 
- 
isRowSelectedpublic boolean isRowSelected(int row) Returns true if the row identified byrowis selected.- Specified by:
- isRowSelectedin interface- TreeSelectionModel
- Parameters:
- row- row to check
- Returns:
- whether the row is selected
 
- 
resetRowSelectionpublic void resetRowSelection()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 insureRowContinuityto make sure the currently selected TreePaths are still valid based on the selection mode.- Specified by:
- resetRowSelectionin interface- TreeSelectionModel
 
- 
getLeadSelectionRowpublic int getLeadSelectionRow()Returns the lead selection index. That is the last index that was added.- Specified by:
- getLeadSelectionRowin interface- TreeSelectionModel
- Returns:
- the lead selection index
 
- 
getLeadSelectionPathReturns the last path that was added. This may differ from the leadSelectionPath property maintained by the JTree.- Specified by:
- getLeadSelectionPathin interface- TreeSelectionModel
- Returns:
- the last path that was added
 
- 
addPropertyChangeListenerAdds a PropertyChangeListener to the listener list. The listener is registered for all properties.A PropertyChangeEvent will get fired when the selection mode changes. - Specified by:
- addPropertyChangeListenerin interface- TreeSelectionModel
- Parameters:
- listener- the PropertyChangeListener to be added
 
- 
removePropertyChangeListenerRemoves a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.- Specified by:
- removePropertyChangeListenerin interface- TreeSelectionModel
- Parameters:
- listener- the PropertyChangeListener to be removed
 
- 
getPropertyChangeListenersReturns an array of all the property change listeners registered on thisDefaultTreeSelectionModel.- Returns:
- all of this model's PropertyChangeListeners or an empty array if no property change listeners are currently registered
- Since:
- 1.4
- See Also:
 
- 
insureRowContinuityprotected void insureRowContinuity()Makes sure the currently selectedTreePaths are valid for the current selection mode. If the selection mode isCONTIGUOUS_TREE_SELECTIONand aRowMapperexists, 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_SELECTIONand more than one TreePath is selected, the selection is reset to contain the first path currently selected.
- 
arePathsContiguousReturns true if the paths are contiguous, or this object has no RowMapper.- Parameters:
- paths- array of paths to check
- Returns:
- whether the paths are contiguous, or this object has no RowMapper
 
- 
canPathsBeAddedUsed to test if a particular set ofTreePaths can be added. This will return true ifpathsis null (or empty), or this object has no RowMapper, or nothing is currently selected, or the selection mode isDISCONTIGUOUS_TREE_SELECTION, or adding the paths to the current selection still results in a contiguous set ofTreePaths.- Parameters:
- paths- array of- TreePathsto check
- Returns:
- whether the particular set of TreePathscan be added
 
- 
canPathsBeRemovedReturns true if the paths can be removed without breaking the continuity of the model. This is rather expensive.- Parameters:
- paths- array of- TreePathto check
- Returns:
- whether the paths can be removed without breaking the continuity of the model
 
- 
notifyPathChangeDeprecated.As of JDK version 1.7Notifies listeners of a change in path. changePaths should contain instances of PathPlaceHolder.- Parameters:
- changedPaths- the vector of the changed paths
- oldLeadSelection- the old selection path
 
- 
updateLeadIndexprotected void updateLeadIndex()Updates the leadIndex instance variable.
- 
insureUniquenessprotected void insureUniqueness()This method is obsolete and its implementation is now a noop. It's still called by setSelectionPaths and addSelectionPaths, but only for backwards compatibility.
- 
toStringReturns a string that displays and identifies this object's properties.
- 
cloneReturns a clone of this object with the same selection. This method does not duplicate selection listeners and property listeners.- Overrides:
- clonein class- Object
- Returns:
- a clone of this instance.
- Throws:
- CloneNotSupportedException- never thrown by instances of this class
- See Also:
 
 
-