annotate java/src/uk/ac/qmul/eecs/ccmi/checkboxtree/CheckBoxTreeNode.java @ 1:e3935c01cde2 tip

moved license of PdPersistenceManager to the beginning of the file
author Fiore Martin <f.martin@qmul.ac.uk>
date Tue, 08 Jul 2014 19:52:03 +0100
parents 78b7fc5391a2
children
rev   line source
f@0 1 /*
f@0 2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
f@0 3
f@0 4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
f@0 5
f@0 6 This program is free software: you can redistribute it and/or modify
f@0 7 it under the terms of the GNU General Public License as published by
f@0 8 the Free Software Foundation, either version 3 of the License, or
f@0 9 (at your option) any later version.
f@0 10
f@0 11 This program is distributed in the hope that it will be useful,
f@0 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
f@0 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f@0 14 GNU General Public License for more details.
f@0 15
f@0 16 You should have received a copy of the GNU General Public License
f@0 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
f@0 18 */
f@0 19 package uk.ac.qmul.eecs.ccmi.checkboxtree;
f@0 20
f@0 21 import javax.swing.tree.DefaultMutableTreeNode;
f@0 22 import javax.swing.tree.TreeNode;
f@0 23
f@0 24
f@0 25 /**
f@0 26 * A special {@code DefaultMutableTreeNode} that has, in addition, the property of being (or not)
f@0 27 * selected.
f@0 28 *
f@0 29 */
f@0 30 @SuppressWarnings("serial")
f@0 31 public class CheckBoxTreeNode extends DefaultMutableTreeNode {
f@0 32
f@0 33 /**
f@0 34 * Construct a new instance of this class.
f@0 35 *
f@0 36 * @param userObject a user object for this tree node @see javax.swing.tree#DefaultMutableTreeNode
f@0 37 * @param selectable whether or not this node is selectable. A non selectable node is pretty much
f@0 38 * equivalent to a {@code DefaultMutableTreeNode}.
f@0 39 */
f@0 40 public CheckBoxTreeNode(Object userObject, boolean selectable){
f@0 41 super(userObject);
f@0 42 this.selectable = selectable;
f@0 43 selected = false;
f@0 44 }
f@0 45
f@0 46 /**
f@0 47 * Returns {@code true} if the node is selected, or {@code false} otherwise.
f@0 48 *
f@0 49 * @return {@code true} if the node is selected, or {@code false} otherwise.
f@0 50 */
f@0 51 public boolean isSelected() {
f@0 52 return selected;
f@0 53 }
f@0 54
f@0 55 /**
f@0 56 * Makes the node selected or unselected
f@0 57 *
f@0 58 * @param selected {@code true} to select the node, {@code false} to unselect it.
f@0 59 */
f@0 60 public void setSelected(boolean selected) {
f@0 61 if(selectable){
f@0 62 this.selected = selected;
f@0 63 }
f@0 64 }
f@0 65
f@0 66 /**
f@0 67 * Whether the node is selectable or not. This depends on the value of the
f@0 68 * {@code selected} parameter passed to the constructor.
f@0 69 *
f@0 70 * @return {@code true} if the node is selectable, {@code false} otherwise.
f@0 71 */
f@0 72 public boolean isSelectable(){
f@0 73 return selectable;
f@0 74 }
f@0 75
f@0 76 /**
f@0 77 * Returns a string representation of the audio description of this node.
f@0 78 * The value returned by this method can be passed to a Text-To-Speech synthesizer
f@0 79 * for speech rendering.
f@0 80 *
f@0 81 * @return the audio description of this node.
f@0 82 */
f@0 83 public String spokenText(){
f@0 84 if(selectable)
f@0 85 return toString()+", "+ (selected ? "checked": "unchecked");
f@0 86 else
f@0 87 return toString();
f@0 88 }
f@0 89
f@0 90 /**
f@0 91 * Returns a string representation of the path of this tree node. The the string is made up
f@0 92 * as the concatenation of the tree node names from the root to this node, separated by
f@0 93 * {@link #STRING_PATH_SEPARATOR}
f@0 94 *
f@0 95 * @return the node path as a String
f@0 96 */
f@0 97 public String getPathAsString(){
f@0 98 StringBuilder builder = new StringBuilder();
f@0 99 TreeNode [] path = getPath();
f@0 100 for(int i=0; i<path.length; i++){
f@0 101 builder.append(path[i].toString());
f@0 102 if(i != path.length-1)
f@0 103 builder.append(STRING_PATH_SEPARATOR);
f@0 104 }
f@0 105 return builder.toString();
f@0 106 }
f@0 107
f@0 108 private boolean selected;
f@0 109 private boolean selectable;
f@0 110 /**
f@0 111 * The character used as a separator when returning the string representation of the path
f@0 112 * of this node via {@link #getPathAsString()}.
f@0 113 */
f@0 114 public static final char STRING_PATH_SEPARATOR = '.';
f@0 115 }