Browse Source

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

Edgardo Palza 8 years ago
parent
commit
bb0fc04e7e

+ 61 - 0
src/classes/HolonBody.java

@@ -0,0 +1,61 @@
+package classes;
+import java.awt.Color;
+
+public class HolonBody {
+  private static final double G = 6.673e-11;   // gravitational constant
+  
+  public int rx, ry;       // holds the cartesian positions
+  public double vx, vy;       // velocity components 
+  public double fx, fy;       // force components
+  public double mass;         // mass
+  public Color color;         // color 
+  
+  // create and initialize a new Body
+  public HolonBody(int rx, int ry, double vx, double vy, double mass, Color color) {
+    this.rx    = rx;
+    this.ry    = ry;
+    this.vx    = vx;
+    this.vy    = vy;
+    this.mass  = mass;
+    this.color = color;
+  }
+  
+  // update the velocity and position using a timestep dt
+  public void update(double dt) {
+    vx += dt * fx / mass;
+    vy += dt * fy / mass;
+    rx += dt * vx;
+    ry += dt * vy;
+  }
+  
+  // returns the distance between two bodies
+  public double distanceTo(HolonBody b) {
+    double dx = rx - b.rx;
+    double dy = ry - b.ry;
+    return Math.sqrt(dx*dx + dy*dy);
+  }
+  
+  // set the force to 0 for the next iteration
+  public void resetForce() {
+    fx = 0.0;
+    fy = 0.0;
+  }
+  
+  // compute the net force acting between the body a and b, and
+  // add to the net force acting on a
+  public void addForce(HolonBody b) {
+    HolonBody a = this;
+    double EPS = 3E4;      // softening parameter (just to avoid infinities)
+    double dx = b.rx - a.rx;
+    double dy = b.ry - a.ry;
+    double dist = Math.sqrt(dx*dx + dy*dy);
+    double F = (G * a.mass * b.mass) / (dist*dist + EPS*EPS);
+    a.fx += F * dx / dist;
+    a.fy += F * dy / dist;
+  }
+  
+  // convert to string representation formatted nicely
+  public String toString() {
+    return "" + rx + ", "+ ry+ ", "+  vx+ ", "+ vy+ ", "+ mass;
+  }
+}

+ 15 - 1
src/classes/SubNet.java

