| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
DefaultTreeSelectionModel dtsm = new DefaultTreeSelectionModel();
Based on 7 examples
public class DefaultTreeSelectionModel extends Object implements Cloneable, Serializable, TreeSelectionModel
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 {@link java.beans.XMLEncoder}.
Field Summary | |
---|---|
protected SwingPropertyChangeSupport |
changeSupport
Used to messaged registered listeners. |
protected int |
leadIndex
Index of the lead path in selection. |
protected TreePath |
leadPath
Last path that was added. |
protected int |
leadRow
Lead row. |
protected EventListenerList |
listenerList
Event listener list. |
protected DefaultListSelectionModel |
listSelectionModel
Handles maintaining the list selection model. |
protected transient RowMapper |
rowMapper
Provides a row for a given path. |
protected TreePath[] |
selection
Paths that are currently selected. |
protected int |
selectionMode
Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION. |
static String |
SELECTION_MODE_PROPERTY
Property name for selectionMode. |
Constructor Summary | |
---|---|
Creates a new instance of DefaultTreeSelectionModel that is empty, with a selection mode of DISCONTIGUOUS_TREE_SELECTION. |
Method Summary | |
---|---|
void |
Adds a PropertyChangeListener to the listener list. |
void |
addSelectionPath(TreePath path) Adds path to the current selection. |
void |
addSelectionPaths(TreePath[] paths) Adds paths to the current selection. |
void |
Adds x to the list of listeners that are notified each time the set of selected TreePaths changes. |
protected boolean |
arePathsContiguous(TreePath[] paths) Returns true if the paths are contiguous, or this object has no RowMapper. |
protected boolean |
canPathsBeAdded(TreePath[] paths) Used to test if a particular set of TreePath s can
be added.
|
protected boolean |
canPathsBeRemoved(TreePath[] paths) Returns true if the paths can be removed without breaking the continuity of the model. |
void |
Empties the current selection. |
Object |
clone() Returns a clone of this object with the same selection. |
protected void |
Notifies all listeners that are registered for tree selection events on this object. |
TreePath |
Returns the last path that was added. |
int |
Returns the lead selection index. |
EventListener[] |
getListeners(Class listenerType) Returns an array of all the objects currently registered as FooListener s
upon this model.
|
int |
Returns the largest value obtained from the RowMapper for the current set of selected TreePaths. |
int |
Returns the smallest value obtained from the RowMapper for the current set of selected TreePaths. |
PropertyChangeListener[] |
Returns an array of all the property change listeners registered on this DefaultTreeSelectionModel .
|
RowMapper |
Returns the RowMapper instance that is able to map a TreePath to a row. |
int |
Returns the number of paths that are selected. |
int |
Returns the selection mode, one of SINGLE_TREE_SELECTION ,
DISCONTIGUOUS_TREE_SELECTION or
CONTIGUOUS_TREE_SELECTION .
|
TreePath |
Returns the first path in the selection. |
TreePath[] |
Returns the paths in the selection. |
int[] |
Returns all of the currently selected rows. |
TreeSelectionListener[] |
Returns an array of all the tree selection listeners registered on this model. |
protected void |
Makes sure the currently selected TreePath s are valid
for the current selection mode.
|
protected void |
This method is obsolete and its implementation is now a noop. |
boolean |
isPathSelected(TreePath path) Returns true if the path, path ,
is in the current selection.
|
boolean |
isRowSelected(int row) Returns true if the row identified by row is selected.
|
boolean |
Returns true if the selection is currently empty. |
protected void |
notifyPathChange(Vector changedPaths, TreePath oldLeadSelection) Notifies listeners of a change in path. |
void |
Removes a PropertyChangeListener from the listener list. |
void |
removeSelectionPath(TreePath path) Removes path from the selection. |
void |
removeSelectionPaths(TreePath[] paths) Removes paths from the selection. |
void |
Removes x from the list of listeners that are notified each time the set of selected TreePaths changes. |
void |
Updates this object's mapping from TreePath to rows. |
void |
setRowMapper(RowMapper newMapper) Sets the RowMapper instance. |
void |
setSelectionMode(int mode) Sets the selection model, which must be one of SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION. |
void |
setSelectionPath(TreePath path) Sets the selection to path. |
void |
setSelectionPaths(TreePath[] pPaths) Sets the selection to the paths in paths. |
String |
toString() Returns a string that displays and identifies this object's properties. |
protected void |
Updates the leadIndex instance variable. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected SwingPropertyChangeSupport changeSupport
protected int leadIndex
protected TreePath leadPath
protected int leadRow
protected EventListenerList listenerList
protected DefaultListSelectionModel listSelectionModel
protected transient RowMapper rowMapper
protected TreePath[] selection
protected int selectionMode
public static final String SELECTION_MODE_PROPERTY
Constructor Detail |
---|
public DefaultTreeSelectionModel()
Method Detail |
---|
public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
A PropertyChangeEvent will get fired when the selection mode changes.
listener
- the PropertyChangeListener to be addedpublic void addSelectionPath(TreePath path)
path
is null.
path
- the new path to add to the current selectionpublic void addSelectionPaths(TreePath[] paths)
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 selectionpublic void addTreeSelectionListener(TreeSelectionListener x)
x
- the new listener to be addedprotected boolean arePathsContiguous(TreePath[] paths)
paths
protected boolean canPathsBeAdded(TreePath[] paths)
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.
paths
protected boolean canPathsBeRemoved(TreePath[] paths)
paths
public void clearSelection()
public Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
- never thrown by instances of
this classprotected void fireValueChanged(TreeSelectionEvent e)
e
public TreePath getLeadSelectionPath()
public int getLeadSelectionRow()
public EventListener[] getListeners(Class listenerType)
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 addedpublic int getMaxSelectionRow()
public int getMinSelectionRow()
public PropertyChangeListener[] getPropertyChangeListeners()
DefaultTreeSelectionModel
.
PropertyChangeListener
s
or an empty
array if no property change listeners are currently registeredpublic RowMapper getRowMapper()
public int getSelectionCount()
public int getSelectionMode()
SINGLE_TREE_SELECTION
,
DISCONTIGUOUS_TREE_SELECTION
or
CONTIGUOUS_TREE_SELECTION
.
public TreePath getSelectionPath()
public TreePath[] getSelectionPaths()
public int[] getSelectionRows()
public TreeSelectionListener[] getTreeSelectionListeners()
TreeSelectionListener
s
or an empty
array if no tree selection listeners are currently registeredprotected void insureRowContinuity()
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.
protected void insureUniqueness()
public boolean isPathSelected(TreePath path)
path
,
is in the current selection.
path
public boolean isRowSelected(int row)
row
is selected.
row
public boolean isSelectionEmpty()
protected void notifyPathChange(Vector changedPaths, TreePath oldLeadSelection)
changedPaths
oldLeadSelection
public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
listener
- the PropertyChangeListener to be removedpublic void removeSelectionPath(TreePath path)
path
is null.
path
- the path to remove from the selectionpublic void removeSelectionPaths(TreePath[] paths)
paths
is null.
paths
- the paths to remove from the selectionpublic void removeTreeSelectionListener(TreeSelectionListener x)
x
- the listener to removepublic void resetRowSelection()
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.
public void setRowMapper(RowMapper newMapper)
newMapper
public void setSelectionMode(int mode)
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
.
mode
public void setSelectionPath(TreePath path)
path
is
null, this has the same effect as invoking clearSelection
.
path
- new path to selectpublic void setSelectionPaths(TreePath[] pPaths)
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 selectionpublic String toString()
toString
in class Object
protected void updateLeadIndex()
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |