|
@@ -1,80 +1,42 @@
|
|
|
package ui.controller;
|
|
|
-
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
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 classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
|
import ui.model.Model;
|
|
|
-
|
|
|
public class LoadStoreController {
|
|
|
-
|
|
|
private Model MODEL;
|
|
|
-
|
|
|
public LoadStoreController(Model model) {
|
|
|
this.MODEL = model;
|
|
|
}
|
|
|
-
|
|
|
public void writeJSONFile() throws IOException {
|
|
|
-
|
|
|
JSONObject jsonObj = new JSONObject();
|
|
|
-
|
|
|
writeCategory(jsonObj);
|
|
|
writeCategoryObjects(jsonObj);
|
|
|
writeCategoryElements(jsonObj);
|
|
|
-
|
|
|
-<<<<<<< HEAD
|
|
|
- FileWriter file = new FileWriter("//Users//Edgardo//Desktop//Tesst.json");
|
|
|
-=======
|
|
|
FileWriter file = new FileWriter("C:/Users/krabs/Desktop/Tesst.json");
|
|
|
->>>>>>> 5f1735a4d30ece2b9dc2d1e34982f17502c21d2f
|
|
|
file.write(jsonObj.toJSONString());
|
|
|
-
|
|
|
file.flush();
|
|
|
file.close();
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
public void writeCategory(JSONObject jsonObj) throws IOException {
|
|
|
-<<<<<<< HEAD
|
|
|
-
|
|
|
- int objI = 1;
|
|
|
-=======
|
|
|
->>>>>>> 5f1735a4d30ece2b9dc2d1e34982f17502c21d2f
|
|
|
-
|
|
|
JSONArray arr = new JSONArray();
|
|
|
for (Category cat : MODEL.getCategories())
|
|
|
arr.add(cat.getName());
|
|
|
-
|
|
|
jsonObj.put("Category", arr);
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
public void writeCategoryObjects(JSONObject jsonObj) {
|
|
|
int i = 1;
|
|
|
JSONArray arr = new JSONArray();
|
|
|
-<<<<<<< HEAD
|
|
|
- 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());
|
|
@@ -84,13 +46,10 @@ public class LoadStoreController {
|
|
|
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)
|
|
@@ -102,16 +61,12 @@ public class LoadStoreController {
|
|
|
jsonObj.put("CategoryElement." + i++, arr);
|
|
|
arr = new JSONArray();
|
|
|
}
|
|
|
-
|
|
|
->>>>>>> 5f1735a4d30ece2b9dc2d1e34982f17502c21d2f
|
|
|
}
|
|
|
-
|
|
|
public void readFromJSON(File jsonFile) throws IOException {
|
|
|
-
|
|
|
String line;
|
|
|
BufferedReader reader = new BufferedReader(new FileReader("textfile"));
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|