瀏覽代碼

Lots and lots of refactoring. MERGE CONFLICTS COMING IN MASSES!

Renamed GraphManager to GraphDisplayManager
Moved GraphDisplayManager to ui package
Renamed Visualizer to GraphManager
Moved GraphManager to main package
Removed unnecessary comment, finished todos
Reformatted code
Added some documentation, still some to do
Jan Enders 8 年之前
父節點
當前提交
b8e7e8e400
共有 17 個文件被更改,包括 652 次插入684 次删除
  1. 1 1
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLExporter.java
  2. 1 1
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLImporter.java
  3. 1 1
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/CreationMode.java
  4. 267 162
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/GraphManager.java
  5. 19 28
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/Main.java
  6. 1 1
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/MainApp.java
  7. 1 1
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/SelectionMode.java
  8. 49 57
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ButtonManager.java
  9. 24 22
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GUIController.java
  10. 165 0
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GraphDisplayManager.java
  11. 17 20
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/MenuBarManager.java
  12. 7 6
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/PropertiesManager.java
  13. 61 61
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ToolboxManager.java
  14. 0 267
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/Visualizer.java
  15. 2 5
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/MyAnimationTimer.java
  16. 34 49
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/MyViewerListener.java
  17. 2 2
      scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/ResizeListener.java

+ 1 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLExporter.java