@@ -12,7 +12,7 @@ public class SubNet {
 	private ArrayList<HolonObject> subNetObjects;
 	private ArrayList<CpsEdge> subNetEdges;
 	private ArrayList<HolonSwitch> subNetSwitches;
-
+	private Position pos;
 	/**
 	 * Constructor for a Subnet.
 	 * 
@@ -54,4 +54,18 @@ public class SubNet {
 	public ArrayList<HolonSwitch> getSwitches() {
 		return subNetSwitches;
 	}
+
+
+	public Position getPos() {
+		return pos;
+	}
+
+	public void setPos(Position pos) {
+		this.pos = pos;
+	}
+	
+	public void setPos(int x, int y){
+		this.pos.x = x;
+		this.pos.y = y;
+	}
 }

+ 13 - 2
src/ui/controller/Control.java

@@ -109,6 +109,17 @@ public class Control {
 	public AbstractCpsObject searchByID(int id) {
 		return multiPurposeController.searchByID(id);
 	}
+	
+	/**
+	 * Search for Object by ID in upperNode
+	 * 
+	 * @param id
+	 *            the id of the Object
+	 * @return the CpsObject
+	 */
+	public AbstractCpsObject searchByIDUpperNode(int id, CpsUpperNode upperNode) {
+		return multiPurposeController.searchByIDUpperNode(id, upperNode);
+	}
 
 	/**
 	 * Search for Object in a Category.
@@ -736,8 +747,8 @@ public class Control {
 	 * Controlling Nodes of Nodes
 	 */
 
-	public void addUpperNode(String nodeName, CpsUpperNode upperNode) {
-		nodeController.doUpperNode(nodeName, upperNode);
+	public void addUpperNode(String nodeName, CpsUpperNode upperNode, ArrayList<AbstractCpsObject> toGroup) {
+		nodeController.doUpperNode(nodeName, upperNode, toGroup);
 	}
 
 	public void delUpperNode(CpsUpperNode node, CpsUpperNode upperNode) {

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

@@ -122,7 +122,7 @@ public class MultiPurposeController {
 	 * @param id
 	 * @return
 	 */
-	public AbstractCpsObject searchIDUpperNode(CpsUpperNode upperNode, int id) {
+	public AbstractCpsObject searchByIDUpperNode(int id, CpsUpperNode upperNode) {
 
 		Integer idx;
 

+ 120 - 17
src/ui/controller/NodeController.java

@@ -30,12 +30,12 @@ public class NodeController {
 	 * @param nodeName
 	 * @param upperNode
 	 */
-	public void doUpperNode(String nodeName, CpsUpperNode upperNode) {
+	public void doUpperNode(String nodeName, CpsUpperNode upperNode, ArrayList<AbstractCpsObject> toGroup) {
 
 		CpsUpperNode node = new CpsUpperNode(nodeName);
-		node.setPosition(calculatePos());
-		makeAdjacent(node, upperNode);
-		makeNodeOfNodes(node, upperNode);
+		node.setPosition(calculatePos(toGroup));
+		makeAdjacent(node, upperNode, toGroup);
+		makeNodeOfNodes(node, upperNode, toGroup);
 		backupOldEdges(node, upperNode);
 		if (upperNode == null)
 			cvs.addNewObject(node);
@@ -66,13 +66,13 @@ public class NodeController {
 	 * @param node
 	 * @param upperNode
 	 */
-	private void makeNodeOfNodes(CpsUpperNode node, CpsUpperNode upperNode) {
+	private void makeNodeOfNodes(CpsUpperNode node, CpsUpperNode upperNode, ArrayList<AbstractCpsObject> toGroup) {
 
 		ArrayList<AbstractCpsObject> nodes = node.getNodes();
 		ArrayList<CpsEdge> toDelete = new ArrayList<>();
 
 		// Put all selected Nodes into the Upper Node
-		for (Iterator<AbstractCpsObject> it = model.getSelectedCpsObjects().iterator(); it.hasNext();) {
+		for (Iterator<AbstractCpsObject> it = toGroup.iterator(); it.hasNext();) {
 
 			// füge Neue Objecte in Neuen Node hinzu
 			AbstractCpsObject obj = it.next();
@@ -98,7 +98,7 @@ public class NodeController {
 
 		(upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges()).removeAll(toDelete);
 		// Lösche dann die Edges aus der nächst höheren schicht
-		for (AbstractCpsObject abs : model.getSelectedCpsObjects()) {
+		for (AbstractCpsObject abs : toGroup) {
 			if (upperNode == null)
 				removeForNodeOfNode(abs, null);
 			else
@@ -117,9 +117,18 @@ public class NodeController {
 	private void unmakeNodesOfNodes(CpsUpperNode node, CpsUpperNode upperNode) {
 		// TODO Auto-generated method stub
 		// add all nodes into upperNode
+
+		for (CpsEdge edge : node.getConnections()) {
+			if (edge.getA().equals(node))
+				edge.getB().getConnections().remove(edge);
+			if (edge.getB().equals(node))
+				edge.getA().getConnections().remove(edge);
+		}
+
 		(upperNode == null ? model.getObjectsOnCanvas() : upperNode.getNodes()).addAll(node.getNodes());
 		// change the indices accordingly the higher layer
-		mpC.adjustIdx(mpC.getHighestIdx((upperNode == null ? model.getCvsObjIdx() : upperNode.getNodesIdx())), node.getNodesIdx());
+		mpC.adjustIdx(mpC.getHighestIdx((upperNode == null ? model.getCvsObjIdx() : upperNode.getNodesIdx())),
+				node.getNodesIdx());
 		// add all indices of nodes into upperNode
 		(upperNode == null ? model.getCvsObjIdx() : upperNode.getNodesIdx()).putAll(node.getNodesIdx());
 		// add all Edges of node into upperNode
@@ -133,7 +142,7 @@ public class NodeController {
 	 * @param node
 	 * @param upperNode
 	 */
-	private void makeAdjacent(CpsUpperNode node, CpsUpperNode upperNode) {
+	private void makeAdjacent(CpsUpperNode node, CpsUpperNode upperNode, ArrayList<AbstractCpsObject> toGroup) {
 
 		ArrayList<AbstractCpsObject> adj = new ArrayList<>();
 		ArrayList<Float> maxCapacity = new ArrayList<>();
@@ -148,8 +157,7 @@ public class NodeController {
 			CpsEdge edge = it.next();
 
 			// wenn ausgewählte Objekte in edge und andere auserhalb
-			if (model.getSelectedCpsObjects().contains(edge.getA())
-					&& !model.getSelectedCpsObjects().contains(edge.getB())) {
+			if (toGroup.contains(edge.getA()) && !toGroup.contains(edge.getB())) {
 				// und wenn in der adj noch nicht vorhanden und füg
 				if (!adj.contains(edge.getB())) {
 					adj.add(edge.getB());
@@ -166,8 +174,7 @@ public class NodeController {
 			}
 
 			// Analog
-			else if (!model.getSelectedCpsObjects().contains(edge.getA())
-					&& model.getSelectedCpsObjects().contains(edge.getB())) {
+			else if (!toGroup.contains(edge.getA()) && toGroup.contains(edge.getB())) {
 				if (!adj.contains(edge.getA())) {
 					adj.add(edge.getA());
 					maxCapacity.add(edge.getCapacity());
@@ -204,6 +211,9 @@ public class NodeController {
 	private void unmakeAdjacent(CpsUpperNode node, CpsUpperNode upperNode) {
 		// TODO Auto-generated method stub
 		ArrayList<CpsEdge> toDelete = new ArrayList<>();
+		ArrayList<CpsEdge> lostEdges = new ArrayList<>();
+		ArrayList<AbstractCpsObject> found = (upperNode == null ? model.getObjectsOnCanvas() : upperNode.getNodes());
+		ArrayList<AbstractCpsObject> lostChildren = new ArrayList<>();
 
 		// für jede Edge aus upperNode die Node enthält tu sie in toDelete
 		for (Iterator<CpsEdge> it = (upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges())
@@ -214,9 +224,78 @@ public class NodeController {
 				toDelete.add(edge);
 
 		}
+		// mark all object that arent in the restored oldEdges
+		for (CpsEdge edge : node.getOldEdges()) {
+			if (node.getNodes().contains(edge.getA()) && !found.contains(edge.getB()) && !lostEdges.contains(edge)) {
+				lostChildren.add(edge.getA());
+				lostEdges.add(edge);
+				// edge.getB().getConnections().remove(edge);
+			}
+
+			else if (node.getNodes().contains(edge.getB()) && !found.contains(edge.getA())
+					&& !lostEdges.contains(edge)) {
+				lostChildren.add(edge.getB());
+				lostEdges.add(edge);
+				// edge.getA().getConnections().remove(edge);
+			}
+		}
+		node.getOldEdges().removeAll(lostEdges);
+
+		// LOST = DIE IN NODE SIND, TOSEARCH = IHRE PARTNER DIE IN ANDEREN NODES
+		// SIND
+
+		for (CpsEdge edge : lostEdges) {
+			AbstractCpsObject toSearch = null;
+			AbstractCpsObject lost = null;
+
+			if (lostChildren.contains(edge.getA())) {
+				toSearch = edge.getB();
+				lost = edge.getA();
+			} else if (lostChildren.contains(edge.getB())) {
+				toSearch = edge.getA();
+				lost = edge.getB();
+			}
+			if (toSearch instanceof CpsUpperNode) {
+				for (CpsEdge e : lost.getConnections()) {
+					if ((found.contains(e.getA()) || found.contains(e.getB())) && !node.getOldEdges().contains(e))
+						node.getOldEdges().add(e);
+				}
+			} else
+				outerLoop: for (AbstractCpsObject cps : found) {
+					if (!cps.equals(node) && !lostChildren.contains(cps))
+						if (backtrackLostChild(cps, toSearch, lost)) {
+
+							for (CpsEdge f : node.getOldEdges())
+								if ((f.getA().equals(cps) && f.getB().equals(toSearch))
+										|| (f.getB().equals(cps) && f.getA().equals(toSearch)))
+									continue outerLoop;
+
+							if (!lookforDuplicates(cps, lost, node.getOldEdges())) {
+								
+								CpsEdge temp = new CpsEdge(cps, lost, edge.getCapacity());
+								node.getOldEdges().add(temp);
+
+								//break;
+							}
+
+						}
+				}
+
+		}
+
 		// lösch alle Edges die in toDelete sind und wiederherstell alte Edges
 		(upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges()).removeAll(toDelete);
 		(upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges()).addAll(node.getOldEdges());
+
+	}
+
+	private boolean lookforDuplicates(AbstractCpsObject a, AbstractCpsObject b, ArrayList<CpsEdge> list) {
+		for (CpsEdge cpsEdge : list) {
+			if ((a.equals(cpsEdge.getA()) && b.equals(cpsEdge.getB()))
+					|| (b.equals(cpsEdge.getA()) && a.equals(cpsEdge.getB())))
+				return true;
+		}
+		return false;
 	}
 
 	/**
@@ -310,17 +389,17 @@ public class NodeController {
 	 * 
 	 * @return
 	 */
-	private Position calculatePos() {
+	private Position calculatePos(ArrayList<AbstractCpsObject> toGroup) {
 
 		Position pos = new Position(0, 0);
 
 		// sum(x0 .. xn) / numOfPos, y analog
-		for (AbstractCpsObject abs : model.getSelectedCpsObjects()) {
+		for (AbstractCpsObject abs : toGroup) {
 			pos.x += abs.getPosition().x;
 			pos.y += abs.getPosition().y;
 		}
-		pos.x /= model.getSelectedCpsObjects().size();
-		pos.y /= model.getSelectedCpsObjects().size();
+		pos.x /= toGroup.size();
+		pos.y /= toGroup.size();
 
 		return pos;
 	}
@@ -332,6 +411,30 @@ public class NodeController {
 		(upperNode == null ? model.getObjectsOnCanvas() : upperNode.getNodes()).remove(obj);
 	}
 
+	/**
+	 * Search Lost Nodes by Backtracking
+	 * 
+	 * @param lost
+	 * @param object
+	 * @return
+	 */
+	private boolean backtrackLostChild(AbstractCpsObject object, AbstractCpsObject find, AbstractCpsObject lost) {
+		if (!(object instanceof CpsUpperNode)) {
+			for (CpsEdge edge : object.getConnections()) {
+				if (edge.getA().equals(find) && edge.getB().equals(lost)
+						|| edge.getA().equals(lost) && edge.getB().equals(find))
+					return true;
+			}
+			return false;
+		} else {
+			for (AbstractCpsObject cps : ((CpsUpperNode) object).getNodes()) {
+				if (backtrackLostChild(cps, find, lost))
+					return true;
+			}
+			return false;
+		}
+	}
+
 	/**
 	 * Add a Object into a CpsUpperNode
 	 * 

+ 14 - 0
src/ui/controller/UpdateController.java

@@ -14,6 +14,7 @@ import ui.view.DefaulTable;
 import ui.view.Languages;
 import ui.view.PropertyTable;
 import ui.view.UnitGraph;
+import ui.view.UpperNodeCanvas;
 import ui.model.*;
 import ui.controller.*;
 
@@ -206,6 +207,19 @@ public class UpdateController {
 		AbstractCpsObject tempCps = controller.searchByID(tempID);
 		return tempCps;
 	}
+	
+	/**
+	 * Getter for selected CpsObject.
+	 * 
+	 * @return selected CpsObject
+	 */
+	public AbstractCpsObject getActualCpsUpperNode(UpperNodeCanvas canvas) {
+		int tempID = model.getSelectedObjectID();
+		AbstractCpsObject tempCps = controller.searchByIDUpperNode(tempID, canvas.upperNode);
+		return tempCps;
+	}
+	
+	
 
 	public void paintProperties(AbstractCpsObject obj) {
 		if (obj != null) {

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

@@ -118,7 +118,7 @@ public class GUI<E> implements CategoryListener {
 
 	private final JScrollPane canvasSP = new JScrollPane();
 	private final JScrollPane scrollPane1 = new JScrollPane();
-	private final JScrollPane holonSP = new JScrollPane();
+	//private final JScrollPane holonSP = new JScrollPane();
 	private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
 	private final JPanel panelTapped_SimMenu = new JPanel();
 	private JPopupMenu popmenuEdit = new JPopupMenu();
@@ -1112,6 +1112,7 @@ public class GUI<E> implements CategoryListener {
 							canvas.invalidate();
 							canvas.repaint();
 						}
+						controller.calculateStateForCurrentTimeStep();
 						dragging = false;
 					}
 				} catch (Exception eex) {
@@ -1581,7 +1582,7 @@ public class GUI<E> implements CategoryListener {
 		splitPaneCanvasConsole.setLeftComponent(panelTapped_SimMenu);
 		tabbedPane.addTab("View", canvasSP);
 		tabbedPane.addTab("Statistics", statScrollPane);
-		tabbedPane.addTab("Holon", holonSP);
+		tabbedPane.addTab("Holon", holonCanvas);
 
 		splitPaneCanvasConsole.setRightComponent(console);
 		splitPane1.setLeftComponent(splitPaneCanvasConsole);
@@ -1596,7 +1597,7 @@ public class GUI<E> implements CategoryListener {
 		splitGraphHolonEl.setTopComponent(scrollGraph);
 		splitGraphHolonEl.setBottomComponent(scrollElements);
 		canvasSP.setViewportView(canvas);
-		holonSP.setViewportView(holonCanvas);
+		//holonSP.setViewportView(holonCanvas);
 		panelTapped_SimMenu.setLayout(new BorderLayout());
 		panelTapped_SimMenu.add(simMenu, BorderLayout.NORTH);
 		panelTapped_SimMenu.add(tabbedPane);
@@ -1614,7 +1615,7 @@ public class GUI<E> implements CategoryListener {
 		splitGraphHolonEl.setBorder(null);
 		panelHolonEl.setBorder(null);
 		canvasSP.setBorder(null);
-		holonSP.setBorder(null);
+		//holonSP.setBorder(null);
 
 		tableHolonElementScrollPane.setBorder(null);
 

+ 104 - 19
src/ui/view/HolonCanvas.java

@@ -4,15 +4,17 @@
 package ui.view;
 
 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.RenderingHints;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
 
-import javax.swing.ImageIcon;
 import javax.swing.JPanel;
+import javax.swing.Timer;
 
-import classes.HolonObject;
+import classes.HolonBody;
 import classes.SubNet;
 import ui.controller.Control;
 import ui.model.Model;
@@ -23,12 +25,18 @@ import ui.model.Model;
  * @author Gruppe14
  *
  */
-public class HolonCanvas extends JPanel {
+public class HolonCanvas extends JPanel implements ActionListener {
 	private static final long serialVersionUID = 1L;
 	// edge Object Start Point
 	private Model model;
 	private final Control controller;
 	Graphics2D g2; // For Painting
+	private int N;
+	private ArrayList<HolonBody> bodies;
+	private Timer timer = new Timer(33, this);
+	private Dimension center;
+	private ArrayList<SubNet> subnets;
+	private int rx, ry;
 
 	/**
 	 * Constructor.
@@ -41,25 +49,102 @@ public class HolonCanvas extends JPanel {
 	public HolonCanvas(Model mod, Control control) {
 		this.controller = control;
 		this.model = mod;
+		subnets = controller.getSimManager().getSubNets();
+		N = subnets.size();
+		bodies = new ArrayList<>();
+		calcCenter();
+		timer.start();
 	}
 
 	public void paintComponent(Graphics g) {
 		super.paintComponent(g);
-		// Rendering
-		g2 = (Graphics2D) g;
-		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-		g2.setRenderingHints(rh);
+		if (!controller.getSimManager().getSubNets().equals(subnets)) {
+			subnets = controller.getSimManager().getSubNets();
+			N = subnets.size();
+			N += 1;
+			bodies = new ArrayList<>();
+			startthebodies(N);
+		}
+		for (int i = 0; i < N; i++) {
+			g.setColor(bodies.get(i).color);
+			if (i != 0) {
+				g.fillOval(bodies.get(i).rx, bodies.get(i).ry, subnets.get(i - 1).getObjects().size() * 8,
+						subnets.get(i - 1).getObjects().size() * 8);
+			} else
+				g.fillOval(bodies.get(0).rx, bodies.get(0).ry, 0, 0);
+		}
+		addforces(N);
+	}
+
+	// Initialize N bodies with random positions
+	public void startthebodies(int N) {
+		double solarmass = 1.98892e30;
+		calcCenter();
+		// the central mass
+		bodies.add(0, new HolonBody(center.width, center.height, 0, 0, 1e6 * solarmass, new Color(0, 0, 0)));
+		for (int i = 0; i < N - 1; i++) {
+			int px = (int) (Math.random() * 201);
+			int py = (int) (Math.random() * 201);
+
+			double mass = (subnets.get(i).getObjects().size()) / 10 * solarmass * 10 + 1e20;
+			Color color = model.getSubNetColors().get(i);
+			bodies.add(new HolonBody(px, py, 0, 0, mass, color));
+		}
+	}
+
+	// reset the forces, then add all the new forces
+	public void addforces(int N) {
+		for (int i = 0; i < N; i++) {
+			bodies.get(i).resetForce();
+
+			for (int j = 0; j < N; j++) {
+				if (i != j)
+					bodies.get(i).addForce(bodies.get(j));
+			}
+		}
+		// loop again and update the bodies using timestep dt
+		for (int i = 1; i < N; i++) {
+			rx = bodies.get(i).rx;
+			ry = bodies.get(i).ry;
+			bodies.get(i).update(1e-9);
+			if (checkCollison(i)) {
+				bodies.get(i).rx = rx;
+				bodies.get(i).ry = ry;
+				bodies.get(i).vx = 0;
+				bodies.get(i).vy = 0;
+			}
+		}
+	}
 
-		int i = 0;
-		int k = 0;
-		// Objects
-		for (SubNet s : controller.getSimManager().getSubNets()) {
-			// draw image
-			g2.setColor(model.getSubNetColors().get(k));
-			g2.fillOval(10 + i, 10 + i, controller.getScale() * s.getObjects().size() / 4,
-					controller.getScale() * s.getObjects().size() / 4);
-			k += 1;
-			i += 20;
+	// check if body would collide with any other body
+	private boolean checkCollison(int i) {
+		boolean collision = false;
+		int r1 = (subnets.get(i - 1).getObjects().size() * 8) / 2;
+		int r2 = 1;
+		for (int j = 0; j < N; j++) {
+			if (j != i) {
+				int dist = (int) (Math.pow(rx - bodies.get(j).rx, 2) + Math.pow(ry - bodies.get(j).ry, 2));
+				if (j != 0)
+					r2 = (subnets.get(j - 1).getObjects().size() * 8) / 2;
+
+				if (Math.pow(r2 - r1, 2) <= dist && dist <= Math.pow(r2 + r1, 2)) {
+					collision = true;
+				}
+			}
 		}
+		return collision;
 	}
+
+	@Override
+	public void actionPerformed(ActionEvent arg0) {
+		repaint();
+	}
+
+	// calculate center of canvas for center gravity
+	public void calcCenter() {
+		center = this.getSize();
+		center.height /= 2;
+		center.width /= 2;
+	}
+
 }

+ 82 - 32
src/ui/view/MyCanvas.java

@@ -2,6 +2,7 @@ package ui.view;
 
 import java.awt.BasicStroke;
 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.Image;
@@ -88,13 +89,16 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 												// rightclicked
 
 	javax.swing.Timer animT; // animation Timer
-	int animFPS = 30;
-	int animDuration = 500; // animation Duration
-	int animDelay = animDuration/animFPS; // animation Delay
-	int animSteps = animDuration / animDelay; // animation Steps;
-	long start = 0;    
-	long elapsedTime = 0;
-	
+	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 long start = 0; // for time
+	private long elapsedTime = 0; // outprint
+
 	// contains the value of the Capacity for new created Edges
 
 	/**
@@ -140,51 +144,50 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			public void actionPerformed(ActionEvent e) {
 				// calculate uppernode pos (taken from the controller)
 				unPos = new Position(0, 0);
-
-				for (AbstractCpsObject abs : model.getSelectedCpsObjects()) {
-					unPos.x += abs.getPosition().x;
-					unPos.y += abs.getPosition().y;
+				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 /= model.getSelectedCpsObjects().size();
-				unPos.y /= model.getSelectedCpsObjects().size();
+				unPos.x /= animCps.size();
+				unPos.y /= animCps.size();
 
 				// save old Position
 				savePos = new ArrayList<>();
-				for (int i = 0; i < model.getSelectedCpsObjects().size(); i++) {
+				for (int i = 0; i < animCps.size(); i++) {
 					savePos.add(new Position(0, 0));
-					savePos.get(i).x = model.getSelectedCpsObjects().get(i).getPosition().x;
-					savePos.get(i).y = model.getSelectedCpsObjects().get(i).getPosition().y;
+					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 && model.getSelectedCpsObjects().size() > 1) {
-							for (int i = 0; i < model.getSelectedCpsObjects().size(); i++) {
-								double x1 = model.getSelectedCpsObjects().get(i).getPosition().x;
-								double y1 = model.getSelectedCpsObjects().get(i).getPosition().y;
-								x1 = x1 - unPos.x;
-								y1 = y1 - unPos.y;
-								model.getSelectedCpsObjects().get(i).getPosition().x -= x1 / animSteps;
-								model.getSelectedCpsObjects().get(i).getPosition().y -= y1 / animSteps;
+						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 = 500;
-							animSteps = animDuration / animDelay; 
+							animDuration = ANIMTIME;
+							animSteps = animDuration / animDelay;
 							animT.stop();
-							for (int i = 0; i < model.getSelectedCpsObjects().size(); i++) {
-								model.getSelectedCpsObjects().get(i).getPosition().x = savePos.get(i).x;
-								model.getSelectedCpsObjects().get(i).getPosition().y = savePos.get(i).y;
+							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);
+							controller.addUpperNode("NodeOfNode", null, animCps);
 							controller.calculateStateForCurrentTimeStep();
 							repaint();
 							elapsedTime = System.currentTimeMillis() - start;
-							controller.addTextToConsole(elapsedTime+"");
+							controller.addTextToConsole(elapsedTime + "");
 						}
 					}
 				});
@@ -196,8 +199,55 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		itemUngroup.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
+				// save old Position
+				savePos = new ArrayList<>();
+				animCps = ((CpsUpperNode) tempCps).getNodes();
 				controller.delUpperNode((CpsUpperNode) tempCps, null);
-				repaint();
+
+				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();
+							elapsedTime = System.currentTimeMillis() - start;
+							controller.addTextToConsole(elapsedTime + "");
+						}
+					}
+				});
+				start = System.currentTimeMillis();
+				animT.start();
 			}
 		});
 

+ 42 - 13
src/ui/view/StatisticGraphPanel.java

@@ -9,8 +9,11 @@ import ui.model.Model;
 
 import javax.swing.JLabel;
 import javax.swing.JButton;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
 import javax.swing.SwingConstants;
 import javax.swing.Timer;
+import javax.swing.border.Border;
 import javax.swing.text.StyledDocument;
 
 import java.awt.BorderLayout;
@@ -24,8 +27,15 @@ import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
 import java.util.Hashtable;
+
+import javax.imageio.ImageIO;
 import javax.swing.BoxLayout;
+import javax.swing.GroupLayout.Alignment;
+
 import java.awt.GridLayout;
 
 public class StatisticGraphPanel extends JPanel {
@@ -42,13 +52,13 @@ public class StatisticGraphPanel extends JPanel {
 	private final JLabel maximumLabel = new JLabel("0");
 	private JPanel topPanel = new JPanel();
 	private JButton closeButton = new JButton("X");
+	private JButton savImgButton = new JButton("Save as Image");
 
 	// Variables
 	String graphName;
 	private final JPanel legendPanel = new JPanel();
 	private JPanel that;
 	private Hashtable<String, StatisticGraphPanel> graphHashtable;
-	private JPanel tempP; // for makeLegend
 
 	/**
 	 * Constructor.
@@ -69,9 +79,10 @@ public class StatisticGraphPanel extends JPanel {
 
 		// ******************** Component Propertys ***************//
 		// Graph
-		sGraph.setPreferredSize(new Dimension(280, 150));
-		sGraph.setMaximumSize(new Dimension(1000, 150));
+		// this.setPreferredSize(new Dimension(280, 300));
+		sGraph.setPreferredSize(new Dimension(280, 180));
 		sGraph.setMinimumSize(new Dimension(100, 150));
+		// this.setMaximumSize(new Dimension(1000, 1000));
 
 		// Graph Name
 		graphNameLabel = new JLabel(graphName);
@@ -79,17 +90,36 @@ public class StatisticGraphPanel extends JPanel {
 
 		// Panel on top (Name and Close Button)
 		topPanel.setLayout(new BorderLayout(0, 0));
-		topPanel.add(graphNameLabel, BorderLayout.CENTER);
+		topPanel.add(graphNameLabel, BorderLayout.WEST);
 		topPanel.add(closeButton, BorderLayout.EAST);
+		topPanel.add(savImgButton, BorderLayout.CENTER);
+		savImgButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				BufferedImage img = new BufferedImage(that.getWidth(), that.getHeight(), BufferedImage.TYPE_INT_RGB);
+				that.print(img.getGraphics());
+				try {
+					JFileChooser fileChooser = new JFileChooser();
+					if (fileChooser.showSaveDialog(new JFrame()) == JFileChooser.APPROVE_OPTION) {
+						String file = fileChooser.getSelectedFile().getPath();
+						ImageIO.write(img, "jpg", new File(file+".jpg"));
+					}
+				} catch (IOException e1) {
+					// TODO Auto-generated catch block
+					e1.printStackTrace();
+				}
+
+			}
+		});
 		topPanel.setBorder(null);
 
 		// Maximum Label
 		maximumLabel.setVerticalAlignment(SwingConstants.TOP);
 		maximumLabel.setMinimumSize(new Dimension(30, 10));
-		
-		//Legend Panel
+
+		// Legend Panel
 		legendPanel.setLayout(new GridLayout(0, 5, 0, 0));
-		
+
 		// ******************** Component Listener ****************//
 
 		that = this;
@@ -141,18 +171,17 @@ public class StatisticGraphPanel extends JPanel {
 		default:
 			break;
 		}
-		
-		
+
 		JLabel b = new JLabel(set.getCpsObject().getName() + ": " + property);
 		b.setBackground(set.getColor());
-		int color = Math.max(Math.max(set.getColor().getRed(), set.getColor().getGreen()),set.getColor().getBlue());
-		if (color<=128) {
+		int color = Math.max(Math.max(set.getColor().getRed(), set.getColor().getGreen()), set.getColor().getBlue());
+		if (color <= 128) {
 			b.setForeground(Color.WHITE);
 		}
-		
+
 		b.setOpaque(true);
 		b.addMouseListener(new MouseAdapter() {
-		
+
 			@Override
 			public void mousePressed(MouseEvent e) {
 				if (MouseEvent.BUTTON3 == e.getButton()) {

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

@@ -151,7 +151,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		itemGroup.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
-				controller.addUpperNode("NodeOfNode", upperNode);
+				controller.addUpperNode("NodeOfNode", upperNode, model.getSelectedCpsObjects());
 				repaint();
 			}
 		});

+ 302 - 283
src/ui/view/splitPane.java

@@ -53,12 +53,12 @@ import java.awt.FlowLayout;
 import java.awt.BorderLayout;
 
 public class splitPane extends JSplitPane implements GraphListener {
-	//Property Integers
-	public static  final int CONSUMPTION = 0;
+	// Property Integers
+	public static final int CONSUMPTION = 0;
 	public static final int PRODUCTION = 1;
 	public static final int ACTIVATED_ELEMENTS = 2;
 	public static final int ON_OFF = 3;
-	
+
 	private JTextField graphNrTxtField;
 	private JTextField redField;
 	private JTextField greenField;
@@ -78,6 +78,7 @@ public class splitPane extends JSplitPane implements GraphListener {
 
 	JLabel showObjectlbl;
 	JLabel showPropertylbl;
+
 	public splitPane(Control cont) {
 		this.controller = cont;
 		objectHashtable = new Hashtable<String, GraphDataSet>();
@@ -86,25 +87,25 @@ public class splitPane extends JSplitPane implements GraphListener {
 		propValTable.put("total Production", PRODUCTION);
 		propValTable.put("total Consumption", CONSUMPTION);
 		propValTable.put("number of activated Elements", ACTIVATED_ELEMENTS);
-		
-		JScrollPane dataPane = new JScrollPane(); 
+
+		JScrollPane dataPane = new JScrollPane();
 		setLeftComponent(dataPane);
 		JPanel panel = new JPanel();
 		dataPane.setViewportView(panel);
-		
+
 		JScrollPane treeScrollPane = new JScrollPane();
 		JLabel lblObject = new JLabel("Object(s):");
-		
+
 		showObjectlbl = new JLabel("...");
-		
+
 		JLabel lblProperty = new JLabel("Property:");
-		
+
 		showPropertylbl = new JLabel("...");
-		
+
 		JLabel lblGraph = new JLabel("Graph:");
-		
+
 		JLabel lblColor = new JLabel("Color:");
-		
+
 		colorComboBox = new JComboBox();
 		colorComboBox.addItem("");
 		colorComboBox.addItem("Red");
@@ -117,118 +118,129 @@ public class splitPane extends JSplitPane implements GraphListener {
 		colorComboBox.addItem("Pink");
 		colorComboBox.addItem("Gray");
 		colorComboBox.addItem("Random");
-		colorComboBox.addItemListener(new ItemListener(){
+		colorComboBox.addItemListener(new ItemListener() {
 
 			@Override
 			public void itemStateChanged(ItemEvent e) {
 				String colorName = (String) colorComboBox.getSelectedItem();
 				Color tmpColor = Color.WHITE;
-				switch(colorName){
-				case "" : 	tmpColor = currentProperty.getColor();
-							break;
-				case "Red": tmpColor = Color.RED;
-							colorChanged(tmpColor);
-							break;
-				case "Blue":tmpColor = Color.BLUE; 
-							colorChanged(tmpColor);
-							break;
-				case "Green":tmpColor = Color.GREEN;
-							colorChanged(tmpColor);
-							break;
-				case "Yellow":tmpColor = Color.YELLOW; 
-							colorChanged(tmpColor);
-							break;
-				case "Orange":tmpColor = Color.ORANGE; 
-							colorChanged(tmpColor);
-							break;
-				case "Cyan":tmpColor = Color.CYAN; 
-							colorChanged(tmpColor);
-							break;
-				case "Magenta":tmpColor = Color.MAGENTA; 
-							colorChanged(tmpColor);
-							break;	
-				case "Pink":tmpColor = Color.PINK; 
-							colorChanged(tmpColor);
-							break;
-				case "Gray":tmpColor = Color.GRAY; 
-							colorChanged(tmpColor);
-							break;
-				case "Random":Random rdm = new Random(); 
-							tmpColor = new Color(rdm.nextInt(255),rdm.nextInt(255),rdm.nextInt(255));
+				switch (colorName) {
+				case "":
+					tmpColor = currentProperty.getColor();
+					break;
+				case "Red":
+					tmpColor = Color.RED;
+					colorChanged(tmpColor);
+					break;
+				case "Blue":
+					tmpColor = Color.BLUE;
+					colorChanged(tmpColor);
+					break;
+				case "Green":
+					tmpColor = Color.GREEN;
+					colorChanged(tmpColor);
+					break;
+				case "Yellow":
+					tmpColor = Color.YELLOW;
+					colorChanged(tmpColor);
+					break;
+				case "Orange":
+					tmpColor = Color.ORANGE;
+					colorChanged(tmpColor);
+					break;
+				case "Cyan":
+					tmpColor = Color.CYAN;
+					colorChanged(tmpColor);
+					break;
+				case "Magenta":
+					tmpColor = Color.MAGENTA;
+					colorChanged(tmpColor);
+					break;
+				case "Pink":
+					tmpColor = Color.PINK;
+					colorChanged(tmpColor);
+					break;
+				case "Gray":
+					tmpColor = Color.GRAY;
+					colorChanged(tmpColor);
+					break;
+				case "Random":
+					Random rdm = new Random();
+					tmpColor = new Color(rdm.nextInt(255), rdm.nextInt(255), rdm.nextInt(255));
 				}
 				redField.setText(Integer.toString(tmpColor.getRed()));
 				greenField.setText(Integer.toString(tmpColor.getGreen()));
 				blueField.setText(Integer.toString(tmpColor.getBlue()));
 			}
-			
+
 		});
-				
-		//====================GRAPH NR TEXTFIELD======================//
+
+		// ====================GRAPH NR TEXTFIELD======================//
 		graphNrTxtField = new JTextField();
 		graphNrTxtField.setColumns(10);
-		graphNrTxtField.getDocument().addDocumentListener(new DocumentListener(){
+		graphNrTxtField.getDocument().addDocumentListener(new DocumentListener() {
 			/*
-			 * if textField for Red changes, changes will applied in the DataStructure "currentProperty"
-			 * if Value is legit
+			 * if textField for Red changes, changes will applied in the
+			 * DataStructure "currentProperty" if Value is legit
 			 */
 			@Override
 			public void insertUpdate(DocumentEvent e) {
-				if(currentProperty != null){
+				if (currentProperty != null) {
 					currentProperty.setGraph(graphNrTxtField.getText());
 				}
 			}
 
 			@Override
 			public void removeUpdate(DocumentEvent e) {
-				if(currentProperty != null){
+				if (currentProperty != null) {
 					currentProperty.setGraph(graphNrTxtField.getText());
 				}
 			}
 
 			@Override
 			public void changedUpdate(DocumentEvent e) {
-				
+
 			}
 		});
-		
-		//====================GRAPH NR TEXTFIELD END==================//
-		
-		//====================RED TEXTFIELD===========================//
+
+		// ====================GRAPH NR TEXTFIELD END==================//
+
+		// ====================RED TEXTFIELD===========================//
 		redField = new JTextField();
 		redField.setColumns(10);
-		redField.getDocument().addDocumentListener(new DocumentListener(){
+		redField.getDocument().addDocumentListener(new DocumentListener() {
 			/*
-			 * if textField for Red changes, changes will applied in the DataStructure "currentProperty"
-			 * if Value is legit
+			 * if textField for Red changes, changes will applied in the
+			 * DataStructure "currentProperty" if Value is legit
 			 */
 			@Override
 			public void insertUpdate(DocumentEvent e) {
 				int tmp = -1;
-				try{
+				try {
 					tmp = Integer.parseInt(redField.getText());
-				}catch(NumberFormatException e1){
-					
+				} catch (NumberFormatException e1) {
+
 				}
-				if(tmp > -1 && tmp <= 255){
-					if(currentProperty != null){
+				if (tmp > -1 && tmp <= 255) {
+					if (currentProperty != null) {
 						Color oldColor = currentProperty.getColor();
 						Color color = new Color(tmp, oldColor.getGreen(), oldColor.getBlue());
 						currentProperty.setColor(color);
 						colorChanged(color);
 					}
-				}	
+				}
 			}
 
 			@Override
 			public void removeUpdate(DocumentEvent e) {
 				int tmp = -1;
-				try{
+				try {
 					tmp = Integer.parseInt(redField.getText());
-				}catch(NumberFormatException e1){
-					
+				} catch (NumberFormatException e1) {
+
 				}
-				if(tmp > -1 && tmp <= 255){
-					if(currentProperty != null){
+				if (tmp > -1 && tmp <= 255) {
+					if (currentProperty != null) {
 						Color oldColor = currentProperty.getColor();
 						Color color = new Color(tmp, oldColor.getGreen(), oldColor.getBlue());
 						currentProperty.setColor(color);
@@ -239,47 +251,47 @@ public class splitPane extends JSplitPane implements GraphListener {
 
 			@Override
 			public void changedUpdate(DocumentEvent e) {
-	
+
 			}
 		});
-		//======================RED TEXTFIELD END==========================//
-		
-		//======================GREEN TEXTFIELD============================//
+		// ======================RED TEXTFIELD END==========================//
+
+		// ======================GREEN TEXTFIELD============================//
 		greenField = new JTextField();
 		greenField.setColumns(10);
-		greenField.getDocument().addDocumentListener(new DocumentListener(){
+		greenField.getDocument().addDocumentListener(new DocumentListener() {
 			/*
-			 * if textField for Red changes, changes will applied in the DataStructure "currentProperty"
-			 * if Value is legit
+			 * if textField for Red changes, changes will applied in the
+			 * DataStructure "currentProperty" if Value is legit
 			 */
 			@Override
 			public void insertUpdate(DocumentEvent e) {
 				int tmp = -1;
-				try{
+				try {
 					tmp = Integer.parseInt(greenField.getText());
-				}catch(NumberFormatException e1){
-					
+				} catch (NumberFormatException e1) {
+
 				}
-				if(tmp > -1 && tmp <= 255){
-					if(currentProperty != null){
+				if (tmp > -1 && tmp <= 255) {
+					if (currentProperty != null) {
 						Color oldColor = currentProperty.getColor();
 						Color color = new Color(oldColor.getRed(), tmp, oldColor.getBlue());
 						currentProperty.setColor(color);
 						colorChanged(color);
 					}
-				}	
+				}
 			}
 
 			@Override
 			public void removeUpdate(DocumentEvent e) {
 				int tmp = -1;
-				try{
+				try {
 					tmp = Integer.parseInt(greenField.getText());
-				}catch(NumberFormatException e1){
-					
+				} catch (NumberFormatException e1) {
+
 				}
-				if(tmp > -1 && tmp <= 255){
-					if(currentProperty != null){
+				if (tmp > -1 && tmp <= 255) {
+					if (currentProperty != null) {
 						Color oldColor = currentProperty.getColor();
 						Color color = new Color(oldColor.getRed(), tmp, oldColor.getBlue());
 						currentProperty.setColor(color);
@@ -290,47 +302,47 @@ public class splitPane extends JSplitPane implements GraphListener {
 
 			@Override
 			public void changedUpdate(DocumentEvent e) {
-				
+
 			}
 		});
-		//======================GREEN TEXTFIELD END========================//
-		
-		//======================BLUE TEXTFIELD=============================//
+		// ======================GREEN TEXTFIELD END========================//
+
+		// ======================BLUE TEXTFIELD=============================//
 		blueField = new JTextField();
 		blueField.setColumns(10);
-		blueField.getDocument().addDocumentListener(new DocumentListener(){
+		blueField.getDocument().addDocumentListener(new DocumentListener() {
 			/*
-			 * if textField for Red changes, changes will applied in the DataStructure "currentProperty"
-			 * if Value is legit
+			 * if textField for Red changes, changes will applied in the
+			 * DataStructure "currentProperty" if Value is legit
 			 */
 			@Override
 			public void insertUpdate(DocumentEvent e) {
 				int tmp = -1;
-				try{
+				try {
 					tmp = Integer.parseInt(blueField.getText());
-				}catch(NumberFormatException e1){
-					
+				} catch (NumberFormatException e1) {
+
 				}
-				if(tmp > -1 && tmp <= 255){
-					if(currentProperty != null){
+				if (tmp > -1 && tmp <= 255) {
+					if (currentProperty != null) {
 						Color oldColor = currentProperty.getColor();
 						Color color = new Color(oldColor.getRed(), oldColor.getGreen(), tmp);
 						currentProperty.setColor(color);
 						colorChanged(color);
 					}
-				}	
+				}
 			}
 
 			@Override
 			public void removeUpdate(DocumentEvent e) {
 				int tmp = -1;
-				try{
+				try {
 					tmp = Integer.parseInt(blueField.getText());
-				}catch(NumberFormatException e1){
-					
+				} catch (NumberFormatException e1) {
+
 				}
-				if(tmp > -1 && tmp <= 255){
-					if(currentProperty != null){
+				if (tmp > -1 && tmp <= 255) {
+					if (currentProperty != null) {
 						Color oldColor = currentProperty.getColor();
 						Color color = new Color(oldColor.getRed(), oldColor.getGreen(), tmp);
 						currentProperty.setColor(color);
@@ -341,130 +353,131 @@ public class splitPane extends JSplitPane implements GraphListener {
 
 			@Override
 			public void changedUpdate(DocumentEvent e) {
-				
+
 			}
 		});
-		//======================BLUE TEXTFIELD END=========================//
-		
+		// ======================BLUE TEXTFIELD END=========================//
+
 		JLabel lblR = new JLabel("R:");
-		
+
 		JLabel lblG = new JLabel("G:");
-		
+
 		JLabel lblB = new JLabel("B:");
-		
+
 		JButton btnAdd = new JButton("Add");
 		btnAdd.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
-				 DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)objectTree.getLastSelectedPathComponent();
-				 if(selectedNode == null){
-					 return;
-				 }else{
-					 if(selectedNode.getLevel() == 3){
-						 StatisticGraphPanel tmp = null;
-						 if(graphNrTxtField.getText().length() > 0){
-							 if(!graphHashtable.containsKey(graphNrTxtField.getText()) && graphNrTxtField.getText().length() > 0){
-								 tmp = new StatisticGraphPanel(controller.getModel(), controller, graphNrTxtField.getText(), 
-										 graphHashtable);
-								 tmp.setPreferredSize(new Dimension(280,150));
-								 tmp.setMaximumSize(new Dimension(1000,150));
-								 tmp.setMinimumSize(new Dimension(100,45));
-								 tmp.setBorder(new LineBorder(new Color(0, 0, 0), 1));
-								 graphPanel.add(tmp);
-								 graphPanel.add(Box.createRigidArea(new Dimension(50,50)));
-								 graphPanel.revalidate();
-								 graphPanel.updateUI();
-								 graphHashtable.put(graphNrTxtField.getText(), tmp);
-						 		}
-							String object = ((DefaultMutableTreeNode)selectedNode.getParent()).toString();
+				DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) objectTree
+						.getLastSelectedPathComponent();
+				if (selectedNode == null) {
+					return;
+				} else {
+					if (selectedNode.getLevel() == 3) {
+						StatisticGraphPanel tmp = null;
+						if (graphNrTxtField.getText().length() > 0) {
+							if (!graphHashtable.containsKey(graphNrTxtField.getText())
+									&& graphNrTxtField.getText().length() > 0) {
+								tmp = new StatisticGraphPanel(controller.getModel(), controller,
+										graphNrTxtField.getText(), graphHashtable);
+								//tmp.setPreferredSize(new Dimension(280, 150));
+								//tmp.setMaximumSize(new Dimension(1000, 1000));
+								// tmp.setMinimumSize(new Dimension(100, 45));
+								tmp.setBorder(new LineBorder(new Color(0, 0, 0), 1));
+								graphPanel.add(tmp);
+								graphPanel.add(Box.createRigidArea(new Dimension(50, 50)));
+								graphPanel.revalidate();
+								graphPanel.updateUI();
+								graphHashtable.put(graphNrTxtField.getText(), tmp);
+							}
+							String object = ((DefaultMutableTreeNode) selectedNode.getParent()).toString();
 							String property = selectedNode.toString();
 							GraphDataSet dataSet = objectHashtable.get(object);
-							TrackedDataSet tds = new TrackedDataSet(dataSet.getObject(), propValTable.get(property), currentProperty.getColor());
+							TrackedDataSet tds = new TrackedDataSet(dataSet.getObject(), propValTable.get(property),
+									currentProperty.getColor());
 							graphHashtable.get(graphNrTxtField.getText()).addObjec(tds);
-						 }
-					 }
-				 }
+						}
+					}
+				}
 			}
 		});
-		
+
 		colorPanel = new JPanel();
 		colorPanel.setBorder(new LineBorder(new Color(0, 0, 0)));
 		colorPanel.setBackground(Color.WHITE);
 		GroupLayout gl_panel = new GroupLayout(panel);
-		gl_panel.setHorizontalGroup(
-			gl_panel.createParallelGroup(Alignment.LEADING)
-				.addGroup(gl_panel.createSequentialGroup()
-					.addContainerGap()
-					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
-						.addComponent(treeScrollPane, Alignment.LEADING)
-						.addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
-							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
-								.addComponent(lblGraph)
-								.addComponent(lblObject)
-								.addComponent(lblProperty)
-								.addComponent(lblColor)
-								.addGroup(gl_panel.createSequentialGroup()
-									.addComponent(lblR)
-									.addPreferredGap(ComponentPlacement.RELATED)
-									.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
-										.addComponent(colorPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-										.addComponent(redField, GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE))))
-							.addPreferredGap(ComponentPlacement.RELATED)
-							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
-								.addComponent(showObjectlbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-								.addComponent(showPropertylbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-								.addComponent(colorComboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-								.addComponent(graphNrTxtField)
-								.addGroup(gl_panel.createSequentialGroup()
-									.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
-										.addComponent(btnAdd)
-										.addGroup(gl_panel.createSequentialGroup()
-											.addComponent(lblG)
-											.addPreferredGap(ComponentPlacement.RELATED)
-											.addComponent(greenField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)))
-									.addPreferredGap(ComponentPlacement.RELATED)
-									.addComponent(lblB)
-									.addPreferredGap(ComponentPlacement.RELATED)
-									.addComponent(blueField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)))))
-					.addGap(32))
-		);
+		gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING)
+				.addGroup(gl_panel.createSequentialGroup().addContainerGap().addGroup(gl_panel
+						.createParallelGroup(Alignment.TRAILING, false).addComponent(treeScrollPane,
+								Alignment.LEADING)
+						.addGroup(Alignment.LEADING,
+								gl_panel.createSequentialGroup()
+										.addGroup(gl_panel.createParallelGroup(Alignment.LEADING).addComponent(lblGraph)
+												.addComponent(lblObject).addComponent(lblProperty)
+												.addComponent(lblColor)
+												.addGroup(gl_panel.createSequentialGroup().addComponent(lblR)
+														.addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_panel
+																.createParallelGroup(Alignment.LEADING, false)
+																.addComponent(colorPanel, GroupLayout.DEFAULT_SIZE,
+																		GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+																.addComponent(redField, GroupLayout.DEFAULT_SIZE, 37,
+																		Short.MAX_VALUE))))
+										.addPreferredGap(ComponentPlacement.RELATED)
+										.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
+												.addComponent(showObjectlbl, GroupLayout.DEFAULT_SIZE,
+														GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+												.addComponent(showPropertylbl, GroupLayout.DEFAULT_SIZE,
+														GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+												.addComponent(colorComboBox, 0, GroupLayout.DEFAULT_SIZE,
+														Short.MAX_VALUE)
+												.addComponent(graphNrTxtField)
+												.addGroup(gl_panel.createSequentialGroup().addGroup(gl_panel
+														.createParallelGroup(Alignment.TRAILING).addComponent(btnAdd)
+														.addGroup(gl_panel.createSequentialGroup().addComponent(lblG)
+																.addPreferredGap(ComponentPlacement.RELATED)
+																.addComponent(greenField, GroupLayout.PREFERRED_SIZE,
+																		37, GroupLayout.PREFERRED_SIZE)))
+														.addPreferredGap(ComponentPlacement.RELATED).addComponent(lblB)
+														.addPreferredGap(ComponentPlacement.RELATED)
+														.addComponent(blueField, GroupLayout.PREFERRED_SIZE, 37,
+																GroupLayout.PREFERRED_SIZE)))))
+						.addGap(32)));
 		gl_panel.setVerticalGroup(
-			gl_panel.createParallelGroup(Alignment.LEADING)
-				.addGroup(gl_panel.createSequentialGroup()
-					.addContainerGap()
-					.addComponent(treeScrollPane, GroupLayout.PREFERRED_SIZE, 174, GroupLayout.PREFERRED_SIZE)
-					.addPreferredGap(ComponentPlacement.RELATED)
-					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
-						.addComponent(lblObject, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
-						.addComponent(showObjectlbl))
-					.addPreferredGap(ComponentPlacement.RELATED)
-					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
-						.addComponent(lblProperty)
-						.addComponent(showPropertylbl))
-					.addPreferredGap(ComponentPlacement.RELATED)
-					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
-						.addComponent(lblGraph)
-						.addComponent(graphNrTxtField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
-					.addPreferredGap(ComponentPlacement.RELATED)
-					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
-						.addComponent(lblColor)
-						.addComponent(colorComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
-					.addGap(18)
-					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
-						.addComponent(lblR)
-						.addComponent(redField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
-						.addComponent(lblG)
-						.addComponent(greenField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
-						.addComponent(lblB)
-						.addComponent(blueField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
-					.addPreferredGap(ComponentPlacement.RELATED)
-					.addComponent(colorPanel, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
-					.addPreferredGap(ComponentPlacement.RELATED)
-					.addComponent(btnAdd)
-					.addContainerGap(35, Short.MAX_VALUE))
-		);
-		
+				gl_panel.createParallelGroup(Alignment.LEADING)
+						.addGroup(gl_panel.createSequentialGroup().addContainerGap()
+								.addComponent(treeScrollPane, GroupLayout.PREFERRED_SIZE, 174,
+										GroupLayout.PREFERRED_SIZE)
+								.addPreferredGap(ComponentPlacement.RELATED)
+								.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
+										.addComponent(lblObject, GroupLayout.PREFERRED_SIZE, 14,
+												GroupLayout.PREFERRED_SIZE)
+										.addComponent(showObjectlbl))
+								.addPreferredGap(ComponentPlacement.RELATED)
+								.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(lblProperty)
+										.addComponent(showPropertylbl))
+								.addPreferredGap(ComponentPlacement.RELATED)
+								.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(lblGraph)
+										.addComponent(graphNrTxtField, GroupLayout.PREFERRED_SIZE,
+												GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+								.addPreferredGap(ComponentPlacement.RELATED)
+								.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(lblColor)
+										.addComponent(colorComboBox, GroupLayout.PREFERRED_SIZE,
+												GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+								.addGap(18)
+								.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(lblR)
+										.addComponent(redField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
+												GroupLayout.PREFERRED_SIZE)
+										.addComponent(lblG)
+										.addComponent(greenField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
+												GroupLayout.PREFERRED_SIZE)
+										.addComponent(lblB).addComponent(blueField, GroupLayout.PREFERRED_SIZE,
+												GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+								.addPreferredGap(ComponentPlacement.RELATED)
+								.addComponent(colorPanel, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
+								.addPreferredGap(ComponentPlacement.RELATED).addComponent(btnAdd)
+								.addContainerGap(35, Short.MAX_VALUE)));
+
 		objectTree = new JTree();
-		treeModel = (DefaultTreeModel)objectTree.getModel();
+		treeModel = (DefaultTreeModel) objectTree.getModel();
 		DefaultMutableTreeNode root = new DefaultMutableTreeNode("Statistics");
 		wholeHolon = new DefaultMutableTreeNode("whole Holon");
 		wholeHolon.add(new DefaultMutableTreeNode("total Production"));
@@ -475,84 +488,86 @@ public class splitPane extends JSplitPane implements GraphListener {
 
 		objectsNode = new DefaultMutableTreeNode("Objects");
 		DefaultMutableTreeNode defaultNode = new DefaultMutableTreeNode("empty");
-	
+
 		objectsNode.add(defaultNode);
 		treeModel.setRoot(root);
 		root.add(wholeHolon);
 		root.add(objectsNode);
 		objectTree.setModel(treeModel);
-		
+
 		treeScrollPane.setViewportView(objectTree);
-		
+
 		JPopupMenu popupMenu = new JPopupMenu();
 		addPopup(objectTree, popupMenu);
-		
+
 		JMenuItem mntmUntrack = new JMenuItem("Untrack");
 		mntmUntrack.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
-				 DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)objectTree.getLastSelectedPathComponent();
-				 if(selectedNode.getLevel() == 2 && !selectedNode.getParent().toString().equals("whole Holon")){
-					 String object = selectedNode.toString();
-					 controller.removeTrackingObj((HolonObject)objectHashtable.get(object).getObject());
-				 }
+				DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) objectTree
+						.getLastSelectedPathComponent();
+				if (selectedNode.getLevel() == 2 && !selectedNode.getParent().toString().equals("whole Holon")) {
+					String object = selectedNode.toString();
+					controller.removeTrackingObj((HolonObject) objectHashtable.get(object).getObject());
+				}
 			}
 		});
 		popupMenu.add(mntmUntrack);
-		
-		objectTree.addTreeSelectionListener(new TreeSelectionListener(){
+
+		objectTree.addTreeSelectionListener(new TreeSelectionListener() {
 
 			@Override
 			public void valueChanged(TreeSelectionEvent e) {
 				resetFields();
 				showObjectlbl.setText("...");
 				showPropertylbl.setText("...");
-				 DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)objectTree.getLastSelectedPathComponent();
-				 if(selectedNode == null){
-					 return;
-				 }else{
-					 if(selectedNode.getLevel() == 0){
-						 disableFields();
-					 }
-					 if(selectedNode.getLevel() == 1){
-						 disableFields();
-						 currentProperty = null;
-						 showObjectlbl.setText(selectedNode.toString());
-					 }
-					 if(selectedNode.getLevel() == 2){
-						 if(((DefaultMutableTreeNode)selectedNode.getParent()).toString().equals("whole Holon")){
-							 enableFields();
-							 showPropertylbl.setText(selectedNode.toString());
-							 showObjectlbl.setText(selectedNode.getParent().toString());
-						 }else{
-							 disableFields();
-							 currentProperty = null;
-							 showObjectlbl.setText(selectedNode.toString());
-						 }
-					 }
-					 if(selectedNode.getLevel() == 3){
-						 enableFields();
-						 String object = ((DefaultMutableTreeNode)selectedNode.getParent()).toString();
-						 String property = selectedNode.toString();
-						 currentProperty = objectHashtable.get(object).getPropertytTable().get(property);
-						 Color color = currentProperty.getColor();
-						 redField.setText(Integer.toString(color.getRed()));
-						 greenField.setText(Integer.toString(color.getGreen()));
-						 blueField.setText(Integer.toString(color.getBlue()));
-						 
-						 showObjectlbl.setText(object);
-						 showPropertylbl.setText(property);
-						 graphNrTxtField.setText(currentProperty.getAssignedGraph());
-						 colorPanel.setBackground(color);
-					 }
-				 }
+				DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) objectTree
+						.getLastSelectedPathComponent();
+				if (selectedNode == null) {
+					return;
+				} else {
+					if (selectedNode.getLevel() == 0) {
+						disableFields();
+					}
+					if (selectedNode.getLevel() == 1) {
+						disableFields();
+						currentProperty = null;
+						showObjectlbl.setText(selectedNode.toString());
+					}
+					if (selectedNode.getLevel() == 2) {
+						if (((DefaultMutableTreeNode) selectedNode.getParent()).toString().equals("whole Holon")) {
+							enableFields();
+							showPropertylbl.setText(selectedNode.toString());
+							showObjectlbl.setText(selectedNode.getParent().toString());
+						} else {
+							disableFields();
+							currentProperty = null;
+							showObjectlbl.setText(selectedNode.toString());
+						}
+					}
+					if (selectedNode.getLevel() == 3) {
+						enableFields();
+						String object = ((DefaultMutableTreeNode) selectedNode.getParent()).toString();
+						String property = selectedNode.toString();
+						currentProperty = objectHashtable.get(object).getPropertytTable().get(property);
+						Color color = currentProperty.getColor();
+						redField.setText(Integer.toString(color.getRed()));
+						greenField.setText(Integer.toString(color.getGreen()));
+						blueField.setText(Integer.toString(color.getBlue()));
+
+						showObjectlbl.setText(object);
+						showPropertylbl.setText(property);
+						graphNrTxtField.setText(currentProperty.getAssignedGraph());
+						colorPanel.setBackground(color);
+					}
+				}
 			}
-			
+
 		});
 		panel.setLayout(gl_panel);
-		
+
 		JScrollPane graphScrollPane = new JScrollPane();
 		setRightComponent(graphScrollPane);
-		
+
 		graphPanel = new JPanel();
 		graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS));
 		graphPanel.revalidate();
@@ -560,16 +575,18 @@ public class splitPane extends JSplitPane implements GraphListener {
 		graphScrollPane.setViewportView(graphPanel);
 		repaintTree();
 	}
+
 	@Override
 	public void repaintTree() {
 		treeModel.reload();
 	}
+
 	@Override
 	public void addTrackedObject(ArrayList<HolonObject> hlList) {
 		objectsNode.removeAllChildren();
 		objectHashtable.clear();
-		if(hlList.size() > 0 && hlList != null){
-			for(HolonObject hO : hlList){
+		if (hlList.size() > 0 && hlList != null) {
+			for (HolonObject hO : hlList) {
 				Hashtable<String, PropertyDataSet> tmpHash = new Hashtable<String, PropertyDataSet>();
 				String name = hO.getName() + " " + hO.getID();
 				DefaultMutableTreeNode tmp = new DefaultMutableTreeNode(name);
@@ -583,26 +600,26 @@ public class splitPane extends JSplitPane implements GraphListener {
 				objectHashtable.put(name, gS);
 				objectsNode.add(tmp);
 			}
-		}else{
+		} else {
 			objectsNode.add(new DefaultMutableTreeNode("empty"));
 		}
-		
+
 	}
-	
-	public void colorChanged(Color color){
+
+	public void colorChanged(Color color) {
 		colorPanel.setBackground(color);
 	}
-	
-	public void resetFields(){
+
+	public void resetFields() {
 		colorPanel.setBackground(Color.WHITE);
 		redField.setText("");
 		greenField.setText("");
 		blueField.setText("");
-		//graphNrTxtField.setText("");
+		// graphNrTxtField.setText("");
 		colorComboBox.setSelectedIndex(0);
 	}
-	
-	public void disableFields(){
+
+	public void disableFields() {
 		redField.setEnabled(false);
 		greenField.setEnabled(false);
 		blueField.setEnabled(false);
@@ -610,8 +627,8 @@ public class splitPane extends JSplitPane implements GraphListener {
 		colorComboBox.setEnabled(false);
 		colorPanel.setBackground(Color.LIGHT_GRAY);
 	}
-	
-	public void enableFields(){
+
+	public void enableFields() {
 		redField.setEnabled(true);
 		greenField.setEnabled(true);
 		blueField.setEnabled(true);
@@ -619,13 +636,13 @@ public class splitPane extends JSplitPane implements GraphListener {
 		colorComboBox.setEnabled(true);
 		colorPanel.setBackground(Color.WHITE);
 	}
-	
-	public void repaintGraphs(){
-		for(StatisticGraphPanel sg: graphHashtable.values()){
+
+	public void repaintGraphs() {
+		for (StatisticGraphPanel sg : graphHashtable.values()) {
 			sg.repaint();
 		}
 	}
-	
+
 	private static void addPopup(Component component, final JPopupMenu popup) {
 		component.addMouseListener(new MouseAdapter() {
 			public void mousePressed(MouseEvent e) {
@@ -633,11 +650,13 @@ public class splitPane extends JSplitPane implements GraphListener {
 					showMenu(e);
 				}
 			}
+
 			public void mouseReleased(MouseEvent e) {
 				if (e.isPopupTrigger()) {
 					showMenu(e);
 				}
 			}
+
 			private void showMenu(MouseEvent e) {
 				popup.show(e.getComponent(), e.getX(), e.getY());
 			}