瀏覽代碼

Merge remote-tracking branch 'origin/Jascha' into dominik

Conflicts:
	scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GUIController.java
	scopviz/src/main/resources/NewBetterCoolerWindowTest.fxml
dominik 8 年之前
父節點
當前提交
2057e857f2

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

@@ -6,6 +6,7 @@ import java.io.IOException;
 import org.graphstream.graph.Graph;
 import org.graphstream.stream.file.FileSinkGraphML;
 
+import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import javafx.stage.FileChooser;
 import javafx.stage.Stage;
 
@@ -49,7 +50,12 @@ public class GraphMLExporter {
 		String fileName;
 		FileChooser fileChooser = new FileChooser();
 		fileChooser.setTitle("Saving graph");
-		fileName = fileChooser.showSaveDialog(stage).getPath();
-		writeGraph(g, fileName);
+		try {
+			fileName = fileChooser.showSaveDialog(stage).getPath();
+			Main.getInstance().getVisualizer().setCurrentPath(fileName);
+			writeGraph(g, fileName);
+		} catch (NullPointerException e) {
+
+		}
 	}
 }

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

@@ -8,6 +8,7 @@ import org.graphstream.graph.implementations.DefaultGraph;
 import org.graphstream.stream.file.FileSource;
 import org.graphstream.stream.file.FileSourceGraphML;
 
+import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import javafx.stage.FileChooser;
 import javafx.stage.Stage;
 
@@ -53,8 +54,13 @@ public class GraphMLImporter {
 	public Graph readGraph(final String id, final Stage stage) {
 		FileChooser fileChooser = new FileChooser();
 		fileChooser.setTitle("open graph");
-		String fileName = fileChooser.showOpenDialog(stage).getPath();
-		return readGraph(id, fileName);
+		try {
+			String fileName = fileChooser.showOpenDialog(stage).getPath();
+			Main.getInstance().getVisualizer().setCurrentPath(fileName);
+			return readGraph(id, fileName);
+		} catch (NullPointerException e) {
+			return null;
+		}
 	}
 
 	/**

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

@@ -2,10 +2,10 @@ package de.tu_darmstadt.informatik.tk.scopviz.main;
 
 import org.graphstream.graph.Node;
 
-import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.Visualizer;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyAnimationTimer;
 import javafx.animation.AnimationTimer;
+import javafx.stage.Stage;
 
 /**
  * Main Class to contain all core functionality. Built as a Singleton, use
@@ -27,6 +27,11 @@ public final class Main {
 	 */
 	private Modus modus = Modus.NORMAL;
 
+	/**
+	 * the root window of the application
+	 */
+	private Stage primaryStage;
+
 	/**
 	 * Private constructor to prevent initialization, facilitates Singleton
 	 * pattern. Loads a Graph from a GraphML file and creates a visualizer to
@@ -126,4 +131,19 @@ public final class Main {
 		// return (new Random().nextInt()+"");
 	}
 
+	/**
+	 * @return the primaryStage
+	 */
+	public Stage getPrimaryStage() {
+		return primaryStage;
+	}
+
+	/**
+	 * @param primaryStage
+	 *            the primaryStage to set
+	 */
+	public void setPrimaryStage(Stage primaryStage) {
+		this.primaryStage = primaryStage;
+	}
+
 }

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

