Browse Source

Merge remote-tracking branch 'origin/dominik'

Jan Enders 8 years ago
parent
commit
acaa10acb6

+ 31 - 22
scopviz/.classpath

@@ -1,22 +1,31 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="src" output="target/classes" path="src/main/java">
-		<attributes>
-			<attribute name="optional" value="true"/>
-			<attribute name="maven.pomderived" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
-		<attributes>
-			<attribute name="optional" value="true"/>
-			<attribute name="maven.pomderived" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
-		<attributes>
-			<attribute name="maven.pomderived" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-	<classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

+ 1 - 0
scopviz/.settings/org.eclipse.core.resources.prefs

@@ -1,4 +1,5 @@
 eclipse.preferences.version=1
 encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
 encoding//src/test/java=UTF-8
 encoding/<project>=UTF-8

+ 5 - 0
scopviz/pom.xml

@@ -38,5 +38,10 @@
     	<artifactId>gs-ui</artifactId>
     	<version>1.3</version>
     </dependency>
+    <dependency>
+    	<groupId>org.jxmapviewer</groupId>
+    	<artifactId>jxmapviewer2</artifactId>
+    	<version>2.2</version>
+    </dependency>
   </dependencies>
 </project>

+ 0 - 2
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/GraphManager.java

@@ -503,8 +503,6 @@ public class GraphManager {
 	public void setStylesheet(String stylesheet) {
 		this.stylesheet = stylesheet;
 		g.removeAttribute("ui.stylesheet");
-		stylesheet = stylesheet.concat(OptionsManager.getNodeGraphics());
-		g.addAttribute("ui.stylesheet", stylesheet);
 		String completeStylesheet = stylesheet;
 		completeStylesheet = completeStylesheet.concat(OptionsManager.getNodeGraphics());
 		completeStylesheet = completeStylesheet.concat(OptionsManager.getLayerStyle((Layer) g.getAttribute("layer")));

+ 158 - 152
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ButtonManager.java

@@ -11,10 +11,8 @@ import org.graphstream.graph.implementations.Graphs;
 import de.tu_darmstadt.informatik.tk.scopviz.main.GraphManager;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
-import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
 import javafx.event.ActionEvent;
-import javafx.event.EventHandler;
 import javafx.scene.control.Button;
 
 /**
@@ -56,212 +54,220 @@ public final class ButtonManager {
 	/**
 	 * Handler for zoom in Button
 	 */
-	public static final EventHandler<ActionEvent> zoomInHandler = new EventHandler<ActionEvent>() {
-		public void handle(ActionEvent evt) {
-			Main.getInstance().getGraphManager().zoomIn();
-		}
-	};
+	public static final void zoomInAction(ActionEvent event) {
+		Main.getInstance().getGraphManager().zoomIn();
+	}
 
 	/**
 	 * Handler for zoom out Button
 	 */
-	public static final EventHandler<ActionEvent> zoomOutHandler = new EventHandler<ActionEvent>() {
-		public void handle(ActionEvent evt) {
-			Main.getInstance().getGraphManager().zoomOut();
-		}
-	};
+	public static final void zoomOutAction(ActionEvent event) {
+		Main.getInstance().getGraphManager().zoomOut();
+	}
 
 	/**
 	 * Handler for the Underlay Layer switch Button.
 	 */
-	public static final EventHandler<ActionEvent> underlayHandler = new EventHandler<ActionEvent>() {
+	public static final void underlayAction(ActionEvent arg0) {
 
-		@Override
-		public void handle(ActionEvent arg0) {
-			if (GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
-				controller.toolbox.setVisible(true);
-				controller.symbolToolVBox.setVisible(false);
+		switchfromSymbolLayer();
 
-			}
-			GraphDisplayManager.setCurrentLayer(Layer.UNDERLAY);
-			GraphDisplayManager.switchActiveGraph();
+		GraphDisplayManager.setCurrentLayer(Layer.UNDERLAY);
+		GraphDisplayManager.switchActiveGraph();
 
-			setBorderStyle((Button) arg0.getSource());
-		}
+		setBorderStyle((Button) arg0.getSource());
 
-	};
+	}
 
 	/**
 	 * Handler for the Operator Layer switch Button.
 	 */
-	public static final EventHandler<ActionEvent> operatorHandler = new EventHandler<ActionEvent>() {
+	public static final void operatorAction(ActionEvent arg0) {
 
-		@Override
-		public void handle(ActionEvent arg0) {
-			if (GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
-				controller.toolbox.setVisible(true);
-				controller.symbolToolVBox.setVisible(false);
+		switchfromSymbolLayer();
 
-			}
+		GraphDisplayManager.setCurrentLayer(Layer.OPERATOR);
+		GraphDisplayManager.switchActiveGraph();
 
-			GraphDisplayManager.setCurrentLayer(Layer.OPERATOR);
-			GraphDisplayManager.switchActiveGraph();
-
-			setBorderStyle((Button) arg0.getSource());
-		}
+		setBorderStyle((Button) arg0.getSource());
 
-	};
+	}
 
 	/**
 	 * Handler for the Mapping Layer switch Button.
 	 */
-	public static final EventHandler<ActionEvent> mappingHandler = new EventHandler<ActionEvent>() {
+	public static final void mappingAction(ActionEvent arg0) {
 
-		@Override
-		public void handle(ActionEvent arg0) {
-			if (GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
-				controller.toolbox.setVisible(true);
-				controller.symbolToolVBox.setVisible(false);
+		switchfromSymbolLayer();
 
-			}
+		GraphDisplayManager.setCurrentLayer(Layer.MAPPING);
+		GraphDisplayManager.switchActiveGraph();
 
-			GraphDisplayManager.setCurrentLayer(Layer.MAPPING);
-			GraphDisplayManager.switchActiveGraph();
+		setBorderStyle((Button) arg0.getSource());
 
-			setBorderStyle((Button) arg0.getSource());
-		}
-
-	};
+	}
 
 	/**
 	 * Handler for the Symbol Representation Layer switch Button.
 	 */
-	public static final EventHandler<ActionEvent> symbolRepHandler = new EventHandler<ActionEvent>() {
+	public static final void symbolRepAction(ActionEvent arg0) {
 
-		@Override
-		public void handle(ActionEvent arg0) {
-			if (!GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
-				controller.toolbox.setVisible(false);
-				controller.symbolToolVBox.setVisible(true);
+		if (!GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
+			controller.toolbox.setVisible(false);
+			controller.symbolToolVBox.setVisible(true);
 
+			controller.propertiesObjectColumn.setEditable(false);
+		}
+
+		// add a copy of the underlay graph to the the symbol layer
+		DefaultGraph gClone = (DefaultGraph) Graphs
+				.clone(GraphDisplayManager.getGraphManager(Layer.UNDERLAY).getGraph());
+		gClone.removeAttribute("layer");
+		GraphDisplayManager.setCurrentLayer(Layer.SYMBOL);
+		GraphDisplayManager.addGraph(gClone, true);
+
+		// apply checkbox changes from last time
+		// TODO abstract these things
+		if (!controller.edgesVisibleCheckbox.isSelected()) {
+
+			for (Edge edge : Main.getInstance().getGraphManager().getGraph().getEachEdge()) {
+				edge.addAttribute("ui.hide");
 			}
-			
-			//add a copy of the underlay graph to the the symbol layer
-			DefaultGraph gClone =(DefaultGraph) Graphs.clone(GraphDisplayManager.getGraphManager(Layer.UNDERLAY).getGraph());
-			gClone.removeAttribute("layer");
-			GraphDisplayManager.setCurrentLayer(Layer.SYMBOL);
-			GraphDisplayManager.addGraph(gClone, true);
-			
-			//apply checkbox changes from last time
-			//TODO abstract these things
-			if(!controller.edgesVisibleCheckbox.isSelected()){
-				
-				for (Edge edge : Main.getInstance().getGraphManager().getGraph().getEachEdge()) {
-					edge.addAttribute("ui.hide");
-				}
-				
-			}
-			
-			if(!controller.nodeLabelCheckbox.isSelected()){
-				GraphManager graphManager = Main.getInstance().getGraphManager();
-				String stylesheet = graphManager.getStylesheet();
-				graphManager.setStylesheet(stylesheet.concat("node{text-mode:hidden;}"));
-				
-			}
-			
-			if(!controller.edgeWeightCheckbox.isSelected()){
-				GraphManager graphManager = Main.getInstance().getGraphManager();
-				String stylesheet = graphManager.getStylesheet();
-				graphManager.setStylesheet(stylesheet.concat("edge{text-mode:hidden;}"));
-				
-			}
-			
-			//nodesToSymbols(Main.getInstance().getGraphManager().getGraph());
-			
-			GraphDisplayManager.switchActiveGraph();
-			setBorderStyle((Button) arg0.getSource());
+
 		}
 
-	};
+		if (!controller.nodeLabelCheckbox.isSelected()) {
+			GraphManager graphManager = Main.getInstance().getGraphManager();
+			String stylesheet = graphManager.getStylesheet();
+			graphManager.setStylesheet(stylesheet.concat("node{text-mode:hidden;}"));
+
+		}
+
+		if (!controller.edgeWeightCheckbox.isSelected()) {
+			GraphManager graphManager = Main.getInstance().getGraphManager();
+			String stylesheet = graphManager.getStylesheet();
+			graphManager.setStylesheet(stylesheet.concat("edge{text-mode:hidden;}"));
+
+		}
+
+		// nodesToSymbols(Main.getInstance().getGraphManager().getGraph());
+
+		GraphDisplayManager.switchActiveGraph();
+		setBorderStyle((Button) arg0.getSource());
+	}
 
 	/**
-	 * replaces all node sprites with symbol sprites corresponding with the device/hardware type
-	 * @param g graph, which nodes should be symbolized
+	 * After switching from symbol-layer to other layer show toolbox and make
+	 * properties editable again
 	 */
-	private static void nodesToSymbols(Graph g){
-		
-		//TODO make it functional/make an extra stylesheet for this
-		for(Node n: g.getEachNode()){
-			
-			if(n.getAttribute("ui.class").equals("standard") || n.getAttribute("ui.class").equals("source")){
-				n.changeAttribute("ui.style", "fill-mode: image-scaled; fill-image: url('src/main/resources/png/computer.png');");
+	private static void switchfromSymbolLayer() {
+
+		if (GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
+			controller.toolbox.setVisible(true);
+			controller.symbolToolVBox.setVisible(false);
+
+			controller.propertiesObjectColumn.setEditable(true);
+
+		}
+	}
+
+	/**
+	 * replaces all node sprites with symbol sprites corresponding with the
+	 * device/hardware type
+	 * 
+	 * @param g
+	 *            graph, which nodes should be symbolized
+	 */
+	private static void nodesToSymbols(Graph g) {
+
+		// TODO make it functional/make an extra stylesheet for this
+		for (Node n : g.getEachNode()) {
+
+			if (n.getAttribute("ui.class").equals("standard") || n.getAttribute("ui.class").equals("source")) {
+				n.changeAttribute("ui.style",
+						"fill-mode: image-scaled; fill-image: url('src/main/resources/png/computer.png');");
 			}
-			
-			else if(n.getAttribute("ui.class").equals("source") || n.getAttribute("ui.class").equals("standard")){
-				n.changeAttribute("ui.style", "fill-mode: image-scaled; fill-image: url('src/main/resources/png/router.png');");
+
+			else if (n.getAttribute("ui.class").equals("source") || n.getAttribute("ui.class").equals("standard")) {
+				n.changeAttribute("ui.style",
+						"fill-mode: image-scaled; fill-image: url('src/main/resources/png/router.png');");
 			}
-			
-		
+
 		}
 	}
-	
-	public static ChangeListener<Boolean> edgeVisibleListener = new ChangeListener<Boolean>() {
-
-		@Override
-		public void changed(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
-			// Show edges
-			if (newVal) {
-				for (Edge edge : Main.getInstance().getGraphManager().getGraph().getEachEdge()) {
-					edge.removeAttribute("ui.hide");
-				}
-
-				// Hide edges
-			} else {
-				for (Edge edge : Main.getInstance().getGraphManager().getGraph().getEachEdge()) {
-					edge.addAttribute("ui.hide");
-				}
+
+	/**
+	 * Functionality for "edge visible" Checkbox
+	 * 
+	 * @param ov
+	 * @param oldVal
+	 *            Checkbox previous state (Checked or unchecked)
+	 * @param newVal
+	 *            Checkbox current state (Checked or unchecked)
+	 */
+	public static void edgeVisibleSwitch(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
+		// Show edges
+		if (newVal) {
+			for (Edge edge : Main.getInstance().getGraphManager().getGraph().getEachEdge()) {
+				edge.removeAttribute("ui.hide");
 			}
-		}
 
-	};
+			// Hide edges
+		} else {
+			for (Edge edge : Main.getInstance().getGraphManager().getGraph().getEachEdge()) {
+				edge.addAttribute("ui.hide");
+			}
+		}
+	}
 
-	public static ChangeListener<Boolean> nodeLabelListener = new ChangeListener<Boolean>() {
+	/**
+	 * Functionality for "label visible" Checkbox
+	 * 
+	 * @param ov
+	 * @param oldVal
+	 *            Checkbox previous state (Checked or unchecked)
+	 * @param newVal
+	 *            Checkbox current state (Checked or unchecked)
+	 */
+	public static void labelVisibilitySwitcher(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
 
-		@Override
-		public void changed(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
-			GraphManager graphManager = Main.getInstance().getGraphManager();
-			String stylesheet = graphManager.getStylesheet();
+		GraphManager graphManager = Main.getInstance().getGraphManager();
+		String stylesheet = graphManager.getStylesheet();
 
-			// Show node weights
-			if (newVal) {
-				graphManager.setStylesheet(stylesheet.replace("node{text-mode:hidden;}", ""));
+		// Show node weights
+		if (newVal) {
+			graphManager.setStylesheet(stylesheet.replace("node{text-mode:hidden;}", ""));
 
-				// Hide node weights
-			} else {
-				graphManager.setStylesheet(stylesheet.concat("node{text-mode:hidden;}"));
-			}
+			// Hide node weights
+		} else {
+			graphManager.setStylesheet(stylesheet.concat("node{text-mode:hidden;}"));
 		}
+	}
 
-	};
-
-	public static ChangeListener<Boolean> edgeWeightListener = new ChangeListener<Boolean>() {
+	/**
+	 * Functionality for "edge weights visible" Checkbox
+	 * 
+	 * @param ov
+	 * @param oldVal
+	 *            Checkbox previous state (Checked or unchecked)
+	 * @param newVal
+	 *            Checkbox current state (Checked or unchecked)
+	 */
+	public static void edgeWeightVisibilitySwitcher(ObservableValue<? extends Boolean> ov, Boolean oldVal,
+			Boolean newVal) {
 
-		@Override
-		public void changed(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
-			GraphManager graphManager = Main.getInstance().getGraphManager();
-			String stylesheet = graphManager.getStylesheet();
+		GraphManager graphManager = Main.getInstance().getGraphManager();
+		String stylesheet = graphManager.getStylesheet();
 
-			// Show Edges weights
-			if (newVal) {
-				graphManager.setStylesheet(stylesheet.replace("edge{text-mode:hidden;}", ""));
+		// Show Edges weights
+		if (newVal) {
+			graphManager.setStylesheet(stylesheet.replace("edge{text-mode:hidden;}", ""));
 
-				// Hide Edges weights
-			} else {
-				graphManager.setStylesheet(stylesheet.concat("edge{text-mode:hidden;}"));
-			}
+			// Hide Edges weights
+		} else {
+			graphManager.setStylesheet(stylesheet.concat("edge{text-mode:hidden;}"));
 		}
-
-	};
+	}
 
 	/**
 	 * Changes the border of the button that was pressed to red

+ 9 - 9
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GUIController.java

@@ -179,27 +179,27 @@ public class GUIController implements Initializable {
 	 * Sets the handlers for the zoomin and zoomout buttons.
 	 */
 	private void initializeZoomButtons() {
-		zoomIn.setOnAction(ButtonManager.zoomInHandler);
-		zoomOut.setOnAction(ButtonManager.zoomOutHandler);
+		zoomIn.setOnAction((event) -> ButtonManager.zoomInAction(event));
+		zoomOut.setOnAction((event) -> ButtonManager.zoomOutAction(event));
 	}
 
 	private void initializeSymbolRepToolbox() {
 		// Hide SymbolRep Toolbox View
 		symbolToolVBox.setVisible(false);
 
-		edgesVisibleCheckbox.selectedProperty().addListener(ButtonManager.edgeVisibleListener);
-		nodeLabelCheckbox.selectedProperty().addListener(ButtonManager.nodeLabelListener);
-		edgeWeightCheckbox.selectedProperty().addListener(ButtonManager.edgeWeightListener);
+		edgesVisibleCheckbox.selectedProperty().addListener((ov, oldVal, newVal) -> ButtonManager.edgeVisibleSwitch(ov, oldVal, newVal));
+		nodeLabelCheckbox.selectedProperty().addListener((ov, oldVal, newVal) -> ButtonManager.labelVisibilitySwitcher(ov, oldVal, newVal));
+		edgeWeightCheckbox.selectedProperty().addListener((ov, oldVal, newVal) -> ButtonManager.edgeWeightVisibilitySwitcher(ov, oldVal, newVal));
 	}
 
 	/**
 	 * Set the Handlers for the Layer switch Buttons.
 	 */
 	private void initializeLayerButton() {
-		underlayButton.setOnAction(ButtonManager.underlayHandler);
-		operatorButton.setOnAction(ButtonManager.operatorHandler);
-		mappingButton.setOnAction(ButtonManager.mappingHandler);
-		symbolRepButton.setOnAction(ButtonManager.symbolRepHandler);
+		underlayButton.setOnAction((event) -> ButtonManager.underlayAction(event));
+		operatorButton.setOnAction((event) -> ButtonManager.operatorAction(event));
+		mappingButton.setOnAction((event) -> ButtonManager.mappingAction(event));
+		symbolRepButton.setOnAction((event) -> ButtonManager.symbolRepAction(event));
 		
 		ArrayList<Button> layerButtons = new ArrayList<Button>();
 		layerButtons.add(underlayButton);

+ 11 - 6
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/PropertiesManager.java

@@ -150,18 +150,21 @@ public final class PropertiesManager {
 
 			final TableRow<KeyValuePair> row = new TableRow<>();
 
+			// ContextMenu on non empty rows (add & delete)
 			final ContextMenu menuOnNonEmptyRows = new ContextMenu();
-			final ContextMenu menuOnEmptyRows = new ContextMenu();
-
-			final MenuItem onlyAddPropMenuItem = new MenuItem("Add..");
 			final MenuItem addPropMenuItem = new MenuItem("Add..");
 			final MenuItem deletePropMenuItem = new MenuItem("Delete");
+			
+			// ContextMenu on empty rows (only add)
+			final ContextMenu menuOnEmptyRows = new ContextMenu();
+			final MenuItem onlyAddPropMenuItem = new MenuItem("Add..");
 
+			// add functionality
 			onlyAddPropMenuItem.setOnAction(addPropHandler);
-
 			addPropMenuItem.setOnAction(addPropHandler);
-
-			deletePropMenuItem.setOnAction(new EventHandler<ActionEvent>() {
+			
+			// delete functionality
+			deletePropMenuItem.setOnAction(new EventHandler<ActionEvent>() { 
 				@Override
 				public void handle(ActionEvent event) {
 					Debug.out("Remove Element");
@@ -170,9 +173,11 @@ public final class PropertiesManager {
 				}
 			});
 
+			// add MenuItem to ContextMenu
 			menuOnEmptyRows.getItems().add(onlyAddPropMenuItem);
 			menuOnNonEmptyRows.getItems().addAll(addPropMenuItem, deletePropMenuItem);
 
+			// when empty row right-clicked open special menu (only add), otherwise normal menu (add & delete)
 			row.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(row.itemProperty()))
 					.then(menuOnNonEmptyRows).otherwise(menuOnEmptyRows));
 

+ 28 - 35
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ToolboxManager.java

@@ -1,5 +1,7 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
+import javax.swing.text.ChangedCharSetException;
+
 import de.tu_darmstadt.informatik.tk.scopviz.main.CreationMode;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.main.MainApp;
@@ -79,7 +81,7 @@ public final class ToolboxManager {
 		@Override
 		public void handle(MouseEvent event) {
 
-			// Get TbaleRow
+			// Get the clicked TableRow
 			Node node = ((Node) event.getTarget()).getParent();
 			TableRow<Pair<Object, String>> row;
 
@@ -89,65 +91,56 @@ public final class ToolboxManager {
 				// clicking on text part
 				row = (TableRow<Pair<Object, String>>) node.getParent();
 			}
-
-			Main main = Main.getInstance();
-
+			
 			// Set CreateModus based on pressed TableRow
 			if (!row.isEmpty()) {
 
 				String rowString = row.getItem().getValue();
 
 				if (rowString.equals("Standard")) {
-					if (main.getCreationMode().equals(CreationMode.CREATE_STANDARD_NODE))
-						main.setCreationMode(CreationMode.CREATE_NONE);
-					else
-						main.setCreationMode(CreationMode.CREATE_STANDARD_NODE);
+					changeCreationMode(CreationMode.CREATE_STANDARD_NODE);
 
 				} else if (rowString.equals("Source")) {
-					if (main.getCreationMode().equals(CreationMode.CREATE_SOURCE_NODE))
-						main.setCreationMode(CreationMode.CREATE_NONE);
-					else
-						main.setCreationMode(CreationMode.CREATE_SOURCE_NODE);
+					changeCreationMode(CreationMode.CREATE_SOURCE_NODE);
 
 				} else if (rowString.equals("Sink")) {
-					if (main.getCreationMode().equals(CreationMode.CREATE_SINK_NODE))
-						main.setCreationMode(CreationMode.CREATE_NONE);
-					else
-						main.setCreationMode(CreationMode.CREATE_SINK_NODE);
+					changeCreationMode(CreationMode.CREATE_SINK_NODE);
 
 				} else if (rowString.equals("EnProc")) {
-					if (main.getCreationMode().equals(CreationMode.CREATE_PROC_NODE))
-						main.setCreationMode(CreationMode.CREATE_NONE);
-					else
-						main.setCreationMode(CreationMode.CREATE_PROC_NODE);
+					changeCreationMode(CreationMode.CREATE_PROC_NODE);
 
 				} else if (rowString.equals("operator")) {
-					if (main.getCreationMode().equals(CreationMode.CREATE_OPERATOR_NODE))
-						main.setCreationMode(CreationMode.CREATE_NONE);
-					else
-						main.setCreationMode(CreationMode.CREATE_OPERATOR_NODE);
-
+					changeCreationMode(CreationMode.CREATE_OPERATOR_NODE);
+					
 				} else if (rowString.equals("Directed")) {
-					if (main.getCreationMode().equals(CreationMode.CREATE_DIRECTED_EDGE))
-						main.setCreationMode(CreationMode.CREATE_NONE);
-					else
-						main.setCreationMode(CreationMode.CREATE_DIRECTED_EDGE);
-
+					changeCreationMode(CreationMode.CREATE_DIRECTED_EDGE);
+					
 				} else if (rowString.equals("Undirected")) {
-					if (main.getCreationMode().equals(CreationMode.CREATE_UNDIRECTED_EDGE))
-						main.setCreationMode(CreationMode.CREATE_NONE);
-					else
-						main.setCreationMode(CreationMode.CREATE_UNDIRECTED_EDGE);
+					changeCreationMode(CreationMode.CREATE_UNDIRECTED_EDGE);
 				}
 
 				// Unselecet Rows if Creation Mode is None
-				if (main.getCreationMode().equals(CreationMode.CREATE_NONE)) {
+				if (Main.getInstance().getCreationMode().equals(CreationMode.CREATE_NONE)) {
 					controller.toolbox.getSelectionModel().clearSelection();
 				}
 			}
 		}
 
 	};
+	
+	/**
+	 * If currentMode already selected then deselect, otherwise set mode on currentMode
+	 * @param currentMode
+	 */
+	private static void changeCreationMode(CreationMode currentMode){
+		
+		if (Main.getInstance().getCreationMode().equals(currentMode))
+			Main.getInstance().setCreationMode(CreationMode.CREATE_NONE);
+		else
+			Main.getInstance().setCreationMode(currentMode);
+	}
+	
+	
 
 	// TODO: Create Documentation for this, together with Dominik, ich versteh
 	// das zeug hier net.