public class MidicaTreeModel
extends javax.swing.tree.DefaultTreeModel
This class defines a tree model for trees displaying MIDI sequence information.
It uses nodes of the type MidicaTreeNode
.
In order to use this tree model, the following steps are necessary:
add(ArrayList, String)
providing one string array per node on the way to the leaf.postprocess()
.setTree(MidicaTree)
.Modifier and Type | Field and Description |
---|---|
private MidicaTreeNode |
rootNode |
private static long |
serialVersionUID |
private MidicaTree |
tree |
Constructor and Description |
---|
MidicaTreeModel(java.lang.String name)
Creates a new tree model and initializes it with a new empty root node.
|
MidicaTreeModel(java.lang.String name,
java.lang.Class<?> nodeClass)
Creates a new tree model and initializes it with a new empty root node.
|
Modifier and Type | Method and Description |
---|---|
MidicaTreeNode |
add(java.util.ArrayList<java.lang.String[]> params,
java.lang.String ttAttachment)
Adds a new path to the tree, if it does not yet exist, using the root node as the entry point.
|
private MidicaTreeNode |
add(MidicaTreeNode parent,
java.util.ArrayList<java.lang.String[]> params,
java.lang.String ttAttachment,
boolean mustIncrement)
Adds and/or increments new nodes (branch or leaf) recursively.
|
MidicaTreeNode |
addWithoutIncrementing(java.util.ArrayList<java.lang.String[]> params)
Adds a new path to the tree, if it does not yet exist, using the root node as the entry point, without incrementing the nodes in the path.
|
void |
expandOrCollapse(boolean mustExpand)
Expands or collapses (selected) nodes of the tree.
|
private void |
expandOrCollapse(javax.swing.tree.TreePath parentPath,
boolean mustExpand)
Expands or collapses all children of the given node recursively.
|
private void |
fillPathsByIds(java.util.TreeSet<java.lang.String> ids,
MidicaTreeNode node,
java.util.ArrayList<javax.swing.tree.TreePath> selectionPaths)
Fills the given selectionPaths structure with all nodes under the given node recursively, that contain one of the given ids.
|
java.util.TreeSet<java.lang.String> |
getSelectedIds()
Collects and returns all IDs of currently selected tree nodes.
|
MidicaTree |
getTree()
Returns the tree or null, if the tree is not yet set.
|
void |
postprocess()
Connects all nodes with each other recursively.
|
void |
selectByIds(java.util.TreeSet<java.lang.String> ids)
Selects all tree nodes that contain one of the given IDs.
|
void |
setTree(MidicaTree tree)
Sets the tree to which this model belongs.
|
addTreeModelListener, asksAllowsChildren, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getChild, getChildCount, getIndexOfChild, getListeners, getPathToRoot, getPathToRoot, getRoot, getTreeModelListeners, insertNodeInto, isLeaf, nodeChanged, nodesChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, reload, reload, removeNodeFromParent, removeTreeModelListener, setAsksAllowsChildren, setRoot, valueForPathChanged
private static final long serialVersionUID
private MidicaTreeNode rootNode
private MidicaTree tree
public MidicaTreeModel(java.lang.String name)
Creates a new tree model and initializes it with a new empty root node. The root node will be a MidicaTreeNode
object.
name
- Name of the root node.public MidicaTreeModel(java.lang.String name, java.lang.Class<?> nodeClass) throws java.lang.InstantiationException, java.lang.IllegalAccessException
Creates a new tree model and initializes it with a new empty root node. The root node can be a derived class of MidicaTreeNode
.
name
- Name of the root node.nodeClass
- Class of the nodes.java.lang.IllegalAccessException
- if the node class or its nullary constructor is not accessible.java.lang.InstantiationException
- if the root node creation fails.public void setTree(MidicaTree tree)
Sets the tree to which this model belongs.
tree
- The tree showing the data of this model.public MidicaTree getTree()
Returns the tree or null, if the tree is not yet set.
public MidicaTreeNode add(java.util.ArrayList<java.lang.String[]> params, java.lang.String ttAttachment) throws java.lang.ReflectiveOperationException
Adds a new path to the tree, if it does not yet exist, using the root node as the entry point.
All nodes on the way to the leaf will be created if not yet done and incremented by 1. That includes all branches and the leaf.
params
- Two-dimensional list.
ttAttachment
- added to the leaf node’s tool tip text, if not nulljava.lang.ReflectiveOperationException
- if the new child node cannot be created.public MidicaTreeNode addWithoutIncrementing(java.util.ArrayList<java.lang.String[]> params) throws java.lang.ReflectiveOperationException
Adds a new path to the tree, if it does not yet exist, using the root node as the entry point, without incrementing the nodes in the path.
All nodes on the way to the leaf will be created if not yet done, but not incremented. That includes all branches and the leaf.
params
- params Two-dimensional list.
java.lang.ReflectiveOperationException
private MidicaTreeNode add(MidicaTreeNode parent, java.util.ArrayList<java.lang.String[]> params, java.lang.String ttAttachment, boolean mustIncrement) throws java.lang.ReflectiveOperationException
Adds and/or increments new nodes (branch or leaf) recursively.
parent
- Data structure where the new node is to be added.params
- Two-dimensional list.
ttAttachment
- added to the leaf node’s tool tip text, if not nullmustIncrement
- true if the affected nodes should be incremented, otherwise false.java.lang.ReflectiveOperationException
- if the new child node cannot be created.public void postprocess()
Connects all nodes with each other recursively.
public void expandOrCollapse(boolean mustExpand)
Expands or collapses (selected) nodes of the tree. If no nodes are selected, all nodes are expanded or collapsed.
mustExpand
- true for expanding, false for collapsingprivate void expandOrCollapse(javax.swing.tree.TreePath parentPath, boolean mustExpand)
Expands or collapses all children of the given node recursively.
parentPath
- Path of the node to be expended.mustExpand
- true for expanding, false for collapsingpublic java.util.TreeSet<java.lang.String> getSelectedIds()
Collects and returns all IDs of currently selected tree nodes. Does not collect null IDs.
public void selectByIds(java.util.TreeSet<java.lang.String> ids)
Selects all tree nodes that contain one of the given IDs.
ids
- the IDs associated with the nodes to be selected.private void fillPathsByIds(java.util.TreeSet<java.lang.String> ids, MidicaTreeNode node, java.util.ArrayList<javax.swing.tree.TreePath> selectionPaths)
Fills the given selectionPaths structure with all nodes under the given node recursively, that contain one of the given ids. Works recursively.
ids
- the IDs associated with the nodes to be collected.node
- the node under which to be searched.selectionPaths
- the structure to be filled.