edu.cs.ai.kreator.ui.gui.components.models
Class CheckboxTreeModel

java.lang.Object
  extended by edu.cs.ai.kreator.ui.gui.components.models.CheckboxTreeModel
All Implemented Interfaces:
javax.swing.tree.TreeModel

public class CheckboxTreeModel
extends java.lang.Object
implements javax.swing.tree.TreeModel

A custom tree model for handling the checkbox states as part of the data.

Author:
Tim Janus

Nested Class Summary
 class CheckboxTreeModel.Node
          Inner class representing a Node in the custom tree model.
 
Constructor Summary
CheckboxTreeModel(java.lang.Object rootdata)
          Ctor: Generates a root node with the given data.
 
Method Summary
 CheckboxTreeModel.Node addAsChild(CheckboxTreeModel.Node parent, java.lang.Object childData)
          Add a new child node with the given user-data to the given parent node.
 void addItemListener(java.awt.event.ItemListener listener)
          connects the item listener to every node checkbox.
 void addTreeModelListener(javax.swing.event.TreeModelListener l)
           
 java.lang.Object getChild(java.lang.Object parent, int index)
           
 int getChildCount(java.lang.Object parent)
           
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
           
 CheckboxTreeModel.Node getNode(javax.swing.JCheckBox box)
           
 java.lang.Object getRoot()
           
 boolean isLeaf(java.lang.Object node)
           
 void onStructureChanged()
          This method: restructures the entire tree component.
 void removeItemListener(java.awt.event.ItemListener listener)
           
 void removeNodesFrom(CheckboxTreeModel.Node parent, java.util.List<java.lang.Object> toRemove)
          Removes all of the nodes in the toRemove list from the given parent node.
 void removeTreeModelListener(javax.swing.event.TreeModelListener l)
           
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CheckboxTreeModel

public CheckboxTreeModel(java.lang.Object rootdata)
Ctor: Generates a root node with the given data.

Parameters:
rootdata -
Method Detail

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Specified by:
getChild in interface javax.swing.tree.TreeModel

getChildCount

public int getChildCount(java.lang.Object parent)
Specified by:
getChildCount in interface javax.swing.tree.TreeModel

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel

getRoot

public java.lang.Object getRoot()
Specified by:
getRoot in interface javax.swing.tree.TreeModel

isLeaf

public boolean isLeaf(java.lang.Object node)
Specified by:
isLeaf in interface javax.swing.tree.TreeModel

addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener l)
Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener l)
Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel

addItemListener

public void addItemListener(java.awt.event.ItemListener listener)
connects the item listener to every node checkbox.

Parameters:
listener -

removeItemListener

public void removeItemListener(java.awt.event.ItemListener listener)
Parameters:
listener -

addAsChild

public CheckboxTreeModel.Node addAsChild(CheckboxTreeModel.Node parent,
                                         java.lang.Object childData)
Add a new child node with the given user-data to the given parent node.

Parameters:
parent - parent node
childData - user-data for the new child node.
Returns:
reference to the newly created child node.

removeNodesFrom

public void removeNodesFrom(CheckboxTreeModel.Node parent,
                            java.util.List<java.lang.Object> toRemove)
Removes all of the nodes in the toRemove list from the given parent node.

Parameters:
parent - parent node of all removed nodes.
toRemove - list of nodes which should be removed.

onStructureChanged

public void onStructureChanged()
This method: restructures the entire tree component. Its useful if you change a lot and than and dont want to inform the tree component about every small change.


getNode

public CheckboxTreeModel.Node getNode(javax.swing.JCheckBox box)