|
@@ -25,11 +25,9 @@ import ui.model.Model;
|
|
|
import ui.model.idCounter;
|
|
|
|
|
|
public class LoadController {
|
|
|
-
|
|
|
+
|
|
|
public enum MODE {
|
|
|
- ALL,
|
|
|
- CATEGORY,
|
|
|
- CANVAS
|
|
|
+ ALL, CATEGORY, CANVAS
|
|
|
}
|
|
|
|
|
|
private Model MODEL;
|
|
@@ -56,60 +54,56 @@ public class LoadController {
|
|
|
*/
|
|
|
public void readJSON(String path) throws IOException {
|
|
|
JSONParser parser = new JSONParser();
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ try {
|
|
|
+ json = (JSONObject) parser.parse(new FileReader(path));
|
|
|
+ } catch (ParseException e1) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
|
|
|
- MODE mode = null;
|
|
|
ArrayList<String> obj = new ArrayList<>();
|
|
|
ArrayList<String> ele = new ArrayList<>();
|
|
|
ArrayList<String> edge = new ArrayList<>();
|
|
|
ArrayList<String> gp = new ArrayList<>();
|
|
|
|
|
|
- try {
|
|
|
+ MODE mode = MODE.valueOf(json.get("MODE").toString());
|
|
|
|
|
|
- JSONObject json = (JSONObject) parser.parse(new FileReader(path));
|
|
|
-
|
|
|
- for (Object key : json.keySet()) {
|
|
|
- if(key.equals("MODE"))
|
|
|
- mode = MODE.valueOf(json.get("MODE").toString());
|
|
|
- else if (key.equals("CG"))
|
|
|
- readCategory((JSONArray) json.get(key));
|
|
|
- else if (key.toString().contains("CGO") || key.toString().contains("CVSO"))
|
|
|
- obj.add(key.toString());
|
|
|
- else if (key.toString().contains("CGE") || key.toString().contains("CVSE"))
|
|
|
- ele.add(key.toString());
|
|
|
- else if (key.toString().contains("EDGE"))
|
|
|
- edge.add(key.toString());
|
|
|
- else if (key.toString().contains("CGGP") || key.toString().contains("CVSGP"))
|
|
|
- gp.add(key.toString());
|
|
|
- else if (key.equals("ID"))
|
|
|
- idCounter.setCounter(Integer.parseInt(json.get(key.toString()).toString()));
|
|
|
- }
|
|
|
-
|
|
|
- Collections.sort(obj);
|
|
|
- Collections.sort(ele);
|
|
|
- Collections.sort(edge);
|
|
|
- Collections.sort(gp);
|
|
|
-
|
|
|
- if(mode.equals(MODE.ALL) || mode.equals(MODE.CATEGORY)){
|
|
|
- MODEL.setCgIdx(new HashMap<String,Integer>());
|
|
|
- MODEL.setCategories(new ArrayList<Category>());
|
|
|
- }
|
|
|
- if(mode.equals(MODE.ALL) || mode.equals(MODE.CATEGORY)){
|
|
|
- MODEL.setCvsObjIdx(new HashMap<Integer,Integer>());
|
|
|
- MODEL.setObjectsOnCanvas(new ArrayList<CpsObject>());
|
|
|
- }
|
|
|
-
|
|
|
+ if (mode.equals(MODE.ALL) || mode.equals(MODE.CATEGORY)) {
|
|
|
+ MODEL.setCgIdx(new HashMap<String, Integer>());
|
|
|
+ MODEL.setCategories(new ArrayList<Category>());
|
|
|
+ }
|
|
|
+ if (mode.equals(MODE.ALL) || mode.equals(MODE.CATEGORY)) {
|
|
|
+ MODEL.setCvsObjIdx(new HashMap<Integer, Integer>());
|
|
|
+ MODEL.setObjectsOnCanvas(new ArrayList<CpsObject>());
|
|
|
+ }
|
|
|
|
|
|
- dispatch(obj, json);
|
|
|
- dispatch(ele, json);
|
|
|
- dispatch(edge, json);
|
|
|
- dispatch(gp, json);
|
|
|
+ for (Object key : json.keySet()) {
|
|
|
+ if (key.equals("CG"))
|
|
|
+ readCategory((JSONArray) json.get(key));
|
|
|
+ else if (key.equals("ID"))
|
|
|
+ idCounter.setCounter(Integer.parseInt(json.get(key.toString()).toString()));
|
|
|
+ else if (key.toString().contains("CGO") || key.toString().contains("CVSO"))
|
|
|
+ obj.add(key.toString());
|
|
|
+ else if (key.toString().contains("CGE") || key.toString().contains("CVSE"))
|
|
|
+ ele.add(key.toString());
|
|
|
+ else if (key.toString().contains("EDGE"))
|
|
|
+ edge.add(key.toString());
|
|
|
+ else if (key.toString().contains("CGGP") || key.toString().contains("CVSGP"))
|
|
|
+ gp.add(key.toString());
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
- // Should be ParseException, but gradle won't work with it
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
+ Collections.sort(obj);
|
|
|
+ Collections.sort(ele);
|
|
|
+ Collections.sort(edge);
|
|
|
+ Collections.sort(gp);
|
|
|
+
|
|
|
+ dispatch(obj, json);
|
|
|
+ dispatch(ele, json);
|
|
|
+ dispatch(edge, json);
|
|
|
+ dispatch(gp, json);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -214,6 +208,7 @@ public class LoadController {
|
|
|
|
|
|
if (sav.equals("CVS")) {
|
|
|
ele.setActive(convert(Integer.parseInt(next(i))));
|
|
|
+ System.out.println(ele.getActive());
|
|
|
objC.addElementIntoCanvasObject((HolonObject) mpC.searchByID(Integer.parseInt(obj)), ele);
|
|
|
} else
|
|
|
objC.addElementIntoCategoryObject(sav, obj, ele);
|
|
@@ -226,7 +221,8 @@ public class LoadController {
|
|
|
public void readEdge(JSONArray arr) {
|
|
|
Iterator<Object> i = arr.iterator();
|
|
|
|
|
|
- CpsEdge edge = new CpsEdge(mpC.searchByID(Integer.parseInt(next(i))), mpC.searchByID(Integer.parseInt(next(i))));
|
|
|
+ CpsEdge edge = new CpsEdge(mpC.searchByID(Integer.parseInt(next(i))),
|
|
|
+ mpC.searchByID(Integer.parseInt(next(i))));
|
|
|
edge.setCapacity(Float.parseFloat(next(i)));
|
|
|
edge.setFlow(Float.parseFloat(next(i)));
|
|
|
|
|
@@ -254,14 +250,17 @@ public class LoadController {
|
|
|
|
|
|
/**
|
|
|
* Get the Next Element from an Iterator
|
|
|
+ *
|
|
|
* @param i
|
|
|
* @return
|
|
|
*/
|
|
|
public String next(Iterator<Object> i) {
|
|
|
return i.next().toString();
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* converting saved Integers into Booleans
|
|
|
+ *
|
|
|
* @param x
|
|
|
* @return
|
|
|
*/
|