|
@@ -14,6 +14,8 @@ import com.sun.scenario.effect.impl.sw.java.JSWBlend_COLOR_BURNPeer;
|
|
|
|
|
|
import classes.Category;
|
|
import classes.Category;
|
|
import classes.CpsObject;
|
|
import classes.CpsObject;
|
|
|
|
+import classes.HolonElement;
|
|
|
|
+import classes.HolonObject;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
|
|
|
|
public class LoadStoreController {
|
|
public class LoadStoreController {
|
|
@@ -29,6 +31,8 @@ public class LoadStoreController {
|
|
JSONObject jsonObj = new JSONObject();
|
|
JSONObject jsonObj = new JSONObject();
|
|
|
|
|
|
writeCategory(jsonObj);
|
|
writeCategory(jsonObj);
|
|
|
|
+ writeCategoryObjects(jsonObj);
|
|
|
|
+ writeCategoryElements(jsonObj);
|
|
|
|
|
|
FileWriter file = new FileWriter("//Users//zheng//Desktop//Tesst.json");
|
|
FileWriter file = new FileWriter("//Users//zheng//Desktop//Tesst.json");
|
|
file.write(jsonObj.toJSONString());
|
|
file.write(jsonObj.toJSONString());
|
|
@@ -39,29 +43,47 @@ public class LoadStoreController {
|
|
}
|
|
}
|
|
|
|
|
|
public void writeCategory(JSONObject jsonObj) throws IOException {
|
|
public void writeCategory(JSONObject jsonObj) throws IOException {
|
|
-
|
|
|
|
- int objI = 1;
|
|
|
|
|
|
|
|
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());
|
|
- writeObjects(jsonObj, cat.getObjects(), objI);
|
|
|
|
- }
|
|
|
|
|
|
|
|
jsonObj.put("Category", arr);
|
|
jsonObj.put("Category", arr);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public void writeObjects(JSONObject jsonObj, ArrayList<CpsObject> objects, int objI) {
|
|
|
|
|
|
+ public void writeCategoryObjects(JSONObject jsonObj) {
|
|
|
|
+ int i = 1;
|
|
JSONArray arr = new JSONArray();
|
|
JSONArray arr = new JSONArray();
|
|
- for (CpsObject cps : objects) {
|
|
|
|
- arr.add(cps.getStored() );
|
|
|
|
- arr.add(cps.getObjName());
|
|
|
|
- arr.add( cps.getName());
|
|
|
|
- arr.add(cps.getImage());
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- jsonObj.put("CategoryObject." + objI++, arr);
|
|
|
|
|
|
+
|
|
|
|
+ for (Category cats : MODEL.getCategories())
|
|
|
|
+ for (CpsObject cps : cats.getObjects()) {
|
|
|
|
+ arr.add(cps.getStored());
|
|
|
|
+ arr.add(cps.getObjName());
|
|
|
|
+ arr.add(cps.getName());
|
|
|
|
+ arr.add(cps.getImage());
|
|
|
|
+ jsonObj.put("CategoryObject." + i++, arr);
|
|
|
|
+ arr = new JSONArray();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void writeCategoryElements(JSONObject jsonObj) {
|
|
|
|
+ int i = 1;
|
|
|
|
+ JSONArray arr = new JSONArray();
|
|
|
|
+
|
|
|
|
+ for (Category cats : MODEL.getCategories())
|
|
|
|
+ for (CpsObject cps : cats.getObjects())
|
|
|
|
+ if (cps instanceof HolonObject)
|
|
|
|
+ for (HolonElement ele : ((HolonObject) cps).getElements()) {
|
|
|
|
+ arr.add(ele.getStored());
|
|
|
|
+ arr.add(ele.getEleName());
|
|
|
|
+ arr.add(ele.getAmount());
|
|
|
|
+ arr.add(ele.getEnergy());
|
|
|
|
+ jsonObj.put("CategoryElement." + i++, arr);
|
|
|
|
+ arr = new JSONArray();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
public void readFromJSON(File jsonFile) throws IOException {
|
|
public void readFromJSON(File jsonFile) throws IOException {
|