浏览代码

Implemented layer funcionality
It is possible to switch between the layers and open graphs in them.

Enum Layer
All our different layers

GetVisualizer and switchActiveGraph now uses currentLayer instead of
ID/currentViz

Julian Ohl 8 年之前
父节点
当前提交
14c0497e9d

+ 46 - 5
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/GraphManager.java

@@ -5,11 +5,13 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.ArrayList;
 
 
 import org.graphstream.graph.Graph;
 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.io.GraphMLImporter;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.GUIController;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.GUIController;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.Visualizer;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.Visualizer;
 import javafx.scene.layout.Pane;
 import javafx.scene.layout.Pane;
+import javafx.stage.Stage;
 
 
 /**
 /**
  * This class holds all Visualizers, provides Functions to add Graphs and get
  * This class holds all Visualizers, provides Functions to add Graphs and get
@@ -25,6 +27,8 @@ public class GraphManager {
 	private static int count = 0;
 	private static int count = 0;
 	private static GUIController guiController;
 	private static GUIController guiController;
 	private static int currentVisualizer = 0;
 	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) {
 	public static void setGuiController(GUIController guiController) {
 		GraphManager.guiController = guiController;
 		GraphManager.guiController = guiController;
@@ -54,11 +58,30 @@ public class GraphManager {
 		String id = getGraphStringID(count);
 		String id = getGraphStringID(count);
 		GraphMLImporter importer = new GraphMLImporter();
 		GraphMLImporter importer = new GraphMLImporter();
 		Graph g = importer.readGraph(id, Main.class.getResource(fileName));
 		Graph g = importer.readGraph(id, Main.class.getResource(fileName));
+		g.addAttribute("layer", currentLayer);
 		Visualizer v = new Visualizer(g);
 		Visualizer v = new Visualizer(g);
 		vList.add(v);
 		vList.add(v);
 		return count++;
 		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.
 	 * Imports and adds the specified Graph to the collection.
 	 * 
 	 * 
@@ -70,6 +93,7 @@ public class GraphManager {
 		String id = getGraphStringID(count);
 		String id = getGraphStringID(count);
 		GraphMLImporter importer = new GraphMLImporter();
 		GraphMLImporter importer = new GraphMLImporter();
 		Graph g = importer.readGraph(id, fileURL);
 		Graph g = importer.readGraph(id, fileURL);
+		g.addAttribute("layer", currentLayer);
 		Visualizer v = new Visualizer(g);
 		Visualizer v = new Visualizer(g);
 		vList.add(v);
 		vList.add(v);
 		return ++count;
 		return ++count;
@@ -82,9 +106,9 @@ public class GraphManager {
 	 *            of the graph
 	 *            of the graph
 	 * @return visualizer for the graph
 	 * @return visualizer for the graph
 	 */
 	 */
