|
@@ -2,10 +2,18 @@ package ui.controller;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
-import java.io.FileNotFoundException;
|
|
|
import java.io.FileReader;
|
|
|
+import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
|
+import org.json.simple.JSONArray;
|
|
|
+import org.json.simple.JSONObject;
|
|
|
+
|
|
|
+import com.sun.scenario.effect.impl.sw.java.JSWBlend_COLOR_BURNPeer;
|
|
|
+
|
|
|
+import classes.Category;
|
|
|
+import classes.CpsObject;
|
|
|
import ui.model.Model;
|
|
|
|
|
|
public class LoadStoreController {
|
|
@@ -16,7 +24,47 @@ public class LoadStoreController {
|
|
|
this.MODEL = model;
|
|
|
}
|
|
|
|
|
|
- public void readFromTextFile(File textFile) throws IOException {
|
|
|
+ public void writeJSONFile() throws IOException {
|
|
|
+
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+
|
|
|
+ writeCategory(jsonObj);
|
|
|
+
|
|
|
+ FileWriter file = new FileWriter("//Users//zheng//Desktop//Tesst.json");
|
|
|
+ file.write(jsonObj.toJSONString());
|
|
|
+
|
|
|
+ file.flush();
|
|
|
+ file.close();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void writeCategory(JSONObject jsonObj) throws IOException {
|
|
|
+
|
|
|
+ int objI = 1;
|
|
|
+
|
|
|
+ JSONArray arr = new JSONArray();
|
|
|
+ for (Category cat : MODEL.getCategories()) {
|
|
|
+ arr.add(cat.getName());
|
|
|
+ writeObjects(jsonObj, cat.getObjects(), objI);
|
|
|
+ }
|
|
|
+
|
|
|
+ jsonObj.put("Category", arr);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void writeObjects(JSONObject jsonObj, ArrayList<CpsObject> objects, int objI) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void readFromJSON(File jsonFile) throws IOException {
|
|
|
|
|
|
String line;
|
|
|
BufferedReader reader = new BufferedReader(new FileReader("textfile"));
|
|
@@ -24,8 +72,4 @@ public class LoadStoreController {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public void unZip(File zipFile) throws IOException {
|
|
|
-
|
|
|
- }
|
|
|
}
|