Browse Source

now opens the last Graph at startup

jascha Bohne 7 years ago
parent
commit
6758ae4289

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

@@ -95,7 +95,7 @@ public final class Debug {
 	 */
 	public static void out(String s, int severity) {
 		if (severity >= logLevel) {
-			if (DEBUG_ENABLED){
+			if (DEBUG_ENABLED) {
 				System.out.println(s);
 			}
 

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

@@ -38,7 +38,7 @@ public class GraphManager {
 	protected MyGraph g;
 
 	protected MyGraph activeSubGraph;
-	
+
 	/**
 	 * The Stylesheet for this Graph, excluding parts that can be set by
 	 * NodeGraphics.
@@ -374,11 +374,11 @@ public class GraphManager {
 		}
 		g.addEdge(e.getId(), (Node) e.getSourceNode(), (Node) e.getTargetNode(), e.isDirected());
 		g.getEdge(e.getId()).addAttributes(attributes);
-		
-		if (activeSubGraph != null){
+
+		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());
+			g.getEdge(e.getId()).addAttribute("originalElement", activeSubGraph.getId() + "+#" + e.getId());
 		}
 	}
 
@@ -397,11 +397,11 @@ public class GraphManager {
 		}
 		g.addNode(n.getId());
 		g.getNode(n.getId()).addAttributes(attributes);
-		
-		if (activeSubGraph != null){
+
+		if (activeSubGraph != null) {
 			activeSubGraph.addNode(n.getId());
 			activeSubGraph.getNode(n.getId()).addAttributes(attributes);
-			g.getNode(n.getId()).addAttribute("originalElement", activeSubGraph.getId()+"+#"+n.getId());
+			g.getNode(n.getId()).addAttribute("originalElement", activeSubGraph.getId() + "+#" + n.getId());
 		}
 	}
 
@@ -602,10 +602,10 @@ public class GraphManager {
 			deselectNodesAfterEdgeCreation(lastClickedID);
 		lastClickedID = null;
 	}
-	
-	public void setActiveSubGraph(String id){
-		for (MyGraph subGraph: g.getAllSubGraphs()){
-			if (subGraph.getId().equals(id)){
+
+	public void setActiveSubGraph(String id) {
+		for (MyGraph subGraph : g.getAllSubGraphs()) {
+			if (subGraph.getId().equals(id)) {
 				activeSubGraph = subGraph;
 				return;
 			}

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

@@ -43,6 +43,9 @@ public class GraphMLImporter {
 		try {
 			fs.readAll(fileName);
 		} catch (IOException e) {
+			if (fileName.contains("shutdown.graphml")) {
+				return new MyGraph((fileName.split(".")[0]));
+			}
 			System.out.println("GraphML File doesn't exist or can't be opened");
 			e.printStackTrace();
 		}

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

@@ -29,6 +29,9 @@ public class MyFileSinkGraphML extends FileSinkGraphML {
 			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;
+				}
 				if (!graphAttributes.containsKey(j)) {
 					Object gValue = g.getAttribute(j);
 					String gType;
@@ -151,6 +154,9 @@ public class MyFileSinkGraphML extends FileSinkGraphML {
 
 			print("\t<graph id=\"%s\" edgedefault=\"undirected\">\n", escapeXmlString(g.getId()));
 			for (String k : g.getAttributeKeySet()) {
+				if (!isWritingMultigraph && (k.equals("layer") || k.equals("ui.stylesheet"))) {
+					continue;
+				}
 				print("\t\t\t<data key=\"%s\">%s</data>\n", graphAttributes.get(k),
 						escapeXmlString(g.getAttribute(k).toString()));
 			}

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

@@ -4,6 +4,7 @@ import java.math.BigDecimal;
 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.handlers.MyAnimationTimer;
 import javafx.animation.AnimationTimer;
@@ -351,4 +352,14 @@ public final class Main {
 		return result;
 	}
 
+	public void closeProgram() {
+		GraphMLExporter exp = new GraphMLExporter();
+		exp.writeGraph(GraphDisplayManager.getGraphManager(Layer.UNDERLAY).getGraph(), "underlay-shutdown.graphml",
+				false);
+		exp.writeGraph(GraphDisplayManager.getGraphManager(Layer.OPERATOR).getGraph(), "operator-shutdown.graphml",
+				false);
+
+		System.exit(0);
+	}
+
 }

+ 16 - 7
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/MainApp.java

@@ -4,7 +4,7 @@ import java.io.IOException;
 import java.net.URL;
 
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
-import de.tu_darmstadt.informatik.tk.scopviz.io.GraphMLExporter;
+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.css.CSSManager;
 import javafx.application.Application;
@@ -72,6 +72,20 @@ public class MainApp extends Application {
 			GraphDisplayManager.addGraph(Debug.getDefaultOperatorGraph(), true);
 			GraphDisplayManager.setCurrentLayer(Layer.UNDERLAY);
 			GraphDisplayManager.addGraph(Debug.getDefaultUnderlayGraph(), true);
+		} else {
+			GraphMLImporter imp = new GraphMLImporter();
+			GraphDisplayManager.setCurrentLayer(Layer.OPERATOR);
+			try {
+				GraphDisplayManager.addGraph(imp.readGraph("graph-1", "operator-shutdown.graphml"), true);
+			} catch (Exception e) {
+				Debug.out("INFORMATION: no previous operatorgraph", 1);
+			}
+			GraphDisplayManager.setCurrentLayer(Layer.UNDERLAY);
+			try {
+				GraphDisplayManager.addGraph(imp.readGraph("graph-2", "underlay-shutdown.graphml"), true);
+			} catch (Exception e) {
+				Debug.out("INFORMATION: no previous underlaygraph", 1);
+			}
 		}
 
 		CSSManager.addRule("node{text-alignment: at-right; size: 15px;}");
@@ -98,12 +112,7 @@ public class MainApp extends Application {
 		primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
 			@Override
 			public void handle(WindowEvent event) {
-				if (exportOnClose) {
-					GraphMLExporter exporter = new GraphMLExporter();
-					exporter.writeGraph(Main.getInstance().getGraphManager().getGraph(), "shutdown.graphml", false);
-				}
-
-				System.exit(0);
+				Main.getInstance().closeProgram();
 			}
 		});
 

+ 12 - 12
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/metrics/OperatorInfoMetric.java

@@ -12,7 +12,7 @@ import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.metrics.interfaces.ScopvizGraphMetric;
 import javafx.util.Pair;
 
-public class OperatorInfoMetric implements ScopvizGraphMetric{
+public class OperatorInfoMetric implements ScopvizGraphMetric {
 
 	@Override
 	public boolean isSetupRequired() {
@@ -23,34 +23,34 @@ public class OperatorInfoMetric implements ScopvizGraphMetric{
 	public String getName() {
 		return "Operator Info";
 	}
-	
+
 	@Override
 	public void setup() {
-		// No Setup needed.		
+		// No Setup needed.
 	}
-	
+
 	@Override
 	public LinkedList<Pair<String, String>> calculate(MyGraph g) {
-		LinkedList<Pair<String, String>> result = new LinkedList<Pair<String,String>>();
-		
-		for (MyGraph subGraph: g.getAllSubGraphs()){
-			if (subGraph.getAttribute("layer") == Layer.OPERATOR && !subGraph.isComposite()){
+		LinkedList<Pair<String, String>> result = new LinkedList<Pair<String, String>>();
+
+		for (MyGraph subGraph : g.getAllSubGraphs()) {
+			if (subGraph.getAttribute("layer") == Layer.OPERATOR && !subGraph.isComposite()) {
 				String graphId = subGraph.getId();
 				String info = "";
 				Double priority = Double.valueOf(subGraph.getAttribute("priority"));
 				boolean placed = fullyPlaced(subGraph, g);
-				
+
 				info = info.concat("Priority: " + priority.doubleValue());
-				if (placed){
+				if (placed) {
 					info = info.concat(", fully placed.");
 				} else {
 					info = info.concat(", not fully placed.");
 				}
-				
+
 				result.add(new Pair<String, String>(graphId, info));
 			}
 		}
-		
+
 		return result;
 	}
 

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

@@ -513,7 +513,8 @@ public final class ButtonManager {
 			Platform.runLater(() -> controller.opGraphSelectionBox.setValue(controller.opGraphSelectionBox.getItems()
 					.get(controller.opGraphSelectionBox.getItems().size() - 2)));
 		} else {
-			GraphDisplayManager.getGraphManager(Layer.OPERATOR).setActiveSubGraph(controller.opGraphSelectionBox.getValue());
+			GraphDisplayManager.getGraphManager(Layer.OPERATOR)
+					.setActiveSubGraph(controller.opGraphSelectionBox.getValue());
 			// FIXME: aktuell zu bearbeitenden graphen im GraphManager setzen
 			// (erfordert Jaschas Implementierung)!
 		}

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

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

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

@@ -84,7 +84,7 @@ public final class MenuBarManager {
 	 * Handler for the "quit" button.
 	 */
 	public static void quitAction(ActionEvent event) {
-		System.exit(0);
+		Main.getInstance().closeProgram();
 	}
 
 	/**

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

@@ -53,7 +53,7 @@ public class MetricboxManager {
 		metrics.add(new MetricRowData(new TaskFulfillmentMetric()));
 		metrics.add(new MetricRowData(new PlacementCostMetric()));
 		metrics.add(new MetricRowData(new CommunicationCostMetric()));
-		
+
 	}
 
 	/**