-	public static Visualizer getVisualizer(int id) {
-		return vList.get(id);
-	}
+	/*
+	 * public static Visualizer getVisualizer(int id) { return vList.get(id); }
+	 */
 
 
 	private static String getGraphStringID(int id) {
 	private static String getGraphStringID(int id) {
 		return GRAPH_STRING_ID_PREFIX + id;
 		return GRAPH_STRING_ID_PREFIX + id;
@@ -96,8 +120,8 @@ public class GraphManager {
 	 * @param id
 	 * @param id
 	 *            of the graph which to switch to
 	 *            of the graph which to switch to
 	 */
 	 */
-	public static void switchActiveGraph(int id) {
-		currentVisualizer = id;
+
+	public static void switchActiveGraph() {
 		// TODO Clean up, is copied out the ResizeListener and should be handled
 		// TODO Clean up, is copied out the ResizeListener and should be handled
 		// somewhere else
 		// somewhere else
 		Pane pane = guiController.pane;
 		Pane pane = guiController.pane;
@@ -116,4 +140,21 @@ public class GraphManager {
 	public static Visualizer getCurrentVisualizer() {
 	public static Visualizer getCurrentVisualizer() {
 		return vList.get(currentVisualizer);
 		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;
+	}
 }
 }

+ 5 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/Layer.java

@@ -0,0 +1,5 @@
+package de.tu_darmstadt.informatik.tk.scopviz.main;
+
+public enum Layer {
+	UNDERLAY, OPERATOR, MAPPING, SYMBOL
+}

+ 6 - 22
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/Main.java

@@ -38,32 +38,16 @@ public final class Main {
 	 * manage it
 	 * manage it
 	 */
 	 */
 	private Main() {
 	private Main() {
-		int gID = GraphManager.addGraph("/Example.graphml");
-		GraphManager.addGraph("/Example.graphml");
 		/*
 		/*
-		 * GraphMLImporter importer = new GraphMLImporter(); graph =
-		 * importer.readGraph("g", Main.class.getResource("/Example.graphml"));
-		 * Node n = graph.addNode("upps"); n.setAttribute("x", 150);
-		 * n.setAttribute("y", 150); visualizer = new Visualizer(graph);
-		 */
-		Node n = GraphManager.getVisualizer(gID).getGraph().addNode("upps");
-		n.setAttribute("x", 150);
-		n.setAttribute("y", 150);
+		GraphManager.addGraph("/Example.graphml");
+		GraphManager.setCurrentLayer(Layer.OPERATOR);
+		GraphManager.addGraph("/Example2.graphml");
+		*/
+		
 		AnimationTimer alwaysPump = new MyAnimationTimer();
 		AnimationTimer alwaysPump = new MyAnimationTimer();
 		alwaysPump.start();
 		alwaysPump.start();
 	}
 	}
 
 
-	private int iid = 0;
-
-	// TODO: for Demo Purposes only
-	public void load2ndGraph() {
-		if (iid == 0)
-			iid = 1;
-		else
-			iid = 0;
-		GraphManager.switchActiveGraph(iid);
-	}
-
 	/**
 	/**
 	 * Returns the singular instance of the Class, grants access to the
 	 * Returns the singular instance of the Class, grants access to the
 	 * Singleton. Initializes the instance when called for the first time.
 	 * Singleton. Initializes the instance when called for the first time.
@@ -90,7 +74,7 @@ public final class Main {
 	 * @return the visualizer in use
 	 * @return the visualizer in use
 	 */
 	 */
 	public Visualizer getVisualizer() {
 	public Visualizer getVisualizer() {
-		return GraphManager.getCurrentVisualizer();
+		return GraphManager.getVisualizer();
 	}
 	}
 
 
 	/**
 	/**

+ 10 - 8
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ButtonManager.java

@@ -5,6 +5,8 @@ import org.graphstream.graph.Node;
 import org.graphstream.ui.geom.Point3;
 import org.graphstream.ui.geom.Point3;
 
 
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
+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.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Modus;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Modus;
 import javafx.event.ActionEvent;
 import javafx.event.ActionEvent;
@@ -162,8 +164,8 @@ public class ButtonManager {
 
 
 		@Override
 		@Override
 		public void handle(ActionEvent arg0) {
 		public void handle(ActionEvent arg0) {
-			// TODO Auto-generated method stub
-			
+			GraphManager.setCurrentLayer(Layer.UNDERLAY);
+			GraphManager.switchActiveGraph();
 		}
 		}
 		
 		
 		
 		
@@ -173,8 +175,8 @@ public class ButtonManager {
 
 
 		@Override
 		@Override
 		public void handle(ActionEvent arg0) {
 		public void handle(ActionEvent arg0) {
-			// TODO Auto-generated method stub
-			
+			GraphManager.setCurrentLayer(Layer.OPERATOR);
+			GraphManager.switchActiveGraph();
 		}
 		}
 		
 		
 		
 		
@@ -184,8 +186,8 @@ public class ButtonManager {
 
 
 		@Override
 		@Override
 		public void handle(ActionEvent arg0) {
 		public void handle(ActionEvent arg0) {
-			// TODO Auto-generated method stub
-			
+			GraphManager.setCurrentLayer(Layer.MAPPING);
+			GraphManager.switchActiveGraph();
 		}
 		}
 			
 			
 			
 			
@@ -195,8 +197,8 @@ public class ButtonManager {
 
 
 		@Override
 		@Override
 		public void handle(ActionEvent arg0) {
 		public void handle(ActionEvent arg0) {
-			// TODO Auto-generated method stub
-			
+			GraphManager.setCurrentLayer(Layer.SYMBOL);
+			GraphManager.switchActiveGraph();
 		}
 		}
 			
 			
 			
 			

+ 0 - 25
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/MenuBarManager.java

@@ -1,25 +0,0 @@
-package de.tu_darmstadt.informatik.tk.scopviz.ui;
-
-import javafx.event.ActionEvent;
-import javafx.event.EventHandler;
-
-public class MenuBarManager {
-	
-	// Handler for NewFile MenuItem
-	public static EventHandler<ActionEvent> newFileHandler = new EventHandler<ActionEvent>() {
-		
-		@Override
-        public void handle(ActionEvent t) {
-			
-        }
-	};
-	
-	// Handler for OpenFile MenuItem
-	public static EventHandler<ActionEvent> openFileHandler = new EventHandler<ActionEvent>() {
-		
-		@Override
-        public void handle(ActionEvent t) {
-	
-        }
-	};
-}

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

@@ -2,6 +2,7 @@ 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.GraphMLExporter;
 import de.tu_darmstadt.informatik.tk.scopviz.io.GraphMLImporter;
 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.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Modus;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Modus;
 import javafx.event.ActionEvent;
 import javafx.event.ActionEvent;
@@ -39,11 +40,7 @@ public class ToolbarManager {
 		@Override
 		@Override
 		public void handle(ActionEvent arg0) {
 		public void handle(ActionEvent arg0) {
 			Visualizer v = Main.getInstance().getVisualizer();
 			Visualizer v = Main.getInstance().getVisualizer();
-			if (v == null) {
-				// TDOD figure out where the new Graph has to go
-			}
-			// TODO figure out where to get a good new ID
-			new GraphMLImporter().readGraph("getABetterID", Main.getInstance().getPrimaryStage());
+			GraphManager.addGraph(Main.getInstance().getPrimaryStage());
 		}
 		}
 	};
 	};
 
 

+ 3 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/MyAnimationTimer.java

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

+ 38 - 0
scopviz/src/main/resources/Example2.graphml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
+	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	 xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
+	   http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
+	<key id="attr0000" for="node" attr.name="Eigenschaft" attr.type="string"/>
+	<key id="attr0001" for="node" attr.name="ui.label" attr.type="string"/>
+	<key id="attr0002" for="node" attr.name="y" attr.type="double"/>
+	<key id="attr0003" for="node" attr.name="x" attr.type="double"/>
+	<graph id="Example" edgedefault="undirected">
+		<node id="A">
+			<data key="attr0000">test</data>
+			<data key="attr0001">A</data>
+			<data key="attr0002">100</data>
+			<data key="attr0003">100</data>
+		</node>
+		<node id="B">
+			<data key="attr0001">B</data>
+			<data key="attr0002">200</data>
+			<data key="attr0003">100</data>
+		</node>
+		<node id="C">
+			<data key="attr0001">C</data>
+			<data key="attr0002">100</data>
+			<data key="attr0003">200</data>
+		</node>
+		<node id="D">
+			<data key="attr0001">D</data>
+			<data key="attr0002">200</data>
+			<data key="attr0003">200</data>
+		</node>
+		<node id="E">
+			<data key="attr0001">E</data>
+			<data key="attr0002">185</data>
+			<data key="attr0003">135</data>
+		</node>
+	</graph>
+</graphml>