com.alee.extended.tree
Class DefaultTreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>

java.lang.Object
  extended by com.alee.extended.tree.DefaultTreeCheckingModel<E>
All Implemented Interfaces:
TreeCheckingModel<E>

public class DefaultTreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>
extends java.lang.Object
implements TreeCheckingModel<E>

Default checking model for WebCheckBoxTree.

Author:
Mikle Garin

Field Summary
protected  WebCheckBoxTree<E> checkBoxTree
          Checkbox tree which uses this checking model.
protected  java.util.List<CheckStateChangeListener<E>> checkStateChangeListeners
          Checkbox tree check state change listeners.
protected  java.util.Map<E,CheckState> nodeCheckStates
          Node check states cache.
 
Constructor Summary
DefaultTreeCheckingModel(WebCheckBoxTree<E> checkBoxTree)
           
 
Method Summary
 void addCheckStateChangeListener(CheckStateChangeListener listener)
          Adds check state change listener.
 void checkAll()
          Checks all tree nodes.
 void checkingModeChanged(boolean recursive)
          Notifies model about checking mode change.
protected  void filterOutChildNodes(java.util.List<E> nodes)
          Filters out all nodes which are childs of other nodes presented in the list.
 void fireCheckStateChanged(java.util.List<CheckStateChange<E>> stateChanges)
          Informs about single or multiply check state changes.
protected  java.util.List<E> getAllNodesForState(CheckState state, boolean optimize)
          Returns list of nodes for the specified state.
 WebCheckBoxTree<E> getCheckBoxTree()
          Returns checkbox tree which uses this checking model.
 java.util.List<E> getCheckedNodes(boolean optimize)
          Returns list of checked nodes.
 CheckState getCheckState(E node)
          Returns specified tree node check state.
 java.util.List<E> getMixedNodes()
          Returns list of nodes in mixed state.
protected  CheckState getNextState(CheckState checkState)
          Returns next check state for check invertion action.
 void invertCheck(java.util.Collection<E> nodes)
          Inverts tree nodes check.
 void invertCheck(E node)
          Inverts tree node check.
protected  boolean isChildNode(E node, E childOf)
          Returns whether the specified node is a child of another node or some of its child nodes or not.
 void removeCheckStateChangeListener(CheckStateChangeListener listener)
          Removes check state change listener.
protected  void repaintTreeNodes(java.util.List<E> nodes)
          Repaints specified tree nodes.
protected  void repaintVisibleTreeRect()
          Repaints visible tree rect.
 void setCheckBoxTree(WebCheckBoxTree<E> checkBoxTree)
          Sets checkbox tree which uses this checking model.
 void setChecked(java.util.Collection<E> nodes, boolean checked)
          Sets specified nodes state to checked.
 void setChecked(E node, boolean checked)
          Sets whether the specified tree node is checked or not.
protected  void setCheckedImpl(E node, boolean checked, java.util.List<E> toUpdate, java.util.List<CheckStateChange<E>> changes)
          Sets whether the specified tree node is checked or not.
 void uncheckAll()
          Unchecks all tree nodes.
protected  void updateChildNodesState(E node, CheckState newState, java.util.List<E> toUpdate, java.util.List<CheckStateChange<E>> changes)
          Updates child nodes check state.
protected  void updateNodeState(E node, CheckState newState, java.util.List<E> toUpdate)
          Updates single node check state.
protected  void updateParentStates(E node, java.util.List<E> toUpdate, java.util.List<CheckStateChange<E>> changes)
          Updates parent nodes check states.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

checkBoxTree

protected WebCheckBoxTree<E extends javax.swing.tree.DefaultMutableTreeNode> checkBoxTree
Checkbox tree which uses this checking model.


nodeCheckStates

protected java.util.Map<E extends javax.swing.tree.DefaultMutableTreeNode,CheckState> nodeCheckStates
Node check states cache.


checkStateChangeListeners

protected java.util.List<CheckStateChangeListener<E extends javax.swing.tree.DefaultMutableTreeNode>> checkStateChangeListeners
Checkbox tree check state change listeners.

Constructor Detail

DefaultTreeCheckingModel

public DefaultTreeCheckingModel(WebCheckBoxTree<E> checkBoxTree)
Parameters:
checkBoxTree -
Method Detail

getCheckBoxTree

public WebCheckBoxTree<E> getCheckBoxTree()
Returns checkbox tree which uses this checking model.

Returns:
checkbox tree which uses this checking model

setCheckBoxTree

public void setCheckBoxTree(WebCheckBoxTree<E> checkBoxTree)
Sets checkbox tree which uses this checking model. This method call also forces cache to clear all stored values.

Parameters:
checkBoxTree - checkbox tree which uses this checking model.

getCheckedNodes

public java.util.List<E> getCheckedNodes(boolean optimize)
Returns list of checked nodes.