@@ -56,6 +56,7 @@ public class MainApp extends Application {
 	@Override
 	public void start(final Stage stage) {
 		this.primaryStage = stage;
+		Main.getInstance().setPrimaryStage(this.primaryStage);
 		initRootLayout();
 	}
 

+ 1 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ButtonManager.java

@@ -3,6 +3,7 @@ package de.tu_darmstadt.informatik.tk.scopviz.ui;
 import org.graphstream.graph.Graph;
 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.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Modus;

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

@@ -17,6 +17,7 @@ import javafx.scene.control.Button;
 import javafx.scene.control.ListCell;
 import javafx.scene.control.ListView;
 import javafx.scene.control.ScrollPane;
+import javafx.scene.control.MenuItem;
 import javafx.scene.control.TableCell;
 import javafx.scene.control.TableColumn;
 import javafx.scene.control.TableView;
@@ -62,6 +63,22 @@ public class GUIController implements Initializable {
 	@FXML
 	public Button symbolRepButton;
 
+	// The Toolbar Items
+	@FXML
+	public MenuItem open;
+	@FXML
+	public MenuItem save;
+	@FXML
+	public MenuItem saveAs;
+	@FXML
+	public MenuItem quit;
+	@FXML
+	public MenuItem delete;
+	@FXML
+	public MenuItem undelete;
+	@FXML
+	public MenuItem selectMode;
+
 	// The contents of the corresponding ScrollPanes
 	@FXML
 	public TableView<Pair<Object, String>> toolbox;
@@ -103,6 +120,14 @@ public class GUIController implements Initializable {
 		assert mappingButton != null : "fx:id=\"mappingButton\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 		assert symbolRepButton != null : "fx:id=\"symbolRepButton\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 
+		assert open != null : "fx:id=\"open\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
+		assert save != null : "fx:id=\"save\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
+		assert saveAs != null : "fx:id=\"saveAs\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
+		assert quit != null : "fx:id=\"quit\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
+		assert delete != null : "fx:id=\"delete\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
+		assert undelete != null : "fx:id=\"undelete\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
+		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'.";
@@ -126,6 +151,7 @@ public class GUIController implements Initializable {
 		ToolboxManager.initializeItems(toolbox);
 		PropertiesManager.initializeItems(properties);
 		ButtonManager.initialize(this);
+		ToolbarManager.initialize(this);
 		GraphManager.setGuiController(this);
 
 		// Bind all the handlers to their corresponding UI elements
@@ -133,6 +159,17 @@ public class GUIController implements Initializable {
 		initializeCreateButtons();
 		initializeLayerButton();
 		initializeDisplayPane();
+		initializeToolBar();
+	}
+
+	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);
 	}
 
 	/**

+ 130 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ToolbarManager.java

@@ -0,0 +1,130 @@
+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.Main;
+import de.tu_darmstadt.informatik.tk.scopviz.main.Modus;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
+import javafx.scene.control.MenuItem;
+
+public class ToolbarManager {
+
+	/**
+	 * 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 the "open" MenuItem.
+	 */
+	public static EventHandler<ActionEvent> openHandler = new EventHandler<ActionEvent>() {
+
+		/**
+		 * Handle method gets called when the button is pressed.
+		 * 
+		 * @param arg0
+		 *            the event that occurred to the button
+		 */
+		@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());
+		}
+	};
+
+	/**
+	 * Handler for the "save" button.
+	 */
+	public static EventHandler<ActionEvent> saveHandler = new EventHandler<ActionEvent>() {
+
+		/**
+		 * Handle method gets called when the button is pressed.
+		 * 
+		 * @param arg0
+		 *            the event that occurred to the button
+		 */
+		@Override
+		public void handle(ActionEvent arg0) {
+			Visualizer v = Main.getInstance().getVisualizer();
+			if (v.getCurrentPath() != null) {
+				new GraphMLExporter().writeGraph(v.getGraph(), v.getCurrentPath());
+			} else {
+				new GraphMLExporter().writeGraph(v.getGraph(), Main.getInstance().getPrimaryStage());
+			}
+		}
+	};
+
+	public static EventHandler<ActionEvent> saveAsHandler = new EventHandler<ActionEvent>() {
+		public void handle(ActionEvent evt) {
+			Visualizer v = Main.getInstance().getVisualizer();
+			new GraphMLExporter().writeGraph(v.getGraph(), Main.getInstance().getPrimaryStage());
+		}
+	};
+
+	public static EventHandler<ActionEvent> quitHandler = new EventHandler<ActionEvent>() {
+		public void handle(ActionEvent evt) {
+			System.exit(0);
+		}
+	};
+
+	/**
+	 * Handler for the "save" button.
+	 */
+	public static EventHandler<ActionEvent> deleteHandler = new EventHandler<ActionEvent>() {
+
+		/**
+		 * Handle method gets called whenever the menuItem is presser
+		 * 
+		 * @param event
+		 *            the event that occurred to the menuItem
+		 */
+		@Override
+		public void handle(ActionEvent event) {
+			Visualizer v = Main.getInstance().getVisualizer();
+			if (v.getSelectedEdgeID() != null) {
+				v.deleteEdge(v.getSelectedEdgeID());
+			}
+			if (v.getSelectedNodeID() != null) {
+				v.deleteNode(v.getSelectedNodeID());
+			}
+		}
+	};
+
+	public static EventHandler<ActionEvent> undeleteHandler = new EventHandler<ActionEvent>() {
+		public void handle(ActionEvent evt) {
+			Main.getInstance().getVisualizer().undelete();
+		}
+	};
+
+	// TODO split Modus Enum
+	public static EventHandler<ActionEvent> selectModeHandler = new EventHandler<ActionEvent>() {
+		public void handle(ActionEvent evt) {
+			MenuItem src = (MenuItem) evt.getSource();
+			Visualizer v = Main.getInstance().getVisualizer();
+			if (src.getText() == "select Edges") {
+				src.setText("select Nodes");
+				Main.getInstance().setModus(Modus.SELECT_EDGE);
+			} else {
+				src.setText("select Edges");
+				Main.getInstance().setModus(Modus.NORMAL);
+			}
+
+		}
+	};
+
+}

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

