Mercurial > hg > ccmieditor
view java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/DiagramNode.java @ 0:9418ab7b7f3f
Initial import
author | Fiore Martin <fiore@eecs.qmul.ac.uk> |
---|---|
date | Fri, 16 Dec 2011 17:35:51 +0000 |
parents | |
children | 9e67171477bc |
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; import java.util.Set; import uk.ac.qmul.eecs.ccmi.diagrammodel.NodeProperties.Modifiers; import uk.ac.qmul.eecs.ccmi.utils.Pair; /** * This class represents a node in the diagram. * */ @SuppressWarnings("serial") public abstract class DiagramNode extends DiagramElement { public DiagramNode(String type, NodeProperties properties){ setType(type); this.properties = properties; } /** * @see DiagramModelTreeNode#setNotes(String) */ @Override void setNotes(String notes){ this.notes = notes; notifyChange(new ElementChangedEvent(this,this,"note")); } /** * Returns the properties of this node. Be aware that what is returned is the reference * to the actual NodeProperties object inside this DiagramNode. Thereforemodifying the returned * object will affect this node. * @return the properties of this node */ public NodeProperties getProperties(){ return properties; } /** * Returns a copy of the properties of this node. The modifying the returned object * won't affect this Node. * @return Returns a copy of the properties of this node */ public NodeProperties getPropertiesCopy(){ NodeProperties p = (NodeProperties)properties.clone(); for(String type : properties.getTypes()){ Modifiers modifiers = properties.getModifiers(type); int index = 0; for(String value : properties.getValues(type)){ if(properties.getModifiers(type).isNull()) p.addValue(type, value); else p.addValue(type, value, modifiers.getIndexes(index++)); } } return p; } /** * Set the NodeProperties of this node * @param properties the properties to set for this node */ public void setProperties(NodeProperties properties){ this.properties = properties; notifyChange(new ElementChangedEvent(this.properties,this,"properties")); } /** * Add a property to the NodeProperties of this node * @see NodeProperties#addValue(String, String) * */ public void addProperty(String propertyType, String propertyValue){ getProperties().addValue(propertyType, propertyValue); int index = getProperties().getValues(propertyType).size() - 1; notifyChange(new ElementChangedEvent(new Pair<String,Integer>(propertyType,index),this,"property.add")); } /** * Removes a property from the NodeProperties of this node * @see NodeProperties#removeValue(String, int) */ public void removeProperty(String propertyType, int valueIndex){ getProperties().removeValue(propertyType, valueIndex); notifyChange(new ElementChangedEvent(new Pair<String,Integer>(propertyType,valueIndex),this,"property.remove")); } /** * Set a property on the NodeProperties of this node to a new value * @see NodeProperties#setValue(String, int, String) */ public void setProperty(String propertyType, int valueIndex, String newValue){ getProperties().setValue(propertyType, valueIndex, newValue); notifyChange(new ElementChangedEvent(new Pair<String,Integer>(propertyType,valueIndex),this,"property.set")); } /** * Removes all the values in the NodeProperties of this node * @see NodeProperties#clear() */ public void clearProperties(){ getProperties().clear(); notifyChange(new ElementChangedEvent(this,this,"properties.clear")); } /** * set the modifier indexes in the NodeProperties of this node * @see Modifiers#setIndexes(int, Set) */ public void setModifierIndexes(String propertyType, int propertyValueIndex, Set<Integer> modifierIndexes){ getProperties().getModifiers(propertyType).setIndexes(propertyValueIndex, modifierIndexes); notifyChange(new ElementChangedEvent(new Pair<String,Integer>(propertyType,propertyValueIndex),this,"property.modifiers")); } /** * Returns a more detailed description of the node than {@link #spokenText()}. * the description includes which how many properties the node has and * how many edges are attached to it. * * @return a description of the node */ @Override public String detailedSpokenText(){ StringBuilder builder = new StringBuilder(getType()); builder.append(' '); builder.append(getName()); builder.append('.').append(' '); for(int i=0; i<getChildCount();i++){ DiagramModelTreeNode treeNode = (DiagramModelTreeNode) getChildAt(i); if(treeNode.getChildCount() > 0){ builder.append(treeNode.getChildCount()) .append(' ') .append(treeNode.getName()) .append(';') .append(' '); } } return builder.toString(); } /** * Returns the number of attached edges * @return the number of attached edges */ public abstract int getEdgesNum(); /** * Returns the attached edge at the specified index * @param index an index into edge's list * @return the attached edge at the specified index */ public abstract DiagramEdge getEdgeAt(int index); /** * add an edge to the attached edges list * @param the edge to be added */ public abstract boolean addEdge(DiagramEdge e); /** * Removes an edge from the attached edges list * @param the edge to be removed */ public abstract boolean removeEdge(DiagramEdge e); /** * Gets the node this node is within. * @return the parent node, or null if the node * has no parent */ public abstract DiagramNode getExternalNode(); /** * Sets the node this node is within. * @param node the parent node, or null if the node * has no parent */ public abstract void setExternalNode(DiagramNode node); /** * Returns the number of internal nodes * @return the number of internal nodes */ public abstract int getInternalNodesNum(); /** * Gets the internal node at the specified index * @param index an index into internal nodes list * @return the internal node at the specified index */ public abstract DiagramNode getInternalNodeAt(int index); /** * Adds a node to the internal nodes list. * @param node the internal node to add */ public abstract void addInternalNode(DiagramNode node); /** * Removes a node from the internal nodes list. * @param node the internal node to remove */ public abstract void removeInternalNode(DiagramNode node); @Override public Object clone(){ DiagramNode clone = (DiagramNode)super.clone(); clone.properties = (NodeProperties)properties.clone(); return clone; } private NodeProperties properties; }