소스 검색

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

dominik.rieder 7 년 전
부모
커밋
8527bf5316

+ 12 - 11
.classpath

@@ -1,11 +1,12 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="src" path="res"/>
-	<classpathentry excluding="src/|res/" kind="src" path=""/>
-	<classpathentry kind="lib" path="jars/json-simple-1.1.1.jar"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
-	<classpathentry kind="lib" path="jars/CpsAlgorithm.jar"/>
-	<classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="res"/>
+	<classpathentry excluding="src/|res/" kind="src" path=""/>
+	<classpathentry kind="lib" path="jars/json-simple-1.1.1.jar"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+	<classpathentry kind="lib" path="jars/CpsAlgorithm.jar"/>
+	<classpathentry kind="lib" path="jars/gson-2.8.0.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

BIN
jars/gson-2.8.0.jar


+ 49 - 0
src/TypeAdapter/AbstractCpsObjectAdapter.java

@@ -0,0 +1,49 @@
+package TypeAdapter;
+
+import java.lang.reflect.Type;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+
+import classes.AbstractCpsObject;
+
+public class AbstractCpsObjectAdapter implements JsonSerializer<AbstractCpsObject>, JsonDeserializer<AbstractCpsObject>{
+
+	
+	@Override
+	public JsonElement serialize(AbstractCpsObject arg0, Type arg1, JsonSerializationContext arg2) {
+		// TODO Auto-generated method stub
+		JsonObject object = new JsonObject();
+		object.add("type", new JsonPrimitive(arg0.getClass().getSimpleName()));
+		object.add("properties", arg2.serialize(arg0,arg0.getClass()));
+
+		return object;
+	}
+	
+	
+	@Override
+	public AbstractCpsObject deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
+			throws JsonParseException {
+		// TODO Auto-generated method stub
+		JsonObject object = arg0.getAsJsonObject();
+		String type = object.get("type").getAsString();
+		JsonElement element = object.get("properties");
+		try {
+			String packageName = "classes.";
+			return arg2.deserialize(element, Class.forName(packageName+type));
+		} catch (ClassNotFoundException cnfe) {
+			// TODO: handle exception
+			throw new JsonParseException("Unknown element type: " + type, cnfe);
+		}
+
+	}
+
+
+
+}

+ 39 - 0
src/TypeAdapter/PositionAdapter.java

@@ -0,0 +1,39 @@
+package TypeAdapter;
+
+import java.lang.reflect.Type;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+
+import classes.Position;
+
+public class PositionAdapter implements JsonSerializer<Position>, JsonDeserializer<Position> {
+
+	@Override
+	public JsonElement serialize(Position arg0, Type arg1, JsonSerializationContext arg2) {
+		// TODO Auto-generated method stub
+		return new JsonPrimitive(arg0.x + ":" + arg0.y);
+	}
+
+	@Override
+	public Position deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) {
+		// TODO Auto-generated method stub
+		try {
+			String arg = arg0.getAsString();
+			int mid = arg.indexOf(':');
+			int x = Integer.parseInt(arg.substring(0, mid));
+			int y = Integer.parseInt(arg.substring(mid + 1, arg.length() - 1));
+			return new Position(x, y);
+
+		} catch (Exception e) {
+			// TODO: handle exception
+		}
+		return new Position(-1, -1);
+	}
+
+}

+ 27 - 18
src/classes/AbstractCpsObject.java

@@ -3,6 +3,8 @@ package classes;
 import java.awt.Color;
 import java.util.ArrayList;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * The abstract class "CpsObject" represents any possible object in the system
  * (except Edges). The representation of any object contains following
