Browse Source

added stylesheetManager, MetricInterface

also did other stuff
Jascha Bohne 8 years ago
parent
commit
3238c91032

+ 26 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLExporter.java

@@ -3,6 +3,7 @@ package de.tu_darmstadt.informatik.tk.scopviz.io;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.LinkedList;
 
 import org.graphstream.graph.Edge;
 import org.graphstream.graph.Graph;
@@ -108,6 +109,30 @@ public class GraphMLExporter {
 							+ ", from Node: " + n 
 							+ ", Type: " + c + ") ");
 				}
+			}
 		}
 	}
-}
+
+	public void writeMapping(Graph underlay, Graph operator, LinkedList<? extends Edge> mappingEdges, Stage parentWindow){
+		String fileName, underlayId, operatorId;
+		String underlayFile = "underlay_Temp_" + Math.random() + ".graphml";
+		String operatorFile = "operator_Temp_" + Math.random() + ".graphml";
+		String edgesFile = "edges_Temp_" + Math.random() + ".graohml";
+		FileChooser fileChooser = new FileChooser();
+		fileChooser.setTitle("Saving graph");
+		
+		underlayId = underlay.getId();
+		writeGraph(underlay, underlayFile);
+		operatorId = operator.getId();
+		writeGraph(operator, operatorFile);
+		writeMappingEdges(mappingEdges, edgesFile);
+		
+		fileName = fileChooser.showSaveDialog(parentWindow).getPath();
+		
+		
+	}
+	
+	private void writeMappingEdges(LinkedList<? extends Edge> mappingEdges, String fileName){
+		
+	}
+}

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

@@ -7,6 +7,7 @@ import java.util.LinkedList;
 import org.graphstream.graph.Node;
 import org.graphstream.graph.implementations.SingleGraph;
 
+import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.main.MyGraph;
 import javafx.stage.FileChooser;
@@ -109,6 +110,7 @@ public class GraphMLImporter {
 		}
 		fs.removeSink(g);
 		addDefaultAttributes(g);
+		Debug.out(g.getId());
 		return g;
 	}
 

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

@@ -16,6 +16,7 @@ import org.graphstream.ui.view.ViewerPipe;
 
 import de.tu_darmstadt.informatik.tk.scopviz.ui.OptionsManager;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.PropertiesManager;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.StylesheetManager;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyMouseManager;
 
 /**
@@ -488,8 +489,8 @@ public class GraphManager {
 		this.stylesheet = stylesheet;
 		g.removeAttribute("ui.stylesheet");
 		String completeStylesheet = stylesheet;
-		completeStylesheet = completeStylesheet.concat(OptionsManager.getNodeGraphics());
-		completeStylesheet = completeStylesheet.concat(OptionsManager.getLayerStyle((Layer) g.getAttribute("layer")));
+		completeStylesheet = completeStylesheet.concat(StylesheetManager.getNodeGraphics());
+		completeStylesheet = completeStylesheet.concat(StylesheetManager.getLayerStyle((Layer) g.getAttribute("layer")));
 		g.addAttribute("ui.stylesheet", completeStylesheet);
 	}
 

+ 20 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/ScopvizGraphMetric.java

@@ -0,0 +1,20 @@
+package de.tu_darmstadt.informatik.tk.scopviz.main;
+
+import java.util.LinkedList;
+
+import javafx.util.Pair;
+
+public interface ScopvizGraphMetric {
+	
+	/**
+	 * calculate the metric on the graph
+	 * @param g a MyGraph
+	 * @return a pair that is displayed in the metrics window
+	 */
+	public LinkedList<Pair<String, String>> calculate (MyGraph g);
+	
+	/**
+	 * returns the name of the Metric which will be displayed above the values
+	 */
+	public Pair<String, Object> getName();
+}

+ 13 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/ScopvizGraphOperator.java

@@ -0,0 +1,13 @@
+package de.tu_darmstadt.informatik.tk.scopviz.main;
+
+import java.util.LinkedList;
+
+public interface ScopvizGraphOperator {
+
+	/**
+	 * calculates a new Version of the Graph using the given operator
+	 * @param g a MyGraph
+	 * @return a list of Graphs that is the result of the operator on the Graph g
+	 */
+	public LinkedList<MyGraph> calculate(MyGraph g);
+}

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

