فهرست منبع

Refactored Code

added lambdas
removed bad code
dominik 8 سال پیش
والد
کامیت
a0cd9b38af

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

@@ -7,10 +7,8 @@ import org.graphstream.graph.Edge;
 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.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
 import javafx.event.ActionEvent;
-import javafx.event.EventHandler;
 import javafx.scene.control.Button;
 
 /**
@@ -48,42 +46,38 @@ public final class ButtonManager {
 		controller = guiController;
 	}
 
-	
 	/**
 	 * Handler for zoom in Button
 	 */
-	public static final void zoomInAction(ActionEvent event){
+	public static final void zoomInAction(ActionEvent event) {
 		Main.getInstance().getGraphManager().zoomIn();
 	}
 
-	
 	/**
 	 * Handler for zoom out Button
 	 */
-	public static final void zoomOutAction(ActionEvent event){
+	public static final void zoomOutAction(ActionEvent event) {
 		Main.getInstance().getGraphManager().zoomOut();
 	}
-	
 
 	/**
 	 * Handler for the Underlay Layer switch Button.
 	 */
-	public static final void underlayAction(ActionEvent arg0){
-		
+	public static final void underlayAction(ActionEvent arg0) {
+
 		switchfromSymbolLayer();
-		
+
 		GraphDisplayManager.setCurrentLayer(Layer.UNDERLAY);
 		GraphDisplayManager.switchActiveGraph();
 
 		setBorderStyle((Button) arg0.getSource());
-		
+
 	}
 
-	
 	/**
 	 * Handler for the Operator Layer switch Button.
 	 */
-	public static final void operatorAction(ActionEvent arg0){
+	public static final void operatorAction(ActionEvent arg0) {
 
 		switchfromSymbolLayer();
 
@@ -94,7 +88,6 @@ public final class ButtonManager {
 
 	}
 
-	
 	/**
 	 * Handler for the Mapping Layer switch Button.
 	 */
@@ -106,19 +99,18 @@ public final class ButtonManager {
 		GraphDisplayManager.switchActiveGraph();
 
 		setBorderStyle((Button) arg0.getSource());
-	
+
 	}
 
-	
 	/**
 	 * Handler for the Symbol Representation Layer switch Button.
 	 */
 	public static final void symbolRepAction(ActionEvent arg0) {
-		
+
 		if (!GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
 			controller.toolbox.setVisible(false);
 			controller.symbolToolVBox.setVisible(true);
-			
+
 			controller.propertiesObjectColumn.setEditable(false);
 
 		}
@@ -127,30 +119,32 @@ public final class ButtonManager {
 		GraphDisplayManager.switchActiveGraph();
 
 		setBorderStyle((Button) arg0.getSource());
-	
+
 	}
-	
-	
+
 	/**
-	 * After switching from symbol-layer to other layer show toolbox and make properties editable again
+	 * After switching from symbol-layer to other layer show toolbox and make
+	 * properties editable again
 	 */
-	private static void switchfromSymbolLayer(){
-		
+	private static void switchfromSymbolLayer() {
+
 		if (GraphDisplayManager.getCurrentLayer().equals(Layer.SYMBOL)) {
 			controller.toolbox.setVisible(true);
 			controller.symbolToolVBox.setVisible(false);
-			
+
 			controller.propertiesObjectColumn.setEditable(true);
 
 		}
 	}
 
-	
 	/**
-	 * Functionality for "edge visible" Checkbox 
+	 * Functionality for "edge visible" Checkbox
+	 * 
 	 * @param ov
-	 * @param oldVal Checkbox previous state (Checked or unchecked)
-	 * @param newVal Checkbox current state (Checked or unchecked)
+	 * @param oldVal
+	 *            Checkbox previous state (Checked or unchecked)
+	 * @param newVal
+	 *            Checkbox current state (Checked or unchecked)
 	 */
 	public static void edgeVisibleSwitch(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
 		// Show edges
@@ -159,23 +153,25 @@ public final class ButtonManager {
 				edge.removeAttribute("ui.hide");
 			}
 
-		// Hide edges
+			// Hide edges
 		} else {
 			for (Edge edge : Main.getInstance().getGraphManager().getGraph().getEachEdge()) {
 				edge.addAttribute("ui.hide");
 			}
 		}
 	}
-	
 
 	/**
-	 * Functionality for "label visible" Checkbox 
+	 * Functionality for "label visible" Checkbox
+	 * 
 	 * @param ov
-	 * @param oldVal Checkbox previous state (Checked or unchecked)
-	 * @param newVal Checkbox current state (Checked or unchecked)
+	 * @param oldVal
+	 *            Checkbox previous state (Checked or unchecked)
+	 * @param newVal
+	 *            Checkbox current state (Checked or unchecked)
 	 */
 	public static void labelVisibilitySwitcher(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
-		
+
 		GraphManager graphManager = Main.getInstance().getGraphManager();
 		String stylesheet = graphManager.getStylesheet();
 
@@ -189,15 +185,18 @@ public final class ButtonManager {
 		}
 	}
 
-	
 	/**
-	 * Functionality for "edge weights visible" Checkbox 
+	 * Functionality for "edge weights visible" Checkbox
+	 * 
 	 * @param ov
-	 * @param oldVal Checkbox previous state (Checked or unchecked)
-	 * @param newVal Checkbox current state (Checked or unchecked)
+	 * @param oldVal
+	 *            Checkbox previous state (Checked or unchecked)
+	 * @param newVal
+	 *            Checkbox current state (Checked or unchecked)
 	 */
-	public static void edgeWeightVisibilitySwitcher(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
-		
+	public static void edgeWeightVisibilitySwitcher(ObservableValue<? extends Boolean> ov, Boolean oldVal,
+			Boolean newVal) {
+
 		GraphManager graphManager = Main.getInstance().getGraphManager();
 		String stylesheet = graphManager.getStylesheet();
 
@@ -210,7 +209,6 @@ public final class ButtonManager {
 			graphManager.setStylesheet(stylesheet.concat("edge{text-mode:hidden;}"));
 		}
 	}
-	
 
 	/**
 	 * Changes the border of the button that was pressed to red

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

@@ -20,7 +20,6 @@ import javafx.scene.control.CheckBox;
 import javafx.scene.control.Label;
 import javafx.scene.control.ListView;
 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;
@@ -28,7 +27,6 @@ import javafx.scene.control.cell.PropertyValueFactory;
 import javafx.scene.control.cell.TextFieldTableCell;
 import javafx.scene.layout.Pane;
 import javafx.scene.layout.VBox;
-import javafx.util.Callback;
 import javafx.util.Pair;
 
 /**
@@ -187,9 +185,12 @@ public class GUIController implements Initializable {
 		// Hide SymbolRep Toolbox View
 		symbolToolVBox.setVisible(false);
 
-		edgesVisibleCheckbox.selectedProperty().addListener((ov, oldVal, newVal) -> ButtonManager.edgeVisibleSwitch(ov, oldVal, newVal));
-		nodeLabelCheckbox.selectedProperty().addListener((ov, oldVal, newVal) -> ButtonManager.labelVisibilitySwitcher(ov, oldVal, newVal));
-		edgeWeightCheckbox.selectedProperty().addListener((ov, oldVal, newVal) -> ButtonManager.edgeWeightVisibilitySwitcher(ov, oldVal, newVal));
+		edgesVisibleCheckbox.selectedProperty()
+				.addListener((ov, oldVal, newVal) -> ButtonManager.edgeVisibleSwitch(ov, oldVal, newVal));
+		nodeLabelCheckbox.selectedProperty()
+				.addListener((ov, oldVal, newVal) -> ButtonManager.labelVisibilitySwitcher(ov, oldVal, newVal));
+		edgeWeightCheckbox.selectedProperty()
+				.addListener((ov, oldVal, newVal) -> ButtonManager.edgeWeightVisibilitySwitcher(ov, oldVal, newVal));
 	}
 
 	/**
@@ -230,14 +231,9 @@ public class GUIController implements Initializable {
 		toolboxStringColumn.setCellValueFactory(new ToolboxManager.PairKeyFactory());
 		toolboxObjectColumn.setCellValueFactory(new ToolboxManager.PairValueFactory());
 
-		toolboxObjectColumn.setCellFactory(
-				new Callback<TableColumn<Pair<Object, String>, Object>, TableCell<Pair<Object, String>, Object>>() {
-					@Override
-					public TableCell<Pair<Object, String>, Object> call(
-							TableColumn<Pair<Object, String>, Object> column) {
-						return new ToolboxManager.PairValueCell();
-					}
-				});
+		toolboxObjectColumn.setCellFactory((column) -> {
+			return new ToolboxManager.PairValueCell();
+		});
 
 		toolbox.getColumns().setAll(toolboxObjectColumn, toolboxStringColumn);
 

+ 13 - 26
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/PropertiesManager.java

@@ -15,7 +15,6 @@ import javafx.application.Platform;
 import javafx.beans.binding.Bindings;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
-import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
 import javafx.geometry.Insets;
 import javafx.scene.control.ButtonBar.ButtonData;
@@ -154,30 +153,28 @@ public final class PropertiesManager {
 			final ContextMenu menuOnNonEmptyRows = new ContextMenu();
 			final MenuItem addPropMenuItem = new MenuItem("Add..");
 			final MenuItem deletePropMenuItem = new MenuItem("Delete");
-			
+
 			// ContextMenu on empty rows (only add)
 			final ContextMenu menuOnEmptyRows = new ContextMenu();
 			final MenuItem onlyAddPropMenuItem = new MenuItem("Add..");
 
 			// add functionality
-			onlyAddPropMenuItem.setOnAction(addPropHandler);
-			addPropMenuItem.setOnAction(addPropHandler);
-			
+			onlyAddPropMenuItem.setOnAction((event) -> addPropFunctionality());
+			addPropMenuItem.setOnAction((event) -> addPropFunctionality());
+
 			// delete functionality
-			deletePropMenuItem.setOnAction(new EventHandler<ActionEvent>() { 
-				@Override
-				public void handle(ActionEvent event) {
-					Debug.out("Remove Element");
-					removeProperty(row.getItem());
-					properties.getItems().remove(row.getItem());
-				}
+			deletePropMenuItem.setOnAction((event) -> {
+				Debug.out("Remove Element");
+				removeProperty(row.getItem());
+				properties.getItems().remove(row.getItem());
 			});
 
 			// add MenuItem to ContextMenu
 			menuOnEmptyRows.getItems().add(onlyAddPropMenuItem);
 			menuOnNonEmptyRows.getItems().addAll(addPropMenuItem, deletePropMenuItem);
 
-			// when empty row right-clicked open special menu (only add), otherwise normal menu (add & delete)
+			// when empty row right-clicked open special menu (only add),
+			// otherwise normal menu (add & delete)
 			row.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(row.itemProperty()))
 					.then(menuOnNonEmptyRows).otherwise(menuOnEmptyRows));
 
@@ -293,20 +290,10 @@ public final class PropertiesManager {
 	}
 
 	/**
-	 * MenuItem Handler, clicked on MenuItem
-	 */
-	private static EventHandler<ActionEvent> addPropHandler = new EventHandler<ActionEvent>() {
-		@Override
-		public void handle(ActionEvent event) {
-			Debug.out("Add Element");
-			addProperty();
-		}
-	};
-
-	/**
-	 * Add a new property to the selected node or edge
+	 * contextMenu add button functionality
 	 */
-	private static void addProperty() {
+	private static void addPropFunctionality() {
+		Debug.out("Add Element");
 
 		// Create new Dialog
 		Dialog<ArrayList<String>> addPropDialog = new Dialog<>();

+ 8 - 10
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ToolboxManager.java

@@ -1,7 +1,5 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
-import javax.swing.text.ChangedCharSetException;
-
 import de.tu_darmstadt.informatik.tk.scopviz.main.CreationMode;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.main.MainApp;
@@ -90,7 +88,7 @@ public final class ToolboxManager {
 				// clicking on text part
 				row = (TableRow<Pair<Object, String>>) node.getParent();
 			}
-			
+
 			// Set CreateModus based on pressed TableRow
 			if (!row.isEmpty()) {
 
@@ -110,7 +108,7 @@ public final class ToolboxManager {
 
 				} else if (rowString.equals("Directed")) {
 					changeCreationMode(CreationMode.CREATE_DIRECTED_EDGE);
-					
+
 				} else if (rowString.equals("Undirected")) {
 					changeCreationMode(CreationMode.CREATE_UNDIRECTED_EDGE);
 				}
@@ -123,20 +121,20 @@ public final class ToolboxManager {
 		}
 
 	};
-	
+
 	/**
-	 * If currentMode already selected then deselect, otherwise set mode on currentMode
+	 * If currentMode already selected then deselect, otherwise set mode on
+	 * currentMode
+	 * 
 	 * @param currentMode
 	 */
-	private static void changeCreationMode(CreationMode currentMode){
-		
+	private static void changeCreationMode(CreationMode currentMode) {
+
 		if (Main.getInstance().getCreationMode().equals(currentMode))
 			Main.getInstance().setCreationMode(CreationMode.CREATE_NONE);
 		else
 			Main.getInstance().setCreationMode(currentMode);
 	}
-	
-	
 
 	// TODO: Create Documentation for this, together with Dominik, ich versteh
 	// das zeug hier net.