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