Browse Source

Merge remote-tracking branch 'origin/Jascha'

Jan Enders 7 years ago
parent
commit
9c455b78bc

+ 19 - 6
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLImporter.java

@@ -46,24 +46,37 @@ public class GraphMLImporter {
 			e.printStackTrace();
 		}
 		fs.removeSink(g);
-		addDefaultAttributes(g);
+		handleAttributes(g);
 		return g;
 	}
 
 	/**
-	 * adds default values for typeofNode and typeofDevice to all Nodes
+	 * adds default values for typeofNode and typeofDevice to all Nodes 
+	 * and converts yEd attributes to regular ones
 	 * 
 	 * @param g
 	 *            the graph that the attributes will be added onto
 	 */
-	private void addDefaultAttributes(MyGraph g) {
+	private void handleAttributes(MyGraph g) {
 		for (Node n : g.getNodeSet()) {
-			if (!n.hasAttribute("typeOfNode")) {
-				n.addAttribute("typeOfNode", "standard");
+			if (!n.hasAttribute("typeofNode")) {
+				n.addAttribute("typeofNode", "standard");
 			}
 			if (!n.hasAttribute("typeofDevice")) {
 				n.addAttribute("typeofDevice", "unknown");
 			}
+			if (!n.hasAttribute("ui.label") && n.hasAttribute("yEd.label")){
+				n.addAttribute("ui.label", n.getAttribute("yEd.label").toString());
+				n.removeAttribute("yEd.label");
+			}
+			if (n.hasAttribute("yEd.x")){	
+				n.addAttribute("x", Double.parseDouble(n.getAttribute("yEd.x").toString()));
+				n.removeAttribute("yEd.x");
+			}
+			if (n.hasAttribute("yEd.y")){	
+				n.addAttribute("y", Double.parseDouble(n.getAttribute("yEd.y").toString()));
+				n.removeAttribute("yEd.y");
+			}
 		}
 	}
 
@@ -109,7 +122,7 @@ public class GraphMLImporter {
 			e.printStackTrace();
 		}
 		fs.removeSink(g);
-		addDefaultAttributes(g);
+		handleAttributes(g);
 		Debug.out(g.getId());
 		return g;
 	}

+ 16 - 14
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/MyFileSourceGraphML.java

@@ -57,6 +57,7 @@ import javax.xml.stream.events.XMLEvent;
 import org.graphstream.stream.file.FileSource;
 
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
+import de.tu_darmstadt.informatik.tk.scopviz.io.MyFileSourceGraphML.NodeAttribute.EndPointType;
 
 /**
  * GraphML is a comprehensive and easy-to-use file format for graphs. It
@@ -107,7 +108,11 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 	}
 
 	protected enum NodeAttribute {
-		ID
+		ID;
+
+		protected enum EndPointType {
+			IN, OUT, UNDIR
+		}
 	}
 
 	protected enum EdgeAttribute {
@@ -126,10 +131,6 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 		ID, NODE, PORT, TYPE
 	}
 
-	protected enum EndPointType {
-		IN, OUT, UNDIR
-	}
-
 	protected enum HyperEdgeAttribute {
 		ID
 	}
@@ -1130,7 +1131,7 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 			k = new Key();
 			k.def = null;
 			k.domain = KeyDomain.ALL;
-			k.name = "y";
+			k.name = "yEd.y";
 			k.type = KeyAttrType.DOUBLE;
 			yPosition.key = k;
 
@@ -1138,7 +1139,7 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 			k = new Key();
 			k.def = null;
 			k.domain = KeyDomain.ALL;
-			k.name = "x";
+			k.name = "yEd.x";
 			k.type = KeyAttrType.STRING;
 			data.key = k;
 
@@ -1167,7 +1168,7 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 			k = new Key();
 			k.def = null;
 			k.domain = KeyDomain.ALL;
-			k.name = "ui.label";
+			k.name = "yEd.label";
 			k.type = KeyAttrType.STRING;
 
 			StringBuffer buffer = new StringBuffer();
@@ -1350,7 +1351,7 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 					pushback(e);
 					data = parseYed();
 					if (data != null) {
-						if (data.key.name.equals("x")) {
+						if (data.key.name.equals("yEd.x")) {
 							sendNodeAttributeAdded(sourceId, id, yPosition.key.name, getValue(yPosition));
 							sentAttributes.add(yPosition.key);
 						}
@@ -1365,7 +1366,7 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 						pushback(yEd);
 						data = parseYed();
 						if (data != null) {
-							if (data.key.name.equals("x")) {
+							if (data.key.name.equals("yEd.x")) {
 								sendNodeAttributeAdded(sourceId, id, yPosition.key.name, getValue(yPosition));
 								sentAttributes.add(yPosition.key);
 							}
@@ -1390,10 +1391,11 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 			}
 		}
 
-		for (Key k : keys.values()) {
+		//TODO: see if this experimental fix breaks anything
+		/*for (Key k : keys.values()) {
 			if ((k.domain == KeyDomain.NODE || k.domain == KeyDomain.ALL) && !sentAttributes.contains(k))
 				sendNodeAttributeAdded(sourceId, id, k.name, getDefaultValue(k));
-		}
+		}*/
 
 		if (isEvent(e, XMLEvent.START_ELEMENT, "graph")) {
 			Location loc = e.getLocation();
@@ -1498,7 +1500,7 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 					pushback(e);
 					data = parseYed();
 					if (data != null) {
-						if (data.key.name.equals("x")) {
+						if (data.key.name.equals("yEd.x")) {
 							sendNodeAttributeAdded(sourceId, id, yPosition.key.name, getValue(yPosition));
 							sentAttributes.add(yPosition.key);
 						}
@@ -1515,7 +1517,7 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 						pushback(yEd);
 						data = parseYed();
 						if (data != null) {
-							if (data.key.name.equals("x")) {
+							if (data.key.name.equals("yEd.x")) {
 								sendNodeAttributeAdded(sourceId, id, yPosition.key.name, getValue(yPosition));
 								sentAttributes.add(yPosition.key);
 							}

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

@@ -532,9 +532,8 @@ public class GraphManager {
 	public void convertUiClass() {
 		Collection<Node> allNodes = g.getNodeSet();
 		for (Node n : allNodes) {
-			n.removeAttribute("typeofNode");
 			if (n.hasAttribute("typeofNode")) {
-				n.addAttribute("ui.class", n.getAttribute("typeofNode"));
+				n.addAttribute("ui.class", n.getAttribute("typeofNode").toString());
 			}
 		}
 	}

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

@@ -2,6 +2,8 @@ package de.tu_darmstadt.informatik.tk.scopviz.main;
 
 import java.util.LinkedList;
 
+import javax.swing.text.TableView.TableRow;
+
 import javafx.util.Pair;
 
 public interface ScopvizGraphMetric {
@@ -11,12 +13,17 @@ public interface ScopvizGraphMetric {
 	 * 
 	 * @param g
 	 *            a MyGraph
-	 * @return a pair that is displayed in the metrics window
+	 * @return a List of tableRows that will be displayed in the metrics window
 	 */
-	public LinkedList<Pair<String, String>> calculate(MyGraph g);
+	public LinkedList<TableRow> calculate(MyGraph g);
 
 	/**
 	 * returns the name of the Metric which will be displayed above the values
 	 */
-	public Pair<String, Object> getName();
+	public String getName();
+	
+	/**
+	 * sets up the metric for the first use
+	 */
+	public void setup();
 }

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

@@ -13,4 +13,14 @@ public interface ScopvizGraphOperator {
 	 *         g
 	 */
 	public LinkedList<MyGraph> calculate(MyGraph g);
+	
+	/**
+	 * returns the name of the Metric
+	 */
+	public String getName();
+	
+	/**
+	 * sets up the metric for the first use
+	 */
+	public void setup();
 }