diff java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/DiagramElement.java @ 3:9e67171477bc

PHANTOM Omni Heptic device release
author Fiore Martin <fiore@eecs.qmul.ac.uk>
date Wed, 25 Apr 2012 17:09:09 +0100
parents 9418ab7b7f3f
children
line wrap: on
line diff
--- a/java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/DiagramElement.java	Mon Feb 06 12:54:06 2012 +0000
+++ b/java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/DiagramElement.java	Wed Apr 25 17:09:09 2012 +0100
@@ -19,6 +19,8 @@
 package uk.ac.qmul.eecs.ccmi.diagrammodel;
 
 import java.io.InputStream;
+import java.util.concurrent.locks.ReentrantLock;
+
 
 /**
  * A Diagram Element is either a node or an edge of the diagram. It's an abstract 
@@ -26,7 +28,7 @@
  *
  */
 @SuppressWarnings("serial")
-public abstract class DiagramElement extends DiagramModelTreeNode implements Cloneable{
+public abstract class DiagramElement extends DiagramTreeNode implements Cloneable{
 	
 	protected DiagramElement(){
 		name = "";
@@ -35,9 +37,10 @@
 	}
 	
 	/**
-	 * Returns the type of this diagram element. The type is the same for all the elements 
-	 * which fall under the same type, whereas a different name can be assigned to each
-	 * instance of such elements.  
+	 * Returns the type of this diagram element. The type is like the category this element belongs to. 
+	 * For instance in a public transport diagram one might have three types of diagram element: tube, train
+	 * and busses.   
+	 *  
 	 * @return the type of this element 
 	 */
 	public String getType(){
@@ -47,6 +50,7 @@
 	/**
 	 * Set the type of this diagram element. This method should be called as soon as the object is created
 	 * and should not be called anymore on this object.
+	 * 
 	 * @param type the type of this element
 	 */
 	protected void setType(String type){
@@ -76,9 +80,10 @@
 	/**
 	 * Sets the name of this element instance.
 	 * 
-	 * @param the string to set as the name 
+	 * @param s the string to set as the name 
+	 * @param source the source of this action
 	 */
-	public void setName(String s){
+	public void setName(String s, Object source){
 		String name = s;
 		/* if the user enters an empty string we go back to the default name */
 		if(s.isEmpty() && id != NO_ID){
@@ -86,7 +91,7 @@
 		}		
 		setUserObject(name);
 		this.name = name;
-		notifyChange(new ElementChangedEvent(this,this,"name"));
+		notifyChange(new ElementChangedEvent(this,this,"name",source));
 	}
 	
 	/**
@@ -122,13 +127,19 @@
 	public long getId(){
 		return id;
 	}
+	
+	public ReentrantLock getMonitor(){
+		if(notifier == null)
+			return null;
+		return (ReentrantLock)notifier;
+	}
 		
 	/** 
 	 *  Sets the notifier to be used for notification 
 	 *  following an internal change of the node
 	 * @param notifier the notifier call the notify method(s) on 
 	 */
-	public void setNotifier(ElementNotifier notifier){
+	<N extends DiagramNode,E extends DiagramEdge> void setNotifier(DiagramModel<N,E>.ReentrantLockNotifier notifier){
 		this.notifier = notifier;
 	}