changeset 4:2c67ac862920

bug fix (correct haptic painting after renaming nodes and after nodes deletion with an edge with more than 2 nodes)
author Fiore Martin <fiore@eecs.qmul.ac.uk>
date Tue, 29 May 2012 15:32:19 +0100
parents 9e67171477bc
children d66dd5880081
files java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/DiagramEdge.java java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/DiagramModel.java java/src/uk/ac/qmul/eecs/ccmi/gui/Edge.java java/src/uk/ac/qmul/eecs/ccmi/gui/HapticTrigger.java java/src/uk/ac/qmul/eecs/ccmi/gui/Node.java java/src/uk/ac/qmul/eecs/ccmi/simpletemplate/SimpleShapeEdge.java java/src/uk/ac/qmul/eecs/ccmi/simpletemplate/SimpleShapeNode.java
diffstat 7 files changed, 32 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/DiagramEdge.java	Wed Apr 25 17:09:09 2012 +0100
+++ b/java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/DiagramEdge.java	Tue May 29 15:32:19 2012 +0100
@@ -147,7 +147,7 @@
 	 * @param n the node to be removed
 	 * @return true if the inner collection changed as a result of the call
 	 */
-	public abstract boolean removeNode(DiagramNode n);
+	public abstract boolean removeNode(DiagramNode n, Object source);
 	
 	/**
 	 * Connect a list of nodes with this edge 
--- a/java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/DiagramModel.java	Wed Apr 25 17:09:09 2012 +0100
+++ b/java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/DiagramModel.java	Tue May 29 15:32:19 2012 +0100
@@ -612,10 +612,10 @@
 		ArrayList<DiagramEdge> edgesToRemove = new ArrayList<DiagramEdge>(edges.size());
 		for(int i=0; i<n.getEdgesNum(); i++){
 			DiagramEdge e = n.getEdgeAt(i);
-			if(e.getNodesNum() == 2){
+			if(e.getNodesNum() == 2){ // deleting a node on a two ends edge means deleting the edge itself
 				edgesToRemove.add(e);
 			}else{
-				e.removeNode(n);
+				e.removeNode(n,source);
 				DiagramTreeNode nodeTreeReference = _lookForNodeReference(e, n);
 				treeModel.removeNodeFromParent(nodeTreeReference);
 			}
--- a/java/src/uk/ac/qmul/eecs/ccmi/gui/Edge.java	Wed Apr 25 17:09:09 2012 +0100
+++ b/java/src/uk/ac/qmul/eecs/ccmi/gui/Edge.java	Tue May 29 15:32:19 2012 +0100
@@ -89,7 +89,7 @@
 	}
 
 	@Override
-	public boolean removeNode(DiagramNode diagramNode){
+	public boolean removeNode(DiagramNode diagramNode, Object source){
 		Node n = (Node)diagramNode;
 		if(nodes.size() == 2)
 			throw new RuntimeException("Cannot remove a node from a two ends edge");
@@ -101,7 +101,10 @@
 						removePoint(p);
 					break;
 				} 
-			return nodes.remove(n);
+			boolean nodeRemoved = nodes.remove(n);
+			/* for update in the haptic device */
+			notifyChange(new ElementChangedEvent(this,n,"remove_node",source));
+			return nodeRemoved;
 		}
 	}
 
--- a/java/src/uk/ac/qmul/eecs/ccmi/gui/HapticTrigger.java	Wed Apr 25 17:09:09 2012 +0100
+++ b/java/src/uk/ac/qmul/eecs/ccmi/gui/HapticTrigger.java	Tue May 29 15:32:19 2012 +0100
@@ -59,7 +59,7 @@
 	@Override
 	public void elementChanged(ElementChangedEvent evt) {
 		DiagramEventSource source = (DiagramEventSource)evt.getSource(); 
-		if("stop_move".equals(evt.getChangeType())){
+		if("stop_move".equals(evt.getChangeType()) || "remove_node".equals(evt.getChangeType())){
 			if(evt.getDiagramElement() instanceof Edge){
 				Edge e = (Edge)evt.getDiagramElement();
 				Edge.PointRepresentation pr = e.getPointRepresentation();
--- a/java/src/uk/ac/qmul/eecs/ccmi/gui/Node.java	Wed Apr 25 17:09:09 2012 +0100
+++ b/java/src/uk/ac/qmul/eecs/ccmi/gui/Node.java	Tue May 29 15:32:19 2012 +0100
@@ -145,6 +145,15 @@
 		notifyChange(new ElementChangedEvent(this,this,"notes",source));
 	}
 	
+	/**
+	 *  The actual implementation of {@code translate()}. The {@code translate} method
+	 *  when called will, in turn, call this method, and then call all the registered
+	 *  change listeners in order to notify them that the node has been translated.
+	 *    
+	 *	@param p the point we are translating from
+	 *	@param dx the amount to translate in the x-direction
+	 *	@param dy the amount to translate in the y-direction
+	 */
 	protected abstract void translateImplementation(Point2D p , double dx, double dy);
 		
 	/**
--- a/java/src/uk/ac/qmul/eecs/ccmi/simpletemplate/SimpleShapeEdge.java	Wed Apr 25 17:09:09 2012 +0100
+++ b/java/src/uk/ac/qmul/eecs/ccmi/simpletemplate/SimpleShapeEdge.java	Tue May 29 15:32:19 2012 +0100
@@ -53,9 +53,9 @@
 	}
 	
 	@Override
-	public boolean removeNode(DiagramNode n){
+	public boolean removeNode(DiagramNode n,Object source){
 		currentHeads.remove(n);
-		return super.removeNode(n);
+		return super.removeNode(n,source);
 	}
 
 	@Override
--- a/java/src/uk/ac/qmul/eecs/ccmi/simpletemplate/SimpleShapeNode.java	Wed Apr 25 17:09:09 2012 +0100
+++ b/java/src/uk/ac/qmul/eecs/ccmi/simpletemplate/SimpleShapeNode.java	Tue May 29 15:32:19 2012 +0100
@@ -90,8 +90,17 @@
 	
 	@Override
 	protected void notifyChange(ElementChangedEvent evt){
-		if(!evt.getChangeType().equals("translate")&&!evt.getChangeType().equals("stop_move")) //don't reshape for just moving 
-			reshape();  
+		if(!evt.getChangeType().equals("translate")&&!evt.getChangeType().equals("stop_move")){ //don't reshape for just moving 
+			Rectangle2D boundsBeforeReshape = getBounds();
+			reshape();
+			Rectangle2D boundsAfterReshape = getBounds();
+			/* after renaming or setting properties the boundaries can change resulting in a slight shift of the *   
+			 * node centre from its original position. the next line is to place it back to the right position   */
+			Point2D start = new Point2D.Double(boundsAfterReshape.getCenterX(),boundsAfterReshape.getCenterY());
+			translateImplementation(start,
+					boundsBeforeReshape.getCenterX() - boundsAfterReshape.getCenterX(),
+					boundsBeforeReshape.getCenterY() - boundsAfterReshape.getCenterY());
+		}
 		super.notifyChange(evt);
 	}
 	
@@ -110,7 +119,7 @@
 				new Point2D.Double(),
 				boundsBeforeReshape.getX() - boundsAfterReshape.getX(),
 				boundsBeforeReshape.getY() - boundsAfterReshape.getY()
-			);
+		);
 	}
 	
 	@Override