소스 검색

Updated Toolbox Selection

- the selection of a toolbox element is possible with a dragging move
 - fixed exception, when dragging on the picture part
dominik 8 년 전
부모
커밋
30ffa51345

+ 18 - 16
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GUIController.java

@@ -68,7 +68,7 @@ public class GUIController implements Initializable {
 	public Button zoomOut;
 	@FXML
 	public Button centerMap;
-	
+
 	@FXML
 	public Button defaultMapView;
 	@FXML
@@ -77,8 +77,8 @@ public class GUIController implements Initializable {
 	public Button satelliteMapView;
 	@FXML
 	public Button hybridMapView;
-	
-	@FXML 
+
+	@FXML
 	public Button previousWaypoint;
 	@FXML
 	public Button nextWaypoint;
@@ -217,10 +217,10 @@ public class GUIController implements Initializable {
 		stackPane.widthProperty().addListener(new ResizeListener(swingNode, stackPane));
 
 		swingNodeWorldView.setVisible(false);
-		
+
 		// bind a context menu to the swing node
 		swingNodeWorldView.setOnContextMenuRequested((event) -> MapViewFunctions.contextMenuRequest(event));
-		
+
 	}
 
 	/**
@@ -247,30 +247,29 @@ public class GUIController implements Initializable {
 		zoomIn.setOnAction((event) -> ButtonManager.zoomInAction(event));
 		zoomOut.setOnAction((event) -> ButtonManager.zoomOutAction(event));
 	}
-	
-	
+
 	/**
 	 * Sets the handlers for the Button that are shown in the symbol layer
 	 */
 	private void initializeSymbolLayerButtons() {
-		
+
 		centerMap.setOnAction((event) -> ButtonManager.centerMapAction(event));
-		
+
 		defaultMapView.setOnAction((event) -> ButtonManager.switchToMap("Default"));
 		roadMapView.setOnAction((event) -> ButtonManager.switchToMap("Road"));
 		satelliteMapView.setOnAction((event) -> ButtonManager.switchToMap("Satellite"));
 		hybridMapView.setOnAction((event) -> ButtonManager.switchToMap("Hybrid"));
-		
+
 		previousWaypoint.setOnAction((event) -> MapViewFunctions.switchToPreviousWaypoint());
 		nextWaypoint.setOnAction((event) -> MapViewFunctions.switchToNextWaypoint());
-		
+
 		centerMap.setVisible(false);
-		
+
 		defaultMapView.setVisible(false);
 		roadMapView.setVisible(false);
 		satelliteMapView.setVisible(false);
 		hybridMapView.setVisible(false);
-		
+
 		previousWaypoint.setVisible(false);
 		nextWaypoint.setVisible(false);
 	}
@@ -354,10 +353,13 @@ public class GUIController implements Initializable {
 
 		toolbox.getColumns().setAll(toolboxObjectColumn, toolboxStringColumn);
 
+		toolbox.getSelectionModel().selectedItemProperty()
+				.addListener((ov, oldVal, newVal) -> ToolboxManager.selectedItemChanged(ov, oldVal, newVal));
+
 		// Click event for TableView row
 		toolbox.setRowFactory(tv -> {
 			TableRow<Pair<Object, String>> row = new TableRow<>();
-			row.setOnMouseClicked(ToolboxManager.rowClickedHandler);
+			row.setOnMouseClicked((event) -> ToolboxManager.rowClickedHandler(event));
 			return row;
 		});
 
@@ -442,12 +444,12 @@ public class GUIController implements Initializable {
 		assert zoomIn != null : "fx:id=\"zoomIn\" was not injected: check your FXML file 'MainWindow.fxml'.";
 		assert zoomOut != null : "fx:id=\"zoomOut\" was not injected: check your FXML file 'MainWindow.fxml'.";
 		assert centerMap != null : "fx:id=\"centerMap\" was not injected: check your FXML file 'MainWindow.fxml'.";
-		
+
 		assert defaultMapView != null : "fx:id=\"defaultMapView\" was not injected: check your FXML file 'MainWindow.fxml'.";
 		assert roadMapView != null : "fx:id=\"roadMapView\" was not injected: check your FXML file 'MainWindow.fxml'.";
 		assert satelliteMapView != null : "fx:id=\"satelliteMapView\" was not injected: check your FXML file 'MainWindow.fxml'.";
 		assert hybridMapView != null : "fx:id=\"hybridMapView\" was not injected: check your FXML file 'MainWindow.fxml'.";
-		
+
 		assert previousWaypoint != null : "fx:id=\"previousWaypoint\" was not injected: check your FXML file 'MainWindow.fxml'.";
 		assert nextWaypoint != null : "fx:id=\"nextWaypoint\" was not injected: check your FXML file 'MainWindow.fxml'.";
 

+ 87 - 40
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ToolboxManager.java

@@ -7,7 +7,6 @@ import javafx.beans.property.ReadOnlyObjectWrapper;
 import javafx.beans.value.ObservableValue;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
-import javafx.event.EventHandler;
 import javafx.scene.Node;
 import javafx.scene.control.CheckBox;
 import javafx.scene.control.TableCell;
@@ -33,6 +32,12 @@ public final class ToolboxManager {
 	 */
 	private static GUIController controller;
 
+	/**
+	 * needed, so that MouseClickedEvent is not fired, when SelectionProperty
+	 * was changed
+	 */
+	private static boolean selectedPropertyChanged = false;
+
 	/**
 	 * private constructor to prevent Instantiation.
 	 */
@@ -101,60 +106,99 @@ public final class ToolboxManager {
 	}
 
 	/**
-	 * Handler for TableRows
+	 * fired when the selected item in the Toolbox was changed
+	 * 
+	 * @param ov
+	 * @param oldVal
+	 *            the previous selected item
+	 * @param newVal
+	 *            the new selected item
 	 */
-	public static final EventHandler<MouseEvent> rowClickedHandler = new EventHandler<MouseEvent>() {
+	public static void selectedItemChanged(ObservableValue<? extends Pair<Object, String>> ov,
+			Pair<Object, String> oldVal, Pair<Object, String> newVal) {
 
-		@SuppressWarnings("unchecked")
-		@Override
-		public void handle(MouseEvent event) {
+		if (newVal != null) {
 
-			// Get the clicked TableRow
-			Node node = ((Node) event.getTarget()).getParent();
-			TableRow<Pair<Object, String>> row;
+			// change creation mode based on selected item
+			String rowString = newVal.getValue();
 
-			if (node instanceof TableRow) {
-				row = (TableRow<Pair<Object, String>>) node;
-			} else {
-				// clicking on text part
-				row = (TableRow<Pair<Object, String>>) node.getParent();
-			}
+			if (rowString.equals("Standard")) {
+				changeCreationMode(CreationMode.CREATE_STANDARD_NODE);
 
-			// Set CreateModus based on pressed TableRow
-			if (!row.isEmpty()) {
+			} else if (rowString.equals("Source")) {
+				changeCreationMode(CreationMode.CREATE_SOURCE_NODE);
 
-				String rowString = row.getItem().getValue();
+			} else if (rowString.equals("Sink")) {
+				changeCreationMode(CreationMode.CREATE_SINK_NODE);
 
-				if (rowString.equals("Standard")) {
-					changeCreationMode(CreationMode.CREATE_STANDARD_NODE);
+			} else if (rowString.equals("EnProc")) {
+				changeCreationMode(CreationMode.CREATE_PROC_NODE);
 
-				} else if (rowString.equals("Source")) {
-					changeCreationMode(CreationMode.CREATE_SOURCE_NODE);
+			} else if (rowString.equals("operator")) {
+				changeCreationMode(CreationMode.CREATE_OPERATOR_NODE);
 
-				} else if (rowString.equals("Sink")) {
-					changeCreationMode(CreationMode.CREATE_SINK_NODE);
+			} else if (rowString.equals("Directed")) {
+				changeCreationMode(CreationMode.CREATE_DIRECTED_EDGE);
 
-				} else if (rowString.equals("EnProc")) {
-					changeCreationMode(CreationMode.CREATE_PROC_NODE);
+			} else if (rowString.equals("Undirected")) {
+				changeCreationMode(CreationMode.CREATE_UNDIRECTED_EDGE);
+			}
 
-				} else if (rowString.equals("operator")) {
-					changeCreationMode(CreationMode.CREATE_OPERATOR_NODE);
+		} else {
+			// selected item was an empty row
+			Main.getInstance().setCreationMode(CreationMode.CREATE_NONE);
+		}
 
-				} else if (rowString.equals("Directed")) {
-					changeCreationMode(CreationMode.CREATE_DIRECTED_EDGE);
+		// Unselecet Rows if Creation Mode is None
+		if (Main.getInstance().getCreationMode().equals(CreationMode.CREATE_NONE)) {
+			controller.toolbox.getSelectionModel().clearSelection();
+		}
 
-				} else if (rowString.equals("Undirected")) {
-					changeCreationMode(CreationMode.CREATE_UNDIRECTED_EDGE);
-				}
+		// set this property to true, so the MouseClickedHandler doesn't also
+		// fire its event
+		selectedPropertyChanged = true;
 
-				// Unselecet Rows if Creation Mode is None
-				if (Main.getInstance().getCreationMode().equals(CreationMode.CREATE_NONE)) {
-					controller.toolbox.getSelectionModel().clearSelection();
-				}
+	}
+
+	/**
+	 * fired when a row was clicked
+	 * 
+	 * @param event
+	 */
+	@SuppressWarnings("unchecked")
+	public static void rowClickedHandler(MouseEvent event) {
+
+		// only use the handler when the selectionProperty Listener didn't fire
+		// its event
+		if (selectedPropertyChanged) {
+			selectedPropertyChanged = false;
+			return;
+		}
+
+		// Get the clicked TableRow
+		Node node = ((Node) event.getTarget()).getParent();
+		TableRow<Pair<Object, String>> row = null;
+
+		if (node instanceof TableRow) {
+			row = (TableRow<Pair<Object, String>>) node;
+		} else {
+			// clicking on picture part
+			try {
+				row = (TableRow<Pair<Object, String>>) node.getParent();
+
+			} catch (ClassCastException e) {
+				// there was a dragging move one the picture part when this
+				// exception is thrown -> cant get row from this action
+				return;
 			}
 		}
 
-	};
+		// clear selection if selected row was clicked again
+		if (row.isEmpty()
+				|| controller.toolbox.getSelectionModel().selectedItemProperty().get().equals(row.getItem())) {
+			controller.toolbox.getSelectionModel().clearSelection();
+		}
+	}
 
 	/**
 	 * If currentMode already selected then deselect, otherwise set mode on
@@ -172,6 +216,7 @@ public final class ToolboxManager {
 
 	/**
 	 * create a pair object under given picture and name
+	 * 
 	 * @param picture
 	 * @param name
 	 * @return
@@ -208,8 +253,9 @@ public final class ToolboxManager {
 	}
 
 	/**
-	 * The actual TableCell, that renders the images of nodes and edges. (Image, String)-Cell
-	 * additional support for (String, String), (Integer, String), (Boolean, String), ("N/A", String) table cells
+	 * The actual TableCell, that renders the images of nodes and edges. (Image,
+	 * String)-Cell additional support for (String, String), (Integer, String),
+	 * (Boolean, String), ("N/A", String) table cells
 	 *
 	 */
 	public static class PairValueCell extends TableCell<Pair<Object, String>, Object> {
@@ -246,4 +292,5 @@ public final class ToolboxManager {
 			}
 		}
 	}
+
 }

+ 0 - 3
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/MapViewFunctions.java

@@ -22,7 +22,6 @@ import org.jxmapviewer.viewer.GeoPosition;
 import org.jxmapviewer.viewer.TileFactoryInfo;
 import org.jxmapviewer.viewer.WaypointPainter;
 
-import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.graphs.GraphManager;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
@@ -374,7 +373,6 @@ public final class MapViewFunctions {
 		}else {
 			int index = waypointsAsList.indexOf(selectedWaypoint);
 			
-			Debug.out(index);
 			if(index == 0){
 				CustomMapClickListener.selectWaypoint(waypointsAsList.get(waypointsAsList.size() - 1));
 			}else {
@@ -397,7 +395,6 @@ public final class MapViewFunctions {
 		} else {
 			int index = waypointsAsList.indexOf(selectedWaypoint);
 			
-			Debug.out(index);
 			if(index == waypointsAsList.size() - 1){
 				CustomMapClickListener.selectWaypoint(waypointsAsList.get(0));
 			}else {