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