Browse Source

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

dominik.rieder 7 years ago
parent
commit
de5bc41a97

+ 4 - 0
src/classes/TrackedDataSet.java

@@ -27,6 +27,10 @@ public class TrackedDataSet {
 	public static final int AVG_WASTED_ENERGY_IN_HOLONS = 17;
 	public static final int AMOUNT_BROKEN_EDGES = 18;
 	public static final int RATIO_PRODUCERS_CONSUMERS = 19;
+	public static final int AVG_AMOUNT_CLOSED_SWITCHES_IN_HOLONS = 20;
+	public static final int AVG_AMOUNT_ACTIVE_ELEMENTS_IN_HOLONS = 21;
+	public static final int AVG_AMOUNT_INACTIVE_ELEMENTS_IN_HOLONS = 22;
+	public static final int AVG_PRODUCED_ENERGY_IN_HOLONS = 23;
 	
 	//Variables of the Data Set
 	private AbstractCpsObject cps;

+ 0 - 15
src/exceptions/CorruptSaveFileException.java

@@ -1,15 +0,0 @@
-package exceptions;
-
-public class CorruptSaveFileException extends Exception{
-
-	private static final long serialVersionUID = 1L;
-	
-	public CorruptSaveFileException() {
-		super();
-	}
-	
-	public CorruptSaveFileException(String s) {
-		super(s);
-	}
-	
-}

+ 16 - 15
src/ui/controller/ClipboardController.java

@@ -136,7 +136,8 @@ public class ClipboardController {
 	 * 
 	 * @param upperNode
 	 */
-	public void paste(CpsUpperNode upperNode, Point p) {
+	public void paste(CpsUpperNode upperNode, Point p)
+			throws UnsupportedFlavorException, IOException, JsonParseException {
 
 		if (p == null)
 			return;
@@ -145,17 +146,17 @@ public class ClipboardController {
 		Transferable content = clipboard.getContents(null);
 
 		if (content != null && content.isDataFlavorSupported(DataFlavor.stringFlavor)
-				&& !content.isDataFlavorSupported(DataFlavor.allHtmlFlavor))
-			try {
-				String str = (String) content.getTransferData(DataFlavor.stringFlavor);
-
-				if (parser.parse(str).isJsonObject())
-					json = (JsonObject) parser.parse(str);
-			} catch (UnsupportedFlavorException | IOException | JsonParseException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		else
+				&& !content.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) {
+
+			String str = (String) content.getTransferData(DataFlavor.stringFlavor);
+			
+			
+			if (parser.parse(str).isJsonObject()) 
+				json = (JsonObject) parser.parse(str);
+			else
+				throw new JsonParseException("Unknown Clipboard Information");
+
+		} else
 			return;
 
 		List<String> keys = load.getKeys(json);
@@ -165,7 +166,7 @@ public class ClipboardController {
 		HashMap<Integer, AbstractCpsObject> objDispatch = new HashMap<>();
 		HashMap<Integer, HolonElement> eleDispatch = new HashMap<>();
 		model.getSelectedCpsObjects().clear();
-		
+
 		objIDMap = new HashMap<>();
 		eleIDMap = new HashMap<>();
 		sav = json.get("SAV").getAsString();
@@ -174,7 +175,7 @@ public class ClipboardController {
 		point = new Point(old.x - p.x, old.y - p.y);
 
 		forwardObjects(keys, json, objDispatch, eleDispatch, upperNode);
-		//for selecting Cps
+		// for selecting Cps
 		getObjectsInDepth();
 		forwardEdges(edges, json, objDispatch, upperNode);
 
@@ -248,7 +249,7 @@ public class ClipboardController {
 				cvsC.addObject(temp);
 			else
 				uppC.addObjectInUpperNode(temp, upperNode);
-			//mark the Pasted Objects
+			// mark the Pasted Objects
 			model.getSelectedCpsObjects().add(temp);
 		} else {
 			// else look up the table and put it into the right Uppernode

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

@@ -2,12 +2,16 @@ package ui.controller;
 
 import java.awt.Color;
 import java.awt.Point;
+import java.awt.datatransfer.UnsupportedFlavorException;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.zip.ZipException;
 
 import org.apache.commons.compress.archivers.ArchiveException;
 
+import com.google.gson.JsonParseException;
+
 import classes.AbstractCpsObject;
 import classes.Category;
 import classes.CpsEdge;
@@ -466,18 +470,28 @@ public class Control {
 	 *             exception
 	 */
 	public void saveFile(String path) throws IOException, ArchiveException {
-		storeController.writeSaveFile(path);
+		storeController.writeSave(path);
 	}
 
 	/**
-	 * Reads the the JSON File and load the state into the Model.
+	 * Reads the the Save File and load the state into the Model.
 	 * 
 	 * @param path
 	 *            the Path
 	 * @throws IOException
 	 *             exception
+	 * @throws ArchiveException 
+	 */
+	public void loadFile(String path) throws IOException, ArchiveException, ZipException {
+		loadController.readSave(path);
+	}
+	
+	/**
+	 * Reads the Json File from Autosave
+	 * @param path
+	 * @throws IOException
 	 */
-	public void loadFile(String path) throws IOException {
+	public void loadAutoSave(String path) throws IOException  {
 		loadController.readJson(path);
 	}
 
@@ -537,7 +551,7 @@ public class Control {
 	 */
 	public void autoSave() throws IOException {
 		autoSaveController.increaseAutoSaveNr();
-		storeController.writeAutosaveFile(autoPath + autoSaveController.getAutoSaveNr());
+		storeController.writeAutosave(autoPath + autoSaveController.getAutoSaveNr());
 		if (autoSaveController.allowed()) {
 			new File(autoPath + (autoSaveController.getAutoSaveNr() - globalController.getNumbersOfSaves())).delete();
 		}
@@ -842,7 +856,7 @@ public class Control {
 		clipboardController.copy(upperNode);
 	}
 	
-	public void paste(CpsUpperNode upperNode, Point point) {
+	public void paste(CpsUpperNode upperNode, Point point) throws JsonParseException, UnsupportedFlavorException, IOException {
 		clipboardController.paste(upperNode, point);
 	}
 	

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

@@ -2,13 +2,23 @@ package ui.controller;
 
 import java.awt.Color;
 import java.awt.Point;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.stream.Collectors;
+import java.util.zip.ZipException;
+
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveException;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
@@ -93,8 +103,15 @@ public class LoadController {
 	 * @throws IOException
 	 *             exception
 	 */
-	public void readJson(String path) throws IOException {
+	public void readSave(String path) throws IOException, ArchiveException, ZipException {
+
+		File src = new File(path);
+		File folder = readArchive(path, src);
+		folder.deleteOnExit();
 
+	}
+
+	public void readJson(String path) throws IOException {
 		JsonObject json = (JsonObject) parser.parse(new FileReader(path));
 		// get all keys via stream
 		List<String> keys = getKeys(json);
@@ -110,6 +127,21 @@ public class LoadController {
 
 	}
 
+	private File readArchive(String path, File src) throws IOException, ArchiveException {
+		File tmp = Files.createTempDirectory("tmpHolon").toFile();
+
+		InputStream input = new FileInputStream(src);
+		ArchiveInputStream stream = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP,
+				input);
+
+		ArchiveEntry entry = stream.getNextEntry();
+		while (entry != null) {
+			entry = stream.getNextEntry();
+		}
+
+		return tmp;
+	}
+
 	/**
 	 * distribute the Edges
 	 * 

+ 56 - 55
src/ui/controller/StoreController.java

@@ -18,8 +18,11 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.stream.Stream;
 
 import javax.imageio.ImageIO;
 
@@ -51,6 +54,7 @@ import classes.HolonSwitch;
 import classes.IdCounter;
 import classes.IdCounterElem;
 import classes.Position;
+import sun.reflect.misc.FieldUtil;
 import ui.model.Model;
 
 /**
@@ -105,15 +109,16 @@ public class StoreController {
 	 * @throws IOException
 	 *             exception
 	 */
-	public void writeSaveFile(String path) throws IOException, ArchiveException {
+	public void writeSave(String path) throws IOException, ArchiveException {
 
 		File dst = new File(path);
 		File holonFile = File.createTempFile("tmp", ".json");
+		holonFile.deleteOnExit();
 		dst.delete();
 
-		OutputStream out = new FileOutputStream(dst);
+		OutputStream output = new FileOutputStream(dst);
 		ArchiveOutputStream stream = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP,
-				out);
+				output);
 
 		initNumeration();
 		JsonObject file = new JsonObject();
@@ -127,10 +132,10 @@ public class StoreController {
 		writer.flush();
 		writer.close();
 
-		addFileToSave(holonFile, stream);
+		addFilesToSave(holonFile, stream);
 
 		stream.finish();
-		out.close();
+		output.close();
 
 	}
 
@@ -142,7 +147,7 @@ public class StoreController {
 	 * @throws IOException
 	 *             Exception
 	 */
-	public void writeAutosaveFile(String path) throws IOException {
+	public void writeAutosave(String path) throws IOException {
 
 		initNumeration();
 		JsonObject file = new JsonObject();
@@ -251,6 +256,21 @@ public class StoreController {
 
 	}
 
+	/**
+	 * Save wanted Data
+	 * @param stream
+	 * @throws IOException
+	 */
+	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);
+		addFilesToSave(background, stream);
+	
+	}
+
 	/**
 	 * Stores Category or Canvas Elements into Json
 	 * 
@@ -367,66 +387,47 @@ public class StoreController {
 
 	}
 
-	private void storeData(ArchiveOutputStream stream) throws IOException {
-		// TODO Auto-generated method stub
-		ArrayList<String> images = new ArrayList<>();
-		Files.newDirectoryStream(Paths.get(System.getProperty("user.home") + "/HolonGUI/Images"),
-				p -> p.toFile().isFile()).forEach(p -> images.add(p.toString()));
-		for (String str : images) {
-			File src = new File(str);
-			addFileToSave(src, stream);
+	/**
+	 * Differs Between Single file or whole Directory to Store
+	 * 
+	 * @param src
+	 * @param stream
+	 * @throws IOException
+	 */
+	private void addFilesToSave(File src, ArchiveOutputStream stream) throws IOException {
+		if (!src.exists())
+			return;
+		
+		if (!src.isDirectory()) {
+			addFileToSave(src, stream, false);
+			return;
+		}
+		ArrayList<File> files = new ArrayList<>();
+		files.addAll(Arrays.asList(src.listFiles()));
+		for (File file : files) {
+			addFileToSave(file, stream, true);
 		}
 
 	}
 
-	private void imageToJson(JsonObject file) {
-		// ArrayList<String> images = new ArrayList<>();
-		// BufferedImage buffered = null;
-		// WritableRaster raster = null;
-		// DataBufferByte data = null;
-		// String k = null;
-		// JsonObject temp = new JsonObject();
-		//
-		// try {
-		// Files.newDirectoryStream(Paths.get(System.getProperty("user.home") +
-		// "/HolonGUI/Images"),
-		// p -> p.toFile().isFile()).forEach(p -> images.add(p.toString()));
-		//
-		// for (String str : images) {
-		// System.out.println("aaaaa");
-		// k = "IMAGE" + getNumerator(NUMTYPE.IMAGE);
-		// buffered = ImageIO.read(new File(str));
-		// raster = buffered.getRaster();
-		// data = (DataBufferByte) raster.getDataBuffer();
-		//
-		// temp.add("Image", new
-		// JsonPrimitive(str.substring(str.indexOf("/HolonGUI/Images"),
-		// str.length())));
-		// for (int i = 0; i < data.getData().length; i++) {
-		// temp.add("" + i, new JsonPrimitive(data.getData()[i]));
-		// System.out.println(i);
-		// }
-		//
-		// file.add(k, gson.toJsonTree(temp));
-		// }
-		// } catch (IOException e) {
-		// // TODO Auto-generated catch block
-		// e.printStackTrace();
-		// }
-	}
-
-	private void addFileToSave(File src, ArchiveOutputStream stream) throws IOException {
-
-		String entryName = src.getName();
+	/**
+	 * Add a File into the Archive
+	 * 
+	 * @param src
+	 * @param stream
+	 * @param dir
+	 * @throws IOException
+	 */
+	private void addFileToSave(File src, ArchiveOutputStream stream, boolean dir) throws IOException {
+		String entryName = (dir == true ? src.getParentFile().getName() + File.separator + src.getName()
+				: src.getName());
 		ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
 		stream.putArchiveEntry(entry);
-
 		BufferedInputStream input = new BufferedInputStream(new FileInputStream(src));
 
 		IOUtils.copy(input, stream);
 		input.close();
 		stream.closeArchiveEntry();
-
 	}
 
 	/**

+ 65 - 34
src/ui/view/GUI.java

@@ -5,9 +5,13 @@ import java.awt.Color;
 import java.awt.Component;
 import java.awt.Cursor;
 import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.HeadlessException;
 import java.awt.Image;
+import java.awt.Label;
 import java.awt.Point;
 import java.awt.Toolkit;
+import java.awt.datatransfer.UnsupportedFlavorException;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ComponentAdapter;
@@ -22,6 +26,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Timer;
 import java.util.TimerTask;
+import java.util.zip.ZipException;
 
 import javax.swing.AbstractAction;
 import javax.swing.ActionMap;
@@ -65,6 +70,8 @@ import javax.swing.tree.TreeCellRenderer;
 
 import org.apache.commons.compress.archivers.ArchiveException;
 
+import com.google.gson.JsonParseException;
+
 import classes.AbstractCpsObject;
 import classes.Category;
 import classes.CpsUpperNode;
@@ -121,7 +128,7 @@ public class GUI<E> implements CategoryListener {
 	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;
@@ -329,7 +336,7 @@ public class GUI<E> implements CategoryListener {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				try {
-					controller.loadFile(controller.getUndoSave());
+					controller.loadAutoSave(controller.getUndoSave());
 					canvas.repaint();
 					ArrayList<HolonElement> tempList = new ArrayList<>();
 					for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
@@ -346,7 +353,7 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 					unitGraph.empty();
-				} catch (IOException eex) {
+				} catch (IOException  eex) {
 					// TODO Auto-generated catch block
 					eex.printStackTrace();
 				}
@@ -362,7 +369,7 @@ public class GUI<E> implements CategoryListener {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				try {
-					controller.loadFile(controller.getRedoSave());
+					controller.loadAutoSave(controller.getRedoSave());
 					canvas.repaint();
 					ArrayList<HolonElement> tempList = new ArrayList<>();
 					for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
@@ -379,7 +386,7 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 					unitGraph.empty();
-				} catch (IOException ex) {
+				} catch (IOException  ex) {
 					// TODO Auto-generated catch block
 					ex.printStackTrace();
 				}
@@ -435,7 +442,7 @@ public class GUI<E> implements CategoryListener {
 							controller.delObjUpperNode(cps, uNC.upperNode);
 							// Remove UpperNodeTab if UpperNode deleted
 							if (cps instanceof CpsUpperNode) {
-								for (int i = 3; i < tabbedPane.getTabCount(); i++) {
+								for (int i = 4; i < tabbedPane.getTabCount(); i++) {
 									if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
 											.getComponent(0)).upperNode.getId() == cps.getId()) {
 										tabbedPane.remove(i);
@@ -458,7 +465,7 @@ public class GUI<E> implements CategoryListener {
 						controller.delCanvasObject(cps, save);
 						// Remove UpperNodeTab if UpperNode deleted
 						if (cps instanceof CpsUpperNode) {
-							for (int i = 3; i < tabbedPane.getTabCount(); i++) {
+							for (int i = 4; i < tabbedPane.getTabCount(); i++) {
 								if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
 										.getComponent(0)).upperNode.getId() == cps.getId()) {
 									tabbedPane.remove(i);
@@ -518,15 +525,22 @@ public class GUI<E> implements CategoryListener {
 
 			@Override
 			public void actionPerformed(ActionEvent e) {
-				if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
-						.getComponent(0) instanceof UpperNodeCanvas)
-					controller.paste(
-							((UpperNodeCanvas) ((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
-									.getComponent(0)).upperNode,
-							((UpperNodeCanvas) ((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
-									.getComponent(0)).getMousePosition());
-				else
-					controller.paste(null, canvas.getMousePosition());
+				try {
+					if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
+							.getComponent(0) instanceof UpperNodeCanvas)
+						
+						controller.paste(
+								((UpperNodeCanvas) ((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
+										.getComponent(0)).upperNode,
+								((UpperNodeCanvas) ((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
+										.getComponent(0)).getMousePosition());
+					else
+						controller.paste(null, canvas.getMousePosition());
+				} catch (HeadlessException | JsonParseException | UnsupportedFlavorException | IOException e1) {
+					// TODO Auto-generated catch block
+					JLabel message = new JLabel("The Clipboard information cannot be pasted into Application.");
+					JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
+				}
 				canvas.repaint();
 			}
 		});
@@ -659,7 +673,7 @@ public class GUI<E> implements CategoryListener {
 				JOptionPane.showMessageDialog(null, myPanel);
 				controller.setCanvasX(Integer.parseInt(field1.getText()));
 				controller.setCanvasY(Integer.parseInt(field2.getText()));
-				for (int i = 3; i < tabbedPane.getTabCount(); i++) {
+				for (int i = 4; i < tabbedPane.getTabCount(); i++) {
 					tabbedPane.getComponentAt(i)
 							.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
 					tabbedPane.getComponentAt(i).repaint();
@@ -677,7 +691,13 @@ public class GUI<E> implements CategoryListener {
 			@Override
 			public void stateChanged(ChangeEvent e) {
 				controller.setScale(sizeSlider.getValue());
-				canvas.repaint();
+				if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
+						.getComponent(0) instanceof UpperNodeCanvas) {
+					((UpperNodeCanvas) ((JScrollPane) tabbedPane.getSelectedComponent()).getViewport().getComponent(0))
+							.repaint();
+				} else {
+					canvas.repaint();
+				}
 			}
 		});
 
@@ -1057,7 +1077,7 @@ public class GUI<E> implements CategoryListener {
 						}
 						updCon.getActualCps().setName(temp.toString());
 						if (updCon.getActualCps() instanceof CpsUpperNode) {
-							for (int index = 3; index < tabbedPane.getTabCount(); index++) {
+							for (int index = 4; index < tabbedPane.getTabCount(); index++) {
 								UpperNodeCanvas unc = ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponent(index))
 										.getViewport().getComponent(0));
 								if (unc.upperNode.getId() == updCon.getActualCps().getId()) {
@@ -1497,8 +1517,8 @@ public class GUI<E> implements CategoryListener {
 			private void menuFileExitActionPerformed(java.awt.event.ActionEvent evt) {
 				JFileChooser fileChooser = new JFileChooser();
 				JFrame test = new JFrame();
-				FileNameExtensionFilter jsonFilter = new FileNameExtensionFilter("*.json", "json");
-				fileChooser.setFileFilter(jsonFilter);
+				FileNameExtensionFilter holonFilter = new FileNameExtensionFilter("Holon Save File(*.holon)", "holon");
+				fileChooser.setFileFilter(holonFilter);
 
 				if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
 					File file = fileChooser.getSelectedFile();
@@ -1522,9 +1542,10 @@ public class GUI<E> implements CategoryListener {
 						}
 						unitGraph.empty();
 						tree.repaint();
-					} catch (IOException e) {
+					} 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);
 					}
 				}
 			}
@@ -1541,19 +1562,29 @@ public class GUI<E> implements CategoryListener {
 			private void menuSaveActionPerformed(java.awt.event.ActionEvent evt) {
 				JFileChooser fileChooser = new JFileChooser();
 				JFrame test = new JFrame();
-				FileNameExtensionFilter holonFilter = new FileNameExtensionFilter("Holon Save File(.holon)", "holon");
-				FileNameExtensionFilter ownFilter = new FileNameExtensionFilter("Own Extension(.ext)", " ");
-				fileChooser.addChoosableFileFilter(holonFilter);
-				fileChooser.addChoosableFileFilter(ownFilter);
+				FileNameExtensionFilter holonFilter = new FileNameExtensionFilter("Holon Save File(*.holon)", "holon");
 				fileChooser.setFileFilter(holonFilter);
 
-
 				if (fileChooser.showSaveDialog(test) == JFileChooser.APPROVE_OPTION) {
 					String file = fileChooser.getSelectedFile().getPath();
 					if (fileChooser.getFileFilter().equals(holonFilter)) {
-						if (!file.endsWith(".holon"))
+						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 };
+
+							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]);
+
+							if (response == 0)
+								file = file.replace(suffix, ".holon");
+						}
 					}
+
 					try {
 						controller.saveFile(new File(file).getAbsolutePath());
 					} catch (IOException | ArchiveException e) {
@@ -1621,7 +1652,7 @@ public class GUI<E> implements CategoryListener {
 
 			private void menuUndoActionPerformed(java.awt.event.ActionEvent evt) {
 				try {
-					controller.loadFile(controller.getUndoSave());
+					controller.loadAutoSave(controller.getUndoSave());
 					canvas.repaint();
 					ArrayList<HolonElement> tempList = new ArrayList<>();
 					for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
@@ -1638,7 +1669,7 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 					unitGraph.empty();
-				} catch (IOException e) {
+				} catch (IOException  e) {
 					// TODO Auto-generated catch block
 					e.printStackTrace();
 				}
@@ -1657,7 +1688,7 @@ public class GUI<E> implements CategoryListener {
 
 			private void menuRedoActionPerformed(java.awt.event.ActionEvent evt) {
 				try {
-					controller.loadFile(controller.getRedoSave());
+					controller.loadAutoSave(controller.getRedoSave());
 					canvas.repaint();
 					ArrayList<HolonElement> tempList = new ArrayList<>();
 					for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
@@ -1674,7 +1705,7 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 					unitGraph.empty();
-				} catch (IOException e) {
+				} catch (IOException  e) {
 					// TODO Auto-generated catch block
 					e.printStackTrace();
 				}
@@ -1998,7 +2029,7 @@ public class GUI<E> implements CategoryListener {
 
 		// check if tab already open for clicked NodeOfNode
 		boolean dupl = false;
-		for (int i = 3; i < tabbedPane.getTabCount() && dupl == false; i++) {
+		for (int i = 4; i < tabbedPane.getTabCount() && dupl == false; i++) {
 			if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport().getComponent(0)).upperNode
 					.getId() == temp.getId()) {
 				dupl = true;

+ 37 - 33
src/ui/view/MyCanvas.java

@@ -7,6 +7,7 @@ import java.awt.Graphics2D;
 import java.awt.Image;
 import java.awt.Point;
 import java.awt.RenderingHints;
+import java.awt.datatransfer.UnsupportedFlavorException;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
@@ -20,12 +21,16 @@ import java.util.Timer;
 import java.util.TimerTask;
 
 import javax.swing.ImageIcon;
+import javax.swing.JLabel;
 import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
 
+import com.google.gson.JsonParseException;
+
 import classes.CpsEdge;
 import classes.CpsNode;
 import classes.CpsUpperNode;
@@ -140,7 +145,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		itemDelete.setEnabled(false);
 		itemCut.setEnabled(false);
 		itemCopy.setEnabled(false);
-		itemPaste.setEnabled(false);
+		itemPaste.setEnabled(true);
 		itemGroup.setEnabled(false);
 		itemUngroup.setEnabled(false);
 		itemTrack.setEnabled(false);
@@ -207,7 +212,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			public void actionPerformed(ActionEvent e) {
 				// save old Position
 				JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
-				for (int i = 3; i < tabbedPane.getTabCount(); i++) {
+				for (int i = 4; i < tabbedPane.getTabCount(); i++) {
 					if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
 							.getComponent(0)).upperNode.getId() == ((CpsUpperNode) tempCps).getId()) {
 						tabbedPane.remove(i);
@@ -335,7 +340,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 					// Remove UpperNodeTab if UpperNode deleted
 					if (cps instanceof CpsUpperNode) {
 						JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
-						for (int i = 3; i < tabbedPane.getTabCount(); i++) {
+						for (int i = 4; i < tabbedPane.getTabCount(); i++) {
 							if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
 									.getComponent(0)).upperNode.getId() == cps.getId()) {
 								tabbedPane.remove(i);
@@ -373,7 +378,13 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		itemPaste.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
-				controller.paste(null, mousePosition);
+				try {
+					controller.paste(null, mousePosition);
+				} catch (JsonParseException | UnsupportedFlavorException | IOException e1) {
+					// TODO Auto-generated catch block
+					JLabel message = new JLabel("The Clipboard information cannot be pastet into Application.");
+					JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
+				}
 				repaint();
 			}
 		});
@@ -606,6 +617,20 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 
 		}
 
+		// Dragged marker Highlighting
+		if (doMark) {
+			g2.setColor(Color.BLACK);
+			g2.setStroke(new BasicStroke(1));
+			if (sx > x && sy > y) {
+				g2.drawRect(x, y, sx - x, sy - y);
+			} else if (sx < x && sy < y) {
+				g2.drawRect(sx, sy, x - sx, y - sy);
+			} else if (sx >= x) {
+				g2.drawRect(x, sy, sx - x, y - sy);
+			} else if (sy >= y) {
+				g2.drawRect(sx, y, x - sx, sy - y);
+			}
+		}
 		// Tooltip
 		if (toolTip) {
 			g2.setColor(new Color(255, 225, 150));
@@ -634,21 +659,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			g2.drawRect(fixXPos, fixYPos, textWidth, 15);
 			g2.drawString(toolTipText, fixXPos + 2, fixYPos + 12);
 		}
-
-		// Dragged marker Highlighting
-		if (doMark) {
-			g2.setColor(Color.BLACK);
-			g2.setStroke(new BasicStroke(1));
-			if (sx > x && sy > y) {
-				g2.drawRect(x, y, sx - x, sy - y);
-			} else if (sx < x && sy < y) {
-				g2.drawRect(sx, sy, x - sx, y - sy);
-			} else if (sx >= x) {
-				g2.drawRect(x, sy, sx - x, y - sy);
-			} else if (sy >= y) {
-				g2.drawRect(sx, y, x - sx, sy - y);
-			}
-		}
 	}
 
 	@Override
@@ -732,6 +742,9 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 
 	@Override
 	public void mouseReleased(MouseEvent e) {
+		x = e.getX();
+		y = e.getY();
+		
 		dragging = false;
 
 		if (drawEdge) {
@@ -761,22 +774,15 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 				itemDelete.setEnabled(true);
 				itemCut.setEnabled(true);
 				itemCopy.setEnabled(true);
-				if (tempCps != null)
+				if (tempCps != null) {
 					itemGroup.setEnabled(true);
+					itemTrack.setEnabled(true);
+					itemUntrack.setEnabled(true);
+				}
 				if (tempCps instanceof CpsUpperNode)
 					itemUngroup.setEnabled(true);
 				else
 					itemUngroup.setEnabled(false);
-				/*
-				 * if (!(tempCps instanceof HolonSwitch)) {
-				 * itemTrack.setEnabled(true); itemUntrack.setEnabled(true); }
-				 * else {
-				 */
-				itemTrack.setEnabled(true);
-				itemUntrack.setEnabled(true);
-				/*
-				 * }
-				 */
 				if (model.getSelectedCpsObjects().size() == 0) {
 					controller.addSelectedObject(tempCps);
 				}
@@ -909,6 +915,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	public void mouseMoved(MouseEvent e) {
 		x = e.getX();
 		y = e.getY();
+
 		// Everytghing for the tooltip :)
 		boolean on = false;
 		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
@@ -938,8 +945,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		boolean onEdge = true;
 		boolean deleteNode = false;
 		CpsEdge e = null;
-		AbstractCpsObject tempCPS = null;
-
 		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
 			cx = cps.getPosition().x - controller.getScaleDiv2();
 			cy = cps.getPosition().y - controller.getScaleDiv2();
@@ -961,7 +966,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 						deleteNode = true;
 					}
 					if (e.getB().getClass() == CpsNode.class && e.getB().getConnections().isEmpty()) {
-						tempCPS = e.getB();
 						deleteNode = true;
 					}
 				}

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

@@ -114,6 +114,10 @@ public class StatisticGraph extends JPanel {
 				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:
@@ -251,6 +255,8 @@ public class StatisticGraph extends JPanel {
 				}
 				break;
 			case TrackedDataSet.AVG_AMOUNT_ELEMENTS_IN_HOLONS:
+			case TrackedDataSet.AVG_AMOUNT_ACTIVE_ELEMENTS_IN_HOLONS:
+			case TrackedDataSet.AVG_AMOUNT_INACTIVE_ELEMENTS_IN_HOLONS:
 				float eCount = 0;
 				for (SubNet sub : controller.getSimManager().getSubNets()) {
 					for (HolonObject obj : sub.getObjects()) {
@@ -293,6 +299,22 @@ public class StatisticGraph extends JPanel {
 			case TrackedDataSet.RATIO_PRODUCERS_CONSUMERS:
 				val = 1;
 				break;
+			case TrackedDataSet.AVG_AMOUNT_CLOSED_SWITCHES_IN_HOLONS:
+				for (SubNet sub : controller.getSimManager().getSubNets()) {
+					float tempVal = sub.getSwitches().size();
+					if (val < tempVal) {
+						val = tempVal;
+					}
+				}
+				break;
+			case TrackedDataSet.AVG_PRODUCED_ENERGY_IN_HOLONS:
+				for (SubNet sub : controller.getSimManager().getSubNets()) {
+					float tempVal = getMaxTotalProduction(new ArrayList<AbstractCpsObject>(sub.getObjects()));
+					if (val < tempVal) {
+						val = tempVal;
+					}
+				}
+				break;
 			default:
 				maximum = 0;
 				break;
@@ -454,12 +476,53 @@ public class StatisticGraph extends JPanel {
 					for (HolonObject obj : sub.getObjects()) {
 						if (obj.getCurrentEnergyAtTimeStep(model.getCurIteration()) > 0) {
 							prod++;
-						} else if(obj.getCurrentEnergyAtTimeStep(model.getCurIteration()) < 0) {
+						} else if (obj.getCurrentEnergyAtTimeStep(model.getCurIteration()) < 0) {
 							cons++;
 						}
 					}
 				}
-				val = prod/(prod+cons);
+				val = prod / (prod + cons);
+				set.setValAt(val, model.getCurIteration());
+				break;
+			case TrackedDataSet.AVG_AMOUNT_CLOSED_SWITCHES_IN_HOLONS:
+				for (SubNet sub : controller.getSimManager().getSubNets()) {
+					val += sub.getSwitches().size();
+				}
+				val /=controller.getSimManager().getSubNets().size();
+				set.setValAt(val, model.getCurIteration());
+				break;
+			case TrackedDataSet.AVG_AMOUNT_ACTIVE_ELEMENTS_IN_HOLONS:
+				for (SubNet sub : controller.getSimManager().getSubNets()) {
+					for (HolonObject obj : sub.getObjects()) {
+						for (HolonElement ele: obj.getElements()) {
+							if (ele.getActive()) {
+								val++;
+							}
+						}
+					}
+				}
+				val /= controller.getSimManager().getSubNets().size();
+				set.setValAt(val, model.getCurIteration());
+				break;
+			case TrackedDataSet.AVG_AMOUNT_INACTIVE_ELEMENTS_IN_HOLONS:
+				for (SubNet sub : controller.getSimManager().getSubNets()) {
+					for (HolonObject obj : sub.getObjects()) {
+						for (HolonElement ele: obj.getElements()) {
+							if (!ele.getActive()) {
+								val++;
+							}
+						}
+					}
+				}
+				val /= controller.getSimManager().getSubNets().size();
+				set.setValAt(val, model.getCurIteration());
+				break;
+			case TrackedDataSet.AVG_PRODUCED_ENERGY_IN_HOLONS:
+				for (SubNet sub : controller.getSimManager().getSubNets()) {
+					val += getTotalProductionAt(new ArrayList<AbstractCpsObject>(sub.getObjects()),
+							model.getCurIteration());
+				}
+				val /= controller.getSimManager().getSubNets().size();
 				set.setValAt(val, model.getCurIteration());
 				break;
 			default:

+ 37 - 1
src/ui/view/StatisticGraphPanel.java

@@ -194,7 +194,43 @@ public class StatisticGraphPanel extends JPanel {
 			property = "Percentage of partial supplied";
 			break;
 		case TrackedDataSet.AMOUNT_HOLONS:
-			property = "Amount of Subnets";
+			property = "Amount of holons";
+			break;
+		case TrackedDataSet.AMOUNT_CLOSED_SWITCHES:
+			property = "Amount of Closed Switches";
+			break;
+		case TrackedDataSet.AVG_AMOUNT_OBJECTS_IN_HOLONS:
+			property = "Avg. Amount of Objects in Holons";
+			break;
+		case TrackedDataSet.AVG_AMOUNT_ELEMENTS_IN_HOLONS:
+			property = "Avg. Amount of Elements in Holons";
+			break;
+		case TrackedDataSet.AVG_AMOUNT_PRODUCERS_IN_HOLONS:
+			property = "Avg. Amount Producers in Holons";
+			break;
+		case TrackedDataSet.AVG_CONSUMED_ENERGY_IN_HOLONS:
+			property = "Avg. Consumed Energy in Holons";
+			break;
+		case TrackedDataSet.AVG_WASTED_ENERGY_IN_HOLONS:
+			property = "Avg. Wasted Energy in Holons";
+			break;
+		case TrackedDataSet.AMOUNT_BROKEN_EDGES:
+			property = "Amount of Broken Edged";
+			break;
+		case TrackedDataSet.RATIO_PRODUCERS_CONSUMERS:
+			property = "Ratio Producers:Consumers";
+			break;
+		case TrackedDataSet.AVG_AMOUNT_CLOSED_SWITCHES_IN_HOLONS:
+			property = "Avg. Amount of Closed Switches in Holons";
+			break;
+		case TrackedDataSet.AVG_AMOUNT_ACTIVE_ELEMENTS_IN_HOLONS:
+			property = "Avg. Amount of Active Elements in Holons";
+			break;
+		case TrackedDataSet.AVG_AMOUNT_INACTIVE_ELEMENTS_IN_HOLONS:
+			property = "Avg. Amount of Inactive Elements in Holons";
+			break;
+		case TrackedDataSet.AVG_PRODUCED_ENERGY_IN_HOLONS:
+			property = "Avg. Produced Energy in Holons";
 			break;
 		default:
 			property = "null";

+ 97 - 115
src/ui/view/UpperNodeCanvas.java

@@ -7,6 +7,7 @@ import java.awt.Graphics2D;
 import java.awt.Image;
 import java.awt.Point;
 import java.awt.RenderingHints;
+import java.awt.datatransfer.UnsupportedFlavorException;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
@@ -22,10 +23,14 @@ import java.util.TimerTask;
 import javax.swing.ImageIcon;
 import javax.swing.JLabel;
 import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
+
+import com.google.gson.JsonParseException;
+
 import classes.CpsEdge;
 import classes.CpsNode;
 import classes.CpsUpperNode;
@@ -113,8 +118,6 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	private Position unPos;
 	private ArrayList<Position> savePos;
 
-	
-
 	/**
 	 * Constructor.
 	 * 
@@ -136,7 +139,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		scalediv20 = model.getScale() / 20;
 
 		// Cps objecte aus dem border links schieben
-		borderPos = (int) (model.getScale() + scalediv20 + scalediv20 + 10);
+		borderPos = (int) (model.getScale() + controller.getScaleDiv2() + scalediv20 + scalediv20 + 10);
 		for (AbstractCpsObject cps : upperNode.getNodes()) {
 			if (cps.getPosition().x < model.getScaleDiv2() + borderPos + 5) {
 				cps.setPosition(new Position(borderPos + 5, cps.getPosition().y));
@@ -159,7 +162,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		itemDelete.setEnabled(false);
 		itemCut.setEnabled(false);
 		itemCopy.setEnabled(false);
-		itemPaste.setEnabled(false);
+		itemPaste.setEnabled(true);
 		itemGroup.setEnabled(false);
 		itemUngroup.setEnabled(false);
 		itemTrack.setEnabled(false);
@@ -225,7 +228,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 			public void actionPerformed(ActionEvent e) {
 				// save old Position
 				JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
-				for (int i = 3; i < tabbedPane.getTabCount(); i++) {
+				for (int i = 4; i < tabbedPane.getTabCount(); i++) {
 					if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
 							.getComponent(0)).upperNode.getId() == ((CpsUpperNode) tempCps).getId()) {
 						tabbedPane.remove(i);
@@ -352,7 +355,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 						// Remove UpperNodeTab if UpperNode deleted
 						if (cps instanceof CpsUpperNode) {
 							JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
-							for (int i = 2; i < tabbedPane.getTabCount(); i++) {
+							for (int i = 4; i < tabbedPane.getTabCount(); i++) {
 								if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
 										.getComponent(0)).upperNode.getId() == cps.getId()) {
 									tabbedPane.remove(i);
@@ -389,7 +392,13 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		itemPaste.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
-				controller.paste(upperNode, mousePosition);
+				try {
+					controller.paste(upperNode, mousePosition);
+				} catch (JsonParseException | UnsupportedFlavorException | IOException e1) {
+					// TODO Auto-generated catch block
+					JLabel message = new JLabel("The Clipboard information cannot be pastet into Application.");
+					JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
+				}
 				repaint();
 			}
 		});
@@ -413,26 +422,28 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 		g2.setRenderingHints(rh);
 
+		// Left Border
+		borderPos = (int) (model.getScale() + scalediv20 + scalediv20 + 10);
+
 		// Paint the Background
 		if (!upperNode.getImagePath().isEmpty()) {
 			img = new ImageIcon(upperNode.getImagePath()).getImage();
 			switch (upperNode.getBackgroundMode()) {
 			case BackgroundPopUp.IMAGE_PIXELS:
-				g2.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);
+				g2.drawImage(img, borderPos, 0, img.getWidth(null), img.getHeight(null), null);
 				break;
 			case BackgroundPopUp.STRETCHED:
-				g2.drawImage(img, 0, 0, model.getCanvasX(), model.getCanvasY(), null);
+				g2.drawImage(img, borderPos, 0, model.getCanvasX(), model.getCanvasY(), null);
 				break;
 			case BackgroundPopUp.CUSTOM:
-				g2.drawImage(img, 0, 0, upperNode.getImageWidht(), upperNode.getImageHeight(), null);
+				g2.drawImage(img, borderPos, 0, upperNode.getImageWidht(), upperNode.getImageHeight(), null);
 				break;
 			default:
 				break;
 			}
 		}
 
-		// Left Border
-		borderPos = (int) (model.getScale() + scalediv20 + scalediv20 + 10);
+		// Draw Left Border
 		g2.setColor(new Color(230, 230, 230));
 		g2.fillRect(0, 0, borderPos, this.getHeight());
 		g2.setColor(Color.BLACK);
@@ -472,8 +483,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					count++;
 				}
 			} else {
-				g2.drawLine(tempCps.getPosition().x + controller.getScaleDiv2(),
-						tempCps.getPosition().y + controller.getScaleDiv2(), x, y);
+				g2.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
 			}
 		}
 
@@ -484,7 +494,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					if (con.getState()) {
 						g2.setColor(Color.GREEN);
 						if (con.getCapacity() != -1) {
-							g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3)+1), 4)));
+							g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
 						}
 					} else {
 						g2.setColor(Color.RED);
@@ -494,10 +504,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					g2.setColor(Color.DARK_GRAY);
 					g2.setStroke(new BasicStroke(2));
 				}
-				g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
-						con.getA().getPosition().y + controller.getScaleDiv2(),
-						con.getB().getPosition().x + controller.getScaleDiv2(),
-						con.getB().getPosition().y + controller.getScaleDiv2());
+				g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
+						con.getB().getPosition().y);
 
 				if (con.getCapacity() == -1) {
 					maxCap = Character.toString('\u221e');
@@ -509,16 +517,11 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 				if (showedInformation[0]) {
 					if (con.getConnected() == 0 || con.getConnected() == 1) {
 						g2.drawString(con.getFlow() + "/" + maxCap,
-								(con.getA().getPosition().x + con.getB().getPosition().x) / 2
-										+ controller.getScaleDiv2(),
-								(con.getA().getPosition().y + con.getB().getPosition().y) / 2
-										+ controller.getScaleDiv2());
+								(con.getA().getPosition().x + con.getB().getPosition().x) / 2,
+								(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
 					} else {
-						g2.drawString("not connected",
-								(con.getA().getPosition().x + con.getB().getPosition().x) / 2
-										+ controller.getScaleDiv2(),
-								(con.getA().getPosition().y + con.getB().getPosition().y) / 2
-										+ controller.getScaleDiv2());
+						g2.drawString("not connected", (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
+								(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
 					}
 				}
 			}
@@ -529,7 +532,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 			g2.setColor(Color.BLUE);
 			for (CpsEdge con : upperNode.getNodeEdges()) {
 				if (con.getFlow() <= con.getCapacity()) {
-					g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 3)+1, 4)));
+					g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 3) + 1, 4)));
 				} else {
 					g2.setStroke(new BasicStroke(2));
 				}
@@ -538,10 +541,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 						|| con.getB().getId() == model.getSelectedObjectID()
 						|| model.getSelectedCpsObjects().contains(con.getB())
 						|| tempSelected.contains(con.getB()) && con != edgeHighlight) {
-					g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
-							con.getA().getPosition().y + controller.getScaleDiv2(),
-							con.getB().getPosition().x + controller.getScaleDiv2(),
-							con.getB().getPosition().y + controller.getScaleDiv2());
+					g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
+							con.getB().getPosition().y);
 
 					if (con.getCapacity() == -1) {
 						maxCap = Character.toString('\u221e');
@@ -553,16 +554,12 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					if (showedInformation[0]) {
 						if (con.getConnected() == 0 || con.getConnected() == 1) {
 							g2.drawString(con.getFlow() + "/" + maxCap,
-									(con.getA().getPosition().x + con.getB().getPosition().x) / 2
-											+ controller.getScaleDiv2(),
-									(con.getA().getPosition().y + con.getB().getPosition().y) / 2
-											+ controller.getScaleDiv2());
+									(con.getA().getPosition().x + con.getB().getPosition().x) / 2,
+									(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
 						} else {
 							g2.drawString("not connected",
-									(con.getA().getPosition().x + con.getB().getPosition().x) / 2
-											+ controller.getScaleDiv2(),
-									(con.getA().getPosition().y + con.getB().getPosition().y) / 2
-											+ controller.getScaleDiv2());
+									(con.getA().getPosition().x + con.getB().getPosition().x) / 2,
+									(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
 						}
 					}
 				}
@@ -570,14 +567,13 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		} else if (edgeHighlight != null) {
 			g2.setColor(Color.BLUE);
 			if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
-				g2.setStroke(new BasicStroke(Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3)+1, 4)));
+				g2.setStroke(
+						new BasicStroke(Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3) + 1, 4)));
 			} else {
 				g2.setStroke(new BasicStroke(2));
 			}
-			g2.drawLine(edgeHighlight.getA().getPosition().x + controller.getScaleDiv2(),
-					edgeHighlight.getA().getPosition().y + controller.getScaleDiv2(),
-					edgeHighlight.getB().getPosition().x + controller.getScaleDiv2(),
-					edgeHighlight.getB().getPosition().y + controller.getScaleDiv2());
+			g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight.getA().getPosition().y,
+					edgeHighlight.getB().getPosition().x, edgeHighlight.getB().getPosition().y);
 
 			if (edgeHighlight.getCapacity() == -1) {
 				maxCap = Character.toString('\u221e');
@@ -588,10 +584,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 			}
 			if (showedInformation[0]) {
 				g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
-						(edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2
-								+ controller.getScaleDiv2(),
-						(edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2
-								+ controller.getScaleDiv2());
+						(edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2,
+						(edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2);
 			}
 		}
 
@@ -601,8 +595,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 			if (showedInformation[3]) {
 				g2.setColor(cps.getBorderColor());
 				if (g2.getColor() != Color.WHITE) {
-					g2.fillRect((int) (cps.getPosition().x - scalediv20 - 3),
-							(int) (cps.getPosition().y - scalediv20 - 3),
+					g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20 - 3),
+							(int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20 - 3),
 							(int) (controller.getScale() + ((scalediv20 + 3) * 2)),
 							(int) (controller.getScale() + ((scalediv20 + 3) * 2)));
 				}
@@ -624,25 +618,29 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 				if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
 						|| model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
 					g2.setColor(Color.BLUE);
-					g2.fillRect((int) (cps.getPosition().x - scalediv20), (int) (cps.getPosition().y - scalediv20),
+					g2.fillRect((int) (cps.getPosition().x - model.getScaleDiv2() - scalediv20),
+							(int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20),
 							(int) (controller.getScale() + (scalediv20 * 2)),
 							(int) (controller.getScale() + (scalediv20 * 2)));
 					if (showedInformation[1] && cps instanceof HolonObject) {
 						g2.setColor(Color.BLACK);
 						float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
-						g2.drawString(Float.toString(totalEnergy), cps.getPosition().x, cps.getPosition().y - 10);
+						g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - model.getScaleDiv2(),
+								cps.getPosition().y - model.getScaleDiv2() - 10);
 					}
 				} else if (cps instanceof HolonObject) {
 					g2.setColor(((HolonObject) cps).getColor());
 
-					g2.fillRect((int) (cps.getPosition().x - scalediv20), (int) (cps.getPosition().y - scalediv20),
+					g2.fillRect((int) (cps.getPosition().x - model.getScaleDiv2() - scalediv20),
+							(int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20),
 							(int) (controller.getScale() + (scalediv20 * 2)),
 							(int) (controller.getScale() + (scalediv20 * 2)));
 
 					if (showedInformation[1]) {
 						g2.setColor(Color.BLACK);
 						float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
-						g2.drawString(Float.toString(totalEnergy), cps.getPosition().x, cps.getPosition().y - 10);
+						g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - model.getScaleDiv2(),
+								cps.getPosition().y - model.getScaleDiv2() - 10);
 					}
 				}
 				// draw image
@@ -653,8 +651,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
 				}
 			}
-			g2.drawImage(img, cps.getPosition().x, cps.getPosition().y, controller.getScale(), controller.getScale(),
-					null);
+			g2.drawImage(img, cps.getPosition().x - model.getScaleDiv2(), cps.getPosition().y - model.getScaleDiv2(),
+					controller.getScale(), controller.getScale(), null);
 		}
 
 		// Objects connected to upperNode
@@ -677,8 +675,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					}
 					if (obj != null) {
 						g2.setColor(Color.BLUE);
-						g2.drawLine(obj.getPosition().x + model.getScaleDiv2(),
-								obj.getPosition().y + model.getScaleDiv2(), (borderPos >> 1),
+						g2.drawLine(obj.getPosition().x, obj.getPosition().y, (borderPos >> 1),
 								(int) (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)
 										+ model.getScaleDiv2());
 					}
@@ -817,8 +814,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 
 		if (e.getX() > borderPos) {
 			for (AbstractCpsObject cps : upperNode.getNodes()) {
-				cx = cps.getPosition().x;
-				cy = cps.getPosition().y;
+				cx = cps.getPosition().x - model.getScaleDiv2();
+				cy = cps.getPosition().y - model.getScaleDiv2();
 				if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
 					tempCps = cps;
 					controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
@@ -834,12 +831,6 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 						}
 					}
 
-					/*
-					 * else if (e.getButton() != MouseEvent.BUTTON3) {
-					 * controller.setSelectedObjectID(tempCps.getID());
-					 * model.getSelectedCpsObjects().clear();
-					 * controller.addSelectedObject(tempCps); }
-					 */
 					// If drawing an Edge (CTRL down)
 					if (tempCps.getClass() == HolonObject.class) {
 						HolonObject tempObj = ((HolonObject) tempCps);
@@ -919,6 +910,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 
 	@Override
 	public void mouseReleased(MouseEvent e) {
+		x = e.getX();
+		y = e.getY();
 		dragging = false;
 		if (model.getSelectedCpsObjects().size() > 1) {
 			model.getTableHolonElement().setModel(model.getMultiTable());
@@ -953,19 +946,15 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 				itemDelete.setEnabled(true);
 				itemCut.setEnabled(true);
 				itemCopy.setEnabled(true);
-				if (tempCps != null)
+				if (tempCps != null) {
 					itemGroup.setEnabled(true);
+					itemTrack.setEnabled(true);
+					itemUntrack.setEnabled(true);
+				}
 				if (tempCps instanceof CpsUpperNode)
 					itemUngroup.setEnabled(true);
 				else
 					itemUngroup.setEnabled(false);
-				if (!(tempCps instanceof HolonSwitch)) {
-					itemTrack.setEnabled(true);
-					itemUntrack.setEnabled(true);
-				} else {
-					itemTrack.setEnabled(false);
-					itemUntrack.setEnabled(false);
-				}
 				if (model.getSelectedCpsObjects().size() == 0) {
 					controller.addSelectedObject(tempCps);
 				}
@@ -1016,26 +1005,24 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		}
 		if (dragging) {
 			try {
+				// tempCps in the upperNode? else its a connected Object from
+				// outside
 				if (upperNode.getNodes().contains(tempCps)) {
 					dragged = true;
 					float xDist, yDist; // Distance
 
-					x = e.getX() - controller.getScaleDiv2();
-					y = e.getY() - controller.getScaleDiv2();
-
-					// tempCps in the upperNode? if not its a connected Object
-					// from
-					// outside
+					x = e.getX();
+					y = e.getY();
 
 					// Make sure its in bounds
 					if (e.getX() < controller.getScaleDiv2() + borderPos + 5)
-						x = borderPos + 5;
+						x = controller.getScaleDiv2() + borderPos + 5;
 					else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
-						x = this.getWidth() - controller.getScale();
+						x = this.getWidth() - controller.getScaleDiv2();
 					if (e.getY() < controller.getScaleDiv2())
-						y = 0;
+						y = controller.getScaleDiv2();
 					else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
-						y = this.getHeight() - controller.getScale();
+						y = this.getHeight() - controller.getScaleDiv2();
 
 					// Distance
 					xDist = x - tempCps.getPosition().x;
@@ -1046,8 +1033,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					// TipText Position and name
 					toolTip = true;
 					toolTipText = tempCps.getName() + ", " + tempCps.getId();
-					toolTipPos.x = tempCps.getPosition().x;
-					toolTipPos.y = tempCps.getPosition().y + model.getScale();
+					toolTipPos.x = tempCps.getPosition().x - model.getScaleDiv2();
+					toolTipPos.y = tempCps.getPosition().y + model.getScaleDiv2();
 
 					// All Selected Objects
 					for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
@@ -1056,14 +1043,14 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 							y = (int) (cps.getPosition().y + yDist);
 
 							// Make sure its in bounds
-							if (x < borderPos + 5)
-								x = borderPos + 5;
-							else if (x > this.getWidth() - controller.getScale())
-								x = this.getWidth() - controller.getScale();
-							if (y <= 0)
-								y = 0;
-							else if (y > this.getHeight() - controller.getScale())
-								y = this.getHeight() - controller.getScale();
+							if (x < borderPos + 5 + controller.getScaleDiv2())
+								x = controller.getScaleDiv2() + borderPos + 5;
+							else if (x > this.getWidth() - controller.getScaleDiv2())
+								x = this.getWidth() - controller.getScaleDiv2();
+							if (y <= controller.getScaleDiv2())
+								y = controller.getScaleDiv2();
+							else if (y > this.getHeight() - controller.getScaleDiv2())
+								y = this.getHeight() - controller.getScaleDiv2();
 
 							cps.setPosition(x, y);
 						}
@@ -1090,8 +1077,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					y2 = sy;
 				}
 				if (x1 <= cps.getPosition().x + model.getScaleDiv2() && y1 <= cps.getPosition().y + model.getScaleDiv2()
-						&& x2 >= cps.getPosition().x + model.getScaleDiv2()
-						&& y2 >= cps.getPosition().y + model.getScaleDiv2()) {
+						&& x2 >= cps.getPosition().x && y2 >= cps.getPosition().y) {
 					tempSelected.add(cps);
 
 				}
@@ -1134,21 +1120,18 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	public void mouseMoved(MouseEvent e) {
 		x = e.getX();
 		y = e.getY();
-		// Everytghing for the tooltip :)
 
+		// Everytghing for the tooltip :)
 		boolean on = false;
 		for (AbstractCpsObject cps : upperNode.getNodes()) {
 
-			cx = cps.getPosition().x;
-			cy = cps.getPosition().y;
+			cx = cps.getPosition().x - controller.getScaleDiv2();
+			cy = cps.getPosition().y - controller.getScaleDiv2();
 			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
-
 				on = true;
-				toolTipPos.x = cps.getPosition().x;
-				toolTipPos.y = cps.getPosition().y + model.getScale();
+				toolTipPos.x = cps.getPosition().x - model.getScaleDiv2();
+				toolTipPos.y = cps.getPosition().y + model.getScaleDiv2();
 				toolTipText = cps.getName() + ", " + cps.getId();
-
-				on = true;
 			}
 		}
 		int count = 0;
@@ -1194,14 +1177,13 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 																		// to
 																		// the
 																		// outside
-		boolean found = false;
+		boolean found = false; // dont search for outside connetion if inside
+								// connection is found
 		CpsEdge e = null;
-		AbstractCpsObject tempCPS = null;
-
 		for (AbstractCpsObject cps : upperNode.getNodes()) {
 
-			cx = cps.getPosition().x;
-			cy = cps.getPosition().y;
+			cx = cps.getPosition().x - controller.getScaleDiv2();
+			cy = cps.getPosition().y - controller.getScaleDiv2();
 
 			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy
 					&& cps != tempCps) {
@@ -1226,7 +1208,6 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 						deleteNode = true;
 					}
 					if (e.getB().getClass() == CpsNode.class && e.getB().getConnections().isEmpty()) {
-						tempCPS = e.getB();
 						deleteNode = true;
 					}
 				}
@@ -1276,7 +1257,6 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 							deleteNode = true;
 						}
 						if (e.getB().getClass() == CpsNode.class && e.getB().getConnections().isEmpty()) {
-							tempCPS = e.getB();
 							deleteNode = true;
 						}
 					}
@@ -1304,7 +1284,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 
 				CpsNode n = new CpsNode("Node");
 
-				n.setPosition(x - model.getScaleDiv2(), y - model.getScaleDiv2());
+				n.setPosition(x, y);
 				controller.addObjUpperNode(n, upperNode);
 
 				AbstractCpsObject r, k;
@@ -1333,7 +1313,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		if (node && x > borderPos) {
 			CpsNode n = new CpsNode("Node");
 
-			n.setPosition(x - model.getScaleDiv2(), y - model.getScaleDiv2());
+			n.setPosition(x, y);
 			controller.addObjUpperNode(n, upperNode);
 
 			e = new CpsEdge(n, tempCps, model.getMaxCapacity());
@@ -1363,6 +1343,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	 * @return CpsEdge the Mouse is on, null if the mouse is not on an Edge
 	 */
 	public CpsEdge mousePositionOnEdge(int x, int y) {
+		x += controller.getScaleDiv2();
+		y += controller.getScaleDiv2();
 		int lx, ly, hx, hy;
 		for (CpsEdge p : upperNode.getNodeEdges()) {
 			Line2D l = new Line2D.Float(p.getA().getPosition().x, p.getA().getPosition().y, p.getB().getPosition().x,