|
@@ -10,8 +10,10 @@ import org.json.simple.JSONObject;
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
+import com.google.gson.JsonElement;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
|
|
|
-import Serializer.PositionSerializer;
|
|
|
+import TypeAdapter.AbstractCpsObjectAdapter;
|
|
|
import classes.Category;
|
|
|
import classes.CpsEdge;
|
|
|
import classes.AbstractCpsObject;
|
|
@@ -55,26 +57,28 @@ public class StoreController {
|
|
|
*/
|
|
|
public void writeSaveFile(String path) throws IOException {
|
|
|
|
|
|
- Gson gson = new GsonBuilder().serializeNulls().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Position.class, new PositionSerializer()).create();
|
|
|
-
|
|
|
+ GsonBuilder builder = new GsonBuilder();
|
|
|
+ builder.registerTypeAdapter(AbstractCpsObject.class, new AbstractCpsObjectAdapter()).serializeNulls()
|
|
|
+ .setPrettyPrinting();
|
|
|
+ Gson gson = builder.create();
|
|
|
+
|
|
|
JSONObject json = new JSONObject();
|
|
|
- int i = 1;
|
|
|
|
|
|
-// json.put("MODE", "ALL");
|
|
|
-// json.put("ID", IdCounter.getCounter());
|
|
|
-// json.put("SIZEX", model.getCanvasX());
|
|
|
-// json.put("SIZEY", model.getCanvasY());
|
|
|
-// writeCategory(json);
|
|
|
-// writeCategoryObjects(json);
|
|
|
-// writeCanvasObjects(json);
|
|
|
-// writeCategoryElements(json);
|
|
|
-// writeCanvasElements(json);
|
|
|
-// writeEdges(json);
|
|
|
-// writeElementGraph(json);
|
|
|
-
|
|
|
+ // json.put("MODE", "ALL");
|
|
|
+ // json.put("ID", IdCounter.getCounter());
|
|
|
+ // json.put("SIZEX", model.getCanvasX());
|
|
|
+ // json.put("SIZEY", model.getCanvasY());
|
|
|
+ // writeCategory(gson, json);
|
|
|
+ // writeCategoryObjects(gson, json);
|
|
|
+ // writeCanvasObjects(json);
|
|
|
+ // writeCategoryElements(json);
|
|
|
+ // writeCanvasElements(json);
|
|
|
+ // writeEdges(json);
|
|
|
+ // writeElementGraph(json);
|
|
|
+ int i = 1;
|
|
|
for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
- gson.toJson(cps);
|
|
|
- json.put("CVS" + i++, gson.toJson(cps));
|
|
|
+ String k = gson.toJson(cps);
|
|
|
+ System.out.println(k);
|
|
|
}
|
|
|
|
|
|
FileWriter writer = new FileWriter(path);
|
|
@@ -126,8 +130,8 @@ public class StoreController {
|
|
|
|
|
|
json.put("MODE", "CATEGORY");
|
|
|
// eventuell muss man ID auch Speichern
|
|
|
- writeCategory(json);
|
|
|
- writeCategoryObjects(json);
|
|
|
+ // writeCategory(gson, json);
|
|
|
+ // writeCategoryObjects(gson, json);
|
|
|
writeCategoryElements(json);
|
|
|
|
|
|
FileWriter writer = new FileWriter(path);
|
|
@@ -141,39 +145,39 @@ public class StoreController {
|
|
|
/**
|
|
|
* writes all Categories into a JSONObject.
|
|
|
*
|
|
|
+ * @param gson
|
|
|
+ *
|
|
|
* @param json
|
|
|
* JSON Object
|
|
|
* @throws IOException
|
|
|
* exception
|
|
|
*/
|
|
|
- public void writeCategory(JSONObject json) {
|
|
|
- JSONArray arr = new JSONArray();
|
|
|
+ public void writeCategory(Gson gson, JSONObject json) {
|
|
|
+ int i = 1;
|
|
|
|
|
|
for (Category cat : model.getCategories())
|
|
|
- arr.add(cat.getName());
|
|
|
-
|
|
|
- json.put("CG", arr);
|
|
|
+ json.put("CG" + i++, gson.toJson(cat));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* writes all Objects in Category into a JSONObject.
|
|
|
*
|
|
|
+ * @param gson
|
|
|
+ *
|
|
|
* @param json
|
|
|
* JSON Object
|
|
|
*/
|
|
|
- public void writeCategoryObjects(JSONObject json) {
|
|
|
+ public void writeCategoryObjects(Gson gson, JSONObject json) {
|
|
|
|
|
|
- JSONArray arr = new JSONArray();
|
|
|
int i = 1;
|
|
|
|
|
|
for (Category cats : model.getCategories())
|
|
|
for (AbstractCpsObject cps : cats.getObjects()) {
|
|
|
- arr.add(getObjectType(cps));
|
|
|
- arr.add(cps.getSav());
|
|
|
- arr.add(cps.getObjName());
|
|
|
- arr.add(cps.getImage());
|
|
|
- json.put("CGO" + i++, arr);
|
|
|
- arr = new JSONArray();
|
|
|
+ // arr.add(cps.getSav());
|
|
|
+ // arr.add(cps.getObjName());
|
|
|
+ // arr.add(cps.getImage());
|
|
|
+ json.put("CGO" + i++, gson.toJson(cps));
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -229,7 +233,8 @@ public class StoreController {
|
|
|
/**
|
|
|
* Write Canvas Elements.
|
|
|
*
|
|
|
- * @param json JSON Objects
|
|
|
+ * @param json
|
|
|
+ * JSON Objects
|
|
|
*/
|
|
|
public void writeCanvasElements(JSONObject json) {
|
|
|
|
|
@@ -253,7 +258,8 @@ public class StoreController {
|
|
|
/**
|
|
|
* write all Edges into a JSONObject.
|
|
|
*
|
|
|
- * @param json JSON Object
|
|
|
+ * @param json
|
|
|
+ * JSON Object
|
|
|
*/
|
|
|
public void writeEdges(JSONObject json) {
|
|
|
|
|
@@ -273,7 +279,8 @@ public class StoreController {
|
|
|
/**
|
|
|
* writes the Graph from all Elements into a JSONObject.
|
|
|
*
|
|
|
- * @param json JSON Object
|
|
|
+ * @param json
|
|
|
+ * JSON Object
|
|
|
*/
|
|
|
public void writeElementGraph(JSONObject json) {
|
|
|
|
|
@@ -325,7 +332,8 @@ public class StoreController {
|
|
|
/**
|
|
|
* Return the Object Type.
|
|
|
*
|
|
|
- * @param cps AbstractCpsObject
|
|
|
+ * @param cps
|
|
|
+ * AbstractCpsObject
|
|
|
* @return The Object Type
|
|
|
*/
|
|
|
public String getObjectType(AbstractCpsObject cps) {
|