Browse Source

Merge branch 'Ohne_Drag_and_Drop' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons into Ohne_Drag_and_Drop

Edgardo Palza 8 years ago
parent
commit
03a3c64415

+ 1 - 1
src/ui/controller/CategoryController.java

@@ -33,7 +33,7 @@ public class CategoryController {
 		addNewHolonObject(searchCatNode("Energy"), "Power Plant", new ArrayList<>(), "/Images/power-plant.png");
 		addNewHolonObject(searchCatNode("Building"), "House", new ArrayList<>(), "/Images/home-2.png");
 		addNewHolonTransformer(searchCatNode("Component"), "Transformer", "/Images/transformer-1.png");
-		addNewHolonSwitch(searchCatNode("Component"), "Switch", "/Images/switch-on.png");
+		addNewHolonSwitch(searchCatNode("Component"), "Switch", "/Images/switch-off.png");
 		
 	}
 

+ 7 - 5
src/ui/controller/Control.java

@@ -25,7 +25,8 @@ public class Control {
 	private final ObjectController objectController;
 	private final CanvasController canvasController;
 	private final GlobalController globalController;
-	private final LoadStoreController loadStoreController;
+	private final StoreController storeController;
+	private final LoadController loadController;
 
 	public Control(Model model) {
 		this.MODEL = model;
@@ -33,7 +34,8 @@ public class Control {
 		this.objectController = new ObjectController(MODEL);
 		this.canvasController = new CanvasController(MODEL);
 		this.globalController = new GlobalController(MODEL);
-		this.loadStoreController = new LoadStoreController(MODEL, categoryController, canvasController, objectController);
+		this.storeController = new StoreController(MODEL);
+		this.loadController = new LoadController(MODEL, categoryController, canvasController, objectController);
 		
 	}
 
@@ -55,7 +57,7 @@ public class Control {
 	}
 
 	public void addSwitch(Category cat, String objName) {
-		categoryController.addNewHolonSwitch(cat, objName, "/Images/switch-on.png");
+		categoryController.addNewHolonSwitch(cat, objName, "/Images/switch-off.png");
 	}
 
 	public Category searchCategory(String name) {
@@ -145,11 +147,11 @@ public class Control {
 	
 	/* Operations for Loading and Storing */
 	public void saveFile(String path) throws IOException {
-		loadStoreController.writeJSONFile(path);
+		storeController.writeJSONFile(path);
 	}
 	
 	public void loadFile(String path) throws IOException {
-		loadStoreController.readJSON(path);
+		loadController.readJSON(path);
 	}
 	////////// etc
 	public void initListener(CategoryListener catLis) {

+ 200 - 0
src/ui/controller/LoadController.java

@@ -0,0 +1,200 @@
+package ui.controller;
+
+import java.awt.Point;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+import classes.CpsEdge;
+import classes.CpsNode;
+import classes.CpsObject;
+import classes.HolonElement;
+import classes.HolonObject;
+import classes.HolonSwitch;
+import classes.HolonTransformer;
+import ui.model.Model;
+import ui.model.idCounter;
+
+public class LoadController {
+
+	private Model MODEL;
+	private CategoryController cgC;
+	private CanvasController cvsC;
+	private ObjectController objC;
+
+	public LoadController(Model model, CategoryController cg, CanvasController cvs, ObjectController obj) {
+		this.MODEL = model;
+		this.cgC = cg;
+		this.cvsC = cvs;
+		this.objC = obj;
+
+	}
+
+	/**
+	 * 
+	 * @param path
+	 * @throws IOException
+	 */
+	public void readJSON(String path) throws IOException {
+		JSONParser parser = new JSONParser();
+		MODEL.setCategories(new ArrayList<>());
+		MODEL.setObjectsOnCanvas(new ArrayList<>());
+
+		ArrayList<String> obj = new ArrayList<>();
+		ArrayList<String> ele = new ArrayList<>();
+		ArrayList<String> edge = new ArrayList<>();
+		ArrayList<String> gp = new ArrayList<>();
+
+		try {
+
+			JSONObject json = (JSONObject) parser.parse(new FileReader(path));
+
+			for (Object key : json.keySet()) {
+
+				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
+					idCounter.setCounter(Integer.parseInt(json.get(key.toString()).toString()));
+			}
+			System.out.println(gp.get(0));
+			dispatch(obj, json);
+			dispatch(ele, json);
+			dispatch(edge, json);
+			dispatch(gp, json);
+
+		} catch (ParseException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+	}
+
+	public void dispatch(ArrayList<String> input, JSONObject json) {
+
+		for (String str : input) {
+			if (str.contains("CGO")) {
+				readCategoryObject((JSONArray) json.get(str));
+			} else if (str.contains("CVSO")) {
+				readCanvasObject((JSONArray) json.get(str));
+			} else if (str.contains("CGE") || str.contains("CVSE")) {
+				readElement((JSONArray) json.get(str));
+			} else if (str.contains("EDGE")) {
+				readEdge((JSONArray) json.get(str));
+			} else if (str.contains("CGGP") || str.contains("CVSGP")) {
+				readElementGraph((JSONArray) json.get(str));
+			}
+		}
+
+	}
+
+	public void readCategory(JSONArray arr) {
+
+		Iterator<Object> i = arr.iterator();
+
+		while (i.hasNext()) {
+			cgC.addNewCategory(i.next().toString());
+		}
+	}
+
+	public void readCategoryObject(JSONArray arr) {
+		Iterator<Object> i = arr.iterator();
+
+		String type = i.next().toString();
+
+		if (type.equals("HolonObject")) {
+			cgC.addNewHolonObject(cgC.searchCatNode(i.next().toString()), i.next().toString(), new ArrayList<>(),
+					i.next().toString());
+		} else if (type.equals("HolonTransformer")) {
+			cgC.addNewHolonTransformer(cgC.searchCatNode(i.next().toString()), i.next().toString(),
+					i.next().toString());
+		} else if (type.equals("HolonSwitch")) {
+			cgC.addNewHolonSwitch(cgC.searchCatNode(i.next().toString()), i.next().toString(), i.next().toString());
+		}
+
+	}
+
+	public void readCanvasObject(JSONArray arr) {
+		Iterator<Object> i = arr.iterator();
+		CpsObject cps = null;
+
+		String type = i.next().toString();
+
+		if (type.equals("HolonObject")) {
+			cps = new HolonObject(i.next().toString());
+		} else if (type.equals("HolonTransformer")) {
+			cps = new HolonTransformer(i.next().toString());
+		} else if (type.equals("HolonSwitch")) {
+			cps = new HolonSwitch(i.next().toString());
+		} else if (type.equals("CpsNode")) {
+			cps = new CpsNode(i.next().toString());
+		}
+
+		cps.setName(i.next().toString());
+		cps.setID(Integer.parseInt(i.next().toString()));
+		cps.setImage(i.next().toString());
+		cps.setPosition(Integer.parseInt(i.next().toString()), Integer.parseInt(i.next().toString()));
+
+		cvsC.addObjectIntoCanvas(cps);
+	}
+
+	public void readElement(JSONArray arr) {
+		Iterator<Object> i = arr.iterator();
+
+		String sav = i.next().toString();
+		if (sav.equals("Canvas")) {
+			objC.addNewElementIntoCanvasObject(Integer.parseInt(i.next().toString()), i.next().toString(),
+					Integer.parseInt(i.next().toString()), Float.parseFloat(i.next().toString()));
+		} else
+			objC.addNewElementIntoCategoryObject(sav, i.next().toString(), i.next().toString(),
+					Integer.parseInt(i.next().toString()), Float.parseFloat(i.next().toString()));
+	}
+
+	public void readEdge(JSONArray arr) {
+		Iterator<Object> i = arr.iterator();
+
+		CpsEdge edge = new CpsEdge(objC.searchByID(Integer.parseInt(i.next().toString())),
+				objC.searchByID(Integer.parseInt(i.next().toString())));
+		edge.setCapacity(Float.parseFloat(i.next().toString()));
+		edge.setFlow(Float.parseFloat(i.next().toString()));
+
+		cvsC.addEdgeOnCanvas(edge);
+	}
+
+	public void readElementGraph(JSONArray arr) {
+		Iterator<Object> i = arr.iterator();
+
+		String sav = i.next().toString();
+		HolonElement ele;
+
+		if (sav.equals("Canvas")) {
+			ele = objC.searchHolonElement((HolonObject) objC.searchByID(Integer.parseInt(i.next().toString())),
+					i.next().toString());
+			while (i.hasNext())
+				ele.getGraphPoints()
+						.add(new Point(Integer.parseInt(i.next().toString()), Integer.parseInt(i.next().toString())));
+			System.out.println(ele.getGraphPoints().size());
+		} else {
+			ele = objC.searchHolonElement(objC.searchHolonObject(i.next().toString(),
+					objC.searchCategory(sav, MODEL.getCategories()).getObjects()), i.next().toString());
+			while (i.hasNext())
+				ele.getGraphPoints()
+						.add(new Point(Integer.parseInt(i.next().toString()), Integer.parseInt(i.next().toString())));
+		}
+
+	}
+
+}

+ 0 - 326
src/ui/controller/LoadStoreController.java

@@ -1,326 +0,0 @@
-package ui.controller;
-
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-
-import classes.Category;
-import classes.CpsEdge;
-import classes.CpsNode;
-import classes.CpsObject;
-import classes.HolonElement;
-import classes.HolonObject;
-import classes.HolonSwitch;
-import classes.HolonTransformer;
-import ui.model.Model;
-import ui.model.idCounter;
-
-public class LoadStoreController {
-
-	private Model MODEL;
-	private CategoryController categoryController;
-	private CanvasController canvasController;
-	private ObjectController objectController;
-
-	public LoadStoreController(Model model, CategoryController cg, CanvasController cvs, ObjectController obj) {
-		this.MODEL = model;
-		this.categoryController = cg;
-		this.canvasController = cvs;
-		this.objectController = obj;
-
-	}
-
-	/**
-	 * Writes a Savefile in .json
-	 * 
-	 * @throws IOException
-	 */
-	public void writeJSONFile(String path) throws IOException {
-
-		JSONObject json = new JSONObject();
-
-		json.put("ID", idCounter.getCounter());
-		writeCategory(json);
-		writeObjects(json);
-		writeElements(json);
-		writeEdges(json);
-		
-
-		FileWriter writer = new FileWriter(path);
-		writer.write(json.toJSONString());
-		writer.flush();
-		writer.close();
-	}
-
-	/**
-	 * writes all Categories into a JSONObject
-	 * 
-	 * @param json
-	 * @throws IOException
-	 */
-	public void writeCategory(JSONObject json) {
-		JSONArray arr = new JSONArray();
-
-		for (Category cat : MODEL.getCategories())
-			arr.add(cat.getName());
-
-		json.put("CG", arr);
-	}
-
-	/**
-	 * writes all Objects in Category into a JSONObject
-	 * 
-	 * @param json
-	 */
-	public void writeObjects(JSONObject json) {
-
-		JSONArray arr = new JSONArray();
-		int i = 1;
-
-		for (Category cats : MODEL.getCategories())
-			for (CpsObject 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();
-			}
-
-		i = 1;
-		for (CpsObject cps : MODEL.getObjectsOnCanvas()) {
-			arr.add(getObjectType(cps));
-			arr.add(cps.getObjName());
-			arr.add(cps.getID());
-			arr.add(cps.getImage());
-			arr.add(cps.getPosition().x);
-			arr.add(cps.getPosition().y);
-			json.put("CVSO" + i++, arr);
-			arr = new JSONArray();
-			;
-
-		}
-	}
-
-	/**
-	 * 
-	 * @param cps
-	 * @return
-	 */
-	public String getObjectType(CpsObject cps) {
-		if (cps instanceof HolonObject)
-			return "HolonObject";
-		if (cps instanceof HolonTransformer)
-			return "HolonTransformer";
-		if (cps instanceof HolonSwitch)
-			return "HolonSwitch";
-		else
-			return "CpsNode";
-	}
-
-	/**
-	 * writes all Elements in Objects in Category into a JSONObject
-	 * 
-	 * @param json
-	 */
-	public void writeElements(JSONObject json) {
-
-		JSONArray arr = new JSONArray();
-		int i = 1;
-
-		for (Category cats : MODEL.getCategories())
-			for (CpsObject cps : cats.getObjects())
-				if (cps instanceof HolonObject)
-					for (HolonElement ele : ((HolonObject) cps).getElements()) {
-						arr.add(ele.getSav());
-						arr.add(ele.getObj());
-						arr.add(ele.getEleName());
-						arr.add(ele.getAmount());
-						arr.add(ele.getEnergy());
-						json.put("CGE" + i++, arr);
-						arr = new JSONArray();
-					}
-
-		i = 1;
-		for (CpsObject cps : MODEL.getObjectsOnCanvas()) {
-			if (cps instanceof HolonObject)
-				for (HolonElement ele : ((HolonObject) cps).getElements()) {
-					arr.add(ele.getSav());
-					arr.add(cps.getID());
-					arr.add(ele.getEleName());
-					arr.add(ele.getAmount());
-					arr.add(ele.getEnergy());
-					json.put("CVSE" + i++, arr);
-					arr = new JSONArray();
-				}
-		}
-	}
-	
-	/**
-	 * Writes all Graph Points into JSONObject
-	 * @param json
-	 */
-	public void writeGraph(JSONObject json) {
-		
-	}
-
-	/**
-	 * write all Edges into a JSONObject
-	 * 
-	 * @param json
-	 */
-	public void writeEdges(JSONObject json) {
-
-		JSONArray arr = new JSONArray();
-		int i = 1;
-
-		for (CpsEdge edge : MODEL.getEdgesOnCanvas()) {
-			arr.add(edge.getA().getID());
-			arr.add(edge.getB().getID());
-			arr.add(edge.getCapacity());
-			arr.add(edge.getFlow());
-			json.put("EDGE" + i++, arr);
-			arr = new JSONArray();
-		}
-	}
-
-	public void readJSON(String path) throws IOException {
-		JSONParser parser = new JSONParser();
-		MODEL.setCategories(new ArrayList<>());
-		MODEL.setObjectsOnCanvas(new ArrayList<>());
-
-		ArrayList<String> obj = new ArrayList<>();
-		ArrayList<String> ele = new ArrayList<>();
-		ArrayList<String> edge = new ArrayList<>();
-
-		try {
-
-			JSONObject json = (JSONObject) parser.parse(new FileReader(path));
-
-			for (Object key : json.keySet()) {
-
-				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 idCounter.setCounter(Integer.parseInt(json.get(key.toString()).toString()));
-			}
-
-			dispatch(obj, json);
-			dispatch(ele, json);
-			dispatch(edge, json);
-
-		} catch (ParseException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-	}
-
-	public void dispatch(ArrayList<String> input, JSONObject json) {
-
-		for (String str : input) {
-			if (str.contains("CGO")) {
-				readCategoryObject((JSONArray) json.get(str));
-			} else if (str.contains("CVSO")) {
-				readCanvasObject((JSONArray) json.get(str));
-			} else if (str.contains("CGE") || str.contains("CVSE")) {
-				readElement((JSONArray) json.get(str));
-			} else if (str.contains("EDGE")) {
-				readEdge((JSONArray) json.get(str));
-			}
-		}
-
-	}
-
-	public void readCategory(JSONArray arr) {
-
-		Iterator<Object> i = arr.iterator();
-
-		while (i.hasNext()) {
-			categoryController.addNewCategory(i.next().toString());
-		}
-	}
-
-	public void readCategoryObject(JSONArray arr) {
-		Iterator<Object> i = arr.iterator();
-
-		String type = i.next().toString();
-
-		if (type.equals("HolonObject")) {
-			categoryController.addNewHolonObject(categoryController.searchCatNode(i.next().toString()),
-					i.next().toString(), new ArrayList<>(), i.next().toString());
-		}
-		if (type.equals("HolonTransformer")) {
-			categoryController.addNewHolonTransformer(categoryController.searchCatNode(i.next().toString()),
-					i.next().toString(), i.next().toString());
-		}
-		if (type.equals("HolonSwitch")) {
-			categoryController.addNewHolonSwitch(categoryController.searchCatNode(i.next().toString()),
-					i.next().toString(), i.next().toString());
-		}
-
-	}
-
-	public void readCanvasObject(JSONArray arr) {
-		Iterator<Object> i = arr.iterator();
-		CpsObject cps = null;
-
-		String type = i.next().toString();
-
-		if (type.equals("HolonObject")) {
-			cps = new HolonObject(i.next().toString());
-		}
-		if (type.equals("HolonTransformer")) {
-			cps = new HolonTransformer(i.next().toString());
-		}
-		if (type.equals("HolonSwitch")) {
-			cps = new HolonSwitch(i.next().toString());
-		}
-		if (type.equals("CpsNode")) {
-			cps = new CpsNode(i.next().toString());
-		}
-
-		cps.setID(Integer.parseInt(i.next().toString()));
-		cps.setImage(i.next().toString());
-		cps.setPosition(Integer.parseInt(i.next().toString()), Integer.parseInt(i.next().toString()));
-
-		canvasController.addObjectIntoCanvas(cps);
-	}
-
-	public void readElement(JSONArray arr) {
-		Iterator<Object> i = arr.iterator();
-
-		String sav = i.next().toString();
-		System.out.println(sav);
-
-		if (sav.equals("Canvas")) {
-			objectController.addNewElementIntoCanvasObject(Integer.parseInt(i.next().toString()), i.next().toString(),
-					Integer.parseInt(i.next().toString()), Float.parseFloat(i.next().toString()));
-		} else
-			objectController.addNewElementIntoCategoryObject(sav, i.next().toString(), i.next().toString(),
-					Integer.parseInt(i.next().toString()), Float.parseFloat(i.next().toString()));
-	}
-
-	public void readEdge(JSONArray arr) {
-		Iterator<Object> i = arr.iterator();
-
-		CpsEdge edge = new CpsEdge(objectController.searchByID(Integer.parseInt(i.next().toString())),
-				objectController.searchByID(Integer.parseInt(i.next().toString())));
-		edge.setCapacity(Float.parseFloat(i.next().toString()));
-		edge.setFlow(Float.parseFloat(i.next().toString()));
-
-		canvasController.addEdgeOnCanvas(edge);
-	}
-}

+ 230 - 0
src/ui/controller/StoreController.java

@@ -0,0 +1,230 @@
+package ui.controller;
+
+import java.awt.Point;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ListIterator;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import classes.Category;
+import classes.CpsEdge;
+import classes.CpsObject;
+import classes.HolonElement;
+import classes.HolonObject;
+import classes.HolonSwitch;
+import classes.HolonTransformer;
+import ui.model.Model;
+import ui.model.idCounter;
+
+public class StoreController {
+
+	private Model MODEL;
+
+	public StoreController(Model model) {
+		this.MODEL = model;
+
+	}
+
+	/**
+	 * Writes the current State of the Modelling into a JSON File which can be
+	 * loaded
+	 * 
+	 * @throws IOException
+	 */
+	public void writeJSONFile(String path) throws IOException {
+
+		JSONObject json = new JSONObject();
+
+		json.put("ID", idCounter.getCounter());
+		writeCategory(json);
+		writeObjects(json);
+		writeElements(json);
+		writeEdges(json);
+		writeElementGraph(json);
+
+		FileWriter writer = new FileWriter(path);
+		writer.write(json.toJSONString());
+		writer.flush();
+		writer.close();
+	}
+
+	/**
+	 * writes all Categories into a JSONObject
+	 * 
+	 * @param json
+	 * @throws IOException
+	 */
+	public void writeCategory(JSONObject json) {
+		JSONArray arr = new JSONArray();
+
+		for (Category cat : MODEL.getCategories())
+			arr.add(cat.getName());
+
+		json.put("CG", arr);
+	}
+
+	/**
+	 * writes all Objects in Category into a JSONObject
+	 * 
+	 * @param json
+	 */
+	public void writeObjects(JSONObject json) {
+
+		JSONArray arr = new JSONArray();
+		int i = 1;
+
+		for (Category cats : MODEL.getCategories())
+			for (CpsObject 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();
+			}
+
+		i = 1;
+		for (CpsObject cps : MODEL.getObjectsOnCanvas()) {
+			arr.add(getObjectType(cps));
+			arr.add(cps.getObjName());
+			arr.add(cps.getName());
+			arr.add(cps.getID());
+			arr.add(cps.getImage());
+			arr.add(cps.getPosition().x);
+			arr.add(cps.getPosition().y);
+			json.put("CVSO" + i++, arr);
+			arr = new JSONArray();
+			;
+
+		}
+	}
+
+	/**
+	 * writes all Elements in Objects in Category into a JSONObject
+	 * 
+	 * @param json
+	 */
+	public void writeElements(JSONObject json) {
+
+		JSONArray arr = new JSONArray();
+		int i = 1;
+
+		for (Category cats : MODEL.getCategories())
+			for (CpsObject cps : cats.getObjects())
+				if (cps instanceof HolonObject)
+					for (HolonElement ele : ((HolonObject) cps).getElements()) {
+						arr.add(ele.getSav());
+						arr.add(ele.getObj());
+						arr.add(ele.getEleName());
+						arr.add(ele.getAmount());
+						arr.add(ele.getEnergy());
+						json.put("CGE" + i++, arr);
+						arr = new JSONArray();
+					}
+
+		i = 1;
+		for (CpsObject cps : MODEL.getObjectsOnCanvas()) {
+			if (cps instanceof HolonObject)
+				for (HolonElement ele : ((HolonObject) cps).getElements()) {
+					arr.add(ele.getSav());
+					arr.add(cps.getID());
+					arr.add(ele.getEleName());
+					arr.add(ele.getAmount());
+					arr.add(ele.getEnergy());
+					json.put("CVSE" + i++, arr);
+					arr = new JSONArray();
+				}
+		}
+	}
+
+	/**
+	 * write all Edges into a JSONObject
+	 * 
+	 * @param json
+	 */
+	public void writeEdges(JSONObject json) {
+
+		JSONArray arr = new JSONArray();
+		int i = 1;
+
+		for (CpsEdge edge : MODEL.getEdgesOnCanvas()) {
+			arr.add(edge.getA().getID());
+			arr.add(edge.getB().getID());
+			arr.add(edge.getCapacity());
+			arr.add(edge.getFlow());
+			json.put("EDGE" + i++, arr);
+			arr = new JSONArray();
+		}
+	}
+
+	/**
+	 * writes the Graph from all Elements into a JSONObject
+	 * 
+	 * @param json
+	 */
+	public void writeElementGraph(JSONObject json) {
+
+		ListIterator<Point> iterator;
+		JSONArray arr = new JSONArray();
+		int i = 1;
+
+		for (Category cats : MODEL.getCategories())
+			for (CpsObject cps : cats.getObjects())
+				if (cps instanceof HolonObject)
+					for (HolonElement ele : ((HolonObject) cps).getElements())
+						if (!ele.getGraphPoints().isEmpty()) {
+							iterator = ele.getGraphPoints().listIterator();
+
+							arr.add(ele.getSav());
+							arr.add(ele.getObj());
+							arr.add(ele.getEleName());
+
+							while (iterator.hasNext()) {
+								Point p = iterator.next();
+								arr.add((int) p.getX());
+								arr.add((int) p.getY());
+							}
+							json.put("CGGP" + i++, arr);
+							arr = new JSONArray();
+						}
+		i = 1;
+		for (CpsObject cps : MODEL.getObjectsOnCanvas()) {
+			if (cps instanceof HolonObject)
+				for (HolonElement ele : ((HolonObject) cps).getElements())
+					if (!ele.getGraphPoints().isEmpty()) {
+						iterator = ele.getGraphPoints().listIterator();
+
+						arr.add(ele.getSav());
+						arr.add(cps.getID());
+						arr.add(ele.getEleName());
+
+						while (iterator.hasNext()) {
+							Point p = iterator.next();
+							arr.add((int) p.getX());
+							arr.add((int) p.getY());
+						}
+						json.put("CVSGP" + i++, arr);
+						arr = new JSONArray();
+					}
+		}
+	}
+
+	/**
+	 * Return the Object Type
+	 * 
+	 * @param cps
+	 * @return
+	 */
+	public String getObjectType(CpsObject cps) {
+		if (cps instanceof HolonObject)
+			return "HolonObject";
+		if (cps instanceof HolonTransformer)
+			return "HolonTransformer";
+		if (cps instanceof HolonSwitch)
+			return "HolonSwitch";
+		else
+			return "CpsNode";
+	}
+
+}

+ 1 - 1
src/ui/view/GUI.java

@@ -491,7 +491,7 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 				}
-				tree.setRowHeight(controller.getScale());
+				tree.setRowHeight(model.getScale());
 				if (hasFocus) {
 					label.setForeground(new Color(0, 0, 255));
 					label.setOpaque(true);

+ 39 - 9
src/ui/view/UnitGraph.java

@@ -50,7 +50,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 	private boolean pointDrag = false;
 	private boolean init = false;
-	private Point tempP = null;
+	private Point tempP = null, p1 = null, p2 = null;
 	private double x = 0, y = 0;
 	private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
 
@@ -349,10 +349,10 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 	public void fillArrayofValue() {
 		for (int i = 0; i < arrayOfValue.length; i++) {
-			arrayOfValue[i] = convertToValueY(getYValueAt_2((int) (i * this.getWidth() / (model.getIterations() - 1))));
+			arrayOfValue[i] = convertToValueY(getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
 		}
 	}
-	
+
 	/**
 	 * 
 	 * @param xVal,
@@ -373,7 +373,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		}
 		return 0;
 	}
-	
+
 	/**
 	 * 
 	 * @param xVal,
@@ -383,17 +383,47 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	public float getYValueAt_2(int xVal) {
 		for (int i = 0; i < pointList.size() - 1; i++) {
 			// get the Points
-			if (xVal <= pointList.get(i + 1).getX()) {
+			if (xVal >= pointList.get(i).getX()) {
 				// Curve erstellen
 				c = buildCurve(pointList.get(i), pointList.get(i + 1));
-				for (int j = 0; j < height; j++) {
-					if (c.contains(xVal, j)) {
-						return j;
+				c.subdivide(cl, cr);
+				// Teil der Kurve aussuchen
+				if (cl.getX1() <= xVal * scaleX && cl.getX2() > xVal * scaleX) {
+					c = cl;
+					//Kurve Links von "unten"
+					if (pointList.get(i).getY() >= pointList.get(i + 1).getY()) {
+						for (int j = (int) (height - 1); j >= 0; j--) {
+							if (c.contains(xVal * scaleX, j * scaleY)) {
+								return (float) (j);
+							}
+						}
+					} else {//Kurve Links von "oben"
+						for (int j = 0; j < height; j++) {
+							if (c.contains(xVal * scaleX, j * scaleY)) {
+								return (float) (j);
+							}
+						}
+					}
+				} else {
+					c = cr;
+					//Kurve Links von "unten"
+					if (pointList.get(i).getY() >= pointList.get(i + 1).getY()) {
+						for (int j = 0; j < height; j++) {
+							if (c.contains(xVal * scaleX, j * scaleY)) {
+								return (float) (j);
+							}
+						}
+					} else {//Kurve Links von "oben"
+						for (int j = (int) (height - 1); j >= 0; j--) {
+							if (c.contains(xVal * scaleX, j * scaleY)) {
+								return (float) (j);
+							}
+						}
 					}
 				}
 			}
 		}
-		return 0;
+		return getYValueAt(xVal);
 	}
 
 	public Point getIntersectionPoint(Line2D l1, Line2D l2) {