Quellcode durchsuchen

distinguish between different os

Teh-Hai Julian Zheng vor 7 Jahren
Ursprung
Commit
66764cac38
2 geänderte Dateien mit 75 neuen und 4 gelöschten Zeilen
  1. 40 1
      src/ui/controller/LoadController.java
  2. 35 3
      src/ui/controller/SaveController.java

+ 40 - 1
src/ui/controller/LoadController.java

@@ -217,6 +217,8 @@ public class LoadController {
 				loadUnitGraph(GRAPHTYPE.SWITCH, json.get(key), objDispatch, null);
 			if (key.contains("ELEUNITGRAPH"))
 				loadUnitGraph(GRAPHTYPE.ELEMENT, json.get(key), null, eleDispatch);
+			if (key.contains("TRACKED"))
+				loadTracked(json.get(key), objDispatch);
 		}
 
 	}
@@ -234,6 +236,7 @@ public class LoadController {
 			model.setCvsObjIdx(new HashMap<Integer, Integer>());
 			model.setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
 			model.setEdgesOnCanvas(new ArrayList<CpsEdge>());
+			model.setTrackingObj(new ArrayList<>());
 			break;
 		case PARTIAL:
 			model.setCvsObjIdx(new HashMap<Integer, Integer>());
@@ -440,6 +443,22 @@ public class LoadController {
 		}
 	}
 
+	private void loadTracked(JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch) {
+		// TODO Auto-generated method stub
+		JsonObject object = jsonElement.getAsJsonObject();
+		List<String> keys = getKeys(object);
+
+		for (String k : keys) {
+			int id = object.get(k).getAsInt();
+			model.getTrackingObj().add(objDispatch.get(id));
+			model.addObjectsToGraphListeners();
+			if (objDispatch.get(id) instanceof HolonObject) {
+				((HolonObject) objDispatch.get(id)).updateTrackingInfo();
+			}
+		}
+
+	}
+
 	/**
 	 * Initialize the Gson with wanted parameters
 	 */
@@ -464,7 +483,8 @@ public class LoadController {
 
 		ArchiveEntry entry = stream.getNextEntry();
 		while (entry != null) {
-			File file = new File(tmp, entry.getName());
+			String entryName = checkOS(entry.getName());
+			File file = new File(tmp, entryName);
 			file.getParentFile().mkdirs();
 			OutputStream output = new FileOutputStream(file);
 			IOUtils.copy(stream, output);
@@ -479,6 +499,25 @@ public class LoadController {
 		return tmp;
 	}
 
+	private String checkOS(String entryName) {
+		// TODO Auto-generated method stub
+		String os = System.getProperty("os.name").toLowerCase();
+		String ret = entryName;
+		String partition = null;
+
+		if (os.contains("windows")) {
+			partition = System.getProperty("user.home").substring(0, entryName.indexOf(":"));
+			ret = partition + ret;
+		}
+		if (os.contains("mac")) {
+
+		}
+		if (os.contains("linux")) {
+
+		}
+		return ret;
+	}
+
 	/**
 	 * Init new Arrays which havent been serialized along the object
 	 * 

+ 35 - 3
src/ui/controller/SaveController.java

@@ -108,6 +108,7 @@ public class SaveController {
 		initialize(MODE.COMPLETE, file);
 		storeCategory(file);
 		storeCanvas(file);
+		storeStatistics(file);
 		storeData(stream);
 
 		FileWriter writer = new FileWriter(holonFile);
@@ -260,6 +261,7 @@ public class SaveController {
 	}
 
 	private void storeStatistics(JsonObject file) {
+		trackedToJson(file);
 
 	}
 
@@ -394,6 +396,18 @@ public class SaveController {
 
 	}
 
+	private void trackedToJson(JsonObject file) {
+		// TODO Auto-generated method stub
+		JsonObject temp = new JsonObject();
+		String key = "TRACKED";
+		// forall points add them
+		for (int i = 0; i < model.getTrackingObj().size(); i++) {
+			temp.add("" + i, new JsonPrimitive(model.getTrackingObj().get(i).getId()));
+		}
+
+		file.add(key, gson.toJsonTree(temp));
+	}
+
 	/**
 	 * Differs Between Single file or whole Directory to Store
 	 * 
@@ -427,9 +441,8 @@ public class SaveController {
 	 */
 	private void addFileToSave(File src, ArchiveOutputStream stream, boolean dir) throws IOException {
 		String entryName = (dir == true ? src.getCanonicalPath() : src.getName());
-		String partition = entryName.substring(0, entryName.indexOf(":"));
-		entryName = entryName.replace(partition, "");
-		entryName = entryName.replace(System.getProperty("user.home") + "/HolonGUI/", "");
+		
+		entryName = checkOS(entryName);
 
 		ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
 		stream.putArchiveEntry(entry);
@@ -440,6 +453,25 @@ public class SaveController {
 		stream.closeArchiveEntry();
 	}
 
+	private String checkOS(String entryName) {
+		// TODO Auto-generated method stub
+		String os = System.getProperty("os.name").toLowerCase();
+		String ret = entryName;
+		String partition = null;
+
+		if(os.contains("windows")) {
+			partition = entryName.substring(0, entryName.indexOf(":"));
+			ret =  entryName.replace(partition, "");
+		}
+		if(os.contains("mac")) {
+			
+		}
+		if(os.contains("linux")) {
+			
+		}
+		return ret.replace(System.getProperty("user.home") + "/HolonGUI/", "");
+	}
+
 	/**
 	 * Initialize the Gson with wanted parameters
 	 */