瀏覽代碼

Merged Everything, Formatted Code, please rebase

Jan Enders 8 年之前
父節點
當前提交
8ef8b16590

+ 2 - 2
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/GraphManager.java

@@ -400,11 +400,11 @@ public class GraphManager {
 			}
 		}
 	}
-	
+
 	/**
 	 * converts the weight property into a label to display on the Graph
 	 */
-	public void handleEdgeWeight(){
+	public void handleEdgeWeight() {
 		Edge e = null;
 		Iterator<Edge> allEdges = g.getEdgeIterator();
 

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

@@ -15,10 +15,10 @@ import javafx.stage.Stage;
  */
 public final class Main {
 	/**
-	 * The Stylesheet that is given to every graph that is added to display everything correctly
+	 * The Stylesheet that is given to every graph that is added to display
+	 * everything correctly
 	 */
-	public static final String DEFAULT_STYLESHEET = 
-			"node{text-alignment:at-right;} \n"
+	public static final String DEFAULT_STYLESHEET = "node{text-alignment:at-right;} \n"
 			+ "edge{text-offset: 4px,-4px;}";
 	/**
 	 * Singular instance of the Class, facilitates Singleton pattern.

+ 17 - 20
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GUIController.java

@@ -5,7 +5,6 @@ import java.util.ResourceBundle;
 
 import javax.swing.JPanel;
 
-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.KeyboardShortcuts;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyAnimationTimer;
@@ -101,8 +100,7 @@ public class GUIController implements Initializable {
 	public TableColumn<KeyValuePair, String> propertiesStringColumn;
 	@FXML
 	public TableColumn propertiesObjectColumn;
-	
-	
+
 	@FXML
 	public Text createModusText;
 	@FXML
@@ -148,13 +146,13 @@ public class GUIController implements Initializable {
 
 		assert propertiesStringColumn != null : "fx:id=\"propertiesString\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 		assert propertiesObjectColumn != null : "fx:id=\"propertiesObject\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
-		
+
 		assert createModusText != null : "fx:id=\"createModusText\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 		assert selectModusText != null : "fx:id=\"selectModusText\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 		assert actualLayerText != null : "fx:id=\"actualLayerText\" was not injected: check your FXML file 'NewBetterCoolerWindowTest.fxml'.";
 
 		MyAnimationTimer.setGUIController(this);
-		
+
 		initializeToolbox();
 		initializeProperties();
 
@@ -173,15 +171,15 @@ public class GUIController implements Initializable {
 		initializeLayerButton();
 		initializeDisplayPane();
 		initializeMenuBar();
-		
+
 		initializeTextFields();
-		
+
 		new KeyboardShortcuts(Main.getInstance().getPrimaryStage());
 	}
 
 	private void initializeMenuBar() {
 		MenuBarManager.setGUIController(this);
-		
+
 		open.setOnAction(MenuBarManager.openHandler);
 		save.setOnAction(MenuBarManager.saveHandler);
 		saveAs.setOnAction(MenuBarManager.saveAsHandler);
@@ -228,10 +226,10 @@ public class GUIController implements Initializable {
 	 */
 	@SuppressWarnings({ "unchecked" })
 	private void initializeToolbox() {
-		
+
 		ToolboxManager.initialize(this);
 		MyViewerListener.setGUIController(this);
-		
+
 		toolboxStringColumn.setCellValueFactory(new ToolboxManager.PairKeyFactory());
 		toolboxObjectColumn.setCellValueFactory(new ToolboxManager.PairValueFactory());
 
@@ -260,11 +258,11 @@ public class GUIController implements Initializable {
 	 */
 	@SuppressWarnings("unchecked")
 	private void initializeProperties() {
-		
-		//removeHeaderTableView(properties);
+
+		// removeHeaderTableView(properties);
 		propertiesObjectColumn.setResizable(true);
 		propertiesStringColumn.setResizable(true);
-		
+
 		propertiesStringColumn.setCellValueFactory(new PropertyValueFactory<KeyValuePair, String>("key"));
 
 		propertiesObjectColumn.setCellValueFactory(new PropertyValueFactory<KeyValuePair, Object>("value"));
@@ -272,15 +270,14 @@ public class GUIController implements Initializable {
 		propertiesObjectColumn.setOnEditCommit(PropertiesManager.setOnEditCommitHandler);
 
 		properties.getColumns().setAll(propertiesStringColumn, propertiesObjectColumn);
-		
+
 		properties.setPlaceholder(new Label("No graph element selected"));
-		
-		properties.setRowFactory(PropertiesManager.rightClickCallback);  
-		
+
+		properties.setRowFactory(PropertiesManager.rightClickCallback);
+
 	}
-	
-	
-	private void initializeTextFields(){
+
+	private void initializeTextFields() {
 		createModusText.setText(Main.getInstance().getCreationMode().toString());
 		selectModusText.setText(Main.getInstance().getSelectionMode().toString());
 		actualLayerText.setText(GraphDisplayManager.getCurrentLayer().toString());

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

@@ -11,7 +11,7 @@ import javafx.scene.control.MenuItem;
 public class MenuBarManager {
 
 	private static GUIController controller;
-	
+
 	/**
 	 * Handler for the "open" MenuItem.
 	 */
@@ -107,8 +107,8 @@ public class MenuBarManager {
 		}
 	};
 
-	public static void setGUIController(GUIController con){
+	public static void setGUIController(GUIController con) {
 		controller = con;
 	}
-	
+
 }

+ 100 - 109
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/PropertiesManager.java

@@ -9,8 +9,6 @@ import org.graphstream.graph.Element;
 import org.graphstream.graph.Node;
 
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
-import com.sun.org.apache.bcel.internal.generic.GOTO;
-
 import de.tu_darmstadt.informatik.tk.scopviz.main.GraphManager;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import javafx.application.Platform;
@@ -20,8 +18,6 @@ import javafx.collections.ObservableList;
 import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
 import javafx.geometry.Insets;
-import javafx.scene.control.TableColumn.CellEditEvent;
-import javafx.util.Callback;
 import javafx.scene.control.ButtonBar.ButtonData;
 import javafx.scene.control.ButtonType;
 import javafx.scene.control.ChoiceBox;
@@ -29,10 +25,12 @@ import javafx.scene.control.ContextMenu;
 import javafx.scene.control.Dialog;
 import javafx.scene.control.Label;
 import javafx.scene.control.MenuItem;
+import javafx.scene.control.TableColumn.CellEditEvent;
 import javafx.scene.control.TableRow;
 import javafx.scene.control.TableView;
 import javafx.scene.control.TextField;
 import javafx.scene.layout.GridPane;
+import javafx.util.Callback;
 
 /**
  * Manager for the Properties pane and its contents.
@@ -48,7 +46,7 @@ public class PropertiesManager {
 	public static final String IS_FLOAT = "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$";
 
 	private static TableView<KeyValuePair> properties;
-	
+
 	public static boolean nameSet;
 	public static boolean valueSet;
 
@@ -79,12 +77,8 @@ public class PropertiesManager {
 			String key = editedPair.getKey();
 			String oldValue = t.getOldValue();
 			String newValue = t.getNewValue();
-			
-			GraphManager viz = Main.getInstance().getGraphManager();
-			Element selected =getSelected();
 
-			String nid = viz.getSelectedNodeID();
-			String eid = viz.getSelectedEdgeID();
+			Element selected = getSelected();
 
 			if (classType.equals(Integer.class) && newValue.matches(IS_INT)) {
 				selected.changeAttribute(key, Integer.valueOf(newValue));
@@ -119,45 +113,42 @@ public class PropertiesManager {
 			}
 		}
 	};
-	
-	public static Callback<TableView<KeyValuePair>, TableRow<KeyValuePair>> rightClickCallback = new Callback<TableView<KeyValuePair>, TableRow<KeyValuePair>>() {  
-        @Override  
-        public TableRow<KeyValuePair> call(TableView<KeyValuePair> tableView) {  
-        	
-            final TableRow<KeyValuePair> row = new TableRow<>(); 
-            
-            final ContextMenu menuOnNonEmptyRows = new ContextMenu();
-            final ContextMenu menuOnEmptyRows = new ContextMenu();
-            
-            final MenuItem onlyAddPropMenuItem = new MenuItem("Add..");
-            final MenuItem addPropMenuItem = new MenuItem("Add..");
-    		final MenuItem deletePropMenuItem = new MenuItem("Delete");
-            
-    		
-    		onlyAddPropMenuItem.setOnAction(addPropHandler);
-    		
-    		addPropMenuItem.setOnAction(addPropHandler);
-    		
-            deletePropMenuItem.setOnAction(new EventHandler<ActionEvent>() {  
-                @Override  
-                public void handle(ActionEvent event) { 
-                	Debug.out("Remove Element");
-                	removeProperty(row.getItem());
-                    properties.getItems().remove(row.getItem());  
-                }  
-            });
-            
-            menuOnEmptyRows.getItems().add(onlyAddPropMenuItem);
-            menuOnNonEmptyRows.getItems().addAll(addPropMenuItem, deletePropMenuItem);
-            
-            row.contextMenuProperty().bind(
-            	      Bindings.when(Bindings.isNotNull(row.itemProperty()))
-            	      .then(menuOnNonEmptyRows)
-            	      .otherwise(menuOnEmptyRows));	      
-            
-            return row;  
-        }  
-    };
+
+	public static Callback<TableView<KeyValuePair>, TableRow<KeyValuePair>> rightClickCallback = new Callback<TableView<KeyValuePair>, TableRow<KeyValuePair>>() {
+		@Override
+		public TableRow<KeyValuePair> call(TableView<KeyValuePair> tableView) {
+
+			final TableRow<KeyValuePair> row = new TableRow<>();
+
+			final ContextMenu menuOnNonEmptyRows = new ContextMenu();
+			final ContextMenu menuOnEmptyRows = new ContextMenu();
+
+			final MenuItem onlyAddPropMenuItem = new MenuItem("Add..");
+			final MenuItem addPropMenuItem = new MenuItem("Add..");
+			final MenuItem deletePropMenuItem = new MenuItem("Delete");
+
+			onlyAddPropMenuItem.setOnAction(addPropHandler);
+
+			addPropMenuItem.setOnAction(addPropHandler);
+
+			deletePropMenuItem.setOnAction(new EventHandler<ActionEvent>() {
+				@Override
+				public void handle(ActionEvent event) {
+					Debug.out("Remove Element");
+					removeProperty(row.getItem());
+					properties.getItems().remove(row.getItem());
+				}
+			});
+
+			menuOnEmptyRows.getItems().add(onlyAddPropMenuItem);
+			menuOnNonEmptyRows.getItems().addAll(addPropMenuItem, deletePropMenuItem);
+
+			row.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(row.itemProperty()))
+					.then(menuOnNonEmptyRows).otherwise(menuOnEmptyRows));
+
+			return row;
+		}
+	};
 
 	/**
 	 * Sets Property-TableView Elements to selected Node or Edge Properties
@@ -210,14 +201,15 @@ public class PropertiesManager {
 
 		properties.setItems(newData);
 	}
-	
+
 	/**
-	 * Get the selceted node or edge 
+	 * Get the selceted node or edge
+	 * 
 	 * @return selected node or egde
 	 */
-	private static Element getSelected(){
+	private static Element getSelected() {
 		GraphManager viz = Main.getInstance().getGraphManager();
-		
+
 		String nid = viz.getSelectedNodeID();
 		String eid = viz.getSelectedEdgeID();
 
@@ -228,61 +220,63 @@ public class PropertiesManager {
 		} else
 			return null;
 	}
-	
+
 	/**
 	 * Delete a given Pair from the current Node or Edge
-	 * @param pair selectedProperty
+	 * 
+	 * @param pair
+	 *            selectedProperty
 	 */
-	private static void removeProperty(KeyValuePair pair){
-		
+	private static void removeProperty(KeyValuePair pair) {
+
 		Element selected = getSelected();
-		
+
 		selected.removeAttribute(pair.getKey());
-		
-		// Caution VERY BAD CODE! BY JULIAN 
-		Debug.out(String.valueOf(properties.getPrefWidth())); 
+
+		// Caution VERY BAD CODE! BY JULIAN
+		Debug.out(String.valueOf(properties.getPrefWidth()));
 	}
-	
+
 	/**
 	 * 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
-     */
-	private static void addProperty(){
-		
+	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
+	 */
+	private static void addProperty() {
+
 		// Create new Dialog
 		Dialog<ArrayList<String>> addPropDialog = new Dialog<>();
 		addPropDialog.setTitle("Add Property");
 		addPropDialog.setHeaderText("Choose your Property Details");
-		
+
 		ButtonType addButtonType = new ButtonType("Confirm", ButtonData.OK_DONE);
 		addPropDialog.getDialogPane().getButtonTypes().addAll(addButtonType, ButtonType.CANCEL);
-		
+
 		// create grid
 		GridPane grid = new GridPane();
 		grid.setHgap(10);
 		grid.setVgap(10);
 		grid.setPadding(new Insets(20, 150, 10, 10));
-		
+
 		// create dialog elements
 		TextField name = new TextField();
 		name.setPromptText("Name");
 		TextField value = new TextField();
 		value.setPromptText("Value");
-		
+
 		ChoiceBox<String> type = new ChoiceBox<String>();
 		type.setItems(FXCollections.observableArrayList("Integer", "Float", "String", "Boolean"));
 		type.getSelectionModel().selectFirst();
-		
+
 		// position elements on grid
 		grid.add(new Label("Property Name:"), 0, 0);
 		grid.add(name, 1, 0);
@@ -290,73 +284,70 @@ public class PropertiesManager {
 		grid.add(value, 1, 1);
 		grid.add(new Label("Property Type:"), 0, 2);
 		grid.add(type, 1, 2);
-		
+
 		javafx.scene.Node confirmButton = addPropDialog.getDialogPane().lookupButton(addButtonType);
 		confirmButton.setDisable(true);
-		
+
 		nameSet = false;
 		valueSet = false;
-		
+
 		// hide confirm button, when textfields empty
 		name.textProperty().addListener((observable, oldValue, newValue) -> {
 			PropertiesManager.nameSet = true;
-			if(newValue.trim().isEmpty()){
+			if (newValue.trim().isEmpty()) {
 				PropertiesManager.nameSet = false;
 				confirmButton.setDisable(true);
-			}else if(PropertiesManager.valueSet){
+			} else if (PropertiesManager.valueSet) {
 				confirmButton.setDisable(false);
 			}
 		});
 		value.textProperty().addListener((observable, oldValue, newValue) -> {
 			PropertiesManager.valueSet = true;
-			if(newValue.trim().isEmpty()){
+			if (newValue.trim().isEmpty()) {
 				PropertiesManager.valueSet = false;
 				confirmButton.setDisable(true);
-			}else if(PropertiesManager.nameSet){
+			} else if (PropertiesManager.nameSet) {
 				confirmButton.setDisable(false);
 			}
 		});
-		
-		
+
 		// set dialog
 		addPropDialog.getDialogPane().setContent(grid);
-		
-		Platform.runLater(() -> name.requestFocus()); 
-		
-		
+
+		Platform.runLater(() -> name.requestFocus());
+
 		// get new property values
-		addPropDialog.setResultConverter(dialogButton -> { 
-			if(dialogButton == addButtonType){
+		addPropDialog.setResultConverter(dialogButton -> {
+			if (dialogButton == addButtonType) {
 				ArrayList<String> tmp = new ArrayList<String>();
 				tmp.add(name.getText());
 				tmp.add(value.getText());
 				tmp.add(type.getValue());
-				
+
 				return tmp;
-			}else 
+			} else
 				return null;
-			
+
 		});
-		
+
 		Optional<ArrayList<String>> result = addPropDialog.showAndWait();
-		
-		
+
 		// create new Property
 		result.ifPresent(t -> {
-			System.out.println("Name: "+ t.get(0)+ ", Value: "+ t.get(1)+ ", Type: "+t.get(2));
-			
+			System.out.println("Name: " + t.get(0) + ", Value: " + t.get(1) + ", Type: " + t.get(2));
+
 			Element selected = getSelected();
-			
-			if(t.get(2).equals("Integer")){
+
+			if (t.get(2).equals("Integer")) {
 				selected.addAttribute(t.get(0), Integer.valueOf(t.get(1)));
-			}else if(t.get(2).equals("Float")){
+			} else if (t.get(2).equals("Float")) {
 				selected.addAttribute(t.get(0), Float.valueOf(t.get(1)));
-			}else if(t.get(2).equals("String")){
+			} else if (t.get(2).equals("String")) {
 				selected.addAttribute(t.get(0), String.valueOf(t.get(1)));
-			}else if(t.get(2).equals("Boolean")){
+			} else if (t.get(2).equals("Boolean")) {
 				selected.addAttribute(t.get(0), Boolean.valueOf(t.get(1)));
 			}
-			
+
 			showNewDataSet(selected);
 		});
 	}

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

@@ -29,17 +29,18 @@ import javafx.util.Pair;
  */
 // TODO Jaschas Code mergen?
 public class ToolboxManager {
-	
+
 	/**
 	 * GUIController reference
 	 */
 	private static GUIController controller;
-	
+
 	/**
 	 * Initialize Toolbox, set controller
+	 * 
 	 * @param guiController
 	 */
-	public static void initialize(GUIController guiController){
+	public static void initialize(GUIController guiController) {
 		controller = guiController;
 	}
 
@@ -56,8 +57,7 @@ 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"));
 

+ 10 - 11
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/KeyboardShortcuts.java

@@ -16,32 +16,31 @@ import javafx.stage.Stage;
  *
  */
 public class KeyboardShortcuts {
-	
-	//example of keycombinations
+
+	// example of keycombinations
 	final KeyCombination rCtrl = new KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN);
-	final KeyCombination rCtrlShift = new KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN);
-	
-	
+	final KeyCombination rCtrlShift = new KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN,
+			KeyCombination.SHIFT_DOWN);
+
 	public KeyboardShortcuts(Stage primaryStage) {
 
 		primaryStage.addEventFilter(KeyEvent.KEY_RELEASED, buttonsPressed);
 
 	}
-	
-	//a general EventHandler for all key combinations
-	private EventHandler<KeyEvent> buttonsPressed = new EventHandler<KeyEvent>() {	
+
+	// a general EventHandler for all key combinations
+	private EventHandler<KeyEvent> buttonsPressed = new EventHandler<KeyEvent>() {
 
 		@Override
 		public void handle(KeyEvent event) {
-			
+
 			if (rCtrl.match(event)) {
 				System.out.println("Ctrl+R pressed");
 			}
-			
+
 			else if (rCtrlShift.match(event)) {
 				System.out.println("Ctrl+Shift+R pressed");
 			}
-			
 
 		}
 	};

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

@@ -21,8 +21,8 @@ public class MyAnimationTimer extends AnimationTimer {
 			guiController.actualLayerText.setText(GraphDisplayManager.getCurrentLayer().toString());
 		}
 	}
-	
-	public static void setGUIController(GUIController con){
+
+	public static void setGUIController(GUIController con) {
 		guiController = con;
 	}
 }

+ 8 - 7
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/MyViewerListener.java

@@ -30,7 +30,7 @@ public class MyViewerListener implements ViewerListener {
 	private GraphManager graphManager;
 
 	private String lastClickedID;
-	
+
 	/**
 	 * GUIController reference
 	 */
@@ -45,12 +45,13 @@ public class MyViewerListener implements ViewerListener {
 	public MyViewerListener(GraphManager viz) {
 		graphManager = viz;
 	}
-	
+
 	/**
-	 * Set GUIController 
+	 * Set GUIController
+	 * 
 	 * @param guiController
 	 */
-	public static void setGUIController(GUIController guiController){
+	public static void setGUIController(GUIController guiController) {
 		controller = guiController;
 	}
 
@@ -138,12 +139,12 @@ public class MyViewerListener implements ViewerListener {
 		default:
 			break;
 		}
-		if(newID != null){
-		graphManager.getGraph().getEdge(newID).addAttribute("Weight", 0);
+		if (newID != null) {
+			graphManager.getGraph().getEdge(newID).addAttribute("Weight", 0);
 		}
 		PropertiesManager.setItemsProperties();
 
-	controller.createModusText.setText(Main.getInstance().getCreationMode().toString());
+		controller.createModusText.setText(Main.getInstance().getCreationMode().toString());
 
 		if (!CREATE_MORE_THEN_ONE) {
 			Main.getInstance().setCreationMode(CreationMode.CREATE_NONE);