Bladeren bron

Implemented different Node and Edge Types in Toolbox

Added functionality to add different Node and Edge Types
dominik 8 jaren geleden
bovenliggende
commit
b1884b8dc2

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

@@ -35,87 +35,6 @@ public class ButtonManager {
 		guiController = guiCon;
 	}
 
-	/**
-	 * Handler for the "Create Node" button.
-	 */
-	public static EventHandler<ActionEvent> createNodeHandler = 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) {
-			switch (Main.getInstance().getCreateModus()) {
-			// end create node mode when the button is clicked while in create
-			// node mode
-			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 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().setCreateModus(CreateModus.CREATE_STANDARD_NODE);
-				Debug.out("Modus set to Create Node");
-				guiController.createNode.setText("Ende");
-				guiController.createEdge.setText("Kante hinzufügen");
-				Main.getInstance().getVisualizer().deselect();
-				break;
-			}
-		}
-	};
-
-	/**
-	 * Handler for the "Create Edge" button.
-	 */
-	public static EventHandler<ActionEvent> createEdgeHandler = 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) {
-			// Deselect any previously selected nodes or edges
-			Main.getInstance().getVisualizer().deselect();
-			switch (Main.getInstance().getCreateModus()) {
-			// end create edge mode when the button is clicked in create edge
-			// mode
-			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 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().setCreateModus(CreateModus.CREATE_UNDIRECTED_EDGE);
-				Debug.out("Modus set to Create Edge");
-				guiController.createEdge.setText("Ende");
-				guiController.createNode.setText("Knoten hinzufügen");
-				break;
-			}
-		}
-	};
 
 	public static EventHandler<ActionEvent> zoomInHandler = new EventHandler<ActionEvent>() {
 		public void handle(ActionEvent evt) {
@@ -147,10 +66,44 @@ public class ButtonManager {
 			CreateModus currentMod = Main.getInstance().getCreateModus();
 			Graph graph = visualizer.getGraph();
 			Point3 cursorPos = visualizer.getView().getCamera().transformPxToGu(event.getX(), event.getY());
-			if (currentMod == CreateModus.CREATE_STANDARD_NODE) {
-				Node n = graph.addNode(Main.getInstance().getUnusedID());
+			
+			Node n;
+			
+			switch(currentMod){
+			
+			case CREATE_STANDARD_NODE: 
+				n = graph.addNode(Main.getInstance().getUnusedID());
 				n.setAttribute("xyz", cursorPos);
 				Debug.out("Added Node at Position (" + cursorPos.x + "/" + cursorPos.y + ")");
+				Main.getInstance().setCreateModus(CreateModus.CREATE_NONE);
+				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 + ")");
+				Main.getInstance().setCreateModus(CreateModus.CREATE_NONE);
+				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 + ")");
+				Main.getInstance().setCreateModus(CreateModus.CREATE_NONE);
+				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 + ")");
+				Main.getInstance().setCreateModus(CreateModus.CREATE_NONE);
+				break;
+				
+			default:
+				break;
 			}
 		}
 	};

+ 28 - 9
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GUIController.java

@@ -5,6 +5,8 @@ import java.util.ResourceBundle;
 
 import javax.swing.JPanel;
 
+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.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.ResizeListener;
@@ -20,6 +22,7 @@ import javafx.scene.control.ScrollPane;
 import javafx.scene.control.MenuItem;
 import javafx.scene.control.TableCell;
 import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableRow;
 import javafx.scene.control.TableView;
 import javafx.scene.control.cell.PropertyValueFactory;
 import javafx.scene.control.cell.TextFieldTableCell;
