annotate java/src/uk/ac/qmul/eecs/ccmi/checkboxtree/CheckBoxTreeNode.java @ 8:ea7885bd9bff tip

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