|
@@ -11,6 +11,8 @@ import classes.Category;
|
|
import classes.CpsObject;
|
|
import classes.CpsObject;
|
|
import classes.HolonElement;
|
|
import classes.HolonElement;
|
|
import classes.HolonObject;
|
|
import classes.HolonObject;
|
|
|
|
+import classes.HolonSwitch;
|
|
|
|
+import classes.HolonTransformer;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
|
|
|
|
public class LoadStoreController {
|
|
public class LoadStoreController {
|
|
@@ -20,63 +22,126 @@ public class LoadStoreController {
|
|
this.MODEL = model;
|
|
this.MODEL = model;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Writes a Savefile in .json
|
|
|
|
+ *
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
public void writeJSONFile() throws IOException {
|
|
public void writeJSONFile() throws IOException {
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
JSONObject json = new JSONObject();
|
|
|
|
|
|
-
|
|
|
|
writeCategory(json);
|
|
writeCategory(json);
|
|
- writeCategoryObjects(json);
|
|
|
|
- writeCategoryElements(json);
|
|
|
|
|
|
+ writeObjects(json);
|
|
|
|
+ writeElements(json);
|
|
|
|
|
|
FileWriter writer = new FileWriter("//Users//zheng//Desktop//Tesst.json");
|
|
FileWriter writer = new FileWriter("//Users//zheng//Desktop//Tesst.json");
|
|
|
|
+ writer.write(json.toJSONString());
|
|
writer.flush();
|
|
writer.flush();
|
|
writer.close();
|
|
writer.close();
|
|
}
|
|
}
|
|
|
|
|
|
- public void writeCategory(JSONObject json) throws IOException {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * writes all Categories into a JSONObject
|
|
|
|
+ *
|
|
|
|
+ * @param json
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public void writeCategory(JSONObject json) {
|
|
JSONArray arr = new JSONArray();
|
|
JSONArray arr = new JSONArray();
|
|
-
|
|
|
|
|
|
+
|
|
for (Category cat : MODEL.getCategories())
|
|
for (Category cat : MODEL.getCategories())
|
|
arr.add(cat.getName());
|
|
arr.add(cat.getName());
|
|
|
|
+
|
|
json.put("Category", arr);
|
|
json.put("Category", arr);
|
|
}
|
|
}
|
|
|
|
|
|
- public void writeCategoryObjects(JSONObject json) throws IOException {
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * writes all Objects in Category into a JSONObject
|
|
|
|
+ *
|
|
|
|
+ * @param json
|
|
|
|
+ */
|
|
|
|
+ public void writeObjects(JSONObject json) {
|
|
|
|
+
|
|
JSONArray arr = new JSONArray();
|
|
JSONArray arr = new JSONArray();
|
|
int i = 1;
|
|
int i = 1;
|
|
-
|
|
|
|
|
|
+
|
|
for (Category cats : MODEL.getCategories())
|
|
for (Category cats : MODEL.getCategories())
|
|
for (CpsObject cps : cats.getObjects()) {
|
|
for (CpsObject cps : cats.getObjects()) {
|
|
- arr.add(cps.getStored());
|
|
|
|
|
|
+ arr.add(cps.getSav());
|
|
arr.add(cps.getObjName());
|
|
arr.add(cps.getObjName());
|
|
- arr.add(cps.getName());
|
|
|
|
arr.add(cps.getImage());
|
|
arr.add(cps.getImage());
|
|
json.put("CategoryObject." + i++, arr);
|
|
json.put("CategoryObject." + i++, arr);
|
|
arr = new JSONArray();
|
|
arr = new JSONArray();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ i = 1;
|
|
|
|
+ for (CpsObject cps : MODEL.getObjectsOnCanvas()) {
|
|
|
|
+ arr.add(getObjectType(cps));
|
|
|
|
+ arr.add(cps.getSav());
|
|
|
|
+ arr.add(cps.getObjName());
|
|
|
|
+ arr.add(cps.getID());
|
|
|
|
+ arr.add(cps.getImage());
|
|
|
|
+ arr.add(cps.getPosition().x);
|
|
|
|
+ arr.add(cps.getPosition().y);
|
|
|
|
+ json.put("CanvasObject." + i++, arr);
|
|
|
|
+ arr = new JSONArray();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param cps
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public String getObjectType(CpsObject cps) {
|
|
|
|
+ if (cps instanceof HolonObject)
|
|
|
|
+ return "HolonObject";
|
|
|
|
+ else if (cps instanceof HolonTransformer)
|
|
|
|
+ return "HolonTransformer";
|
|
|
|
+ else if (cps instanceof HolonSwitch)
|
|
|
|
+ return "HolonSwtich";
|
|
|
|
+ else
|
|
|
|
+ return "CpsNode";
|
|
}
|
|
}
|
|
|
|
|
|
- public void writeCategoryElements(JSONObject json) throws IOException {
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * writes all Elements in Objects in Category into a JSONObject
|
|
|
|
+ *
|
|
|
|
+ * @param json
|
|
|
|
+ */
|
|
|
|
+ public void writeElements(JSONObject json) {
|
|
|
|
|
|
JSONArray arr = new JSONArray();
|
|
JSONArray arr = new JSONArray();
|
|
int i = 1;
|
|
int i = 1;
|
|
-
|
|
|
|
|
|
+
|
|
for (Category cats : MODEL.getCategories())
|
|
for (Category cats : MODEL.getCategories())
|
|
for (CpsObject cps : cats.getObjects())
|
|
for (CpsObject cps : cats.getObjects())
|
|
if (cps instanceof HolonObject)
|
|
if (cps instanceof HolonObject)
|
|
for (HolonElement ele : ((HolonObject) cps).getElements()) {
|
|
for (HolonElement ele : ((HolonObject) cps).getElements()) {
|
|
- arr.add(ele.getStored());
|
|
|
|
|
|
+ arr.add(ele.getSav());
|
|
|
|
+ arr.add(ele.getObj());
|
|
arr.add(ele.getEleName());
|
|
arr.add(ele.getEleName());
|
|
arr.add(ele.getAmount());
|
|
arr.add(ele.getAmount());
|
|
arr.add(ele.getEnergy());
|
|
arr.add(ele.getEnergy());
|
|
json.put("CategoryElement." + i++, arr);
|
|
json.put("CategoryElement." + i++, arr);
|
|
arr = new JSONArray();
|
|
arr = new JSONArray();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ i = 1;
|
|
|
|
+ for (CpsObject cps : MODEL.getObjectsOnCanvas()) {
|
|
|
|
+ if (cps instanceof HolonObject)
|
|
|
|
+ for (HolonElement ele : ((HolonObject) cps).getElements()) {
|
|
|
|
+ arr.add(ele.getSav());
|
|
|
|
+ arr.add(ele.getObj());
|
|
|
|
+ arr.add(ele.getEleName());
|
|
|
|
+ arr.add(ele.getAmount());
|
|
|
|
+ arr.add(ele.getEnergy());
|
|
|
|
+ json.put("CategoryElement." + i++, arr);
|
|
|
|
+ arr = new JSONArray();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public void readFromJSON(File jsonFile) throws IOException {
|
|
public void readFromJSON(File jsonFile) throws IOException {
|