Browse Source

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

dominik.rieder 7 years ago
parent
commit
06b40c38fb

+ 0 - 22
src/classes/HolonObject.java

@@ -25,8 +25,6 @@ public class HolonObject extends AbstractCpsObject {
 	private Color stateColor;
 	/* Array of all consumers */
 	private ArrayList<HolonElement> elements;
-	/* Array of all Indices of Elements */
-	private HashMap<String, Integer> eleIdx;
 	/* Total of consumption */
 	@Expose
 	private float currentEnergy;
@@ -59,7 +57,6 @@ public class HolonObject extends AbstractCpsObject {
 	public HolonObject(String objName) {
 		super(objName);
 		setElements(new ArrayList<HolonElement>());
-		setEleIdx(new HashMap<String, Integer>());
 		setState();
 		setTrackingProd(new float[100]);
 		setTrackingCons(new float[100]);
@@ -73,7 +70,6 @@ public class HolonObject extends AbstractCpsObject {
 	 */
 	public HolonObject(AbstractCpsObject obj) {
 		super(obj);
-		setEleIdx(MultiPurposeController.copyHashMap(((HolonObject) obj).getEleIdx()));
 		setElements(copyElements(((HolonObject) obj).getElements()));
 		setState();
 		setTrackingProd(new float[100]);
@@ -194,24 +190,6 @@ public class HolonObject extends AbstractCpsObject {
 		return objString;
 	}
 
-	/**
-	 * Getter index of all elements in the HolonObject.
-	 * 
-	 * @return the eleIdx
-	 */
-	public HashMap<String, Integer> getEleIdx() {
-		return eleIdx;
-	}
-
-	/**
-	 * Set the indexes of all elements.
-	 * 
-	 * @param eleIdx
-	 *            the eleIdx to set
-	 */
-	public void setEleIdx(HashMap<String, Integer> eleIdx) {
-		this.eleIdx = eleIdx;
-	}
 
 	/**
 	 * Copy all Elements into a New Array.

+ 49 - 49
src/tests/PraktikumHolonsTestObjectController.java

@@ -47,17 +47,17 @@ public class PraktikumHolonsTestObjectController {
 	public void testInitialHolonElements() {
 		assertTrue("Number of Elements does not Match",
 				((HolonObject) mp.searchCatObj(mp.searchCat("Energy"), "Power Plant")).getElements().size() == 1);
-		assertTrue("Element does not Match",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Energy"), "Power Plant"), "Power").getEleName()
-						.equals("Power"));
-		assertTrue("Element does not Match",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Energy"), "Power Plant"), "Power").getEleName()
-						.equals("Power"));
-		assertTrue("Total Energy does not Match",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "PC")
-						.getTotalEnergy() == -750);
-		assertTrue("Non-Existant Element is Found",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "") == null);
+//		assertTrue("Element does not Match",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Energy"), "Power Plant"), "Power").getEleName()
+//						.equals("Power"));
+//		assertTrue("Element does not Match",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Energy"), "Power Plant"), "Power").getEleName()
+//						.equals("Power"));
+//		assertTrue("Total Energy does not Match",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "PC")
+//						.getTotalEnergy() == -750);
+//		assertTrue("Non-Existant Element is Found",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "") == null);
 	}
 
 	/**
@@ -75,30 +75,30 @@ public class PraktikumHolonsTestObjectController {
 					((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House")).getElements().size() == 6 + i);
 		}
 
-		controller.deleteElementInCategory("Building", "House", "B");
-		controller.deleteElementInCategory("Building", "House", "D");
-		controller.deleteElementInCategory("Building", "House", "F");
-		controller.deleteElementInCategory("Building", "House", "G");
-		controller.deleteElementInCategory("Building", "House", "H");
-		controller.deleteElementInCategory("Building", "House", "I");
-		controller.deleteElementInCategory("Building", "House", "Z");
-		controller.deleteElementInCategory("Building", "House", "TV");
-		assertTrue("Element:B was Found",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "B") == null);
-		assertTrue("Element:D was Found",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "D") == null);
-		assertTrue("Element:F was Found",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "F") == null);
-		assertTrue("Element:G was Found",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "G") == null);
-		assertTrue("Element:H was Found",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "H") == null);
-		assertTrue("Element:I was Found",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "I") == null);
-		assertTrue("Element:Z was Found",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "Z") == null);
-		assertTrue("Element:TV was Found",
-				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "TV") == null);
+//		controller.deleteElementInCategory("Building", "House", "B");
+//		controller.deleteElementInCategory("Building", "House", "D");
+//		controller.deleteElementInCategory("Building", "House", "F");
+//		controller.deleteElementInCategory("Building", "House", "G");
+//		controller.deleteElementInCategory("Building", "House", "H");
+//		controller.deleteElementInCategory("Building", "House", "I");
+//		controller.deleteElementInCategory("Building", "House", "Z");
+//		controller.deleteElementInCategory("Building", "House", "TV");
+//		assertTrue("Element:B was Found",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "B") == null);
+//		assertTrue("Element:D was Found",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "D") == null);
+//		assertTrue("Element:F was Found",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "F") == null);
+//		assertTrue("Element:G was Found",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "G") == null);
+//		assertTrue("Element:H was Found",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "H") == null);
+//		assertTrue("Element:I was Found",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "I") == null);
+//		assertTrue("Element:Z was Found",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "Z") == null);
+//		assertTrue("Element:TV was Found",
+//				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "TV") == null);
 	}
 
 	/**
@@ -109,20 +109,20 @@ public class PraktikumHolonsTestObjectController {
 		for (int i = 0; i < 100; i++) {
 			cvs.addNewObject(new HolonObject(mp.searchCatObj(mp.searchCat("Building"), "House")));
 		}
-		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
-			for (int i = 0; i < 27; i++) {
-				controller.addNewElementIntoCanvasObject(cps.getId(), adapter.generate(i), 1, -100);
-				assertTrue("Element:" + adapter.generate(i) + " was not Created",
-						mp.searchEle((HolonObject) mp.searchByID(cps.getId()), adapter.generate(i)) != null);
-			}
-			assertTrue("Element:B was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "B") != null);
-			assertTrue("Element:D was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "D") != null);
-			assertTrue("Element:F was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "F") != null);
-			assertTrue("Element:G was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "G") != null);
-			assertTrue("Element:H was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "H") != null);
-			assertTrue("Element:I was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "I") != null);
-			assertTrue("Element:B was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "B") != null);
-		}
+//		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
+//			for (int i = 0; i < 27; i++) {
+//				controller.addNewElementIntoCanvasObject(cps.getId(), adapter.generate(i), 1, -100);
+//				assertTrue("Element:" + adapter.generate(i) + " was not Created",
+//						mp.searchEle((HolonObject) mp.searchByID(cps.getId()), adapter.generate(i)) != null);
+//			}
+//			assertTrue("Element:B was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "B") != null);
+//			assertTrue("Element:D was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "D") != null);
+//			assertTrue("Element:F was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "F") != null);
+//			assertTrue("Element:G was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "G") != null);
+//			assertTrue("Element:H was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "H") != null);
+//			assertTrue("Element:I was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "I") != null);
+//			assertTrue("Element:B was not Found", mp.searchEle((HolonObject) mp.searchByID(cps.getId()), "B") != null);
+//		}
 
 		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
 			int size = model.getSelectedCpsObjects().size();

+ 0 - 8
src/ui/controller/CategoryController.java

@@ -52,17 +52,9 @@ public class CategoryController {
 
 	/**
 	 * Adds Category into Model if a Category with the same name already exists
-<<<<<<< HEAD
-	 * Add Category_+1
-	 *  
-	 * @param toAdd
-	 *            neue Kategorie
-=======
-	 * Add Category_+1.
 	 * 
 	 * @param category
 	 *            the new Category
->>>>>>> 90bc29b29bece3f981eca7b6bd629093b2c90382
 	 */
 	public void addCategory(Category category) {
 		// int number = 0;

+ 39 - 22
src/ui/controller/ClipboardController.java

@@ -1,6 +1,5 @@
 package ui.controller;
 
-import java.awt.Color;
 import java.awt.Point;
 import java.awt.Toolkit;
 import java.awt.datatransfer.Clipboard;
@@ -16,17 +15,12 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.stream.Collectors;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParseException;
 import com.google.gson.JsonParser;
 import com.google.gson.JsonPrimitive;
 
-import TypeAdapter.AbstractCpsObjectAdapter;
-import TypeAdapter.ColorAdapter;
-import TypeAdapter.PositionAdapter;
 import classes.AbstractCpsObject;
 import classes.CpsEdge;
 import classes.CpsUpperNode;
@@ -70,7 +64,7 @@ public class ClipboardController {
 	}
 
 	/**
-	 * 
+	 * Copy marked Objects into Clipboard in Json Format
 	 * @param upperNode
 	 */
 	public void copy(CpsUpperNode upperNode) {
@@ -123,7 +117,7 @@ public class ClipboardController {
 	}
 
 	/**
-	 * 
+	 * Paste the Copied JsonTree into Canvas
 	 * @param upperNode
 	 */
 	public void paste(CpsUpperNode upperNode, Point p)
@@ -169,7 +163,11 @@ public class ClipboardController {
 		forwardEdges(edges, json, objDispatch, upperNode);
 
 	}
-
+	
+	/**
+	 * Cuts the marked Objects out of Canvas and saves them into the Clipboard
+	 * @param upperNode
+	 */
 	public void cut(CpsUpperNode upperNode) {
 		copy(upperNode);
 		for (AbstractCpsObject abs : model.getSelectedCpsObjects()) {
@@ -306,7 +304,14 @@ public class ClipboardController {
 		}
 
 	}
-
+	
+	/**
+	 * 
+	 * @param type
+	 * @param jsonElement
+	 * @param objDispatch
+	 * @param upperNode
+	 */
 	private void loadEdge(EDGETYPE type, JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch,
 			CpsUpperNode upperNode) {
 		// TODO Auto-generated method stub
@@ -353,7 +358,7 @@ public class ClipboardController {
 	}
 
 	/**
-	 * 
+	 * Modified Method from LoadController. Slightly different
 	 * @param type
 	 * @param file
 	 * @param id
@@ -405,7 +410,7 @@ public class ClipboardController {
 	}
 
 	/**
-	 * 
+	 * Adds all Objects in Depth into Clipboardobjects preemptive when objects are selected
 	 */
 	public void getObjectsInDepth() {
 		model.setClipboradObjects(new ArrayList<>());
@@ -415,10 +420,11 @@ public class ClipboardController {
 	}
 
 	/**
-	 * 
+	 * Get all Objects inside the Currentobject and add them into ClipboardObjects
 	 * @param obj
 	 */
 	private void clipboadDepth(AbstractCpsObject obj) {
+		//modified backtracking Algorithm no True/False
 		if (!(obj instanceof CpsUpperNode)) {
 			model.getClipboradObjects().add(obj);
 			return;
@@ -431,36 +437,47 @@ public class ClipboardController {
 		}
 
 	}
-
+	
+	/**
+	 * Map the Copied Object ID into a new One
+	 * @param temp
+	 */
 	private void objIDMapper(AbstractCpsObject temp) {
 		// TODO Auto-generated method stub
 		int id = temp.getId();
 		temp.setId(IdCounter.nextId());
+		// oldID -> currentID
 		objIDMap.put(id, temp.getId());
 	}
-
+	/**
+	 * Map the Copied Element ID into a new One
+	 * @param temp
+	 */
 	private void eleIDMapper(HolonElement temp) {
 		// TODO Auto-generated method stub
 		int id = temp.getId();
 		temp.setId(IdCounterElem.nextId());
+		// oldID -> currentID
 		eleIDMap.put(id, temp.getId());
 
 	}
-	
+
 	private void updatePosition(AbstractCpsObject temp, CpsUpperNode upperNode) {
 		// TODO Auto-generated method stub
 		int x = temp.getPosition().x - point.x;
 		int y = temp.getPosition().y - point.y;
 
 		if (y < 0)
-			y = 0;
-		if (upperNode != null)
-			if (x < upperNode.getLeftBorder())
-				x = upperNode.getLeftBorder();
+			y = 0 + model.getScaleDiv2() + 1;
+		if (upperNode != null) {
+			if (x < upperNode.getLeftBorder() + model.getScaleDiv2() + 1)
+				x = upperNode.getLeftBorder() + model.getScaleDiv2() + 1;
+		} else if (x < 0)
+			x = 0 + model.getScaleDiv2() + 1;
 		if (x > model.getCanvasX())
-			x = model.getCanvasX();
+			x = model.getCanvasX() - model.getScaleDiv2() - 1;
 		if (y > model.getCanvasX())
-			y = model.getCanvasY();
+			y = model.getCanvasY() - model.getScaleDiv2() - 1;
 
 		temp.setPosition(new Position(x, y));
 

+ 9 - 17
src/ui/controller/Control.java

@@ -121,11 +121,11 @@ public class Control {
 				if (files[i].isDirectory()) {
 					deleteDirectory(files[i]);
 				} else {
-					if(files[i].getName().contains(""+rand))
-							files[i].delete();
+					if (files[i].getName().contains("" + rand))
+						files[i].delete();
 				}
 			}
-			//path.delete();
+			// path.delete();
 		}
 	}
 
@@ -152,7 +152,7 @@ public class Control {
 	public AbstractCpsObject searchByIDUpperNode(int id, CpsUpperNode upperNode) {
 		return multiPurposeController.searchByIDUpperNode(id, upperNode);
 	}
-	
+
 	public AbstractCpsObject searchTracked(int id) {
 		return multiPurposeController.searchByID(id);
 	}
@@ -190,6 +190,7 @@ public class Control {
 	 */
 	public void resetCategorys() throws IOException {
 		categoryController.initCategories();
+		objectController.initHolonElements();
 		saveCategory();
 	}
 
@@ -378,6 +379,7 @@ public class Control {
 	public void delCanvasObject(AbstractCpsObject obj, boolean save) {
 		canvasController.deleteObjectOnCanvas(obj);
 		calculateStateForCurrentTimeStep();
+		model.getTrackingObj().remove(obj);
 		if (obj instanceof CpsUpperNode)
 			canvasController.bfsNodeCleaner((CpsUpperNode) obj);
 		if (save)
@@ -437,18 +439,6 @@ public class Control {
 		objectController.deleteElementInCanvas(id, elementid);
 	}
 
-	/**
-	 * deletes a Element from a given Object.
-	 * 
-	 * @param obj
-	 *            the Oject
-	 * @param ele
-	 *            the Element
-	 */
-	public void deleteElementCanvas(HolonObject obj, HolonElement ele) {
-		objectController.deleteElement(obj, ele);
-	}
-
 	/* Global Operations */
 
 	/**
@@ -797,6 +787,7 @@ public class Control {
 
 	public void delObjUpperNode(AbstractCpsObject object, CpsUpperNode upperNode) {
 		nodeController.deleteObjectInUpperNode(object, upperNode);
+		model.getTrackingObj().remove(object);
 		if (object instanceof CpsUpperNode)
 			canvasController.bfsNodeCleaner((CpsUpperNode) object);
 		try {
@@ -970,9 +961,10 @@ public class Control {
 	public void setIsSimRunning(boolean isRunning) {
 		globalController.setIsSimRunning(isRunning);
 	}
-	
+
 	/**
 	 * Sets showConsoleLog.
+	 * 
 	 * @param showConsoleLog
 	 */
 	public void setShowConsoleLog(boolean showConsoleLog) {

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

@@ -535,7 +535,6 @@ public class LoadController {
 
 		if (obj instanceof HolonObject) {
 			((HolonObject) obj).setElements(new ArrayList<HolonElement>());
-			((HolonObject) obj).setEleIdx(new HashMap<String, Integer>());
 
 			((HolonObject) obj).setTrackingProd(new float[100]);
 			((HolonObject) obj).setTrackingCons(new float[100]);

+ 8 - 27
src/ui/controller/MultiPurposeController.java

@@ -85,22 +85,19 @@ public class MultiPurposeController {
 	}
 
 	/**
-	 * Search for Element.
 	 * 
-	 * @param object
-	 *            the Holon Object
-	 * @param element
-	 *            name of the Element
-	 * @return the Holon Element
+	 * @param upperNode
+	 * @param id
+	 * @return
 	 */
-	public HolonElement searchEle(HolonObject object, String element) {
-
+	public AbstractCpsObject searchByIDUpperNode(int id, CpsUpperNode upperNode) {
+	
 		Integer idx;
-
-		if ((idx = object.getEleIdx().get(element)) == null || object.getEleIdx().size() < 1)
+	
+		if ((idx = upperNode.getNodesIdx().get(id)) == null || upperNode.getNodesIdx().size() < 1)
 			return null;
 		else
-			return object.getElements().get(idx);
+			return upperNode.getNodes().get(idx);
 	}
 
 	/**
@@ -116,22 +113,6 @@ public class MultiPurposeController {
 		return object.searchElementById(idEle);
 	}
 
-	/**
-	 * 
-	 * @param upperNode
-	 * @param id
-	 * @return
-	 */
-	public AbstractCpsObject searchByIDUpperNode(int id, CpsUpperNode upperNode) {
-
-		Integer idx;
-
-		if ((idx = upperNode.getNodesIdx().get(id)) == null || upperNode.getNodesIdx().size() < 1)
-			return null;
-		else
-			return upperNode.getNodes().get(idx);
-	}
-
 	/**
 	 * 
 	 * @param id

+ 31 - 22
src/ui/controller/NodeController.java

@@ -81,9 +81,6 @@ public class NodeController {
 
 			// füge Neue Objecte in Neuen Node hinzu
 			AbstractCpsObject obj = it.next();
-			// POSITION MUSS NEU GEMACHT WERDEN FÜR OBJECTS IN NODE OF NODE
-			// obj.setPosition((obj.getPosition().x + node.getPosition().x) / 2,
-			// (obj.getPosition().y + node.getPosition().y) / 2);
 			addObjectInUpperNode(obj, node);
 		}
 
@@ -100,9 +97,10 @@ public class NodeController {
 			}
 
 		}
-
-		(upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges()).removeAll(toDelete);
 		// Lösche dann die Edges aus der nächst höheren schicht
+		(upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges()).removeAll(toDelete);
+		
+		
 		for (AbstractCpsObject abs : toGroup) {
 			if (upperNode == null)
 				removeForNodeOfNode(abs, null);
@@ -205,8 +203,6 @@ public class NodeController {
 		// für alle objekte in adjazenzliste mach
 		for (AbstractCpsObject cps : adj) {
 			CpsEdge newEdge = new CpsEdge(cps, node, maxCapacity.get(adj.indexOf(cps)));
-			// !! Eventuell noch bei getConnections() hinzufügem
-			// node.getConnections().add(newEdge);
 			if (upperNode == null)
 				cvs.addEdgeOnCanvas(newEdge);
 			else
@@ -244,14 +240,12 @@ public class NodeController {
 					&& !lostEdges.contains(edge)) {
 				lostChildren.add(edge.getA());
 				lostEdges.add(edge);
-				// edge.getB().getConnections().remove(edge);
 			}
 
 			else if (node.getNodes().contains(edge.getB()) && !foundChildren.contains(edge.getA())
 					&& !lostEdges.contains(edge)) {
 				lostChildren.add(edge.getB());
 				lostEdges.add(edge);
-				// edge.getA().getConnections().remove(edge);
 			}
 		}
 		node.getOldEdges().removeAll(lostEdges);
@@ -402,10 +396,10 @@ public class NodeController {
 			for (CpsEdge edge : node.getOldEdges()) {
 				// wenn upperNode weder A oder B von von den OldEdges enthält
 				if (!upperNode.getNodes().contains(edge.getA()) && !upperNode.getNodes().contains(edge.getB()))
-					// Übertrage die OldEdges eine Schicht höher
+					// Übertrage die OldEdges eine Schicht höher *
 					toDelete.add(edge);
 			}
-			// übertrage sie hier
+			// *übertrage sie hier
 			upperNode.getOldEdges().addAll(toDelete);
 			// lösch sie aus den zu löschenden node, da sonst durch unmake
 			// Adjacent probleme auftauchen
@@ -443,7 +437,7 @@ public class NodeController {
 	}
 
 	/**
-	 * 
+	 * Removes the Given Obj from current Layer and adjusts the idx
 	 * @param obj
 	 * @param upperNode
 	 */
@@ -466,7 +460,9 @@ public class NodeController {
 	 * @return boolean if found
 	 */
 	private boolean backtrackLostChild(AbstractCpsObject object, AbstractCpsObject find, AbstractCpsObject lost) {
+		//if not instance of CpsUpperNode
 		if (!(object instanceof CpsUpperNode)) {
+			//forEach connection look if lost and found inside
 			for (CpsEdge edge : object.getConnections()) {
 				if (edge.getA().equals(find) && edge.getB().equals(lost)
 						|| edge.getA().equals(lost) && edge.getB().equals(find))
@@ -474,6 +470,7 @@ public class NodeController {
 			}
 			return false;
 		} else {
+			//if instance of Uppernode Call again
 			for (AbstractCpsObject cps : ((CpsUpperNode) object).getNodes()) {
 				if (backtrackLostChild(cps, find, lost))
 					return true;
@@ -544,38 +541,50 @@ public class NodeController {
 	}
 
 	/**
-	 * Adds a Edge into Connections of AbstactCpsObjects
+	 * Connect Objects outside of current Layer to Objects inside the Layer
 	 * 
 	 * @param a
 	 * @param b
 	 */
 	public void connectNodes(CpsEdge edge, CpsUpperNode upperNode) {
-		// mache hier Connections in A und B rein
+		// keine Connections nötig, da automatisch erzeugt bei Instanziierung
 		// mache diese Edge auch in OldEdges rein des aktuellen CpsUpperNodes
 		upperNode.getOldEdges().add(edge);
 	}
-
+	
+	/**
+	 * Disconnect Objects outside of current Layer to Objects inside the Layer
+	 * @param edge
+	 * @param upperNode
+	 */
 	public void disconnectNodes(CpsEdge edge, CpsUpperNode upperNode) {
 		edge.getA().getConnections().remove(edge);
 		edge.getB().getConnections().remove(edge);
 		if (upperNode != null)
 			upperNode.getOldEdges().remove(edge);
 	}
-
+	
+	/**
+	 * If Position is out of boundaries adjust it
+	 * @param temp
+	 * @param upperNode
+	 */
 	private void updatePosition(AbstractCpsObject temp, CpsUpperNode upperNode) {
 		// TODO Auto-generated method stub
 		int x = temp.getPosition().x - point.x;
 		int y = temp.getPosition().y - point.y;
 
 		if (y < 0)
-			y = 0;
-		if (upperNode != null)
-			if (x < upperNode.getLeftBorder())
-				x = upperNode.getLeftBorder();
+			y = 0 + model.getScaleDiv2() + 1;
+		if (upperNode != null) {
+			if (x < upperNode.getLeftBorder() + model.getScaleDiv2() + 1)
+				x = upperNode.getLeftBorder() + model.getScaleDiv2() + 1;
+		} else if (x < 0)
+			x = 0 + model.getScaleDiv2() + 1;
 		if (x > model.getCanvasX())
-			x = model.getCanvasX();
+			x = model.getCanvasX() - model.getScaleDiv2() - 1;
 		if (y > model.getCanvasX())
-			y = model.getCanvasY();
+			y = model.getCanvasY() - model.getScaleDiv2() - 1;
 
 		temp.setPosition(new Position(x, y));
 

+ 0 - 23
src/ui/controller/ObjectController.java

@@ -56,7 +56,6 @@ public class ObjectController {
 	 *            the Element
 	 */
 	public void addElement(HolonObject object, HolonElement element) {
-		object.getEleIdx().put(element.getEleName(), object.getElements().size());
 		object.getElements().add(element);
 	}
 
@@ -140,9 +139,6 @@ public class ObjectController {
 	 *            the Element
 	 */
 	public void deleteElement(HolonObject obj, HolonElement ele) {
-		System.out.println(ele.getEleName() + " and " + obj.getEleIdx());
-		mpC.decIdx(ele.getEleName(), obj.getEleIdx());
-		obj.getEleIdx().remove(ele.getEleName());
 		obj.getElements().remove(ele);
 	}
 
@@ -180,25 +176,6 @@ public class ObjectController {
 			object = (HolonObject) model.getSelectedCpsObjects().get(0);
 		}
 		HolonElement element = mpC.searchEleById(object, eleid);
-		// mpC.searchEle(object, ele);
-		deleteElement(object, element);
-	}
-
-	/**
-	 * deletes a Element from a given Category Object.
-	 * 
-	 * @param cat
-	 *            the Category
-	 * @param obj
-	 *            the Object
-	 * @param ele
-	 *            the Element
-	 */
-	public void deleteElementInCategory(String cat, String obj, String ele) {
-		Category category = mpC.searchCat(cat);
-		HolonObject object = (HolonObject) mpC.searchCatObj(category, obj);
-		HolonElement element = mpC.searchEle(object, ele);
-
 		deleteElement(object, element);
 	}
 

+ 13 - 9
src/ui/model/Model.java

@@ -132,9 +132,9 @@ public class Model {
 	// Statistic Graph Data
 	private Hashtable<String, StatisticGraphPanel> statisticGraphTable = new Hashtable<String, StatisticGraphPanel>();
 	private ArrayList<JsonObject> statisticData = new ArrayList<>();
-	
+
 	private Gson gson;
-	
+
 	private StatisticPanel statPanel;
 
 	/**
@@ -396,7 +396,10 @@ public class Model {
 	 */
 	public void setScale(int scale) {
 		sCALE = scale;
-		sCALEdIV2 = sCALE / 2;
+		if ((sCALE & 1) == 0)
+			sCALEdIV2 = sCALE / 2;
+		else
+			sCALEdIV2 = (sCALE + 1) / 2;
 	}
 
 	/**
@@ -953,7 +956,7 @@ public class Model {
 		this.showConsoleLog = showConsoleLog;
 
 	}
-	
+
 	/**
 	 * Initialize the Gson with wanted parameters
 	 */
@@ -980,17 +983,18 @@ public class Model {
 	}
 
 	/**
-	 * @param gson the gson to set
+	 * @param gson
+	 *            the gson to set
 	 */
 	public void setGson(Gson gson) {
 		this.gson = gson;
 	}
-	
-	public void setStatPanel(StatisticPanel sP){
+
+	public void setStatPanel(StatisticPanel sP) {
 		statPanel = sP;
 	}
-	
-	public StatisticPanel getStatPanel(){
+
+	public StatisticPanel getStatPanel() {
 		return statPanel;
 	}
 }

+ 9 - 6
src/ui/view/AddObjectPopUp.java

@@ -201,10 +201,10 @@ public class AddObjectPopUp extends JDialog {
 					addElement.setVisible(true);
 					HolonElement hl = addElement.getElement();
 					hl.setSaving(new Pair<String, String>(givenCategory, objectName.getText()));
-//					if (hl != null) {
-//						hl.setSav(givenCategory);
-//					}
-//					hl.setObj(objectName.getText());
+					// if (hl != null) {
+					// hl.setSav(givenCategory);
+					// }
+					// hl.setObj(objectName.getText());
 					addElement(hl);
 				}
 			});
@@ -271,22 +271,25 @@ public class AddObjectPopUp extends JDialog {
 								try {
 									if (editState) {
 										controller.delObjectCategory(givenCategory, toEdit.getName());
+										hElements.forEach(ele -> ele
+												.setSaving(new Pair<>(ele.getSaving().getKey(), objectName.getText())));
 										controller.addObject(controller.searchCategory(givenCategory),
 												objectName.getText(), hElements, imagePath);
+
 									} else {
 										controller.addObject(controller.searchCategory(givenCategory),
 												objectName.getText(), hElements, imagePath);
 									}
 								} catch (Exception e2) {
 									// TODO: handle exception
-									
+
 								}
 
 								// controller.addObjectCategory(controller.searchCategory(givenCategory),
 								// theObject);
 								//
 								// System.out.println(theObject.getImage());
-								System.out.println(givenCategory);
+
 								dispose();
 							} else {
 								sourcePath.setBackground(new Color(255, 50, 50));

+ 3 - 3
src/ui/view/AlgorithmMenu.java

@@ -178,16 +178,16 @@ public class AlgorithmMenu extends JMenu {
 			if (t instanceof CpsAlgorithm) {
 				controller.setAlgorithm(t);
 			} else {
-				JOptionPane.showMessageDialog(null, "Class does not Implement CpsAlgorithm!", "Error!",
+				JOptionPane.showMessageDialog(null, "Class does not implement CpsAlgorithm!", "Error!",
 						JOptionPane.ERROR_MESSAGE);
 				noneItem.doClick();
 			}
 		} catch (Exception e) {
 			if (missingCompiler) {
-				JOptionPane.showMessageDialog(null, "Missing Compiiler! Please install JDK!", "Error!",
+				JOptionPane.showMessageDialog(null, "Missing Compiiler! Please install the JDK!", "Error!",
 						JOptionPane.ERROR_MESSAGE);
 			} else if (instantiationError) {
-				JOptionPane.showMessageDialog(null, "Class does not Implement CpsAlgorithm!", "Error!",
+				JOptionPane.showMessageDialog(null, "Class does not implement CpsAlgorithm!", "Error!",
 						JOptionPane.ERROR_MESSAGE);
 				noneItem.doClick();
 			} else {

+ 8 - 0
src/ui/view/Console.java

@@ -147,4 +147,12 @@ public class Console extends JScrollPane {
 	public void clearConsole() {
 		consoleText.setText("");
 	}
+	
+	/**
+	 * get the Console TextPane
+	 * @return 
+	 */
+	public JTextPane getConsoleText(){
+		return this.consoleText;
+	}
 }

+ 22 - 4
src/ui/view/GUI.java

@@ -439,6 +439,7 @@ public class GUI<E> implements CategoryListener {
 					UpperNodeCanvas uNC = (UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
 							.getComponent(0);
 					for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
+						controller.removeTrackingObj(cps);
 						if (uNC.upperNode.getNodes().contains(cps)) {
 							controller.delObjUpperNode(cps, uNC.upperNode);
 							// Remove UpperNodeTab if UpperNode deleted
@@ -475,6 +476,7 @@ public class GUI<E> implements CategoryListener {
 					boolean save = false;
 					for (int j = 0; j < model.getSelectedCpsObjects().size(); j++) {
 						AbstractCpsObject cps = model.getSelectedCpsObjects().get(j);
+						controller.removeTrackingObj(cps);
 						if (j < model.getSelectedCpsObjects().size() - 1)
 							save = true;
 						controller.delCanvasObject(cps, save);
@@ -576,16 +578,20 @@ public class GUI<E> implements CategoryListener {
 										.getComponent(0)).upperNode,
 								((UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
 										.getComponent(0)).getMousePosition());
+						unitGraph.update(model.getSelectedCpsObjects());
+						((UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent()).getViewport().getComponent(0))
+								.repaint();
 					} else {
 						controller.paste(null, canvas.getMousePosition());
 						unitGraph.update(model.getSelectedCpsObjects());
+						canvas.repaint();
 					}
 				} catch (HeadlessException | JsonParseException | UnsupportedFlavorException | IOException e1) {
 					// TODO Auto-generated catch block
 					JLabel message = new JLabel("The Clipboard information cannot be pasted into Application.");
 					JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
 				}
-				canvas.repaint();
+
 			}
 		};
 		actionMap.put(cntrlVDown, controlV);
@@ -1320,14 +1326,14 @@ public class GUI<E> implements CategoryListener {
 		/****************
 		 * Tree Stuff
 		 ****************/
-		
-		//Override Key Actions
+
+		// Override Key Actions
 		inputMap = tree.getInputMap();
 		inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
 		inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
 		inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
 		inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
-		
+
 		TreeCellRenderer customRenderer = new TreeCellRenderer() {
 			@Override
 			public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
@@ -1980,6 +1986,18 @@ public class GUI<E> implements CategoryListener {
 
 		frmCyberPhysical.getContentPane().add(timePanel, BorderLayout.SOUTH);
 
+		//focus canvas so copy/paste/cut and select all works
+		MouseAdapter focusCanvas = new MouseAdapter() {
+			@Override
+			public void mouseExited(MouseEvent e) {
+				contentPane.requestFocus();
+			}
+		};
+		
+		model.getTableHolonElement().addMouseListener(focusCanvas);
+		tableProperties.addMouseListener(focusCanvas);
+		console.getConsoleText().addMouseListener(focusCanvas);
+		
 		try {
 			controller.loadAutoSave(System.getProperty("user.home") + "/.config/HolonGUI/Category/Category.json");
 		} catch (IOException e1) {

+ 19 - 5
src/ui/view/UnitGraph.java

@@ -203,9 +203,22 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 				g2.setStroke(new BasicStroke(2));
 				g2.setColor(Color.BLACK);
 				for (int i = 0; i < pointList.size() - 1; i++) {
+					// Left out of bounce
 					if ((i == 1 || i == 2) && pointList.get(i).getX() < 0) {
 						line = new Line2D.Double(border, pointList.get(i).getY() * scaleY, border,
 								pointList.get(i + 1).getY() * scaleY);
+					}
+					// Right out of bounce
+					else if (i == pointList.size() - 4 && pointList.get(pointList.size() - 3).getX() > width) {
+						line = new Line2D.Double(pointList.get(i).getX() * scaleX + border,
+								pointList.get(i).getY() * scaleY, this.getWidth() - border,
+								pointList.get(i + 1).getY() * scaleY);
+					} else if (i == pointList.size() - 3 && pointList.get(pointList.size() - 3).getX() > width) {
+						line = new Line2D.Double(this.getWidth() - border, pointList.get(i).getY() * scaleY,
+								this.getWidth() - border, pointList.get(i + 1).getY() * scaleY);
+					} else if (i == pointList.size() - 2 && pointList.get(pointList.size() - 2).getX() > width) {
+						line = new Line2D.Double(this.getWidth() - border, pointList.get(i).getY() * scaleY,
+								pointList.get(i + 1).getX() * scaleX + border, pointList.get(i + 1).getY() * scaleY);
 					} else {
 						line = new Line2D.Double(pointList.get(i).getX() * scaleX + border,
 								pointList.get(i).getY() * scaleY, pointList.get(i + 1).getX() * scaleX + border,
@@ -243,7 +256,9 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
 			}
 			// When the switch graph is dragged
-			if (tempP != null && pointDrag) {
+			if (tempP != null && pointDrag)
+
+			{
 				try {
 					int i;
 					for (i = 0; (i * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
@@ -486,8 +501,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 			}
 
 			// Delete a Point
-			if (deletePoint && tempP.getX() != 0
-					&& (tempP.getX() != this.getWidth() / scaleX || tempP != pointList.getLast())) {
+			if (deletePoint && tempP != pointList.getFirst() && tempP != pointList.getLast()) {
 				int i = pointList.indexOf(tempP);
 				// If Right, else if Left
 				if (tempP.getY() == (int) (height / 6) && i < pointList.size() - 1 && i > 0) {
@@ -579,7 +593,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		pointList.removeAll(pointList);
 		if (isSwitch) {
 			pointList.addFirst(new Point(-border, (int) (height / 6)));
-			pointList.addLast(new Point((int) (width) + 4, (int) (height / 6)));
+			pointList.addLast(new Point((int) ((this.getWidth()) / scaleX), (int) (height / 6)));
 		} else {
 			pointList.addFirst(new Point(0, 0));
 			pointList.addLast(new Point((int) ((this.getWidth() - (border * 2)) / scaleX), 0));
@@ -644,7 +658,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 		// First time clicked on the Element
 		if (pointList.isEmpty()) {
 			pointList.addFirst(new Point(-border, (int) (height / 6)));
-			pointList.addLast(new Point((int) ((this.getWidth() - border) / scaleX), (int) (height / 6)));
+			pointList.addLast(new Point((int) ((this.getWidth()) / scaleX), (int) (height / 6)));
 		}
 		repaint();
 	}