@@ -21,6 +21,7 @@ import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyViewerListener;
  * @version 3.0.0.0
  *
  */
+// TODO remove sysout in deleteNode and undelete
 public class Visualizer {
 	// The graph of this Visualizer
 	private Graph g;
@@ -37,6 +38,9 @@ public class Visualizer {
 	// 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;
 
@@ -75,6 +79,7 @@ public class Visualizer {
 		// and need the Node to still be in the Graph
 		deleteEdgesOfNode(id);
 		deletedNode = g.removeNode(id);
+		// System.out.println("test-del");
 	}
 
 	/**
@@ -130,6 +135,7 @@ public class Visualizer {
 	 *            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()) {
@@ -243,4 +249,19 @@ public class Visualizer {
 	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;
+	}
 }

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

@@ -1,6 +1,5 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui.handlers;
 
-import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import javafx.animation.AnimationTimer;
 
@@ -12,14 +11,7 @@ public class MyAnimationTimer extends AnimationTimer {
 	public void handle(long now) {
 		Main.getInstance().getVisualizer().pumpIt();
 		// TODO: For Demo purposes only
-		if (time == -1)
-			time = now;
-		else {
-			if (time + 2000000000 < now) {
-				Main.getInstance().load2ndGraph();
-				time += 2000000000;
-			}
-		}
+
 	}
 
 }

+ 10 - 18
scopviz/src/main/resources/NewBetterCoolerWindowTest.fxml

@@ -20,37 +20,29 @@
       <menus>
         <Menu mnemonicParsing="false" text="File">
           <items>
-            <MenuItem mnemonicParsing="false" text="New" />
-            <MenuItem mnemonicParsing="false" text="Open…" />
-            <Menu mnemonicParsing="false" text="Open Recent" />
+            <MenuItem mnemonicParsing="false" text="New - TODO" />
+            <MenuItem mnemonicParsing="false" text="Open…" fx:id="open"/>
             <SeparatorMenuItem mnemonicParsing="false" />
-            <MenuItem mnemonicParsing="false" text="Close" />
-            <MenuItem mnemonicParsing="false" text="Save" />
-            <MenuItem mnemonicParsing="false" text="Save As…" />
-            <MenuItem mnemonicParsing="false" text="Revert" />
+            <MenuItem mnemonicParsing="false" text="Save" fx:id="save"/>
+            <MenuItem mnemonicParsing="false" text="Save As…" fx:id="saveAs"/>
             <SeparatorMenuItem mnemonicParsing="false" />
-            <MenuItem mnemonicParsing="false" text="Preferences" />
+            <MenuItem mnemonicParsing="false" text="Preferences - TODO" />
             <SeparatorMenuItem mnemonicParsing="false" />
-            <MenuItem mnemonicParsing="false" text="Quit" />
+            <MenuItem mnemonicParsing="false" text="Quit" fx:id="quit"/>
           </items>
         </Menu>
         <Menu mnemonicParsing="false" text="Edit">
           <items>
-            <MenuItem mnemonicParsing="false" text="Undo" />
-            <MenuItem mnemonicParsing="false" text="Redo" />
             <SeparatorMenuItem mnemonicParsing="false" />
-            <MenuItem mnemonicParsing="false" text="Cut" />
-            <MenuItem mnemonicParsing="false" text="Copy" />
-            <MenuItem mnemonicParsing="false" text="Paste" />
-            <MenuItem mnemonicParsing="false" text="Delete" />
+            <MenuItem mnemonicParsing="false" text="Delete" fx:id="delete"/>
+            <MenuItem mnemonicParsing="false" text="Undelete" fx:id="undelete"/>
             <SeparatorMenuItem mnemonicParsing="false" />
-            <MenuItem mnemonicParsing="false" text="Select All" />
-            <MenuItem mnemonicParsing="false" text="Unselect All" />
+            <MenuItem mnemonicParsing="false" text="Select Edges" fx:id="selectMode"/>
           </items>
         </Menu>
         <Menu mnemonicParsing="false" text="Help">
           <items>
-            <MenuItem mnemonicParsing="false" text="About MyHelloApp" />
+            <MenuItem mnemonicParsing="false" text="About MyHelloApp - TODO" />
           </items>
         </Menu>
       </menus>