All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.java.swing.tree.DefaultTreeSelectionModel
java.lang.Object
|
+----com.sun.java.swing.tree.DefaultTreeSelectionModel
- 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.
-
changeSupport
- Used to messaged registered listeners.
-
leadIndex
- Index of the lead path in selection.
-
leadPath
- Last path that was added.
-
leadRow
- Lead row.
-
listenerList
- Event listener list.
-
listSelectionModel
- Handles maintaining the list selection model.
-
rowMapper
- Provides a row for a given path.
-
selection
- Paths that are currently selected.
-
SELECTION_MODE_PROPERTY
- Property name for selectionMode.
-
selectionMode
- Mode for the selection, will be either SINGLE_TREE_SELECTION,
CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
-
DefaultTreeSelectionModel()
-
-
addPropertyChangeListener(PropertyChangeListener)
- Add a PropertyChangeListener to the listener list.
-
addSelectionPath(TreePath)
- Adds path to the current selection.
-
addSelectionPaths(TreePath[])
- Adds paths to the current selection.
-
addTreeSelectionListener(TreeSelectionListener)
- Adds x to the list of listeners that are notified each time the
selection changes.
-
arePathsContiguous(TreePath[])
- Returns true if the paths are contiguous.
-
canPathsBeAdded(TreePath[])
- Returns true if the paths can be added without breaking the
continuity of the model.
-
canPathsBeRemoved(TreePath[])
- Returns true if the paths can be removed without breaking the
continuity of the model.
-
clearSelection()
- Empties the current selection.
-
clone()
- Returns a clone of the reciever with the same selection.
-
fireValueChanged(TreeSelectionEvent)
-
-
getLeadSelectionPath()
- Returns the last path that was added.
-
getLeadSelectionRow()
- Returns the lead selection index.
-
getMaxSelectionRow()
- Gets the last selected row.
-
getMinSelectionRow()
- Gets the first selected row.
-
getRowMapper()
- Returns the RowMapper instance that is able to map a path to a
row.
-
getSelectionCount()
- Returns the number of paths that are selected.
-
getSelectionMode()
- Returns the selection mode.
-
getSelectionPath()
- Returns the first path in the selection.
-
getSelectionPaths()
- Returns the paths in the selection.
-
getSelectionRows()
- Returns all of the currently selected rows.
-
insureRowContinuity()
- Useful for CONTIGUOUS_TREE_SELECTION.
-
insureUniqueness()
- Insures that all the elements in path are unique.
-
isPathSelected(TreePath)
- Returns true if the path, path, is in the current selection.
-
isRowSelected(int)
- Returns true if the row identitifed by row is selected.
-
isSelectionEmpty()
- Returns true if the selection is currently empty.
-
notifyPathChange(Vector, TreePath)
- Notifies listeners of a change in path.
-
removePropertyChangeListener(PropertyChangeListener)
- Remove a PropertyChangeListener from the listener list.
-
removeSelectionPath(TreePath)
- Removes path from the selection.
-
removeSelectionPaths(TreePath[])
- Removes paths from the selection.
-
removeTreeSelectionListener(TreeSelectionListener)
- Removes x from the list of listeners that are notified each time
the selection changes.
-
resetRowSelection()
- Recalculates what rows are selected by asking the RowMapper for the
row for each path.
-
setRowMapper(RowMapper)
- Sets the RowMapper instance.
-
setSelectionMode(int)
- Sets the selection model, which must be one of SINGLE_TREE_SELECTION,
CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
-
setSelectionPath(TreePath)
- Sets the selection to path.
-
setSelectionPaths(TreePath[])
- Sets the selection to the paths in paths.
-
toString()
-
-
updateLeadIndex()
- Updates the leadIndex instance variable.
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.
getRowMapper
public RowMapper getRowMapper()
- Returns the RowMapper instance that is able to map a path to a
row.
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.
getSelectionMode
public int getSelectionMode()
- Returns the selection mode.
setSelectionPath
public void setSelectionPath(TreePath path)
- Sets the selection to path. If this represents a change, then
the TreeSelectionListeners are notified.
- 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.
- 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.
- 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.
- 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.
- 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.
- Parameters:
- path - the path to remove from the selection.
getSelectionPath
public TreePath getSelectionPath()
- Returns the first path in the selection.
getSelectionPaths
public TreePath[] getSelectionPaths()
- Returns the paths in the selection.
getSelectionCount
public int getSelectionCount()
- Returns the number of paths that are selected.
isPathSelected
public boolean isPathSelected(TreePath path)
- Returns true if the path, path, is in the current selection.
isSelectionEmpty
public boolean isSelectionEmpty()
- Returns true if the selection is currently empty.
clearSelection
public void clearSelection()
- Empties the current selection. If this represents a change in the
current selection, the selection listeners are notified.
addTreeSelectionListener
public void addTreeSelectionListener(TreeSelectionListener x)
- Adds x to the list of listeners that are notified each time the
selection changes.
- 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.
- Parameters:
- x - the listener to remove.
fireValueChanged
protected void fireValueChanged(TreeSelectionEvent e)
getSelectionRows
public int[] getSelectionRows()
- Returns all of the currently selected rows.
getMinSelectionRow
public int getMinSelectionRow()
- Gets the first selected row.
getMaxSelectionRow
public int getMaxSelectionRow()
- Gets the last selected row.
isRowSelected
public boolean isRowSelected(int row)
- Returns true if the row identitifed by row is selected.
resetRowSelection
public void resetRowSelection()
- Recalculates what rows are selected by asking the RowMapper for the
row for each path.
getLeadSelectionRow
public int getLeadSelectionRow()
- Returns the lead selection index. That is the last index that was
added.
getLeadSelectionPath
public TreePath getLeadSelectionPath()
- Returns the last path that was added.
addPropertyChangeListener
public synchronized 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.
- Parameters:
- listener - The PropertyChangeListener to be added
removePropertyChangeListener
public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
- Remove a PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered
for all properties.
- 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
All Packages Class Hierarchy This Package Previous Next Index