瀏覽代碼

minor fix

Teh-Hai Julian Zheng 7 年之前
父節點
當前提交
96ece2e5bc
共有 2 個文件被更改,包括 56 次插入28 次删除
  1. 34 19
      src/ui/controller/LoadController.java
  2. 22 9
      src/ui/controller/StoreController.java

+ 34 - 19
src/ui/controller/LoadController.java

@@ -110,7 +110,8 @@ public class LoadController {
 	}
 
 	/**
-	 * distribute the Edges 
+	 * distribute the Edges
+	 * 
 	 * @param edges
 	 * @param json
 	 * @param objDispatch
@@ -118,20 +119,28 @@ public class LoadController {
 	private void distEdges(List<String> edges, JsonObject json, HashMap<Integer, AbstractCpsObject> objDispatch) {
 		// TODO Auto-generated method stub
 
+		List<String> conn = new ArrayList<>();
+
 		for (String edge : edges) {
 			if (edge.contains("CVSEDGE"))
 				loadEdge(EDGETYPE.CANVAS, json.get(edge), objDispatch);
 			if (edge.contains("CONNEDGE"))
-				loadEdge(EDGETYPE.CONNECTION, json.get(edge), objDispatch);
+				conn.add(edge);
 			if (edge.contains("NODE"))
 				loadEdge(EDGETYPE.NODE, json.get(edge), objDispatch);
 			if (edge.contains("OLD"))
 				loadEdge(EDGETYPE.OLD, json.get(edge), objDispatch);
 		}
+
+		for (String edge : conn) {
+			loadEdge(EDGETYPE.CONNECTION, json.get(edge), objDispatch);
+		}
+
 	}
-	
+
 	/**
 	 * Distribute the given keys for right processing
+	 * 
 	 * @param keys
 	 * @param json
 	 * @param objDispatch
@@ -248,9 +257,10 @@ public class LoadController {
 		objDispatch.put(temp.getID(), temp);
 
 	}
-	
+
 	/**
 	 * Load a given Element in Canvas by Deserialization
+	 * 
 	 * @param jsonElement
 	 * @param objDispatch
 	 * @param eleDispatch
@@ -260,21 +270,22 @@ public class LoadController {
 		// TODO Auto-generated method stub
 
 		JsonObject object = jsonElement.getAsJsonObject();
-		
+
 		HolonElement temp = gson.fromJson(object.get("properties"), HolonElement.class);
 		initElements(temp);
-		//id which Object it was stored before
+		// id which Object it was stored before
 		int stored = object.get("ID").getAsInt();
-		//lookup that object
+		// lookup that object
 		HolonObject temp2 = (HolonObject) objDispatch.get(stored);
-		//add it
+		// add it
 		objC.addElement(temp2, temp);
-		//store element also inside a table
+		// store element also inside a table
 		eleDispatch.put(temp.getId(), temp);
 	}
-	
+
 	/**
 	 * Load a given Edge by Deserialization
+	 * 
 	 * @param type
 	 * @param jsonElement
 	 * @param objDispatch
@@ -284,7 +295,7 @@ public class LoadController {
 		JsonObject object = jsonElement.getAsJsonObject();
 		CpsEdge temp = gson.fromJson(object.get("properties"), CpsEdge.class);
 		initCpsEdge(temp);
-		//look for A and B inside the Table
+		// look for A and B inside the Table
 		temp.setA(objDispatch.get(object.get("A").getAsInt()));
 		temp.setB(objDispatch.get(object.get("B").getAsInt()));
 
@@ -292,13 +303,11 @@ public class LoadController {
 
 		switch (type) {
 		case CANVAS:
-			//if in canvas add it into the canvas but delete connection before
+			// if in canvas add it into the canvas but delete connection before
 			model.getEdgesOnCanvas().add(temp);
-			temp.getA().getConnections().remove(temp);
-			temp.getB().getConnections().remove(temp);
 			break;
 		case CONNECTION:
-			//if no duplicates in connection store them into the given A and B
+			// if no duplicates in connection store them into the given A and B
 			if (!uppC.lookforDuplicates(temp.getA(), temp.getB(), temp.getA().getConnections()))
 				temp.getA().getConnections().add(temp);
 			if (!uppC.lookforDuplicates(temp.getA(), temp.getB(), temp.getB().getConnections()))
@@ -310,7 +319,7 @@ public class LoadController {
 			((CpsUpperNode) objDispatch.get(sav)).getNodeEdges().add(temp);
 			break;
 		case OLD:
-			//same as above
+			// same as above
 			sav = object.get("ID").getAsInt();
 			((CpsUpperNode) objDispatch.get(sav)).getOldEdges().add(temp);
 			break;
@@ -318,10 +327,16 @@ public class LoadController {
 			break;
 		}
 
+		if (object.get("connection").getAsBoolean()) {
+			temp.getA().getConnections().add(temp);
+			temp.getB().getConnections().add(temp);
+		}
+
 	}
-	
+
 	/**
 	 * Load a Unitgraph by Deserialization
+	 * 
 	 * @param type
 	 * @param jsonElement
 	 * @param objDispatch
@@ -338,7 +353,7 @@ public class LoadController {
 
 		LinkedList<Point> graphpoint = new LinkedList<>();
 		int sav = 0;
-		//foreach Point in the graph restore it
+		// foreach Point in the graph restore it
 		for (String k : keys) {
 			if (!k.equals("ID")) {
 				p = object.get(k).getAsString();
@@ -347,7 +362,7 @@ public class LoadController {
 				y = Integer.parseInt(p.substring(mid + 1, p.length()));
 				graphpoint.add(new Point(x, y));
 			} else
-				//else its an ID
+				// else its an ID
 				sav = object.get(k).getAsInt();
 
 		}

+ 22 - 9
src/ui/controller/StoreController.java

@@ -229,7 +229,7 @@ public class StoreController {
 		for (HolonElement ele : ((HolonObject) obj).getElements()) {
 			temp.add("properties", gson.toJsonTree(ele));
 			temp.add("ID", new JsonPrimitive(obj.getID()));
-			//switch for deciding the key
+			// switch for deciding the key
 			switch (type) {
 			case CANVAS:
 				key = "CVSELEMENT" + getNumerator(NUMTYPE.ELEMENT);
@@ -241,7 +241,7 @@ public class StoreController {
 				break;
 			}
 			file.add(key, gson.toJsonTree(temp));
-			//if there are gps add them into
+			// if there are gps add them into
 			if (ele.getGraphPoints().size() != 0)
 				unitgraphToJson(GRAPHTYPE.ELEMENT, file, ele.getId(), ele.getGraphPoints());
 			temp = new JsonObject();
@@ -251,17 +251,18 @@ public class StoreController {
 
 	/**
 	 * Put the UnitGraphs of Switches or Elements into Json
+	 * 
 	 * @param ele
 	 */
 	private void unitgraphToJson(GRAPHTYPE type, JsonObject file, int id, LinkedList<Point> graph) {
 
 		JsonObject temp = new JsonObject();
 		String key = null;
-		//forall points add them
+		// forall points add them
 		for (int i = 0; i < graph.size(); i++) {
 			temp.add("" + i, new JsonPrimitive(graph.get(i).x + ":" + graph.get(i).y));
 		}
-		//decide key
+		// decide key
 		switch (type) {
 		case SWITCH:
 			key = "SWUNITGRAPH" + getNumerator(NUMTYPE.UNITGRAPH);
@@ -272,7 +273,7 @@ public class StoreController {
 		default:
 			break;
 		}
-		//add id of element so it can be found again
+		// add id of element so it can be found again
 		temp.add("ID", new JsonPrimitive(id));
 
 		file.add(key, gson.toJsonTree(temp));
@@ -280,6 +281,7 @@ public class StoreController {
 
 	/**
 	 * Canvas-Edge, Connections, Node-Edge and Old-Edges to json
+	 * 
 	 * @param type
 	 * @param file
 	 * @param id
@@ -288,29 +290,40 @@ public class StoreController {
 	private void edgeToJson(EDGETYPE type, JsonObject file, int id, ArrayList<CpsEdge> arr) {
 		// TODO Auto-generated method stub
 		String k = null;
+		boolean b = false;
 		JsonObject temp = new JsonObject();
 
 		for (CpsEdge edge : arr) {
-			//add properties and only the ids from a and b
+			// add properties and only the ids from a and b
 			temp.add("properties", gson.toJsonTree(edge));
 			temp.add("A", new JsonPrimitive(edge.getA().getID()));
 			temp.add("B", new JsonPrimitive(edge.getB().getID()));
 
-			//Key and occasionally the id of Uppernode 
+			// Key and occasionally the id of Uppernode
 			switch (type) {
 			case CANVAS:
+				if (edge.getA().getConnections().contains(edge) && edge.getA().getConnections().contains(edge))
+					b = true;
+				temp.add("connection", new JsonPrimitive(b));
+
 				k = "CVSEDGE" + getNumerator(NUMTYPE.EDGE);
 				break;
 			case CONNECTION:
+				temp.add("connection", new JsonPrimitive(b));
 				k = "CONNEDGE" + getNumerator(NUMTYPE.CONNECTION);
 				break;
 			case NODE:
-				k = "NODEEDGE" + getNumerator(NUMTYPE.NODEEDGE);
 				temp.add("ID", new JsonPrimitive(id));
+				if (edge.getA().getConnections().contains(edge) && edge.getA().getConnections().contains(edge))
+					b = true;
+				k = "NODEEDGE" + getNumerator(NUMTYPE.NODEEDGE);
 				break;
 			case OLD:
-				k = "OLDEDGE" + getNumerator(NUMTYPE.OLDEDGE);
 				temp.add("ID", new JsonPrimitive(id));
+				if (edge.getA().getConnections().contains(edge) && edge.getA().getConnections().contains(edge))
+					b = true;
+				temp.add("connection", new JsonPrimitive(b));
+				k = "OLDEDGE" + getNumerator(NUMTYPE.OLDEDGE);
 				break;
 			default:
 				break;