public class MidicaTreeNode
extends javax.swing.tree.DefaultMutableTreeNode
This class represents a node for a MidicaTree
.
It contains a name, a descendant counter, an ID and a number representing a MIDI byte, double byte or byte range. However the number can be null, as well as the ID.
This class is designed to be used mainly from a MidicaTreeModel
. The following steps are necessary:
initChildren()
, if it’s a branch. Not necessary for leafs.addAndOrIncrement(String, String, String, boolean, String, String, boolean)
increment()
addChildren()
. This works recursively.Modifier and Type | Field and Description |
---|---|
private int |
count
number of leaves under the node’s hierarchy
|
private java.lang.String |
id
id of the node
|
private java.lang.String |
name
basic text to be displayed
|
private java.lang.String |
number
number representation of the node (e.g. bank number, program, status byte, etc.)
|
private static long |
serialVersionUID |
private java.util.TreeMap<java.lang.String,MidicaTreeNode> |
sortedChildren
stores the child nodes in a sorted form
|
private java.lang.String |
toolTipAttachment
additions to the tool tip
|
Constructor and Description |
---|
MidicaTreeNode()
Creates a new node with an empty name.
|
MidicaTreeNode(java.lang.String name)
Creates a new node with the given text but without a number.
|
MidicaTreeNode(java.lang.String name,
java.lang.String number)
Creates a new node with the given text and number.
|
Modifier and Type | Method and Description |
---|---|
MidicaTreeNode |
addAndOrIncrement(java.lang.String id,
java.lang.String name,
java.lang.String number,
boolean isLeaf,
java.lang.String sortKey,
java.lang.String ttAttachment,
boolean mustIncrement)
Creates and/or increments the specified child.
|
void |
addChildren()
Adds all children recursively.
|
void |
attachToToolTip(java.lang.String ttAttachment)
Adds the given attachment to the node’s tool tip.
|
java.lang.String |
getId()
Returns the ID of the node.
|
java.lang.String |
getName()
Returns the base text of the node.
|
java.lang.String |
getNumber()
Returns the number representation of the node.
|
java.lang.String |
getToolTip()
Returns the same string that’s also displayed as the node.
|
void |
increment()
Increments the count by 1.
|
void |
initChildren()
Initializes the data structure for the sorted children.
|
void |
setId(java.lang.String id)
Sets the ID of the node.
|
void |
setName(java.lang.String name)
Sets the base text of the node.
|
void |
setNumber(java.lang.String number)
Sets the number representation of the node.
|
java.lang.String |
toString()
Returns the string to be displayed in the tree.
|
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject
private static final long serialVersionUID
private java.lang.String name
basic text to be displayed
private java.lang.String number
number representation of the node (e.g. bank number, program, status byte, etc.)
private int count
number of leaves under the node’s hierarchy
private java.lang.String id
id of the node
private java.util.TreeMap<java.lang.String,MidicaTreeNode> sortedChildren
stores the child nodes in a sorted form
private java.lang.String toolTipAttachment
additions to the tool tip
public MidicaTreeNode(java.lang.String name, java.lang.String number)
Creates a new node with the given text and number.
name
- Main text to be displayed.number
- MIDI number representing this node.public MidicaTreeNode(java.lang.String name)
Creates a new node with the given text but without a number.
name
- Main text to be displayed.public MidicaTreeNode()
Creates a new node with an empty name.
This constructor is used indirectly from the MidicaTreeModel
and from this class (MidicaTreeNode
) by calling newInstance() on the class object. So the node name or number must be set later with setName(String)
or setNumber(String)
.
public void increment()
Increments the count by 1. This is called if a descendant of this node is added to the tree.
public void setNumber(java.lang.String number)
Sets the number representation of the node.
number
- MIDI number.public java.lang.String getNumber()
Returns the number representation of the node.
public void setName(java.lang.String name)
Sets the base text of the node.
name
- base text of the nodepublic java.lang.String getId()
Returns the ID of the node.
public void setId(java.lang.String id)
Sets the ID of the node.
id
- ID of the nodepublic java.lang.String getName()
Returns the base text of the node.
public void initChildren()
Initializes the data structure for the sorted children.
public MidicaTreeNode addAndOrIncrement(java.lang.String id, java.lang.String name, java.lang.String number, boolean isLeaf, java.lang.String sortKey, java.lang.String ttAttachment, boolean mustIncrement) throws java.lang.ReflectiveOperationException
Creates and/or increments the specified child.
If a new child is created, it is also added to the sorted children data structure. However it is not yet added to the tree.
id
- Child identifier string – unique for the children of this node.name
- Child name.number
- MIDI number representation of the child.isLeaf
- Specifies if the child is a leaf or a branch.sortKey
- String used for sorting (if null, the id is used for sorting instead).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 attachToToolTip(java.lang.String ttAttachment)
Adds the given attachment to the node’s tool tip.
ttAttachment
- tool tip attachmentpublic void addChildren()
Adds all children recursively.
public java.lang.String getToolTip()
Returns the same string that’s also displayed as the node.
Can be overridden in order to return a more customized tooltip.
public java.lang.String toString()
Returns the string to be displayed in the tree.
toString
in class javax.swing.tree.DefaultMutableTreeNode