Selaa lähdekoodia

some code cleaning concerning mainly MyCanvas and UpperNodeCanvas

I. Dix 7 vuotta sitten
vanhempi
commit
dc395a682c

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

@@ -79,7 +79,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -103,12 +102,12 @@ public class Control {
     public void deleteDirectory(File path) {
         if (path.exists()) {
             File[] files = path.listFiles();
-            for (int i = 0; i < files.length; i++) {
-                if (files[i].isDirectory()) {
-                    deleteDirectory(files[i]);
+            for (File file : files) {
+                if (file.isDirectory()) {
+                    deleteDirectory(file);
                 } else {
-                    if (files[i].getName().contains("" + rand))
-                        files[i].delete();
+                    if (file.getName().contains("" + rand))
+                        file.delete();
                 }
             }
             // path.delete();
@@ -277,7 +276,6 @@ public class Control {
             try {
                 autoSave();
             } catch (IOException e) {
-                // TODO Auto-generated catch block
                 e.printStackTrace();
             }
         }
@@ -298,7 +296,6 @@ public class Control {
             try {
                 autoSave();
             } catch (IOException e) {
-                // TODO Auto-generated catch block
                 e.printStackTrace();
             }
     }
@@ -313,7 +310,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -328,7 +324,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -369,7 +364,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -398,7 +392,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -641,7 +634,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -656,7 +648,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -698,7 +689,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -708,7 +698,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -724,7 +713,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -734,7 +722,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -744,7 +731,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -756,7 +742,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
 
@@ -767,7 +752,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -777,7 +761,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -787,7 +770,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -797,7 +779,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -861,7 +842,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
@@ -871,7 +851,6 @@ public class Control {
         try {
             autoSave();
         } catch (IOException e) {
-            // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }

+ 931 - 997
src/ui/model/Model.java

@@ -1,1016 +1,950 @@
 package ui.model;
 
-import java.awt.Color;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.swing.JTable;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-
 import TypeAdapter.AbstractCpsObjectAdapter;
 import TypeAdapter.ColorAdapter;
 import TypeAdapter.PairAdapter;
 import TypeAdapter.PositionAdapter;
-import classes.AbstractCpsObject;
-import classes.Category;
-import classes.CpsEdge;
-import classes.CpsUpperNode;
-import classes.HolonElement;
-import classes.HolonSwitch;
-import classes.Pair;
-import classes.Position;
+import classes.*;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
 import interfaces.CategoryListener;
 import interfaces.GraphListener;
 import interfaces.ObjectListener;
+import ui.view.*;
 
-import ui.view.Console;
-import ui.view.DefaulTable;
-import ui.view.PropertyTable;
-import ui.view.StatisticGraphPanel;
-import ui.view.StatisticPanel;
+import javax.swing.*;
+import java.awt.*;
+import java.util.*;
+import java.util.List;
 
 /**
  * The Class Model is the class where everything is saved. All changes made to
  * the Data is managed via a controller.
- * 
- * @author Gruppe14
  *
+ * @author Gruppe14
  */
 public class Model {
 
-	// Canvas Attributes
-	private String imgPath = "";
-	private int backgroundMode = 0;
-	private int backgroundWidth = 0;
-	private int backgroundHeight = 0;
-	private int canvasX = 1000;
-	private int canvasY = 1000;
-
-	// Global Variables
-	private static int sCALE = 50; // Picture Scale
-	private static int sCALEdIV2 = sCALE / 2;
-	private static int holonBodysCALE = 100; // Picture Scale
-	private static final int ITERATIONS = 100;
-	private int curIteration = 0;
-	private LinkedList<Color> subNetColors = new LinkedList<>();
-	// ID of the Selected Object
-	private AbstractCpsObject selectedCpsObject = null;
-	private HolonElement selectedHolonElement;
-	private CpsEdge selectedEdge;
-	private ArrayList<AbstractCpsObject> selectedObjects = new ArrayList<AbstractCpsObject>();
-	private ArrayList<AbstractCpsObject> clipboardObjects = new ArrayList<AbstractCpsObject>();
-	private Console console;
-	private HashMap<Integer, ArrayList<HolonElement>> eleToDelete;
-	// Capacity for Edge
-	private float maxCapacity;
-
-	// Table for HolonElements --> all cells are editable
-	private JTable tableHolonElement;
-
-	private ArrayList<GraphListener> graphListeners = new ArrayList<GraphListener>();
-	// Iteration Speed
-	private int timerSpeed = 1000;
-
-	private int selectedID = 0;
-	// number of the current autosave
-	private int autoSaveNr = -1;
-	// number of max simultaneous autosaves
-	private int numberOfSaves = 35;
-	// if the simulation is running and has not been reseted
-	private boolean isSimRunning = false;
-	// if the console log of the program should be displayed
-	private boolean showConsoleLog = true;
-	/*
-	 * Array of all categories in the model. It is set by default with the
-	 * categories ENERGY, BUILDINGS and COMPONENTS
-	 */
-	private ArrayList<Category> categories;
-
-	/*
-	 * Array of all HolonObj and HolonSwitches, that should be tracked through
-	 * out the statistics tab
-	 */
-	private ArrayList<AbstractCpsObject> trackedObjects;
-
-	/*
-	 * Array of all CpsObjects in our canvas. It is set by default as an empty
-	 * list.
-	 */
-	private ArrayList<AbstractCpsObject> objectsOnCanvas;
-
-	private HashMap<String, Integer> cgIdx;
-	private HashMap<Integer, Integer> cvsObjIdx;
-
-	/*
-	 * Array of all CpsObjects in our canvas. It is set by default as an empty
-	 * list.
-	 */
-	private ArrayList<CpsEdge> edgesOnCanvas;
-
-	/*
-	 * Array for all Listeners
-	 */
-	private List<CategoryListener> categoryListeners;
-	private List<ObjectListener> objectListeners;
-
-	private PropertyTable tableModelHolonElementMulti;
-	private PropertyTable tableModelHolonElementSingle;
-	private DefaulTable tableModelProperties;
-	public String[] colNames = { "Field", "Information" };
-	/*
-	 * Object that runs the Algorithm
-	 */
-	private Object algorithm = null;
-	private int selectedHolonBody;
-
-	// Statistic Graph Data
-	private Hashtable<String, StatisticGraphPanel> statisticGraphTable = new Hashtable<String, StatisticGraphPanel>();
-	private HashMap<Integer, CpsUpperNode> hashcodeMap = new HashMap<>();
-	private ArrayList<JsonObject> statisticData = new ArrayList<>();
-
-	private Gson gson;
-
-	private StatisticPanel statPanel;
-
-	/**
-	 * Constructor for the model. It initializes the categories and
-	 * objectsOnCanvas by default values. Listeners are also initialized by
-	 * default values.
-	 */
-	public Model() {
-		setCategories(new ArrayList<Category>());
-		setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
-		setEdgesOnCanvas(new ArrayList<CpsEdge>());
-		setCategoryListeners(new LinkedList<CategoryListener>());
-		setObjectListeners(new LinkedList<ObjectListener>());
-		setCgIdx(new HashMap<String, Integer>());
-		setCvsObjIdx(new HashMap<Integer, Integer>());
-		setClipboradObjects(new ArrayList<AbstractCpsObject>());
-		setTrackingObj(new ArrayList<AbstractCpsObject>());
-		setEleToDelete(new HashMap<Integer, ArrayList<HolonElement>>());
-		setSingleTable(new PropertyTable());
-		setMultiTable(new PropertyTable());
-		setPropertyTable(new DefaulTable(1000, colNames.length));
-		getPropertyTable().setColumnIdentifiers(colNames);
-		setTableHolonElement(new JTable());
-		initGson();
-	}
-
-	/**
-	 * Returns all Categories.
-	 * 
-	 * @return the categories
-	 */
-	public ArrayList<Category> getCategories() {
-		return categories;
-	}
-
-	/**
-	 * Sets all Categories.
-	 * 
-	 * @param categories
-	 *            the categories to set
-	 */
-	public void setCategories(ArrayList<Category> categories) {
-		this.categories = categories;
-	}
-
-	/**
-	 * Transform the Arraylist of categories into a string of all objectName
-	 * with a separation (',') between each name.
-	 * 
-	 * @return String of all names separeted by ','
-	 */
-	public String toStringCat() {
-		String text = "";
-		for (int i = 0; i < categories.size(); i++) {
-			if (text == "") {
-				text = categories.get(i).getName();
-			} else {
-				text = text + ", " + categories.get(i).getName();
-			}
-		}
-		return text;
-	}
-
-	/**
-	 * Returns all Objects on the Canvas.
-	 * 
-	 * @return the objectsOnCanvas
-	 */
-	public ArrayList<AbstractCpsObject> getObjectsOnCanvas() {
-		return objectsOnCanvas;
-	}
-
-	/**
-	 * Sets all Objects on the Canvas.
-	 * 
-	 * @param objectsOnCanvas
-	 *            the objectsOnCanvas to set
-	 */
-	public void setObjectsOnCanvas(ArrayList<AbstractCpsObject> objectsOnCanvas) {
-		this.objectsOnCanvas = objectsOnCanvas;
-	}
-
-	/**
-	 * Get all Edges on the Canvas.
-	 * 
-	 * @return the objectsOnCanvas
-	 */
-	public ArrayList<CpsEdge> getEdgesOnCanvas() {
-		return edgesOnCanvas;
-	}
-
-	/**
-	 * Adds an Edge to The Canvas.
-	 * 
-	 * @param edge
-	 *            the edgesOnCanvas to add
-	 */
-	public void addEdgeOnCanvas(CpsEdge edge) {
-		this.edgesOnCanvas.add(edge);
-	}
-
-	/**
-	 * Remove an edge from the Canvas.
-	 * 
-	 * @param edge
-	 *            the edge to remove
-	 */
-	public void removeEdgesOnCanvas(CpsEdge edge) {
-		this.edgesOnCanvas.remove(edge);
-	}
-
-	/**
-	 * Sets the edges on the Canvas.
-	 * 
-	 * @param arrayList
-	 *            the edgesOnCanvas to set
-	 */
-	public void setEdgesOnCanvas(ArrayList<CpsEdge> arrayList) {
-		this.edgesOnCanvas = arrayList;
-	}
-
-	/**
-	 * Returns the ObjectListener.
-	 * 
-	 * @return the objectListeners
-	 */
-	public List<ObjectListener> getObjectListeners() {
-		return objectListeners;
-	}
-
-	/**
-	 * Sets the ObjectListener.
-	 * 
-	 * @param linkedList
-	 *            the objectListeners to set
-	 */
-	public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
-		this.objectListeners = linkedList;
-	}
-
-	/**
-	 * Returns the CategorieListener.
-	 * 
-	 * @return the categoryListeners
-	 */
-	public List<CategoryListener> getCategoryListeners() {
-		return categoryListeners;
-	}
-
-	/**
-	 * Sets the CategorieListener.
-	 * 
-	 * @param linkedList
-	 *            the categoryListeners to set
-	 */
-	public void setCategoryListeners(LinkedList<CategoryListener> linkedList) {
-		this.categoryListeners = linkedList;
-	}
-
-	/**
-	 * Set the ID of the selected Object 0 = no Object is selected.
-	 * 
-	 * @param id
-	 *            the ID
-	 * 
-	 */
-	public void setSelectedObjectID(int id) {
-		this.selectedID = id;
-	}
-
-	/**
-	 * Returns the ID of the selected Object 0 = no Object is selected.
-	 * 
-	 * @return ID
-	 */
-	public int getSelectedObjectID() {
-		return selectedID;
-	}
-
-	/**
-	 * Returns the Selected Cps Object.
-	 * 
-	 * @return selected Cps Object
-	 */
-	public AbstractCpsObject getSelectedCpsObject() {
-		return selectedCpsObject;
-	}
-
-	/**
-	 * Set the Selected Objecs.
-	 * 
-	 * @param selectedCpsObject
-	 *            Objects that are selected
-	 */
-	public void setSelectedCpsObject(AbstractCpsObject selectedCpsObject) {
-		this.selectedCpsObject = selectedCpsObject;
-	}
-
-	/**
-	 * Returns all selected Objects on the Canvas.
-	 * 
-	 * @return The selected Objects
-	 */
-	public ArrayList<AbstractCpsObject> getSelectedCpsObjects() {
-		return selectedObjects;
-	}
-
-	/**
-	 * Returns all selected Objects on the Canvas.
-	 * 
-	 * @return The selected Objects
-	 */
-	public void setSelectedCpsObjects(ArrayList<AbstractCpsObject> arr) {
-		this.selectedObjects = arr;
-	}
-
-	/**
-	 * Returns the Selected Holon Element.
-	 * 
-	 * @return selected Holon Element
-	 */
-	public HolonElement getSelectedHolonElement() {
-		return selectedHolonElement;
-	}
-
-	/**
-	 * Sets the Selecte HolonElement.
-	 * 
-	 * @param selectedHolonElement
-	 *            that is Selected
-	 */
-	public void setSelectedHolonElement(HolonElement selectedHolonElement) {
-		this.selectedHolonElement = selectedHolonElement;
-	}
-
-	/**
-	 * Returns the sCale (Scale for the Images).
-	 * 
-	 * @return sCALE
-	 */
-	public int getScale() {
-		return sCALE;
-	}
-
-	/**
-	 * Returns sCALEdIV2 (The Scale divided by 2).
-	 * 
-	 * @return sCALEdIV2
-	 */
-	public int getScaleDiv2() {
-		return sCALEdIV2;
-	}
-
-	/**
-	 * Sets the Image Scale.
-	 * 
-	 * @param scale
-	 *            for the image
-	 */
-	public void setScale(int scale) {
-		sCALE = scale;
-		if ((sCALE & 1) == 0)
-			sCALEdIV2 = sCALE / 2;
-		else
-			sCALEdIV2 = (sCALE + 1) / 2;
-	}
-
-	/**
-	 * Returns ITERATIONS.
-	 * 
-	 * @return ITERATIONS
-	 */
-	public int getIterations() {
-		return ITERATIONS;
-	}
-
-	/**
-	 * sets the current Iteration.
-	 * 
-	 * @param curIT
-	 *            the current Iteration
-	 */
-	public void setCurIteration(int curIT) {
-		this.curIteration = curIT;
-		notifyGraphListeners();
-	}
-
-	private void notifyGraphListeners() {
-		for (GraphListener gl : graphListeners) {
-			gl.repaintTree();
-		}
-
-	}
-
-	/**
-	 * Returns cURiTERATION.
-	 * 
-	 * @return cURiTERATION
-	 */
-	public int getCurIteration() {
-		return curIteration;
-	}
-
-	/**
-	 * Set the selected Edge.
-	 * 
-	 * @param edge
-	 *            that is selected
-	 * 
-	 */
-	public void setSelectedEdge(CpsEdge edge) {
-		this.selectedEdge = edge;
-	}
-
-	/**
-	 * Returns the selected Edge.
-	 * 
-	 * @return selectedEdge
-	 */
-	public CpsEdge getSelectedEdge() {
-		return selectedEdge;
-	}
-
-	/**
-	 * Returns the Categorie Index.
-	 * 
-	 * @return the cgIdx
-	 */
-	public HashMap<String, Integer> getCgIdx() {
-		return cgIdx;
-	}
-
-	/**
-	 * Sets the Categorie Index.
-	 * 
-	 * @param cgIdx
-	 *            the cgIdx to set
-	 */
-	public void setCgIdx(HashMap<String, Integer> cgIdx) {
-		this.cgIdx = cgIdx;
-	}
-
-	/**
-	 * Returns the CanvasObject Index.
-	 * 
-	 * @return the cvsObjIdx
-	 */
-	public HashMap<Integer, Integer> getCvsObjIdx() {
-		return cvsObjIdx;
-	}
-
-	/**
-	 * Sets the CanvasObject Index.
-	 * 
-	 * @param cvsObjIdx
-	 *            the cvsObjIdx to set
-	 */
-	public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
-		this.cvsObjIdx = cvsObjIdx;
-	}
-
-	/**
-	 * Sets the auto save Number.
-	 * 
-	 * @param autoSaveNr
-	 *            the auto save number
-	 */
-	public void setAutoSaveNr(int autoSaveNr) {
-		this.autoSaveNr = autoSaveNr;
-	}
-
-	/**
-	 * Returns the auto save Number.
-	 * 
-	 * @return the auto save Number
-	 */
-	public int getAutoSaveNr() {
-		return autoSaveNr;
-	}
-
-	/**
-	 * Returns the Number of Saves.
-	 * 
-	 * @return the numberOfSaves
-	 */
-	public int getNumberOfSaves() {
-		return numberOfSaves;
-	}
-
-	/**
-	 * Set the Number of Saves.
-	 * 
-	 * @param numberOfSaves
-	 *            the numberOfSaves to set
-	 */
-	public void setNumberOfSaves(int numberOfSaves) {
-		this.numberOfSaves = numberOfSaves;
-	}
-
-	/**
-	 * Sets the ClipboardObjects.
-	 * 
-	 * @param c
-	 *            Array of Objects
-	 */
-	public void setClipboradObjects(ArrayList<AbstractCpsObject> c) {
-		this.clipboardObjects = c;
-	}
-
-	/**
-	 * Returns all Objects in the Clipboard.
-	 * 
-	 * @return Objects in the Clipboard
-	 */
-	public ArrayList<AbstractCpsObject> getClipboradObjects() {
-		return clipboardObjects;
-	}
-
-	/**
-	 * Sets the console.
-	 * 
-	 * @param console
-	 *            the console
-	 */
-	public void setConsole(Console console) {
-		this.console = console;
-	}
-
-	/**
-	 * Returns the Console.
-	 * 
-	 * @return console the console
-	 */
-	public Console getConsole() {
-		return console;
-	}
-
-	/**
-	 * @return the maxCapacity
-	 */
-	public float getMaxCapacity() {
-		return maxCapacity;
-	}
-
-	/**
-	 * @param maxCapacity
-	 *            the maxCapacity to set
-	 */
-	public void setMaxCapacity(float maxCapacity) {
-		this.maxCapacity = maxCapacity;
-	}
-
-	/**
-	 * Sets the Interval in ms between each Iteration.
-	 * 
-	 * @param t
-	 *            speed for the Iterations
-	 */
-	public void setTimerSpeed(int t) {
-		this.timerSpeed = t;
-	}
-
-	/**
-	 * get the Interval in ms between each Iteration.
-	 * 
-	 * @return timerSpeed speed for the Iterations
-	 */
-	public int getTimerSpeed() {
-		return this.timerSpeed;
-	}
-
-	/**
-	 * Get Canvas X Size.
-	 * 
-	 * @return the cANVAS_X
-	 */
-	public int getCanvasX() {
-		return canvasX;
-	}
-
-	/**
-	 * Set Canvas X Size.
-	 * 
-	 * @param canvasX
-	 *            the cANVAS_X to set
-	 */
-	public void setCanvasX(int canvasX) {
-		this.canvasX = canvasX;
-	}
-
-	/**
-	 * get Canvas Y size.
-	 * 
-	 * @return the cANVAS_Y
-	 */
-	public int getCanvasY() {
-		return canvasY;
-	}
-
-	/**
-	 * Set Canvas Y size.
-	 * 
-	 * @param canvasY
-	 *            the cANVAS_Y to set
-	 */
-	public void setCanvasY(int canvasY) {
-		this.canvasY = canvasY;
-	}
-
-	/**
-	 * get the Algorithm.
-	 * 
-	 * @return the Algorithm
-	 */
-	public Object getAlgorithm() {
-		return algorithm;
-	}
-
-	/**
-	 * Set the Algorithm.
-	 * 
-	 * @param obj
-	 *            the Algorithm
-	 */
-	public void setAlgorithm(Object obj) {
-		this.algorithm = null;
-		this.algorithm = obj;
-	}
-
-	/**
-	 * Add a SubNetColor.
-	 * 
-	 * @param c
-	 *            the Color
-	 */
-	public void addSubNetColor(Color c) {
-		this.subNetColors.add(c);
-	}
-
-	/**
-	 * Get the SubNetColors.
-	 * 
-	 * @return SubNetColors
-	 */
-	public LinkedList<Color> getSubNetColors() {
-		return this.subNetColors;
-	}
-
-	public void setTrackingObj(ArrayList<AbstractCpsObject> toTrack) {
-		trackedObjects = toTrack;
-	}
-
-	public ArrayList<AbstractCpsObject> getTrackingObj() {
-		return trackedObjects;
-	}
-
-	public void addGraphListener(GraphListener gl) {
-		graphListeners.add(gl);
-	}
-
-	public void setEleToDelete(HashMap<Integer, ArrayList<HolonElement>> theHash) {
-		this.eleToDelete = theHash;
-	}
-
-	public HashMap<Integer, ArrayList<HolonElement>> getEleToDelete() {
-		return this.eleToDelete;
-	}
-
-	public void setSingleTable(PropertyTable pt) {
-		this.tableModelHolonElementSingle = pt;
-	}
-
-	public PropertyTable getSingleTable() {
-		return this.tableModelHolonElementSingle;
-	}
-
-	public PropertyTable getMultiTable() {
-		return this.tableModelHolonElementMulti;
-	}
-
-	public void setMultiTable(PropertyTable pt) {
-		this.tableModelHolonElementMulti = pt;
-	}
-
-	public void addObjectsToGraphListeners() {
-		for (GraphListener gl : graphListeners) {
-			gl.addTrackedObject(trackedObjects);
-			gl.repaintTree();
-		}
-	}
-
-	public DefaulTable getPropertyTable() {
-		return this.tableModelProperties;
-	}
-
-	public void setPropertyTable(DefaulTable pt) {
-		this.tableModelProperties = pt;
-	}
-
-	public JTable getTableHolonElement() {
-		return tableHolonElement;
-	}
-
-	public void setTableHolonElement(JTable tableHolonElement) {
-		this.tableHolonElement = tableHolonElement;
-	}
-
-	/**
-	 * Sets the HolonBody Scale.
-	 * 
-	 * @param scale
-	 *            for the HolonBody
-	 */
-	public void setHolonBodyScale(int scale) {
-		holonBodysCALE = scale;
-	}
-
-	/**
-	 * Returns the sCale (Scale for the Images).
-	 * 
-	 * @return sCALE
-	 */
-	public int getHolonBodyScale() {
-		return holonBodysCALE;
-	}
-
-	/**
-	 * Sets the ID of the selected HolonBody
-	 * 
-	 * @param i
-	 *            int
-	 */
-	public void setSelectedHolonBody(int i) {
-		selectedHolonBody = i;
-	}
-
-	/**
-	 * Returns the ID of the selected HolonBody
-	 * 
-	 * @return selectedHolonBody
-	 */
-	public int getSelectedHolonBody() {
-		return selectedHolonBody;
-	}
-
-	/**
-	 * get all Switches
-	 */
-	public ArrayList<HolonSwitch> getSwitches() {
-		ArrayList<HolonSwitch> switches = new ArrayList<>();
-		for (AbstractCpsObject obj : getObjectsOnCanvas()) {
-			if (obj instanceof HolonSwitch) {
-				switches.add((HolonSwitch) obj);
-			} else if (obj instanceof CpsUpperNode) {
-				getSwitchesRec(((CpsUpperNode) obj).getNodes(), switches);
-			}
-		}
-		return switches;
-	}
-
-	/**
-	 * get the Amount of Switches help function
-	 *
-	 * @param objects
-	 *            objects
-	 * @param switches
-	 *            List of switches
-	 */
-	private ArrayList<HolonSwitch> getSwitchesRec(ArrayList<AbstractCpsObject> objects,
-			ArrayList<HolonSwitch> switches) {
-		for (AbstractCpsObject obj : objects) {
-			if (obj instanceof HolonSwitch) {
-				switches.add((HolonSwitch) obj);
-			} else if (obj instanceof CpsUpperNode) {
-				getSwitchesRec(((CpsUpperNode) obj).getNodes(), switches);
-			}
-		}
-		return switches;
-	}
-
-	/**
-	 * Returns the Path for the background Image of the Canvas.
-	 * 
-	 * @return imgPath the Path
-	 */
-	public String getCanvasImagePath() {
-		return imgPath;
-	}
-
-	/**
-	 * Returns the mode for the background Image of the Canvas.
-	 * 
-	 * 0 take size of the Image 1 stretch the Image 2 Custom Image size
-	 * 
-	 * @return backgroundMode the mode
-	 */
-	public int getCanvasImageMode() {
-		return backgroundMode;
-	}
-
-	/**
-	 * Returns the Custom width of the background Image of the Canvas.
-	 * 
-	 * @return backgroundWidth the Width
-	 */
-	public int getCanvasImageWidth() {
-		return backgroundWidth;
-	}
-
-	/**
-	 * Returns the Custom height of the background Image of the Canvas.
-	 * 
-	 * @return backgroundHeight the height
-	 */
-	public int getCanvasImageHeight() {
-		return backgroundHeight;
-	}
-
-	/**
-	 * Set the Path for the background Image of the Canvas.
-	 * 
-	 * @param paththe
-	 *            Path
-	 */
-	public void setCanvasImagePath(String path) {
-		imgPath = path;
-	}
-
-	/**
-	 * Set the mode for the background Image of the Canvas.
-	 * 
-	 * 0 take size of the Image, 1 stretch the Image, 2 Custom Image size
-	 * 
-	 * @param backgroundMode
-	 *            the mode
-	 */
-	public void setCanvasImageMode(int mode) {
-		backgroundMode = mode;
-	}
-
-	/**
-	 * Set the Custom width of the background Image of the Canvas.
-	 * 
-	 * @param width
-	 *            the Width
-	 */
-	public void setCanvasImageWidth(int width) {
-		backgroundWidth = width;
-	}
-
-	/**
-	 * Set the Custom height of the background Image of the Canvas.
-	 * 
-	 * @param height
-	 *            the height
-	 */
-	public void setCanvasImageHeight(int height) {
-		backgroundHeight = height;
-	}
-
-	/**
-	 * Set the graphtable for Statistic Graphs
-	 */
-	public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT) {
-		statisticGraphTable = gT;
-	}
-
-	/**
-	 * Returns the graphtable for Statistic Graphs.
-	 */
-	public Hashtable<String, StatisticGraphPanel> getGraphTable() {
-		return statisticGraphTable;
-	}
-
-	/**
-	 * Returns if the Simulation is running.
-	 */
-	public boolean getIsSimRunning() {
-		return isSimRunning;
-	}
-
-	/**
-	 * Sets isSimRunning.
-	 * 
-	 * @param isRunning
-	 */
-	public void setIsSimRunning(boolean isRunning) {
-		isSimRunning = isRunning;
-	}
-
-	/**
-	 * @return the statisticData
-	 */
-	public ArrayList<JsonObject> getStatisticData() {
-		return statisticData;
-	}
-
-	/**
-	 * @param statisticData
-	 *            the statisticData to set
-	 */
-	public void setStatisticData(ArrayList<JsonObject> statisticData) {
-		this.statisticData = statisticData;
-	}
-
-	/**
-	 * Returns showConsoleLog.
-	 */
-	public boolean getShowConsoleLog() {
-		return this.showConsoleLog;
-	}
-
-	/**
-	 * Sets showConsoleLog.
-	 * 
-	 * @param showConsoleLog
-	 */
-	public void setShowConsoleLog(boolean showConsoleLog) {
-		this.showConsoleLog = showConsoleLog;
-
-	}
-
-	/**
-	 * Initialize the Gson with wanted parameters
-	 */
-	private void initGson() {
-		// TODO Auto-generated method stub
-		GsonBuilder builder = new GsonBuilder();
-		builder.serializeNulls();
-		builder.excludeFieldsWithoutExposeAnnotation();
-		builder.setPrettyPrinting();
-		builder.registerTypeAdapter(AbstractCpsObject.class, new AbstractCpsObjectAdapter());
-		builder.registerTypeAdapter(Position.class, new PositionAdapter());
-		builder.registerTypeAdapter(Color.class, new ColorAdapter());
-		builder.registerTypeAdapter(Pair.class, new PairAdapter());
-		// use the builder and make a instance of the Gson
-		this.setGson(builder.create());
-
-	}
-
-	/**
-	 * @return the gson
-	 */
-	public Gson getGson() {
-		return gson;
-	}
-
-	/**
-	 * @param gson
-	 *            the gson to set
-	 */
-	public void setGson(Gson gson) {
-		this.gson = gson;
-	}
-
-	public void setStatPanel(StatisticPanel sP) {
-		statPanel = sP;
-	}
-
-	public StatisticPanel getStatPanel() {
-		return statPanel;
-	}
-
-	/**
-	 * @return the hashcodeMap
-	 */
-	public HashMap<Integer, CpsUpperNode> getHashcodeMap() {
-		return hashcodeMap;
-	}
-
-	/**
-	 * @param hashcodeMap the hashcodeMap to set
-	 */
-	public void setHashcodeMap(HashMap<Integer, CpsUpperNode> hashcodeMap) {
-		this.hashcodeMap = hashcodeMap;
-	}
+    private static final int ITERATIONS = 100;
+    // Global Variables
+    private static int sCALE = 50; // Picture Scale
+    private static int sCALEdIV2 = sCALE / 2;
+    private static int holonBodysCALE = 100; // Picture Scale
+    public String[] colNames = {"Field", "Information"};
+    // Canvas Attributes
+    private String imgPath = "";
+    private int backgroundMode = 0;
+    private int backgroundWidth = 0;
+    private int backgroundHeight = 0;
+    private int canvasX = 1000;
+    private int canvasY = 1000;
+    private int curIteration = 0;
+    private LinkedList<Color> subNetColors = new LinkedList<>();
+    // ID of the Selected Object
+    private AbstractCpsObject selectedCpsObject = null;
+    private HolonElement selectedHolonElement;
+    private CpsEdge selectedEdge;
+    private ArrayList<AbstractCpsObject> selectedObjects = new ArrayList<>();
+    private ArrayList<AbstractCpsObject> clipboardObjects = new ArrayList<>();
+    private Console console;
+    private HashMap<Integer, ArrayList<HolonElement>> eleToDelete;
+    // Capacity for Edge
+    private float maxCapacity;
+    // Table for HolonElements --> all cells are editable
+    private JTable tableHolonElement;
+    private ArrayList<GraphListener> graphListeners = new ArrayList<GraphListener>();
+    // Iteration Speed
+    private int timerSpeed = 1000;
+    private int selectedID = 0;
+    // number of the current autosave
+    private int autoSaveNr = -1;
+    // number of max simultaneous autosaves
+    private int numberOfSaves = 35;
+    // if the simulation is running and has not been reseted
+    private boolean isSimRunning = false;
+    // if the console log of the program should be displayed
+    private boolean showConsoleLog = true;
+    /*
+     * Array of all categories in the model. It is set by default with the
+     * categories ENERGY, BUILDINGS and COMPONENTS
+     */
+    private ArrayList<Category> categories;
+    /*
+     * Array of all HolonObj and HolonSwitches, that should be tracked through
+     * out the statistics tab
+     */
+    private ArrayList<AbstractCpsObject> trackedObjects;
+    /*
+     * Array of all CpsObjects in our canvas. It is set by default as an empty
+     * list.
+     */
+    private ArrayList<AbstractCpsObject> objectsOnCanvas;
+    private HashMap<String, Integer> cgIdx;
+    private HashMap<Integer, Integer> cvsObjIdx;
+    /*
+     * Array of all CpsObjects in our canvas. It is set by default as an empty
+     * list.
+     */
+    private ArrayList<CpsEdge> edgesOnCanvas;
+    /*
+     * Array for all Listeners
+     */
+    private List<CategoryListener> categoryListeners;
+    private List<ObjectListener> objectListeners;
+    private PropertyTable tableModelHolonElementMulti;
+    private PropertyTable tableModelHolonElementSingle;
+    private DefaulTable tableModelProperties;
+    /*
+     * Object that runs the Algorithm
+     */
+    private Object algorithm = null;
+    private int selectedHolonBody;
+
+    // Statistic Graph Data
+    private Hashtable<String, StatisticGraphPanel> statisticGraphTable = new Hashtable<>();
+    private HashMap<Integer, CpsUpperNode> hashcodeMap = new HashMap<>();
+    private ArrayList<JsonObject> statisticData = new ArrayList<>();
+
+    private Gson gson;
+
+    private StatisticPanel statPanel;
+
+    /**
+     * Constructor for the model. It initializes the categories and
+     * objectsOnCanvas by default values. Listeners are also initialized by
+     * default values.
+     */
+    public Model() {
+        setCategories(new ArrayList<>());
+        setObjectsOnCanvas(new ArrayList<>());
+        setEdgesOnCanvas(new ArrayList<>());
+        setCategoryListeners(new LinkedList<>());
+        setObjectListeners(new LinkedList<>());
+        setCgIdx(new HashMap<>());
+        setCvsObjIdx(new HashMap<>());
+        setClipboradObjects(new ArrayList<>());
+        setTrackingObj(new ArrayList<>());
+        setEleToDelete(new HashMap<>());
+        setSingleTable(new PropertyTable());
+        setMultiTable(new PropertyTable());
+        setPropertyTable(new DefaulTable(1000, colNames.length));
+        getPropertyTable().setColumnIdentifiers(colNames);
+        setTableHolonElement(new JTable());
+        initGson();
+    }
+
+    /**
+     * Returns all Categories.
+     *
+     * @return the categories
+     */
+    public ArrayList<Category> getCategories() {
+        return categories;
+    }
+
+    /**
+     * Sets all Categories.
+     *
+     * @param categories the categories to set
+     */
+    public void setCategories(ArrayList<Category> categories) {
+        this.categories = categories;
+    }
+
+    /**
+     * Transform the Arraylist of categories into a string of all objectName
+     * with a separation (',') between each name.
+     *
+     * @return String of all names separeted by ','
+     */
+    public String toStringCat() {
+        String text = "";
+        for (int i = 0; i < categories.size(); i++) {
+            if (text.equals("")) {
+                text = categories.get(i).getName();
+            } else {
+                text = text + ", " + categories.get(i).getName();
+            }
+        }
+        return text;
+    }
+
+    /**
+     * Returns all Objects on the Canvas.
+     *
+     * @return the objectsOnCanvas
+     */
+    public ArrayList<AbstractCpsObject> getObjectsOnCanvas() {
+        return objectsOnCanvas;
+    }
+
+    /**
+     * Sets all Objects on the Canvas.
+     *
+     * @param objectsOnCanvas the objectsOnCanvas to set
+     */
+    public void setObjectsOnCanvas(ArrayList<AbstractCpsObject> objectsOnCanvas) {
+        this.objectsOnCanvas = objectsOnCanvas;
+    }
+
+    /**
+     * Get all Edges on the Canvas.
+     *
+     * @return the objectsOnCanvas
+     */
+    public ArrayList<CpsEdge> getEdgesOnCanvas() {
+        return edgesOnCanvas;
+    }
+
+    /**
+     * Sets the edges on the Canvas.
+     *
+     * @param arrayList the edgesOnCanvas to set
+     */
+    public void setEdgesOnCanvas(ArrayList<CpsEdge> arrayList) {
+        this.edgesOnCanvas = arrayList;
+    }
+
+    /**
+     * Adds an Edge to The Canvas.
+     *
+     * @param edge the edgesOnCanvas to add
+     */
+    public void addEdgeOnCanvas(CpsEdge edge) {
+        this.edgesOnCanvas.add(edge);
+    }
+
+    /**
+     * Remove an edge from the Canvas.
+     *
+     * @param edge the edge to remove
+     */
+    public void removeEdgesOnCanvas(CpsEdge edge) {
+        this.edgesOnCanvas.remove(edge);
+    }
+
+    /**
+     * Returns the ObjectListener.
+     *
+     * @return the objectListeners
+     */
+    public List<ObjectListener> getObjectListeners() {
+        return objectListeners;
+    }
+
+    /**
+     * Sets the ObjectListener.
+     *
+     * @param linkedList the objectListeners to set
+     */
+    public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
+        this.objectListeners = linkedList;
+    }
+
+    /**
+     * Returns the CategorieListener.
+     *
+     * @return the categoryListeners
+     */
+    public List<CategoryListener> getCategoryListeners() {
+        return categoryListeners;
+    }
+
+    /**
+     * Sets the CategorieListener.
+     *
+     * @param linkedList the categoryListeners to set
+     */
+    public void setCategoryListeners(LinkedList<CategoryListener> linkedList) {
+        this.categoryListeners = linkedList;
+    }
+
+    /**
+     * Returns the ID of the selected Object 0 = no Object is selected.
+     *
+     * @return ID
+     */
+    public int getSelectedObjectID() {
+        return selectedID;
+    }
+
+    /**
+     * Set the ID of the selected Object 0 = no Object is selected.
+     *
+     * @param id the ID
+     */
+    public void setSelectedObjectID(int id) {
+        this.selectedID = id;
+    }
+
+    /**
+     * Returns the Selected Cps Object.
+     *
+     * @return selected Cps Object
+     */
+    public AbstractCpsObject getSelectedCpsObject() {
+        return selectedCpsObject;
+    }
+
+    /**
+     * Set the Selected Objecs.
+     *
+     * @param selectedCpsObject Objects that are selected
+     */
+    public void setSelectedCpsObject(AbstractCpsObject selectedCpsObject) {
+        this.selectedCpsObject = selectedCpsObject;
+    }
+
+    /**
+     * Returns all selected Objects on the Canvas.
+     *
+     * @return The selected Objects
+     */
+    public ArrayList<AbstractCpsObject> getSelectedCpsObjects() {
+        return selectedObjects;
+    }
+
+    /**
+     * Returns all selected Objects on the Canvas.
+     *
+     * @return The selected Objects
+     */
+    public void setSelectedCpsObjects(ArrayList<AbstractCpsObject> arr) {
+        this.selectedObjects = arr;
+    }
+
+    /**
+     * Returns the Selected Holon Element.
+     *
+     * @return selected Holon Element
+     */
+    public HolonElement getSelectedHolonElement() {
+        return selectedHolonElement;
+    }
+
+    /**
+     * Sets the Selecte HolonElement.
+     *
+     * @param selectedHolonElement that is Selected
+     */
+    public void setSelectedHolonElement(HolonElement selectedHolonElement) {
+        this.selectedHolonElement = selectedHolonElement;
+    }
+
+    /**
+     * Returns the sCale (Scale for the Images).
+     *
+     * @return sCALE
+     */
+    public int getScale() {
+        return sCALE;
+    }
+
+    /**
+     * Sets the Image Scale.
+     *
+     * @param scale for the image
+     */
+    public void setScale(int scale) {
+        sCALE = scale;
+        if ((sCALE & 1) == 0)
+            sCALEdIV2 = sCALE / 2;
+        else
+            sCALEdIV2 = (sCALE + 1) / 2;
+    }
+
+    /**
+     * Returns sCALEdIV2 (The Scale divided by 2).
+     *
+     * @return sCALEdIV2
+     */
+    public int getScaleDiv2() {
+        return sCALEdIV2;
+    }
+
+    /**
+     * Returns ITERATIONS.
+     *
+     * @return ITERATIONS
+     */
+    public int getIterations() {
+        return ITERATIONS;
+    }
+
+    private void notifyGraphListeners() {
+        for (GraphListener gl : graphListeners) {
+            gl.repaintTree();
+        }
+
+    }
+
+    /**
+     * Returns cURiTERATION.
+     *
+     * @return cURiTERATION
+     */
+    public int getCurIteration() {
+        return curIteration;
+    }
+
+    /**
+     * sets the current Iteration.
+     *
+     * @param curIT the current Iteration
+     */
+    public void setCurIteration(int curIT) {
+        this.curIteration = curIT;
+        notifyGraphListeners();
+    }
+
+    /**
+     * Returns the selected Edge.
+     *
+     * @return selectedEdge
+     */
+    public CpsEdge getSelectedEdge() {
+        return selectedEdge;
+    }
+
+    /**
+     * Set the selected Edge.
+     *
+     * @param edge that is selected
+     */
+    public void setSelectedEdge(CpsEdge edge) {
+        this.selectedEdge = edge;
+    }
+
+    /**
+     * Returns the Categorie Index.
+     *
+     * @return the cgIdx
+     */
+    public HashMap<String, Integer> getCgIdx() {
+        return cgIdx;
+    }
+
+    /**
+     * Sets the Categorie Index.
+     *
+     * @param cgIdx the cgIdx to set
+     */
+    public void setCgIdx(HashMap<String, Integer> cgIdx) {
+        this.cgIdx = cgIdx;
+    }
+
+    /**
+     * Returns the CanvasObject Index.
+     *
+     * @return the cvsObjIdx
+     */
+    public HashMap<Integer, Integer> getCvsObjIdx() {
+        return cvsObjIdx;
+    }
+
+    /**
+     * Sets the CanvasObject Index.
+     *
+     * @param cvsObjIdx the cvsObjIdx to set
+     */
+    public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
+        this.cvsObjIdx = cvsObjIdx;
+    }
+
+    /**
+     * Returns the auto save Number.
+     *
+     * @return the auto save Number
+     */
+    public int getAutoSaveNr() {
+        return autoSaveNr;
+    }
+
+    /**
+     * Sets the auto save Number.
+     *
+     * @param autoSaveNr the auto save number
+     */
+    public void setAutoSaveNr(int autoSaveNr) {
+        this.autoSaveNr = autoSaveNr;
+    }
+
+    /**
+     * Returns the Number of Saves.
+     *
+     * @return the numberOfSaves
+     */
+    public int getNumberOfSaves() {
+        return numberOfSaves;
+    }
+
+    /**
+     * Set the Number of Saves.
+     *
+     * @param numberOfSaves the numberOfSaves to set
+     */
+    public void setNumberOfSaves(int numberOfSaves) {
+        this.numberOfSaves = numberOfSaves;
+    }
+
+    /**
+     * Returns all Objects in the Clipboard.
+     *
+     * @return Objects in the Clipboard
+     */
+    public ArrayList<AbstractCpsObject> getClipboradObjects() {
+        return clipboardObjects;
+    }
+
+    /**
+     * Sets the ClipboardObjects.
+     *
+     * @param c Array of Objects
+     */
+    public void setClipboradObjects(ArrayList<AbstractCpsObject> c) {
+        this.clipboardObjects = c;
+    }
+
+    /**
+     * Returns the Console.
+     *
+     * @return console the console
+     */
+    public Console getConsole() {
+        return console;
+    }
+
+    /**
+     * Sets the console.
+     *
+     * @param console the console
+     */
+    public void setConsole(Console console) {
+        this.console = console;
+    }
+
+    /**
+     * @return the maxCapacity
+     */
+    public float getMaxCapacity() {
+        return maxCapacity;
+    }
+
+    /**
+     * @param maxCapacity the maxCapacity to set
+     */
+    public void setMaxCapacity(float maxCapacity) {
+        this.maxCapacity = maxCapacity;
+    }
+
+    /**
+     * get the Interval in ms between each Iteration.
+     *
+     * @return timerSpeed speed for the Iterations
+     */
+    public int getTimerSpeed() {
+        return this.timerSpeed;
+    }
+
+    /**
+     * Sets the Interval in ms between each Iteration.
+     *
+     * @param t speed for the Iterations
+     */
+    public void setTimerSpeed(int t) {
+        this.timerSpeed = t;
+    }
+
+    /**
+     * Get Canvas X Size.
+     *
+     * @return the cANVAS_X
+     */
+    public int getCanvasX() {
+        return canvasX;
+    }
+
+    /**
+     * Set Canvas X Size.
+     *
+     * @param canvasX the cANVAS_X to set
+     */
+    public void setCanvasX(int canvasX) {
+        this.canvasX = canvasX;
+    }
+
+    /**
+     * get Canvas Y size.
+     *
+     * @return the cANVAS_Y
+     */
+    public int getCanvasY() {
+        return canvasY;
+    }
+
+    /**
+     * Set Canvas Y size.
+     *
+     * @param canvasY the cANVAS_Y to set
+     */
+    public void setCanvasY(int canvasY) {
+        this.canvasY = canvasY;
+    }
+
+    /**
+     * get the Algorithm.
+     *
+     * @return the Algorithm
+     */
+    public Object getAlgorithm() {
+        return algorithm;
+    }
+
+    /**
+     * Set the Algorithm.
+     *
+     * @param obj the Algorithm
+     */
+    public void setAlgorithm(Object obj) {
+        this.algorithm = null;
+        this.algorithm = obj;
+    }
+
+    /**
+     * Add a SubNetColor.
+     *
+     * @param c the Color
+     */
+    public void addSubNetColor(Color c) {
+        this.subNetColors.add(c);
+    }
+
+    /**
+     * Get the SubNetColors.
+     *
+     * @return SubNetColors
+     */
+    public LinkedList<Color> getSubNetColors() {
+        return this.subNetColors;
+    }
+
+    public ArrayList<AbstractCpsObject> getTrackingObj() {
+        return trackedObjects;
+    }
+
+    public void setTrackingObj(ArrayList<AbstractCpsObject> toTrack) {
+        trackedObjects = toTrack;
+    }
+
+    public void addGraphListener(GraphListener gl) {
+        graphListeners.add(gl);
+    }
+
+    public HashMap<Integer, ArrayList<HolonElement>> getEleToDelete() {
+        return this.eleToDelete;
+    }
+
+    public void setEleToDelete(HashMap<Integer, ArrayList<HolonElement>> theHash) {
+        this.eleToDelete = theHash;
+    }
+
+    public PropertyTable getSingleTable() {
+        return this.tableModelHolonElementSingle;
+    }
+
+    public void setSingleTable(PropertyTable pt) {
+        this.tableModelHolonElementSingle = pt;
+    }
+
+    public PropertyTable getMultiTable() {
+        return this.tableModelHolonElementMulti;
+    }
+
+    public void setMultiTable(PropertyTable pt) {
+        this.tableModelHolonElementMulti = pt;
+    }
+
+    public void addObjectsToGraphListeners() {
+        for (GraphListener gl : graphListeners) {
+            gl.addTrackedObject(trackedObjects);
+            gl.repaintTree();
+        }
+    }
+
+    public DefaulTable getPropertyTable() {
+        return this.tableModelProperties;
+    }
+
+    public void setPropertyTable(DefaulTable pt) {
+        this.tableModelProperties = pt;
+    }
+
+    public JTable getTableHolonElement() {
+        return tableHolonElement;
+    }
+
+    public void setTableHolonElement(JTable tableHolonElement) {
+        this.tableHolonElement = tableHolonElement;
+    }
+
+    /**
+     * Returns the sCale (Scale for the Images).
+     *
+     * @return sCALE
+     */
+    public int getHolonBodyScale() {
+        return holonBodysCALE;
+    }
+
+    /**
+     * Sets the HolonBody Scale.
+     *
+     * @param scale for the HolonBody
+     */
+    public void setHolonBodyScale(int scale) {
+        holonBodysCALE = scale;
+    }
+
+    /**
+     * Returns the ID of the selected HolonBody
+     *
+     * @return selectedHolonBody
+     */
+    public int getSelectedHolonBody() {
+        return selectedHolonBody;
+    }
+
+    /**
+     * Sets the ID of the selected HolonBody
+     *
+     * @param i int
+     */
+    public void setSelectedHolonBody(int i) {
+        selectedHolonBody = i;
+    }
+
+    /**
+     * get all Switches
+     */
+    public ArrayList<HolonSwitch> getSwitches() {
+        ArrayList<HolonSwitch> switches = new ArrayList<>();
+        for (AbstractCpsObject obj : getObjectsOnCanvas()) {
+            if (obj instanceof HolonSwitch) {
+                switches.add((HolonSwitch) obj);
+            } else if (obj instanceof CpsUpperNode) {
+                getSwitchesRec(((CpsUpperNode) obj).getNodes(), switches);
+            }
+        }
+        return switches;
+    }
+
+    /**
+     * get the Amount of Switches help function
+     *
+     * @param objects  objects
+     * @param switches List of switches
+     */
+    private ArrayList<HolonSwitch> getSwitchesRec(ArrayList<AbstractCpsObject> objects,
+                                                  ArrayList<HolonSwitch> switches) {
+        for (AbstractCpsObject obj : objects) {
+            if (obj instanceof HolonSwitch) {
+                switches.add((HolonSwitch) obj);
+            } else if (obj instanceof CpsUpperNode) {
+                getSwitchesRec(((CpsUpperNode) obj).getNodes(), switches);
+            }
+        }
+        return switches;
+    }
+
+    /**
+     * Returns the Path for the background Image of the Canvas.
+     *
+     * @return imgPath the Path
+     */
+    public String getCanvasImagePath() {
+        return imgPath;
+    }
+
+    /**
+     * Set the Path for the background Image of the Canvas.
+     *
+     * @param path the Path
+     */
+    public void setCanvasImagePath(String path) {
+        imgPath = path;
+    }
+
+    /**
+     * Returns the mode for the background Image of the Canvas.
+     * <p>
+     * 0 take size of the Image 1 stretch the Image 2 Custom Image size
+     *
+     * @return backgroundMode the mode
+     */
+    public int getCanvasImageMode() {
+        return backgroundMode;
+    }
+
+    /**
+     * Set the mode for the background Image of the Canvas.
+     * <p>
+     * 0 take size of the Image, 1 stretch the Image, 2 Custom Image size
+     *
+     * @param mode the backgroundMode
+     */
+    public void setCanvasImageMode(int mode) {
+        backgroundMode = mode;
+    }
+
+    /**
+     * Returns the Custom width of the background Image of the Canvas.
+     *
+     * @return backgroundWidth the Width
+     */
+    public int getCanvasImageWidth() {
+        return backgroundWidth;
+    }
+
+    /**
+     * Set the Custom width of the background Image of the Canvas.
+     *
+     * @param width the Width
+     */
+    public void setCanvasImageWidth(int width) {
+        backgroundWidth = width;
+    }
+
+    /**
+     * Returns the Custom height of the background Image of the Canvas.
+     *
+     * @return backgroundHeight the height
+     */
+    public int getCanvasImageHeight() {
+        return backgroundHeight;
+    }
+
+    /**
+     * Set the Custom height of the background Image of the Canvas.
+     *
+     * @param height the height
+     */
+    public void setCanvasImageHeight(int height) {
+        backgroundHeight = height;
+    }
+
+    /**
+     * Returns the graphtable for Statistic Graphs.
+     */
+    public Hashtable<String, StatisticGraphPanel> getGraphTable() {
+        return statisticGraphTable;
+    }
+
+    /**
+     * Set the graphtable for Statistic Graphs
+     */
+    public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT) {
+        statisticGraphTable = gT;
+    }
+
+    /**
+     * Returns if the Simulation is running.
+     */
+    public boolean getIsSimRunning() {
+        return isSimRunning;
+    }
+
+    /**
+     * Sets isSimRunning.
+     *
+     * @param isRunning
+     */
+    public void setIsSimRunning(boolean isRunning) {
+        isSimRunning = isRunning;
+    }
+
+    /**
+     * @return the statisticData
+     */
+    public ArrayList<JsonObject> getStatisticData() {
+        return statisticData;
+    }
+
+    /**
+     * @param statisticData the statisticData to set
+     */
+    public void setStatisticData(ArrayList<JsonObject> statisticData) {
+        this.statisticData = statisticData;
+    }
+
+    /**
+     * Returns showConsoleLog.
+     */
+    public boolean getShowConsoleLog() {
+        return this.showConsoleLog;
+    }
+
+    /**
+     * Sets showConsoleLog.
+     *
+     * @param showConsoleLog
+     */
+    public void setShowConsoleLog(boolean showConsoleLog) {
+        this.showConsoleLog = showConsoleLog;
+
+    }
+
+    /**
+     * Initialize the Gson with wanted parameters
+     */
+    private void initGson() {
+        // TODO Auto-generated method stub
+        GsonBuilder builder = new GsonBuilder();
+        builder.serializeNulls();
+        builder.excludeFieldsWithoutExposeAnnotation();
+        builder.setPrettyPrinting();
+        builder.registerTypeAdapter(AbstractCpsObject.class, new AbstractCpsObjectAdapter());
+        builder.registerTypeAdapter(Position.class, new PositionAdapter());
+        builder.registerTypeAdapter(Color.class, new ColorAdapter());
+        builder.registerTypeAdapter(Pair.class, new PairAdapter());
+        // use the builder and make a instance of the Gson
+        this.setGson(builder.create());
+
+    }
+
+    /**
+     * @return the gson
+     */
+    public Gson getGson() {
+        return gson;
+    }
+
+    /**
+     * @param gson the gson to set
+     */
+    public void setGson(Gson gson) {
+        this.gson = gson;
+    }
+
+    public StatisticPanel getStatPanel() {
+        return statPanel;
+    }
+
+    public void setStatPanel(StatisticPanel sP) {
+        statPanel = sP;
+    }
+
+    /**
+     * @return the hashcodeMap
+     */
+    public HashMap<Integer, CpsUpperNode> getHashcodeMap() {
+        return hashcodeMap;
+    }
+
+    /**
+     * @param hashcodeMap the hashcodeMap to set
+     */
+    public void setHashcodeMap(HashMap<Integer, CpsUpperNode> hashcodeMap) {
+        this.hashcodeMap = hashcodeMap;
+    }
 }

+ 362 - 0
src/ui/view/AbstractCanvas.java

@@ -0,0 +1,362 @@
+package ui.view;
+
+import classes.*;
+import ui.controller.Control;
+import ui.controller.UpdateController;
+import ui.model.Model;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.MouseEvent;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.TimerTask;
+
+/**
+ * Collection of methods and values needed in both <code>MyCanvas</code> and <code>UpperNodeCanvas</code>
+ * <p>
+ * Although Java works on references we chose to add explicit return values for clearer code understanding in most cases
+ *
+ * @author: I. Dix
+ */
+public abstract class AbstractCanvas extends JPanel {
+    protected final JMenuItem itemDelete = new JMenuItem(Languages.getLanguage()[98]);
+    protected final JMenuItem itemCut = new JMenuItem(Languages.getLanguage()[95]);
+    protected final JMenuItem itemCopy = new JMenuItem(Languages.getLanguage()[96]);
+    protected final JMenuItem itemPaste = new JMenuItem(Languages.getLanguage()[97]);
+    protected final JMenuItem itemGroup = new JMenuItem(Languages.getLanguage()[99]);
+    protected final JMenuItem itemUngroup = new JMenuItem(Languages.getLanguage()[100]);
+    protected final JMenuItem itemTrack = new JMenuItem(Languages.getLanguage()[101]);
+    protected final JMenuItem itemUntrack = new JMenuItem(Languages.getLanguage()[102]);
+    protected final int ANIMTIME = 500; // animation Time
+    protected final int animFPS = 60;
+    protected final int animDelay = 1000 / animFPS; // animation Delay
+    // Selection
+    public AbstractCpsObject tempCps = null;
+    protected Model model;
+    protected Control controller;
+    protected UpdateController updCon;
+    // PopUpMenu
+    protected JPopupMenu popmenu = new JPopupMenu();
+    // Tooltip
+    protected boolean toolTip; // Tooltip on or off
+    protected Position toolTipPos = new Position(); // Tooltip Position
+    protected String toolTipText = "";
+    protected ArrayList<HolonElement> dataSelected = new ArrayList<>();
+    protected ArrayList<AbstractCpsObject> tempSelected = new ArrayList<>();
+    protected boolean[] showedInformation = new boolean[5];
+    // Mouse
+    protected boolean click = false;
+    protected boolean dragging = false; // for dragging
+    protected boolean dragged = false; // if an object/objects was/were dragged
+    protected boolean drawEdge = false; // for drawing edges
+    protected boolean doMark = false; // for double click
+    protected CpsEdge edgeHighlight = null;
+    protected int x = 0;
+    protected int y = 0;
+    protected Point mousePosition = new Point(); // Mouse Position when
+    protected ArrayList<Position> savePos;
+    // edge Object Start Point
+    protected int cx, cy;
+    protected int sx, sy; // Mark Coords
+    protected Position unPos;
+    // Animation
+    protected Timer animT; // animation Timer
+    protected int animDuration = ANIMTIME; // animation Duration
+    protected int animSteps = animDuration / animDelay; // animation Steps;
+    protected ArrayList<AbstractCpsObject> animCps = null;
+
+    // Graphics
+    protected Image img = null; // Contains the image to draw on the Canvas
+    protected Graphics2D g2; // For Painting
+    protected float scalediv20;
+
+
+    // ------------------------------------------ METHODS ------------------------------------------
+    protected String paintEdge(CpsEdge con, String maxCap) {
+        if (con.getA().getId() != model.getSelectedObjectID() && con.getB().getId() != model.getSelectedObjectID()
+                && con != edgeHighlight) {
+            if (con.getConnected() == 0) {
+                setEdgeState(con);
+            } else {
+                g2.setColor(Color.DARK_GRAY);
+                g2.setStroke(new BasicStroke(2));
+            }
+            g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
+                    con.getB().getPosition().y);
+
+            maxCap = setCapacityString(con, maxCap);
+
+            if (showedInformation[0]) {
+                if (con.getConnected() == 0 || con.getConnected() == 1) {
+                    g2.drawString(con.getFlow() + "/" + maxCap,
+                            (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
+                            (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
+                } else {
+                    g2.drawString("not connected", (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
+                            (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
+                }
+            }
+        }
+
+        return maxCap;
+    }
+
+
+    protected void setEdgeState(CpsEdge con) {
+        if (con.getState()) {
+            g2.setColor(Color.GREEN);
+            if (con.getCapacity() != -1) {
+                g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
+            }
+        } else {
+            g2.setColor(Color.RED);
+            g2.setStroke(new BasicStroke(2));
+        }
+    }
+
+
+    protected String setCapacityString(CpsEdge con, String maxCap) {
+        if (con.getCapacity() == -1) {
+            maxCap = Character.toString('\u221e');
+        } else if (con.getCapacity() == -2) {
+            maxCap = "???";
+        } else {
+            maxCap = String.valueOf(con.getCapacity());
+        }
+        return maxCap;
+    }
+
+
+    protected String nameSthSensible(CpsEdge con, String maxCap) {
+        if (con.getA().getId() == model.getSelectedObjectID()
+                || model.getSelectedCpsObjects().contains(con.getA()) || tempSelected.contains(con.getA())
+                || con.getB().getId() == model.getSelectedObjectID()
+                || model.getSelectedCpsObjects().contains(con.getB())
+                || tempSelected.contains(con.getB()) && con != edgeHighlight) {
+            g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
+                    con.getB().getPosition().y);
+
+            maxCap = setCapacityString(con, maxCap);
+
+            if (showedInformation[0]) {
+                if (con.getConnected() == 0 || con.getConnected() == 1) {
+                    g2.drawString(con.getFlow() + "/" + maxCap,
+                            (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
+                            (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
+                } else {
+                    g2.drawString("not connected",
+                            (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
+                            (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
+                }
+            }
+        }
+
+        return maxCap;
+    }
+
+
+    protected void nameSthSensible2(AbstractCpsObject cps) {
+        // node image
+        if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
+                || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
+            img = new ImageIcon(this.getClass().getResource("/Images/node_selected.png")).getImage();
+        } else {
+            if (cps instanceof HolonSwitch) {
+                if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
+                    ((HolonSwitch) cps).setAutoState(true);
+                } else {
+                    ((HolonSwitch) cps).setAutoState(false);
+                }
+            }
+            // Highlighting
+            if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
+                    || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
+                g2.setColor(Color.BLUE);
+                g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20),
+                        (int) (cps.getPosition().y - controller.getScaleDiv2() - scalediv20),
+                        (int) (controller.getScale() + (scalediv20 * 2)),
+                        (int) (controller.getScale() + (scalediv20 * 2)));
+                if (showedInformation[1] && cps instanceof HolonObject) {
+                    g2.setColor(Color.BLACK);
+                    float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
+                    g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
+                            cps.getPosition().y - controller.getScaleDiv2() - 10);
+                }
+            } else if (cps instanceof HolonObject) {
+                g2.setColor(((HolonObject) cps).getColor());
+
+                g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20),
+                        (int) (cps.getPosition().y - controller.getScaleDiv2() - scalediv20),
+                        (int) (controller.getScale() + (scalediv20 * 2)),
+                        (int) (controller.getScale() + (scalediv20 * 2)));
+
+                if (showedInformation[1]) {
+                    g2.setColor(Color.BLACK);
+                    float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
+                    g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
+                            cps.getPosition().y - controller.getScaleDiv2() - 10);
+                }
+            }
+            // draw image
+            File checkPath = new File(cps.getImage());
+            if (checkPath.exists()) {
+                img = new ImageIcon(cps.getImage()).getImage();
+            } else {
+                img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
+            }
+        }
+    }
+
+
+    protected void drawMarker() {
+        if (sx > x && sy > y) {
+            g2.drawRect(x, y, sx - x, sy - y);
+        } else if (sx < x && sy < y) {
+            g2.drawRect(sx, sy, x - sx, y - sy);
+        } else if (sx >= x) {
+            g2.drawRect(x, sy, sx - x, y - sy);
+        } else if (sy >= y) {
+            g2.drawRect(sx, y, x - sx, sy - y);
+        }
+    }
+
+
+    protected void showTooltip(Graphics g) {
+        if (toolTip) {
+            g2.setColor(new Color(255, 225, 150));
+            g2.setStroke(new BasicStroke(1));
+            int textWidth = g.getFontMetrics().stringWidth(toolTipText) + 2; // Text
+            // width
+
+            // fixed x and y Position to the screen
+            int fixXPos = toolTipPos.x - (textWidth >> 1) + model.getScaleDiv2();
+            int fixYPos = toolTipPos.y;
+
+            if (fixXPos < 0) {
+                fixXPos = 0;
+            } else if (fixXPos + textWidth + 1 > this.getWidth()) {
+                fixXPos -= (fixXPos + textWidth + 1) - this.getWidth();
+            }
+            if (fixYPos + 16 > this.getHeight()) {
+                fixYPos -= (fixYPos + 16) - this.getHeight();
+            }
+            g2.fillRect(fixXPos, fixYPos, textWidth, 15);
+            g2.setColor(Color.BLACK);
+            g2.drawRect(fixXPos, fixYPos, textWidth, 15);
+            g2.drawString(toolTipText, fixXPos + 2, fixYPos + 12);
+        }
+    }
+
+
+    protected void setConsoleTextAfterSelect(AbstractCpsObject cps) {
+        if (model.getShowConsoleLog()) {
+            controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
+            controller.addTextToConsole("" + cps.getName(), Color.BLUE, 12, true, false, false);
+            controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
+            controller.addTextToConsole("" + cps.getId(), Color.RED, 12, true, false, true);
+        }
+    }
+
+
+    protected void setRightclickMenu(MouseEvent e) {
+        if (e.getButton() == MouseEvent.BUTTON3) {
+            if (tempCps != null) {
+                itemDelete.setEnabled(true);
+                itemCut.setEnabled(true);
+                itemCopy.setEnabled(true);
+                if (tempCps != null) {
+                    itemGroup.setEnabled(true);
+                    itemTrack.setEnabled(true);
+                    itemUntrack.setEnabled(true);
+                }
+                if (tempCps instanceof CpsUpperNode)
+                    itemUngroup.setEnabled(true);
+                else
+                    itemUngroup.setEnabled(false);
+                if (model.getSelectedCpsObjects().size() == 0) {
+                    controller.addSelectedObject(tempCps);
+                }
+            } else {
+                itemCut.setEnabled(false);
+                itemCopy.setEnabled(false);
+                itemDelete.setEnabled(false);
+                itemGroup.setEnabled(false);
+                itemUngroup.setEnabled(false);
+                itemTrack.setEnabled(false);
+                itemUntrack.setEnabled(false);
+            }
+            mousePosition = this.getMousePosition();
+            popmenu.show(e.getComponent(), e.getX(), e.getY());
+        }
+    }
+
+
+    protected void markObjects() {
+        if (doMark) {
+            doMark = false;
+            for (AbstractCpsObject cps : tempSelected) {
+                if (!model.getSelectedCpsObjects().contains(cps)) {
+                    controller.addSelectedObject(cps);
+                }
+            }
+            controller.getObjectsInDepth();
+            tempSelected.clear();
+        }
+    }
+
+    protected int[] determineMousePositionOnEdge(CpsEdge p) {
+        int lx, ly, hx, hy;
+
+        if (p.getA().getPosition().x > p.getB().getPosition().x) {
+            hx = p.getA().getPosition().x + model.getScaleDiv2() + 7;
+            lx = p.getB().getPosition().x + model.getScaleDiv2() - 7;
+        } else {
+            lx = p.getA().getPosition().x + model.getScaleDiv2() - 7;
+            hx = p.getB().getPosition().x + model.getScaleDiv2() + 7;
+        }
+        if (p.getA().getPosition().y > p.getB().getPosition().y) {
+            hy = p.getA().getPosition().y + model.getScaleDiv2() + 7;
+            ly = p.getB().getPosition().y + model.getScaleDiv2() - 7;
+        } else {
+            ly = p.getA().getPosition().y + model.getScaleDiv2() - 7;
+            hy = p.getB().getPosition().y + model.getScaleDiv2() + 7;
+        }
+
+        return new int[]{lx, ly, hx, hy};
+    }
+
+
+    /**
+     * Checks if a double click was made.
+     *
+     * @return true if doublecklick, false if not
+     */
+    protected boolean doubleClick() {
+        if (click) {
+            click = false;
+            return true;
+        } else {
+            click = true;
+            java.util.Timer t = new java.util.Timer("doubleclickTimer", false);
+            t.schedule(new TimerTask() {
+                @Override
+                public void run() {
+                    click = false;
+                }
+            }, 500);
+        }
+        return false;
+    }
+
+    protected boolean setToolTipInfoAndPosition(boolean on, AbstractCpsObject cps) {
+        if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
+            on = true;
+            toolTipPos.x = cps.getPosition().x - controller.getScaleDiv2();
+            toolTipPos.y = cps.getPosition().y + controller.getScaleDiv2();
+            toolTipText = cps.getName() + ", " + cps.getId();
+        }
+
+        return on;
+    }
+}

+ 9 - 21
src/ui/view/DisplayedInformationPopUp.java

@@ -1,16 +1,10 @@
 package ui.view;
 
-import java.awt.BorderLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
+import ui.controller.Control;
 
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JDialog;
-import javax.swing.JPanel;
+import javax.swing.*;
 import javax.swing.border.EmptyBorder;
-
-import ui.controller.Control;
+import java.awt.*;
 
 /**
  * This Class represents a Popup to edit the shown Information.
@@ -60,24 +54,18 @@ public class DisplayedInformationPopUp extends JDialog {
 
 		objectEnergyCheckbox.setSelected(canvas.getShowedInformation()[1]);
 		connectionCheckbox.setSelected(canvas.getShowedInformation()[0]);
-		btnOk.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent arg0) {
-				setInformation(connectionCheckbox.isSelected(), objectEnergyCheckbox.isSelected(),
-						colorizedBorderCheckbox.isSelected(), nodeOfnodeConnectionCheckbox.isSelected());
-				controller.getSimManager().getFlexiblePane().recalculate();
-				dispose();
-			}
+		btnOk.addActionListener(actionEvent -> {
+			setInformation(connectionCheckbox.isSelected(), objectEnergyCheckbox.isSelected(),
+					colorizedBorderCheckbox.isSelected(), nodeOfnodeConnectionCheckbox.isSelected());
+			controller.getSimManager().getFlexiblePane().recalculate();
+			dispose();
 		});
 		btnOk.setBounds(174, 193, 82, 23);
 		contentPanel.add(btnOk);
 
 		JButton btnCancel = new JButton(Languages.getLanguage()[34]);
 		btnCancel.setActionCommand(Languages.getLanguage()[34]);
-		btnCancel.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent arg0) {
-				dispose();
-			}
-		});
+		btnCancel.addActionListener(actionEvent -> dispose());
 		btnCancel.setBounds(69, 193, 89, 23);
 		contentPanel.add(btnCancel);
 		

+ 76 - 350
src/ui/view/MyCanvas.java

@@ -9,71 +9,22 @@ import ui.model.Model;
 import javax.swing.*;
 import java.awt.*;
 import java.awt.datatransfer.UnsupportedFlavorException;
-import java.awt.event.*;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
 import java.awt.geom.Line2D;
-import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Timer;
-import java.util.TimerTask;
 
 /**
  * This Class is the Canvas. All Objects will be visualized here
  *
  * @author Gruppe14
  */
-public class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
+public class MyCanvas extends AbstractCanvas implements MouseListener, MouseMotionListener {
 
     private static final long serialVersionUID = 1L;
-    public final JMenuItem itemPaste = new JMenuItem(Languages.getLanguage()[97]);
-    // edge Object Start Point
-    private final Model model;
-    private final Control controller;
-    private final float scalediv20;
-    private final UpdateController updCon;
-    private final boolean[] showedInformation = new boolean[5];
-    // PopUpMenu
-    private final JPopupMenu popmenu = new JPopupMenu();
-    private final JMenuItem itemDelete = new JMenuItem(Languages.getLanguage()[98]);
-    private final JMenuItem itemCut = new JMenuItem(Languages.getLanguage()[95]);
-    private final JMenuItem itemCopy = new JMenuItem(Languages.getLanguage()[96]);
-    private final JMenuItem itemGroup = new JMenuItem(Languages.getLanguage()[99]);
-    private final JMenuItem itemUngroup = new JMenuItem(Languages.getLanguage()[100]);
-    private final JMenuItem itemTrack = new JMenuItem(Languages.getLanguage()[101]);
-    private final JMenuItem itemUntrack = new JMenuItem(Languages.getLanguage()[102]);
-    private final Position toolTipPos = new Position(); // Tooltip Position
-    private final int ANIMTIME = 500; // animation Time
-    private final int animFPS = 60;
-    private final int animDelay = 1000 / animFPS; // animation Delay
-    public AbstractCpsObject tempCps = null;
-    ArrayList<HolonElement> dataSelected = new ArrayList<>();
-    ArrayList<AbstractCpsObject> tempSelected = new ArrayList<>();
-    private Image img = null; // Contains the image to draw on MyCanvas
-    private int x = 0;
-    private int y = 0;
-    private Graphics2D g2; // For Painting
-    private int cx, cy;
-    private int sx, sy; // Mark Coords
-    private Position unPos;
-    private ArrayList<Position> savePos;
-    private boolean dragging = false; // for dragging
-    private boolean dragged = false; // if an object/objects was/were dragged
-    private boolean drawEdge = false; // for drawing edges
-    private boolean click = false; // for double click
-    private boolean doMark = false; // for double click
-    private CpsEdge edgeHighlight = null;
-    // rightclicked
-    // Tooltip
-    private boolean toolTip; // Tooltip on or off
-    private String toolTipText = "";
-    private Point mousePosition = new Point(); // Mouse Position when
-    // Animation Stuff
-    private javax.swing.Timer animT; // animation Timer
-    private ArrayList<AbstractCpsObject> animCps = null;
-    private int animDuration = ANIMTIME; // animation Duration
-    private int animSteps = animDuration / animDelay; // animation Steps;
-
-    // contains the value of the Capacity for new created Edges
+
 
     /**
      * Constructor.
@@ -137,32 +88,28 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
                 savePos.get(i).y = animCps.get(i).getPosition().y;
             }
 
-            animT = new javax.swing.Timer(animDelay, new ActionListener() {
-
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    if (animDuration - animDelay > 0 && animCps.size() > 1) {
-                        for (AbstractCpsObject animCpObject : animCps) {
-                            double x1 = animCpObject.getPosition().x - unPos.x;
-                            double y1 = animCpObject.getPosition().y - unPos.y;
-                            animCpObject.getPosition().x -= x1 / animSteps;
-                            animCpObject.getPosition().y -= y1 / animSteps;
-                        }
-                        repaint();
-                        animDuration -= animDelay;
-                        animSteps--;
-                    } else {
-                        animDuration = ANIMTIME;
-                        animSteps = animDuration / animDelay;
-                        animT.stop();
-                        for (int i = 0; i < animCps.size(); i++) {
-                            animCps.get(i).getPosition().x = savePos.get(i).x;
-                            animCps.get(i).getPosition().y = savePos.get(i).y;
-                        }
-                        controller.addUpperNode("NodeOfNode", null, animCps);
-                        controller.calculateStateForCurrentTimeStep();
-                        repaint();
+            animT = new javax.swing.Timer(animDelay, actionEvent1 -> {
+                if (animDuration - animDelay > 0 && animCps.size() > 1) {
+                    for (AbstractCpsObject animCpObject : animCps) {
+                        double x1 = animCpObject.getPosition().x - unPos.x;
+                        double y1 = animCpObject.getPosition().y - unPos.y;
+                        animCpObject.getPosition().x -= x1 / animSteps;
+                        animCpObject.getPosition().y -= y1 / animSteps;
                     }
+                    repaint();
+                    animDuration -= animDelay;
+                    animSteps--;
+                } else {
+                    animDuration = ANIMTIME;
+                    animSteps = animDuration / animDelay;
+                    animT.stop();
+                    for (int i = 0; i < animCps.size(); i++) {
+                        animCps.get(i).getPosition().x = savePos.get(i).x;
+                        animCps.get(i).getPosition().y = savePos.get(i).y;
+                    }
+                    controller.addUpperNode("NodeOfNode", null, animCps);
+                    controller.calculateStateForCurrentTimeStep();
+                    repaint();
                 }
             });
             animT.start();
@@ -195,32 +142,28 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
                 cps.setPosition(new Position(x, y));
             }
 
-            animT = new javax.swing.Timer(animDelay, new ActionListener() {
-
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    if (animDuration - animDelay >= 0) {
-                        for (int i = 0; i < animCps.size(); i++) {
-                            double x1 = animCps.get(i).getPosition().x - savePos.get(i).x;
-                            double y1 = animCps.get(i).getPosition().y - savePos.get(i).y;
-                            animCps.get(i).getPosition().x -= x1 / animSteps;
-                            animCps.get(i).getPosition().y -= y1 / animSteps;
-                        }
-                        repaint();
-                        animDuration -= animDelay;
-                        animSteps--;
-                    } else {
-                        animDuration = ANIMTIME;
-                        animSteps = animDuration / animDelay;
-                        animT.stop();
-                        for (int i = 0; i < animCps.size(); i++) {
-                            animCps.get(i).getPosition().x = savePos.get(i).x;
-                            animCps.get(i).getPosition().y = savePos.get(i).y;
-                        }
-
-                        controller.calculateStateForCurrentTimeStep();
-                        repaint();
+            animT = new javax.swing.Timer(animDelay, actionEvent1 -> {
+                if (animDuration - animDelay >= 0) {
+                    for (int i = 0; i < animCps.size(); i++) {
+                        double x1 = animCps.get(i).getPosition().x - savePos.get(i).x;
+                        double y1 = animCps.get(i).getPosition().y - savePos.get(i).y;
+                        animCps.get(i).getPosition().x -= x1 / animSteps;
+                        animCps.get(i).getPosition().y -= y1 / animSteps;
+                    }
+                    repaint();
+                    animDuration -= animDelay;
+                    animSteps--;
+                } else {
+                    animDuration = ANIMTIME;
+                    animSteps = animDuration / animDelay;
+                    animT.stop();
+                    for (int i = 0; i < animCps.size(); i++) {
+                        animCps.get(i).getPosition().x = savePos.get(i).x;
+                        animCps.get(i).getPosition().y = savePos.get(i).y;
                     }
+
+                    controller.calculateStateForCurrentTimeStep();
+                    repaint();
                 }
             });
             animT.start();
@@ -367,7 +310,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
      * @param g Graphics
      */
     public void paintComponent(Graphics g) {
-        String maxCap;
+        String maxCap = null;
         super.paintComponent(g);
         // Rendering
         g2 = (Graphics2D) g;
@@ -416,43 +359,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
         }
 
         for (CpsEdge con : model.getEdgesOnCanvas()) {
-            if (con.getA().getId() != model.getSelectedObjectID() && con.getB().getId() != model.getSelectedObjectID()
-                    && con != edgeHighlight) {
-                if (con.getConnected() == 0) {
-                    if (con.getState()) {
-                        g2.setColor(Color.GREEN);
-                        if (con.getCapacity() != -1) {
-                            g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
-                        }
-                    } else {
-                        g2.setColor(Color.RED);
-                        g2.setStroke(new BasicStroke(2));
-                    }
-                } else {
-                    g2.setColor(Color.DARK_GRAY);
-                    g2.setStroke(new BasicStroke(2));
-                }
-                g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
-                        con.getB().getPosition().y);
-
-                if (con.getCapacity() == -1) {
-                    maxCap = Character.toString('\u221e');
-                } else if (con.getCapacity() == -2) {
-                    maxCap = "???";
-                } else {
-                    maxCap = String.valueOf(con.getCapacity());
-                }
-                if (showedInformation[0]) {
-                    if (con.getConnected() == 0 || con.getConnected() == 1) {
-                        g2.drawString(con.getFlow() + "/" + maxCap,
-                                (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
-                                (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
-                    } else {
-                        g2.drawString("not connected", (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
-                                (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
-                    }
-                }
-            }
+            maxCap = paintEdge(con, maxCap);
         }
 
         // Highlighted Edge
@@ -464,33 +371,8 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
                 } else {
                     g2.setStroke(new BasicStroke(2));
                 }
-                if (con.getA().getId() == model.getSelectedObjectID()
-                        || model.getSelectedCpsObjects().contains(con.getA()) || tempSelected.contains(con.getA())
-                        || con.getB().getId() == model.getSelectedObjectID()
-                        || model.getSelectedCpsObjects().contains(con.getB())
-                        || tempSelected.contains(con.getB()) && con != edgeHighlight) {
-                    g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
-                            con.getB().getPosition().y);
-
-                    if (con.getCapacity() == -1) {
-                        maxCap = Character.toString('\u221e');
-                    } else if (con.getCapacity() == -2) {
-                        maxCap = "???";
-                    } else {
-                        maxCap = String.valueOf(con.getCapacity());
-                    }
-                    if (showedInformation[0]) {
-                        if (con.getConnected() == 0 || con.getConnected() == 1) {
-                            g2.drawString(con.getFlow() + "/" + maxCap,
-                                    (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
-                                    (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
-                        } else {
-                            g2.drawString("not connected",
-                                    (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
-                                    (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
-                        }
-                    }
-                }
+
+                maxCap = nameSthSensible(con, maxCap);
             }
         } else if (edgeHighlight != null) {
             g2.setColor(Color.BLUE);
@@ -503,13 +385,8 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
             g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight.getA().getPosition().y,
                     edgeHighlight.getB().getPosition().x, edgeHighlight.getB().getPosition().y);
 
-            if (edgeHighlight.getCapacity() == -1) {
-                maxCap = Character.toString('\u221e');
-            } else if (edgeHighlight.getCapacity() == -2) {
-                maxCap = "???";
-            } else {
-                maxCap = String.valueOf(edgeHighlight.getCapacity());
-            }
+            maxCap = setCapacityString(edgeHighlight, maxCap);
+
             if (showedInformation[0]) {
                 g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
                         (edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2,
@@ -529,55 +406,9 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
                             (int) (controller.getScale() + ((scalediv20 + 3) * 2)));
                 }
             }
-            // node image
-            if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
-                    || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
-                img = new ImageIcon(this.getClass().getResource("/Images/node_selected.png")).getImage();
-            } else {
-                if (cps instanceof HolonSwitch) {
-                    if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
-                        ((HolonSwitch) cps).setAutoState(true);
-                    } else {
-                        ((HolonSwitch) cps).setAutoState(false);
-                    }
-                }
-                // Highlighting
-                if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
-                        || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
-                    g2.setColor(Color.BLUE);
-                    g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20),
-                            (int) (cps.getPosition().y - controller.getScaleDiv2() - scalediv20),
-                            (int) (controller.getScale() + (scalediv20 * 2)),
-                            (int) (controller.getScale() + (scalediv20 * 2)));
-                    if (showedInformation[1] && cps instanceof HolonObject) {
-                        g2.setColor(Color.BLACK);
-                        float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
-                        g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
-                                cps.getPosition().y - controller.getScaleDiv2() - 10);
-                    }
-                } else if (cps instanceof HolonObject) {
-                    g2.setColor(((HolonObject) cps).getColor());
-
-                    g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20),
-                            (int) (cps.getPosition().y - controller.getScaleDiv2() - scalediv20),
-                            (int) (controller.getScale() + (scalediv20 * 2)),
-                            (int) (controller.getScale() + (scalediv20 * 2)));
-
-                    if (showedInformation[1]) {
-                        g2.setColor(Color.BLACK);
-                        float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
-                        g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
-                                cps.getPosition().y - controller.getScaleDiv2() - 10);
-                    }
-                }
-                // draw image
-                File checkPath = new File(cps.getImage());
-                if (checkPath.exists()) {
-                    img = new ImageIcon(cps.getImage()).getImage();
-                } else {
-                    img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
-                }
-            }
+
+            nameSthSensible2(cps);
+
             g2.drawImage(img, cps.getPosition().x - controller.getScaleDiv2(),
                     cps.getPosition().y - controller.getScaleDiv2(), controller.getScale(), controller.getScale(),
                     null);