@@ -13,21 +15,27 @@ import java.util.ArrayList;
  */
 public abstract class AbstractCpsObject {
 	/* Type of the Object. */
+	@Expose
 	String objName;
 	/* Name given by the user. */
+	@Expose
 	String name;
 	/* ID of the Obj. */
+	@Expose
 	int id;
 	/* Path of the image for the Obj. */
+	@Expose
 	String image;
 	/* Array of neighbors */
 	ArrayList<CpsEdge> connections;
 	/* Position with a X and Y value */
+	@Expose
 	Position position;
 	/*
 	 * Energy input and output of each object in the grid Where the Object is
 	 * Stored
 	 */
+	@Expose
 	String sav;
 	/* borderColor the user sets */
 	Color borderColor = Color.WHITE;
@@ -35,7 +43,7 @@ public abstract class AbstractCpsObject {
 	ArrayList<Integer> tags;
 	/* a Tag that can be used */
 	ArrayList<Integer> pseudoTags;
-	
+
 	/**
 	 * Constructor for a CpsObejct with an unique ID.
 	 * 
@@ -244,7 +252,7 @@ public abstract class AbstractCpsObject {
 	 * Set the Border Color of this CpsObject.
 	 * 
 	 * @param c
-	 *          the BorderColor
+	 *            the BorderColor
 	 */
 	public void setBorderColor(Color c) {
 		this.borderColor = c;
@@ -257,13 +265,13 @@ public abstract class AbstractCpsObject {
 	 *            for internal purpose
 	 */
 	public void addTag(int tag) {
-		if(!(tags.contains(tag))){
+		if (!(tags.contains(tag))) {
 			this.tags.add(tag);
 		}
 	}
-	
-	public void addAllTags(ArrayList<Integer> tags){
-		for(Integer tag: tags){
+
+	public void addAllTags(ArrayList<Integer> tags) {
+		for (Integer tag : tags) {
 			addTag(tag);
 		}
 	}
@@ -302,9 +310,9 @@ public abstract class AbstractCpsObject {
 	 *            for internal purpose
 	 */
 	public void setPseudoTags(ArrayList<Integer> tags) {
-		this.pseudoTags= tags;
+		this.pseudoTags = tags;
 	}
-	
+
 	/**
 	 * Get the pseudo tags.
 	 * 
@@ -313,37 +321,38 @@ public abstract class AbstractCpsObject {
 	public ArrayList<Integer> getPseudoTags() {
 		return this.pseudoTags;
 	}
-	
+
 	/**
 	 * add a pseudo tag.
 	 * 
 	 * @return ArrayList
 	 */
 	public void addPseudoTag(int tag) {
-		if(!pseudoTags.contains(tag)){
+		if (!pseudoTags.contains(tag)) {
 			pseudoTags.add(tag);
 		}
 	}
-	
+
 	/**
 	 * adds all given pseudotags to the tags
+	 * 
 	 * @param pseudoTags
 	 */
-	public void addAllPseudoTags(ArrayList<Integer> pseudoTags){
-		for(Integer tag: pseudoTags){
+	public void addAllPseudoTags(ArrayList<Integer> pseudoTags) {
+		for (Integer tag : pseudoTags) {
 			addPseudoTag(tag);
 		}
 	}
-	
+
 	/**
 	 * adds All pseudoTags to tags without duplicates
 	 */
-	public void recalculateTags(){
-		for(Integer tag: pseudoTags){
-			if(!tags.contains(tag)){
+	public void recalculateTags() {
+		for (Integer tag : pseudoTags) {
+			if (!tags.contains(tag)) {
 				tags.add(tag);
 			}
 		}
 	}
-	
+
 }

+ 3 - 0
src/classes/Category.java

@@ -3,6 +3,8 @@ package classes;
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * Class "Category" performs the functionality of listing elements into groups.
  * Each Category contains an ArrayList of CpsObjects, a name and a HashMap of
@@ -16,6 +18,7 @@ public class Category {
 	// objects: is a ArrayList of all Objects that belongs to the Category
 	private ArrayList<AbstractCpsObject> objects;
 	// name: is a String chosen by the User
+	@Expose
 	private String name; 
 	// ObjIdx: Index of each Category that corresponds to the order in the tree
 	private HashMap<String, Integer> objIdx;

+ 8 - 0
src/classes/CpsEdge.java

@@ -2,6 +2,8 @@ package classes;
 
 import java.util.ArrayList;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * The class "CpsEdge" represents the connections on the GUI. Each connection
  * contains a max. capacity, a flow, a status (isWorking), tags (for internal
@@ -14,8 +16,10 @@ public class CpsEdge {
 
 	// Max. capacity of the Edge, if flow is greater than the status --> is
 	// Working would be false
+	@Expose
 	float maxCapacity;
 	// Current flow of electricity (through the edge)
+	@Expose
 	float flow;
 	/*
 	 * Represents the actual status of the Edge (true = flows electricity; false
@@ -23,20 +27,24 @@ public class CpsEdge {
 	 * it breaks --> stay ruin no matter the actual scenario The only way to
 	 * repair it is through manual change (setStateEdge)
 	 */
+	@Expose
 	boolean isWorking;
 	
 	/*
 	 * Is true when a Connection to an Group Object, is connected inside the Group. 
 	 * Is false when not
 	 */
+	@Expose
 	boolean isConnected;
 	// for internal use --> flow of electricity (simulation state)
 	ArrayList<Integer> tags;
 	// for internal use --> flow of electricity (simulation state)
 	ArrayList<Integer> pseudoTags;
 	// Source
+	@Expose
 	AbstractCpsObject a;
 	// Destination
+	@Expose
 	AbstractCpsObject b;
 
 	/**

BIN
src/classes/HolonBody.class


+ 2 - 2
src/classes/HolonBody.java

@@ -33,14 +33,14 @@ public class HolonBody implements Comparable<HolonBody> {
 		this.color = color;
 	}
 
-	public void draw(Graphics2D g2) {
+	public void draw(Graphics2D g2, String info) {
 
 		g2.setColor(color);
 		g2.fillOval((int) (position.getX() - getRadius()), (int) (position.getY() - getRadius()),
 				(int) (2 * getRadius()), (int) (2 * getRadius()));
 		g2.setFont(new Font("TimesRoman", Font.PLAIN, (int) radius));
 		g2.setColor(Color.WHITE);
-		g2.drawString("" + id, position.getX() - radius / 2 + 2, position.getY() + radius / 2 - 2);
+		g2.drawString(info, position.getX() - radius / 2 + 2, position.getY() + radius / 2 - 2);
 
 	}
 

+ 11 - 0
src/classes/HolonElement.java

@@ -3,6 +3,8 @@ package classes;
 import java.awt.Point;
 import java.util.LinkedList;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * The class "HolonElement" represents any possible element that can be added to
  * a CpsObject (such as TV (consumer) or any energy source/producer).
@@ -13,22 +15,31 @@ import java.util.LinkedList;
 public class HolonElement {
 
 	/* Name of the gadget */
+	@Expose
 	private String eleName;
 	/* Quantity */
+	@Expose
 	private int amount;
 	/* Energy per gadget */
+	@Expose
 	private float energy;
 	/* If the gadget is working xor not (true xor false) */
+	@Expose
 	private boolean active;
+	@Expose
 	/* Total Energy */
 	private float totalEnergy;
 	/* +: for Consumers and -: Producers */
+	@Expose
 	private char sign;
 	/* Place where the Object is Stored */
+	@Expose
 	private String sav;
 	/* Object where the Element is Stored */
+	@Expose
 	private String obj;
 	/* Unique Id of the Element */
+	@Expose
 	private int id; 
 	/*
 	 * Energy at each point of the graph with 100 predefined points. At the

+ 5 - 0
src/classes/HolonSwitch.java

@@ -3,6 +3,8 @@ package classes;
 import java.awt.Point;
 import java.util.LinkedList;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * The class HolonSwitch represents a Switch, which can be turned on and off.
  * 
@@ -23,17 +25,20 @@ public class HolonSwitch extends AbstractCpsObject {
 	 * manual state True, if this wire is working (capable of carrying
 	 * electricity), else false
 	 */
+	@Expose
 	boolean manualActive;
 
 	/*
 	 * active state True, if this wire is working (capable of carrying
 	 * electricity), else false
 	 */
+	@Expose
 	boolean autoActive;
 
 	/*
 	 * true if switch has to be used manually
 	 */
+	@Expose
 	boolean manualMode;
 
 	/*

+ 3 - 0
src/classes/IdCounter.java

@@ -1,11 +1,14 @@
 package classes;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * ID-Counter for all Cps Objects.
  * 
  * @author Gruppe14
  */
 public class IdCounter {
+	@Expose
 	private static int counter = 1;
 
 	/**

+ 3 - 0
src/classes/IdCounterElem.java

@@ -1,11 +1,14 @@
 package classes;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * ID-Counter for all Holon Elements.
  * 
  * @author Gruppe14
  */
 public class IdCounterElem {
+	@Expose
 	private static int counter = 1;
 
 	/**

+ 61 - 6
src/ui/controller/CanvasController.java

@@ -2,7 +2,7 @@ package ui.controller;
 
 import java.awt.Point;
 import java.util.ArrayList;
-
+import sun.misc.Queue;
 import classes.CpsEdge;
 import classes.CpsNode;
 import classes.CpsUpperNode;
@@ -12,7 +12,6 @@ import classes.HolonSwitch;
 import classes.Position;
 import interfaces.ObjectListener;
 import ui.model.Model;
-import ui.view.UpperNodeCanvas;
 
 /**
  * Controller for the Canvas.
@@ -226,6 +225,7 @@ public class CanvasController {
 
 	/**
 	 * In Case if a One or Both Side of the to Removing Edge is a CpsUpperNode
+	 * 
 	 * @param edge
 	 * @param upperNode
 	 */
@@ -238,21 +238,21 @@ public class CanvasController {
 
 			upper = (CpsUpperNode) edge.getA();
 
-			//wenn in OldEdges eine B enhält
+			// wenn in OldEdges eine B enhält
 			for (CpsEdge cpsEdge : upper.getOldEdges()) {
 				if (cpsEdge.getA().equals(edge.getB()) || cpsEdge.getB().equals(edge.getB()))
 					toDelete.add(cpsEdge);
 			}
-			//lösche alle Edges mit B
+			// lösche alle Edges mit B
 			upper.getOldEdges().removeAll(toDelete);
-			//lösche hier alle Connections
+			// lösche hier alle Connections
 			for (CpsEdge cpsEdge : toDelete) {
 				cpsEdge.getA().getConnections().remove(cpsEdge);
 				cpsEdge.getB().getConnections().remove(cpsEdge);
 			}
 			toDelete.clear();
 		}
-		//Hier analog
+		// Hier analog
 		if (edge.getB() instanceof CpsUpperNode) {
 
 			upper = (CpsUpperNode) edge.getB();
@@ -270,4 +270,59 @@ public class CanvasController {
 		}
 
 	}
+
+	/**
+	 * Some cleaning Algorithm which traverses the UpperNode through BFS Can be
+	 * extended with other cleaning stuff No need for coloring since there tree
+	 * is only directed in one direction
+	 * 
+	 * @param node
+	 */
+	public void bfsNodeCleaner(CpsUpperNode node) {
+
+		Queue<AbstractCpsObject> queue = new Queue<>();
+		AbstractCpsObject u = node;
+
+		queue.enqueue(u);
+		while (!queue.isEmpty()) {
+			try {
+				u = queue.dequeue();
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			deleteConnections(u);
+			if (u instanceof CpsUpperNode)
+				for (AbstractCpsObject adjacent : ((CpsUpperNode) u).getNodes()) {
+					queue.enqueue(adjacent);
+				}
+		}
+
+	}
+
+	/**
+	 * Deletes all Connections to Objects inside the to deleting UpperNode
+	 * 
+	 * @param obj
+	 */
+	private void deleteConnections(AbstractCpsObject obj) {
+
+		Queue<CpsEdge> queue = new Queue<>();
+		CpsEdge e = null;
+
+		for (CpsEdge edge : obj.getConnections()) {
+			queue.enqueue(edge);
+		}
+		while (!queue.isEmpty()) {
+			try {
+				e = queue.dequeue();
+			} catch (InterruptedException e1) {
+				// TODO Auto-generated catch block
+				e1.printStackTrace();
+			}
+			e.getA().getConnections().remove(e);
+			e.getB().getConnections().remove(e);
+		}
+
+	}
 }

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

@@ -327,6 +327,8 @@ public class Control {
 	 */
 	public void delCanvasObject(AbstractCpsObject obj) {
 		canvasController.deleteObjectOnCanvas(obj);
+		if (obj instanceof CpsUpperNode)
+			canvasController.bfsNodeCleaner((CpsUpperNode) obj);
 		try {
 			autoSave();
 		} catch (IOException e) {
@@ -760,6 +762,8 @@ public class Control {
 
 	public void delObjUpperNode(AbstractCpsObject object, CpsUpperNode upperNode) {
 		nodeController.deleteObjectInUpperNode(object, upperNode);
+		if (object instanceof CpsUpperNode)
+			canvasController.bfsNodeCleaner((CpsUpperNode) object);
 	}
 
 	public void addEdgeUpperNode(CpsEdge edge, CpsUpperNode upperNode) {
@@ -786,7 +790,7 @@ public class Control {
 	public int getNumberHolonObjects(ArrayList<AbstractCpsObject> list) {
 		return objectController.getNumberHolonObjects(list);
 	}
-	
+
 	/**
 	 * Get the number of HolonObjects with the given state in the given List
 	 * 
@@ -798,7 +802,7 @@ public class Control {
 	}
 
 	/**
-	 * Changes the value of HolonBodySCALE 
+	 * Changes the value of HolonBodySCALE
 	 * 
 	 * @param s
 	 *            HolonBodyScale
@@ -806,7 +810,7 @@ public class Control {
 	public void setHolonBodyScale(int s) {
 		globalController.setHolonBodyScale(s);
 	}
-	
+
 	/**
 	 * Returns HolonBodySCALE.
 	 * 

+ 10 - 7
src/ui/controller/NodeController.java

@@ -212,12 +212,13 @@ public class NodeController {
 		// 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<CpsEdge> foundEdges = (upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges());
 		ArrayList<AbstractCpsObject> lostChildren = new ArrayList<>();
+		ArrayList<AbstractCpsObject> foundChildren = (upperNode == null ? model.getObjectsOnCanvas()
+				: upperNode.getNodes());
 
 		// für jede Edge aus upperNode die Node enthält tu sie in toDelete
-		for (Iterator<CpsEdge> it = (upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges())
-				.iterator(); it.hasNext();) {
+		for (Iterator<CpsEdge> it = foundEdges.iterator(); it.hasNext();) {
 
 			CpsEdge edge = it.next();
 			if (edge.getA().equals(node) || edge.getB().equals(node))
@@ -226,13 +227,14 @@ public class NodeController {
 		}
 		// 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)) {
+			if (node.getNodes().contains(edge.getA()) && !foundChildren.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())
+			else if (node.getNodes().contains(edge.getB()) && !foundChildren.contains(edge.getA())
 					&& !lostEdges.contains(edge)) {
 				lostChildren.add(edge.getB());
 				lostEdges.add(edge);
@@ -261,7 +263,8 @@ public class NodeController {
 				// guck einfach in den Connections des Verlorenen nach Edges die
 				// auf der Canvas sind.
 				for (CpsEdge e : lost.getConnections()) {
-					if (found.contains(e.getA()) && found.contains(e.getB()) && !node.getOldEdges().contains(e)) {
+					if (foundChildren.contains(e.getA()) && foundChildren.contains(e.getB())
+							&& !node.getOldEdges().contains(e) && !foundEdges.contains(e)) {
 						node.getOldEdges().add(e);
 						foundCps = true;
 					}
@@ -272,7 +275,7 @@ public class NodeController {
 			// wenn das verlorene Object nicht gefunden
 			if (!foundCps)
 				// für alle auf der Ebene liegende Objekte
-				outerLoop: for (AbstractCpsObject cps : found) {
+				outerLoop: for (AbstractCpsObject cps : foundChildren) {
 				if (!cps.equals(node) && !lostChildren.contains(cps))
 					// such per Backtracking Algorithmus ob der enthalten ist
 					if (backtrackLostChild(cps, toSearch, lost)) {

+ 51 - 30
src/ui/controller/StoreController.java

@@ -8,6 +8,12 @@ import java.util.ListIterator;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+import TypeAdapter.AbstractCpsObjectAdapter;
 import classes.Category;
 import classes.CpsEdge;
 import classes.AbstractCpsObject;
@@ -16,6 +22,7 @@ import classes.HolonObject;
 import classes.HolonSwitch;
 import classes.HolonTransformer;
 import classes.IdCounter;
+import classes.Position;
 import ui.model.Model;
 
 /**
@@ -50,19 +57,29 @@ public class StoreController {
 	 */
 	public void writeSaveFile(String path) throws IOException {
 
+		GsonBuilder builder = new GsonBuilder();
+		builder.registerTypeAdapter(AbstractCpsObject.class, new AbstractCpsObjectAdapter()).serializeNulls()
+				.setPrettyPrinting();
+		Gson gson = builder.create();
+
 		JSONObject json = new JSONObject();
 
-		json.put("MODE", "ALL");
-		json.put("ID", IdCounter.getCounter());
-		json.put("SIZEX", model.getCanvasX());
-		json.put("SIZEY", model.getCanvasY());
-		writeCategory(json);
-		writeCategoryObjects(json);
-		writeCanvasObjects(json);
-		writeCategoryElements(json);
-		writeCanvasElements(json);
-		writeEdges(json);
-		writeElementGraph(json);
+		// json.put("MODE", "ALL");
+		// json.put("ID", IdCounter.getCounter());
+		// json.put("SIZEX", model.getCanvasX());
+		// json.put("SIZEY", model.getCanvasY());
+		// writeCategory(gson, json);
+		// writeCategoryObjects(gson, json);
+		// writeCanvasObjects(json);
+		// writeCategoryElements(json);
+		// writeCanvasElements(json);
+		// writeEdges(json);
+		// writeElementGraph(json);
+		int i = 1;
+		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
+			String k = gson.toJson(cps);
+			System.out.println(k);
+		}
 
 		FileWriter writer = new FileWriter(path);
 		writer.write(json.toJSONString());
@@ -113,8 +130,8 @@ public class StoreController {
 
 		json.put("MODE", "CATEGORY");
 		// eventuell muss man ID auch Speichern
-		writeCategory(json);
-		writeCategoryObjects(json);
+		// writeCategory(gson, json);
+		// writeCategoryObjects(gson, json);
 		writeCategoryElements(json);
 
 		FileWriter writer = new FileWriter(path);
@@ -128,39 +145,39 @@ public class StoreController {
 	/**
 	 * writes all Categories into a JSONObject.
 	 * 
+	 * @param gson
+	 * 
 	 * @param json
 	 *            JSON Object
 	 * @throws IOException
 	 *             exception
 	 */
-	public void writeCategory(JSONObject json) {
-		JSONArray arr = new JSONArray();
+	public void writeCategory(Gson gson, JSONObject json) {
+		int i = 1;
 
 		for (Category cat : model.getCategories())
-			arr.add(cat.getName());
-
-		json.put("CG", arr);
+			json.put("CG" + i++, gson.toJson(cat));
 	}
 
 	/**
 	 * writes all Objects in Category into a JSONObject.
 	 * 
+	 * @param gson
+	 * 
 	 * @param json
 	 *            JSON Object
 	 */
-	public void writeCategoryObjects(JSONObject json) {
+	public void writeCategoryObjects(Gson gson, JSONObject json) {
 
-		JSONArray arr = new JSONArray();
 		int i = 1;
 
 		for (Category cats : model.getCategories())
 			for (AbstractCpsObject cps : cats.getObjects()) {
-				arr.add(getObjectType(cps));
-				arr.add(cps.getSav());
-				arr.add(cps.getObjName());
-				arr.add(cps.getImage());
-				json.put("CGO" + i++, arr);
-				arr = new JSONArray();
+				// arr.add(cps.getSav());
+				// arr.add(cps.getObjName());
+				// arr.add(cps.getImage());
+				json.put("CGO" + i++, gson.toJson(cps));
+
 			}
 	}
 
@@ -216,7 +233,8 @@ public class StoreController {
 	/**
 	 * Write Canvas Elements.
 	 * 
-	 * @param json JSON Objects
+	 * @param json
+	 *            JSON Objects
 	 */
 	public void writeCanvasElements(JSONObject json) {
 
@@ -240,7 +258,8 @@ public class StoreController {
 	/**
 	 * write all Edges into a JSONObject.
 	 * 
-	 * @param json JSON Object
+	 * @param json
+	 *            JSON Object
 	 */
 	public void writeEdges(JSONObject json) {
 
@@ -260,7 +279,8 @@ public class StoreController {
 	/**
 	 * writes the Graph from all Elements into a JSONObject.
 	 * 
-	 * @param json JSON Object
+	 * @param json
+	 *            JSON Object
 	 */
 	public void writeElementGraph(JSONObject json) {
 
@@ -312,7 +332,8 @@ public class StoreController {
 	/**
 	 * Return the Object Type.
 	 * 
-	 * @param cps AbstractCpsObject
+	 * @param cps
+	 *            AbstractCpsObject
 	 * @return The Object Type
 	 */
 	public String getObjectType(AbstractCpsObject cps) {

+ 29 - 0
src/ui/controller/TestNewStoreController.java

@@ -1,5 +1,34 @@
 package ui.controller;
 
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+
+import ui.model.Model;
+import classes.HolonObject;
+
+
 public class TestNewStoreController {
 
+	private Model model;
+	
+	/**
+	 * Constructor
+	 * 
+	 * @param model
+	 */
+	public TestNewStoreController(Model model) {
+		this.model = model;
+		
+	}
+	
+	public void writeSaveFile(String path) {
+		Gson gson = new Gson();
+		JSONObject json = new JSONObject();
+//		
+		
+	}
+
 }

+ 1 - 3
src/ui/controller/UpdateController.java

@@ -40,10 +40,8 @@ public class UpdateController {
 	public void refreshTableProperties(DefaulTable table) {
 
 		if (model.getSelectedCpsObjects().size() == 1) {
-			AbstractCpsObject tempCps = model.getSelectedCpsObject();
-			//System.out.println(tempCps.getName());
+			AbstractCpsObject tempCps = model.getSelectedCpsObjects().get(0);
 			if (tempCps != null && tempCps.getClass() == HolonObject.class) {
-				System.out.println("In here");
 				table.removeRow(2);
 				Object[] tempEnergy = { Languages.getLanguage()[73], ((HolonObject) tempCps).getCurrentEnergy() };
 				table.insertRow(2, tempEnergy);

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

@@ -1314,6 +1314,7 @@ public class GUI<E> implements CategoryListener {
 					elementGraph.setText(Languages.getLanguage()[25]);
 				}
 				temp = updCon.getActualCps();
+
 				// Erase old data in the PropertyTable
 				if (model.getPropertyTable().getRowCount() > 0) {
 					for (int i = model.getPropertyTable().getRowCount() - 1; i > -1; i--) {
@@ -1333,6 +1334,7 @@ public class GUI<E> implements CategoryListener {
 				}
 				// Write new data in the PropertyTable
 				updCon.paintProperties(temp);
+
 				// New Tab with NodeOfNode
 				if (doubleClick() && MouseEvent.BUTTON3 != e.getButton() && temp instanceof CpsUpperNode) {
 					openNewUpperNodeTab();
@@ -1349,7 +1351,7 @@ public class GUI<E> implements CategoryListener {
 					model.getTableHolonElement().setModel(model.getSingleTable());
 				}
 			}
-		
+
 		});
 
 		toolBar.add(btnAdd);
@@ -1837,7 +1839,7 @@ public class GUI<E> implements CategoryListener {
 		mntmEditEdges.setText(tempArray[15]);
 		mnLanguage.setText(tempArray[16]);
 		canvas.updateLanguages();
-		
+
 		// Tables
 		for (int i = 0; i < columnNamesMulti.length; i++) {
 			columnNamesMulti[i] = tempArray[i + 17];

+ 58 - 35
src/ui/view/HolonCanvas.java

@@ -6,6 +6,8 @@ import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.RenderingHints;
 import java.awt.ScrollPane;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.MouseWheelEvent;
 import java.awt.event.MouseWheelListener;
 import java.util.ArrayList;
@@ -19,6 +21,11 @@ import classes.HolonObject;
 import classes.SubNet;
 import ui.controller.Control;
 import ui.model.Model;
+import javax.swing.JTextArea;
+import java.awt.List;
+
+import javax.swing.JComboBox;
+import javax.swing.JMenuBar;
 
 public class HolonCanvas extends JPanel implements MouseWheelListener {
 
@@ -37,21 +44,27 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 	// Frames
 	private int currentFrameRate;
 
-	long previousTime = System.currentTimeMillis();
-	long currentTime = previousTime;
-	long elapsedTime;
-	long totalElapsedTime = 0;
-	int frameCount = 0;
+	private long previousTime = System.currentTimeMillis();
+	private long currentTime = previousTime;
+	private long elapsedTime;
+	private long totalElapsedTime = 0;
+	private int frameCount = 0;
 	private Dimension center;
 	private ArrayList<SubNet> subnets;
 
 	private Control controller;
 	private Model model;
+	private int maxX;
+	private int maxY;
+	private JComboBox<String> combo = new JComboBox<>();
+	private int comboChoice = 0;
+	private String info;
 
 	public HolonCanvas(Model mod, Control control) {
 		// Wire up Events
 		this.controller = control;
 		this.model = mod;
+		this.add(combo);
 		subnets = controller.getSimManager().getSubNets();
 		subCount = subnets.size();
 		previousTime = System.currentTimeMillis();
@@ -59,10 +72,17 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 		totalElapsedTime = 0;
 		frameCount = 0;
 		this.addMouseWheelListener(this);
+		combo.addItem("ID");
+
+		combo.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				comboChoice = combo.getSelectedIndex();
+			}
+		});
 	}
 
 	// Start Render and Update Threads
-
 	public void paintComponent(Graphics g) {
 		super.paintComponent(g);
 
@@ -77,11 +97,10 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 			subnets = controller.getSimManager().getSubNets();
 			subCount = subnets.size();
 			calcCenter();
-			if (bodies.isEmpty()) {
-				createBodies(subCount);
-			} else {
-				addNewBodies(subCount);
-			}
+			maxX = center.width;
+			maxY = center.height;
+			addNewBodies(subCount);
+
 		}
 
 		currentTime = System.currentTimeMillis();
@@ -94,7 +113,7 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 			totalElapsedTime = 0;
 		}
 
-		updateGame(elapsedTime / 1000f);
+		updateBodies(elapsedTime / 1000f);
 		render(g);
 
 		try {
@@ -118,9 +137,13 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 				if (model.getSubNetColors().get(i) == bodies.get(j).getColor()) {
 					bodies.get(j).setRadius(
 							(subnets.get(i).getObjects().size() * 5 + 10) * controller.getHolonBodyScale() / 100);
-					bodies.get(j).setMass(subnets.get(i).getObjects().size() * 5 + 10);
+					bodies.get(j).setMass((float) Math.pow((subnets.get(i).getObjects().size() + 1) * 5, 3));
 					newBodies.add(bodies.get(j));
 					newBodies.get(i).setId(i);
+					if (newBodies.get(i).position.getX() > maxX)
+						maxX = (int) newBodies.get(i).position.getX();
+					if (newBodies.get(i).position.getY() > maxY)
+						maxY = (int) newBodies.get(i).position.getY();
 					break;
 				}
 			}
@@ -128,24 +151,18 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 
 		bodies = newBodies;
 		for (int i = bodies.size(); i < subCount; i++) {
-			HolonBody temp = new HolonBody((center.width + 1) + (-1 * i), (center.height + 1) + (-1 * i),
-					(subnets.get(i).getObjects().size() * 5 + 10) * controller.getHolonBodyScale() / 100,
-					subnets.get(i).getObjects().size() * 5 + 10, model.getSubNetColors().get(i));
+			float radius = (subnets.get(i).getObjects().size() * 5 + 10) * controller.getHolonBodyScale() / 100;
+			HolonBody temp = new HolonBody(maxX + radius, maxY + radius, radius,
+					(float) Math.pow((subnets.get(i).getObjects().size() + 1) * 5, 3), model.getSubNetColors().get(i));
 			temp.setId(i);
 			bodies.add(temp);
-		}
-
-	}
 
-	// creates the first round of bodies
-	private void createBodies(int subCount) {
-		for (int i = 0; i < subCount; i++) {
-			HolonBody temp = new HolonBody((center.width + 1) + (-1 * i), (center.height + 1) + (-1 * i),
-					subnets.get(i).getObjects().size() * 5 + 10, subnets.get(i).getObjects().size() * 5 + 10,
-					model.getSubNetColors().get(i));
-			temp.setId(i);
-			bodies.add(temp);
+			if (bodies.get(i).position.getX() > maxX)
+				maxX = (int) newBodies.get(i).position.getX();
+			if (bodies.get(i).position.getY() > maxY)
+				maxY = (int) newBodies.get(i).position.getY();
 		}
+
 	}
 
 	public void render(Graphics g) {
@@ -158,13 +175,22 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 
 		// Render Game Objects
 		for (int i = 0; i < subCount; i++) {
+			switch (comboChoice) {
+			case 0:
+				info = "" + bodies.get(i).getId();
+				break;
+
+			default:
+				info = "" + bodies.get(i).getId();
+				break;
+			}
 			bodies.get(i).setRadius((subnets.get(bodies.get(i).getId()).getObjects().size() * 5 + 10)
 					* controller.getHolonBodyScale() / 100);
-			bodies.get(i).draw(this.g2);
+			bodies.get(i).draw(this.g2, info);
 		}
 	}
 
-	public void updateGame(float elapsedSeconds) {
+	public void updateBodies(float elapsedSeconds) {
 
 		// step the position of movable objects based off their velocity/gravity
 		// and elapsedTime
@@ -172,26 +198,23 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 		for (int i = 0; i < subCount; i++) {
 			bodies.get(i).position
 					.setX((float) (bodies.get(i).position.getX() + (bodies.get(i).velocity.getX() * (elapsedSeconds))
-							- ((bodies.get(i).position.getX() - center.getWidth()) / 100)));
+							- ((bodies.get(i).position.getX() - center.getWidth()) / (50 + subCount))));
 			bodies.get(i).position
 					.setY((float) (bodies.get(i).position.getY() + (bodies.get(i).velocity.getY() * (elapsedSeconds))
-							- ((bodies.get(i).position.getY() - center.getHeight()) / 100)));
+							- ((bodies.get(i).position.getY() - center.getHeight()) / (50 + subCount))));
 
 			if (Math.abs(bodies.get(i).velocity.getX()) < Constants.epsilon)
 				bodies.get(i).velocity.setX(0);
 			if (Math.abs(bodies.get(i).velocity.getY()) < Constants.epsilon)
 				bodies.get(i).velocity.setY(0);
-
 		}
-
 		checkCollisions();
-
 	}
 
 	// Insertion sort for Sweep and Prune
 	public void insertionSort(ArrayList<HolonBody> a) {
 		for (int p = 1; p < subCount; p++) {
-			Comparable tmp = a.get(p);
+			Comparable<HolonBody> tmp = a.get(p);
 			int j = p;
 
 			for (; j > 0 && tmp.compareTo(a.get(j - 1)) < 0; j--)

+ 8 - 2
src/ui/view/SimulationMenu.java

@@ -66,12 +66,17 @@ public class SimulationMenu extends JMenuBar {
 		// Init Stuff
 		this.model = mod;
 		this.controller = cont;
+		algoCombo.addItem("non chosen");
 
 		// Algorithm ComboBox Action
 		algoCombo.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
-				setAlgorithm(algosHash.get(algoCombo.getSelectedItem()), algoCombo.getSelectedItem() + "");
+				if (algoCombo.getSelectedIndex() != 0) {
+					setAlgorithm(algosHash.get(algoCombo.getSelectedItem()), algoCombo.getSelectedItem() + "");
+				}else{
+					setAlgorithm(null, "non Chosen");
+				}
 			}
 		});
 
@@ -91,6 +96,7 @@ public class SimulationMenu extends JMenuBar {
 
 				if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
 					algoCombo.removeAllItems();
+					algoCombo.addItem("non chosen");
 					File[] files = fileChooser.getSelectedFile().listFiles();
 					// Set Root Folder Path
 					root = new File(fileChooser.getCurrentDirectory().getPath());
@@ -148,7 +154,7 @@ public class SimulationMenu extends JMenuBar {
 
 		// timerSpeed
 		simSpeedText.setMaximumSize(new Dimension(300, 300));
-		//simSpeedText.setMinimumSize(new Dimension(300, 300));
+		// simSpeedText.setMinimumSize(new Dimension(300, 300));
 		simSpeedText.addCaretListener(new CaretListener() {
 			@Override
 			public void caretUpdate(CaretEvent e) {

+ 0 - 1
src/ui/view/StatisticGraph.java

@@ -326,7 +326,6 @@ public class StatisticGraph extends JPanel {
 			case TrackedDataSet.AMOUNT_SUBNETS:
 				set.setValAt(controller.getSimManager().getSubNets().size(), model.getCurIteration());
 				break;
-
 			default:
 				break;
 			}