Browse Source

Merge remote-tracking branch 'origin/Julian'

Conflicts:
	scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ButtonManager.java
dominik 8 năm trước cách đây
mục cha
commit
fca8293304

+ 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 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
@@ -25,6 +27,8 @@ public class GraphManager {
 	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;
@@ -54,11 +58,30 @@ public class GraphManager {
 		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.
 	 * 
@@ -70,6 +93,7 @@ public class GraphManager {
 		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;
@@ -82,9 +106,9 @@ public class GraphManager {
 	 *            of 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) {
 		return GRAPH_STRING_ID_PREFIX + id;
@@ -96,8 +120,8 @@ public class GraphManager {
 	 * @param id
 	 *            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
 		// somewhere else
 		Pane pane = guiController.pane;
@@ -116,4 +140,21 @@ public class GraphManager {
 	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;
+	}
 }

+ 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

@@ -43,32 +43,16 @@ public final class Main {
 	 * manage it
 	 */
 	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();
 		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
 	 * Singleton. Initializes the instance when called for the first time.
@@ -95,7 +79,7 @@ public final class Main {
 	 * @return the visualizer in use
 	 */
 	public Visualizer getVisualizer() {
-		return GraphManager.getCurrentVisualizer();
+		return GraphManager.getVisualizer();
 	}
 
 	/**

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

@@ -6,6 +6,8 @@ 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.GraphManager;
+import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
@@ -25,6 +27,20 @@ public class ButtonManager {
 	 */
 	public static final Boolean CREATE_MORE_THEN_ONE = true; 
 
+	/**
+	 * Reference to the GUIController used by the app for access to UI Elements.
+	 */
+	private static GUIController guiController;
+
+	/**
+	 * Initializes the ButtonManager by getting access to the GUIController.
+	 * 
+	 * @param guiCon
+	 *            a reference to the GUIController used by the App
+	 */
+	public static void initialize(GUIController guiCon) {
+		guiController = guiCon;
+	}
 	/**
 	 * Handler for zoom in Button
 	 */
@@ -116,8 +132,8 @@ public class ButtonManager {
 
 		@Override
 		public void handle(ActionEvent arg0) {
-			// TODO Auto-generated method stub
-			
+			GraphManager.setCurrentLayer(Layer.UNDERLAY);
+			GraphManager.switchActiveGraph();
 		}
 		
 		
@@ -127,8 +143,8 @@ public class ButtonManager {
 
 		@Override
 		public void handle(ActionEvent arg0) {
-			// TODO Auto-generated method stub
-			
+			GraphManager.setCurrentLayer(Layer.OPERATOR);
+			GraphManager.switchActiveGraph();
 		}
 		
 		
@@ -138,8 +154,8 @@ public class ButtonManager {
 
 		@Override
 		public void handle(ActionEvent arg0) {
-			// TODO Auto-generated method stub
-			
+			GraphManager.setCurrentLayer(Layer.MAPPING);
+			GraphManager.switchActiveGraph();
 		}
 			
 			
@@ -149,8 +165,8 @@ public class ButtonManager {
 
 		@Override
 		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.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 javafx.event.ActionEvent;
@@ -25,11 +26,7 @@ public class ToolbarManager {
 		@Override
 		public void handle(ActionEvent arg0) {
 			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
 	public void handle(long now) {
-		Main.getInstance().getVisualizer().pumpIt();
+		if(Main.getInstance().getVisualizer() != null){
+			Main.getInstance().getVisualizer().pumpIt();
+		}
 		// 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>