@@ -52,7 +52,7 @@ public class GraphMLExporter {
 		fileChooser.setTitle("Saving graph");
 		try {
 			fileName = fileChooser.showSaveDialog(stage).getPath();
-			Main.getInstance().getVisualizer().setCurrentPath(fileName);
+			Main.getInstance().getGraphManager().setCurrentPath(fileName);
 			writeGraph(g, fileName);
 		} catch (NullPointerException e) {
 

+ 1 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLImporter.java

@@ -56,7 +56,7 @@ public class GraphMLImporter {
 		fileChooser.setTitle("open graph");
 		try {
 			String fileName = fileChooser.showOpenDialog(stage).getPath();
-			Main.getInstance().getVisualizer().setCurrentPath(fileName);
+			Main.getInstance().getGraphManager().setCurrentPath(fileName);
 			return readGraph(id, fileName);
 		} catch (NullPointerException e) {
 			return null;

+ 1 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/CreateModus.java → scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/CreationMode.java

@@ -8,7 +8,7 @@ package de.tu_darmstadt.informatik.tk.scopviz.main;
  * @version 1.0
  *
  */
-public enum CreateModus {
+public enum CreationMode {
 	CREATE_STANDARD_NODE, 
 	CREATE_SOURCE_NODE, 
 	CREATE_SINK_NODE, 

+ 267 - 162
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/GraphManager.java

@@ -1,162 +1,267 @@
-package de.tu_darmstadt.informatik.tk.scopviz.main;
-
-import java.awt.Dimension;
-import java.net.URL;
-import java.util.ArrayList;
-
-import org.graphstream.graph.Graph;
-import org.graphstream.graph.implementations.SingleGraph;
-
-import de.tu_darmstadt.informatik.tk.scopviz.io.GraphMLImporter;
-import de.tu_darmstadt.informatik.tk.scopviz.ui.GUIController;
-import de.tu_darmstadt.informatik.tk.scopviz.ui.Visualizer;
-import javafx.scene.layout.Pane;
-import javafx.stage.Stage;
-
-/**
- * This class holds all Visualizers, provides Functions to add Graphs and get
- * corresponding Visualizers.
- * 
- * @author Matthias Wilhelm
- * @version 1.0
- *
- */
-public class GraphManager {
-	private static final String GRAPH_STRING_ID_PREFIX = "graph";
-	private static ArrayList<Visualizer> vList = new ArrayList<Visualizer>();
-	private static int count = 0;
-	private static GUIController guiController;
-	private static int currentVisualizer = 0;
-	private static Layer currentLayer = Layer.UNDERLAY;
-	private final static Visualizer emptyLayer = new Visualizer(new SingleGraph("g"));
-
-	public static void setGuiController(GUIController guiController) {
-		GraphManager.guiController = guiController;
-	}
-
-	/**
-	 * Adds an empty Graph to the collection.
-	 * 
-	 * @return the id to access the specific Graph
-	 */
-	public static int addGraph() {
-		String id = getGraphStringID(count);
-		Graph g = new MyGraph(id);
-		Visualizer v = new Visualizer(g);
-		vList.add(v);
-		return ++count;
-	}
-
-	/**
-	 * Imports and adds the specified Graph to the collection.
-	 * 
-	 * @param fileName
-	 *            path to the file on disk
-	 * @return the id to access the specific Graph
-	 */
-	public static int addGraph(String fileName) {
-		String id = getGraphStringID(count);
-		GraphMLImporter importer = new GraphMLImporter();
-		Graph g = importer.readGraph(id, Main.class.getResource(fileName));
-		g.addAttribute("layer", currentLayer);
-		Visualizer v = new Visualizer(g);
-		vList.add(v);
-		return count++;
-	}
-
-	/**
-	 * Opens a Wizard and adds the chosen Graph to the collection.
-	 * 
-	 * @param stage
-	 *            the root Window of the program
-	 * @return the id to access the specific Graph
-	 */
-	public static int addGraph(Stage stage) {
-		String id = getGraphStringID(count);
-		GraphMLImporter importer = new GraphMLImporter();
-		Graph g = importer.readGraph(id, stage);
-		g.addAttribute("layer", currentLayer);
-		Visualizer v = new Visualizer(g);
-		vList.add(v);
-		switchActiveGraph();
-		return count++;
-	}
-
-	/**
-	 * Imports and adds the specified Graph to the collection.
-	 * 
-	 * @param fileURL
-	 *            URL of the file
-	 * @return the id to access the specific Graph
-	 */
-	public static int addGraph(URL fileURL) {
-		String id = getGraphStringID(count);
-		GraphMLImporter importer = new GraphMLImporter();
-		Graph g = importer.readGraph(id, fileURL);
-		g.addAttribute("layer", currentLayer);
-		Visualizer v = new Visualizer(g);
-		vList.add(v);
-		return ++count;
-	}
-
-	/**
-	 * Returns the Visualizer for the given graph id
-	 * 
-	 * @param id
-	 *            of the graph
-	 * @return visualizer for the graph
-	 */
-	/*
-	 * public static Visualizer getVisualizer(int id) { return vList.get(id); }
-	 */
-
-	private static String getGraphStringID(int id) {
-		return GRAPH_STRING_ID_PREFIX + id;
-	}
-
-	/**
-	 * Switches the active Graph to the give id.
-	 * 
-	 * @param id
-	 *            of the graph which to switch to
-	 */
-
-	public static void switchActiveGraph() {
-		// TODO Clean up, is copied out the ResizeListener and should be handled
-		// somewhere else
-		Pane pane = guiController.pane;
-		Main.getInstance().getVisualizer().getView()
-				.setPreferredSize(new Dimension((int) pane.getWidth() - 5, (int) pane.getHeight() - 5));
-		guiController.swingNode.setContent(Main.getInstance().getVisualizer().getView());
-		
-		Main.getInstance().setCreateModus(CreateModus.CREATE_NONE);
-	}
-
-	/**
-	 * get the current Visualizer. To get change it call
-	 * {@link #switchActiveGraph(int)}
-	 * 
-	 * @return the current Visualizer
-	 * @see #switchActiveGraph(int)
-	 */
-	public static Visualizer getCurrentVisualizer() {
-		return vList.get(currentVisualizer);
-	}
-
-	public static Visualizer getVisualizer() {
-		for (Visualizer viz : vList) {
-			if (viz.getGraph().getAttribute("layer").equals(currentLayer)) {
-				return viz;
-			}
-		}
-		return emptyLayer;
-	}
-
-	public static Layer getCurrentLayer() {
-		return currentLayer;
-	}
-
-	public static void setCurrentLayer(Layer currentLayer) {
-		GraphManager.currentLayer = currentLayer;
-	}
-}
+package de.tu_darmstadt.informatik.tk.scopviz.main;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+
+import org.graphstream.graph.Edge;
+import org.graphstream.graph.Graph;
+import org.graphstream.graph.Node;
+import org.graphstream.ui.swingViewer.ViewPanel;
+import org.graphstream.ui.view.Viewer;
+import org.graphstream.ui.view.ViewerPipe;
+
+import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyViewerListener;
+
+/**
+ * Interface between GUI and internal Graph representation. Manages internal
+ * representation of the Graph to accommodate creation and deletion of nodes and
+ * edges.
+ * 
+ * @author Jascha Bohne
+ * @version 3.0.0.0
+ *
+ */
+// TODO remove sysout in deleteNode and undelete
+public class GraphManager {
+	// The graph of this Visualizer
+	private Graph g;
+
+	// last deleted elements for undelete
+	private Node deletedNode;
+	private LinkedList<Edge> deletedEdges = new LinkedList<>();
+
+	// Currently selected Edge or Node at least on of these is always null
+	private String selectedNodeID = null;
+	// TODO figure out how to do this
+	private String selectedEdgeID = null;
+
+	// View Panel of the Graph
+	private ViewPanel view;
+
+	// The location the graph will be saved to
+	private String currentPath;
+
+	private Viewer viewer;
+	private ViewerPipe fromViewer;
+
+	/**
+	 * Creates a new visualizer for the given graph.
+	 * 
+	 * @param graph
+	 *            the graph this visualizer should handle
+	 */
+	public GraphManager(Graph graph) {
+		g = graph;
+		/* Viewer */ viewer = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
+		view = viewer.addDefaultView(false);
+		viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.EXIT);
+		/* ViewerPipe */fromViewer = viewer.newViewerPipe();
+		fromViewer.addViewerListener(new MyViewerListener(this));
+		fromViewer.addSink(graph);
+		fromViewer.removeElementSink(graph);
+	}
+
+	/**
+	 * Deletes the Node corresponding to the given ID from the Graph. The
+	 * referenced Graph is modified directly. Will throw an
+	 * ElementNotFoundException, when the Node is not Found Will also remove all
+	 * Edges connected to the given Node
+	 * 
+	 * @param g
+	 *            the Graph with the Node that shall be removed
+	 * @param id
+	 *            the ID of the node that will be removed
+	 */
+	public void deleteNode(final String id) {
+		deletedEdges.removeAll(deletedEdges);
+		deletedNode = null;
+		// Edges have to be deleted first because they clear deletedNode
+		// and need the Node to still be in the Graph
+		deleteEdgesOfNode(id);
+		deletedNode = g.removeNode(id);
+		// System.out.println("test-del");
+	}
+
+	/**
+	 * Deletes the Edge corresponding to the given ID from the Graph. The
+	 * referenced Graph is modified directly. Will throw an
+	 * ElementNotFoundException, when the Edge is not Found
+	 * 
+	 * @param g
+	 *            the Graph with the Edge that shall be removed
+	 * @param id
+	 *            the ID of the Edge that will be removed
+	 */
+	public void deleteEdge(final String id) {
+		deletedEdges.removeAll(deletedEdges);
+		deletedNode = null;
+		deletedEdges.add(g.removeEdge(id));
+	}
+
+	/**
+	 * Deletes all Edges connected to the given Node. The referenced Graph is
+	 * modified directly. Will throw an ElementNotFoundException if the Node is
+	 * not Found
+	 * 
+	 * @param g
+	 *            the Graph containing the Node
+	 * @param id
+	 *            the Id of the Node, whose Edges shall be removed
+	 */
+	public void deleteEdgesOfNode(final String id) {
+		Node node = g.getNode(id);
+		deletedEdges.removeAll(deletedEdges);
+		deletedNode = null;
+		Edge[] temp = new Edge[0];
+		temp = g.getEdgeSet().toArray(temp);
+
+		for (Edge e : temp) {
+			if (e.getSourceNode().equals(node) || e.getTargetNode().equals(node)) {
+				// adds the Edge to the list of deleted Edges and remove sit
+				// from the Graph
+				deletedEdges.add(g.removeEdge(e));
+			}
+		}
+	}
+
+	// TODO make undelete Graph specific
+	/**
+	 * Undoes the last deleting operation on the given Graph. Deleting
+	 * operations are: deleteNode, deleteEdge and deleteEdgesOfNode. Only undoes
+	 * the last deleting operation even if that operation didn't change the
+	 * Graph
+	 * 
+	 * @param g
+	 *            the Graph, whose Elements shall be undeleted
+	 */
+	public void undelete() {
+		// System.out.println("test-undel");
+		HashMap<String, Object> attributes = new HashMap<String, Object>();
+		if (deletedNode != null) {
+			for (String s : deletedNode.getAttributeKeySet()) {
+				attributes.put(s, deletedNode.getAttribute(s));
+			}
+			g.addNode(deletedNode.getId());
+			g.getNode(deletedNode.getId()).addAttributes(attributes);
+		}
+
+		for (Edge e : deletedEdges) {
+			attributes = new HashMap<String, Object>();
+			for (String s : e.getAttributeKeySet()) {
+				attributes.put(s, e.getAttribute(s));
+			}
+			g.addEdge(e.getId(), (Node) e.getSourceNode(), (Node) e.getTargetNode());
+			g.getEdge(e.getId()).addAttributes(attributes);
+		}
+	}
+
+	/**
+	 * returns a View of the Graph. The View is in the Swing Thread and the
+	 * Graph in the Main thread.
+	 * 
+	 * 
+	 * @return a View of the Graph, inheriting from JPanel
+	 */
+	public ViewPanel getView() {
+		return view;
+	}
+
+	/**
+	 * Returns the ID of the currently selected Node.
+	 * 
+	 * @return the node's ID
+	 */
+	public String getSelectedNodeID() {
+		return selectedNodeID;
+	}
+
+	/**
+	 * Sets the ID for the currently selected node, effectively selecting the
+	 * node with that ID.
+	 * 
+	 * @param selectedNodeID
+	 *            the ID of the node to select
+	 */
+	public void setSelectedNodeID(String selectedNodeID) {
+		this.selectedNodeID = selectedNodeID;
+	}
+
+	/**
+	 * Returns the ID of the currently selected Edge.
+	 * 
+	 * @return the edge's ID
+	 */
+	public String getSelectedEdgeID() {
+		return selectedEdgeID;
+	}
+
+	/**
+	 * Sets the ID for the currently selected edge, effectively selecting the
+	 * edge with that ID.
+	 * 
+	 * @param selectedEdgeID
+	 *            the ID of the edge to select
+	 */
+	public void setSelectedEdgeID(String selectedEdgeID) {
+		this.selectedEdgeID = selectedEdgeID;
+	}
+
+	/**
+	 * Deselect any currently selected nodes or edges.
+	 */
+	public void deselect() {
+		this.selectedNodeID = null;
+		this.selectedEdgeID = null;
+	}
+
+	/**
+	 * Returns a reference to the Graph object managed by this visualizer.
+	 * 
+	 * @return the graph
+	 */
+	public Graph getGraph() {
+		return g;
+	}
+
+	/**
+	 * Zooms in the view of the graph by 5 percent.
+	 */
+	public void zoomIn() {
+		view.getCamera().setViewPercent(view.getCamera().getViewPercent() * 0.95);
+	}
+
+	/**
+	 * Zooms out the view of the graph by 5 percent.
+	 */
+	public void zoomOut() {
+		view.getCamera().setViewPercent(view.getCamera().getViewPercent() * 1.05);
+	}
+
+	public ViewerPipe getFromViewer() {
+		return fromViewer;
+	}
+
+	public void pumpIt() {
+		fromViewer.pump();
+	}
+
+	@Override
+	public String toString() {
+		return "Visualizer for Graph \"" + g.getId() + "\"";
+	}
+
+	/**
+	 * @return the currentPath
+	 */
+	public String getCurrentPath() {
+		return currentPath;
+	}
+
+	/**
+	 * @param currentPath
+	 *            the currentPath to set
+	 */
+	public void setCurrentPath(String currentPath) {
+		this.currentPath = currentPath;
+	}
+}

+ 19 - 28
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/Main.java

@@ -1,8 +1,6 @@
 package de.tu_darmstadt.informatik.tk.scopviz.main;
 
-import org.graphstream.graph.Node;
-
-import de.tu_darmstadt.informatik.tk.scopviz.ui.Visualizer;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.GraphDisplayManager;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyAnimationTimer;
 import javafx.animation.AnimationTimer;
 import javafx.stage.Stage;
@@ -22,15 +20,13 @@ public final class Main {
 	private static Main instance;
 
 	/**
-	 * Current mode of the application for creating new Nodes and
-	 * Edges.
+	 * Current mode of the application for creating new Nodes and Edges.
 	 */
-	private CreateModus createModus = CreateModus.CREATE_NONE;
+	private CreationMode creationMode = CreationMode.CREATE_NONE;
 	/**
-	 * Current mode of the application for selecting Nodes and
-	 * Edges.
+	 * Current mode of the application for selecting Nodes and Edges.
 	 */
-	private SelectionModus selectModus = SelectionModus.SELECT_NODES;
+	private SelectionMode selectModus = SelectionMode.SELECT_NODES;
 
 	/**
 	 * the root window of the application
@@ -43,12 +39,6 @@ public final class Main {
 	 * manage it
 	 */
 	private Main() {
-		/*
-		GraphManager.addGraph("/Example.graphml");
-		GraphManager.setCurrentLayer(Layer.OPERATOR);
-		GraphManager.addGraph("/Example2.graphml");
-		*/
-		
 		AnimationTimer alwaysPump = new MyAnimationTimer();
 		alwaysPump.start();
 	}
@@ -78,8 +68,8 @@ public final class Main {
 	 * 
 	 * @return the visualizer in use
 	 */
-	public Visualizer getVisualizer() {
-		return GraphManager.getVisualizer();
+	public GraphManager getGraphManager() {
+		return GraphDisplayManager.getGraphManager();
 	}
 
 	/**
@@ -91,14 +81,13 @@ public final class Main {
 		int i = 0;
 		while (true) {
 			String tempID = i + "";
-			if (getVisualizer().getGraph().getNode(tempID) == null
-					&& getVisualizer().getGraph().getEdge(tempID) == null) {
+			if (getGraphManager().getGraph().getNode(tempID) == null
+					&& getGraphManager().getGraph().getEdge(tempID) == null) {
 				return (tempID);
 			} else {
 				i++;
 			}
 		}
-		// return (new Random().nextInt()+"");
 	}
 
 	/**
@@ -119,28 +108,30 @@ public final class Main {
 	/**
 	 * @return the createModus
 	 */
-	public CreateModus getCreateModus() {
-		return createModus;
+	public CreationMode getCreationMode() {
+		return creationMode;
 	}
 
 	/**
-	 * @param createModus the createModus to set
+	 * @param creationMode
+	 *            the createModus to set
 	 */
-	public void setCreateModus(CreateModus createModus) {
-		this.createModus = createModus;
+	public void setCreationMode(CreationMode creationMode) {
+		this.creationMode = creationMode;
 	}
 
 	/**
 	 * @return the selectModus
 	 */
-	public SelectionModus getSelectModus() {
+	public SelectionMode getSelectModus() {
 		return selectModus;
 	}
 
 	/**
-	 * @param selectModus the selectModus to set
+	 * @param selectModus
+	 *            the selectModus to set
 	 */
-	public void setSelectModus(SelectionModus selectModus) {
+	public void setSelectModus(SelectionMode selectModus) {
 		this.selectModus = selectModus;
 	}
 

+ 1 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/MainApp.java

@@ -82,7 +82,7 @@ public class MainApp extends Application {
 			public void handle(WindowEvent event) {
 				if (exportOnClose) {
 					GraphMLExporter exporter = new GraphMLExporter();
-					exporter.writeGraph(Main.getInstance().getVisualizer().getGraph(), "shutdown.graphml");
+					exporter.writeGraph(Main.getInstance().getGraphManager().getGraph(), "shutdown.graphml");
 				}
 
 				System.exit(0);

+ 1 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/SelectionModus.java → scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/SelectionMode.java

@@ -1,6 +1,6 @@
 package de.tu_darmstadt.informatik.tk.scopviz.main;
 
-public enum SelectionModus {
+public enum SelectionMode {
 	SELECT_NODES,
 	SELECT_EDGES,
 	CREATE

+ 49 - 57
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ButtonManager.java

@@ -5,7 +5,7 @@ import org.graphstream.graph.Node;
 import org.graphstream.ui.geom.Point3;
 
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
-import de.tu_darmstadt.informatik.tk.scopviz.main.CreateModus;
+import de.tu_darmstadt.informatik.tk.scopviz.main.CreationMode;
 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;
@@ -21,34 +21,34 @@ import javafx.scene.input.MouseEvent;
  *
  */
 public class ButtonManager {
-	
+
 	/**
 	 * Create more then one Edge at a time mode
 	 */
-	public static final Boolean CREATE_MORE_THEN_ONE = true; 
+	public static final Boolean CREATE_MORE_THEN_ONE = true;
 
 	/**
 	 * Handler for zoom in Button
 	 */
-	public static EventHandler<ActionEvent> zoomInHandler = new EventHandler<ActionEvent>() {
+	public static final EventHandler<ActionEvent> zoomInHandler = new EventHandler<ActionEvent>() {
 		public void handle(ActionEvent evt) {
-			Main.getInstance().getVisualizer().zoomIn();
+			Main.getInstance().getGraphManager().zoomIn();
 		}
 	};
 
 	/**
 	 * Handler for zoom out Button
 	 */
-	public static EventHandler<ActionEvent> zoomOutHandler = new EventHandler<ActionEvent>() {
+	public static final EventHandler<ActionEvent> zoomOutHandler = new EventHandler<ActionEvent>() {
 		public void handle(ActionEvent evt) {
-			Main.getInstance().getVisualizer().zoomOut();
+			Main.getInstance().getGraphManager().zoomOut();
 		}
 	};
 
 	/**
 	 * Handler for clicks on the graph viewer.
 	 */
-	public static EventHandler<MouseEvent> clickedHandler = new EventHandler<MouseEvent>() {
+	public static final EventHandler<MouseEvent> clickedHandler = new EventHandler<MouseEvent>() {
 
 		/**
 		 * Handle method gets called whenever a click is registered within the
@@ -59,104 +59,96 @@ public class ButtonManager {
 		 */
 		@Override
 		public void handle(MouseEvent event) {
-			Visualizer visualizer = Main.getInstance().getVisualizer();
-			Graph graph = visualizer.getGraph();
-			Point3 cursorPos = visualizer.getView().getCamera().transformPxToGu(event.getX(), event.getY());
-			
+			GraphManager graphManager = Main.getInstance().getGraphManager();
+			Graph graph = graphManager.getGraph();
+			Point3 cursorPos = graphManager.getView().getCamera().transformPxToGu(event.getX(), event.getY());
+
 			Node n;
-			
+
 			// Create node based on creation Mode
-			switch(Main.getInstance().getCreateModus()){
-			
-			case CREATE_STANDARD_NODE: 
+			switch (Main.getInstance().getCreationMode()) {
+
+			case CREATE_STANDARD_NODE:
 				n = graph.addNode(Main.getInstance().getUnusedID());
 				n.setAttribute("xyz", cursorPos);
 				Debug.out("Added Node at Position (" + cursorPos.x + "/" + cursorPos.y + ")");
-		
+
 				break;
-			
+
 			case CREATE_SOURCE_NODE:
 				n = graph.addNode(Main.getInstance().getUnusedID());
 				n.setAttribute("xyz", cursorPos);
 				n.setAttribute("ui.style", "fill-color: rgb(0, 0, 255);");
 				Debug.out("Added Source Node at Position (" + cursorPos.x + "/" + cursorPos.y + ")");
-				
+
 				break;
-				
+
 			case CREATE_SINK_NODE:
 				n = graph.addNode(Main.getInstance().getUnusedID());
 				n.setAttribute("xyz", cursorPos);
 				n.setAttribute("ui.style", "fill-color: rgb(255, 0, 0);");
 				Debug.out("Added Sink Node at Position (" + cursorPos.x + "/" + cursorPos.y + ")");
-				
+
 				break;
-				
+
 			case CREATE_PROC_NODE:
 				n = graph.addNode(Main.getInstance().getUnusedID());
 				n.setAttribute("xyz", cursorPos);
 				n.setAttribute("ui.style", "fill-color: rgb(0, 255, 0);");
 				Debug.out("Added ProcEn Node at Position (" + cursorPos.x + "/" + cursorPos.y + ")");
-				
+
 				break;
-				
+
 			default:
 				break;
 			}
-			
+
 			PropertiesManager.setItemsProperties();
-			
-			if(!CREATE_MORE_THEN_ONE){
-				Main.getInstance().setCreateModus(CreateModus.CREATE_NONE);
+
+			if (!CREATE_MORE_THEN_ONE) {
+				Main.getInstance().setCreationMode(CreationMode.CREATE_NONE);
 			}
 		}
 	};
-	
-	
-	
-	
-	public static EventHandler<ActionEvent> underlayHandler = new EventHandler<ActionEvent>(){
+
+	public static final EventHandler<ActionEvent> underlayHandler = new EventHandler<ActionEvent>() {
 
 		@Override
 		public void handle(ActionEvent arg0) {
-			GraphManager.setCurrentLayer(Layer.UNDERLAY);
-			GraphManager.switchActiveGraph();
+			GraphDisplayManager.setCurrentLayer(Layer.UNDERLAY);
+			GraphDisplayManager.switchActiveGraph();
 		}
-		
-		
+
 	};
-	
-	public static EventHandler<ActionEvent> operatorHandler = new EventHandler<ActionEvent>(){
+
+	public static final EventHandler<ActionEvent> operatorHandler = new EventHandler<ActionEvent>() {
 
 		@Override
 		public void handle(ActionEvent arg0) {
-			GraphManager.setCurrentLayer(Layer.OPERATOR);
-			GraphManager.switchActiveGraph();
+			GraphDisplayManager.setCurrentLayer(Layer.OPERATOR);
+			GraphDisplayManager.switchActiveGraph();
 		}
-		
-		
+
 	};
-	
-	public static EventHandler<ActionEvent> mappingHandler = new EventHandler<ActionEvent>(){
+
+	public static final EventHandler<ActionEvent> mappingHandler = new EventHandler<ActionEvent>() {
 
 		@Override
 		public void handle(ActionEvent arg0) {
-			GraphManager.setCurrentLayer(Layer.MAPPING);
-			GraphManager.switchActiveGraph();
+			GraphDisplayManager.setCurrentLayer(Layer.MAPPING);
+			GraphDisplayManager.switchActiveGraph();
 		}
-			
-			
+
 	};
-		
-	public static EventHandler<ActionEvent> symbolRepHandler = new EventHandler<ActionEvent>(){
+
+	public static final EventHandler<ActionEvent> symbolRepHandler = new EventHandler<ActionEvent>() {
 
 		@Override
 		public void handle(ActionEvent arg0) {
-			GraphManager.setCurrentLayer(Layer.SYMBOL);
-			GraphManager.switchActiveGraph();
+			GraphDisplayManager.setCurrentLayer(Layer.SYMBOL);
+			GraphDisplayManager.switchActiveGraph();
 		}
-			
-			
+
 	};
-	
-	
+
 }

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

@@ -5,7 +5,6 @@ import java.util.ResourceBundle;
 
 import javax.swing.JPanel;
 
-import de.tu_darmstadt.informatik.tk.scopviz.main.GraphManager;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.ResizeListener;
 import javafx.beans.value.ChangeListener;
@@ -43,12 +42,12 @@ public class GUIController implements Initializable {
 	@FXML
 	public Pane pane;
 
-	// The Button present in the UI
+	// The buttons present in the UI
 	@FXML
 	public Button zoomIn;
 	@FXML
 	public Button zoomOut;
-	
+
 	@FXML
 	public Button underlayButton;
 	@FXML
@@ -84,11 +83,14 @@ public class GUIController implements Initializable {
 	@FXML
 	public ListView<String> layerListView;
 
+	// The columns of the Toolbox
 	@FXML
 	public TableColumn<Pair<Object, String>, String> toolboxStringColumn;
 	@FXML
 	public TableColumn<Pair<Object, String>, Object> toolboxObjectColumn;
 
+	// The columns of the Properites pane
+	// TODO: Fix Generic type arguments for propertiesObjectColumn
 	@FXML
 	public TableColumn<KeyValuePair, String> propertiesStringColumn;
 	@FXML
@@ -107,7 +109,7 @@ public class GUIController implements Initializable {
 
 		assert zoomIn != null : "fx:id=\"zoomIn\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 		assert zoomOut != null : "fx:id=\"zoomOut\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
-		
+
 		assert underlayButton != null : "fx:id=\"underlayButton\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 		assert operatorButton != null : "fx:id=\"operatorButton\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 		assert mappingButton != null : "fx:id=\"mappingButton\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
@@ -122,7 +124,7 @@ public class GUIController implements Initializable {
 		assert selectMode != null : "fx:id=\"selectMode\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 
 		assert layerListView != null : "fx:id=\"layerListView\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
-	
+
 		assert toolbox != null : "fx:id=\"toolbox\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 		assert properties != null : "fx:id=\"properties\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 		assert metricListView != null : "fx:id=\"metricListView\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
@@ -135,7 +137,7 @@ public class GUIController implements Initializable {
 
 		initializeToolbox();
 		initializeProperties();
-		
+
 		// Remove Header for TableViews
 		removeHeaderTableView(toolbox);
 		removeHeaderTableView(properties);
@@ -143,7 +145,7 @@ public class GUIController implements Initializable {
 		// Initialize the Managers for the various managers for UI elements
 		ToolboxManager.initializeItems(toolbox);
 		PropertiesManager.initializeItems(properties);
-		GraphManager.setGuiController(this);
+		GraphDisplayManager.setGuiController(this);
 
 		// Bind all the handlers to their corresponding UI elements
 		initializeZoomButtons();
@@ -154,13 +156,13 @@ public class GUIController implements Initializable {
 	}
 
 	private void initializeToolBar() {
-		open.setOnAction(ToolbarManager.openHandler);
-		save.setOnAction(ToolbarManager.saveHandler);
-		saveAs.setOnAction(ToolbarManager.saveAsHandler);
-		quit.setOnAction(ToolbarManager.quitHandler);
-		delete.setOnAction(ToolbarManager.deleteHandler);
-		undelete.setOnAction(ToolbarManager.undeleteHandler);
-		selectMode.setOnAction(ToolbarManager.selectModeHandler);
+		open.setOnAction(MenuBarManager.openHandler);
+		save.setOnAction(MenuBarManager.saveHandler);
+		saveAs.setOnAction(MenuBarManager.saveAsHandler);
+		quit.setOnAction(MenuBarManager.quitHandler);
+		delete.setOnAction(MenuBarManager.deleteHandler);
+		undelete.setOnAction(MenuBarManager.undeleteHandler);
+		selectMode.setOnAction(MenuBarManager.selectModeHandler);
 	}
 
 	/**
@@ -177,8 +179,8 @@ public class GUIController implements Initializable {
 	private void initializeCreateButtons() {
 		swingNode.setOnMouseClicked(ButtonManager.clickedHandler);
 	}
-	
-	private void initializeLayerButton(){
+
+	private void initializeLayerButton() {
 		underlayButton.setOnAction(ButtonManager.underlayHandler);
 		operatorButton.setOnAction(ButtonManager.operatorHandler);
 		mappingButton.setOnAction(ButtonManager.mappingHandler);
@@ -191,7 +193,7 @@ public class GUIController implements Initializable {
 	private void initializeDisplayPane() {
 		pane.heightProperty().addListener(new ResizeListener(swingNode, pane));
 		pane.widthProperty().addListener(new ResizeListener(swingNode, pane));
-		swingNode.setContent((JPanel) Main.getInstance().getVisualizer().getView());
+		swingNode.setContent((JPanel) Main.getInstance().getGraphManager().getView());
 		pane.setMinSize(200, 200);
 	}
 
@@ -213,12 +215,12 @@ public class GUIController implements Initializable {
 						return new ToolboxManager.PairValueCell();
 					}
 				});
-		
+
 		// Click event for TableView row
-		toolbox.setRowFactory( tv -> {
-		    TableRow<Pair<Object, String>> row = new TableRow<>();
-		    row.setOnMouseClicked(ToolboxManager.rowClickedHandler);
-		    return row ;
+		toolbox.setRowFactory(tv -> {
+			TableRow<Pair<Object, String>> row = new TableRow<>();
+			row.setOnMouseClicked(ToolboxManager.rowClickedHandler);
+			return row;
 		});
 
 	}

+ 165 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GraphDisplayManager.java

@@ -0,0 +1,165 @@
+package de.tu_darmstadt.informatik.tk.scopviz.ui;
+
+import java.awt.Dimension;
+import java.net.URL;
+import java.util.ArrayList;
+
+import org.graphstream.graph.Graph;
+import org.graphstream.graph.implementations.SingleGraph;
+
+import de.tu_darmstadt.informatik.tk.scopviz.io.GraphMLImporter;
+import de.tu_darmstadt.informatik.tk.scopviz.main.CreationMode;
+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 de.tu_darmstadt.informatik.tk.scopviz.main.MyGraph;
+import javafx.scene.layout.Pane;
+import javafx.stage.Stage;
+
+/**
+ * This class holds all Visualizers, provides Functions to add Graphs and get
+ * corresponding Visualizers.
+ * 
+ * @author Matthias Wilhelm
+ * @version 1.0
+ *
+ */
+public class GraphDisplayManager {
+	private static final String GRAPH_STRING_ID_PREFIX = "graph";
+	private static ArrayList<GraphManager> vList = new ArrayList<GraphManager>();
+	private static int count = 0;
+	private static GUIController guiController;
+	private static int currentVisualizer = 0;
+	private static Layer currentLayer = Layer.UNDERLAY;
+	private final static GraphManager emptyLayer = new GraphManager(new SingleGraph("g"));
+
+	public static void setGuiController(GUIController guiController) {
+		GraphDisplayManager.guiController = guiController;
+	}
+
+	/**
+	 * Adds an empty Graph to the collection.
+	 * 
+	 * @return the id to access the specific Graph
+	 */
+	public static int addGraph() {
+		String id = getGraphStringID(count);
+		Graph g = new MyGraph(id);
+		GraphManager v = new GraphManager(g);
+		vList.add(v);
+		return ++count;
+	}
+
+	/**
+	 * Imports and adds the specified Graph to the collection.
+	 * 
+	 * @param fileName
+	 *            path to the file on disk
+	 * @return the id to access the specific Graph
+	 */
+	public static int addGraph(String fileName) {
+		String id = getGraphStringID(count);
+		GraphMLImporter importer = new GraphMLImporter();
+		Graph g = importer.readGraph(id, Main.class.getResource(fileName));
+		g.addAttribute("layer", currentLayer);
+		GraphManager v = new GraphManager(g);
+		vList.add(v);
+		return count++;
+	}
+
+	/**
+	 * Opens a Wizard and adds the chosen Graph to the collection.
+	 * 
+	 * @param stage
+	 *            the root Window of the program
+	 * @return the id to access the specific Graph
+	 */
+	public static int addGraph(Stage stage) {
+		String id = getGraphStringID(count);
+		GraphMLImporter importer = new GraphMLImporter();
+		Graph g = importer.readGraph(id, stage);
+		g.addAttribute("layer", currentLayer);
+		GraphManager v = new GraphManager(g);
+		vList.add(v);
+		switchActiveGraph();
+		return count++;
+	}
+
+	/**
+	 * Imports and adds the specified Graph to the collection.
+	 * 
+	 * @param fileURL
+	 *            URL of the file
+	 * @return the id to access the specific Graph
+	 */
+	public static int addGraph(URL fileURL) {
+		String id = getGraphStringID(count);
+		GraphMLImporter importer = new GraphMLImporter();
+		Graph g = importer.readGraph(id, fileURL);
+		g.addAttribute("layer", currentLayer);
+		GraphManager v = new GraphManager(g);
+		vList.add(v);
+		return ++count;
+	}
+
+	/**
+	 * Returns the Visualizer for the given graph id
+	 * 
+	 * @param id
+	 *            of the graph
+	 * @return visualizer for the graph
+	 */
+	/*
+	 * public static Visualizer getVisualizer(int id) { return vList.get(id); }
+	 */
+
+	private static String getGraphStringID(int id) {
+		return GRAPH_STRING_ID_PREFIX + id;
+	}
+
+	/**
+	 * Switches the active Graph to the give id.
+	 * 
+	 * @param id
+	 *            of the graph which to switch to
+	 */
+
+	public static void switchActiveGraph() {
+		// TODO Clean up, is copied out the ResizeListener and should be handled
+		// somewhere else
+		Pane pane = guiController.pane;
+		Main.getInstance().getGraphManager().getView()
+				.setPreferredSize(new Dimension((int) pane.getWidth() - 5, (int) pane.getHeight() - 5));
+		guiController.swingNode.setContent(Main.getInstance().getGraphManager().getView());
+		
+		Main.getInstance().setCreationMode(CreationMode.CREATE_NONE);
+	}
+
+	/**
+	 * get the current Visualizer. To get change it call
+	 * {@link #switchActiveGraph(int)}
+	 * 
+	 * @return the current Visualizer
+	 * @see #switchActiveGraph(int)
+	 */
+	public static GraphManager getCurrentGraphManager() {
+		return vList.get(currentVisualizer);
+	}
+
+	public static GraphManager getGraphManager() {
+		for (GraphManager viz : vList) {
+			if (viz.getGraph().getAttribute("layer").equals(currentLayer)) {
+				return viz;
+			}
+		}
+		return emptyLayer;
+	}
+
+	public static Layer getCurrentLayer() {
+		return currentLayer;
+	}
+
+	public static void setCurrentLayer(Layer currentLayer) {
+		GraphDisplayManager.currentLayer = currentLayer;
+	}
+}

+ 17 - 20
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ToolbarManager.java → scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/MenuBarManager.java

@@ -1,21 +1,19 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
 import de.tu_darmstadt.informatik.tk.scopviz.io.GraphMLExporter;
-import de.tu_darmstadt.informatik.tk.scopviz.io.GraphMLImporter;
 import de.tu_darmstadt.informatik.tk.scopviz.main.GraphManager;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
-import de.tu_darmstadt.informatik.tk.scopviz.main.SelectionModus;
+import de.tu_darmstadt.informatik.tk.scopviz.main.SelectionMode;
 import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
 import javafx.scene.control.MenuItem;
 
-public class ToolbarManager {
-
+public class MenuBarManager {
 
 	/**
 	 * Handler for the "open" MenuItem.
 	 */
-	public static EventHandler<ActionEvent> openHandler = new EventHandler<ActionEvent>() {
+	public static final EventHandler<ActionEvent> openHandler = new EventHandler<ActionEvent>() {
 
 		/**
 		 * Handle method gets called when the button is pressed.
@@ -25,15 +23,15 @@ public class ToolbarManager {
 		 */
 		@Override
 		public void handle(ActionEvent arg0) {
-			Visualizer v = Main.getInstance().getVisualizer();
-			GraphManager.addGraph(Main.getInstance().getPrimaryStage());
+			// GraphManager v = Main.getInstance().getGraphManager();
+			GraphDisplayManager.addGraph(Main.getInstance().getPrimaryStage());
 		}
 	};
 
 	/**
 	 * Handler for the "save" button.
 	 */
-	public static EventHandler<ActionEvent> saveHandler = new EventHandler<ActionEvent>() {
+	public static final EventHandler<ActionEvent> saveHandler = new EventHandler<ActionEvent>() {
 
 		/**
 		 * Handle method gets called when the button is pressed.
@@ -43,7 +41,7 @@ public class ToolbarManager {
 		 */
 		@Override
 		public void handle(ActionEvent arg0) {
-			Visualizer v = Main.getInstance().getVisualizer();
+			GraphManager v = Main.getInstance().getGraphManager();
 			if (v.getCurrentPath() != null) {
 				new GraphMLExporter().writeGraph(v.getGraph(), v.getCurrentPath());
 			} else {
@@ -52,14 +50,14 @@ public class ToolbarManager {
 		}
 	};
 
-	public static EventHandler<ActionEvent> saveAsHandler = new EventHandler<ActionEvent>() {
+	public static final EventHandler<ActionEvent> saveAsHandler = new EventHandler<ActionEvent>() {
 		public void handle(ActionEvent evt) {
-			Visualizer v = Main.getInstance().getVisualizer();
+			GraphManager v = Main.getInstance().getGraphManager();
 			new GraphMLExporter().writeGraph(v.getGraph(), Main.getInstance().getPrimaryStage());
 		}
 	};
 
-	public static EventHandler<ActionEvent> quitHandler = new EventHandler<ActionEvent>() {
+	public static final EventHandler<ActionEvent> quitHandler = new EventHandler<ActionEvent>() {
 		public void handle(ActionEvent evt) {
 			System.exit(0);
 		}
@@ -68,7 +66,7 @@ public class ToolbarManager {
 	/**
 	 * Handler for the "save" button.
 	 */
-	public static EventHandler<ActionEvent> deleteHandler = new EventHandler<ActionEvent>() {
+	public static final EventHandler<ActionEvent> deleteHandler = new EventHandler<ActionEvent>() {
 
 		/**
 		 * Handle method gets called whenever the menuItem is presser
@@ -78,7 +76,7 @@ public class ToolbarManager {
 		 */
 		@Override
 		public void handle(ActionEvent event) {
-			Visualizer v = Main.getInstance().getVisualizer();
+			GraphManager v = Main.getInstance().getGraphManager();
 			if (v.getSelectedEdgeID() != null) {
 				v.deleteEdge(v.getSelectedEdgeID());
 			}
@@ -88,22 +86,21 @@ public class ToolbarManager {
 		}
 	};
 
-	public static EventHandler<ActionEvent> undeleteHandler = new EventHandler<ActionEvent>() {
+	public static final EventHandler<ActionEvent> undeleteHandler = new EventHandler<ActionEvent>() {
 		public void handle(ActionEvent evt) {
-			Main.getInstance().getVisualizer().undelete();
+			Main.getInstance().getGraphManager().undelete();
 		}
 	};
 
-	// TODO split Modus Enum
-	public static EventHandler<ActionEvent> selectModeHandler = new EventHandler<ActionEvent>() {
+	public static final EventHandler<ActionEvent> selectModeHandler = new EventHandler<ActionEvent>() {
 		public void handle(ActionEvent evt) {
 			MenuItem src = (MenuItem) evt.getSource();
 			if (src.getText().equals("Select Edges")) {
 				src.setText("Select Nodes");
-				Main.getInstance().setSelectModus(SelectionModus.SELECT_EDGES);
+				Main.getInstance().setSelectModus(SelectionMode.SELECT_EDGES);
 			} else {
 				src.setText("Select Edges");
-				Main.getInstance().setSelectModus(SelectionModus.SELECT_NODES);
+				Main.getInstance().setSelectModus(SelectionMode.SELECT_NODES);
 			}
 
 		}

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

@@ -5,6 +5,7 @@ import org.graphstream.graph.Edge;
 import org.graphstream.graph.Element;
 import org.graphstream.graph.Node;
 
+import de.tu_darmstadt.informatik.tk.scopviz.main.GraphManager;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
@@ -39,7 +40,7 @@ public class PropertiesManager {
 	/**
 	 * Update Properties of selected Node/Edge, if a any Property was changed
 	 */
-	public static EventHandler<CellEditEvent<KeyValuePair, String>> setOnEditCommitHandler = new EventHandler<CellEditEvent<KeyValuePair, String>>() {
+	public static final EventHandler<CellEditEvent<KeyValuePair, String>> setOnEditCommitHandler = new EventHandler<CellEditEvent<KeyValuePair, String>>() {
 
 		@Override
 		public void handle(CellEditEvent<KeyValuePair, String> t) {
@@ -51,7 +52,7 @@ public class PropertiesManager {
 
 			editedPair.setValue(t.getNewValue());
 
-			Visualizer viz = Main.getInstance().getVisualizer();
+			GraphManager viz = Main.getInstance().getGraphManager();
 			Element selected;
 
 			String nid = viz.getSelectedNodeID();
@@ -88,15 +89,15 @@ public class PropertiesManager {
 	 */
 	public static void setItemsProperties() {
 
-		String nid = Main.getInstance().getVisualizer().getSelectedNodeID();
-		String eid = Main.getInstance().getVisualizer().getSelectedEdgeID();
+		String nid = Main.getInstance().getGraphManager().getSelectedNodeID();
+		String eid = Main.getInstance().getGraphManager().getSelectedEdgeID();
 
 		if (nid != null) {
-			Node selectedNode = Main.getInstance().getVisualizer().getGraph().getNode(nid);
+			Node selectedNode = Main.getInstance().getGraphManager().getGraph().getNode(nid);
 			showNewDataSet(selectedNode);
 
 		} else if (eid != null) {
-			Edge selectedEdge = Main.getInstance().getVisualizer().getGraph().getEdge(eid);
+			Edge selectedEdge = Main.getInstance().getGraphManager().getGraph().getEdge(eid);
 			showNewDataSet(selectedEdge);
 
 		} else

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

@@ -1,6 +1,6 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
-import de.tu_darmstadt.informatik.tk.scopviz.main.CreateModus;
+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;
 import javafx.beans.property.ReadOnlyObjectWrapper;
@@ -21,12 +21,13 @@ import javafx.util.Callback;
 import javafx.util.Pair;
 
 /**
- * Manager for the Toolbox pane. Der Jascha soll mal sein Ding da reinmergen
+ * Manager for the Toolbox pane.
  * 
  * @author Dominik Renkel
  * @version 0.9
  *
  */
+// TODO Jaschas Code mergen?
 public class ToolboxManager {
 
 	/**
@@ -42,81 +43,80 @@ public class ToolboxManager {
 				pair(new Image(MainApp.class.getResource("/png/node.png").toString()), "Standard"),
 				pair(new Image(MainApp.class.getResource("/png/source.png").toString()), "Source"),
 				pair(new Image(MainApp.class.getResource("/png/sink.png").toString()), "Sink"),
-				pair(new Image(MainApp.class.getResource("/png/enProc.png").toString()), "EnProc"), 
-				pair("", ""),
+				pair(new Image(MainApp.class.getResource("/png/enProc.png").toString()), "EnProc"), pair("", ""),
 				pair(new Image(MainApp.class.getResource("/png/dirEdge.png").toString()), "Directed"),
 				pair(new Image(MainApp.class.getResource("/png/undirEdge.png").toString()), "Undirected"));
 
 		toolbox.getItems().setAll(data);
 	}
-	
+
 	/**
 	 * Handler for TableRows
 	 */
-	public static EventHandler<MouseEvent> rowClickedHandler = new EventHandler<MouseEvent>(){
+	public static final EventHandler<MouseEvent> rowClickedHandler = new EventHandler<MouseEvent>() {
 
 		@SuppressWarnings("unchecked")
 		@Override
 		public void handle(MouseEvent event) {
-			
+
 			// Get TbaleRow
 			Node node = ((Node) event.getTarget()).getParent();
-            TableRow<Pair<Object, String>> row;
-            
-            if (node instanceof TableRow) {
-                row = (TableRow<Pair<Object, String>>) node;
-            } else {
-                // clicking on text part
-                row = (TableRow<Pair<Object, String>>) node.getParent();
-            }
-			
-            Main main = Main.getInstance();
-            
-            // Set CreateModus based on pressed TableRow
-			if (! row.isEmpty()) {
-				
+			TableRow<Pair<Object, String>> row;
+
+			if (node instanceof TableRow) {
+				row = (TableRow<Pair<Object, String>>) node;
+			} else {
+				// 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.getCreateModus().equals(CreateModus.CREATE_STANDARD_NODE))
-	            		main.setCreateModus(CreateModus.CREATE_NONE);
-	            	else
-	            		main.setCreateModus(CreateModus.CREATE_STANDARD_NODE);
-	            	
-	            }else if(rowString.equals("Source")){
-	            	if(main.getCreateModus().equals(CreateModus.CREATE_SOURCE_NODE))
-	            		main.setCreateModus(CreateModus.CREATE_NONE);
-	            	else
-	            		main.setCreateModus(CreateModus.CREATE_SOURCE_NODE);
-		            
-	            }else if(rowString.equals("Sink")){
-	            	if(main.getCreateModus().equals(CreateModus.CREATE_SINK_NODE))
-	            		main.setCreateModus(CreateModus.CREATE_NONE);
-	            	else
-	            		main.setCreateModus(CreateModus.CREATE_SINK_NODE);
-	            	
-	            }else if(rowString.equals("EnProc")){
-	            	if(main.getCreateModus().equals(CreateModus.CREATE_PROC_NODE))
-	            		main.setCreateModus(CreateModus.CREATE_NONE);
-	            	else
-	            		main.setCreateModus(CreateModus.CREATE_PROC_NODE);
-	            	
-	            }else if(rowString.equals("Directed")){
-	            	if(main.getCreateModus().equals(CreateModus.CREATE_DIRECTED_EDGE))
-	            		main.setCreateModus(CreateModus.CREATE_NONE);
-	            	else
-	            		main.setCreateModus(CreateModus.CREATE_DIRECTED_EDGE);
-	            	
-	            }else if(rowString.equals("Undirected")){
-	            	if(main.getCreateModus().equals(CreateModus.CREATE_UNDIRECTED_EDGE))
-	            		main.setCreateModus(CreateModus.CREATE_NONE);
-	            	else
-	            		main.setCreateModus(CreateModus.CREATE_UNDIRECTED_EDGE);
-	            }
-	        }
-			
+
+				if (rowString.equals("Standard")) {
+					if (main.getCreationMode().equals(CreationMode.CREATE_STANDARD_NODE))
+						main.setCreationMode(CreationMode.CREATE_NONE);
+					else
+						main.setCreationMode(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);
+
+				} 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);
+
+				} 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);
+
+				} 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);
+
+				} 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);
+				}
+			}
+
 		}
-		
+
 	};
 
 	private static Pair<Object, String> pair(Object picture, String name) {

+ 0 - 267
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/Visualizer.java

@@ -1,267 +0,0 @@
-package de.tu_darmstadt.informatik.tk.scopviz.ui;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-
-import org.graphstream.graph.Edge;
-import org.graphstream.graph.Graph;
-import org.graphstream.graph.Node;
-import org.graphstream.ui.swingViewer.ViewPanel;
-import org.graphstream.ui.view.Viewer;
-import org.graphstream.ui.view.ViewerPipe;
-
-import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyViewerListener;
-
-/**
- * Interface between GUI and internal Graph representation. Manages internal
- * representation of the Graph to accommodate creation and deletion of nodes and
- * edges.
- * 
- * @author Jascha Bohne
- * @version 3.0.0.0
- *
- */
-// TODO remove sysout in deleteNode and undelete
-public class Visualizer {
-	// The graph of this Visualizer
-	private Graph g;
-
-	// last deleted elements for undelete
-	private Node deletedNode;
-	private LinkedList<Edge> deletedEdges = new LinkedList<>();
-
-	// Currently selected Edge or Node at least on of these is always null
-	private String selectedNodeID = null;
-	// TODO figure out how to do this
-	private String selectedEdgeID = null;
-
-	// View Panel of the Graph
-	private ViewPanel view;
-
-	// The location the graph will be saved to
-	private String currentPath;
-
-	private Viewer viewer;
-	private ViewerPipe fromViewer;
-
-	/**
-	 * Creates a new visualizer for the given graph.
-	 * 
-	 * @param graph
-	 *            the graph this visualizer should handle
-	 */
-	public Visualizer(Graph graph) {
-		g = graph;
-		/* Viewer */ viewer = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
-		view = viewer.addDefaultView(false);
-		viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.EXIT);
-		/* ViewerPipe */fromViewer = viewer.newViewerPipe();
-		fromViewer.addViewerListener(new MyViewerListener(this));
-		fromViewer.addSink(graph);
-		fromViewer.removeElementSink(graph);
-	}
-
-	/**
-	 * Deletes the Node corresponding to the given ID from the Graph. The
-	 * referenced Graph is modified directly. Will throw an
-	 * ElementNotFoundException, when the Node is not Found Will also remove all
-	 * Edges connected to the given Node
-	 * 
-	 * @param g
-	 *            the Graph with the Node that shall be removed
-	 * @param id
-	 *            the ID of the node that will be removed
-	 */
-	public void deleteNode(final String id) {
-		deletedEdges.removeAll(deletedEdges);
-		deletedNode = null;
-		// Edges have to be deleted first because they clear deletedNode
-		// and need the Node to still be in the Graph
-		deleteEdgesOfNode(id);
-		deletedNode = g.removeNode(id);
-		// System.out.println("test-del");
-	}
-
-	/**
-	 * Deletes the Edge corresponding to the given ID from the Graph. The
-	 * referenced Graph is modified directly. Will throw an
-	 * ElementNotFoundException, when the Edge is not Found
-	 * 
-	 * @param g
-	 *            the Graph with the Edge that shall be removed
-	 * @param id
-	 *            the ID of the Edge that will be removed
-	 */
-	public void deleteEdge(final String id) {
-		deletedEdges.removeAll(deletedEdges);
-		deletedNode = null;
-		deletedEdges.add(g.removeEdge(id));
-	}
-
-	/**
-	 * Deletes all Edges connected to the given Node. The referenced Graph is
-	 * modified directly. Will throw an ElementNotFoundException if the Node is
-	 * not Found
-	 * 
-	 * @param g
-	 *            the Graph containing the Node
-	 * @param id
-	 *            the Id of the Node, whose Edges shall be removed
-	 */
-	public void deleteEdgesOfNode(final String id) {
-		Node node = g.getNode(id);
-		deletedEdges.removeAll(deletedEdges);
-		deletedNode = null;
-		Edge[] temp = new Edge[0];
-		temp = g.getEdgeSet().toArray(temp);
-
-		for (Edge e : temp) {
-			if (e.getSourceNode().equals(node) || e.getTargetNode().equals(node)) {
-				// adds the Edge to the list of deleted Edges and remove sit
-				// from the Graph
-				deletedEdges.add(g.removeEdge(e));
-			}
-		}
-	}
-
-	// TODO make undelete Graph specific
-	/**
-	 * Undoes the last deleting operation on the given Graph. Deleting
-	 * operations are: deleteNode, deleteEdge and deleteEdgesOfNode. Only undoes
-	 * the last deleting operation even if that operation didn't change the
-	 * Graph
-	 * 
-	 * @param g
-	 *            the Graph, whose Elements shall be undeleted
-	 */
-	public void undelete() {
-		// System.out.println("test-undel");
-		HashMap<String, Object> attributes = new HashMap<String, Object>();
-		if (deletedNode != null) {
-			for (String s : deletedNode.getAttributeKeySet()) {
-				attributes.put(s, deletedNode.getAttribute(s));
-			}
-			g.addNode(deletedNode.getId());
-			g.getNode(deletedNode.getId()).addAttributes(attributes);
-		}
-
-		for (Edge e : deletedEdges) {
-			attributes = new HashMap<String, Object>();
-			for (String s : e.getAttributeKeySet()) {
-				attributes.put(s, e.getAttribute(s));
-			}
-			g.addEdge(e.getId(), (Node) e.getSourceNode(), (Node) e.getTargetNode());
-			g.getEdge(e.getId()).addAttributes(attributes);
-		}
-	}
-
-	/**
-	 * returns a View of the Graph. The View is in the Swing Thread and the
-	 * Graph in the Main thread.
-	 * 
-	 * 
-	 * @return a View of the Graph, inheriting from JPanel
-	 */
-	public ViewPanel getView() {
-		return view;
-	}
-
-	/**
-	 * Returns the ID of the currently selected Node.
-	 * 
-	 * @return the node's ID
-	 */
-	public String getSelectedNodeID() {
-		return selectedNodeID;
-	}
-
-	/**
-	 * Sets the ID for the currently selected node, effectively selecting the
-	 * node with that ID.
-	 * 
-	 * @param selectedNodeID
-	 *            the ID of the node to select
-	 */
-	public void setSelectedNodeID(String selectedNodeID) {
-		this.selectedNodeID = selectedNodeID;
-	}
-
-	/**
-	 * Returns the ID of the currently selected Edge.
-	 * 
-	 * @return the edge's ID
-	 */
-	public String getSelectedEdgeID() {
-		return selectedEdgeID;
-	}
-
-	/**
-	 * Sets the ID for the currently selected edge, effectively selecting the
-	 * edge with that ID.
-	 * 
-	 * @param selectedEdgeID
-	 *            the ID of the edge to select
-	 */
-	public void setSelectedEdgeID(String selectedEdgeID) {
-		this.selectedEdgeID = selectedEdgeID;
-	}
-
-	/**
-	 * Deselect any currently selected nodes or edges.
-	 */
-	public void deselect() {
-		this.selectedNodeID = null;
-		this.selectedEdgeID = null;
-	}
-
-	/**
-	 * Returns a reference to the Graph object managed by this visualizer.
-	 * 
-	 * @return the graph
-	 */
-	public Graph getGraph() {
-		return g;
-	}
-
-	/**
-	 * Zooms in the view of the graph by 5 percent.
-	 */
-	public void zoomIn() {
-		view.getCamera().setViewPercent(view.getCamera().getViewPercent() * 0.95);
-	}
-
-	/**
-	 * Zooms out the view of the graph by 5 percent.
-	 */
-	public void zoomOut() {
-		view.getCamera().setViewPercent(view.getCamera().getViewPercent() * 1.05);
-	}
-
-	public ViewerPipe getFromViewer() {
-		return fromViewer;
-	}
-
-	public void pumpIt() {
-		fromViewer.pump();
-	}
-
-	@Override
-	public String toString() {
-		return "Visualizer for Graph \"" + g.getId() + "\"";
-	}
-
-	/**
-	 * @return the currentPath
-	 */
-	public String getCurrentPath() {
-		return currentPath;
-	}
-
-	/**
-	 * @param currentPath
-	 *            the currentPath to set
-	 */
-	public void setCurrentPath(String currentPath) {
-		this.currentPath = currentPath;
-	}
-}

+ 2 - 5
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/MyAnimationTimer.java

@@ -9,11 +9,8 @@ public class MyAnimationTimer extends AnimationTimer {
 
 	@Override
 	public void handle(long now) {
-		if(Main.getInstance().getVisualizer() != null){
-			Main.getInstance().getVisualizer().pumpIt();
+		if (Main.getInstance().getGraphManager() != null) {
+			Main.getInstance().getGraphManager().pumpIt();
 		}
-		// TODO: For Demo purposes only
-
 	}
-
 }

+ 34 - 49
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/MyViewerListener.java

@@ -4,10 +4,10 @@ import org.graphstream.graph.Edge;
 import org.graphstream.ui.view.ViewerListener;
 
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
-import de.tu_darmstadt.informatik.tk.scopviz.main.CreateModus;
+import de.tu_darmstadt.informatik.tk.scopviz.main.CreationMode;
+import de.tu_darmstadt.informatik.tk.scopviz.main.GraphManager;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.PropertiesManager;
-import de.tu_darmstadt.informatik.tk.scopviz.ui.Visualizer;
 
 /**
  * Listener to react to changes in the graph viewer.
@@ -17,16 +17,16 @@ import de.tu_darmstadt.informatik.tk.scopviz.ui.Visualizer;
  *
  */
 public class MyViewerListener implements ViewerListener {
-	
+
 	/**
 	 * Create more then one Edge at a time mode
 	 */
-	public static final Boolean CREATE_MORE_THEN_ONE = true; 
+	public static final Boolean CREATE_MORE_THEN_ONE = true;
 
 	/**
 	 * Reference to the visualizer for easier access.
 	 */
-	private Visualizer visualizer;
+	private GraphManager graphManager;
 
 	private String lastClickedID;
 
@@ -36,8 +36,8 @@ public class MyViewerListener implements ViewerListener {
 	 * @param viz
 	 *            the visualizer that manages the view this listener listens to
 	 */
-	public MyViewerListener(Visualizer viz) {
-		visualizer = viz;
+	public MyViewerListener(GraphManager viz) {
+		graphManager = viz;
 	}
 
 	/**
@@ -48,102 +48,87 @@ public class MyViewerListener implements ViewerListener {
 	 */
 	@Override
 	public void buttonPushed(String id) {
-		if(Main.getInstance().getCreateModus() != CreateModus.CREATE_NONE){
+		if (Main.getInstance().getCreationMode() != CreationMode.CREATE_NONE) {
 			createEdges(id);
 			return;
 		}
 		switch (Main.getInstance().getSelectModus()) {
 		case SELECT_NODES:
-			visualizer.setSelectedNodeID(id);
-			visualizer.setSelectedEdgeID(null);
+			graphManager.setSelectedNodeID(id);
+			graphManager.setSelectedEdgeID(null);
 			break;
 		case SELECT_EDGES:
 			if (lastClickedID == null) {
 				lastClickedID = id;
 			} else {
-				Edge e = visualizer.getGraph().getNode(lastClickedID).getEdgeToward(id);
+				Edge e = graphManager.getGraph().getNode(lastClickedID).getEdgeToward(id);
 				if (e != null) {
-					visualizer.setSelectedEdgeID(e.getId());
-					visualizer.setSelectedNodeID(null);
+					graphManager.setSelectedEdgeID(e.getId());
+					graphManager.setSelectedNodeID(null);
 					lastClickedID = null;
 				} else {
 					lastClickedID = id;
 				}
 			}
 			break;
-/*		case CREATE_EDGE:
-			if (lastClickedID == null) {
-				lastClickedID = id;
-			} else {
-				if (!id.equals(lastClickedID)) {
-					String newID = Main.getInstance().getUnusedID();
-					visualizer.getGraph().addEdge(newID, lastClickedID, id);
-
-					Debug.out("Created an edge with Id " + newID + " between " + lastClickedID + " and " + id);
-
-					lastClickedID = null;
-					visualizer.setSelectedNodeID(null);
-					visualizer.setSelectedEdgeID(newID);
-				}
-			}
-			break;*/
 		default:
 			break;
 		}
 		PropertiesManager.setItemsProperties();
 	}
-	
-	
+
 	/**
 	 * Create Edges based on CreateMode
+	 * 
 	 * @param id
 	 */
-	private void createEdges(String id){
-		
-		switch(Main.getInstance().getCreateModus()){
-		
+	private void createEdges(String id) {
+
+		switch (Main.getInstance().getCreationMode()) {
+
 		case CREATE_DIRECTED_EDGE:
-			
+
 			if (lastClickedID == null) {
 				lastClickedID = id;
 			} else {
 				if (!id.equals(lastClickedID)) {
 					String newID = Main.getInstance().getUnusedID();
-					visualizer.getGraph().addEdge(newID, lastClickedID, id, true);
+					graphManager.getGraph().addEdge(newID, lastClickedID, id, true);
 					Debug.out("Created an directed edge with Id " + newID + " between " + lastClickedID + " and " + id);
 
 					lastClickedID = null;
-					visualizer.setSelectedNodeID(null);
-					visualizer.setSelectedEdgeID(newID);
+					graphManager.setSelectedNodeID(null);
+					graphManager.setSelectedEdgeID(newID);
 				}
 			}
 			break;
-			
+
 		case CREATE_UNDIRECTED_EDGE:
 			if (lastClickedID == null) {
 				lastClickedID = id;
 			} else {
 				if (!id.equals(lastClickedID)) {
 					String newID = Main.getInstance().getUnusedID();
-					visualizer.getGraph().addEdge(newID, lastClickedID, id);
+					graphManager.getGraph().addEdge(newID, lastClickedID, id);
 
-					Debug.out("Created an undirected edge with Id " + newID + " between " + lastClickedID + " and " + id);
+					Debug.out(
+							"Created an undirected edge with Id " + newID + " between " + lastClickedID + " and " + id);
 
 					lastClickedID = null;
-					visualizer.setSelectedNodeID(null);
-					visualizer.setSelectedEdgeID(newID);
+					graphManager.setSelectedNodeID(null);
+					graphManager.setSelectedEdgeID(newID);
 				}
 			}
 			break;
-			
+
 		default:
 			break;
 		}
-		
+
 		PropertiesManager.setItemsProperties();
-		
-		if(!CREATE_MORE_THEN_ONE){
-			Main.getInstance().setCreateModus(CreateModus.CREATE_NONE);
+
+		if (!CREATE_MORE_THEN_ONE) {
+			Main.getInstance().setCreationMode(CreationMode.CREATE_NONE);
 		}
 	}
 

+ 2 - 2
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/ResizeListener.java

@@ -42,9 +42,9 @@ public class ResizeListener implements ChangeListener<Number> {
 
 	@Override
 	public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) {
-		Main.getInstance().getVisualizer().getView()
+		Main.getInstance().getGraphManager().getView()
 				.setPreferredSize(new Dimension((int) pane.getWidth() - 5, (int) pane.getHeight() - 5));
-		swingNode.setContent(Main.getInstance().getVisualizer().getView());
+		swingNode.setContent(Main.getInstance().getGraphManager().getView());
 	}
 
 }