Class java.awt.swing.tree.DefaultTreeSelectionModel
java.lang.Object
|
+----java.awt.swing.tree.DefaultTreeSelectionModel
- Subclasses:
- JTree.EmptySelectionModel
- public class DefaultTreeSelectionModel
- extends Object
- implements Cloneable, Serializable, TreeSelectionModel
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.
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 Swing1.0 applications. It will
not be possible to load serialized Swing1.0 objects with future releases
of Swing. The JDK1.2 release of Swing will be the compatibility
baseline for the serialized form of Swing objects.
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SELECTION_MODE_PROPERTY
public static final String SELECTION_MODE_PROPERTY
- Property name for selectionMode.
changeSupport
protected PropertyChangeSupport changeSupport
- Used to messaged registered listeners.
selection
protected TreePath[] selection
- Paths that are currently selected. Will be null if nothing is
currently selected.
listenerList
protected EventListenerList listenerList
- Event listener list.
rowMapper
protected transient RowMapper rowMapper
- Provides a row for a given path.
listSelectionModel
protected DefaultListSelectionModel listSelectionModel
- Handles maintaining the list selection model.
selectionMode
protected int selectionMode
- Mode for the selection, will be either SINGLE_TREE_SELECTION,
CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
leadPath
protected TreePath leadPath
- Last path that was added.
leadIndex
protected int leadIndex
- Index of the lead path in selection.
leadRow
protected int leadRow
- Lead row.
DefaultTreeSelectionModel
public DefaultTreeSelectionModel()
setRowMapper
public void setRowMapper(RowMapper newMapper)
- Sets the RowMapper instance. This instance is used to determine
what row corresponds to what path.
- Implements:
- setRowMapper in interface TreeSelectionModel
getRowMapper
public RowMapper getRowMapper()
- Returns the RowMapper instance that is able to map a path to a
row.
- Implements:
- getRowMapper in interface TreeSelectionModel
setSelectionMode
public void setSelectionMode(int mode)
- Sets the selection model, which must be one of SINGLE_TREE_SELECTION,
CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
- Implements:
- setSelectionMode in interface TreeSelectionModel
getSelectionMode
public int getSelectionMode()
- Returns the selection mode.
- Implements:
- getSelectionMode in interface TreeSelectionModel
setSelectionPath
public void setSelectionPath(TreePath path)
- Sets the selection to path. If this represents a change, then
the TreeSelectionListeners are notified.
- Implements:
- setSelectionPath in interface TreeSelectionModel
- Parameters:
path
- new path to select
setSelectionPaths
public void setSelectionPaths(TreePath[] pPaths)
- Sets the selection to the paths in paths. If this represents a
change the TreeSelectionListeners are notified. Potentially
paths will be held by the reciever, in other words don't change
any of the objects in the array once passed in.
- Implements:
- setSelectionPaths in interface TreeSelectionModel
- Parameters:
paths
- new selection.
addSelectionPath
public void addSelectionPath(TreePath path)
- Adds path to the current selection. If path is not currently
in the selection the TreeSelectionListeners are notified.
- Implements:
- addSelectionPath in interface TreeSelectionModel
- Parameters:
path
- the new path to add to the current selection.
addSelectionPaths
public void addSelectionPaths(TreePath[] paths)
- Adds paths to the current selection. If any of the paths in
paths are not currently in the selection the TreeSelectionListeners
are notified.
- Implements:
- addSelectionPaths in interface TreeSelectionModel
- Parameters:
path
- the new path to add to the current selection.
removeSelectionPath
public void removeSelectionPath(TreePath path)
- Removes path from the selection. If path is in the selection
The TreeSelectionListeners are notified.
- Implements:
- removeSelectionPath in interface TreeSelectionModel
- Parameters:
path
- the path to remove from the selection.
removeSelectionPaths
public void removeSelectionPaths(TreePath[] paths)
- Removes paths from the selection. If any of the paths in paths
are in the selection the TreeSelectionListeners are notified.
- Implements:
- removeSelectionPaths in interface TreeSelectionModel
- Parameters:
path
- the path to remove from the selection.
getSelectionPath
public TreePath getSelectionPath()
- Returns the first path in the selection.
- Implements:
- getSelectionPath in interface TreeSelectionModel
getSelectionPaths
public TreePath[] getSelectionPaths()
- Returns the paths in the selection.
- Implements:
- getSelectionPaths in interface TreeSelectionModel
getSelectionCount
public int getSelectionCount()
- Returns the number of paths that are selected.
- Implements:
- getSelectionCount in interface TreeSelectionModel
isPathSelected
public boolean isPathSelected(TreePath path)
- Returns true if the path, path, is in the current selection.
- Implements:
- isPathSelected in interface TreeSelectionModel
isSelectionEmpty
public boolean isSelectionEmpty()
- Returns true if the selection is currently empty.
- Implements:
- isSelectionEmpty in interface TreeSelectionModel
clearSelection
public void clearSelection()
- Empties the current selection. If this represents a change in the
current selection, the selection listeners are notified.
- Implements:
- clearSelection in interface TreeSelectionModel
addTreeSelectionListener
public void addTreeSelectionListener(TreeSelectionListener x)
- Adds x to the list of listeners that are notified each time the
selection changes.
- Implements:
- addTreeSelectionListener in interface TreeSelectionModel
- Parameters:
x
- the new listener to be added.
removeTreeSelectionListener
public void removeTreeSelectionListener(TreeSelectionListener x)
- Removes x from the list of listeners that are notified each time
the selection changes.
- Implements:
- removeTreeSelectionListener in interface TreeSelectionModel
- Parameters:
x
- the listener to remove.
fireValueChanged
protected void fireValueChanged(TreeSelectionEvent e)
getSelectionRows
public int[] getSelectionRows()
- Returns all of the currently selected rows.
- Implements:
- getSelectionRows in interface TreeSelectionModel
getMinSelectionRow
public int getMinSelectionRow()
- Gets the first selected row.
- Implements:
- getMinSelectionRow in interface TreeSelectionModel
getMaxSelectionRow
public int getMaxSelectionRow()
- Gets the last selected row.
- Implements:
- getMaxSelectionRow in interface TreeSelectionModel
isRowSelected
public boolean isRowSelected(int row)
- Returns true if the row identitifed by row is selected.
- Implements:
- isRowSelected in interface TreeSelectionModel
resetRowSelection
public void resetRowSelection()
- Recalculates what rows are selected by asking the RowMapper for the
row for each path.
- Implements:
- resetRowSelection in interface TreeSelectionModel
getLeadSelectionRow
public int getLeadSelectionRow()
- Returns the lead selection index. That is the last index that was
added.
- Implements:
- getLeadSelectionRow in interface TreeSelectionModel
getLeadSelectionPath
public TreePath getLeadSelectionPath()
- Returns the last path that was added.
- Implements:
- getLeadSelectionPath in interface TreeSelectionModel
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
- Add a PropertyChangeListener to the listener list.
The listener is registered for all properties.
A PropertyChangeEvent will get fired in response to an
explicit setFont, setBackground, or SetForeground on the
current component. Note that if the current component is
inheriting its foreground, background, or font from its
container, then no event will be fired in response to a
change in the inherited property.
- Implements:
- addPropertyChangeListener in interface TreeSelectionModel
- Parameters:
listener
- The PropertyChangeListener to be added
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
- Remove a PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered
for all properties.
- Implements:
- removePropertyChangeListener in interface TreeSelectionModel
- Parameters:
listener
- The PropertyChangeListener to be removed
insureRowContinuity
protected void insureRowContinuity()
- Useful for CONTIGUOUS_TREE_SELECTION. If the rows that are selected
are not contiguous then the selection is reset to be contiguous.
Or if the selection mode is single selection and more than one
this is selected the selection is reset.
arePathsContiguous
protected boolean arePathsContiguous(TreePath[] paths)
- Returns true if the paths are contiguous.
canPathsBeAdded
protected boolean canPathsBeAdded(TreePath[] paths)
- Returns true if the paths can be added without breaking the
continuity of the model.
canPathsBeRemoved
protected boolean canPathsBeRemoved(TreePath[] paths)
- Returns true if the paths can be removed without breaking the
continuity of the model.
This is rather expensive.
notifyPathChange
protected void notifyPathChange(Vector changedPaths,
TreePath oldLeadSelection)
- Notifies listeners of a change in path. changePaths should contain
instances of PathPlaceHolder.
updateLeadIndex
protected void updateLeadIndex()
- Updates the leadIndex instance variable.
insureUniqueness
protected void insureUniqueness()
- Insures that all the elements in path are unique. This does not
check for a null selection!
toString
public String toString()
- Overrides:
- toString in class Object
clone
public Object clone() throws CloneNotSupportedException
- Returns a clone of the reciever with the same selection.
selectionListeners, and PropertyListeners are not duplicated.
- Throws:
- CloneNotSupportedException - if the receiver does not
both (a) implement the Cloneable interface and (b) define a
clone
method. - Overrides:
- clone in class Object
Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.