Specified by:
getCheckedNodes in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>
Parameters:
optimize - whether should optimize the resulting list by removing checked node childs or not
Returns:
list of checked nodes

getMixedNodes

public java.util.List<E> getMixedNodes()
Returns list of nodes in mixed state.

Specified by:
getMixedNodes in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>
Returns:
list of nodes in mixed state

getAllNodesForState

protected java.util.List<E> getAllNodesForState(CheckState state,
                                                boolean optimize)
Returns list of nodes for the specified state. For a reasonable cause this will not work for unchecked state.

Parameters:
state - check state
optimize -
Returns:
list of nodes for the specified state

setChecked

public void setChecked(java.util.Collection<E> nodes,
                       boolean checked)
Sets specified nodes state to checked.

Specified by:
setChecked in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>
Parameters:
nodes - nodes to check
checked - whether the specified tree nodes should be checked or not

getCheckState

public CheckState getCheckState(E node)
Returns specified tree node check state.

Specified by:
getCheckState in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>
Parameters:
node - tree node to process
Returns:
specified tree node check state

setChecked

public void setChecked(E node,
                       boolean checked)
Sets whether the specified tree node is checked or not.

Specified by:
setChecked in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>
Parameters:
node - tree node to process
checked - whether the specified tree node should be checked or not

setCheckedImpl

protected void setCheckedImpl(E node,
                              boolean checked,
                              java.util.List<E> toUpdate,
                              java.util.List<CheckStateChange<E>> changes)
Sets whether the specified tree node is checked or not.

Parameters:
node - tree node to process
checked - whether the specified tree node is checked or not
toUpdate - list of nodes for later update
changes -

updateParentStates

protected void updateParentStates(E node,
                                  java.util.List<E> toUpdate,
                                  java.util.List<CheckStateChange<E>> changes)
Updates parent nodes check states.

Parameters:
node - node to start checking parents from
toUpdate - list of nodes for later update
changes -

updateChildNodesState

protected void updateChildNodesState(E node,
                                     CheckState newState,
                                     java.util.List<E> toUpdate,
                                     java.util.List<CheckStateChange<E>> changes)
Updates child nodes check state.

Parameters:
node - parent node
newState - new check state
toUpdate - list of nodes for later update
changes -

updateNodeState

protected void updateNodeState(E node,
                               CheckState newState,
                               java.util.List<E> toUpdate)
Updates single node check state.

Parameters:
node - node to update
newState - new check state
toUpdate - list of nodes for later update

invertCheck

public void invertCheck(E node)
Inverts tree node check.

Specified by:
invertCheck in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>
Parameters:
node - tree node to process

invertCheck

public void invertCheck(java.util.Collection<E> nodes)
Inverts tree nodes check.

Specified by:
invertCheck in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>
Parameters:
nodes - list of tree nodes to process

uncheckAll

public void uncheckAll()
Unchecks all tree nodes.

Specified by:
uncheckAll in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>

checkAll

public void checkAll()
Checks all tree nodes.

Specified by:
checkAll in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>

getNextState

protected CheckState getNextState(CheckState checkState)
Returns next check state for check invertion action.

Parameters:
checkState - current check state
Returns:
next check state for check invertion action

checkingModeChanged

public void checkingModeChanged(boolean recursive)
Notifies model about checking mode change.

Specified by:
checkingModeChanged in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>
Parameters:
recursive - whether checked or unchecked node childs should be checked or unchecked recursively or not

filterOutChildNodes

protected void filterOutChildNodes(java.util.List<E> nodes)
Filters out all nodes which are childs of other nodes presented in the list.

Parameters:
nodes - list of nodes to filter

isChildNode

protected boolean isChildNode(E node,
                              E childOf)
Returns whether the specified node is a child of another node or some of its child nodes or not.

Parameters:
node - node to process
childOf - node to compare parent nodes with
Returns:
true if the specified node is a child of another node or some of its child nodes, false otherwise

repaintVisibleTreeRect

protected void repaintVisibleTreeRect()
Repaints visible tree rect.


repaintTreeNodes

protected void repaintTreeNodes(java.util.List<E> nodes)
Repaints specified tree nodes.

Parameters:
nodes - tree nodes to repaint

addCheckStateChangeListener

public void addCheckStateChangeListener(CheckStateChangeListener listener)
Adds check state change listener.

Specified by:
addCheckStateChangeListener in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>
Parameters:
listener - check state change listener to add

removeCheckStateChangeListener

public void removeCheckStateChangeListener(CheckStateChangeListener listener)
Removes check state change listener.

Specified by:
removeCheckStateChangeListener in interface TreeCheckingModel<E extends javax.swing.tree.DefaultMutableTreeNode>
Parameters:
listener - check state change listener to remove

fireCheckStateChanged

public void fireCheckStateChanged(java.util.List<CheckStateChange<E>> stateChanges)
Informs about single or multiply check state changes.

Parameters:
stateChanges - check state changes list