Преглед изворни кода

Edge propagation and Option saving

jascha Bohne пре 7 година
родитељ
комит
160aabcb41

+ 12 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/debug/Debug.java

@@ -82,6 +82,18 @@ public final class Debug {
 		}
 	}
 
+	/**
+	 * Short form for System.out.println().
+	 * 
+	 * @param s
+	 *            Object to be printed on the console
+	 */
+	public static void out(Object s) {
+		if (DEBUG_ENABLED) {
+			System.out.println("DEBUG: " + s);
+		}
+	}
+
 	/**
 	 * Short form for System.out.println(). Also look if a message is important
 	 * enough to be printed

+ 11 - 27
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/GraphManager.java

@@ -359,29 +359,6 @@ public class GraphManager {
 		this.currentPath = currentPath;
 	}
 
-	/**
-	 * Adds a <b>Copy</b> of the given Edge to the graph. The Copy retains the
-	 * ID and all attributes.
-	 * 
-	 * @param e
-	 *            the Edge to be added to the graph
-	 */
-	public void addEdge(Edge e) {
-		HashMap<String, Object> attributes = new HashMap<>();
-
-		for (String s : e.getAttributeKeySet()) {
-			attributes.put(s, e.getAttribute(s));
-		}
-		g.addEdge(e.getId(), (Node) e.getSourceNode(), (Node) e.getTargetNode(), e.isDirected());
-		g.getEdge(e.getId()).addAttributes(attributes);
-
-		if (activeSubGraph != null) {
-			activeSubGraph.addEdge(e.getId(), (Node) e.getSourceNode(), (Node) e.getTargetNode(), e.isDirected());
-			activeSubGraph.getEdge(e.getId()).addAttributes(attributes);
-			g.getEdge(e.getId()).addAttribute("originalElement", activeSubGraph.getId() + "+#" + e.getId());
-		}
-	}
-
 	/**
 	 * Adds a <b>Copy</b> of the given Node to the graph. The Copy retains the
 	 * ID and all attributes.
@@ -397,7 +374,6 @@ public class GraphManager {
 		}
 		g.addNode(n.getId());
 		g.getNode(n.getId()).addAttributes(attributes);
-
 		if (activeSubGraph != null) {
 			activeSubGraph.addNode(n.getId());
 			activeSubGraph.getNode(n.getId()).addAttributes(attributes);
@@ -548,14 +524,22 @@ public class GraphManager {
 		if (getGraph().getNode(from).hasEdgeBetween(to))
 			return false;
 		String newID = Main.getInstance().getUnusedID();
-
+		Edge e;
 		if (Main.getInstance().getCreationMode() == CreationMode.CREATE_DIRECTED_EDGE) {
-			getGraph().addEdge(newID, from, to, true);
+			e = getGraph().addEdge(newID, from, to, true);
 			Debug.out("Created an directed edge with Id " + newID + " between " + from + " and " + to);
 		} else {
-			getGraph().addEdge(newID, from, to);
+			e = getGraph().addEdge(newID, from, to);
 			Debug.out("Created an undirected edge with Id " + newID + " between " + from + " and " + to);
 		}
+		
+		Debug.out(activeSubGraph);
+		if (activeSubGraph != null) {
+			Debug.out("edge creation");
+			activeSubGraph.addEdge(e.getId(), e.getSourceNode().getAttribute("originalElement").toString().split("\\+#")[1]
+					, e.getTargetNode().getAttribute("originalElement").toString().split("\\+#")[1], e.isDirected());
+			g.getEdge(e.getId()).addAttribute("originalElement", activeSubGraph.getId() + "+#" + e.getId());
+		}
 
 		selectEdge(newID);
 

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

@@ -106,7 +106,6 @@ public class MyGraph extends SingleGraph {
 				|| (e.getAttribute("weight") != null && (OptionsManager.getDefaultWeight() == Main.getInstance()
 						.convertAttributeTypes(e.getAttribute("weight"), new Double(0.0)))));
 		if (doWeight) {
-			Debug.out("MyGraph:105 " + e.getId() + " " + e.getAttribute("weight"));
 			ToolboxManager.createWeightDialog(e);
 		}
 		for (EdgeCreatedListener list : allEdgeListeners) {

+ 0 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/MyFileSinkGraphML.java

@@ -27,7 +27,6 @@ public class MyFileSinkGraphML extends FileSinkGraphML {
 			HashMap<String, String> nodeAttributes = new HashMap<String, String>();
 			HashMap<String, String> edgeAttributes = new HashMap<String, String>();
 			HashMap<String, String> graphAttributes = new HashMap<String, String>();
-			Debug.out(g.getAttributeCount());
 			for (String j : g.getAttributeKeySet()) {
 				if (!isWritingMultigraph && (j.equals("layer") || j.equals("ui.stylesheet"))) {
 					continue;

+ 0 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/MySourceBase.java

@@ -1195,7 +1195,6 @@ public class MySourceBase implements Source {
 	 */
 	protected void newSubGraph() {
 		if (subGraphCounter > 1) {
-			Debug.out(originalSink.toString());
 			removeSink(originalSink);
 			multiGraph = true;
 		}

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

@@ -6,6 +6,7 @@ import java.math.BigInteger;
 import de.tu_darmstadt.informatik.tk.scopviz.graphs.GraphManager;
 import de.tu_darmstadt.informatik.tk.scopviz.io.GraphMLExporter;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.GraphDisplayManager;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.OptionsManager;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyAnimationTimer;
 import javafx.animation.AnimationTimer;
 import javafx.stage.Stage;
@@ -358,7 +359,7 @@ public final class Main {
 				false);
 		exp.writeGraph(GraphDisplayManager.getGraphManager(Layer.OPERATOR).getGraph(), "operator-shutdown.graphml",
 				false);
-
+		OptionsManager.save();
 		System.exit(0);
 	}
 

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

