f@0: /*
f@0: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
f@0:
f@0: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
f@0:
f@0: This program is free software: you can redistribute it and/or modify
f@0: it under the terms of the GNU General Public License as published by
f@0: the Free Software Foundation, either version 3 of the License, or
f@0: (at your option) any later version.
f@0:
f@0: This program is distributed in the hope that it will be useful,
f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of
f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f@0: GNU General Public License for more details.
f@0:
f@0: You should have received a copy of the GNU General Public License
f@0: along with this program. If not, see .
f@0: */
f@0: package uk.ac.qmul.eecs.ccmi.checkboxtree;
f@0:
f@0: import javax.swing.tree.DefaultMutableTreeNode;
f@0: import javax.swing.tree.TreeNode;
f@0:
f@0:
f@0: /**
f@0: * A special {@code DefaultMutableTreeNode} that has, in addition, the property of being (or not)
f@0: * selected.
f@0: *
f@0: */
f@0: @SuppressWarnings("serial")
f@0: public class CheckBoxTreeNode extends DefaultMutableTreeNode {
f@0:
f@0: /**
f@0: * Construct a new instance of this class.
f@0: *
f@0: * @param userObject a user object for this tree node @see javax.swing.tree#DefaultMutableTreeNode
f@0: * @param selectable whether or not this node is selectable. A non selectable node is pretty much
f@0: * equivalent to a {@code DefaultMutableTreeNode}.
f@0: */
f@0: public CheckBoxTreeNode(Object userObject, boolean selectable){
f@0: super(userObject);
f@0: this.selectable = selectable;
f@0: selected = false;
f@0: }
f@0:
f@0: /**
f@0: * Returns {@code true} if the node is selected, or {@code false} otherwise.
f@0: *
f@0: * @return {@code true} if the node is selected, or {@code false} otherwise.
f@0: */
f@0: public boolean isSelected() {
f@0: return selected;
f@0: }
f@0:
f@0: /**
f@0: * Makes the node selected or unselected
f@0: *
f@0: * @param selected {@code true} to select the node, {@code false} to unselect it.
f@0: */
f@0: public void setSelected(boolean selected) {
f@0: if(selectable){
f@0: this.selected = selected;
f@0: }
f@0: }
f@0:
f@0: /**
f@0: * Whether the node is selectable or not. This depends on the value of the
f@0: * {@code selected} parameter passed to the constructor.
f@0: *
f@0: * @return {@code true} if the node is selectable, {@code false} otherwise.
f@0: */
f@0: public boolean isSelectable(){
f@0: return selectable;
f@0: }
f@0:
f@0: /**
f@0: * Returns a string representation of the audio description of this node.
f@0: * The value returned by this method can be passed to a Text-To-Speech synthesizer
f@0: * for speech rendering.
f@0: *
f@0: * @return the audio description of this node.
f@0: */
f@0: public String spokenText(){
f@0: if(selectable)
f@0: return toString()+", "+ (selected ? "checked": "unchecked");
f@0: else
f@0: return toString();
f@0: }
f@0:
f@0: /**
f@0: * Returns a string representation of the path of this tree node. The the string is made up
f@0: * as the concatenation of the tree node names from the root to this node, separated by
f@0: * {@link #STRING_PATH_SEPARATOR}
f@0: *
f@0: * @return the node path as a String
f@0: */
f@0: public String getPathAsString(){
f@0: StringBuilder builder = new StringBuilder();
f@0: TreeNode [] path = getPath();
f@0: for(int i=0; i