|
@@ -25,6 +25,12 @@ import ui.model.Model;
|
|
|
import ui.model.idCounter;
|
|
|
|
|
|
public class LoadController {
|
|
|
+
|
|
|
+ public enum MODE {
|
|
|
+ ALL,
|
|
|
+ CATEGORY,
|
|
|
+ CANVAS
|
|
|
+ }
|
|
|
|
|
|
private Model MODEL;
|
|
|
private CategoryController cgC;
|
|
@@ -50,12 +56,8 @@ public class LoadController {
|
|
|
*/
|
|
|
public void readJSON(String path) throws IOException {
|
|
|
JSONParser parser = new JSONParser();
|
|
|
- MODEL.setCgIdx(new HashMap<String,Integer>());
|
|
|
- MODEL.setCvsObjIdx(new HashMap<Integer,Integer>());
|
|
|
- MODEL.setCategories(new ArrayList<Category>());
|
|
|
- MODEL.setObjectsOnCanvas(new ArrayList<CpsObject>());
|
|
|
-
|
|
|
|
|
|
+ MODE mode = null;
|
|
|
ArrayList<String> obj = new ArrayList<>();
|
|
|
ArrayList<String> ele = new ArrayList<>();
|
|
|
ArrayList<String> edge = new ArrayList<>();
|
|
@@ -66,8 +68,9 @@ public class LoadController {
|
|
|
JSONObject json = (JSONObject) parser.parse(new FileReader(path));
|
|
|
|
|
|
for (Object key : json.keySet()) {
|
|
|
-
|
|
|
- if (key.equals("CG"))
|
|
|
+ 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());
|
|
@@ -77,7 +80,7 @@ public class LoadController {
|
|
|
edge.add(key.toString());
|
|
|
else if (key.toString().contains("CGGP") || key.toString().contains("CVSGP"))
|
|
|
gp.add(key.toString());
|
|
|
- else
|
|
|
+ else if (key.equals("ID"))
|
|
|
idCounter.setCounter(Integer.parseInt(json.get(key.toString()).toString()));
|
|
|
}
|
|
|
|
|
@@ -85,6 +88,16 @@ public class LoadController {
|
|
|
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>());
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
dispatch(obj, json);
|
|
|
dispatch(ele, json);
|