Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.swing.tree.DefaultTreeSelectionModel
public class DefaultTreeSelectionModel
extends Object
implements Cloneable, Serializable, TreeSelectionModel
Field Summary | |
static String |
|
protected SwingPropertyChangeSupport |
|
protected int |
|
protected TreePath |
|
protected int |
|
protected DefaultListSelectionModel |
|
protected EventListenerList |
|
protected RowMapper |
|
protected TreePath[] |
|
protected int |
|
Fields inherited from interface javax.swing.tree.TreeSelectionModel | |
CONTIGUOUS_TREE_SELECTION , DISCONTIGUOUS_TREE_SELECTION , SINGLE_TREE_SELECTION |
Constructor Summary | |
|
Method Summary | |
void |
|
void |
|
void |
|
void |
|
protected boolean |
|
protected boolean |
|
protected boolean |
|
void |
|
Object |
|
|
|
protected void |
|
TreePath |
|
int |
|
int |
|
int |
|
PropertyChangeListener[] |
|
RowMapper |
|
int |
|
int |
|
TreePath |
|
TreePath[] |
|
int[] |
|
TreeSelectionListener[] |
|
protected void |
|
protected void |
|
boolean |
|
boolean |
|
boolean |
|
protected void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
String |
|
protected void |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public static final String SELECTION_MODE_PROPERTY
The name of the selection mode property.
- Field Value:
- "selectionMode"
protected DefaultListSelectionModel listSelectionModel
The current listSelectionModel.
public DefaultTreeSelectionModel()
Constructs a new DefaultTreeSelectionModel.
public void addPropertyChangeListener(PropertyChangeListener listener)
Adds aPropertyChangeListener
object to this model.
- Specified by:
- addPropertyChangeListener in interface TreeSelectionModel
- Parameters:
listener
- the listener to add.
public void addSelectionPath(TreePath path)
Adds a path to the list of selected paths. This method checks if the path is already selected and doesn't add the same path twice. If this changes the selection the registered TreeSelectionListeners are notified. The lead path is changed to the added path. This also happen if the passed path was already selected before.
- Specified by:
- addSelectionPath in interface TreeSelectionModel
- Parameters:
path
- the path to add to the selection
public void addSelectionPaths(TreePath[] paths)
Adds the paths to the list of selected paths. This method checks if the paths are already selected and doesn't add the same path twice. If this changes the selection the registered TreeSelectionListeners are notified.
- Specified by:
- addSelectionPaths in interface TreeSelectionModel
- Parameters:
paths
- the paths to add to the selection
public void addTreeSelectionListener(TreeSelectionListener listener)
Adds aTreeSelectionListener
object to this model.
- Specified by:
- addTreeSelectionListener in interface TreeSelectionModel
- Parameters:
listener
- the listener to add
protected boolean arePathsContiguous(TreePath[] paths)
Returnstrue
if the paths are contiguous (take subsequent rows in the diplayed tree view. The method returnstrue
if we have no RowMapper assigned.
- Parameters:
paths
- the paths to check for continuity
- Returns:
true
if the paths are contiguous or we have no RowMapper assigned
protected boolean canPathsBeAdded(TreePath[] paths)
Checks if the paths can be added. This returnstrue
if:
paths
isnull
or empty- we have no RowMapper assigned
- nothing is currently selected
- selectionMode is
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION
- adding the paths to the selection still results in a contiguous set of paths
- Parameters:
paths
- the paths to check
- Returns:
true
if the paths can be added with respect to the selectionMode
protected boolean canPathsBeRemoved(TreePath[] paths)
Checks if the paths can be removed without breaking the continuity of the selection according to selectionMode.
- Parameters:
paths
- the paths to check
- Returns:
true
if the paths can be removed with respect to the selectionMode
public void clearSelection()
Removes all paths from the selection. Fire the unselection event.
- Specified by:
- clearSelection in interface TreeSelectionModel
public Object clone() throws CloneNotSupportedException
Creates a clone of this DefaultTreeSelectionModel with the same selection. The cloned instance will have the same registered listeners, the listeners themselves will not be cloned. The selection will be cloned.
- Returns:
- a copy of this DefaultTreeSelectionModel
- Throws:
CloneNotSupportedException
- should not be thrown here
publicextends EventListener> T[] getListeners (ClasslistenerType)
Returns all added listeners of a special type.
- Parameters:
listenerType
- the listener type
- Returns:
- an array of listeners
- Since:
- 1.3
protected void fireValueChanged(TreeSelectionEvent event)
fireValueChanged
- Parameters:
event
- the event to fire.
public TreePath getLeadSelectionPath()
getLeadSelectionPath
- Specified by:
- getLeadSelectionPath in interface TreeSelectionModel
- Returns:
- TreePath
public int getLeadSelectionRow()
getLeadSelectionRow
- Specified by:
- getLeadSelectionRow in interface TreeSelectionModel
- Returns:
- int
public int getMaxSelectionRow()
Returns the largest row index from the selection.
- Specified by:
- getMaxSelectionRow in interface TreeSelectionModel
- Returns:
- the largest row index from the selection
public int getMinSelectionRow()
Returns the smallest row index from the selection.
- Specified by:
- getMinSelectionRow in interface TreeSelectionModel
- Returns:
- the smallest row index from the selection
public PropertyChangeListener[] getPropertyChangeListeners()
Returns all addedPropertyChangeListener
objects.
- Returns:
- an array of listeners.
- Since:
- 1.4
public RowMapper getRowMapper()
Returns the RowMapper that is currently used to map between paths and their rows.
- Specified by:
- getRowMapper in interface TreeSelectionModel
- Returns:
- the current RowMapper
- See Also:
RowMapper
public int getSelectionCount()
Returns the number of paths in the selection.
- Specified by:
- getSelectionCount in interface TreeSelectionModel
- Returns:
- the number of paths in the selection
public int getSelectionMode()
Returns the current selection mode.
- Specified by:
- getSelectionMode in interface TreeSelectionModel
- Returns:
- the current selection mode
public TreePath getSelectionPath()
Returns the first path in the selection. This is especially useful when the selectionMode isTreeSelectionModel.SINGLE_TREE_SELECTION
.
- Specified by:
- getSelectionPath in interface TreeSelectionModel
- Returns:
- the first path in the selection
public TreePath[] getSelectionPaths()
Returns the complete selection.
- Specified by:
- getSelectionPaths in interface TreeSelectionModel
- Returns:
- the complete selection
public int[] getSelectionRows()
Returns the currently selected rows.
- Specified by:
- getSelectionRows in interface TreeSelectionModel
- Returns:
- the currently selected rows
public TreeSelectionListener[] getTreeSelectionListeners()
Returns allTreeSelectionListener
added to this model.
- Returns:
- an array of listeners
- Since:
- 1.4
protected void insureRowContinuity()
Makes sure the currently selected paths are valid according to the current selectionMode. If the selectionMode is set toTreeSelectionModel.CONTIGUOUS_TREE_SELECTION
and the selection isn't contiguous then the selection is reset to the first set of contguous paths. If the selectionMode is set toTreeSelectionModel.SINGLE_TREE_SELECTION
and the selection has more than one path, the selection is reset to the contain only the first path.
protected void insureUniqueness()
This method exists due historical reasons and returns without action (unless overridden). For compatibility with the applications that override it, it is still called from thesetSelectionPaths(TreePath[])
andaddSelectionPaths(TreePath[])
.
public boolean isPathSelected(TreePath path)
Checks if a given path is in the selection.
- Specified by:
- isPathSelected in interface TreeSelectionModel
- Parameters:
path
- the path to check
- Returns:
true
if the path is in the selection,false
otherwise
public boolean isRowSelected(int row)
Checks if a particular row is selected.
- Specified by:
- isRowSelected in interface TreeSelectionModel
- Parameters:
row
- the index of the row to check
- Returns:
true
if the row is in this selection,false
otherwise
- Throws:
NullPointerException
- if the row mapper is not set (can only happen if the user has plugged in the custom incorrect TreeUI implementation.
public boolean isSelectionEmpty()
Checks if the selection is empty.
- Specified by:
- isSelectionEmpty in interface TreeSelectionModel
- Returns:
true
if the selection is empty,false
otherwise
protected void notifyPathChange(VectorvPaths, TreePath oldLeadSelection)
Notify the installed listeners that the given patches have changed. This method will call listeners if invoked, but it is not called from the implementation of this class.
- Parameters:
vPaths
- the vector of the changed patchesoldLeadSelection
- the old selection index
public void removePropertyChangeListener(PropertyChangeListener listener)
Removes aPropertyChangeListener
object from this model.
- Specified by:
- removePropertyChangeListener in interface TreeSelectionModel
- Parameters:
listener
- the listener to remove.
public void removeSelectionPath(TreePath path)
Removes the path from the selection. If this changes the selection the registered TreeSelectionListeners are notified.
- Specified by:
- removeSelectionPath in interface TreeSelectionModel
- Parameters:
path
- the path to remove
public void removeSelectionPaths(TreePath[] paths)
Removes the paths from the selection. If this changes the selection the registered TreeSelectionListeners are notified.
- Specified by:
- removeSelectionPaths in interface TreeSelectionModel
- Parameters:
paths
- the paths to remove
public void removeTreeSelectionListener(TreeSelectionListener listener)
Removes aTreeSelectionListener
object from this model.
- Specified by:
- removeTreeSelectionListener in interface TreeSelectionModel
- Parameters:
listener
- the listener to remove
public void resetRowSelection()
Updates the mappings from TreePaths to row indices.
- Specified by:
- resetRowSelection in interface TreeSelectionModel
public void setRowMapper(RowMapper mapper)
Sets the RowMapper that should be used to map between paths and their rows.
- Specified by:
- setRowMapper in interface TreeSelectionModel
- Parameters:
mapper
- the RowMapper to set
- See Also:
RowMapper
public void setSelectionMode(int mode)
Sets the current selection mode. Possible values areTreeSelectionModel.SINGLE_TREE_SELECTION
,TreeSelectionModel.CONTIGUOUS_TREE_SELECTION
andTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION
.
- Specified by:
- setSelectionMode in interface TreeSelectionModel
- Parameters:
mode
- the selection mode to be set
public void setSelectionPath(TreePath path)
Sets this path as the only selection. If this changes the selection the registered TreeSelectionListeners are notified.
- Specified by:
- setSelectionPath in interface TreeSelectionModel
- Parameters:
path
- the path to set as selection
public void setSelectionPaths(TreePath[] paths)
Sets the paths as selection. This method checks for duplicates and removes them. If this changes the selection the registered TreeSelectionListeners are notified.
- Specified by:
- setSelectionPaths in interface TreeSelectionModel
- Parameters:
paths
- the paths to set as selection
public String toString()
Returns a string that shows this object's properties. The returned string lists the selected tree rows, if any.
- Returns:
- a string that shows this object's properties
protected void updateLeadIndex()
Updates the lead selection row number after changing the lead selection path.