view java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/EdgeReferenceMutableTreeNode.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
line wrap: on
line source
/*  
 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
  
 Copyright (C) 2011  Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package uk.ac.qmul.eecs.ccmi.diagrammodel;

/**
 * The diagramModeltreeNode placed in a node subtree representing an edge connecting 
 * that node with another node.
 */
@SuppressWarnings("serial")
public class EdgeReferenceMutableTreeNode extends DiagramTreeNode {
	EdgeReferenceMutableTreeNode(DiagramEdge edge, DiagramNode node){
		super();
		this.edge = edge;
		this.node = node;
	}
	
	@Override
	public String toString(){
		final String and = " and ";
		StringBuilder b = new StringBuilder();
		b.append("to ");
		for(int i=0;i<edge.getNodesNum();i++){
			DiagramNode n = edge.getNodeAt(i);
			if(!n.equals(node))
				b.append(n.getName()).append(and);
		}
		// remove the last " and "
		b.delete(b.length()-and.length(), b.length());
		b.append(", via ");
		b.append(edge.getName());
		super.setUserObject(b.toString());
		return super.toString();
	}
	
	@Override
	public String getName(){
		return toString();
	}
	
	/**
	 * Return a String representing this object for this tree node in a way more suitable 
	 * for a text to speech synthesizer to read, than toString(). 
	 * @return a String suitable for text to speech synthesis
	 */
	@Override
	public String spokenText(){
		toString();
		return super.spokenText();
	}
	
	/**
	 * Returns the diagram edge that this tree node represents inside the node subtree 
	 * @return a reference to the actual edge
	 */
	public DiagramEdge getEdge(){
		return edge;
	}
	
	/**
	 * Returns the node containing this tree node in its subtree. Notice that 
	 * diagram nodes are DiagrammodelTreeNode as well. 
	 * @return a reference to the diagram node
	 */
	public DiagramNode getNode(){
		return node;
	}
	
	private DiagramEdge edge;
	private DiagramNode node;
}