public class DefaultTreeSelectionModel extends Object implements Cloneable, Serializable, TreeSelectionModel
Modifier and Type | Field and Description |
---|---|
protected SwingPropertyChangeSupport |
changeSupport
Our Swing property change support.
|
protected int |
leadIndex
The index of the last added path.
|
protected TreePath |
leadPath
The path that has been added last.
|
protected int |
leadRow
The row of the last added path according to the RowMapper.
|
protected EventListenerList |
listenerList
Our TreeSelectionListeners.
|
protected DefaultListSelectionModel |
listSelectionModel
The current listSelectionModel.
|
protected RowMapper |
rowMapper
The current RowMapper.
|
protected TreePath[] |
selection
The current selection.
|
static String |
SELECTION_MODE_PROPERTY
The name of the selection mode property.
|
protected int |
selectionMode
The current selection mode.
|
CONTIGUOUS_TREE_SELECTION, DISCONTIGUOUS_TREE_SELECTION, SINGLE_TREE_SELECTION
Constructor and Description |
---|
DefaultTreeSelectionModel()
Constructs a new DefaultTreeSelectionModel.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a
PropertyChangeListener object to this model. |
void |
addSelectionPath(TreePath path)
Adds a path to the list of selected paths.
|
void |
addSelectionPaths(TreePath[] paths)
Adds the paths to the list of selected paths.
|
void |
addTreeSelectionListener(TreeSelectionListener listener)
Adds a
TreeSelectionListener object to this model. |
protected boolean |
arePathsContiguous(TreePath[] paths)
Returns
true if the paths are contiguous (take subsequent
rows in the diplayed tree view. |
protected boolean |
canPathsBeAdded(TreePath[] paths)
Checks if the paths can be added.
|
protected boolean |
canPathsBeRemoved(TreePath[] paths)
Checks if the paths can be removed without breaking the continuity of the
selection according to selectionMode.
|
void |
clearSelection()
Removes all paths from the selection.
|
Object |
clone()
Creates a clone of this DefaultTreeSelectionModel with the same selection.
|
protected void |
fireValueChanged(TreeSelectionEvent event)
fireValueChanged
|
TreePath |
getLeadSelectionPath()
getLeadSelectionPath
|
int |
getLeadSelectionRow()
getLeadSelectionRow
|
<T extends EventListener> |
getListeners(Class<T> listenerType)
Returns all added listeners of a special type.
|
int |
getMaxSelectionRow()
Returns the largest row index from the selection.
|
int |
getMinSelectionRow()
Returns the smallest row index from the selection.
|
PropertyChangeListener[] |
getPropertyChangeListeners()
Returns all added
PropertyChangeListener objects. |
RowMapper |
getRowMapper()
Returns the RowMapper that is currently used to map between paths and their
rows.
|
int |
getSelectionCount()
Returns the number of paths in the selection.
|
int |
getSelectionMode()
Returns the current selection mode.
|
TreePath |
getSelectionPath()
Returns the first path in the selection.
|
TreePath[] |
getSelectionPaths()
Returns the complete selection.
|
int[] |
getSelectionRows()
Returns the currently selected rows.
|
TreeSelectionListener[] |
getTreeSelectionListeners()
Returns all
TreeSelectionListener added to this model. |
protected void |
insureRowContinuity()
Makes sure the currently selected paths are valid according to the current
selectionMode.
|
protected void |
insureUniqueness()
This method exists due historical reasons and returns without action
(unless overridden).
|
boolean |
isPathSelected(TreePath path)
Checks if a given path is in the selection.
|
boolean |
isRowSelected(int row)
Checks if a particular row is selected.
|
boolean |
isSelectionEmpty()
Checks if the selection is empty.
|
protected void |
notifyPathChange(Vector<javax.swing.tree.DefaultTreeSelectionModel.PathPlaceHolder> vPaths,
TreePath oldLeadSelection)
Notify the installed listeners that the given patches have changed.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a
PropertyChangeListener object from this model. |
void |
removeSelectionPath(TreePath path)
Removes the path from the selection.
|
void |
removeSelectionPaths(TreePath[] paths)
Removes the paths from the selection.
|
void |
removeTreeSelectionListener(TreeSelectionListener listener)
Removes a
TreeSelectionListener object from this model. |
void |
resetRowSelection()
Updates the mappings from TreePaths to row indices.
|
void |
setRowMapper(RowMapper mapper)
Sets the RowMapper that should be used to map between paths and their rows.
|
void |
setSelectionMode(int mode)
Sets the current selection mode.
|
void |
setSelectionPath(TreePath path)
Sets this path as the only selection.
|
void |
setSelectionPaths(TreePath[] paths)
Sets the paths as selection.
|
String |
toString()
Returns a string that shows this object's properties.
|
protected void |
updateLeadIndex()
Updates the lead selection row number after changing the lead selection
path.
|
public static final String SELECTION_MODE_PROPERTY
protected SwingPropertyChangeSupport changeSupport
protected EventListenerList listenerList
protected DefaultListSelectionModel listSelectionModel
protected int selectionMode
protected int leadIndex
protected int leadRow
public DefaultTreeSelectionModel()
public Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
- should not be thrown hereCloneable
public String toString()
toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)
public void setRowMapper(RowMapper mapper)
setRowMapper
in interface TreeSelectionModel
mapper
- the RowMapper to setRowMapper
public RowMapper getRowMapper()
getRowMapper
in interface TreeSelectionModel
RowMapper
public void setSelectionMode(int mode)
TreeSelectionModel.SINGLE_TREE_SELECTION
, TreeSelectionModel.CONTIGUOUS_TREE_SELECTION
and
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION
.setSelectionMode
in interface TreeSelectionModel
mode
- the selection mode to be setgetSelectionMode()
,
TreeSelectionModel.SINGLE_TREE_SELECTION
,
TreeSelectionModel.CONTIGUOUS_TREE_SELECTION
,
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION
public int getSelectionMode()
getSelectionMode
in interface TreeSelectionModel
setSelectionMode(int)
,
TreeSelectionModel.SINGLE_TREE_SELECTION
,
TreeSelectionModel.CONTIGUOUS_TREE_SELECTION
,
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION
public void setSelectionPath(TreePath path)
setSelectionPath
in interface TreeSelectionModel
path
- the path to set as selectionpublic void setSelectionPaths(TreePath[] paths)
setSelectionPaths
in interface TreeSelectionModel
paths
- the paths to set as selectionpublic void addSelectionPath(TreePath path)
addSelectionPath
in interface TreeSelectionModel
path
- the path to add to the selectionpublic void addSelectionPaths(TreePath[] paths)
addSelectionPaths
in interface TreeSelectionModel
paths
- the paths to add to the selectionpublic void removeSelectionPath(TreePath path)
removeSelectionPath
in interface TreeSelectionModel
path
- the path to removepublic void removeSelectionPaths(TreePath[] paths)
removeSelectionPaths
in interface TreeSelectionModel
paths
- the paths to removepublic TreePath getSelectionPath()
TreeSelectionModel.SINGLE_TREE_SELECTION
.getSelectionPath
in interface TreeSelectionModel
public TreePath[] getSelectionPaths()
getSelectionPaths
in interface TreeSelectionModel
public int getSelectionCount()
getSelectionCount
in interface TreeSelectionModel
public boolean isPathSelected(TreePath path)
isPathSelected
in interface TreeSelectionModel
path
- the path to checktrue
if the path is in the selection,
false
otherwisepublic boolean isSelectionEmpty()
isSelectionEmpty
in interface TreeSelectionModel
true
if the selection is empty, false
otherwisepublic void clearSelection()
clearSelection
in interface TreeSelectionModel
public void addTreeSelectionListener(TreeSelectionListener listener)
TreeSelectionListener
object to this model.addTreeSelectionListener
in interface TreeSelectionModel
listener
- the listener to addpublic void removeTreeSelectionListener(TreeSelectionListener listener)
TreeSelectionListener
object from this model.removeTreeSelectionListener
in interface TreeSelectionModel
listener
- the listener to removepublic TreeSelectionListener[] getTreeSelectionListeners()
TreeSelectionListener
added to this model.protected void fireValueChanged(TreeSelectionEvent event)
event
- the event to fire.public <T extends EventListener> T[] getListeners(Class<T> listenerType)
listenerType
- the listener typepublic int[] getSelectionRows()
getSelectionRows
in interface TreeSelectionModel
public int getMinSelectionRow()
getMinSelectionRow
in interface TreeSelectionModel
public int getMaxSelectionRow()
getMaxSelectionRow
in interface TreeSelectionModel
public boolean isRowSelected(int row)
isRowSelected
in interface TreeSelectionModel
row
- the index of the row to checktrue
if the row is in this selection,
false
otherwiseNullPointerException
- if the row mapper is not set (can only happen
if the user has plugged in the custom incorrect TreeUI
implementation.public void resetRowSelection()
resetRowSelection
in interface TreeSelectionModel
public int getLeadSelectionRow()
getLeadSelectionRow
in interface TreeSelectionModel
public TreePath getLeadSelectionPath()
getLeadSelectionPath
in interface TreeSelectionModel
public void addPropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
object to this model.addPropertyChangeListener
in interface TreeSelectionModel
listener
- the listener to add.public void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
object from this model.removePropertyChangeListener
in interface TreeSelectionModel
listener
- the listener to remove.public PropertyChangeListener[] getPropertyChangeListeners()
PropertyChangeListener
objects.protected void insureRowContinuity()
TreeSelectionModel.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 to TreeSelectionModel.SINGLE_TREE_SELECTION
and the selection
has more than one path, the selection is reset to the contain only the
first path.protected boolean arePathsContiguous(TreePath[] paths)
true
if the paths are contiguous (take subsequent
rows in the diplayed tree view. The method returns true
if
we have no RowMapper assigned.paths
- the paths to check for continuitytrue
if the paths are contiguous or we have no
RowMapper assignedprotected boolean canPathsBeAdded(TreePath[] paths)
true
if:
paths
is null
or emptyTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION
paths
- the paths to checktrue
if the paths can be added with respect to the
selectionModeprotected boolean canPathsBeRemoved(TreePath[] paths)
paths
- the paths to checktrue
if the paths can be removed with respect to the
selectionModeprotected void notifyPathChange(Vector<javax.swing.tree.DefaultTreeSelectionModel.PathPlaceHolder> vPaths, TreePath oldLeadSelection)
vPaths
- the vector of the changed patchesoldLeadSelection
- the old selection indexprotected void updateLeadIndex()
protected void insureUniqueness()
setSelectionPaths(TreePath[])
and
addSelectionPaths(TreePath[])
.