ソースを参照

added a TextDialog for entering weight

also fixed bugs with the new defaultSystem

new edges automatically get all defaults now
jascha Bohne 8 年 前
コミット
4838dba18b

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

@@ -134,17 +134,17 @@ public class GraphHelper {
 			if (!n.hasAttribute("ui.label") && n.hasAttribute("yEd.label")) {
 				n.addAttribute("ui.label", n.getAttribute("yEd.label").toString());
 				n.removeAttribute("yEd.label");
-			} else {
+			} else if(n.hasAttribute("ui.label")) {
 				n.removeAttribute("yEd.label");
 			}
 			if (n.hasAttribute("yEd.x") && !n.getAttribute("yEd.x").equals("")) {
 				n.addAttribute("x", Main.getInstance().convertAttributeTypes(n.getAttribute("yEd.x"), new Double(0.0)));
 				n.removeAttribute("yEd.x");
-			} else {
+			} else{
 				n.removeAttribute("yEd.x");
 			}
 			if (n.hasAttribute("yEd.y") && !n.getAttribute("yEd.y").equals("")) {
-				n.addAttribute("y", Main.getInstance().convertAttributeTypes(n.getAttribute("yEd.x"), new Double(0.0)));
+				n.addAttribute("y", Main.getInstance().convertAttributeTypes(n.getAttribute("yEd.y"), new Double(0.0)));
 				n.removeAttribute("yEd.y");
 			} else {
 				n.removeAttribute("yEd.y");

+ 9 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/MyGraph.java

@@ -2,11 +2,17 @@ package de.tu_darmstadt.informatik.tk.scopviz.graphs;
 
 import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.Optional;
 
 import org.graphstream.graph.Edge;
 import org.graphstream.graph.Node;
 import org.graphstream.graph.implementations.SingleGraph;
 
+import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.OptionsManager;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.ToolboxManager;
+import javafx.scene.control.TextInputDialog;
+
 /**
  * Our own Class to extend GraphStreams Graph with our own Functionality.
  * 
@@ -92,6 +98,9 @@ public class MyGraph extends SingleGraph {
 	 *            the Edge that was just created
 	 */
 	private void edgeCreatedNotify(Edge e) {
+		if(Layer.UNDERLAY.equals(this.getAttribute("layer"))){
+			ToolboxManager.createWeighDialog(e);
+		}
 		for (EdgeCreatedListener list : allEdgeListeners) {
 			list.edgeCreated(e, id);
 		}

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

@@ -145,6 +145,9 @@ public final class Main {
 	// don't worry I checked all the conversions
 	@SuppressWarnings("unchecked")
 	public <T extends Number> T convertAttributeTypes(Object attribute, T result) {
+		if(attribute == null){
+			return null;
+		}
 		String currentType = attribute.getClass().getSimpleName().toLowerCase();
 		String targetType = result.getClass().getSimpleName().toLowerCase();
 		switch (targetType) {

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

@@ -194,12 +194,15 @@ public final class GraphDisplayManager {
 		if (g == null) {
 			throw new NullArgumentException();
 		}
+				
 		GraphManager v;
 		int ret = 0;
 		// replacing the current graph or merging
 		if (replaceCurrent) {
 			v = new GraphManager(g);
 			v.getGraph().addAttribute("layer", currentLayer);
+			//set default values
+			GraphHelper.setAllDefaults(g);
 			v.getGraph().addAttribute("ui.antialias");
 			removeAllCurrentGraphs();
 			vList.add(v);
@@ -218,8 +221,6 @@ public final class GraphDisplayManager {
 
 		// set ui.class
 		v.convertUiClass();
-		//set default values
-		GraphHelper.setAllDefaults(v.getGraph());
 		// display the graph
 		switchActiveGraph();
 		return ret;

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

@@ -1,9 +1,14 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
+import java.util.Optional;
+
+import org.graphstream.graph.Edge;
+
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 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;
+import javafx.application.Platform;
 import javafx.beans.property.ReadOnlyObjectWrapper;
 import javafx.beans.value.ObservableValue;
 import javafx.collections.FXCollections;
@@ -14,6 +19,7 @@ import javafx.scene.control.CheckBox;
 import javafx.scene.control.TableCell;
 import javafx.scene.control.TableColumn;
 import javafx.scene.control.TableRow;
+import javafx.scene.control.TextInputDialog;
 import javafx.scene.image.Image;
 import javafx.scene.image.ImageView;
 import javafx.scene.input.MouseEvent;
@@ -188,13 +194,41 @@ public final class ToolboxManager {
 	private static Pair<Object, String> pair(Object picture, String name) {
 		return new Pair<>(picture, name);
 	}
+	
+	/**
+	 * the last edge that was created
+	 */
+	private static Edge lastCreatedEdge = null;
+	
+	/**
+	 * opens a dialog that asks for a weight for a newly created Edge. 
+	 * The default value is Optionsmanager.getDefaultWeight()
+	 *   
+	 * @param e the new Edge that needs a weight
+	 */
+	public static void createWeighDialog(Edge e){
+		if(e.equals(lastCreatedEdge)){
+			return;
+		}
+		lastCreatedEdge = e;
+		Platform.runLater(() -> {
+			TextInputDialog weightDialog = new TextInputDialog(Integer.toString(OptionsManager.getDefaultWeight()));
+			weightDialog.setTitle("Edge Weight");
+			weightDialog.setHeaderText("Please enter the weight of the Edge");
+			weightDialog.setContentText("Edge Weight");
+			Optional<String> result = weightDialog.showAndWait();
+			if(result.isPresent()){
+				e.addAttribute("weight", result.get());
+			}
+		});
+	}
 
 	/**
 	 * Class for getting the string out of the pair elements in each row
 	 *
 	 */
 	public static class PairKeyFactory
-			implements Callback<TableColumn.CellDataFeatures<Pair<Object, String>, String>, ObservableValue<String>> {
+	implements Callback<TableColumn.CellDataFeatures<Pair<Object, String>, String>, ObservableValue<String>> {
 		@Override
 		public ObservableValue<String> call(TableColumn.CellDataFeatures<Pair<Object, String>, String> data) {
 			return new ReadOnlyObjectWrapper<>(data.getValue().getValue());
@@ -206,7 +240,7 @@ public final class ToolboxManager {
 	 *
 	 */
 	public static class PairValueFactory
-			implements Callback<TableColumn.CellDataFeatures<Pair<Object, String>, Object>, ObservableValue<Object>> {
+	implements Callback<TableColumn.CellDataFeatures<Pair<Object, String>, Object>, ObservableValue<Object>> {
 		@SuppressWarnings("unchecked")
 		@Override
 		public ObservableValue<Object> call(TableColumn.CellDataFeatures<Pair<Object, String>, Object> data) {