@@ -588,40 +419,10 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
         if (doMark) {
             g2.setColor(Color.BLACK);
             g2.setStroke(new BasicStroke(1));
-            if (sx > x && sy > y) {
-                g2.drawRect(x, y, sx - x, sy - y);
-            } else if (sx < x && sy < y) {
-                g2.drawRect(sx, sy, x - sx, y - sy);
-            } else if (sx >= x) {
-                g2.drawRect(x, sy, sx - x, y - sy);
-            } else if (sy >= y) {
-                g2.drawRect(sx, y, x - sx, sy - y);
-            }
+            drawMarker();
         }
         // Tooltip
-        if (toolTip) {
-            g2.setColor(new Color(255, 225, 150));
-            g2.setStroke(new BasicStroke(1));
-            int textWidth = g.getFontMetrics().stringWidth(toolTipText) + 2; // Text
-            // width
-
-            // fixed x and y Position to the screen
-            int fixXPos = toolTipPos.x - (textWidth >> 1) + model.getScaleDiv2();
-            int fixYPos = toolTipPos.y;
-
-            if (fixXPos < 0) {
-                fixXPos = 0;
-            } else if (fixXPos + textWidth + 1 > this.getWidth()) {
-                fixXPos -= (fixXPos + textWidth + 1) - this.getWidth();
-            }
-            if (fixYPos + 16 > this.getHeight()) {
-                fixYPos -= (fixYPos + 16) - this.getHeight();
-            }
-            g2.fillRect(fixXPos, fixYPos, textWidth, 15);
-            g2.setColor(Color.BLACK);
-            g2.drawRect(fixXPos, fixYPos, textWidth, 15);
-            g2.drawString(toolTipText, fixXPos + 2, fixYPos + 12);
-        }
+        showTooltip(g);
     }
 
     @Override
