123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 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());
- 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();
- }
- >>>>>>> 5f1735a4d30ece2b9dc2d1e34982f17502c21d2f
- }
- public void readFromJSON(File jsonFile) throws IOException {
- String line;
- BufferedReader reader = new BufferedReader(new FileReader("textfile"));
- while ((line = reader.readLine()) != null) {
- // mach hier irgendwas mit der Gelesenen Zeile
- }
- }
- }
|