@@ -49,10 +52,6 @@ public class GUIController implements Initializable {
 	public Button zoomIn;
 	@FXML
 	public Button zoomOut;
-	@FXML
-	public Button createNode;
-	@FXML
-	public Button createEdge;
 	
 	@FXML
 	public Button underlayButton;
@@ -112,9 +111,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 createNode != null : "fx:id=\"createNode\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
-		assert createEdge != null : "fx:id=\"createEdge\" 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'.";
@@ -184,8 +181,6 @@ public class GUIController implements Initializable {
 	 * Sets the Handlers for the create node and create edge buttons.
 	 */
 	private void initializeCreateButtons() {
-		createNode.setOnAction(ButtonManager.createNodeHandler);
-		createEdge.setOnAction(ButtonManager.createEdgeHandler);
 		swingNode.setOnMouseClicked(ButtonManager.clickedHandler);
 	}
 	
@@ -224,6 +219,30 @@ 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(event -> {
+		        if (! row.isEmpty()) {
+		            if(row.getItem().getValue().equals("Standard")){
+		            	Main.getInstance().setCreateModus(CreateModus.CREATE_STANDARD_NODE);
+		            	Debug.out(Main.getInstance().getCreateModus().toString());
+		            }else if(row.getItem().getValue().equals("Source")){
+			            Main.getInstance().setCreateModus(CreateModus.CREATE_SOURCE_NODE);
+		            }else if(row.getItem().getValue().equals("Sink")){
+		            	Main.getInstance().setCreateModus(CreateModus.CREATE_SINK_NODE);
+		            }else if(row.getItem().getValue().equals("EnProc")){
+		            	Main.getInstance().setCreateModus(CreateModus.CREATE_PROC_NODE);
+		            }else if(row.getItem().getValue().equals("Directed")){
+		            	Main.getInstance().setCreateModus(CreateModus.CREATE_DIRECTED_EDGE);
+		            }else if(row.getItem().getValue().equals("Undirected")){
+		            	Main.getInstance().setCreateModus(CreateModus.CREATE_UNDIRECTED_EDGE);
+		            }
+		        }
+		    });
+		    return row ;
+		});
 
 	}
 

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

@@ -36,7 +36,8 @@ 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"));
 

+ 48 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/MyViewerListener.java

@@ -44,6 +44,7 @@ public class MyViewerListener implements ViewerListener {
 	@Override
 	public void buttonPushed(String id) {
 		if(Main.getInstance().getCreateModus() != CreateModus.CREATE_NONE){
+			createEdges(id);
 			return;
 		}
 		switch (Main.getInstance().getSelectModus()) {
@@ -86,6 +87,53 @@ public class MyViewerListener implements ViewerListener {
 		}
 		PropertiesManager.setItemsProperties();
 	}
+	
+	private void createEdges(String id){
+		
+		switch(Main.getInstance().getCreateModus()){
+		
+		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);
+					Debug.out("Created an directed edge with Id " + newID + " between " + lastClickedID + " and " + id);
+
+					lastClickedID = null;
+					visualizer.setSelectedNodeID(null);
+					visualizer.setSelectedEdgeID(newID);
+					
+					Main.getInstance().setCreateModus(CreateModus.CREATE_NONE);
+				}
+			}
+			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);
+
+					Debug.out("Created an undirected edge with Id " + newID + " between " + lastClickedID + " and " + id);
+
+					lastClickedID = null;
+					visualizer.setSelectedNodeID(null);
+					visualizer.setSelectedEdgeID(newID);
+					
+					Main.getInstance().setCreateModus(CreateModus.CREATE_NONE);
+				}
+			}
+			break;
+			
+		default:
+			break;
+		}
+	}
 
 	/**
 	 * Gets called whenever the click on the node is released.

+ 1 - 3
scopviz/src/main/resources/NewBetterCoolerWindowTest.fxml

@@ -63,9 +63,7 @@
                                         <TableColumn fx:id="toolboxStringColumn" editable="false" maxWidth="-1.0" minWidth="90.0" prefWidth="-1.0" sortable="false" />
                                       </columns>
                                     </TableView>
-                                    <Button fx:id="createNode" mnemonicParsing="false" text="Knoten hinzufügen" textAlignment="JUSTIFY" AnchorPane.bottomAnchor="45.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
-                                    <Button fx:id="createEdge" mnemonicParsing="false" text="Kante hinzufügen" textAlignment="JUSTIFY" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
-                                 </children>
+                                </children>
                               </AnchorPane>
                             <AnchorPane>
                                  <children>