public class CheckBoxTreeSelectionModel
extends javax.swing.tree.DefaultTreeSelectionModel
implements javax.swing.event.TreeModelListener
CheckBoxTreeSelectionModel is a selection _model based on DefaultTreeSelectionModel and use in
CheckBoxTree to keep track of the checked tree paths.| Modifier and Type | Field and Description |
|---|---|
protected java.util.Set<javax.swing.tree.TreePath> |
_pathHasAdded
Used in
areSiblingsSelected(javax.swing.tree.TreePath) for those paths pending added so that they are not
in the selection model right now. |
| Constructor and Description |
|---|
CheckBoxTreeSelectionModel(javax.swing.tree.TreeModel model) |
CheckBoxTreeSelectionModel(javax.swing.tree.TreeModel model,
boolean digIn) |
| Modifier and Type | Method and Description |
|---|---|
void |
addSelectionPaths(javax.swing.tree.TreePath[] paths)
Overrides the method in DefaultTreeSelectionModel to consider digIn mode.
|
protected void |
addSelectionPaths(javax.swing.tree.TreePath[] paths,
boolean needCheckPathSelection)
Add the selection paths.
|
protected boolean |
areSiblingsSelected(javax.swing.tree.TreePath path)
tells whether all siblings of given path are selected.
|
protected java.lang.Object |
getChild(java.lang.Object node,
int i)
Get the child of node in the designated index.
|
protected int |
getChildrenCount(java.lang.Object node)
Get the children count
|
javax.swing.tree.TreeModel |
getModel() |
boolean |
isDigIn()
Gets the dig-in mode.
|
protected boolean |
isParentActuallySelected(javax.swing.tree.TreePath path,
javax.swing.tree.TreePath parent)
Check if the parent path is really selected.
|
boolean |
isPartiallySelected(javax.swing.tree.TreePath path)
Tests whether there is any unselected node in the subtree of given path.
|
boolean |
isPathSelected(javax.swing.tree.TreePath path) |
boolean |
isPathSelected(javax.swing.tree.TreePath path,
boolean digIn)
Tells whether given path is selected.
|
boolean |
isRowSelected(int row) |
boolean |
isSingleEventMode() |
protected void |
notifyPathChange(javax.swing.tree.TreePath[] changedPaths,
boolean isNew,
javax.swing.tree.TreePath oldLeadSelection)
Notifies listeners of a change in path.
|
protected void |
notifyPathChange(java.util.Vector changedPaths,
javax.swing.tree.TreePath oldLeadSelection) |
void |
removeSelectionPaths(javax.swing.tree.TreePath[] paths) |
void |
removeSelectionPaths(javax.swing.tree.TreePath[] paths,
boolean doFireEvent) |
void |
setBatchMode(boolean batchMode) |
void |
setDigIn(boolean digIn)
Sets the dig-in mode.
|
void |
setModel(javax.swing.tree.TreeModel model) |
void |
setSelectionPaths(javax.swing.tree.TreePath[] pPaths)
Overrides the method in DefaultTreeSelectionModel to consider digIn mode.
|
void |
setSingleEventMode(boolean singleEventMode)
Single event mode is a mode that always fires only one event when you select or deselect a tree node.
|
void |
treeNodesChanged(javax.swing.event.TreeModelEvent e) |
void |
treeNodesInserted(javax.swing.event.TreeModelEvent e) |
void |
treeNodesRemoved(javax.swing.event.TreeModelEvent e) |
void |
treeStructureChanged(javax.swing.event.TreeModelEvent e) |
addPropertyChangeListener, addSelectionPath, addTreeSelectionListener, arePathsContiguous, canPathsBeAdded, canPathsBeRemoved, clearSelection, clone, fireValueChanged, getLeadSelectionPath, getLeadSelectionRow, getListeners, getMaxSelectionRow, getMinSelectionRow, getPropertyChangeListeners, getRowMapper, getSelectionCount, getSelectionMode, getSelectionPath, getSelectionPaths, getSelectionRows, getTreeSelectionListeners, insureRowContinuity, insureUniqueness, isSelectionEmpty, removePropertyChangeListener, removeSelectionPath, removeTreeSelectionListener, resetRowSelection, setRowMapper, setSelectionMode, setSelectionPath, toString, updateLeadIndexprotected java.util.Set<javax.swing.tree.TreePath> _pathHasAdded
areSiblingsSelected(javax.swing.tree.TreePath) for those paths pending added so that they are not
in the selection model right now.public CheckBoxTreeSelectionModel(javax.swing.tree.TreeModel model)
public CheckBoxTreeSelectionModel(javax.swing.tree.TreeModel model,
boolean digIn)
public javax.swing.tree.TreeModel getModel()
public void setModel(javax.swing.tree.TreeModel model)
public boolean isDigIn()
public void setDigIn(boolean digIn)
digIn - true to enable dig-in mode. False to disable it.public boolean isPartiallySelected(javax.swing.tree.TreePath path)
path - check if the path is partially selected.public boolean isRowSelected(int row)
isRowSelected in interface javax.swing.tree.TreeSelectionModelisRowSelected in class javax.swing.tree.DefaultTreeSelectionModelprotected boolean isParentActuallySelected(javax.swing.tree.TreePath path,
javax.swing.tree.TreePath parent)
path - the original path to be checkedparent - the parent part which is closest to the original path and is selectedpublic boolean isPathSelected(javax.swing.tree.TreePath path)
isPathSelected in interface javax.swing.tree.TreeSelectionModelisPathSelected in class javax.swing.tree.DefaultTreeSelectionModelpublic boolean isPathSelected(javax.swing.tree.TreePath path,
boolean digIn)
path - check if the path is selected.digIn - whether we will check its descendants.protected void notifyPathChange(java.util.Vector changedPaths,
javax.swing.tree.TreePath oldLeadSelection)
notifyPathChange in class javax.swing.tree.DefaultTreeSelectionModelpublic void setSelectionPaths(javax.swing.tree.TreePath[] pPaths)
setSelectionPaths in interface javax.swing.tree.TreeSelectionModelsetSelectionPaths in class javax.swing.tree.DefaultTreeSelectionModelpPaths - the tree paths to be selected.public void addSelectionPaths(javax.swing.tree.TreePath[] paths)
addSelectionPaths in interface javax.swing.tree.TreeSelectionModeladdSelectionPaths in class javax.swing.tree.DefaultTreeSelectionModelpaths - the tree paths to be added to selection paths.protected void addSelectionPaths(javax.swing.tree.TreePath[] paths,
boolean needCheckPathSelection)
paths - the paths to be addedneedCheckPathSelection - the flag to indicating if the path selection should be checked to improve performanceprotected boolean areSiblingsSelected(javax.swing.tree.TreePath path)
path - the tree pathpublic void removeSelectionPaths(javax.swing.tree.TreePath[] paths)
removeSelectionPaths in interface javax.swing.tree.TreeSelectionModelremoveSelectionPaths in class javax.swing.tree.DefaultTreeSelectionModelpublic void removeSelectionPaths(javax.swing.tree.TreePath[] paths,
boolean doFireEvent)
protected java.lang.Object getChild(java.lang.Object node,
int i)
node - the parent nodei - the child indexprotected int getChildrenCount(java.lang.Object node)
node - the parent nodepublic boolean isSingleEventMode()
public void setSingleEventMode(boolean singleEventMode)
A -- a
|- b
|- c
Case 1: Assuming b and c are selected at this point, you click on a. DefaultTreeSelectionModel.getSelectionPaths() to
find out. In non-single event mode, the events reflect what happened inside the selection model. So you can get a
complete picture of the exact state without asking the selection model. The downside is it will generate too many
events. With this option, you can decide which mode you want to use that is the best for your case.
By default, singleEventMode is set to false to be compatible with the older versions that don't have this
option.singleEventMode - true or false.protected void notifyPathChange(javax.swing.tree.TreePath[] changedPaths,
boolean isNew,
javax.swing.tree.TreePath oldLeadSelection)
changedPaths - the paths that are changed.isNew - is it a new path.oldLeadSelection - the old selection.public void setBatchMode(boolean batchMode)
public void treeNodesChanged(javax.swing.event.TreeModelEvent e)
treeNodesChanged in interface javax.swing.event.TreeModelListenerpublic void treeNodesInserted(javax.swing.event.TreeModelEvent e)
treeNodesInserted in interface javax.swing.event.TreeModelListenerpublic void treeNodesRemoved(javax.swing.event.TreeModelEvent e)
treeNodesRemoved in interface javax.swing.event.TreeModelListenerpublic void treeStructureChanged(javax.swing.event.TreeModelEvent e)
treeStructureChanged in interface javax.swing.event.TreeModelListener