@@ -180,7 +180,7 @@ public final class GraphDisplayManager {
 		// set ui.class
 		v.convertUiClass();
 		// set basic style
-		v.setStylesheet(OptionsManager.DEFAULT_STYLESHEET);
+		v.setStylesheet(StylesheetManager.DEFAULT_STYLESHEET);
 		// display the graph
 		vList.add(v);
 		switchActiveGraph();
@@ -325,7 +325,7 @@ public final class GraphDisplayManager {
 			mapping = new MappingGraphManager(g, underlay, operator);
 			g.addAttribute("layer", Layer.MAPPING);
 			g.addAttribute("ui.antialias");
-			mapping.setStylesheet(OptionsManager.DEFAULT_STYLESHEET);
+			mapping.setStylesheet(StylesheetManager.DEFAULT_STYLESHEET);
 			vList.add(mapping);
 
 			underlay.addEdgeCreatedListener(mapping);

+ 7 - 137
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/OptionsManager.java

@@ -2,9 +2,6 @@ package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
 import java.util.ArrayList;
 
-import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
-import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
-import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import javafx.application.Platform;
 import javafx.collections.FXCollections;
 import javafx.geometry.Insets;
@@ -24,45 +21,16 @@ import javafx.scene.layout.GridPane;
  * @version 1.0.0.0
  */
 public final class OptionsManager {
-	/**
-	 * all available graphic styles
-	 */
-	private static String[] allNodeGraphics = { "Shapes", "Sprites" };
-	/**
-	 * 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"
-			+ "edge{text-offset: 4px,-4px;}";
-	/**
-	 * Part of the stylesheet that styles the different Nodes with shapes.
-	 */
-	public static final String STYLE_NODES_SHAPES = "node.standard{shape: circle;}" + "node.source{shape: rounded-box;}"
-			+ "node.procEn{shape: diamond;}" + "node.sink{shape: cross;}";
-	/**
-	 * Part of the stylesheet that styles the different Nodes with sprites.
-	 */
-	public static final String STYLE_NODES_SPRITES = "node.standard{fill-mode: image-scaled; fill-image: url('src/main/resources/png/standard.png'); }"
-			+ "node.source{fill-mode: image-scaled; fill-image: url('src/main/resources/png/source.png'); }"
-			+ "node.procEn{fill-mode: image-scaled; fill-image: url('src/main/resources/png/procEn.png'); }"
-			+ "node.sink{fill-mode: image-scaled; fill-image: url('src/main/resources/png/sink.png'); }"
-			+ "node.operator{fill-mode: image-scaled; fill-image: url('src/main/resources/png/operator.png'); }";
-
 	// SETTINGS
 	/** The Default Weight for all new Edges. */
 	private static int defaultWeight = 0;
 	/** Flag whether to show the weight labels on Edges. */
 	private static boolean showWeight = true;
-	/** The currently selected Display Mode */
-	private static String nodeGraphics = allNodeGraphics[1];
-	/** The currently active Stylesheet. */
-	private static String nodeStylesheet = STYLE_NODES_SPRITES;
-
 	// Layer stylesheets
-	private static String styleLayerUnderlay = "";
-	private static String styleLayerOperator = "";
-	private static String styleLayerMapping = "";
-	private static String styleLayerSymbol = "";
+	static String styleLayerUnderlay = "";
+	static String styleLayerOperator = "";
+	static String styleLayerMapping = "";
+	static String styleLayerSymbol = "";
 
 	/**
 	 * Private Constructor to prevent Instantiation.
@@ -95,8 +63,8 @@ public final class OptionsManager {
 		showWeightButton.setSelected(showWeight);
 
 		ChoiceBox<String> nodeGraphicsSelector = new ChoiceBox<String>();
-		nodeGraphicsSelector.setItems(FXCollections.observableArrayList(allNodeGraphics[0], allNodeGraphics[1]));
-		nodeGraphicsSelector.getSelectionModel().select(nodeGraphics);
+		nodeGraphicsSelector.setItems(FXCollections.observableArrayList(StylesheetManager.getAllNodeGraphics()[0], StylesheetManager.getAllNodeGraphics()[1]));
+		nodeGraphicsSelector.getSelectionModel().select(StylesheetManager.getNodeGraphics());
 		;
 
 		// position elements on grid
@@ -120,7 +88,7 @@ public final class OptionsManager {
 				} catch (NumberFormatException e) {
 				}
 				showWeight = showWeightButton.isSelected();
-				adjustNodeGraphics(nodeGraphicsSelector.getValue());
+				StylesheetManager.adjustNodeGraphics(nodeGraphicsSelector.getValue());
 				return null;
 			} else
 				return null;
@@ -130,35 +98,6 @@ public final class OptionsManager {
 
 	}
 
-	/**
-	 * Changes the Stylesheet and updates all Nodes to use it.
-	 * 
-	 * @param newGraphics
-	 *            the new Stylesheet to use
-	 */
-	public static void adjustNodeGraphics(String newGraphics) {
-		if (!newGraphics.equalsIgnoreCase(nodeGraphics)) {
-			nodeGraphics = newGraphics;
-			if (newGraphics.equals(allNodeGraphics[0])) {
-				setNodeGraphics(STYLE_NODES_SHAPES);
-			} else if (newGraphics.equals(allNodeGraphics[1])) {
-				setNodeGraphics(STYLE_NODES_SPRITES);
-			} else {
-				throw new RuntimeException("These graphics do not exist");
-			}
-		}
-		Main.getInstance().getGraphManager().updateStylesheet();
-	}
-
-	/**
-	 * Returns all available Stylesheets as Strings.
-	 * 
-	 * @return all the StyleSheets
-	 */
-	public static String[] getAllNodeGraphics() {
-		return allNodeGraphics;
-	}
-
 	/**
 	 * Returns the default weight for new Edges.
 	 * 
@@ -197,73 +136,4 @@ public final class OptionsManager {
 		OptionsManager.showWeight = showWeight;
 	}
 
-	/**
-	 * Returns the currently active StyleSheet.
-	 * 
-	 * @return the currently active StyleSheet as a String
-	 */
-	public static String getNodeGraphics() {
-		return nodeStylesheet;
-	}
-
-	/**
-	 * Sets the current Stylesheet.
-	 * 
-	 * @param nodeGraphics
-	 *            the Stylesheet to use
-	 */
-	public static void setNodeGraphics(String nodeGraphics) {
-		OptionsManager.nodeStylesheet = nodeGraphics;
-	}
-
-	/**
-	 * Returns the styleSheet for a given Layer
-	 * 
-	 * @param l
-	 *            the Layer
-	 * @return the Stylesheet
-	 */
-	public static String getLayerStyle(Layer l) {
-		switch (l) {
-		case UNDERLAY:
-			return styleLayerUnderlay;
-		case OPERATOR:
-			return styleLayerOperator;
-		case MAPPING:
-			return styleLayerMapping;
-		case SYMBOL:
-			return styleLayerSymbol;
-		default:
-			Debug.out("OptionsManager: Stylesheet for an unknown Layer Requested");
-			return "";
-		}
-	}
-
-	/**
-	 * Sets the Stylesheet for a given Layer
-	 * 
-	 * @param l
-	 *            the Layer
-	 * @param newStyle
-	 *            the Stylesheet
-	 */
-	public static void setLayerStyle(Layer l, String newStyle) {
-		switch (l) {
-		case UNDERLAY:
-			styleLayerUnderlay = newStyle;
-			break;
-		case OPERATOR:
-			styleLayerOperator = newStyle;
-			break;
-		case MAPPING:
-			styleLayerMapping = newStyle;
-			break;
-		case SYMBOL:
-			styleLayerSymbol = newStyle;
-			break;
-		default:
-			Debug.out("OptionsManager: Stylesheet for an unknown Layer Requested");
-		}
-	}
-
 }

+ 135 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/StylesheetManager.java

@@ -0,0 +1,135 @@
+package de.tu_darmstadt.informatik.tk.scopviz.ui;
+
+import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
+import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
+import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
+
+public class StylesheetManager {
+
+	/**
+	 * all available graphic styles
+	 */
+	private static String[] allNodeGraphics = { "Shapes", "Sprites" };
+	/**
+	 * 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"
+			+ "edge{text-offset: 4px,-4px;}";
+	/**
+	 * Part of the stylesheet that styles the different Nodes with shapes.
+	 */
+	public static final String STYLE_NODES_SHAPES = "node.standard{shape: circle;}" + "node.source{shape: rounded-box;}"
+			+ "node.procEn{shape: diamond;}" + "node.sink{shape: cross;}";
+	/**
+	 * Part of the stylesheet that styles the different Nodes with sprites.
+	 */
+	public static final String STYLE_NODES_SPRITES = "node.standard{fill-mode: image-scaled; fill-image: url('src/main/resources/png/standard.png'); }"
+			+ "node.source{fill-mode: image-scaled; fill-image: url('src/main/resources/png/source.png'); }"
+			+ "node.procEn{fill-mode: image-scaled; fill-image: url('src/main/resources/png/procEn.png'); }"
+			+ "node.sink{fill-mode: image-scaled; fill-image: url('src/main/resources/png/sink.png'); }"
+			+ "node.operator{fill-mode: image-scaled; fill-image: url('src/main/resources/png/operator.png'); }";
+	/** The currently selected Display Mode */
+	private static String nodeGraphics = allNodeGraphics[1];
+	/** The currently active Stylesheet. */
+	private static String nodeStylesheet = STYLE_NODES_SPRITES;
+
+	/**
+	 * Changes the Stylesheet and updates all Nodes to use it.
+	 * 
+	 * @param newGraphics
+	 *            the new Stylesheet to use
+	 */
+	public static void adjustNodeGraphics(String newGraphics) {
+		if (!newGraphics.equalsIgnoreCase(StylesheetManager.nodeGraphics)) {
+			StylesheetManager.nodeGraphics = newGraphics;
+			if (newGraphics.equals(StylesheetManager.allNodeGraphics[0])) {
+				StylesheetManager.setNodeGraphics(StylesheetManager.STYLE_NODES_SHAPES);
+			} else if (newGraphics.equals(StylesheetManager.allNodeGraphics[1])) {
+				StylesheetManager.setNodeGraphics(StylesheetManager.STYLE_NODES_SPRITES);
+			} else {
+				throw new RuntimeException("These graphics do not exist");
+			}
+		}
+		Main.getInstance().getGraphManager().updateStylesheet();
+	}
+
+	/**
+	 * Returns all available Stylesheets as Strings.
+	 * 
+	 * @return all the StyleSheets
+	 */
+	public static String[] getAllNodeGraphics() {
+		return StylesheetManager.allNodeGraphics;
+	}
+
+	/**
+	 * Returns the currently active StyleSheet.
+	 * 
+	 * @return the currently active StyleSheet as a String
+	 */
+	public static String getNodeGraphics() {
+		return StylesheetManager.nodeStylesheet;
+	}
+
+	/**
+	 * Sets the current Stylesheet.
+	 * 
+	 * @param nodeGraphics
+	 *            the Stylesheet to use
+	 */
+	public static void setNodeGraphics(String nodeGraphics) {
+		StylesheetManager.nodeStylesheet = nodeGraphics;
+	}
+
+	/**
+	 * Returns the styleSheet for a given Layer
+	 * 
+	 * @param l
+	 *            the Layer
+	 * @return the Stylesheet
+	 */
+	public static String getLayerStyle(Layer l) {
+		switch (l) {
+		case UNDERLAY:
+			return OptionsManager.styleLayerUnderlay;
+		case OPERATOR:
+			return OptionsManager.styleLayerOperator;
+		case MAPPING:
+			return OptionsManager.styleLayerMapping;
+		case SYMBOL:
+			return OptionsManager.styleLayerSymbol;
+		default:
+			Debug.out("OptionsManager: Stylesheet for an unknown Layer Requested");
+			return "";
+		}
+	}
+
+	/**
+	 * Sets the Stylesheet for a given Layer
+	 * 
+	 * @param l
+	 *            the Layer
+	 * @param newStyle
+	 *            the Stylesheet
+	 */
+	public static void setLayerStyle(Layer l, String newStyle) {
+		switch (l) {
+		case UNDERLAY:
+			OptionsManager.styleLayerUnderlay = newStyle;
+			break;
+		case OPERATOR:
+			OptionsManager.styleLayerOperator = newStyle;
+			break;
+		case MAPPING:
+			OptionsManager.styleLayerMapping = newStyle;
+			break;
+		case SYMBOL:
+			OptionsManager.styleLayerSymbol = newStyle;
+			break;
+		default:
+			Debug.out("OptionsManager: Stylesheet for an unknown Layer Requested");
+		}
+	}
+
+}