@@ -6,6 +6,7 @@ import java.net.URL;
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.io.GraphMLImporter;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.GraphDisplayManager;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.OptionsManager;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.css.CSSManager;
 import javafx.application.Application;
 import javafx.event.EventHandler;
@@ -87,7 +88,7 @@ public class MainApp extends Application {
 				Debug.out("INFORMATION: no previous underlaygraph", 1);
 			}
 		}
-
+		OptionsManager.load();
 		CSSManager.addRule("node{text-alignment: at-right; size: 15px;}");
 	}
 

+ 0 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GraphDisplayManager.java

@@ -106,7 +106,6 @@ public final class GraphDisplayManager {
 	 */
 	public static void init(GUIController guiController) {
 		GraphDisplayManager.guiController = guiController;
-		Debug.out("init");
 		addGraph();
 		currentLayer = Layer.OPERATOR;
 		addGraph();

+ 61 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/OptionsManager.java

@@ -1,5 +1,10 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 
@@ -326,5 +331,61 @@ public final class OptionsManager {
 	public static void setShowWeight(boolean showWeight) {
 		OptionsManager.showWeight = showWeight;
 	}
+	
+	public static void load(){
+		try{
+			BufferedReader read = new BufferedReader (new FileReader("settings.properties"));
+			defaultWeight = Double.parseDouble(read.readLine());
+			showWeight = Boolean.parseBoolean(read.readLine());
+			defaultLat = Double.parseDouble(read.readLine());
+			defaultLong = Double.parseDouble(read.readLine());
+			coordinatesChanged = Boolean.parseBoolean(read.readLine());
+			defaultDeviceSize = Integer.parseInt(read.readLine());
+			defaultEdgeThickness = Integer.parseInt(read.readLine());
+			defaultStandardEdgeColor = read.readLine();
+			defaultClickedEdgeColor = read.readLine();
+			defaultPlacementColor = read.readLine();
+			defaultStandardDeviceColor = read.readLine();
+			defaultClickedDeviceColor = read.readLine();
+			Debug.setLogLevel(Integer.parseInt(read.readLine()));
+			read.close();
+		} catch (IOException e){
+			defaultValues();
+		}
+	}
+	public static void save(){
+		try{
+			BufferedWriter write = new BufferedWriter(new FileWriter("settings.properties"));
+			write.write(defaultWeight + "\n"
+					+ showWeight + "\n"
+					+ defaultLat + "\n"
+					+ defaultLong  + "\n"
+					+ coordinatesChanged + "\n"
+					+ defaultDeviceSize + "\n"
+					+ defaultEdgeThickness + "\n"
+					+ defaultStandardEdgeColor + "\n"
+					+ defaultClickedEdgeColor + "\n"
+					+ defaultPlacementColor + "\n"
+					+ defaultStandardDeviceColor + "\n"
+					+ defaultClickedDeviceColor + "\n"
+					+ Debug.getLogLevel());
+			write.close();
+		} catch (IOException e){}
+	}
+	protected static void defaultValues(){
+		defaultWeight = 0.0;
+		showWeight = true;
+		defaultLat = 49.877559;
+		defaultLong = 8.654546;
+		coordinatesChanged = false;
+		defaultDeviceSize = 50;
+		defaultEdgeThickness = 2;
+		defaultStandardEdgeColor = "Black";
+		defaultClickedEdgeColor = "Red";
+		defaultPlacementColor = "Blue";
+		defaultStandardDeviceColor = "Black";
+		defaultClickedDeviceColor = "Red";
+		Debug.setLogLevel(2);
+	}
 
 }

+ 0 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/PropertiesManager.java

@@ -318,7 +318,6 @@ public final class PropertiesManager {
 				}
 				break;
 			case "process-need":
-				Debug.out(key);
 				if (selected instanceof Node
 						&& Layer.UNDERLAY == Main.getInstance().getGraphManager().getGraph().getAttribute("layer")) {
 					break;