瀏覽代碼

Refactored Modus into to two enums

SelectionModus
CreateModus
updated References
Jascha Bohne 8 年之前
父節點
當前提交
7a3c56308e

+ 8 - 2
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/Modus.java → scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/CreateModus.java

@@ -8,6 +8,12 @@ package de.tu_darmstadt.informatik.tk.scopviz.main;
  * @version 1.0
  *
  */
-public enum Modus {
-	NORMAL, CREATE_NODE, CREATE_EDGE, SELECT_EDGE
+public enum CreateModus {
+	CREATE_STANDARD_NODE, 
+	CREATE_SOURCE_NODE, 
+	CREATE_SINK_NODE, 
+	CREATE_PROC_NODE, 
+	CREATE_UNDIRECTED_EDGE, 
+	CREATE_DIRECTED_EDGE,
+	CREATE_NONE
 }

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

@@ -22,10 +22,15 @@ public final class Main {
 	private static Main instance;
 
 	/**
-	 * Current mode of the application for things like creating new Nodes and
+	 * Current mode of the application for creating new Nodes and
 	 * Edges.
 	 */
-	private Modus modus = Modus.NORMAL;
+	private CreateModus createModus = CreateModus.CREATE_NONE;
+	/**
+	 * Current mode of the application for selecting Nodes and
+	 * Edges.
+	 */
+	private SelectionModus selectModus = SelectionModus.SELECT_NODES;
 
 	/**
 	 * the root window of the application
@@ -93,25 +98,6 @@ public final class Main {
 		return GraphManager.getCurrentVisualizer();
 	}
 
-	/**
-	 * Returns the current mode of the app.
-	 * 
-	 * @return the current mode
-	 */
-	public Modus getModus() {
-		return modus;
-	}
-
-	/**
-	 * Sets the mode of the app.
-	 * 
-	 * @param newMod
-	 *            the new Mode to set
-	 */
-	public void setModus(Modus newMod) {
-		modus = newMod;
-	}
-
 	/**
 	 * Returns a unique id for a new node not yet used by the graph.
 	 * 
@@ -146,4 +132,32 @@ public final class Main {
 		this.primaryStage = primaryStage;
 	}
 
+	/**
+	 * @return the createModus
+	 */
+	public CreateModus getCreateModus() {
+		return createModus;
+	}
+
+	/**
+	 * @param createModus the createModus to set
+	 */
+	public void setCreateModus(CreateModus createModus) {
+		this.createModus = createModus;
+	}
+
+	/**
+	 * @return the selectModus
+	 */
+	public SelectionModus getSelectModus() {
+		return selectModus;
+	}
+
+	/**
+	 * @param selectModus the selectModus to set
+	 */
+	public void setSelectModus(SelectionModus selectModus) {
+		this.selectModus = selectModus;
+	}
+
 }

+ 7 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/SelectionModus.java

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

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

@@ -5,8 +5,8 @@ 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.Main;
-import de.tu_darmstadt.informatik.tk.scopviz.main.Modus;
 import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
 import javafx.scene.input.MouseEvent;
@@ -48,25 +48,25 @@ public class ButtonManager {
 		 */
 		@Override
 		public void handle(ActionEvent arg0) {
-			switch (Main.getInstance().getModus()) {
+			switch (Main.getInstance().getCreateModus()) {
 			// end create node mode when the button is clicked while in create
 			// node mode
-			case CREATE_NODE:
-				Main.getInstance().setModus(Modus.NORMAL);
+			case CREATE_STANDARD_NODE:
+				Main.getInstance().setCreateModus(CreateModus.CREATE_NONE);
 				Debug.out("Modus set to Normal");
 				guiController.createNode.setText("Knoten hinzufügen");
 				break;
 			// enter create node mode when the button is clicked while in normal
 			// mode
-			case NORMAL:
-				Main.getInstance().setModus(Modus.CREATE_NODE);
+			case CREATE_NONE:
+				Main.getInstance().setCreateModus(CreateModus.CREATE_STANDARD_NODE);
 				Debug.out("Modus set to Create Node");
 				guiController.createNode.setText("Ende");
 				break;
 			// enter create node mode when button is clicked in any other
 			// situation
 			default:
-				Main.getInstance().setModus(Modus.CREATE_NODE);
+				Main.getInstance().setCreateModus(CreateModus.CREATE_STANDARD_NODE);
 				Debug.out("Modus set to Create Node");
 				guiController.createNode.setText("Ende");
 				guiController.createEdge.setText("Kante hinzufügen");
@@ -91,24 +91,24 @@ public class ButtonManager {
 		public void handle(ActionEvent arg0) {
 			// Deselect any previously selected nodes or edges
 			Main.getInstance().getVisualizer().deselect();
-			switch (Main.getInstance().getModus()) {
+			switch (Main.getInstance().getCreateModus()) {
 			// end create edge mode when the button is clicked in create edge
 			// mode
-			case CREATE_EDGE:
-				Main.getInstance().setModus(Modus.NORMAL);
+			case CREATE_UNDIRECTED_EDGE:
+				Main.getInstance().setCreateModus(CreateModus.CREATE_NONE);
 				Debug.out("Modus set to Normal");
 				guiController.createEdge.setText("Kante hinzufügen");
 				break;
 			// enter create edge mode when button is clicked in normal mode
-			case NORMAL:
-				Main.getInstance().setModus(Modus.CREATE_EDGE);
+			case CREATE_NONE:
+				Main.getInstance().setCreateModus(CreateModus.CREATE_UNDIRECTED_EDGE);
 				Debug.out("Modus set to Create Edge");
 				guiController.createEdge.setText("Ende");
 				break;
 			// enter create edge mode when button is clicked in any other
 			// situation
 			default:
-				Main.getInstance().setModus(Modus.CREATE_EDGE);
+				Main.getInstance().setCreateModus(CreateModus.CREATE_UNDIRECTED_EDGE);
 				Debug.out("Modus set to Create Edge");
 				guiController.createEdge.setText("Ende");
 				guiController.createNode.setText("Knoten hinzufügen");
@@ -144,10 +144,10 @@ public class ButtonManager {
 		@Override
 		public void handle(MouseEvent event) {
 			Visualizer visualizer = Main.getInstance().getVisualizer();
-			Modus currentMod = Main.getInstance().getModus();
+			CreateModus currentMod = Main.getInstance().getCreateModus();
 			Graph graph = visualizer.getGraph();
 			Point3 cursorPos = visualizer.getView().getCamera().transformPxToGu(event.getX(), event.getY());
-			if (currentMod == Modus.CREATE_NODE) {
+			if (currentMod == CreateModus.CREATE_STANDARD_NODE) {
 				Node n = graph.addNode(Main.getInstance().getUnusedID());
 				n.setAttribute("xyz", cursorPos);
 				Debug.out("Added Node at Position (" + cursorPos.x + "/" + cursorPos.y + ")");

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

@@ -3,7 +3,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.Main;
-import de.tu_darmstadt.informatik.tk.scopviz.main.Modus;
+import de.tu_darmstadt.informatik.tk.scopviz.main.SelectionModus;
 import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
 import javafx.scene.control.MenuItem;
@@ -118,10 +118,10 @@ public class ToolbarManager {
 			Visualizer v = Main.getInstance().getVisualizer();
 			if (src.getText().equals("select Edges")) {
 				src.setText("select Nodes");
-				Main.getInstance().setModus(Modus.SELECT_EDGE);
+				Main.getInstance().setSelectModus(SelectionModus.SELECT_EDGES);
 			} else {
 				src.setText("select Edges");
-				Main.getInstance().setModus(Modus.NORMAL);
+				Main.getInstance().setSelectModus(SelectionModus.SELECT_NODES);
 			}
 
 		}

+ 9 - 5
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/MyViewerListener.java

@@ -4,6 +4,7 @@ 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.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.PropertiesManager;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.Visualizer;
@@ -42,12 +43,15 @@ public class MyViewerListener implements ViewerListener {
 	 */
 	@Override
 	public void buttonPushed(String id) {
-		switch (Main.getInstance().getModus()) {
-		case NORMAL:
+		if(Main.getInstance().getCreateModus() != CreateModus.CREATE_NONE){
+			return;
+		}
+		switch (Main.getInstance().getSelectModus()) {
+		case SELECT_NODES:
 			visualizer.setSelectedNodeID(id);
 			visualizer.setSelectedEdgeID(null);
 			break;
-		case SELECT_EDGE:
+		case SELECT_EDGES:
 			if (lastClickedID == null) {
 				lastClickedID = id;
 			} else {
@@ -61,7 +65,7 @@ public class MyViewerListener implements ViewerListener {
 				}
 			}
 			break;
-		case CREATE_EDGE:
+/*		case CREATE_EDGE:
 			if (lastClickedID == null) {
 				lastClickedID = id;
 			} else {
@@ -76,7 +80,7 @@ public class MyViewerListener implements ViewerListener {
 					visualizer.setSelectedEdgeID(newID);
 				}
 			}
-			break;
+			break;*/
 		default:
 			break;
 		}