Browse Source

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

Edgardo Palza 7 years ago
parent
commit
01da5e6f96

+ 10 - 3
src/classes/TrackedDataSet.java

@@ -58,9 +58,7 @@ public class TrackedDataSet {
 		this.property = property;
 		this.color = color;
 		this.values = new float[100];
-		for (int i = 0; i < values.length; i++) {
-			values[i] = -1;
-		}
+		resetValues();
 	}
 
 	public AbstractCpsObject getCpsObject() {
@@ -82,4 +80,13 @@ public class TrackedDataSet {
 	public void setValAt(float val, int at){
 		this.values[at] = val;
 	}
+	
+	/**
+	 * Resets all values.
+	 */
+	public void resetValues(){
+		for (int i = 0; i < values.length; i++) {
+			values[i] = -1;
+		}
+	}
 }

+ 60 - 20
src/ui/controller/Control.java

@@ -6,6 +6,7 @@ import java.awt.datatransfer.UnsupportedFlavorException;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Hashtable;
 import java.util.zip.ZipException;
 
 import org.apache.commons.compress.archivers.ArchiveException;
@@ -24,6 +25,7 @@ import interfaces.CategoryListener;
 import ui.model.Model;
 import ui.view.FlexiblePane;
 import ui.view.MyCanvas;
+import ui.view.StatisticGraphPanel;
 
 /**
  * The Class represents the controller in the model, controller view Pattern.
@@ -41,7 +43,7 @@ public class Control {
 	private final ObjectController objectController;
 	private final CanvasController canvasController;
 	private final GlobalController globalController;
-	private final SaveController storeController;
+	private final SaveController saveController;
 	private final LoadController loadController;
 	private final AutoSaveController autoSaveController;
 	private SimulationManager simulationManager;
@@ -49,7 +51,8 @@ public class Control {
 	private final NodeController nodeController;
 	private final ClipboardController clipboardController;
 	private final HolonCanvasController holonCanvasController;
-	private String autoPath = "";
+	private String autosaveDir = "";
+	private String categoryDir = "";
 
 	/**
 	 * Constructor.
@@ -65,7 +68,7 @@ public class Control {
 		this.objectController = new ObjectController(model, multiPurposeController);
 		this.canvasController = new CanvasController(model, multiPurposeController);
 		this.globalController = new GlobalController(model);
-		this.storeController = new SaveController(model);
+		this.saveController = new SaveController(model);
 		this.nodeController = new NodeController(model, canvasController, multiPurposeController);
 		this.loadController = new LoadController(model, categoryController, canvasController, objectController,
 				nodeController, multiPurposeController);
@@ -73,14 +76,17 @@ public class Control {
 		this.autoSaveController = new AutoSaveController(model);
 		this.consoleController = new ConsoleController(model);
 		this.statsController = new StatsController(model);
-		this.clipboardController = new ClipboardController(model, storeController, loadController, canvasController,
+		this.clipboardController = new ClipboardController(model, saveController, loadController, canvasController,
 				objectController, nodeController, multiPurposeController);
 		this.holonCanvasController = new HolonCanvasController(model);
 
-		autoPath = System.getProperty("user.home") + "/HolonGUI/Autosave/";
-		File dest = new File(autoPath);
+		autosaveDir = System.getProperty("user.home") + "/HolonGUI/Autosave/";
+		categoryDir = System.getProperty("user.home") + "/HolonGUI/Category/";
+		File autoSave = new File(autosaveDir);
+		File category = new File(categoryDir);
 		// deleteDirectory(dest);
-		dest.mkdirs();
+		autoSave.mkdirs();
+		category.mkdirs();
 		try {
 			autoSave();
 		} catch (IOException e) {
@@ -161,9 +167,11 @@ public class Control {
 
 	/**
 	 * init default category and objects.
+	 * @throws IOException 
 	 */
-	public void resetCategorys() {
+	public void resetCategorys() throws IOException {
 		categoryController.initCategories();
+		saveCategory();
 	}
 
 	/**
@@ -171,9 +179,11 @@ public class Control {
 	 * 
 	 * @param cat
 	 *            name of the new Category
+	 * @throws IOException 
 	 */
-	public void addCategory(String cat) {
+	public void addCategory(String cat) throws IOException {
 		categoryController.addNewCategory(cat);
+		saveCategory();
 	}
 
 	/**
@@ -187,9 +197,11 @@ public class Control {
 	 *            Array of Elements
 	 * @param img
 	 *            the image Path
+	 * @throws IOException 
 	 */
-	public void addObject(Category cat, String obj, ArrayList<HolonElement> ele, String img) {
+	public void addObject(Category cat, String obj, ArrayList<HolonElement> ele, String img) throws IOException {
 		categoryController.addNewHolonObject(cat, obj, ele, img);
+		saveCategory();
 	}
 
 	/**
@@ -211,9 +223,11 @@ public class Control {
 	 *            Category
 	 * @param obj
 	 *            New Object Name
+	 * @throws IOException 
 	 */
-	public void addSwitch(Category cat, String obj) {
+	public void addSwitch(Category cat, String obj) throws IOException {
 		categoryController.addNewHolonSwitch(cat, obj, "/Images/switch-on.png");
+		saveCategory();
 	}
 
 	/**
@@ -221,9 +235,11 @@ public class Control {
 	 * 
 	 * @param cat
 	 *            the Category
+	 * @throws IOException 
 	 */
-	public void deleteCategory(String cat) {
+	public void deleteCategory(String cat) throws IOException {
 		categoryController.deleteCategory(cat);
+		saveCategory();
 	}
 
 	/**
@@ -233,9 +249,11 @@ public class Control {
 	 *            the Category
 	 * @param obj
 	 *            the Object
+	 * @throws IOException 
 	 */
-	public void delObjectCategory(String cat, String obj) {
+	public void delObjectCategory(String cat, String obj) throws IOException {
 		categoryController.deleteObject(cat, obj);
+		saveCategory();
 	}
 
 	/**
@@ -471,7 +489,7 @@ public class Control {
 	 *             exception
 	 */
 	public void saveFile(String path) throws IOException, ArchiveException {
-		storeController.writeSave(path);
+		saveController.writeSave(path);
 	}
 
 	/**
@@ -485,6 +503,8 @@ public class Control {
 	 */
 	public void loadFile(String path) throws IOException, ArchiveException, ZipException {
 		loadController.readSave(path);
+		saveCategory();
+		autoSave();
 	}
 	
 	/**
@@ -531,6 +551,7 @@ public class Control {
 	 * including a reset of all Edges to the default "is working" state
 	 */
 	public void resetSimulation(){
+		setIsSimRunning(false);
 		simulationManager.resetSimulation();
 	}
 
@@ -552,11 +573,15 @@ public class Control {
 	 */
 	public void autoSave() throws IOException {
 		autoSaveController.increaseAutoSaveNr();
-		storeController.writeAutosave(autoPath + autoSaveController.getAutoSaveNr());
+		saveController.writeAutosave(autosaveDir + autoSaveController.getAutoSaveNr());
 		if (autoSaveController.allowed()) {
-			new File(autoPath + (autoSaveController.getAutoSaveNr() - globalController.getNumbersOfSaves())).delete();
+			new File(autosaveDir + (autoSaveController.getAutoSaveNr() - globalController.getNumbersOfSaves())).delete();
 		}
 	}
+	
+	public void saveCategory() throws IOException {
+		saveController.writeCategory(categoryDir + "Category.json");
+	}
 
 	/**
 	 * Returns the undo save.
@@ -565,10 +590,10 @@ public class Control {
 	 */
 	public String getUndoSave() {
 		autoSaveController.decreaseAutoSaveNr();
-		if (!new File(autoPath + (autoSaveController.getAutoSaveNr())).exists()) {
+		if (!new File(autosaveDir + (autoSaveController.getAutoSaveNr())).exists()) {
 			autoSaveController.increaseAutoSaveNr();
 		}
-		return autoPath + (autoSaveController.getAutoSaveNr());
+		return autosaveDir + (autoSaveController.getAutoSaveNr());
 	}
 
 	/**
@@ -578,10 +603,10 @@ public class Control {
 	 */
 	public String getRedoSave() {
 		autoSaveController.increaseAutoSaveNr();
-		if (!new File(autoPath + (autoSaveController.getAutoSaveNr())).exists()) {
+		if (!new File(autosaveDir + (autoSaveController.getAutoSaveNr())).exists()) {
 			autoSaveController.decreaseAutoSaveNr();
 		}
-		return autoPath + (autoSaveController.getAutoSaveNr());
+		return autosaveDir + (autoSaveController.getAutoSaveNr());
 	}
 
 
@@ -907,5 +932,20 @@ public class Control {
 	public void setFlexiblePane(FlexiblePane fp){
 		simulationManager.setFlexiblePane(fp);
 	}
+	
+	public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT){
+		model.setGraphTable(gT);
+	}
+	
+	public Hashtable<String, StatisticGraphPanel> getGraphTable(){
+		return model.getGraphTable();
+	}
+	
+	/**
+	 * Sets if the Simulation is running
+	 */
+	public void setIsSimRunning(boolean isRunning){
+		globalController.setIsSimRunning(isRunning);
+	}
 
 }

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

@@ -3,6 +3,7 @@ package ui.controller;
 import java.awt.Color;
 
 import ui.model.Model;
+import ui.view.StatisticGraphPanel;
 
 /**
  * Controller for the Global Variables.
@@ -142,4 +143,17 @@ public class GlobalController {
 	public int getHolonBodyScale() {
 		return model.getHolonBodyScale();
 	}
+	
+	/**
+	 * Sets if the Simulation is running
+	 */
+	public void setIsSimRunning(boolean isRunning){
+		model.setIsSimRunning(isRunning);
+		//Reset the Graph if isRunning == true
+		if (isRunning) {
+			for (StatisticGraphPanel sg : model.getGraphTable().values()) {
+				sg.resetGraph();
+			}
+		}
+	}
 }

+ 81 - 10
src/ui/controller/LoadController.java

@@ -57,7 +57,7 @@ public class LoadController {
 	 * enum Mode.
 	 */
 	public enum MODE {
-		COMPLETE, PARTIAL
+		COMPLETE, PARTIAL, CATEGORY
 	}
 
 	public enum EDGETYPE {
@@ -137,9 +137,10 @@ public class LoadController {
 		forwardEdges(edges, json, objDispatch);
 
 	}
-	
+
 	/**
 	 * Loads the Files from the Savefile
+	 * 
 	 * @param folder
 	 * @param trim
 	 * @throws IOException
@@ -148,7 +149,7 @@ public class LoadController {
 		// TODO Auto-generated method stub
 		for (File file : folder.listFiles()) {
 			File dst = new File(System.getProperty("user.home") + "/HolonGUI/" + file.getPath().replace(trim, ""));
-			
+
 			if (file.getName().contains(".json"))
 				readJson(file.getPath());
 			else if (file.isDirectory())
@@ -157,7 +158,7 @@ public class LoadController {
 				dst.getParentFile().mkdirs();
 				Files.copy(file.toPath(), dst.toPath(), StandardCopyOption.REPLACE_EXISTING);
 			}
-	
+
 		}
 	}
 
@@ -216,6 +217,8 @@ public class LoadController {
 				loadUnitGraph(GRAPHTYPE.SWITCH, json.get(key), objDispatch, null);
 			if (key.contains("ELEUNITGRAPH"))
 				loadUnitGraph(GRAPHTYPE.ELEMENT, json.get(key), null, eleDispatch);
+			if (key.contains("TRACKED"))
+				loadTracked(json.get(key), objDispatch);
 		}
 
 	}
@@ -230,25 +233,32 @@ public class LoadController {
 
 		switch (MODE.valueOf(json.get("MODE").getAsString())) {
 		case COMPLETE:
-			model.setCgIdx(new HashMap<String, Integer>());
-			model.setCategories(new ArrayList<Category>());
 			model.setCvsObjIdx(new HashMap<Integer, Integer>());
 			model.setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
 			model.setEdgesOnCanvas(new ArrayList<CpsEdge>());
+			model.setTrackingObj(new ArrayList<>());
 			model.setCanvasX(json.get("CANVAS_SIZE_X").getAsInt());
 			model.setCanvasX(json.get("CANVAS_SIZE_Y").getAsInt());
+			IdCounter.setCounter(json.get("IDCOUNTER").getAsInt());
+			IdCounterElem.setCounter(json.get("IDCOUNTERELEMENT").getAsInt());
 			break;
 		case PARTIAL:
 			model.setCvsObjIdx(new HashMap<Integer, Integer>());
 			model.setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
 			model.setEdgesOnCanvas(new ArrayList<CpsEdge>());
+			model.setCanvasX(json.get("CANVAS_SIZE_X").getAsInt());
+			model.setCanvasX(json.get("CANVAS_SIZE_Y").getAsInt());
+			IdCounter.setCounter(json.get("IDCOUNTER").getAsInt());
+			IdCounterElem.setCounter(json.get("IDCOUNTERELEMENT").getAsInt());
 			break;
+		case CATEGORY:
+			model.setCgIdx(new HashMap<String, Integer>());
+			model.setCategories(new ArrayList<Category>());
 
 		default:
 			break;
 		}
-		IdCounter.setCounter(json.get("IDCOUNTER").getAsInt());
-		IdCounterElem.setCounter(json.get("IDCOUNTERELEMENT").getAsInt());
+
 	}
 
 	/**
@@ -258,7 +268,8 @@ public class LoadController {
 	 */
 	private void loadCategory(JsonElement jsonElement) {
 		// TODO Auto-generated method stub
-		cgC.addCategory(new Category(jsonElement.getAsString()));
+		if (mpC.searchCat(jsonElement.getAsString()) == null)
+			cgC.addCategory(new Category(jsonElement.getAsString()));
 	}
 
 	/**
@@ -268,10 +279,22 @@ public class LoadController {
 	 */
 	private void loadCategoryObject(JsonElement jsonElement) {
 		// TODO Auto-generated method stub
+
 		AbstractCpsObject temp = gson.fromJson(jsonElement.getAsJsonObject(), AbstractCpsObject.class);
+		temp.setImage(checkOS(temp.getImage()));
 		initObjects(temp);
-
+		if (mpC.searchCatObj(mpC.searchCat(temp.getSav()), temp.getObjName()) != null)
+			cgC.deleteObject(temp.getSav(), temp.getObjName());
 		cgC.addObject(mpC.searchCat(temp.getSav()), temp);
+
+	}
+
+	private String refreshPath(String image) {
+		// TODO Auto-generated method stub
+		if (!image.contains("/HolonGUI/"))
+			return image;
+		return (System.getProperty("user.home") + image.substring(image.indexOf("/HolonGUI/"), image.length()))
+				.replace("\\", "/");
 	}
 
 	/**
@@ -297,6 +320,7 @@ public class LoadController {
 		// TODO Auto-generated method stub
 		AbstractCpsObject temp = gson.fromJson(jsonElement.getAsJsonObject(), AbstractCpsObject.class);
 		initObjects(temp);
+		temp.setImage(checkOS(temp.getImage()));
 		// if its stored before on the canvas just put it there
 		if (temp.getSav().equals("CVS")) {
 			cvsC.addObject(temp);
@@ -434,6 +458,22 @@ public class LoadController {
 		}
 	}
 
+	private void loadTracked(JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch) {
+		// TODO Auto-generated method stub
+		JsonObject object = jsonElement.getAsJsonObject();
+		List<String> keys = getKeys(object);
+
+		for (String k : keys) {
+			int id = object.get(k).getAsInt();
+			model.getTrackingObj().add(objDispatch.get(id));
+			model.addObjectsToGraphListeners();
+			if (objDispatch.get(id) instanceof HolonObject) {
+				((HolonObject) objDispatch.get(id)).updateTrackingInfo();
+			}
+		}
+
+	}
+
 	/**
 	 * Initialize the Gson with wanted parameters
 	 */
@@ -458,6 +498,7 @@ public class LoadController {
 
 		ArchiveEntry entry = stream.getNextEntry();
 		while (entry != null) {
+			// String entryName = checkOS(entry.getName());
 			File file = new File(tmp, entry.getName());
 			file.getParentFile().mkdirs();
 			OutputStream output = new FileOutputStream(file);
@@ -473,6 +514,36 @@ public class LoadController {
 		return tmp;
 	}
 
+	private String checkOS(String entryName) {
+		// TODO Auto-generated method stub
+		String os = System.getProperty("os.name").toLowerCase();
+		String ret = entryName;
+		String partition = System.getProperty("user.home");
+
+		if (!ret.contains("HolonGUI"))
+			return ret;
+
+		if (os.contains("windows")) {
+			ret = ret.replace("/", "\\");
+			ret = System.getProperty("user.home") + ret.substring(ret.indexOf("\\HolonGUI\\"), ret.length());
+
+		}
+		if (os.contains("mac")) {
+			// dosmth
+			ret = ret.replace("\\", "/");
+			ret = System.getProperty("user.home") + ret.substring(ret.indexOf("/HolonGUI/"), ret.length());
+		}
+		if (os.contains("linux")) {
+			// dosmth
+			ret = ret.replace("\\", "/");
+			ret = System.getProperty("user.home") + ret.substring(ret.indexOf("/HolonGUI/"), ret.length());
+		}
+		if (os.contains("solaris")) {
+			// dosmth
+		}
+		return ret;
+	}
+
 	/**
 	 * Init new Arrays which havent been serialized along the object
 	 * 

+ 84 - 12
src/ui/controller/SaveController.java

@@ -48,7 +48,7 @@ import ui.model.Model;
 public class SaveController {
 
 	public enum MODE {
-		COMPLETE, PARTIAL
+		COMPLETE, PARTIAL, CATEGORY
 	}
 
 	public enum TYPE {
@@ -60,7 +60,7 @@ public class SaveController {
 	}
 
 	public enum NUMTYPE {
-		CATEGORY, OBJECT, ELEMENT, EDGE, CONNECTION, NODEEDGE, OLDEDGE, UNITGRAPH, IMAGE
+		CATEGORY, OBJECT, ELEMENT, EDGE, CONNECTION, NODEEDGE, OLDEDGE, UNITGRAPH, STATSGRAPH
 	}
 
 	public enum GRAPHTYPE {
@@ -69,7 +69,7 @@ public class SaveController {
 
 	private Model model;
 	private Gson gson;
-	private int nCat, nObj, nEle, nEdge, nConn, nNodeEdge, nOldEdge, nUnitGraph, nImg;
+	private int nCat, nObj, nEle, nEdge, nConn, nNodeEdge, nOldEdge, nUnitGraph, nStatsGraph;
 
 	/**
 	 * Constructor.
@@ -108,6 +108,7 @@ public class SaveController {
 		initialize(MODE.COMPLETE, file);
 		storeCategory(file);
 		storeCanvas(file);
+		storeStatistics(file);
 		storeData(stream);
 
 		FileWriter writer = new FileWriter(holonFile);
@@ -144,6 +145,27 @@ public class SaveController {
 		writer.close();
 	}
 
+	/**
+	 * Writes the Category File in Case of Changes
+	 * 
+	 * @param path
+	 * @throws IOException
+	 */
+	public void writeCategory(String path) throws IOException {
+
+		initNumeration();
+		JsonObject file = new JsonObject();
+		initialize(MODE.CATEGORY, file);
+		storeCategory(file);
+
+		FileWriter writer = new FileWriter(path);
+		writer.write(gson.toJson(file));
+
+		writer.flush();
+		writer.close();
+
+	}
+
 	/**
 	 * Write needed default parameter into the JsonObject. Can be extended later
 	 * on
@@ -165,11 +187,15 @@ public class SaveController {
 			file.add("MODE", new JsonPrimitive(mode.name()));
 			file.add("IDCOUNTER", new JsonPrimitive(IdCounter.getCounter()));
 			file.add("IDCOUNTERELEMENT", new JsonPrimitive(IdCounterElem.getCounter()));
+			file.add("CANVAS_SIZE_X", new JsonPrimitive(model.getCanvasX()));
+			file.add("CANVAS_SIZE_Y", new JsonPrimitive(model.getCanvasY()));
 			break;
-
+		case CATEGORY:
+			file.add("MODE", new JsonPrimitive(mode.name()));
 		default:
 			break;
 		}
+
 	}
 
 	/**
@@ -193,7 +219,7 @@ public class SaveController {
 			}
 		}
 	}
-	
+
 	/**
 	 * Travers through all Objects via BFS and Stores everything relevant
 	 * 
@@ -240,7 +266,8 @@ public class SaveController {
 	}
 
 	private void storeStatistics(JsonObject file) {
-		
+		trackedToJson(file);
+		statisticgraphToJson(file);
 	}
 
 	/**
@@ -251,7 +278,6 @@ public class SaveController {
 	 */
 	private void storeData(ArchiveOutputStream stream) throws IOException {
 		// TODO Auto-generated method stub
-
 		File images = new File(System.getProperty("user.home") + "/HolonGUI/Images");
 		File background = new File(System.getProperty("user.home") + "/HolonGUI/BackgroundImages");
 		addFilesToSave(images, stream);
@@ -375,6 +401,25 @@ public class SaveController {
 
 	}
 
+	private void trackedToJson(JsonObject file) {
+		// TODO Auto-generated method stub
+		JsonObject temp = new JsonObject();
+		String key = "TRACKED";
+		// forall points add them
+		for (int i = 0; i < model.getTrackingObj().size(); i++) {
+			temp.add("" + i, new JsonPrimitive(model.getTrackingObj().get(i).getId()));
+		}
+
+		file.add(key, gson.toJsonTree(temp));
+	}
+
+	private void statisticgraphToJson(JsonObject file) {
+		// TODO Auto-generated method stub
+		JsonObject temp = new JsonObject();
+		String key = null;
+
+	}
+
 	/**
 	 * Differs Between Single file or whole Directory to Store
 	 * 
@@ -408,8 +453,9 @@ public class SaveController {
 	 */
 	private void addFileToSave(File src, ArchiveOutputStream stream, boolean dir) throws IOException {
 		String entryName = (dir == true ? src.getCanonicalPath() : src.getName());
-		entryName = entryName.replace(System.getProperty("user.home") + "/HolonGUI/", "");
-		
+
+		entryName = checkOS(entryName);
+
 		ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
 		stream.putArchiveEntry(entry);
 		BufferedInputStream input = new BufferedInputStream(new FileInputStream(src));
@@ -419,6 +465,31 @@ public class SaveController {
 		stream.closeArchiveEntry();
 	}
 
+	private String checkOS(String entryName) {
+		// TODO Auto-generated method stub
+		String os = System.getProperty("os.name").toLowerCase();
+		String ret = entryName;
+		String partition = null;
+
+		if (os.contains("windows")) {
+			partition = ret.substring(0, ret.indexOf(":") + 1);
+			ret = ret.replace(System.getProperty("user.home") + "\\HolonGUI\\", "");
+			ret = ret.replace(partition, "");
+		}
+		if (os.contains("mac")) {
+			// dosmth
+			ret = ret.replace(System.getProperty("user.home") + "/HolonGUI/", "");
+		}
+		if (os.contains("linux")) {
+			// dosmth
+			ret = ret.replace(System.getProperty("user.home") + "/HolonGUI/", "");
+		}
+		if (os.contains("solaris")) {
+			// dosmth
+		}
+		return ret;
+	}
+
 	/**
 	 * Initialize the Gson with wanted parameters
 	 */
@@ -437,7 +508,7 @@ public class SaveController {
 	 * Just initialize the Numerators for the Json Keys. Maybe bad Style..
 	 */
 	public void initNumeration() {
-		this.nCat = this.nObj = this.nEle = this.nEdge = this.nConn = this.nNodeEdge = this.nOldEdge = this.nImg = 0;
+		this.nCat = this.nObj = this.nEle = this.nEdge = this.nConn = this.nNodeEdge = this.nOldEdge = this.nStatsGraph = 0;
 	}
 
 	/**
@@ -465,8 +536,9 @@ public class SaveController {
 			return nOldEdge++;
 		case UNITGRAPH:
 			return nUnitGraph++;
-		case IMAGE:
-			return nImg++;
+		case STATSGRAPH:
+			return nStatsGraph++;
+
 		default:
 			break;
 		}

+ 35 - 0
src/ui/model/Model.java

@@ -3,6 +3,7 @@ package ui.model;
 import java.awt.Color;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -20,6 +21,7 @@ import interfaces.ObjectListener;
 import ui.view.Console;
 import ui.view.DefaulTable;
 import ui.view.PropertyTable;
+import ui.view.StatisticGraphPanel;
 
 /**
  * The Class Model is the class where everything is saved. All changes made to
@@ -68,6 +70,8 @@ public class Model {
 	private int autoSaveNr = -1;
 	// number of max simultaneous autosaves
 	private int numberOfSaves = 35;
+	// if the simulation is running and has not been reseted
+	private boolean isSimRunning = false;
 	/*
 	 * Array of all categories in the model. It is set by default with the
 	 * categories ENERGY, BUILDINGS and COMPONENTS
@@ -111,6 +115,7 @@ public class Model {
 	private Object algorithm = null;
 	private int selectedHolonBody;
 
+	private Hashtable<String, StatisticGraphPanel> statisticGraphTable = new Hashtable<String, StatisticGraphPanel>();
 	/**
 	 * Constructor for the model. It initializes the categories and
 	 * objectsOnCanvas by default values. Listeners are also initialized by
@@ -860,4 +865,34 @@ public class Model {
 	public void setCanvasImageHeight(int height) {
 		backgroundHeight = height;
 	}
+	
+	/**
+	 * Set the graphtable for Statistic Graphs
+	 */
+	public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT){
+		statisticGraphTable = gT;
+	}
+	
+	/**
+	 * Returns the graphtable for Statistic Graphs.
+	 */
+	public Hashtable<String, StatisticGraphPanel> getGraphTable(){
+		return statisticGraphTable;
+	}
+	
+	/**
+	 * Returns if the Simulation is running.
+	 */
+	public boolean getIsSimRunning(){
+		return isSimRunning;
+	}
+
+	/**
+	 * Sets isSimRunning.
+	 * @param isRunning
+	 */
+	public void setIsSimRunning(boolean isRunning) {
+		isSimRunning = isRunning;
+	}
 }
+

+ 13 - 7
src/ui/view/AddObjectPopUp.java

@@ -266,14 +266,20 @@ public class AddObjectPopUp extends JDialog {
 								// HolonObject(objectName.getText());
 								// theObject.setElements(hElements);
 								// theObject.setImage(imagePath);
-								if (editState) {
-									controller.delObjectCategory(givenCategory, toEdit.getName());
-									controller.addObject(controller.searchCategory(givenCategory), objectName.getText(),
-											hElements, imagePath);
-								} else {
-									controller.addObject(controller.searchCategory(givenCategory), objectName.getText(),
-											hElements, imagePath);
+								try {
+									if (editState) {
+										controller.delObjectCategory(givenCategory, toEdit.getName());
+										controller.addObject(controller.searchCategory(givenCategory),
+												objectName.getText(), hElements, imagePath);
+									} else {
+										controller.addObject(controller.searchCategory(givenCategory),
+												objectName.getText(), hElements, imagePath);
+									}
+								} catch (Exception e2) {
+									// TODO: handle exception
+									
 								}
+
 								// controller.addObjectCategory(controller.searchCategory(givenCategory),
 								// theObject);
 								//

+ 4 - 61
src/ui/view/SimulationMenu.java → src/ui/view/AlgorithmMenu.java

@@ -1,8 +1,5 @@
 package ui.view;
 
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.BufferedReader;
@@ -16,7 +13,6 @@ import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JFileChooser;
 import javax.swing.JFrame;
-import javax.swing.JMenuBar;
 import javax.swing.JPanel;
 import javax.tools.JavaCompiler;
 import javax.tools.ToolProvider;
@@ -30,13 +26,10 @@ import ui.model.Model;
  * 
  * @author Gruppe14
  */
-public class SimulationMenu extends JMenuBar {
+public class AlgorithmMenu extends JPanel {
 
 	private static final long serialVersionUID = 1L;
 
-	private JPanel menuPanel = new JPanel();
-	//JLabel simSpeedLabel = new JLabel(Languages.getLanguage()[84]);
-	//private JTextField simSpeedText = new JTextField("1000");
 	private JComboBox<Object> algoCombo = new JComboBox<>();
 	JButton algoFolderButton = new JButton(Languages.getLanguage()[85]);
 	private HashMap<String, File> algosHash = new HashMap<>();
@@ -55,14 +48,12 @@ public class SimulationMenu extends JMenuBar {
 	 * @param cont
 	 *            the Controller
 	 */
-	public SimulationMenu(Model mod, Control cont) {
+	public AlgorithmMenu(Model mod, Control cont) {
 		super();
 		// Init Stuff
 		this.model = mod;
 		this.controller = cont;
 		
-		//simSpeedLabel.setMaximumSize(simSpeedLabel.getPreferredSize());
-		//simSpeedLabel.setMinimumSize(simSpeedLabel.getPreferredSize());
 		algoCombo.addItem("None");
 
 		// Algorithm ComboBox Action
@@ -119,57 +110,9 @@ public class SimulationMenu extends JMenuBar {
 		});
 
 		// Add to Panel
-		GridBagLayout gblmenuPanel = new GridBagLayout();
-		gblmenuPanel.columnWidths = new int[] { 79, 105, 34, 60, 31, 151, 0 };
-		gblmenuPanel.rowHeights = new int[] { 25, 0 };
-		gblmenuPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
-		gblmenuPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
-		menuPanel.setLayout(gblmenuPanel);
-
-		GridBagConstraints gbcsimSpeedLabel = new GridBagConstraints();
-		gbcsimSpeedLabel.anchor = GridBagConstraints.WEST;
-		gbcsimSpeedLabel.insets = new Insets(0, 0, 0, 5);
-		gbcsimSpeedLabel.gridx = 1;
-		gbcsimSpeedLabel.gridy = 0;
-		//menuPanel.add(simSpeedLabel, gbcsimSpeedLabel);
-
-		// timerSpeed
-		/*simSpeedText.setMaximumSize(new Dimension(300, 300));
-		// simSpeedText.setMinimumSize(new Dimension(300, 300));
-		simSpeedText.addCaretListener(new CaretListener() {
-			@Override
-			public void caretUpdate(CaretEvent e) {
-				try {
-					controller.setTimerSpeed(Integer.parseInt(simSpeedText.getText()));
-				} catch (Exception ex) {
-					// TODO: handle exception
-				}
+		this.add(algoFolderButton);
 
-			}
-		});*/
-		GridBagConstraints gbcSimSpeedText = new GridBagConstraints();
-		gbcSimSpeedText.anchor = GridBagConstraints.WEST;
-		gbcSimSpeedText.insets = new Insets(0, 0, 0, 5);
-		gbcSimSpeedText.gridx = 2;
-		gbcSimSpeedText.gridy = 0;
-		//menuPanel.add(simSpeedText, gbcSimSpeedText);
-		GridBagConstraints gbcAlgoFolderButton = new GridBagConstraints();
-		gbcAlgoFolderButton.anchor = GridBagConstraints.WEST;
-		gbcAlgoFolderButton.insets = new Insets(0, 0, 0, 5);
-		gbcAlgoFolderButton.gridx = 3;
-		gbcAlgoFolderButton.gridy = 0;
-		menuPanel.add(algoFolderButton, gbcAlgoFolderButton);
-
-		GridBagConstraints gbcAlgoCombo = new GridBagConstraints();
-		gbcAlgoCombo.anchor = GridBagConstraints.WEST;
-		gbcAlgoCombo.insets = new Insets(0, 0, 0, 5);
-		gbcAlgoCombo.gridx = 4;
-		gbcAlgoCombo.gridy = 0;
-		menuPanel.add(algoCombo, gbcAlgoCombo);
-		// algoCombo.addItem(Languages.getLanguage()[86]);
-
-		// Add Panel to SimulationMenu
-		this.add(menuPanel);
+		this.add(algoCombo);
 	}
 
 	public void setAlgorithm(File file, String name) {

+ 2 - 1
src/ui/view/FlexiblePane.java

@@ -30,6 +30,7 @@ public class FlexiblePane extends JScrollPane {
 		float gridCons = 0;
 		int counter = 1;
 		for(SubNet sn: controller.getSimManager().getSubNets()){
+			int index = flexPanel.getComponentCount();
 			float subProd = 0;
 			float subCons = 0;
 			for(HolonObject hl: sn.getObjects()){
@@ -40,7 +41,7 @@ public class FlexiblePane extends JScrollPane {
 			}
 			gridProd += subProd;
 			gridCons += subCons;
-			flexPanel.add(new FlexibleData("Subnet "+ counter, subProd, subCons));
+			flexPanel.add(new FlexibleData("Subnet "+ counter, subProd, subCons), index);
 			counter++;
 		}
 		if (flexPanel.getComponent(0) instanceof FlexibleData){

+ 166 - 114
src/ui/view/GUI.java

@@ -98,7 +98,7 @@ public class GUI<E> implements CategoryListener {
 
 	private JFrame frmCyberPhysical;
 
-	private final SimulationMenu simMenu;
+	private final AlgorithmMenu simMenu;
 
 	private JTabbedPane tabTemp; // tabbedPane or tabbedPane2
 	private final JMenuBar menuBar = new JMenuBar();
@@ -107,12 +107,14 @@ public class GUI<E> implements CategoryListener {
 	private final JMenu mnNewMenuOptions = new JMenu("Options");
 	private final JMenu mnNewMenuView = new JMenu("View");
 	private final JMenu mnHelp = new JMenu("Help");
+	private final JMenu mnAlgorithm = new JMenu("Algorithm");
 	private final JMenuItem mntmOpen = new JMenuItem("Open");
 	private final JMenuItem mntmNew = new JMenuItem("New");
 	private final JMenuItem mntmSave = new JMenuItem("Save");
-	private final JMenuItem aboutUs = new JMenuItem("About Us");
-	private final JMenuItem canvasSize = new JMenuItem("View Size");
-	private final JMenuItem background = new JMenuItem("Background Image");
+	private final JMenuItem mntmAboutUs = new JMenuItem("About Us");
+	private final JMenuItem mntmCanvasSize = new JMenuItem("View Size");
+	private final JMenuItem mntmBackground = new JMenuItem("Background Image");
+	private final JMenuItem mntmSplitView = new JMenuItem("Split View");
 	private final JSplitPane splitPane = new JSplitPane();
 	private final JSplitPane splitPane1 = new JSplitPane();
 	private final JSplitPane splitPaneCanvasConsole = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
@@ -122,16 +124,12 @@ public class GUI<E> implements CategoryListener {
 	// private final JScrollPane holonSP = new JScrollPane();
 	private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
 	private final JTabbedPane tabbedPane2 = new JTabbedPane(JTabbedPane.TOP);
-	private final JButton splitButton = new JButton("Split View Test");
 	private JSplitPane tempSplit;
 	private boolean initSplit = true;
 
-	private final JPanel panelTapped_SimMenu = new JPanel();
 	private JPopupMenu popmenuEdit = new JPopupMenu();
 	private JMenuItem editItem = new JMenuItem("Edit Object");
 	private String catOfObjToBeEdited;
-	private final JScrollPane statTab = new JScrollPane();
-
 	private FlexiblePane flexPane;
 	private StatPanel2 statSplitPane;
 	private JScrollPane statScrollPane;
@@ -301,7 +299,7 @@ public class GUI<E> implements CategoryListener {
 		control.initListener(this);
 		controller.setCanvas(canvas);
 		model.setConsole(console);
-		simMenu = new SimulationMenu(model, control);
+		simMenu = new AlgorithmMenu(model, control);
 		initialize();
 		updateCategories(model.getCategories());
 		updCon = new UpdateController(model, controller);
@@ -416,22 +414,41 @@ public class GUI<E> implements CategoryListener {
 
 			@Override
 			public void actionPerformed(ActionEvent e) {
+				if (tabbedPane.getMousePosition() != null) {
+					tabTemp = tabbedPane;
+				} else {
+					tabTemp = tabbedPane2;
+				}
 				// Uppernode Canvas?
-				if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
+				if (((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
 						.getComponent(0) instanceof UpperNodeCanvas) {
-					UpperNodeCanvas uNC = (UpperNodeCanvas) ((JScrollPane) tabbedPane.getSelectedComponent())
-							.getViewport().getComponent(0);
+					UpperNodeCanvas uNC = (UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
+							.getComponent(0);
 					for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
 						if (uNC.upperNode.getNodes().contains(cps)) {
 							controller.delObjUpperNode(cps, uNC.upperNode);
 							// Remove UpperNodeTab if UpperNode deleted
 							if (cps instanceof CpsUpperNode) {
+								boolean splitView = false;
 								for (int i = 4; i < tabbedPane.getTabCount(); i++) {
-									if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
-											.getComponent(0)).upperNode.getId() == cps.getId()) {
-										tabbedPane.remove(i);
-										i = tabbedPane.getTabCount();
+									if (tabbedPane.getComponentAt(i) == null) {
+										splitView = true;
+									} else if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i))
+											.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
+										((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
+										break;
+									}
+								}
+								// If SplitView is on and the view on
+								// tabbedPane2 is the deleted upperNode
+								try {
+									if (splitView
+											&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
+													.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
+										((ButtonTabComponent) tabbedPane
+												.getTabComponentAt(tabbedPane2.getSelectedIndex())).removeTabs();
 									}
+								} catch (Exception e2) {
 								}
 							}
 						}
@@ -439,7 +456,7 @@ public class GUI<E> implements CategoryListener {
 					uNC.repaint();
 
 					// or Canvas?
-				} else if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
+				} else if (((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
 						.getComponent(0) instanceof MyCanvas) {
 					boolean save = false;
 					for (int j = 0; j < model.getSelectedCpsObjects().size(); j++) {
@@ -449,13 +466,26 @@ public class GUI<E> implements CategoryListener {
 						controller.delCanvasObject(cps, save);
 						// Remove UpperNodeTab if UpperNode deleted
 						if (cps instanceof CpsUpperNode) {
+							boolean splitView = false;
 							for (int i = 4; i < tabbedPane.getTabCount(); i++) {
-								if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
+								if (tabbedPane.getComponentAt(i) == null) {
+									splitView = true;
+								} else if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
 										.getComponent(0)).upperNode.getId() == cps.getId()) {
-									tabbedPane.remove(i);
-									i = tabbedPane.getTabCount();
+									((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
+									break;
 								}
 							}
+							// If SplitView is on and the view on
+							// tabbedPane2 is the deleted upperNode
+							try {
+								if (splitView && ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
+										.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
+									((ButtonTabComponent) tabbedPane.getTabComponentAt(tabbedPane2.getSelectedIndex()))
+											.removeTabs();
+								}
+							} catch (Exception e2) {
+							}
 						}
 					}
 					canvas.repaint();
@@ -654,19 +684,24 @@ public class GUI<E> implements CategoryListener {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				ArrayList<Category> cat = model.getCategories();
-				while (!cat.isEmpty()) {
-					controller.deleteCategory(cat.get(0).getName());
-					;
+				try {
+					while (!cat.isEmpty()) {
+						controller.deleteCategory(cat.get(0).getName());
+
+					}
+					controller.resetCategorys();
+				} catch (Exception e2) {
+					// TODO: handle exception
 				}
-				controller.resetCategorys();
+
 				tree.repaint();
 			}
 		});
 
 		menuBar.add(mnNewMenuView);
 
-		mnNewMenuView.add(canvasSize);
-		canvasSize.addActionListener(new ActionListener() {
+		mnNewMenuView.add(mntmCanvasSize);
+		mntmCanvasSize.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				JPanel myPanel = new JPanel();
@@ -707,10 +742,53 @@ public class GUI<E> implements CategoryListener {
 			}
 		});
 
-		mnNewMenuView.add(canvasSize);
+		mnNewMenuView.add(mntmCanvasSize);
+		mnNewMenuView.add(mntmSplitView);
+		
+		// Split View
+				mntmSplitView.addActionListener(new ActionListener() {
+					@Override
+					public void actionPerformed(ActionEvent e) {
+						if (splitPaneCanvasConsole.getLeftComponent() instanceof JSplitPane) {
+							initSplit = true;
+							Component tempC = tabbedPane2.getSelectedComponent();
+							tabbedPane.setComponentAt(tabbedPane2.getSelectedIndex(), tempC);
+							tabbedPane2.removeAll();
+							splitPaneCanvasConsole.setLeftComponent(tabbedPane);
+						} else {
+							for (int i = 0; i < tabbedPane.getTabCount(); i++) {
+								tabbedPane2.addTab(tabbedPane.getTitleAt(i), null);
+								if (i >= 4) {
+									// tabbedPane2.setTabComponentAt(tabbedPane.getTabCount()
+									// - 1,
+									// new ButtonTabComponent(tabbedPane, tabbedPane2));
+								}
+							}
+							if (tabbedPane.getSelectedComponent() == statScrollPane) {
+								tabbedPane.setComponentAt(0, null);
+								tabbedPane2.setComponentAt(0, canvasSP);
+								tabbedPane2.setSelectedIndex(0);
+							} else {
+								tabbedPane.setComponentAt(1, null);
+								tabbedPane2.setComponentAt(1, statScrollPane);
+								tabbedPane2.setSelectedIndex(1);
+							}
+							tempSplit = new JSplitPane();
+							tempSplit.setBorder(null);
+							tempSplit.setRightComponent(tabbedPane2);
+							tempSplit.setLeftComponent(tabbedPane);
+							tempSplit.setDividerLocation(tabbedPane.getWidth() / 2);
+							tempSplit.setResizeWeight(0.9);
+							splitPaneCanvasConsole.setLeftComponent(tempSplit);
+							initSplit = false;
+						}
+						contentPane.updateUI();
+					}
 
-		mnNewMenuView.add(background);
-		background.addActionListener(new ActionListener() {
+				});
+		mnNewMenuView.add(mntmBackground);
+		
+		mntmBackground.addActionListener(new ActionListener() {
 
 			@Override
 			public void actionPerformed(ActionEvent e) {
@@ -754,57 +832,15 @@ public class GUI<E> implements CategoryListener {
 
 		splitPane_1.setLeftComponent(lblHolonBodySize);
 
-		menuBar.add(mnHelp);
+		mnAlgorithm.add(simMenu);
 
-		mnHelp.add(aboutUs);
+		menuBar.add(mnAlgorithm);
 
-		// Testing
-		menuBar.add(splitButton);
-		// Split View
-		splitButton.addActionListener(new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				if (panelTapped_SimMenu
-						.getComponent(panelTapped_SimMenu.getComponentCount() - 1) instanceof JSplitPane) {
-					initSplit = true;
-					Component tempC = tabbedPane2.getSelectedComponent();
-					tabbedPane.setComponentAt(tabbedPane2.getSelectedIndex(), tempC);
-					tabbedPane2.removeAll();
-					panelTapped_SimMenu
-							.remove(panelTapped_SimMenu.getComponent(panelTapped_SimMenu.getComponentCount() - 1));
-					panelTapped_SimMenu.add(tabbedPane);
-				} else {
-					for (int i = 0; i < tabbedPane.getTabCount(); i++) {
-						tabbedPane2.addTab(tabbedPane.getTitleAt(i), null);
-						if (i >= 4) {
-							// tabbedPane2.setTabComponentAt(tabbedPane.getTabCount()
-							// - 1,
-							// new ButtonTabComponent(tabbedPane, tabbedPane2));
-						}
-					}
-					if (tabbedPane.getSelectedComponent() == statScrollPane) {
-						tabbedPane.setComponentAt(0, null);
-						tabbedPane2.setComponentAt(0, canvasSP);
-						tabbedPane2.setSelectedIndex(0);
-					} else {
-						tabbedPane.setComponentAt(1, null);
-						tabbedPane2.setComponentAt(1, statScrollPane);
-						tabbedPane2.setSelectedIndex(1);
-					}
-					tempSplit = new JSplitPane();
-					tempSplit.setBorder(null);
-					tempSplit.setRightComponent(tabbedPane2);
-					tempSplit.setLeftComponent(tabbedPane);
-					tempSplit.setDividerLocation(tabbedPane.getWidth() / 2);
-					tempSplit.setResizeWeight(0.9);
-					panelTapped_SimMenu.remove(tabbedPane);
-					panelTapped_SimMenu.add(tempSplit);
-					initSplit = false;
-				}
-				contentPane.updateUI();
-			}
+		menuBar.add(mnHelp);
 
-		});
+		mnHelp.add(mntmAboutUs);
+
+		
 
 		tabbedPane.addChangeListener(new ChangeListener() {
 
@@ -1497,7 +1533,7 @@ public class GUI<E> implements CategoryListener {
 		 * Pop up - About Us with some important information about the
 		 * developers, source and programming stuff
 		 */
-		aboutUs.addMouseListener(new MouseAdapter() {
+		mntmAboutUs.addMouseListener(new MouseAdapter() {
 			@Override
 			public void mousePressed(MouseEvent e) {
 				aboutUsPopUp = new AboutUsPopUp();
@@ -1586,23 +1622,27 @@ public class GUI<E> implements CategoryListener {
 					DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
 					String nodeName = selectedNode.getUserObject().toString();
 					int depthOfNode = selectedNode.getLevel();
+					try {
+						switch (depthOfNode) {
+						case 1:
+							int dialogResult = JOptionPane.showConfirmDialog(null, eraseCategory + nodeName + "?",
+									warningText, JOptionPane.YES_NO_OPTION);
+							if (dialogResult == JOptionPane.YES_OPTION) {
+								controller.deleteCategory(nodeName);
+							}
+							break;
+						case 2:
+							DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
+							controller.delObjectCategory(parent.getUserObject().toString(), nodeName);
+							break;
 
-					switch (depthOfNode) {
-					case 1:
-						int dialogResult = JOptionPane.showConfirmDialog(null, eraseCategory + nodeName + "?",
-								warningText, JOptionPane.YES_NO_OPTION);
-						if (dialogResult == JOptionPane.YES_OPTION) {
-							controller.deleteCategory(nodeName);
+						default:
+							JOptionPane.showMessageDialog(new JFrame(), selectObjBeforeErase);
 						}
-						break;
-					case 2:
-						DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
-						controller.delObjectCategory(parent.getUserObject().toString(), nodeName);
-						break;
-
-					default:
-						JOptionPane.showMessageDialog(new JFrame(), selectObjBeforeErase);
+					} catch (Exception e2) {
+						// TODO: handle exception
 					}
+
 				} else {
 					JOptionPane.showMessageDialog(new JFrame(), selectObjBeforeErase);
 				}
@@ -1663,6 +1703,7 @@ public class GUI<E> implements CategoryListener {
 						tree.repaint();
 					} catch (IOException | ArchiveException e) {
 						// TODO Auto-generated catch block
+						e.printStackTrace();
 						JLabel message = new JLabel("The savefile is corrupt and cannot be opened.");
 						JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
 					}
@@ -1689,19 +1730,19 @@ public class GUI<E> implements CategoryListener {
 					if (fileChooser.getFileFilter().equals(holonFilter)) {
 						if (!file.contains("."))
 							file += ".holon";
-						if (!file.endsWith(".holon")) {
-							String suffix = file.substring(file.lastIndexOf("."), file.length());
-							String[] options = new String[] { "keep .holon", "use " + suffix };
+					}
+					if (!file.endsWith(".holon")) {
+						String suffix = file.substring(file.lastIndexOf("."), file.length());
+						String[] options = new String[] { "keep .holon", "use " + suffix };
 
-							JLabel message = new JLabel(
-									"Are you sure to use the extension \"" + suffix + "\" instead of \".holon\"?");
+						JLabel message = new JLabel(
+								"Are you sure to use the extension \"" + suffix + "\" instead of \".holon\"?");
 
-							int response = JOptionPane.showOptionDialog(null, message, "", JOptionPane.DEFAULT_OPTION,
-									JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
+						int response = JOptionPane.showOptionDialog(null, message, "", JOptionPane.DEFAULT_OPTION,
+								JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
 
-							if (response == 0)
-								file = file.replace(suffix, ".holon");
-						}
+						if (response == 0)
+							file = file.replace(suffix, ".holon");
 					}
 
 					try {
@@ -1842,7 +1883,9 @@ public class GUI<E> implements CategoryListener {
 				controller.runAlgorithm(model, controller);
 				controller.calculateStateForTimeStep(i);
 				unitGraph.repaint();
-				statSplitPane.repaintGraphs();
+				if (model.getIsSimRunning()) {
+					statSplitPane.repaintGraphs();
+				}
 				contentPane.updateUI();
 			}
 		});
@@ -1854,7 +1897,7 @@ public class GUI<E> implements CategoryListener {
 		splitPaneCanvasConsole.setResizeWeight(0.9);
 
 		splitPane.setLeftComponent(scrollPane1);
-		splitPaneCanvasConsole.setLeftComponent(panelTapped_SimMenu);
+		splitPaneCanvasConsole.setLeftComponent(tabbedPane);
 		tabbedPane.addTab("View", canvasSP);
 		tabbedPane.addTab("Statistics", statScrollPane);
 		tabbedPane.addTab("Holon", holonCanvas);
@@ -1876,12 +1919,8 @@ public class GUI<E> implements CategoryListener {
 		splitGraphHolonEl.setBottomComponent(scrollElements);
 		canvasSP.setViewportView(canvas);
 		// holonSP.setViewportView(holonCanvas);
-		panelTapped_SimMenu.setLayout(new BorderLayout());
-		panelTapped_SimMenu.add(simMenu, BorderLayout.NORTH);
-		panelTapped_SimMenu.add(tabbedPane);
 		simMenu.setBackground(new Color(240, 240, 240));
 
-		panelTapped_SimMenu.setBorder(null);
 		tabbedPane.setBorder(null);
 		scrollProperties.setBorder(null);
 		scrollGraph.setBorder(null);
@@ -1899,6 +1938,12 @@ public class GUI<E> implements CategoryListener {
 
 		frmCyberPhysical.getContentPane().add(timePanel, BorderLayout.SOUTH);
 
+		try {
+			controller.loadAutoSave(System.getProperty("user.home") + "/HolonGUI/Category/Category.json");
+		} catch (IOException e1) {
+			// TODO Auto-generated catch block
+		}
+
 		String autoPath = System.getProperty("user.home") + "/HolonGUI/Autosave/";
 		File dest = new File(autoPath);
 		if (dest.listFiles().length > 1) {
@@ -1917,6 +1962,7 @@ public class GUI<E> implements CategoryListener {
 				setUpAutoSave(dest);
 			}
 		}
+
 		canvasSP.addComponentListener(new ComponentAdapter() {
 			@Override
 			public void componentResized(ComponentEvent e) {
@@ -1965,12 +2011,17 @@ public class GUI<E> implements CategoryListener {
 				Category cat = controller.searchCategory(selectedNode.getUserObject().toString());
 
 				if (objname.length() != 0) {
-					switch (objType) {
+					try {
+						switch (objType) {
 
-					case "Switch":
-						controller.addSwitch(cat, objname);
-						break;
+						case "Switch":
+							controller.addSwitch(cat, objname);
+							break;
+						}
+					} catch (Exception e) {
+						// TODO: handle exception
 					}
+
 				}
 			} else {
 				JOptionPane.showMessageDialog(new JFrame(),
@@ -2071,9 +2122,9 @@ public class GUI<E> implements CategoryListener {
 		mnNewMenuOptions.setText(tempArray[9]);
 		mntmResetCategory.setText(tempArray[10]);
 		mnNewMenuView.setText(tempArray[11]);
-		canvasSize.setText(tempArray[12]);
+		mntmCanvasSize.setText(tempArray[12]);
 		mnHelp.setText(tempArray[13]);
-		aboutUs.setText(tempArray[14]);
+		mntmAboutUs.setText(tempArray[14]);
 		mntmEditEdges.setText(tempArray[15]);
 		mnLanguage.setText(tempArray[16]);
 		canvas.updateLanguages();
@@ -2200,6 +2251,7 @@ public class GUI<E> implements CategoryListener {
 
 			JScrollPane sp = new JScrollPane(unc);
 			sp.setBorder(null);
+			// Selected tabbed Pane = tabbedPane or tabbedPane2
 			if (tabTemp == tabbedPane) {
 				tabbedPane.add(temp.getName(), sp);
 				tabbedPane.setSelectedComponent(sp);

+ 35 - 7
src/ui/view/MyCanvas.java

@@ -27,6 +27,7 @@ import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
 import javax.swing.JTabbedPane;
 
 import com.google.gson.JsonParseException;
@@ -71,7 +72,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	ArrayList<HolonElement> dataSelected = new ArrayList<HolonElement>();
 	ArrayList<AbstractCpsObject> tempSelected = new ArrayList<AbstractCpsObject>();
 
-	private boolean[] showedInformation = new boolean[4];
+	private boolean[] showedInformation = new boolean[5];
 	private boolean dragging = false; // for dragging
 	private boolean dragged = false; // if an object/objects was/were dragged
 	private boolean drawEdge = false; // for drawing edges
@@ -131,6 +132,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		showedInformation[0] = true;
 		showedInformation[1] = true;
 		showedInformation[3] = false;
+		showedInformation[4] = true;
 		control.setMaxCapacity(10000);
 
 		popmenu.add(itemCut);
@@ -342,16 +344,40 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 					controller.removeTrackingObj(cps);
 					// Remove UpperNodeTab if UpperNode deleted
 					if (cps instanceof CpsUpperNode) {
-						JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
+						boolean splitView = false;
+						JSplitPane tempSplit = (JSplitPane) getParent().getParent().getParent().getParent();
+						JTabbedPane tabbedPane;
+						JTabbedPane tabbedPane2;
+						// if SplitView is activated
+						if (tempSplit.getLeftComponent() instanceof JTabbedPane
+								&& tempSplit.getRightComponent() instanceof JTabbedPane) {
+							splitView = true;
+							tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
+							tabbedPane2 = (JTabbedPane) tempSplit.getRightComponent();
+						} else {
+							tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
+							tabbedPane2 = null;
+						}
+						//Look if the uppernode is open in a Tab
 						for (int i = 4; i < tabbedPane.getTabCount(); i++) {
-							if (tabbedPane.getComponentAt(i) != null
-									&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
-											.getComponent(0)).upperNode.getId() == cps.getId()) {
-
+							if (tabbedPane.getComponentAt(i) == null) {
+							} else if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
+									.getComponent(0)).upperNode.getId() == cps.getId()) {
 								((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
 								break;
 							}
 						}
+						// If SplitView is on and the view on
+						// tabbedPane2 is the deleted upperNode
+						try {
+							if (tabbedPane2 != null
+									&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
+											.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
+								((ButtonTabComponent) tabbedPane
+										.getTabComponentAt(tabbedPane2.getSelectedIndex())).removeTabs();
+							}
+						} catch (Exception e2) {
+						}
 					}
 					toolTip = false;
 				}
@@ -1115,11 +1141,13 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	 *            boolean for conecction
 	 * @param object
 	 *            boolean for objects
+	 * @param nodeOfnode
 	 */
-	public void setShowedInformation(boolean connection, boolean object, boolean border) {
+	public void setShowedInformation(boolean connection, boolean object, boolean border, boolean nodeOfnode) {
 		showedInformation[0] = connection;
 		showedInformation[1] = object;
 		showedInformation[3] = border;
+		showedInformation[4] = nodeOfnode;
 	}
 
 	/**

+ 14 - 7
src/ui/view/ShowedInformationPopUp.java

@@ -24,6 +24,7 @@ public class ShowedInformationPopUp extends JDialog {
 	private JCheckBox objectEnergyCheckbox;
 	private JCheckBox connectionCheckbox;
 	private JCheckBox colorizedBorderCheckbox;
+	private JCheckBox nodeOfnodeConnectionCheckbox;
 	private JPanel toUpdate;
 
 	/**
@@ -36,7 +37,7 @@ public class ShowedInformationPopUp extends JDialog {
 		super((java.awt.Frame) null, true);
 		setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
 		this.setTitle(Languages.getLanguage()[31]);
-		setBounds(100, 100, 400, 220);
+		setBounds(100, 100, 400, 254);
 		getContentPane().setLayout(new BorderLayout());
 		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
 		getContentPane().add(contentPanel, BorderLayout.CENTER);
@@ -57,11 +58,11 @@ public class ShowedInformationPopUp extends JDialog {
 		btnOk.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent arg0) {
 				setInformation(connectionCheckbox.isSelected(), objectEnergyCheckbox.isSelected(),
-						colorizedBorderCheckbox.isSelected());
+						colorizedBorderCheckbox.isSelected(), nodeOfnodeConnectionCheckbox.isSelected());
 				dispose();
 			}
 		});
-		btnOk.setBounds(171, 147, 82, 23);
+		btnOk.setBounds(174, 193, 82, 23);
 		contentPanel.add(btnOk);
 
 		JButton btnCancel = new JButton(Languages.getLanguage()[34]);
@@ -71,13 +72,18 @@ public class ShowedInformationPopUp extends JDialog {
 				dispose();
 			}
 		});
-		btnCancel.setBounds(72, 147, 89, 23);
+		btnCancel.setBounds(69, 193, 89, 23);
 		contentPanel.add(btnCancel);
 		
 		colorizedBorderCheckbox = new JCheckBox("Show colorized Border for Objects");
-		colorizedBorderCheckbox.setBounds(19, 96, 195, 23);
+		colorizedBorderCheckbox.setBounds(19, 96, 369, 23);
 		contentPanel.add(colorizedBorderCheckbox);
 		colorizedBorderCheckbox.setSelected(canvas.getShowedInformation()[3]);
+		
+		nodeOfnodeConnectionCheckbox = new JCheckBox("Show outside Connections in gouped Nodes");
+		nodeOfnodeConnectionCheckbox.setBounds(19, 133, 369, 23);
+		contentPanel.add(nodeOfnodeConnectionCheckbox);
+		nodeOfnodeConnectionCheckbox.setSelected(canvas.getShowedInformation()[4]);
 	}
 
 	/**
@@ -87,9 +93,10 @@ public class ShowedInformationPopUp extends JDialog {
 	 *            conection Information
 	 * @param object
 	 *            Object Information
+	 * @param nodeOfnode 
 	 */
-	private void setInformation(boolean connection, boolean object, boolean borders) {
-		canvas.setShowedInformation(connection, object, borders);
+	private void setInformation(boolean connection, boolean object, boolean borders, boolean nodeOfnode) {
+		canvas.setShowedInformation(connection, object, borders, nodeOfnode);
 		canvas.repaint();
 		toUpdate.updateUI();
 	}

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

@@ -110,6 +110,7 @@ public class StatPanel2 extends JSplitPane implements GraphListener {
 		this.controller = cont;
 		objectHashtable = new Hashtable<String, GraphDataSet>();
 		graphHashtable = new Hashtable<String, StatisticGraphPanel>();
+		controller.setGraphTable(graphHashtable);
 		
 		holonHashtable = new Hashtable<String, PropertyDataSet>();
 		holonHashtable.put(TOT_PROD_HOLON, new PropertyDataSet());

+ 77 - 65
src/ui/view/StatisticGraph.java

@@ -83,60 +83,54 @@ public class StatisticGraph extends JPanel {
 			g2.drawLine(0, i, this.getWidth(), i);
 		}
 
-		isSimRunning = true;
-
-		// if sim is on
-		if (isSimRunning) {
-			g2.setStroke(new BasicStroke(3));
-
-			// Calculate the Maximum
-			// calcMaximum();
-
-			// Calculate values for each set and add them
-			// addValues();
-
-			// Create Paths and draw them
-			for (TrackedDataSet set : dataSets) {
-				path.reset();
-				switch (set.getProperty()) {
-				case TrackedDataSet.CONSUMPTION:
-				case TrackedDataSet.PRODUCTION:
-				case TrackedDataSet.ACTIVATED_ELEMENTS:
-				case TrackedDataSet.TOTAL_PRODUCTION:
-				case TrackedDataSet.TOTAL_CONSUMPTION:
-				case TrackedDataSet.AMOUNT_HOLONS:
-				case TrackedDataSet.GROUP_CONSUMPTION:
-				case TrackedDataSet.GROUP_PRODUCTION:
-				case TrackedDataSet.AMOUNT_CLOSED_SWITCHES:
-				case TrackedDataSet.AVG_AMOUNT_OBJECTS_IN_HOLONS:
-				case TrackedDataSet.AVG_AMOUNT_ELEMENTS_IN_HOLONS:
-				case TrackedDataSet.AVG_AMOUNT_PRODUCERS_IN_HOLONS:
-				case TrackedDataSet.AVG_CONSUMED_ENERGY_IN_HOLONS:
-				case TrackedDataSet.AVG_WASTED_ENERGY_IN_HOLONS:
-				case TrackedDataSet.AMOUNT_BROKEN_EDGES:
-				case TrackedDataSet.AVG_AMOUNT_CLOSED_SWITCHES_IN_HOLONS:
-				case TrackedDataSet.AVG_AMOUNT_ACTIVE_ELEMENTS_IN_HOLONS:
-				case TrackedDataSet.AVG_AMOUNT_INACTIVE_ELEMENTS_IN_HOLONS:
-				case TrackedDataSet.AVG_PRODUCED_ENERGY_IN_HOLONS:
-					createPathFloats(set);
-					break;
-				case TrackedDataSet.ON_OFF:
-					createPathBooleans(set);
-					break;
-				case TrackedDataSet.PERCENT_SUPPLIED:
-				case TrackedDataSet.PERCENT_NOT_SUPPLIED:
-				case TrackedDataSet.PERCENT_PARTIAL_SUPPLIED:
-				case TrackedDataSet.RATIO_PRODUCERS_CONSUMERS:
-					createPathPercent(set);
-					break;
-				default:
-					break;
-				}
-				g2.setColor(set.getColor());
-				g2.draw(path);
+		g2.setStroke(new BasicStroke(3));
+
+		// Calculate the Maximum
+		// calcMaximum();
+
+		// Calculate values for each set and add them
+		// addValues();
+
+		// Create Paths and draw them
+		for (TrackedDataSet set : dataSets) {
+			path.reset();
+			switch (set.getProperty()) {
+			case TrackedDataSet.CONSUMPTION:
+			case TrackedDataSet.PRODUCTION:
+			case TrackedDataSet.ACTIVATED_ELEMENTS:
+			case TrackedDataSet.TOTAL_PRODUCTION:
+			case TrackedDataSet.TOTAL_CONSUMPTION:
+			case TrackedDataSet.AMOUNT_HOLONS:
+			case TrackedDataSet.GROUP_CONSUMPTION:
+			case TrackedDataSet.GROUP_PRODUCTION:
+			case TrackedDataSet.AMOUNT_CLOSED_SWITCHES:
+			case TrackedDataSet.AVG_AMOUNT_OBJECTS_IN_HOLONS:
+			case TrackedDataSet.AVG_AMOUNT_ELEMENTS_IN_HOLONS:
+			case TrackedDataSet.AVG_AMOUNT_PRODUCERS_IN_HOLONS:
+			case TrackedDataSet.AVG_CONSUMED_ENERGY_IN_HOLONS:
+			case TrackedDataSet.AVG_WASTED_ENERGY_IN_HOLONS:
+			case TrackedDataSet.AMOUNT_BROKEN_EDGES:
+			case TrackedDataSet.AVG_AMOUNT_CLOSED_SWITCHES_IN_HOLONS:
+			case TrackedDataSet.AVG_AMOUNT_ACTIVE_ELEMENTS_IN_HOLONS:
+			case TrackedDataSet.AVG_AMOUNT_INACTIVE_ELEMENTS_IN_HOLONS:
+			case TrackedDataSet.AVG_PRODUCED_ENERGY_IN_HOLONS:
+				createPathFloats(set);
+				break;
+			case TrackedDataSet.ON_OFF:
+				createPathBooleans(set);
+				break;
+			case TrackedDataSet.PERCENT_SUPPLIED:
+			case TrackedDataSet.PERCENT_NOT_SUPPLIED:
+			case TrackedDataSet.PERCENT_PARTIAL_SUPPLIED:
+			case TrackedDataSet.RATIO_PRODUCERS_CONSUMERS:
+				createPathPercent(set);
+				break;
+			default:
+				break;
 			}
+			g2.setColor(set.getColor());
+			g2.draw(path);
 		}
-
 	}
 
 	/**
@@ -197,7 +191,7 @@ public class StatisticGraph extends JPanel {
 			case TrackedDataSet.CONSUMPTION:
 				for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
 					if (h.getEnergy() < 0) {
-						val += h.getEnergy() * h.getAmount();
+						val += (h.getEnergy() + h.getFlexibility()) * h.getAmount();
 					}
 				}
 				val *= -1;
@@ -205,7 +199,7 @@ public class StatisticGraph extends JPanel {
 			case TrackedDataSet.PRODUCTION:
 				for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
 					if (h.getEnergy() > 0) {
-						val += h.getEnergy() * h.getAmount();
+						val += (h.getEnergy() + h.getFlexibility()) * h.getAmount();
 					}
 				}
 				break;
@@ -335,16 +329,16 @@ public class StatisticGraph extends JPanel {
 			switch (set.getProperty()) {
 			case TrackedDataSet.CONSUMPTION:
 				for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
-					if (h.getEnergy() < 0 && h.getActive()) {
-						val += Math.abs(h.getEnergyAt()[model.getCurIteration()]) * h.getAmount();
+					if (h.getTotalEnergyAtTimeStep(model.getCurIteration()) < 0 && h.getActive()) {
+						val += Math.abs(h.getTotalEnergyAtTimeStep(model.getCurIteration()));
 					}
 					set.setValAt(val, model.getCurIteration());
 				}
 				break;
 			case TrackedDataSet.PRODUCTION:
 				for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
-					if (h.getEnergy() > 0 && h.getActive()) {
-						val += Math.abs(h.getEnergyAt()[model.getCurIteration()]) * h.getAmount();
+					if (h.getTotalEnergyAtTimeStep(model.getCurIteration()) > 0 && h.getActive()) {
+						val += Math.abs(h.getTotalEnergyAtTimeStep(model.getCurIteration()));
 					}
 					set.setValAt(val, model.getCurIteration());
 				}
@@ -537,17 +531,21 @@ public class StatisticGraph extends JPanel {
 	 * @param set
 	 */
 	private void createPathFloats(TrackedDataSet set) {
+		int range = model.getCurIteration(); //to which iteration
+		if (!model.getIsSimRunning()) {
+			range = model.getIterations()-1;
+		}
 		if (set.getValues()[0] != -1) {
 			path.moveTo(0, convertToCanvasY(set.getValues()[0]));
 		} else {
 			path.moveTo(1 * this.getWidth() / model.getIterations(), convertToCanvasY(set.getValues()[1]));
 		}
-		for (int i = 0; i < model.getCurIteration(); i++) {
+		for (int i = 0; i < range; i++) {
 			if (set.getValues()[i + 1] != -1) {
 				path.lineTo((i + 1) * this.getWidth() / model.getIterations(),
 						convertToCanvasY(set.getValues()[i + 1]));
 			} else {
-				if (i + 2 < model.getCurIteration()) {
+				if (i + 2 < range) {
 					path.moveTo((i + 2) * this.getWidth() / model.getIterations(),
 							convertToCanvasY(set.getValues()[i + 2]));
 				}
@@ -619,7 +617,7 @@ public class StatisticGraph extends JPanel {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
 					if (ele.getEnergy() > 0) {
-						val += ele.getEnergy() * ele.getAmount();
+						val += (ele.getEnergy() + ele.getFlexibility()) * ele.getAmount();
 					}
 				}
 			} else if (obj instanceof CpsUpperNode) {
@@ -642,7 +640,7 @@ public class StatisticGraph extends JPanel {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
 					if (ele.getEnergy() < 0) {
-						val += ele.getEnergy() * ele.getAmount();
+						val += (ele.getEnergy() + ele.getFlexibility()) * ele.getAmount();
 					}
 				}
 			} else if (obj instanceof CpsUpperNode) {
@@ -665,8 +663,8 @@ public class StatisticGraph extends JPanel {
 		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
-					if (ele.getEnergyAt()[tStep] > 0 && ele.getActive()) {
-						val += ele.getEnergyAt()[tStep] * ele.getAmount();
+					if (ele.getTotalEnergyAtTimeStep(tStep) > 0 && ele.getActive()) {
+						val += ele.getTotalEnergyAtTimeStep(tStep);
 					}
 				}
 			} else if (obj instanceof CpsUpperNode) {
@@ -690,7 +688,7 @@ public class StatisticGraph extends JPanel {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
 					if (ele.getEnergyAt()[tStep] < 0 && ele.getActive()) {
-						val += ele.getEnergyAt()[tStep] * ele.getAmount();
+						val += ele.getTotalEnergyAtTimeStep(tStep);
 					}
 				}
 			} else if (obj instanceof CpsUpperNode) {
@@ -714,8 +712,22 @@ public class StatisticGraph extends JPanel {
 		return stateObjectss / count;
 	}
 
+	/**
+	 * Return all TrackedDataSets
+	 * 
+	 * @return ArrayList of TrackedDataSet
+	 */
 	public ArrayList<TrackedDataSet> getDataSets() {
 		return dataSets;
 	}
 
+	/**
+	 * Reset the Graph. Delete all calculated values.
+	 */
+	public void resetGraph() {
+		for (TrackedDataSet s : dataSets) {
+			s.resetValues();
+		}
+	}
+
 }

+ 14 - 0
src/ui/view/StatisticGraphPanel.java

@@ -289,4 +289,18 @@ public class StatisticGraphPanel extends JPanel {
 		sGraph.calcMaximum();
 	}
 	
+	public StatisticGraph getStatGraph(){
+		return sGraph;
+	}
+	
+	public void setStatisticGraph(StatisticGraph sG){
+		this.sGraph = sG;
+	}
+	/**
+	 *	Reset the Graph. Delete all calculated values.
+	 */
+	public void resetGraph(){
+		sGraph.resetGraph();
+	}
+	
 }

+ 15 - 3
src/ui/view/TimePanel.java

@@ -128,6 +128,9 @@ public class TimePanel extends JPanel {
 			@Override
 			public void mousePressed(MouseEvent e) {
 				controller.resetSimulation();
+				if (running) {
+					playBtn.doClick();
+				}
 			}
 		});
 
@@ -135,6 +138,9 @@ public class TimePanel extends JPanel {
 			@Override
 			public void mouseDragged(MouseEvent e) {
 				controller.resetSimulation();
+				if (running) {
+					playBtn.doClick();
+				}
 			}
 		});
 
@@ -155,6 +161,9 @@ public class TimePanel extends JPanel {
 			public void actionPerformed(ActionEvent e) {
 				running = !running;
 				if (running) {
+					if (!model.getIsSimRunning()) {
+						controller.setIsSimRunning(true);
+					}
 					timer.start();
 					timer.setDelay(model.getTimerSpeed());
 					playBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/pause.png"))
@@ -178,6 +187,9 @@ public class TimePanel extends JPanel {
 				controller.setCurIteration(timeSlider.getValue());
 				// controller.calculateStateForCurrentTimeStep();
 				controller.resetSimulation();
+				if (running) {
+					playBtn.doClick();
+				}
 			}
 		});
 		timeForwardBtn.setToolTipText(Languages.getLanguage()[91]);
@@ -222,17 +234,17 @@ public class TimePanel extends JPanel {
 		speedSlider.setMaximum(5000);
 		speedSlider.setMinimum(500);
 		speedSlider.setValue(1000);
-		//speedSlider.setMajorTickSpacing(100);
+		// speedSlider.setMajorTickSpacing(100);
 		speedSlider.addChangeListener(new ChangeListener() {
 			@Override
 			public void stateChanged(ChangeEvent e) {
 				controller.setTimerSpeed(speedSlider.getValue());
-				speedSlider.setToolTipText("Speed: "+speedSlider.getValue());
+				speedSlider.setToolTipText("Speed: " + speedSlider.getValue());
 			}
 		});
 
 		// Buttons and Speed Panel
-		btnAndSpeedPanel.setLayout(new BorderLayout(0,0));
+		btnAndSpeedPanel.setLayout(new BorderLayout(0, 0));
 		btnAndSpeedPanel.setBorder(null);
 		btnAndSpeedPanel.add(timeBtnPanel, BorderLayout.NORTH);
 		btnAndSpeedPanel.add(speedPanel, BorderLayout.CENTER);

+ 52 - 11
src/ui/view/UpperNodeCanvas.java

@@ -27,6 +27,7 @@ import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
 import javax.swing.JTabbedPane;
 
 import com.google.gson.JsonParseException;
@@ -74,7 +75,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	// The UpperNode
 	public CpsUpperNode upperNode;
 
-	private boolean[] showedInformation = new boolean[3];
+	private boolean[] showedInformation = new boolean[5];
 	private boolean dragging = false; // for dragging
 	private boolean dragged = false; // if an object/objects was/were dragged
 	private boolean drawEdge = false; // for drawing edges
@@ -151,6 +152,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 
 		showedInformation[0] = true;
 		showedInformation[1] = true;
+		showedInformation[4] = true;
 
 		popmenu.add(itemCut);
 		popmenu.add(itemCopy);
@@ -357,14 +359,41 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 						controller.removeTrackingObj(cps);
 						// Remove UpperNodeTab if UpperNode deleted
 						if (cps instanceof CpsUpperNode) {
-							JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
+							boolean splitView = false;
+							JSplitPane tempSplit = (JSplitPane) getParent().getParent().getParent().getParent();
+							JTabbedPane tabbedPane;
+							JTabbedPane tabbedPane2;
+							// if SplitView is activated
+							if (tempSplit.getLeftComponent() instanceof JTabbedPane
+									&& tempSplit.getRightComponent() instanceof JTabbedPane) {
+								splitView = true;
+								tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
+								tabbedPane2 = (JTabbedPane) tempSplit.getRightComponent();
+							} else {
+								tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
+								tabbedPane2 = null;
+							}
+							//Look if the uppernode is open in a Tab
 							for (int i = 4; i < tabbedPane.getTabCount(); i++) {
-								if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
+								if (tabbedPane.getComponentAt(i) == null) {
+								} else if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
 										.getComponent(0)).upperNode.getId() == cps.getId()) {
-									tabbedPane.remove(i);
-									i = tabbedPane.getTabCount();
+									((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
+									break;
 								}
 							}
+							// If SplitView is on and the view on
+							// tabbedPane2 is the deleted upperNode
+							try {
+								if (tabbedPane2 != null
+										&& ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
+												.getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
+									((ButtonTabComponent) tabbedPane
+											.getTabComponentAt(tabbedPane2.getSelectedIndex())).removeTabs();
+								}
+							} catch (Exception e2) {
+							}
+
 						}
 					}
 				}
@@ -666,7 +695,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 				cps = e.getA();
 			}
 			// Show and Highlight
-			if (model.getSelectedCpsObjects().contains(cps)) {
+			if (model.getSelectedCpsObjects().contains(cps) || showedInformation[4] == true) {
 				for (CpsEdge ed : cps.getConnections()) {
 					AbstractCpsObject obj = null;
 					if (upperNode.getNodes().contains(ed.getA())) {
@@ -675,10 +704,21 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 						obj = ed.getB();
 					}
 					if (obj != null) {
-						if (ed.getFlow() == 0)
-							g2.setColor(Color.RED);
-						else
-							g2.setColor(Color.BLUE);
+						if (ed.getConnected() == 0) {
+							if (ed.getState()) {
+								g2.setColor(Color.GREEN);
+								if (ed.getCapacity() != -1) {
+									g2.setStroke(
+											new BasicStroke(Math.min(((ed.getFlow() / ed.getCapacity() * 3) + 1), 4)));
+								}
+							} else {
+								g2.setColor(Color.RED);
+								g2.setStroke(new BasicStroke(2));
+							}
+						} else {
+							g2.setColor(Color.DARK_GRAY);
+							g2.setStroke(new BasicStroke(2));
+						}
 						g2.drawLine(obj.getPosition().x, obj.getPosition().y, (borderPos >> 1),
 								(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + 25);
 						if (showedInformation[0]) {
@@ -1423,9 +1463,10 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	 * @param object
 	 *            boolean for objects
 	 */
-	public void setShowedInformation(boolean connection, boolean object) {
+	public void setShowedInformation(boolean connection, boolean object, boolean nodeOfnode) {
 		showedInformation[0] = connection;
 		showedInformation[1] = object;
+		showedInformation[4] = nodeOfnode;
 	}
 
 	/**