@@ -657,12 +458,9 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
             cy = cps.getPosition().y - controller.getScaleDiv2();
             if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
                 tempCps = cps;
-                if (model.getShowConsoleLog()) {
-                    controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
-                    controller.addTextToConsole("" + cps.getName(), Color.BLUE, 12, true, false, false);
-                    controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
-                    controller.addTextToConsole("" + cps.getId(), Color.RED, 12, true, false, true);
-                }
+
+                setConsoleTextAfterSelect(cps);
+
                 dragging = true;
                 if (e.isControlDown() && tempCps != null) {
                     if (model.getSelectedCpsObjects().contains(tempCps)) {
@@ -733,46 +531,9 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
         dragged = false;
 
         // Rightclick List
-        if (e.getButton() == MouseEvent.BUTTON3) {
-            if (e.getButton() == MouseEvent.BUTTON3 && tempCps != null) {
-                itemDelete.setEnabled(true);
-                itemCut.setEnabled(true);
-                itemCopy.setEnabled(true);
-                if (tempCps != null) {
-                    itemGroup.setEnabled(true);
-                    itemTrack.setEnabled(true);
-                    itemUntrack.setEnabled(true);
-                }
-                if (tempCps instanceof CpsUpperNode)
-                    itemUngroup.setEnabled(true);
-                else
-                    itemUngroup.setEnabled(false);
-                if (model.getSelectedCpsObjects().size() == 0) {
-                    controller.addSelectedObject(tempCps);
-                }
-            } else {
-                itemCut.setEnabled(false);
-                itemCopy.setEnabled(false);
-                itemDelete.setEnabled(false);
-                itemGroup.setEnabled(false);
-                itemUngroup.setEnabled(false);
-                itemTrack.setEnabled(false);
-                itemUntrack.setEnabled(false);
-            }
-            mousePosition = this.getMousePosition();
-            popmenu.show(e.getComponent(), e.getX(), e.getY());
-        }
+        setRightclickMenu(e);
 
-        if (doMark) {
-            doMark = false;
-            for (AbstractCpsObject cps : tempSelected) {
-                if (!model.getSelectedCpsObjects().contains(cps)) {
-                    controller.addSelectedObject(cps);
-                }
-            }
-            controller.getObjectsInDepth();
-            tempSelected.clear();
-        }
+        markObjects();
 
         if (doubleClick() && tempCps != null && tempCps instanceof HolonSwitch && MouseEvent.BUTTON3 != e.getButton()) {
             ((HolonSwitch) tempCps).switchState();
@@ -883,17 +644,13 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
         x = e.getX();
         y = e.getY();
 
-        // Everytghing for the tooltip :)
+        // Everything for the tooltip :)
         boolean on = false;
         for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
             cx = cps.getPosition().x - controller.getScaleDiv2();
             cy = cps.getPosition().y - controller.getScaleDiv2();
-            if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
-                on = true;
-                toolTipPos.x = cps.getPosition().x - controller.getScaleDiv2();
-                toolTipPos.y = cps.getPosition().y + controller.getScaleDiv2();
-                toolTipText = cps.getName() + ", " + cps.getId();
-            }
+
+            on = setToolTipInfoAndPosition(on, cps);
         }
         toolTip = on;
         repaint();
@@ -1000,24 +757,15 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
     private CpsEdge mousePositionOnEdge(int x, int y) {
         x += controller.getScaleDiv2();
         y += controller.getScaleDiv2();
-        int lx, ly, hx, hy;
         for (CpsEdge p : model.getEdgesOnCanvas()) {
             Line2D l = new Line2D.Float(p.getA().getPosition().x, p.getA().getPosition().y, p.getB().getPosition().x,
                     p.getB().getPosition().y);
-            if (p.getA().getPosition().x > p.getB().getPosition().x) {
-                hx = p.getA().getPosition().x + model.getScaleDiv2() + 7;
-                lx = p.getB().getPosition().x + model.getScaleDiv2() - 7;
-            } else {
-                lx = p.getA().getPosition().x + model.getScaleDiv2() - 7;
-                hx = p.getB().getPosition().x + model.getScaleDiv2() + 7;
-            }
-            if (p.getA().getPosition().y > p.getB().getPosition().y) {
-                hy = p.getA().getPosition().y + model.getScaleDiv2() + 7;
-                ly = p.getB().getPosition().y + model.getScaleDiv2() - 7;
-            } else {
-                ly = p.getA().getPosition().y + model.getScaleDiv2() - 7;
-                hy = p.getB().getPosition().y + model.getScaleDiv2() + 7;
-            }
+
+            int[] positions = determineMousePositionOnEdge(p);
+            int lx = positions[0];
+            int ly = positions[1];
+            int hx = positions[2];
+            int hy = positions[3];
 
             // distance from a point to a line and between both Objects
             if (l.ptLineDistSq(x - model.getScaleDiv2(), y - model.getScaleDiv2()) < 20 && x > lx && x < hx && y > ly
@@ -1028,7 +776,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
         return null;
     }
 
-    public void updateLanguages() {
+    protected void updateLanguages() {
         itemCut.setText(Languages.getLanguage()[95]);
         itemCopy.setText(Languages.getLanguage()[96]);
         itemPaste.setText(Languages.getLanguage()[97]);
@@ -1039,28 +787,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
         itemUntrack.setText(Languages.getLanguage()[102]);
     }
 
-    /**
-     * Checks if a double click was made.
-     *
-     * @return true if doublecklick, false if not
-     */
-    private boolean doubleClick() {
-        if (click) {
-            click = false;
-            return true;
-        } else {
-            click = true;
-            Timer t = new Timer("doubleclickTimer", false);
-            t.schedule(new TimerTask() {
-                @Override
-                public void run() {
-                    click = false;
-                }
-            }, 500);
-        }
-        return false;
-    }
-
     /**
      * Set if Information should be shown.
      *
@@ -1080,7 +806,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
      *
      * @return Array of boolean [0] = connection, [1] = objects
      */
-    public boolean[] getShowedInformation() {
+    protected boolean[] getShowedInformation() {
         return showedInformation;
     }
 
@@ -1089,7 +815,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
      *
      * @param bool
      */
-    public void setToolTip(boolean bool) {
+    protected void setToolTip(boolean bool) {
         this.toolTip = bool;
     }
 
@@ -1099,7 +825,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
      * @param x
      * @param y
      */
-    public void setXY(int x, int y) {
+    protected void setXY(int x, int y) {
         this.x = x;
         this.y = y;
     }

+ 1206 - 1581
src/ui/view/UpperNodeCanvas.java

@@ -1,15 +1,14 @@
 package ui.view;
 
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.Point;
-import java.awt.RenderingHints;
+import classes.*;
+import com.google.gson.JsonParseException;
+import ui.controller.Control;
+import ui.controller.UpdateController;
+import ui.model.Model;
+
+import javax.swing.*;
+import java.awt.*;
 import java.awt.datatransfer.UnsupportedFlavorException;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
@@ -17,1582 +16,1208 @@ import java.awt.geom.Line2D;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Timer;
-import java.util.TimerTask;
-
-import javax.swing.ImageIcon;
-import javax.swing.JLabel;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JPopupMenu;
-import javax.swing.JScrollPane;
-import javax.swing.JSplitPane;
-import javax.swing.JTabbedPane;
-
-import com.google.gson.JsonParseException;
-
-import classes.CpsEdge;
-import classes.CpsNode;
-import classes.CpsUpperNode;
-import classes.AbstractCpsObject;
-import classes.HolonElement;
-import classes.HolonObject;
-import classes.HolonSwitch;
-import classes.Position;
-import classes.SubNet;
-import ui.controller.Control;
-import ui.controller.UpdateController;
-import ui.model.Model;
 
 /**
  * This Class is the Canvas. All Objects will be visualized here
- * 
+ *
  * @author Gruppe14
  */
-public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotionListener {
-
-	private static final long serialVersionUID = 1L;
-	private Image img = null; // Contains the image to draw on MyCanvas
-	private int x = 0;
-	private int y = 0;
-	// edge Object Start Point
-	private Model model;
-	private final Control controller;
-	Graphics2D g2; // For Painting
-	private int cx, cy;
-	private int sx, sy; // Mark Coords
-	private float scalediv20;
-
-	// Path
-	public String path;
-	private JLabel breadCrumb;
-
-	ArrayList<HolonElement> dataSelected = new ArrayList<HolonElement>();
-	ArrayList<AbstractCpsObject> tempSelected = new ArrayList<AbstractCpsObject>();
-
-	// The UpperNode
-	public CpsUpperNode upperNode;
-	public int code;
-
-	private boolean[] showedInformation = new boolean[5];
-	private boolean dragging = false; // for dragging
-	private boolean dragged = false; // if an object/objects was/were dragged
-	private boolean drawEdge = false; // for drawing edges
-	private boolean click = false; // for double click
-	private boolean doMark = false; // for double click
-	public AbstractCpsObject tempCps = null;
-	private CpsEdge edgeHighlight = null;
-
-	// PopUpMenu
-	private JPopupMenu popmenu = new JPopupMenu();
-	private JMenuItem itemDelete = new JMenuItem("Delete");
-	private JMenuItem itemCut = new JMenuItem("Cut");
-	private JMenuItem itemCopy = new JMenuItem("Copy");
-	public JMenuItem itemPaste = new JMenuItem("Paste");
-	public JMenuItem itemGroup = new JMenuItem("Group");
-	public JMenuItem itemUngroup = new JMenuItem("Ungroup");
-	public JMenuItem itemTrack = new JMenuItem("Track");
-	public JMenuItem itemUntrack = new JMenuItem("Untrack");
-
-	// Tooltip
-	private boolean toolTip; // Tooltip on or off
-	private Position toolTipPos = new Position(); // Tooltip Position
-	private String toolTipText = "";
-
-	private Point mousePosition = new Point(); // Mouse Position when
-												// rightclicked
-
-	// contains the value of the Capacity for new created Edges
-
-	private UpdateController updCon;
-
-	// Animation Stuff
-	javax.swing.Timer animT; // animation Timer
-	private final int ANIMTIME = 500; // animation Time
-
-	private ArrayList<AbstractCpsObject> animCps = null;
-	private int animFPS = 60;
-	private int animDuration = ANIMTIME; // animation Duration
-	private int animDelay = 1000 / animFPS; // animation Delay
-	private int animSteps = animDuration / animDelay; // animation Steps;
-	private Position unPos;
-	private ArrayList<Position> savePos;
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param mod
-	 *            the Model
-	 * @param control
-	 *            the Controller
-	 * @param unitGraph
-	 */
-	public UpperNodeCanvas(Model mod, Control control, UnitGraph unitGraph, CpsUpperNode UpperNode, String parentPath) {
-		toolTip = false;
-
-		this.controller = control;
-		this.model = mod;
-		this.upperNode = UpperNode;
-		this.code = UpperNode.hashCode();
-		this.path = parentPath + upperNode.getName();
-		this.breadCrumb = new JLabel(path);
-		// this.add(breadCrumb);
-		scalediv20 = model.getScale() / 20;
-
-		// Cps objecte aus dem border links schieben
-		upperNode.setLeftBorder((int) (50 + scalediv20 + scalediv20 + 10));
-		for (AbstractCpsObject cps : upperNode.getNodes()) {
-			if (cps.getPosition().x < model.getScaleDiv2() + upperNode.getLeftBorder() + 5) {
-				cps.setPosition(
-						new Position(upperNode.getLeftBorder() + 5 + model.getScaleDiv2(), cps.getPosition().y));
-			}
-		}
-
-		showedInformation[0] = true;
-		showedInformation[1] = true;
-		showedInformation[4] = true;
-
-		popmenu.add(itemCut);
-		popmenu.add(itemCopy);
-		popmenu.add(itemPaste);
-		popmenu.add(itemDelete);
-		popmenu.addSeparator();
-		popmenu.add(itemGroup);
-		popmenu.add(itemUngroup);
-		popmenu.add(itemTrack);
-		popmenu.add(itemUntrack);
-
-		itemDelete.setEnabled(false);
-		itemCut.setEnabled(false);
-		itemCopy.setEnabled(false);
-		itemPaste.setEnabled(true);
-		itemGroup.setEnabled(false);
-		itemUngroup.setEnabled(false);
-		itemTrack.setEnabled(false);
-		itemUntrack.setEnabled(false);
-		updCon = new UpdateController(model, controller);
-
-		itemGroup.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				// calculate uppernode pos (taken from the controller)
-				unPos = new Position(0, 0);
-				animCps = new ArrayList<>();
-				for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
-					animCps.add(cps); // add to animation Cps ArrayList
-					unPos.x += cps.getPosition().x;
-					unPos.y += cps.getPosition().y;
-				}
-				unPos.x /= animCps.size();
-				unPos.y /= animCps.size();
-
-				// save old Position
-				savePos = new ArrayList<>();
-				for (int i = 0; i < animCps.size(); i++) {
-					savePos.add(new Position(0, 0));
-					savePos.get(i).x = animCps.get(i).getPosition().x;
-					savePos.get(i).y = animCps.get(i).getPosition().y;
-				}
-
-				animT = new javax.swing.Timer(animDelay, new ActionListener() {
-
-					@Override
-					public void actionPerformed(ActionEvent e) {
-						if (animDuration - animDelay > 0 && animCps.size() > 1) {
-							for (int i = 0; i < animCps.size(); i++) {
-								double x1 = animCps.get(i).getPosition().x - unPos.x;
-								double y1 = animCps.get(i).getPosition().y - unPos.y;
-								animCps.get(i).getPosition().x -= x1 / animSteps;
-								animCps.get(i).getPosition().y -= y1 / animSteps;
-							}
-							repaint();
-							animDuration -= animDelay;
-							animSteps--;
-						} else {
-							animDuration = ANIMTIME;
-							animSteps = animDuration / animDelay;
-							animT.stop();
-							for (int i = 0; i < animCps.size(); i++) {
-								animCps.get(i).getPosition().x = savePos.get(i).x;
-								animCps.get(i).getPosition().y = savePos.get(i).y;
-							}
-							controller.addUpperNode("NodeOfNode", upperNode, model.getSelectedCpsObjects());
-							controller.calculateStateForCurrentTimeStep();
-							repaint();
-						}
-					}
-				});
-				animT.start();
-			}
-		});
-
-		itemUngroup.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				// save old Position
-				JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
-				for (int i = 4; i < tabbedPane.getTabCount(); i++) {
-					if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
-							.getComponent(0)).upperNode.getId() == ((CpsUpperNode) tempCps).getId()) {
-						tabbedPane.remove(i);
-						break;
-					}
-				}
-
-				savePos = new ArrayList<>();
-				animCps = ((CpsUpperNode) tempCps).getNodes();
-				controller.delUpperNode((CpsUpperNode) tempCps, upperNode);
-
-				for (int i = 0; i < animCps.size(); i++) {
-					savePos.add(new Position(0, 0));
-					savePos.get(i).x = animCps.get(i).getPosition().x;
-					savePos.get(i).y = animCps.get(i).getPosition().y;
-				}
-				for (AbstractCpsObject cps : animCps) {
-					int x = ((CpsUpperNode) tempCps).getPosition().x;
-					int y = ((CpsUpperNode) tempCps).getPosition().y;
-
-					cps.setPosition(new Position(x, y));
-				}
-
-				animT = new javax.swing.Timer(animDelay, new ActionListener() {
-
-					@Override
-					public void actionPerformed(ActionEvent e) {
-						if (animDuration - animDelay >= 0) {
-							for (int i = 0; i < animCps.size(); i++) {
-								double x1 = animCps.get(i).getPosition().x - savePos.get(i).x;
-								double y1 = animCps.get(i).getPosition().y - savePos.get(i).y;
-								animCps.get(i).getPosition().x -= x1 / animSteps;
-								animCps.get(i).getPosition().y -= y1 / animSteps;
-							}
-							repaint();
-							animDuration -= animDelay;
-							animSteps--;
-						} else {
-							animDuration = ANIMTIME;
-							animSteps = animDuration / animDelay;
-							animT.stop();
-							for (int i = 0; i < animCps.size(); i++) {
-								animCps.get(i).getPosition().x = savePos.get(i).x;
-								animCps.get(i).getPosition().y = savePos.get(i).y;
-							}
-
-							controller.calculateStateForCurrentTimeStep();
-							repaint();
-						}
-					}
-				});
-				animT.start();
-			}
-		});
-
-		itemTrack.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				for (AbstractCpsObject o : model.getSelectedCpsObjects()) {
-					if (o instanceof HolonObject) {
-						boolean found = false;
-						if (controller.getTrackingObj() != null) {
-							for (AbstractCpsObject obj : controller.getTrackingObj()) {
-								if (obj instanceof HolonObject) {
-									if (obj.getId() == o.getId()) {
-										found = true;
-									}
-								}
-							}
-						}
-						if (!found) {
-							controller.addTrackingObj((HolonObject) o);
-							((HolonObject) o).updateTrackingInfo();
-						}
-						if (model.getShowConsoleLog()) {
-							controller.addTextToConsole("Tracking: ", Color.BLACK, 12, false, false, false);
-							controller.addTextToConsole("" + o.getName(), Color.BLUE, 12, true, false, false);
-							controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
-							controller.addTextToConsole("" + o.getId(), Color.RED, 12, true, false, true);
-						}
-					}
-				}
-			}
-		});
-
-		itemUntrack.addActionListener(new ActionListener() {
-
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				for (AbstractCpsObject o : model.getSelectedCpsObjects()) {
-					if (o instanceof HolonObject) {
-						boolean found = false;
-						if (controller.getTrackingObj() != null) {
-							for (AbstractCpsObject obj : controller.getTrackingObj()) {
-								if (obj instanceof HolonObject) {
-									if (obj.getId() == o.getId()) {
-										found = true;
-									}
-								}
-							}
-						}
-						if (found) {
-							// Removed from tracking array and tracking
-							// information reseted
-							controller.removeTrackingObj((HolonObject) o);
-							((HolonObject) o).setTrackingProd(new float[100]);
-							((HolonObject) o).setTrackingCons(new float[100]);
-						}
-					}
-				}
-				System.out.println(controller.getTrackingObj());
-			}
-		});
-
-		itemDelete.addActionListener(new ActionListener() {
-
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				// Remove the selected Object objects
-				for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
-					if (upperNode.getNodes().contains(cps)) {
-						controller.delObjUpperNode(cps, upperNode);
-						// Removes the object from the tracked objects, in case
-						// it was tracked
-						controller.removeTrackingObj(cps);
-						// Remove UpperNodeTab if UpperNode deleted
-						if (cps instanceof CpsUpperNode) {
-							boolean splitView = false;
-							JSplitPane tempSplit = (JSplitPane) getParent().getParent().getParent().getParent();
-							JTabbedPane tabbedPane;
-							JTabbedPane tabbedPane2;
-							// if SplitView is activated
-							if (tempSplit.getLeftComponent() instanceof JTabbedPane
-									&& tempSplit.getRightComponent() instanceof JTabbedPane) {
-								splitView = true;
-								tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
-								tabbedPane2 = (JTabbedPane) tempSplit.getRightComponent();
-							} else {
-								tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
-								tabbedPane2 = null;
-							}
-							// Look if the uppernode is open in a Tab
-							for (int i = 4; i < tabbedPane.getTabCount(); i++) {
-								if (tabbedPane.getComponentAt(i) == null) {
-								} else if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
-										.getComponent(0)).upperNode.getId() == cps.getId()) {
-									((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
-									break;
-								}
-							}
-							// If SplitView is on and the view on
-							// tabbedPane2 is the deleted upperNode
-							try {
-								if (tabbedPane2 != null
-										&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
-												.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
-									((ButtonTabComponent) tabbedPane.getTabComponentAt(tabbedPane2.getSelectedIndex()))
-											.removeTabs();
-								}
-							} catch (Exception e2) {
-							}
-
-						}
-					}
-				}
-				toolTip = false;
-				model.getSelectedCpsObjects().clear();
-				tempCps = null;
-				repaint();
-			}
-		});
-
-		itemCut.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				controller.cut(upperNode);
-				itemPaste.setEnabled(true);
-				repaint();
-			}
-		});
-
-		itemCopy.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				controller.copy(upperNode);
-				itemPaste.setEnabled(true);
-				repaint();
-			}
-		});
-
-		itemPaste.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				try {
-					controller.paste(upperNode, mousePosition);
-					unitGraph.update(model.getSelectedCpsObjects());
-				} catch (JsonParseException | UnsupportedFlavorException | IOException e1) {
-					// TODO Auto-generated catch block
-					JLabel message = new JLabel("The Clipboard information cannot be pastet into Application.");
-					JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
-				}
-				repaint();
-			}
-		});
-
-		this.addMouseListener(this);
-		this.addMouseMotionListener(this);
-	}
-
-	/**
-	 * Paints all Components on the Canvas.
-	 * 
-	 * @param g
-	 *            Graphics
-	 */
-	public void paintComponent(Graphics g) {
-		String maxCap;
-		super.paintComponent(g);
-		((JScrollPane) this.getParent().getParent()).setColumnHeaderView(breadCrumb);
-		// Rendering
-		g2 = (Graphics2D) g;
-		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-		g2.setRenderingHints(rh);
-
-		// Paint the Background
-		if (!upperNode.getImagePath().isEmpty()) {
-			img = new ImageIcon(upperNode.getImagePath()).getImage();
-			switch (upperNode.getBackgroundMode()) {
-			case BackgroundPopUp.IMAGE_PIXELS:
-				g2.drawImage(img, upperNode.getLeftBorder(), 0, img.getWidth(null), img.getHeight(null), null);
-				break;
-			case BackgroundPopUp.STRETCHED:
-				g2.drawImage(img, upperNode.getLeftBorder(), 0, model.getCanvasX(), model.getCanvasY(), null);
-				break;
-			case BackgroundPopUp.CUSTOM:
-				g2.drawImage(img, upperNode.getLeftBorder(), 0, upperNode.getImageWidht(), upperNode.getImageHeight(),
-						null);
-				break;
-			default:
-				break;
-			}
-		}
-
-		// Draw Left Border
-		g2.setColor(new Color(230, 230, 230));
-		g2.fillRect(0, 0, upperNode.getLeftBorder(), this.getHeight());
-		g2.setColor(Color.BLACK);
-		g2.drawLine(0, 0, this.getWidth(), 0);
-
-		// Test SubNet Coloring
-		int i = 0;
-		for (SubNet s : controller.getSimManager().getSubNets()) {
-
-			if (model.getSubNetColors().size() - 1 < i) {
-				controller.addSubNetColor(new Color((int) (Math.random() * 255), (int) (Math.random() * 255),
-						(int) (Math.random() * 255)));
-			}
-
-			for (HolonObject cps : s.getObjects()) {
-				cps.setBorderColor(model.getSubNetColors().get(i));
-			}
-			i++;
-		}
-
-		// drawEdges that is being dragged
-		if (drawEdge) {
-			g2.setColor(Color.BLACK);
-			g2.setStroke(new BasicStroke(2));
-
-			// If TempCps is an outside Object
-			if (!upperNode.getNodes().contains(tempCps)) {
-				int count = 0;
-				for (CpsEdge e : upperNode.getConnections()) {
-					if (e.getA().equals(tempCps)) {
-						g2.drawLine(upperNode.getLeftBorder() >> 1, (int) (model.getScaleDiv2() + scalediv20 + 5
-								+ (model.getScale() + scalediv20 + 10) * count), x, y);
-					} else if (e.getB().equals(tempCps)) {
-						g2.drawLine(upperNode.getLeftBorder() >> 1, (int) (model.getScaleDiv2() + scalediv20 + 5
-								+ (model.getScale() + scalediv20 + 10) * count), x, y);
-					}
-					count++;
-				}
-			} else {
-				g2.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
-			}
-		}
-		// draw Edges
-		for (CpsEdge con : upperNode.getNodeEdges()) {
-			if (con.getA().getId() != model.getSelectedObjectID() && con.getB().getId() != model.getSelectedObjectID()
-					&& con != edgeHighlight) {
-				if (con.getConnected() == 0) {
-					if (con.getState()) {
-						g2.setColor(Color.GREEN);
-						if (con.getCapacity() != -1) {
-							g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
-						}
-					} else {
-						g2.setColor(Color.RED);
-						g2.setStroke(new BasicStroke(2));
-					}
-				} else {
-					g2.setColor(Color.DARK_GRAY);
-					g2.setStroke(new BasicStroke(2));
-				}
-				g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
-						con.getB().getPosition().y);
-
-				if (con.getCapacity() == -1) {
-					maxCap = Character.toString('\u221e');
-				} else if (con.getCapacity() == -2) {
-					maxCap = "???";
-				} else {
-					maxCap = String.valueOf(con.getCapacity());
-				}
-				if (showedInformation[0]) {
-					if (con.getConnected() == 0 || con.getConnected() == 1) {
-						g2.drawString(con.getFlow() + "/" + maxCap,
-								(con.getA().getPosition().x + con.getB().getPosition().x) / 2,
-								(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
-					} else {
-						g2.drawString("not connected", (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
-								(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
-					}
-				}
-			}
-		}
-
-		// Objects connected to upperNode
-		int count = 0;
-		for (CpsEdge e : upperNode.getConnections()) {
-			AbstractCpsObject cps;
-			if (e.getA().equals(this.upperNode)) {
-				cps = e.getB();
-			} else {
-				cps = e.getA();
-			}
-			// Show and Highlight
-			if (model.getSelectedCpsObjects().contains(cps) || showedInformation[4] == true) {
-				for (CpsEdge ed : cps.getConnections()) {
-					AbstractCpsObject obj = null;
-					if (upperNode.getNodes().contains(ed.getA())) {
-						obj = ed.getA();
-					} else if (upperNode.getNodes().contains(ed.getB())) {
-						obj = ed.getB();
-					}
-					if (obj != null) {
-						if (ed.getConnected() == 0) {
-							if (ed.getState()) {
-								g2.setColor(Color.GREEN);
-								if (ed.getCapacity() != -1) {
-									g2.setStroke(
-											new BasicStroke(Math.min(((ed.getFlow() / ed.getCapacity() * 3) + 1), 4)));
-								}
-							} else {
-								g2.setColor(Color.RED);
-								g2.setStroke(new BasicStroke(2));
-							}
-							if (ed.getA().getId() == model.getSelectedObjectID()
-									|| ed.getB().getId() == model.getSelectedObjectID() || edgeHighlight == ed)
-								g2.setColor(Color.BLUE);
-						} else {
-							g2.setColor(Color.DARK_GRAY);
-							g2.setStroke(new BasicStroke(2));
-						}
-						g2.drawLine(obj.getPosition().x, obj.getPosition().y, (upperNode.getLeftBorder() >> 1),
-								(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + 25);
-						if (showedInformation[0]) {
-							if (ed.getCapacity() == -1) {
-								maxCap = Character.toString('\u221e');
-							} else if (ed.getCapacity() == -2) {
-								maxCap = "???";
-							} else {
-								maxCap = String.valueOf(ed.getCapacity());
-							}
-							if (ed.getConnected() == 0 || ed.getConnected() == 1) {
-								g2.drawString(ed.getFlow() + "/" + maxCap,
-										(obj.getPosition().x + (upperNode.getLeftBorder() >> 1)) / 2,
-										(obj.getPosition().y + (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count)
-												+ 25) / 2);
-							} else {
-								g2.drawString("not connected",
-										(obj.getPosition().x + (upperNode.getLeftBorder() >> 1)) / 2,
-										(obj.getPosition().y + (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count)
-												+ 25) / 2);
-							}
-						}
-					}
-				}
-			}
-
-			// Border Highlighting
-			if (showedInformation[3]) {
-				g2.setColor(cps.getBorderColor());
-				if (g2.getColor() != Color.WHITE) {
-					g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20) - 3,
-							(int) (scalediv20 + 5 + (25 + scalediv20 + 10) * count - scalediv20) - 3,
-							(int) (50 + ((scalediv20 + 3) * 2)), (int) (50 + ((scalediv20 + 3) * 2)));
-				}
-			}
-
-			// node image
-			if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
-					|| model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
-				img = new ImageIcon(this.getClass().getResource("/Images/node_selected.png")).getImage();
-			} else {
-				if (cps instanceof HolonSwitch) {
-					if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
-						((HolonSwitch) cps).setAutoState(true);
-					} else {
-						((HolonSwitch) cps).setAutoState(false);
-					}
-				}
-				// Highlighting
-				if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
-						|| model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
-					g2.setColor(Color.BLUE);
-					g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
-							(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
-							(int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
-				} else if (cps instanceof HolonObject) {
-					g2.setColor(((HolonObject) cps).getColor());
-
-					g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
-							(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
-							(int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
-				}
-				// draw image
-				File checkPath = new File(cps.getImage());
-				if (checkPath.exists()) {
-					img = new ImageIcon(cps.getImage()).getImage();
-				} else {
-					img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
-				}
-			}
-			g2.drawImage(img, (upperNode.getLeftBorder() >> 1) - 25,
-					(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count), 50, 50, null);
-			count++;
-		}
-		// Highlighted Edge
-		if (model.getSelectedObjectID() > 0 || !model.getSelectedCpsObjects().isEmpty() || !tempSelected.isEmpty()) {
-			g2.setColor(Color.BLUE);
-			for (CpsEdge con : upperNode.getNodeEdges()) {
-				if (con.getFlow() <= con.getCapacity()) {
-					g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 3) + 1, 4)));
-				} else {
-					g2.setStroke(new BasicStroke(2));
-				}
-				if (con.getA().getId() == model.getSelectedObjectID()
-						|| model.getSelectedCpsObjects().contains(con.getA()) || tempSelected.contains(con.getA())
-						|| con.getB().getId() == model.getSelectedObjectID()
-						|| model.getSelectedCpsObjects().contains(con.getB())
-						|| tempSelected.contains(con.getB()) && con != edgeHighlight) {
-					g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
-							con.getB().getPosition().y);
-
-					if (con.getCapacity() == -1) {
-						maxCap = Character.toString('\u221e');
-					} else if (con.getCapacity() == -2) {
-						maxCap = "???";
-					} else {
-						maxCap = String.valueOf(con.getCapacity());
-					}
-					if (showedInformation[0]) {
-						if (con.getConnected() == 0 || con.getConnected() == 1) {
-							g2.drawString(con.getFlow() + "/" + maxCap,
-									(con.getA().getPosition().x + con.getB().getPosition().x) / 2,
-									(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
-						} else {
-							g2.drawString("not connected",
-									(con.getA().getPosition().x + con.getB().getPosition().x) / 2,
-									(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
-						}
-					}
-				}
-			}
-		} else if (edgeHighlight != null) {
-			g2.setColor(Color.BLUE);
-			if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
-				g2.setStroke(
-						new BasicStroke(Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3) + 1, 4)));
-			} else {
-				g2.setStroke(new BasicStroke(2));
-			}
-			if (upperNode.getNodeEdges().contains(edgeHighlight)) {
-				g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight.getA().getPosition().y,
-						edgeHighlight.getB().getPosition().x, edgeHighlight.getB().getPosition().y);
-
-				if (edgeHighlight.getCapacity() == -1) {
-					maxCap = Character.toString('\u221e');
-				} else if (edgeHighlight.getCapacity() == -2) {
-					maxCap = "???";
-				} else {
-					maxCap = String.valueOf(edgeHighlight.getCapacity());
-				}
-				if (showedInformation[0]) {
-					g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
-							(edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2,
-							(edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2);
-				}
-			}
-		}
-
-		// Objects in upper node
-		for (AbstractCpsObject cps : upperNode.getNodes()) {
-			// Border Highlighting
-			if (showedInformation[3]) {
-				g2.setColor(cps.getBorderColor());
-				if (g2.getColor() != Color.WHITE) {
-					g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20 - 3),
-							(int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20 - 3),
-							(int) (controller.getScale() + ((scalediv20 + 3) * 2)),
-							(int) (controller.getScale() + ((scalediv20 + 3) * 2)));
-				}
-			}
-
-			// node image
-			if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
-					|| model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
-				img = new ImageIcon(this.getClass().getResource("/Images/node_selected.png")).getImage();
-			} else {
-				if (cps instanceof HolonSwitch) {
-					if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
-						((HolonSwitch) cps).setAutoState(true);
-					} else {
-						((HolonSwitch) cps).setAutoState(false);
-					}
-				}
-				// Highlighting
-				if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
-						|| model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
-					g2.setColor(Color.BLUE);
-					g2.fillRect((int) (cps.getPosition().x - model.getScaleDiv2() - scalediv20),
-							(int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20),
-							(int) (controller.getScale() + (scalediv20 * 2)),
-							(int) (controller.getScale() + (scalediv20 * 2)));
-					if (showedInformation[1] && cps instanceof HolonObject) {
-						g2.setColor(Color.BLACK);
-						float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
-						g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - model.getScaleDiv2(),
-								cps.getPosition().y - model.getScaleDiv2() - 10);
-					}
-				} else if (cps instanceof HolonObject) {
-					g2.setColor(((HolonObject) cps).getColor());
-
-					g2.fillRect((int) (cps.getPosition().x - model.getScaleDiv2() - scalediv20),
-							(int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20),
-							(int) (controller.getScale() + (scalediv20 * 2)),
-							(int) (controller.getScale() + (scalediv20 * 2)));
-
-					if (showedInformation[1]) {
-						g2.setColor(Color.BLACK);
-						float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
-						g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - model.getScaleDiv2(),
-								cps.getPosition().y - model.getScaleDiv2() - 10);
-					}
-				}
-				// draw image
-				File checkPath = new File(cps.getImage());
-				if (checkPath.exists()) {
-					img = new ImageIcon(cps.getImage()).getImage();
-				} else {
-					img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
-				}
-			}
-			g2.drawImage(img, cps.getPosition().x - model.getScaleDiv2(), cps.getPosition().y - model.getScaleDiv2(),
-					controller.getScale(), controller.getScale(), null);
-		}
-
-		// Dragg Highlighting
-		g2.setStroke(new BasicStroke(1));
-		if (doMark) {
-			g2.setColor(Color.BLACK);
-			if (sx > x && sy > y) {
-				g2.drawRect(x, y, sx - x, sy - y);
-			} else if (sx < x && sy < y) {
-				g2.drawRect(sx, sy, x - sx, y - sy);
-			} else if (sx >= x) {
-				g2.drawRect(x, sy, sx - x, y - sy);
-			} else if (sy >= y) {
-				g2.drawRect(sx, y, x - sx, sy - y);
-			}
-		}
-
-		// Border Line
-		g2.setColor(Color.BLACK);
-		g2.drawLine(upperNode.getLeftBorder(), 0, upperNode.getLeftBorder(), this.getHeight());
-
-		// Tooltip
-		if (toolTip) {
-			g2.setColor(new Color(255, 225, 150));
-			g2.setStroke(new BasicStroke(1));
-			int textWidth = g.getFontMetrics().stringWidth(toolTipText) + 2; // Text
-																				// width
-			int fixXPos = toolTipPos.x - (textWidth >> 1) + model.getScaleDiv2(); // Position
-																					// fixed
-																					// x
-																					// Position
-																					// to
-																					// the
-																					// screen
-			int fixYPos = toolTipPos.y; //// Position fixed y Position to the
-										//// screen
-			if (fixXPos < 0) {
-				fixXPos = 0;
-			} else if (fixXPos + textWidth + 1 > this.getWidth()) {
-				fixXPos -= (fixXPos + textWidth + 1) - this.getWidth();
-			}
-			if (fixYPos + 16 > this.getHeight()) {
-				fixYPos -= (fixYPos + 16) - this.getHeight();
-			}
-			g2.fillRect(fixXPos, fixYPos, textWidth, 15);
-			g2.setColor(Color.BLACK);
-			g2.drawRect(fixXPos, fixYPos, textWidth, 15);
-			g2.drawString(toolTipText, fixXPos + 2, fixYPos + 12);
-		}
-	}
-
-	@Override
-	public void mouseClicked(MouseEvent e) {
-		updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
-	}
-
-	@Override
-	public void mouseEntered(MouseEvent e) {
-	}
-
-	@Override
-	public void mouseExited(MouseEvent e) {
-	}
-
-	@Override
-	public void mousePressed(MouseEvent e) {
-		tempCps = null;
-		dataSelected = null;
-		edgeHighlight = null;
-		controller.setSelecteEdge(null);
-		controller.setSelectedObjectID(-1);
-		// Object Selection
-
-		// Erase old data in the PropertyTable
-		if (model.getPropertyTable().getRowCount() > 0) {
-			for (int i = model.getPropertyTable().getRowCount() - 1; i > -1; i--) {
-				model.getPropertyTable().removeRow(i);
-			}
-		}
-
-		if (e.getX() > upperNode.getLeftBorder()) {
-			for (AbstractCpsObject cps : upperNode.getNodes()) {
-				cx = cps.getPosition().x - model.getScaleDiv2();
-				cy = cps.getPosition().y - model.getScaleDiv2();
-				if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
-					tempCps = cps;
-					if (model.getShowConsoleLog()) {
-						controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
-						controller.addTextToConsole("" + cps.getName(), Color.BLUE, 12, true, false, false);
-						controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
-						controller.addTextToConsole("" + cps.getId(), Color.RED, 12, true, false, true);
-					}
-					dragging = true;
-					if (e.isControlDown() && tempCps != null) {
-						if (model.getSelectedCpsObjects().contains(tempCps)) {
-							controller.deleteSelectedObject(tempCps);
-						} else {
-							controller.addSelectedObject(tempCps);
-						}
-					}
-
-					// If drawing an Edge (CTRL down)
-					if (tempCps.getClass() == HolonObject.class) {
-						HolonObject tempObj = ((HolonObject) tempCps);
-						dataSelected = tempObj.getElements();
-					}
-					if (e.isShiftDown()) {
-						drawEdge = true;
-						dragging = false;
-					}
-					break;
-				}
-			}
-		} else {
-			// look for objects connected to uppernode
-			int count = 0;
-			for (CpsEdge ed : upperNode.getConnections()) {
-				AbstractCpsObject cps;
-				if (ed.getA().equals(this.upperNode)) {
-					cps = ed.getB();
-				} else {
-					cps = ed.getA();
-				}
-				if (x - controller.getScale() <= ((upperNode.getLeftBorder() >> 1) - model.getScaleDiv2())
-						&& y - controller.getScale() <= (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)
-						&& x >= (upperNode.getLeftBorder() >> 1) - model.getScaleDiv2()
-						&& y >= (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)) {
-					tempCps = cps;
-					if (model.getShowConsoleLog()) {
-						controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
-						controller.addTextToConsole("" + cps.getName(), Color.BLUE, 12, true, false, false);
-						controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
-						controller.addTextToConsole("" + cps.getId(), Color.RED, 12, true, false, true);
-						controller.setSelectedObjectID(tempCps.getId());
-					}
-					// If drawing an Edge (CTRL down)
-					if (tempCps.getClass() == HolonObject.class) {
-						HolonObject tempObj = ((HolonObject) tempCps);
-						dataSelected = tempObj.getElements();
-					}
-					if (e.isShiftDown()) {
-						drawEdge = true;
-					}
-				}
-				count++;
-			}
-		}
-
-		// Selection of CpsObject
-		// model.setSelectedCpsObject(tempCps);
-
-		// Edge Selection
-		if (e.getButton() == e.BUTTON1) {
-			if (tempCps == null) {
-				edgeHighlight = mousePositionOnEdge(x, y);
-				controller.setSelecteEdge(edgeHighlight);
-				controller.setSelectedObjectID(0);
-				if (!e.isControlDown() && e.getButton() != MouseEvent.BUTTON3) {
-					model.getSelectedCpsObjects().clear();
-				}
-				updCon.deleteRows(model.getMultiTable());
-				updCon.deleteRows(model.getSingleTable());
-			}
-
-			if (edgeHighlight == null && tempCps == null) {
-				sx = e.getX();
-				sy = e.getY();
-				doMark = true;
-			}
-			// System.out.println("Selected Objects");
-			// for (AbstractCpsObject temp : model.getSelectedCpsObjects()) {
-			// System.out.println(temp.getName() + " " + temp.getID());
-			// }
-			repaint();
-		}
-	}
-
-	@Override
-	public void mouseReleased(MouseEvent e) {
-		x = e.getX();
-		y = e.getY();
-		dragging = false;
-		if (model.getSelectedCpsObjects().size() > 1) {
-			model.getTableHolonElement().setModel(model.getMultiTable());
-		} else if (model.getSelectedCpsObjects().size() == 1) {
-			model.getTableHolonElement().setModel(model.getSingleTable());
-		}
-
-		if (drawEdge) {
-			drawEdge = false;
-			drawDeleteEdge();
-		}
-
-		if (dragged == true) {
-			try {
-				controller.autoSave();
-			} catch (IOException ex) {
-				// TODO Auto-generated catch block
-				ex.printStackTrace();
-			}
-		}
-
-		if (!e.isControlDown() && dragged == false && tempCps != null && MouseEvent.BUTTON3 != e.getButton()) {
-			model.getSelectedCpsObjects().clear();
-			controller.addSelectedObject(tempCps);
-		}
-
-		dragged = false;
-
-		// Rightclick List
-		if (e.getButton() == MouseEvent.BUTTON3) {
-			if (tempCps != null) {
-				itemDelete.setEnabled(true);
-				itemCut.setEnabled(true);
-				itemCopy.setEnabled(true);
-				if (tempCps != null) {
-					itemGroup.setEnabled(true);
-					itemTrack.setEnabled(true);
-					itemUntrack.setEnabled(true);
-				}
-				if (tempCps instanceof CpsUpperNode)
-					itemUngroup.setEnabled(true);
-				else
-					itemUngroup.setEnabled(false);
-				if (model.getSelectedCpsObjects().size() == 0) {
-					controller.addSelectedObject(tempCps);
-				}
-			} else {
-				itemCut.setEnabled(false);
-				itemCopy.setEnabled(false);
-				itemDelete.setEnabled(false);
-				itemGroup.setEnabled(false);
-				itemUngroup.setEnabled(false);
-				itemTrack.setEnabled(false);
-				itemUntrack.setEnabled(false);
-			}
-			mousePosition = this.getMousePosition();
-			popmenu.show(e.getComponent(), e.getX(), e.getY());
-		}
-
-		if (doMark) {
-			doMark = false;
-			for (AbstractCpsObject cps : tempSelected) {
-				if (!model.getSelectedCpsObjects().contains(cps)) {
-					controller.addSelectedObject(cps);
-				}
-			}
-			controller.getObjectsInDepth();
-			tempSelected.clear();
-		}
-
-		if (doubleClick() && tempCps != null && tempCps instanceof HolonSwitch) {
-			((HolonSwitch) tempCps).switchState();
-		}
-
-		controller.calculateStateForTimeStep(model.getCurIteration());
-		updCon.paintProperties(tempCps);
-		updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
-		updCon.refreshTableProperties(model.getPropertyTable());
-		repaint();
-
-	}
-
-	@Override
-	public void mouseDragged(MouseEvent e) {
-		// If Edge is drawn
-		x = e.getX();
-		y = e.getY();
-		if (!model.getSelectedCpsObjects().contains(tempCps) && doMark == false) {
-			model.getSelectedCpsObjects().clear();
-			if (tempCps != null) {
-				controller.addSelectedObject(tempCps);
-			}
-		}
-		if (dragging) {
-			try {
-				// tempCps in the upperNode? else its a connected Object from
-				// outside
-				if (upperNode.getNodes().contains(tempCps)) {
-					dragged = true;
-					float xDist, yDist; // Distance
-
-					x = e.getX();
-					y = e.getY();
-
-					// Make sure its in bounds
-					if (e.getX() < controller.getScaleDiv2() + upperNode.getLeftBorder() + 5)
-						x = controller.getScaleDiv2() + upperNode.getLeftBorder() + 5;
-					else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
-						x = this.getWidth() - controller.getScaleDiv2();
-					if (e.getY() < controller.getScaleDiv2())
-						y = controller.getScaleDiv2();
-					else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
-						y = this.getHeight() - controller.getScaleDiv2();
-
-					// Distance
-					xDist = x - tempCps.getPosition().x;
-					yDist = y - tempCps.getPosition().y;
-
-					tempCps.setPosition(x, y); // Drag Position
-
-					// TipText Position and name
-					toolTip = true;
-					toolTipText = tempCps.getName() + ", " + tempCps.getId();
-					toolTipPos.x = tempCps.getPosition().x - model.getScaleDiv2();
-					toolTipPos.y = tempCps.getPosition().y + model.getScaleDiv2();
-
-					// All Selected Objects
-					for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
-						if (cps != tempCps) {
-							x = (int) (cps.getPosition().x + xDist);
-							y = (int) (cps.getPosition().y + yDist);
-
-							// Make sure its in bounds
-							if (x < upperNode.getLeftBorder() + 5 + controller.getScaleDiv2())
-								x = controller.getScaleDiv2() + upperNode.getLeftBorder() + 5;
-							else if (x > this.getWidth() - controller.getScaleDiv2())
-								x = this.getWidth() - controller.getScaleDiv2();
-							if (y <= controller.getScaleDiv2())
-								y = controller.getScaleDiv2();
-							else if (y > this.getHeight() - controller.getScaleDiv2())
-								y = this.getHeight() - controller.getScaleDiv2();
-
-							cps.setPosition(x, y);
-						}
-					}
-				}
-				repaint();
-			} catch (Exception eex) {
-
-			}
-		}
-
-		// Mark Objects
-		if (doMark) {
-			tempSelected.clear();
-			for (AbstractCpsObject cps : upperNode.getNodes()) {
-				int x1 = sx, x2 = x, y1 = sy, y2 = y;
-
-				if (sx >= x) {
-					x1 = x;
-					x2 = sx;
-				}
-				if (sy >= y) {
-					y1 = y;
-					y2 = sy;
-				}
-				if (x1 <= cps.getPosition().x + model.getScaleDiv2() && y1 <= cps.getPosition().y + model.getScaleDiv2()
-						&& x2 >= cps.getPosition().x && y2 >= cps.getPosition().y) {
-					tempSelected.add(cps);
-
-				}
-			}
-			int count = 0;
-			for (CpsEdge ed : upperNode.getConnections()) {
-				AbstractCpsObject cps = null;
-				if (ed.getA().equals(upperNode)) {
-					cps = ed.getB();
-				} else {
-					cps = ed.getA();
-				}
-
-				int x1 = sx, x2 = x, y1 = sy, y2 = y;
-
-				if (sx >= x) {
-					x1 = x;
-					x2 = sx;
-				}
-				if (sy >= y) {
-					y1 = y;
-					y2 = sy;
-				}
-
-				if (x1 <= upperNode.getLeftBorder() >> 1
-						&& y1 <= (int) (5 + (model.getScale() + scalediv20 + 10) * count) + model.getScaleDiv2()
-						&& x2 >= upperNode.getLeftBorder() >> 1
-						&& y2 >= (int) (5 + (model.getScale() + scalediv20 + 10) * count)) {
-					tempSelected.add(cps);
-
-				}
-				count++;
-			}
-		}
-
-		repaint();
-
-	}
-
-	@Override
-	public void mouseMoved(MouseEvent e) {
-		x = e.getX();
-		y = e.getY();
-
-		// Everytghing for the tooltip :)
-		boolean on = false;
-		for (AbstractCpsObject cps : upperNode.getNodes()) {
-
-			cx = cps.getPosition().x - controller.getScaleDiv2();
-			cy = cps.getPosition().y - controller.getScaleDiv2();
-			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
-				on = true;
-				toolTipPos.x = cps.getPosition().x - model.getScaleDiv2();
-				toolTipPos.y = cps.getPosition().y + model.getScaleDiv2();
-				toolTipText = cps.getName() + ", " + cps.getId();
-			}
-		}
-		int count = 0;
-		for (CpsEdge ed : upperNode.getConnections()) {
-
-			AbstractCpsObject cps;
-			if (ed.getA().equals(this.upperNode)) {
-				cps = ed.getB();
-			} else {
-				cps = ed.getA();
-			}
-
-			cx = upperNode.getLeftBorder() >> 1;
-			cy = (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count);
-			if (x - 50 <= cx && y - 50 <= cy && x >= cx && y >= cy) {
-
-				on = true;
-				toolTipPos.x = cx - 25;
-				toolTipPos.y = cy + 50;
-				toolTipText = cps.getName() + ", " + cps.getId();
-
-			}
-			count++;
-		}
-
-		if (on) {
-			toolTip = true;
-		} else {
-			toolTip = false;
-		}
-		repaint();
-	}
-
-	/**
-	 * Draws or Deletes an Edge.
-	 */
-	private void drawDeleteEdge() {
-		boolean node = true; // new node?
-		boolean newEdge = true;
-		boolean onEdge = true;
-		boolean deleteNode = false;
-		boolean outsideCon = !upperNode.getNodes().contains(tempCps); // Connection
-																		// to
-																		// the
-																		// outside
-		boolean found = false; // dont search for outside connetion if inside
-								// connection is found
-		CpsEdge e = null;
-		for (AbstractCpsObject cps : upperNode.getNodes()) {
-
-			cx = cps.getPosition().x - controller.getScaleDiv2();
-			cy = cps.getPosition().y - controller.getScaleDiv2();
-
-			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy
-					&& cps != tempCps) {
-				found = true;
-				node = false;
-				onEdge = false;
-				for (CpsEdge p : tempCps.getConnections()) {
-					if ((p.getA() == tempCps && p.getB() == cps) || (p.getB() == tempCps && p.getA() == cps)) {
-						newEdge = false;
-						e = p;
-					}
-				}
-				if (!newEdge) {
-					if (outsideCon) {
-						controller.disconnectNodes(e, upperNode);
-					} else {
-						controller.delEdgeUpperNode(e, upperNode);
-					}
-					// Node ohne Edge?
-					if (e.getA().getClass() == CpsNode.class && e.getA().getConnections().isEmpty()) {
-						tempCps = e.getA();
-						deleteNode = true;
-					}
-					if (e.getB().getClass() == CpsNode.class && e.getB().getConnections().isEmpty()) {
-						deleteNode = true;
-					}
-				}
-				if (newEdge) {
-					e = new CpsEdge(cps, tempCps, model.getMaxCapacity());
-					if (outsideCon) {
-						controller.connectNodes(e, upperNode);
-					} else {
-						controller.addEdgeUpperNode(e, upperNode);
-					}
-				}
-			}
-		}
-		if (!found && !outsideCon) {
-			int count = 0;
-			for (CpsEdge ed : upperNode.getConnections()) {
-				AbstractCpsObject cps = null;
-				if (ed.getA().equals(upperNode)) {
-					cps = ed.getB();
-				} else {
-					cps = ed.getA();
-				}
-
-				cx = upperNode.getLeftBorder() >> 1;
-				cy = (int) (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count);
-
-				if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy
-						&& cps != tempCps) {
-					outsideCon = true;
-					node = false;
-					onEdge = false;
-					for (CpsEdge p : tempCps.getConnections()) {
-						if ((p.getA() == tempCps && p.getB() == cps) || (p.getB() == tempCps && p.getA() == cps)) {
-							newEdge = false;
-							e = p;
-						}
-					}
-					if (!newEdge) {
-						if (outsideCon) {
-							controller.disconnectNodes(e, upperNode);
-						} else {
-							controller.delEdgeUpperNode(e, upperNode);
-						}
-						// Node ohne Edge?
-						if (e.getA().getClass() == CpsNode.class && e.getA().getConnections().isEmpty()) {
-							tempCps = e.getA();
-							deleteNode = true;
-						}
-						if (e.getB().getClass() == CpsNode.class && e.getB().getConnections().isEmpty()) {
-							deleteNode = true;
-						}
-					}
-					if (newEdge) {
-						CpsEdge edge = new CpsEdge(cps, tempCps, model.getMaxCapacity());
-						if (outsideCon) {
-							controller.connectNodes(edge, upperNode);
-						} else {
-							controller.addEdgeUpperNode(edge, upperNode);
-						}
-					}
-				}
-				count++;
-			}
-		}
-
-		// Edge auf eine Edge gezogen?
-		if (onEdge) {
-			CpsEdge p = mousePositionOnEdge(x, y);
-			if (p != null) {
-				CpsEdge e1 = null;
-				CpsEdge e2 = null;
-
-				node = false;
-
-				CpsNode n = new CpsNode("Node");
-
-				n.setPosition(x, y);
-				controller.addObjUpperNode(n, upperNode);
-
-				AbstractCpsObject r, k;
-				r = p.getA();
-				k = p.getB();
-
-				e = new CpsEdge(n, tempCps, model.getMaxCapacity());
-
-				e1 = new CpsEdge(n, r, model.getMaxCapacity());
-
-				e2 = new CpsEdge(n, k, model.getMaxCapacity());
-
-				controller.delEdgeUpperNode(p, upperNode);
-				if (outsideCon) {
-					controller.connectNodes(e, upperNode);
-				} else {
-					controller.addEdgeUpperNode(e, upperNode);
-				}
-
-				controller.addEdgeUpperNode(e1, upperNode);
-				controller.addEdgeUpperNode(e2, upperNode);
-			}
-		}
-
-		// ins leere Gedragged
-		if (node && x > upperNode.getLeftBorder()) {
-			CpsNode n = new CpsNode("Node");
-
-			n.setPosition(x, y);
-			controller.addObjUpperNode(n, upperNode);
-
-			e = new CpsEdge(n, tempCps, model.getMaxCapacity());
-
-			if (outsideCon) {
-				controller.connectNodes(e, upperNode);
-			} else {
-				controller.addEdgeUpperNode(e, upperNode);
-			}
-		}
-
-		// Wenn ein Node ohne Connections da ist
-		if (deleteNode) {
-			controller.delCanvasObject(tempCps, true);
-			tempCps = null;
-		}
-	}
-
-	/**
-	 * Checks if the mouse is on an Edge.
-	 * 
-	 * @param x
-	 *            Position of the Mouse
-	 * @param y
-	 *            Position of the Mouse
-	 * 
-	 * @return CpsEdge the Mouse is on, null if the mouse is not on an Edge
-	 */
-	public CpsEdge mousePositionOnEdge(int x, int y) {
-		x += controller.getScaleDiv2();
-		y += controller.getScaleDiv2();
-		int lx, ly, hx, hy;
-		for (CpsEdge p : upperNode.getNodeEdges()) {
-			Line2D l = new Line2D.Float(p.getA().getPosition().x, p.getA().getPosition().y, p.getB().getPosition().x,
-					p.getB().getPosition().y);
-			if (p.getA().getPosition().x > p.getB().getPosition().x) {
-				hx = p.getA().getPosition().x + model.getScaleDiv2() + 7;
-				lx = p.getB().getPosition().x + model.getScaleDiv2() - 7;
-			} else {
-				lx = p.getA().getPosition().x + model.getScaleDiv2() - 7;
-				hx = p.getB().getPosition().x + model.getScaleDiv2() + 7;
-			}
-			if (p.getA().getPosition().y > p.getB().getPosition().y) {
-				hy = p.getA().getPosition().y + model.getScaleDiv2() + 7;
-				ly = p.getB().getPosition().y + model.getScaleDiv2() - 7;
-			} else {
-				ly = p.getA().getPosition().y + model.getScaleDiv2() - 7;
-				hy = p.getB().getPosition().y + model.getScaleDiv2() + 7;
-			}
-
-			// distance from a point to a line and between both Objects
-			if (l.ptLineDistSq(x - model.getScaleDiv2(), y - model.getScaleDiv2()) < 20 && x > lx && x < hx && y > ly
-					&& y < hy) {
-				return p;
-			}
-		}
-
-		// edge to outside connection
-
-		int count = 0;
-		for (CpsEdge e : upperNode.getConnections()) {
-			AbstractCpsObject cps;
-			if (e.getA().equals(this.upperNode)) {
-				cps = e.getB();
-			} else {
-				cps = e.getA();
-			}
-			for (CpsEdge p : cps.getConnections()) {
-				AbstractCpsObject obj = null;
-				boolean doTest = false;
-				if (upperNode.getNodes().contains(p.getA())) {
-					obj = p.getA();
-					doTest = true;
-				} else if (upperNode.getNodes().contains(p.getB())) {
-					obj = p.getB();
-					doTest = true;
-				}
-				// g2.drawImage(img, (borderPos >> 1) - 25, (int) (scalediv20 +
-				// 5 + (50 + scalediv20 + 10) * count), 50, 50, null);
-				if (doTest) {
-					Line2D l = new Line2D.Float((upperNode.getLeftBorder() >> 1) - 25,
-							(int) (scalediv20 + 5 + 25 + (50 + scalediv20 + 10) * count), obj.getPosition().x,
-							obj.getPosition().y);
-					if ((upperNode.getLeftBorder() >> 1) > obj.getPosition().x) {
-						hx = (upperNode.getLeftBorder() >> 1) - 25 + model.getScaleDiv2() + 7;
-						lx = obj.getPosition().x + model.getScaleDiv2() - 7;
-					} else {
-						lx = (upperNode.getLeftBorder() >> 1) - 25 + model.getScaleDiv2() - 7;
-						hx = obj.getPosition().x + model.getScaleDiv2() + 7;
-					}
-					if ((int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) > obj.getPosition().y) {
-						hy = (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + model.getScaleDiv2() + 7;
-						ly = obj.getPosition().y + model.getScaleDiv2() - 7;
-					} else {
-						ly = (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + model.getScaleDiv2() - 7;
-						hy = obj.getPosition().y + model.getScaleDiv2() + 7;
-					}
-
-					// distance from a point to a line and between both Objects
-					if (l.ptLineDistSq(x - model.getScaleDiv2(), y - model.getScaleDiv2()) < 20 && x > lx && x < hx
-							&& y > ly && y < hy) {
-						return p;
-					}
-				}
-			}
-			count++;
-		}
-		return null;
-	}
-
-	/**
-	 * Checks if a double click was made.
-	 * 
-	 * @return true if doublecklick, false if not
-	 */
-	private boolean doubleClick() {
-		if (click) {
-			click = false;
-			return true;
-		} else {
-			click = true;
-			Timer t = new Timer("doubleclickTimer", false);
-			t.schedule(new TimerTask() {
-				@Override
-				public void run() {
-					click = false;
-				}
-			}, 500);
-		}
-		return false;
-	}
-
-	/**
-	 * sets the Edge Capacity.
-	 * 
-	 * @param cap
-	 *            capacity
-	 */
-	public void setEdgeCapacity(float cap) {
-		controller.setMaxCapacity(cap);
-	}
-
-	/**
-	 * Set if Information should be shown.
-	 * 
-	 * @param connection
-	 *            boolean for conecction
-	 * @param object
-	 *            boolean for objects
-	 */
-	public void setShowedInformation(boolean connection, boolean object, boolean nodeOfnode) {
-		showedInformation[0] = connection;
-		showedInformation[1] = object;
-		showedInformation[4] = nodeOfnode;
-	}
-
-	/**
-	 * copies a set of given informations
-	 * 
-	 * @param informations
-	 */
-	public void setShowedInformation(boolean[] informations) {
-		showedInformation = informations;
-	}
-
-	/**
-	 * Returns if Information should be shown.
-	 * 
-	 * @return Array of boolean [0] = connection, [1] = objects
-	 */
-	public boolean[] getShowedInformation() {
-		return showedInformation;
-	}
-
-	/**
-	 * Set the Background Image;
-	 * 
-	 * @param imagePath
-	 *            Image Path
-	 * @param mode
-	 *            Image Mode
-	 * @param width
-	 *            Image custom width
-	 * @param height
-	 *            Image custom height
-	 */
-	public void setBackgroundImage(String imagePath, int mode, int width, int height) {
-		upperNode.setBackgroundImage(imagePath, mode, width, height);
-	}
-
-	/**
-	 * set tooltIp
-	 * 
-	 * @param bool
-	 */
-	public void setToolTip(boolean bool) {
-		this.toolTip = bool;
-	}
-
-	/**
-	 * Set the Mouse Position on the UpperNodeCanvas;
-	 * 
-	 * @param x
-	 * @param y
-	 */
-	public void setXY(int x, int y) {
-		this.x = x;
-		this.y = y;
-	}
+public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, MouseMotionListener {
+
+    private static final long serialVersionUID = 1L;
+    // The UpperNode
+    public CpsUpperNode upperNode;
+    // Path
+    protected String path;
+    protected int code;
+    private JLabel breadCrumb;
+
+
+    /**
+     * Constructor.
+     *
+     * @param mod       the Model
+     * @param control   the Controller
+     * @param unitGraph
+     */
+    public UpperNodeCanvas(Model mod, Control control, UnitGraph unitGraph, CpsUpperNode UpperNode, String parentPath) {
+        toolTip = false;
+
+        this.controller = control;
+        this.model = mod;
+        this.upperNode = UpperNode;
+        this.code = UpperNode.hashCode();
+        this.path = parentPath + upperNode.getName();
+        this.breadCrumb = new JLabel(path);
+        // this.add(breadCrumb);
+        scalediv20 = model.getScale() / 20;
+
+        // Cps objecte aus dem border links schieben
+        upperNode.setLeftBorder((int) (50 + scalediv20 + scalediv20 + 10));
+        for (AbstractCpsObject cps : upperNode.getNodes()) {
+            if (cps.getPosition().x < model.getScaleDiv2() + upperNode.getLeftBorder() + 5) {
+                cps.setPosition(
+                        new Position(upperNode.getLeftBorder() + 5 + model.getScaleDiv2(), cps.getPosition().y));
+            }
+        }
+
+        showedInformation[0] = true;
+        showedInformation[1] = true;
+        showedInformation[4] = true;
+
+        popmenu.add(itemCut);
+        popmenu.add(itemCopy);
+        popmenu.add(itemPaste);
+        popmenu.add(itemDelete);
+        popmenu.addSeparator();
+        popmenu.add(itemGroup);
+        popmenu.add(itemUngroup);
+        popmenu.add(itemTrack);
+        popmenu.add(itemUntrack);
+
+        itemDelete.setEnabled(false);
+        itemCut.setEnabled(false);
+        itemCopy.setEnabled(false);
+        itemPaste.setEnabled(true);
+        itemGroup.setEnabled(false);
+        itemUngroup.setEnabled(false);
+        itemTrack.setEnabled(false);
+        itemUntrack.setEnabled(false);
+        updCon = new UpdateController(model, controller);
+
+        itemGroup.addActionListener(actionEvent -> {
+            // calculate uppernode pos (taken from the controller)
+            unPos = new Position(0, 0);
+            animCps = new ArrayList<>();
+            for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
+                animCps.add(cps); // add to animation Cps ArrayList
+                unPos.x += cps.getPosition().x;
+                unPos.y += cps.getPosition().y;
+            }
+            unPos.x /= animCps.size();
+            unPos.y /= animCps.size();
+
+            // save old Position
+            savePos = new ArrayList<>();
+            for (int i = 0; i < animCps.size(); i++) {
+                savePos.add(new Position(0, 0));
+                savePos.get(i).x = animCps.get(i).getPosition().x;
+                savePos.get(i).y = animCps.get(i).getPosition().y;
+            }
+
+            animT = new javax.swing.Timer(animDelay, actionEvent1 -> {
+                if (animDuration - animDelay > 0 && animCps.size() > 1) {
+                    for (AbstractCpsObject currentAnimCps : animCps) {
+                        double x1 = currentAnimCps.getPosition().x - unPos.x;
+                        double y1 = currentAnimCps.getPosition().y - unPos.y;
+                        currentAnimCps.getPosition().x -= x1 / animSteps;
+                        currentAnimCps.getPosition().y -= y1 / animSteps;
+                    }
+                    repaint();
+                    animDuration -= animDelay;
+                    animSteps--;
+                } else {
+                    animDuration = ANIMTIME;
+                    animSteps = animDuration / animDelay;
+                    animT.stop();
+                    for (int i = 0; i < animCps.size(); i++) {
+                        animCps.get(i).getPosition().x = savePos.get(i).x;
+                        animCps.get(i).getPosition().y = savePos.get(i).y;
+                    }
+                    controller.addUpperNode("NodeOfNode", upperNode, model.getSelectedCpsObjects());
+                    controller.calculateStateForCurrentTimeStep();
+                    repaint();
+                }
+            });
+            animT.start();
+        });
+
+        itemUngroup.addActionListener(actionEvent -> {
+            // save old Position
+            JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
+            for (int i = 4; i < tabbedPane.getTabCount(); i++) {
+                if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
+                        .getComponent(0)).upperNode.getId() == tempCps.getId()) {
+                    tabbedPane.remove(i);
+                    break;
+                }
+            }
+
+            savePos = new ArrayList<>();
+            animCps = ((CpsUpperNode) tempCps).getNodes();
+            controller.delUpperNode((CpsUpperNode) tempCps, upperNode);
+
+            for (int i = 0; i < animCps.size(); i++) {
+                savePos.add(new Position(0, 0));
+                savePos.get(i).x = animCps.get(i).getPosition().x;
+                savePos.get(i).y = animCps.get(i).getPosition().y;
+            }
+            for (AbstractCpsObject cps : animCps) {
+                int x = tempCps.getPosition().x;
+                int y = tempCps.getPosition().y;
+
+                cps.setPosition(new Position(x, y));
+            }
+
+            animT = new javax.swing.Timer(animDelay, actionEvent1 -> {
+                if (animDuration - animDelay >= 0) {
+                    for (int i = 0; i < animCps.size(); i++) {
+                        double x1 = animCps.get(i).getPosition().x - savePos.get(i).x;
+                        double y1 = animCps.get(i).getPosition().y - savePos.get(i).y;
+                        animCps.get(i).getPosition().x -= x1 / animSteps;
+                        animCps.get(i).getPosition().y -= y1 / animSteps;
+                    }
+                    repaint();
+                    animDuration -= animDelay;
+                    animSteps--;
+                } else {
+                    animDuration = ANIMTIME;
+                    animSteps = animDuration / animDelay;
+                    animT.stop();
+                    for (int i = 0; i < animCps.size(); i++) {
+                        animCps.get(i).getPosition().x = savePos.get(i).x;
+                        animCps.get(i).getPosition().y = savePos.get(i).y;
+                    }
+
+                    controller.calculateStateForCurrentTimeStep();
+                    repaint();
+                }
+            });
+            animT.start();
+        });
+
+        itemTrack.addActionListener(actionEvent -> {
+            for (AbstractCpsObject o : model.getSelectedCpsObjects()) {
+                if (o instanceof HolonObject) {
+                    boolean found = false;
+                    if (controller.getTrackingObj() != null) {
+                        for (AbstractCpsObject obj : controller.getTrackingObj()) {
+                            if (obj instanceof HolonObject) {
+                                if (obj.getId() == o.getId()) {
+                                    found = true;
+                                }
+                            }
+                        }
+                    }
+                    if (!found) {
+                        controller.addTrackingObj(o);
+                        ((HolonObject) o).updateTrackingInfo();
+                    }
+                    if (model.getShowConsoleLog()) {
+                        controller.addTextToConsole("Tracking: ", Color.BLACK, 12, false, false, false);
+                        controller.addTextToConsole("" + o.getName(), Color.BLUE, 12, true, false, false);
+                        controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
+                        controller.addTextToConsole("" + o.getId(), Color.RED, 12, true, false, true);
+                    }
+                }
+            }
+        });
+
+        itemUntrack.addActionListener(actionEvent -> {
+            for (AbstractCpsObject o : model.getSelectedCpsObjects()) {
+                if (o instanceof HolonObject) {
+                    boolean found = false;
+                    if (controller.getTrackingObj() != null) {
+                        for (AbstractCpsObject obj : controller.getTrackingObj()) {
+                            if (obj instanceof HolonObject) {
+                                if (obj.getId() == o.getId()) {
+                                    found = true;
+                                }
+                            }
+                        }
+                    }
+                    if (found) {
+                        // Removed from tracking array and tracking
+                        // information reseted
+                        controller.removeTrackingObj(o);
+                        ((HolonObject) o).setTrackingProd(new float[100]);
+                        ((HolonObject) o).setTrackingCons(new float[100]);
+                    }
+                }
+            }
+            System.out.println(controller.getTrackingObj());
+        });
+
+        itemDelete.addActionListener(actionEvent -> {
+            // Remove the selected Object objects
+            for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
+                if (upperNode.getNodes().contains(cps)) {
+                    controller.delObjUpperNode(cps, upperNode);
+                    // Removes the object from the tracked objects, in case
+                    // it was tracked
+                    controller.removeTrackingObj(cps);
+                    // Remove UpperNodeTab if UpperNode deleted
+                    if (cps instanceof CpsUpperNode) {
+                        JSplitPane tempSplit = (JSplitPane) getParent().getParent().getParent().getParent();
+                        JTabbedPane tabbedPane;
+                        JTabbedPane tabbedPane2;
+                        // if SplitView is activated
+                        if (tempSplit.getLeftComponent() instanceof JTabbedPane
+                                && tempSplit.getRightComponent() instanceof JTabbedPane) {
+                            tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
+                            tabbedPane2 = (JTabbedPane) tempSplit.getRightComponent();
+                        } else {
+                            tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
+                            tabbedPane2 = null;
+                        }
+                        // Look if the uppernode is open in a Tab
+                        for (int i = 4; i < tabbedPane.getTabCount(); i++) {
+
+                            if (tabbedPane.getComponentAt(i) != null &&
+                                    ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
+                                            .getComponent(0)).upperNode.getId() == cps.getId()) {
+                                ((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
+                                break;
+                            }
+                        }
+                        // If SplitView is on and the view on
+                        // tabbedPane2 is the deleted upperNode
+                        try {
+                            if (tabbedPane2 != null
+                                    && ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
+                                    .getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
+                                ((ButtonTabComponent) tabbedPane.getTabComponentAt(tabbedPane2.getSelectedIndex()))
+                                        .removeTabs();
+                            }
+                        } catch (Exception e2) {
+                        }
+
+                    }
+                }
+            }
+            toolTip = false;
+            model.getSelectedCpsObjects().clear();
+            tempCps = null;
+            repaint();
+        });
+
+        itemCut.addActionListener(actionEvent -> {
+            controller.cut(upperNode);
+            itemPaste.setEnabled(true);
+            repaint();
+        });
+
+        itemCopy.addActionListener(actionEvent -> {
+            controller.copy(upperNode);
+            itemPaste.setEnabled(true);
+            repaint();
+        });
+
+        itemPaste.addActionListener(actionEvent -> {
+            try {
+                controller.paste(upperNode, mousePosition);
+                unitGraph.update(model.getSelectedCpsObjects());
+            } catch (JsonParseException | UnsupportedFlavorException | IOException e1) {
+                JLabel message = new JLabel("The Clipboard information cannot be pastet into Application.");
+                JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
+            }
+            repaint();
+        });
+
+        this.addMouseListener(this);
+        this.addMouseMotionListener(this);
+    }
+
+    /**
+     * Paints all Components on the Canvas.
+     *
+     * @param g Graphics
+     */
+    public void paintComponent(Graphics g) {
+        String maxCap = null;
+        super.paintComponent(g);
+        ((JScrollPane) this.getParent().getParent()).setColumnHeaderView(breadCrumb);
+        // Rendering
+        g2 = (Graphics2D) g;
+        RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        g2.setRenderingHints(rh);
+
+        // Paint the Background
+        if (!upperNode.getImagePath().isEmpty()) {
+            img = new ImageIcon(upperNode.getImagePath()).getImage();
+            switch (upperNode.getBackgroundMode()) {
+                case BackgroundPopUp.IMAGE_PIXELS:
+                    g2.drawImage(img, upperNode.getLeftBorder(), 0, img.getWidth(null), img.getHeight(null), null);
+                    break;
+                case BackgroundPopUp.STRETCHED:
+                    g2.drawImage(img, upperNode.getLeftBorder(), 0, model.getCanvasX(), model.getCanvasY(), null);
+                    break;
+                case BackgroundPopUp.CUSTOM:
+                    g2.drawImage(img, upperNode.getLeftBorder(), 0, upperNode.getImageWidht(), upperNode.getImageHeight(),
+                            null);
+                    break;
+                default:
+                    break;
+            }
+        }
+
+        // Draw Left Border
+        g2.setColor(new Color(230, 230, 230));
+        g2.fillRect(0, 0, upperNode.getLeftBorder(), this.getHeight());
+        g2.setColor(Color.BLACK);
+        g2.drawLine(0, 0, this.getWidth(), 0);
+
+        // Test SubNet Coloring
+        int i = 0;
+        for (SubNet s : controller.getSimManager().getSubNets()) {
+
+            if (model.getSubNetColors().size() - 1 < i) {
+                controller.addSubNetColor(new Color((int) (Math.random() * 255), (int) (Math.random() * 255),
+                        (int) (Math.random() * 255)));
+            }
+
+            for (HolonObject cps : s.getObjects()) {
+                cps.setBorderColor(model.getSubNetColors().get(i));
+            }
+            i++;
+        }
+
+        // drawEdges that is being dragged
+        if (drawEdge) {
+            g2.setColor(Color.BLACK);
+            g2.setStroke(new BasicStroke(2));
+
+            // If TempCps is an outside Object
+            if (!upperNode.getNodes().contains(tempCps)) {
+                int count = 0;
+                for (CpsEdge e : upperNode.getConnections()) {
+                    if (e.getA().equals(tempCps)) {
+                        g2.drawLine(upperNode.getLeftBorder() >> 1, (int) (model.getScaleDiv2() + scalediv20 + 5
+                                + (model.getScale() + scalediv20 + 10) * count), x, y);
+                    } else if (e.getB().equals(tempCps)) {
+                        g2.drawLine(upperNode.getLeftBorder() >> 1, (int) (model.getScaleDiv2() + scalediv20 + 5
+                                + (model.getScale() + scalediv20 + 10) * count), x, y);
+                    }
+                    count++;
+                }
+            } else {
+                g2.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
+            }
+        }
+        // draw Edges
+        for (CpsEdge con : upperNode.getNodeEdges()) {
+            maxCap = paintEdge(con, maxCap);
+        }
+
+        // Objects connected to upperNode
+        int count = 0;
+        for (CpsEdge e : upperNode.getConnections()) {
+            AbstractCpsObject cps;
+            if (e.getA().equals(this.upperNode)) {
+                cps = e.getB();
+            } else {
+                cps = e.getA();
+            }
+            // Show and Highlight
+            if (model.getSelectedCpsObjects().contains(cps) || showedInformation[4]) {
+                for (CpsEdge ed : cps.getConnections()) {
+                    AbstractCpsObject obj = null;
+                    if (upperNode.getNodes().contains(ed.getA())) {
+                        obj = ed.getA();
+                    } else if (upperNode.getNodes().contains(ed.getB())) {
+                        obj = ed.getB();
+                    }
+                    if (obj != null) {
+                        if (ed.getConnected() == 0) {
+
+                            setEdgeState(ed);
+
+                            if (ed.getA().getId() == model.getSelectedObjectID()
+                                    || ed.getB().getId() == model.getSelectedObjectID() || edgeHighlight == ed)
+                                g2.setColor(Color.BLUE);
+                        } else {
+                            g2.setColor(Color.DARK_GRAY);
+                            g2.setStroke(new BasicStroke(2));
+                        }
+                        g2.drawLine(obj.getPosition().x, obj.getPosition().y, (upperNode.getLeftBorder() >> 1),
+                                (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + 25);
+                        if (showedInformation[0]) {
+
+                            maxCap = setCapacityString(ed, maxCap);
+
+                            if (ed.getConnected() == 0 || ed.getConnected() == 1) {
+                                g2.drawString(ed.getFlow() + "/" + maxCap,
+                                        (obj.getPosition().x + (upperNode.getLeftBorder() >> 1)) / 2,
+                                        (obj.getPosition().y + (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count)
+                                                + 25) / 2);
+                            } else {
+                                g2.drawString("not connected",
+                                        (obj.getPosition().x + (upperNode.getLeftBorder() >> 1)) / 2,
+                                        (obj.getPosition().y + (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count)
+                                                + 25) / 2);
+                            }
+                        }
+                    }
+                }
+            }
+
+            // Border Highlighting
+            if (showedInformation[3]) {
+                g2.setColor(cps.getBorderColor());
+                if (g2.getColor() != Color.WHITE) {
+                    g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20) - 3,
+                            (int) (scalediv20 + 5 + (25 + scalediv20 + 10) * count - scalediv20) - 3,
+                            (int) (50 + ((scalediv20 + 3) * 2)), (int) (50 + ((scalediv20 + 3) * 2)));
+                }
+            }
+
+            // node image
+            if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
+                    || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
+                img = new ImageIcon(this.getClass().getResource("/Images/node_selected.png")).getImage();
+            } else {
+                if (cps instanceof HolonSwitch) {
+                    if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
+                        ((HolonSwitch) cps).setAutoState(true);
+                    } else {
+                        ((HolonSwitch) cps).setAutoState(false);
+                    }
+                }
+                // Highlighting
+                if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
+                        || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
+                    g2.setColor(Color.BLUE);
+                    g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
+                            (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
+                            (int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
+                } else if (cps instanceof HolonObject) {
+                    g2.setColor(((HolonObject) cps).getColor());
+
+                    g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
+                            (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
+                            (int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
+                }
+                // draw image
+                File checkPath = new File(cps.getImage());
+                if (checkPath.exists()) {
+                    img = new ImageIcon(cps.getImage()).getImage();
+                } else {
+                    img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
+                }
+            }
+            g2.drawImage(img, (upperNode.getLeftBorder() >> 1) - 25,
+                    (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count), 50, 50, null);
+            count++;
+        }
+        // Highlighted Edge
+        if (model.getSelectedObjectID() > 0 || !model.getSelectedCpsObjects().isEmpty() || !tempSelected.isEmpty()) {
+            g2.setColor(Color.BLUE);
+            for (CpsEdge con : upperNode.getNodeEdges()) {
+                if (con.getFlow() <= con.getCapacity()) {
+                    g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 3) + 1, 4)));
+                } else {
+                    g2.setStroke(new BasicStroke(2));
+                }
+
+                maxCap = nameSthSensible(con, maxCap);
+            }
+        } else if (edgeHighlight != null) {
+            g2.setColor(Color.BLUE);
+            if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
+                g2.setStroke(
+                        new BasicStroke(Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3) + 1, 4)));
+            } else {
+                g2.setStroke(new BasicStroke(2));
+            }
+            if (upperNode.getNodeEdges().contains(edgeHighlight)) {
+                g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight.getA().getPosition().y,
+                        edgeHighlight.getB().getPosition().x, edgeHighlight.getB().getPosition().y);
+
+                maxCap = setCapacityString(edgeHighlight, maxCap);
+
+                if (showedInformation[0]) {
+                    g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
+                            (edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2,
+                            (edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2);
+                }
+            }
+        }
+
+        // Objects in upper node
+        for (AbstractCpsObject cps : upperNode.getNodes()) {
+            // Border Highlighting
+            if (showedInformation[3]) {
+                g2.setColor(cps.getBorderColor());
+                if (g2.getColor() != Color.WHITE) {
+                    g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20 - 3),
+                            (int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20 - 3),
+                            (int) (controller.getScale() + ((scalediv20 + 3) * 2)),
+                            (int) (controller.getScale() + ((scalediv20 + 3) * 2)));
+                }
+            }
+
+            nameSthSensible2(cps);
+
+            g2.drawImage(img, cps.getPosition().x - model.getScaleDiv2(), cps.getPosition().y - model.getScaleDiv2(),
+                    controller.getScale(), controller.getScale(), null);
+        }
+
+        // Dragged marker Highlighting
+        g2.setStroke(new BasicStroke(1));
+        if (doMark) {
+            g2.setColor(Color.BLACK);
+            drawMarker();
+        }
+
+        // Border Line
+        g2.setColor(Color.BLACK);
+        g2.drawLine(upperNode.getLeftBorder(), 0, upperNode.getLeftBorder(), this.getHeight());
+
+        // Tooltip
+        showTooltip(g);
+    }
+
+    @Override
+    public void mouseClicked(MouseEvent e) {
+        updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
+    }
+
+    @Override
+    public void mouseEntered(MouseEvent e) {
+    }
+
+    @Override
+    public void mouseExited(MouseEvent e) {
+    }
+
+    @Override
+    public void mousePressed(MouseEvent e) {
+        tempCps = null;
+        dataSelected = null;
+        edgeHighlight = null;
+        controller.setSelecteEdge(null);
+        controller.setSelectedObjectID(-1);
+        // Object Selection
+
+        // Erase old data in the PropertyTable
+        if (model.getPropertyTable().getRowCount() > 0) {
+            for (int i = model.getPropertyTable().getRowCount() - 1; i > -1; i--) {
+                model.getPropertyTable().removeRow(i);
+            }
+        }
+
+        if (e.getX() > upperNode.getLeftBorder()) {
+            for (AbstractCpsObject cps : upperNode.getNodes()) {
+                cx = cps.getPosition().x - model.getScaleDiv2();
+                cy = cps.getPosition().y - model.getScaleDiv2();
+                if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
+                    tempCps = cps;
+
+                    setConsoleTextAfterSelect(cps);
+
+                    dragging = true;
+                    if (e.isControlDown() && tempCps != null) {
+                        if (model.getSelectedCpsObjects().contains(tempCps)) {
+                            controller.deleteSelectedObject(tempCps);
+                        } else {
+                            controller.addSelectedObject(tempCps);
+                        }
+                    }
+
+                    // If drawing an Edge (CTRL down)
+                    if (tempCps.getClass() == HolonObject.class) {
+                        HolonObject tempObj = ((HolonObject) tempCps);
+                        dataSelected = tempObj.getElements();
+                    }
+                    if (e.isShiftDown()) {
+                        drawEdge = true;
+                        dragging = false;
+                    }
+                    break;
+                }
+            }
+        } else {
+            // look for objects connected to uppernode
+            int count = 0;
+            for (CpsEdge ed : upperNode.getConnections()) {
+                AbstractCpsObject cps;
+                if (ed.getA().equals(this.upperNode)) {
+                    cps = ed.getB();
+                } else {
+                    cps = ed.getA();
+                }
+                if (x - controller.getScale() <= ((upperNode.getLeftBorder() >> 1) - model.getScaleDiv2())
+                        && y - controller.getScale() <= (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)
+                        && x >= (upperNode.getLeftBorder() >> 1) - model.getScaleDiv2()
+                        && y >= (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)) {
+                    tempCps = cps;
+                    if (model.getShowConsoleLog()) {
+                        controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
+                        controller.addTextToConsole("" + cps.getName(), Color.BLUE, 12, true, false, false);
+                        controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
+                        controller.addTextToConsole("" + cps.getId(), Color.RED, 12, true, false, true);
+                        controller.setSelectedObjectID(tempCps.getId());
+                    }
+                    // If drawing an Edge (CTRL down)
+                    if (tempCps.getClass() == HolonObject.class) {
+                        HolonObject tempObj = ((HolonObject) tempCps);
+                        dataSelected = tempObj.getElements();
+                    }
+                    if (e.isShiftDown()) {
+                        drawEdge = true;
+                    }
+                }
+                count++;
+            }
+        }
+
+        // Selection of CpsObject
+        // model.setSelectedCpsObject(tempCps);
+
+        // Edge Selection
+        if (e.getButton() == MouseEvent.BUTTON1) {
+            if (tempCps == null) {
+                edgeHighlight = mousePositionOnEdge(x, y);
+                controller.setSelecteEdge(edgeHighlight);
+                controller.setSelectedObjectID(0);
+                if (!e.isControlDown() && e.getButton() != MouseEvent.BUTTON3) {
+                    model.getSelectedCpsObjects().clear();
+                }
+                updCon.deleteRows(model.getMultiTable());
+                updCon.deleteRows(model.getSingleTable());
+            }
+
+            if (edgeHighlight == null && tempCps == null) {
+                sx = e.getX();
+                sy = e.getY();
+                doMark = true;
+            }
+            // System.out.println("Selected Objects");
+            // for (AbstractCpsObject temp : model.getSelectedCpsObjects()) {
+            // System.out.println(temp.getName() + " " + temp.getID());
+            // }
+            repaint();
+        }
+    }
+
+    @Override
+    public void mouseReleased(MouseEvent e) {
+        x = e.getX();
+        y = e.getY();
+        dragging = false;
+        if (model.getSelectedCpsObjects().size() > 1) {
+            model.getTableHolonElement().setModel(model.getMultiTable());
+        } else if (model.getSelectedCpsObjects().size() == 1) {
+            model.getTableHolonElement().setModel(model.getSingleTable());
+        }
+
+        if (drawEdge) {
+            drawEdge = false;
+            drawDeleteEdge();
+        }
+
+        if (dragged) {
+            try {
+                controller.autoSave();
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+
+        if (!e.isControlDown() && !dragged && tempCps != null && MouseEvent.BUTTON3 != e.getButton()) {
+            model.getSelectedCpsObjects().clear();
+            controller.addSelectedObject(tempCps);
+        }
+
+        dragged = false;
+
+        // Rightclick List
+        setRightclickMenu(e);
+
+        markObjects();
+
+        if (doubleClick() && tempCps != null && tempCps instanceof HolonSwitch) {
+            ((HolonSwitch) tempCps).switchState();
+        }
+
+        controller.calculateStateForTimeStep(model.getCurIteration());
+        updCon.paintProperties(tempCps);
+        updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
+        updCon.refreshTableProperties(model.getPropertyTable());
+        repaint();
+
+    }
+
+    @Override
+    public void mouseDragged(MouseEvent e) {
+        // If Edge is drawn
+        x = e.getX();
+        y = e.getY();
+        if (!model.getSelectedCpsObjects().contains(tempCps) && !doMark) {
+            model.getSelectedCpsObjects().clear();
+            if (tempCps != null) {
+                controller.addSelectedObject(tempCps);
+            }
+        }
+        if (dragging) {
+            try {
+                // tempCps in the upperNode? else its a connected Object from
+                // outside
+                if (upperNode.getNodes().contains(tempCps)) {
+                    dragged = true;
+                    float xDist, yDist; // Distance
+
+                    x = e.getX();
+                    y = e.getY();
+
+                    // Make sure its in bounds
+                    if (e.getX() < controller.getScaleDiv2() + upperNode.getLeftBorder() + 5)
+                        x = controller.getScaleDiv2() + upperNode.getLeftBorder() + 5;
+                    else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
+                        x = this.getWidth() - controller.getScaleDiv2();
+                    if (e.getY() < controller.getScaleDiv2())
+                        y = controller.getScaleDiv2();
+                    else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
+                        y = this.getHeight() - controller.getScaleDiv2();
+
+                    // Distance
+                    xDist = x - tempCps.getPosition().x;
+                    yDist = y - tempCps.getPosition().y;
+
+                    tempCps.setPosition(x, y); // Drag Position
+
+                    // TipText Position and name
+                    toolTip = true;
+                    toolTipText = tempCps.getName() + ", " + tempCps.getId();
+                    toolTipPos.x = tempCps.getPosition().x - model.getScaleDiv2();
+                    toolTipPos.y = tempCps.getPosition().y + model.getScaleDiv2();
+
+                    // All Selected Objects
+                    for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
+                        if (cps != tempCps) {
+                            x = (int) (cps.getPosition().x + xDist);
+                            y = (int) (cps.getPosition().y + yDist);
+
+                            // Make sure its in bounds
+                            if (x < upperNode.getLeftBorder() + 5 + controller.getScaleDiv2())
+                                x = controller.getScaleDiv2() + upperNode.getLeftBorder() + 5;
+                            else if (x > this.getWidth() - controller.getScaleDiv2())
+                                x = this.getWidth() - controller.getScaleDiv2();
+                            if (y <= controller.getScaleDiv2())
+                                y = controller.getScaleDiv2();
+                            else if (y > this.getHeight() - controller.getScaleDiv2())
+                                y = this.getHeight() - controller.getScaleDiv2();
+
+                            cps.setPosition(x, y);
+                        }
+                    }
+                }
+                repaint();
+            } catch (Exception eex) {
+
+            }
+        }
+
+        // Mark Objects
+        if (doMark) {
+            tempSelected.clear();
+            for (AbstractCpsObject cps : upperNode.getNodes()) {
+                int x1 = sx, x2 = x, y1 = sy, y2 = y;
+
+                if (sx >= x) {
+                    x1 = x;
+                    x2 = sx;
+                }
+                if (sy >= y) {
+                    y1 = y;
+                    y2 = sy;
+                }
+                if (x1 <= cps.getPosition().x + model.getScaleDiv2() && y1 <= cps.getPosition().y + model.getScaleDiv2()
+                        && x2 >= cps.getPosition().x && y2 >= cps.getPosition().y) {
+                    tempSelected.add(cps);
+
+                }
+            }
+            int count = 0;
+            for (CpsEdge ed : upperNode.getConnections()) {
+                AbstractCpsObject cps;
+                if (ed.getA().equals(upperNode)) {
+                    cps = ed.getB();
+                } else {
+                    cps = ed.getA();
+                }
+
+                int x1 = sx, x2 = x, y1 = sy, y2 = y;
+
+                if (sx >= x) {
+                    x1 = x;
+                    x2 = sx;
+                }
+                if (sy >= y) {
+                    y1 = y;
+                    y2 = sy;
+                }
+
+                if (x1 <= upperNode.getLeftBorder() >> 1
+                        && y1 <= (int) (5 + (model.getScale() + scalediv20 + 10) * count) + model.getScaleDiv2()
+                        && x2 >= upperNode.getLeftBorder() >> 1
+                        && y2 >= (int) (5 + (model.getScale() + scalediv20 + 10) * count)) {
+                    tempSelected.add(cps);
+
+                }
+                count++;
+            }
+        }
+
+        repaint();
+
+    }
+
+    @Override
+    public void mouseMoved(MouseEvent e) {
+        x = e.getX();
+        y = e.getY();
+
+        // Everything for the tooltip :)
+        boolean on = false;
+        for (AbstractCpsObject cps : upperNode.getNodes()) {
+
+            cx = cps.getPosition().x - controller.getScaleDiv2();
+            cy = cps.getPosition().y - controller.getScaleDiv2();
+
+            on = setToolTipInfoAndPosition(on, cps);
+        }
+        int count = 0;
+        for (CpsEdge ed : upperNode.getConnections()) {
+
+            AbstractCpsObject cps;
+            if (ed.getA().equals(this.upperNode)) {
+                cps = ed.getB();
+            } else {
+                cps = ed.getA();
+            }
+
+            cx = upperNode.getLeftBorder() >> 1;
+            cy = (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count);
+            if (x - 50 <= cx && y - 50 <= cy && x >= cx && y >= cy) {
+
+                on = true;
+                toolTipPos.x = cx - 25;
+                toolTipPos.y = cy + 50;
+                toolTipText = cps.getName() + ", " + cps.getId();
+
+            }
+            count++;
+        }
+
+        toolTip = on;
+        repaint();
+    }
+
+    /**
+     * Draws or Deletes an Edge.
+     */
+    private void drawDeleteEdge() {
+        boolean node = true; // new node?
+        boolean newEdge = true;
+        boolean onEdge = true;
+        boolean deleteNode = false;
+        boolean outsideCon = !upperNode.getNodes().contains(tempCps); // Connection to the outside
+        boolean found = false; // dont search for outside connetion if inside
+        // connection is found
+        CpsEdge e = null;
+        for (AbstractCpsObject cps : upperNode.getNodes()) {
+
+            cx = cps.getPosition().x - controller.getScaleDiv2();
+            cy = cps.getPosition().y - controller.getScaleDiv2();
+
+            if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy
+                    && cps != tempCps) {
+                found = true;
+                node = false;
+                onEdge = false;
+                for (CpsEdge p : tempCps.getConnections()) {
+                    if ((p.getA() == tempCps && p.getB() == cps) || (p.getB() == tempCps && p.getA() == cps)) {
+                        newEdge = false;
+                        e = p;
+                    }
+                }
+                if (!newEdge) {
+                    if (outsideCon) {
+                        controller.disconnectNodes(e, upperNode);
+                    } else {
+                        controller.delEdgeUpperNode(e, upperNode);
+                    }
+                    // Node ohne Edge?
+                    if (e.getA().getClass() == CpsNode.class && e.getA().getConnections().isEmpty()) {
+                        tempCps = e.getA();
+                        deleteNode = true;
+                    }
+                    if (e.getB().getClass() == CpsNode.class && e.getB().getConnections().isEmpty()) {
+                        deleteNode = true;
+                    }
+                } else {
+                    e = new CpsEdge(cps, tempCps, model.getMaxCapacity());
+                    if (outsideCon) {
+                        controller.connectNodes(e, upperNode);
+                    } else {
+                        controller.addEdgeUpperNode(e, upperNode);
+                    }
+                }
+            }
+        }
+        if (!found && !outsideCon) {
+            int count = 0;
+            for (CpsEdge ed : upperNode.getConnections()) {
+                AbstractCpsObject cps;
+                if (ed.getA().equals(upperNode)) {
+                    cps = ed.getB();
+                } else {
+                    cps = ed.getA();
+                }
+
+                cx = upperNode.getLeftBorder() >> 1;
+                cy = (int) (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count);
+
+                if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy
+                        && cps != tempCps) {
+                    outsideCon = true;
+                    node = false;
+                    onEdge = false;
+                    for (CpsEdge p : tempCps.getConnections()) {
+                        if ((p.getA() == tempCps && p.getB() == cps) || (p.getB() == tempCps && p.getA() == cps)) {
+                            newEdge = false;
+                            e = p;
+                        }
+                    }
+                    if (!newEdge) {
+                        if (outsideCon) {
+                            controller.disconnectNodes(e, upperNode);
+                        } else {
+                            controller.delEdgeUpperNode(e, upperNode);
+                        }
+                        // Node ohne Edge?
+                        if (e.getA().getClass() == CpsNode.class && e.getA().getConnections().isEmpty()) {
+                            tempCps = e.getA();
+                            deleteNode = true;
+                        }
+                        if (e.getB().getClass() == CpsNode.class && e.getB().getConnections().isEmpty()) {
+                            deleteNode = true;
+                        }
+                    } else {
+                        CpsEdge edge = new CpsEdge(cps, tempCps, model.getMaxCapacity());
+                        if (outsideCon) {
+                            controller.connectNodes(edge, upperNode);
+                        } else {
+                            controller.addEdgeUpperNode(edge, upperNode);
+                        }
+                    }
+                }
+                count++;
+            }
+        }
+
+        // Edge auf eine Edge gezogen?
+        if (onEdge) {
+            CpsEdge p = mousePositionOnEdge(x, y);
+            if (p != null) {
+                CpsEdge e1;
+                CpsEdge e2;
+
+                node = false;
+
+                CpsNode n = new CpsNode("Node");
+
+                n.setPosition(x, y);
+                controller.addObjUpperNode(n, upperNode);
+
+                AbstractCpsObject r, k;
+                r = p.getA();
+                k = p.getB();
+
+                e = new CpsEdge(n, tempCps, model.getMaxCapacity());
+
+                e1 = new CpsEdge(n, r, model.getMaxCapacity());
+
+                e2 = new CpsEdge(n, k, model.getMaxCapacity());
+
+                controller.delEdgeUpperNode(p, upperNode);
+                if (outsideCon) {
+                    controller.connectNodes(e, upperNode);
+                } else {
+                    controller.addEdgeUpperNode(e, upperNode);
+                }
+
+                controller.addEdgeUpperNode(e1, upperNode);
+                controller.addEdgeUpperNode(e2, upperNode);
+            }
+        }
+
+        // ins leere Gedragged
+        if (node && x > upperNode.getLeftBorder()) {
+            CpsNode n = new CpsNode("Node");
+
+            n.setPosition(x, y);
+            controller.addObjUpperNode(n, upperNode);
+
+            e = new CpsEdge(n, tempCps, model.getMaxCapacity());
+
+            if (outsideCon) {
+                controller.connectNodes(e, upperNode);
+            } else {
+                controller.addEdgeUpperNode(e, upperNode);
+            }
+        }
+
+        // Wenn ein Node ohne Connections da ist
+        if (deleteNode) {
+            controller.delCanvasObject(tempCps, true);
+            tempCps = null;
+        }
+    }
+
+    /**
+     * Checks if the mouse is on an Edge.
+     *
+     * @param x Position of the Mouse
+     * @param y Position of the Mouse
+     * @return CpsEdge the Mouse is on, null if the mouse is not on an Edge
+     */
+    private CpsEdge mousePositionOnEdge(int x, int y) {
+        x += controller.getScaleDiv2();
+        y += controller.getScaleDiv2();
+        int lx, ly, hx, hy;
+
+
+        for (CpsEdge p : upperNode.getNodeEdges()) {
+            Line2D l = new Line2D.Float(p.getA().getPosition().x, p.getA().getPosition().y, p.getB().getPosition().x,
+                    p.getB().getPosition().y);
+
+            int[] positions = determineMousePositionOnEdge(p);
+            lx = positions[0];
+            ly = positions[1];
+            hx = positions[2];
+            hy = positions[3];
+
+            // distance from a point to a line and between both Objects
+            if (l.ptLineDistSq(x - model.getScaleDiv2(), y - model.getScaleDiv2()) < 20 && x > lx && x < hx && y > ly
+                    && y < hy) {
+                return p;
+            }
+        }
+
+        // edge to outside connection
+
+        int count = 0;
+        for (CpsEdge e : upperNode.getConnections()) {
+            AbstractCpsObject cps;
+            if (e.getA().equals(this.upperNode)) {
+                cps = e.getB();
+            } else {
+                cps = e.getA();
+            }
+            for (CpsEdge p : cps.getConnections()) {
+                AbstractCpsObject obj = null;
+                boolean doTest = false;
+                if (upperNode.getNodes().contains(p.getA())) {
+                    obj = p.getA();
+                    doTest = true;
+                } else if (upperNode.getNodes().contains(p.getB())) {
+                    obj = p.getB();
+                    doTest = true;
+                }
+                // g2.drawImage(img, (borderPos >> 1) - 25, (int) (scalediv20 +
+                // 5 + (50 + scalediv20 + 10) * count), 50, 50, null);
+                if (doTest) {
+                    Line2D l = new Line2D.Float((upperNode.getLeftBorder() >> 1) - 25,
+                            (int) (scalediv20 + 5 + 25 + (50 + scalediv20 + 10) * count), obj.getPosition().x,
+                            obj.getPosition().y);
+                    if ((upperNode.getLeftBorder() >> 1) > obj.getPosition().x) {
+                        hx = (upperNode.getLeftBorder() >> 1) - 25 + model.getScaleDiv2() + 7;
+                        lx = obj.getPosition().x + model.getScaleDiv2() - 7;
+                    } else {
+                        lx = (upperNode.getLeftBorder() >> 1) - 25 + model.getScaleDiv2() - 7;
+                        hx = obj.getPosition().x + model.getScaleDiv2() + 7;
+                    }
+                    if ((int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) > obj.getPosition().y) {
+                        hy = (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + model.getScaleDiv2() + 7;
+                        ly = obj.getPosition().y + model.getScaleDiv2() - 7;
+                    } else {
+                        ly = (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + model.getScaleDiv2() - 7;
+                        hy = obj.getPosition().y + model.getScaleDiv2() + 7;
+                    }
+
+                    // distance from a point to a line and between both Objects
+                    if (l.ptLineDistSq(x - model.getScaleDiv2(), y - model.getScaleDiv2()) < 20 && x > lx && x < hx
+                            && y > ly && y < hy) {
+                        return p;
+                    }
+                }
+            }
+            count++;
+        }
+        return null;
+    }
+
+    /**
+     * sets the Edge Capacity.
+     *
+     * @param cap capacity
+     */
+    public void setEdgeCapacity(float cap) {
+        controller.setMaxCapacity(cap);
+    }
+
+    /**
+     * Set if Information should be shown.
+     *
+     * @param connection boolean for conecction
+     * @param object     boolean for objects
+     */
+    public void setShowedInformation(boolean connection, boolean object, boolean nodeOfnode) {
+        showedInformation[0] = connection;
+        showedInformation[1] = object;
+        showedInformation[4] = nodeOfnode;
+    }
+
+    /**
+     * Returns if Information should be shown.
+     *
+     * @return Array of boolean [0] = connection, [1] = objects
+     */
+    public boolean[] getShowedInformation() {
+        return showedInformation;
+    }
+
+    /**
+     * copies a set of given informations
+     *
+     * @param informations
+     */
+    protected void setShowedInformation(boolean[] informations) {
+        showedInformation = informations;
+    }
+
+    /**
+     * Set the Background Image;
+     *
+     * @param imagePath Image Path
+     * @param mode      Image Mode
+     * @param width     Image custom width
+     * @param height    Image custom height
+     */
+    public void setBackgroundImage(String imagePath, int mode, int width, int height) {
+        upperNode.setBackgroundImage(imagePath, mode, width, height);
+    }
+
+    /**
+     * set tooltIp
+     *
+     * @param bool
+     */
+    protected void setToolTip(boolean bool) {
+        this.toolTip = bool;
+    }
+
+    /**
+     * Set the Mouse Position on the UpperNodeCanvas;
+     *
+     * @param x
+     * @param y
+     */
+    public void setXY(int x, int y) {
+        this.x = x;
+        this.y = y;
+    }
 
 }