Browse Source

bug fixes and Attribute checking

GraphMLExporter
	now removes ui.class
	now removes all Attributes that are not a String or primitive and logs 
it

GraphMlImporter
	now adds default values for typeofNode and typeofDevice if they are
nonexistant

updated convertuiclass() to new symbol layer version

Bug fixes:
	fixed a null pointer when deselecting after deleting
	
minor:
	updated Documentation on a few classes
	formated and organized imports
Jascha Bohne 7 years ago
parent
commit
97fcfe9ae8

+ 1 - 0
scopviz/.gitignore

@@ -5,3 +5,4 @@
 /Labels.png
 /testImporter-multigraph.graphml
 /testImporter.graphml
+/asdf.fdsa

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

@@ -9,6 +9,7 @@ import org.graphstream.graph.Graph;
 import org.graphstream.graph.Node;
 import org.graphstream.stream.file.FileSinkGraphML;
 
+import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import javafx.stage.FileChooser;
 import javafx.stage.Stage;
@@ -51,6 +52,7 @@ public class GraphMLExporter {
 	 *            The parent window of the save Window
 	 */
 	public void writeGraph(final Graph g, final Stage stage) {
+		g.getEdge(0).addAttribute("asd", g);
 		clearAttributes(g);
 		String fileName;
 		FileChooser fileChooser = new FileChooser();
@@ -66,7 +68,8 @@ public class GraphMLExporter {
 
 	/**
 	 * Cleans up the Attributes of all Nodes and Edges of a given Graph,
-	 * removing the ui.j2dsk Attribute.
+	 * removing the ui.j2dsk and ui.class Attribute.
+	 * also removes all Attributesthat are not a String or (a Wrapper of) a primitive type
 	 * 
 	 * @param g
 	 *            the Graph to clean up
@@ -76,11 +79,35 @@ public class GraphMLExporter {
 		while (edges.hasNext()) {
 			Edge e = edges.next();
 			e.removeAttribute("ui.j2dsk");
+			for(String s : e.getEachAttributeKey()){
+				Class<? extends Object> c = e.getAttribute(s).getClass();
+				if(!c.isPrimitive() && !(c == String.class) && !(c == Character.class) && !(c == Boolean.class)
+						&& !(c == Integer.class) && !(c == Long.class) && !(c == Short.class) && !(c == Byte.class)
+						&& !(c == Float.class) && !(c == Double.class)){
+					Debug.out("Could not parse an Attribute because it is not Primitive or a String \n\t"
+							+ "(Attribute: " + s 
+							+ ", Value: " + e.getAttribute(s)  
+							+ ", from Edge: " + e 
+							+ ", Type: " + c + ") ");
+				}
+			}
 		}
 		Iterator<? extends Node> nodes = g.getNodeIterator();
 		while (nodes.hasNext()) {
 			Node n = nodes.next();
 			n.removeAttribute("ui.j2dsk");
+			n.removeAttribute("ui.class");
+			for(String s : n.getEachAttributeKey()){
+				Class<? extends Object> c = n.getAttribute(s).getClass();
+				if(!c.isPrimitive() && !(c == String.class) && !(c == Character.class) && !(c == Boolean.class)
+						&& !(c == Integer.class) && !(c == Long.class) && !(c == Short.class) && !(c == Byte.class)
+						&& !(c == Float.class) && !(c == Double.class)){
+					Debug.out("Could not parse an Attribute because it is not Primitive or a String \n\t"
+							+ "(Attribute: " + s 
+							+ ", Value: " + n.getAttribute(s)  
+							+ ", from Node: " + n 
+							+ ", Type: " + c + ") ");
+				}
 		}
 	}
 }

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

@@ -4,6 +4,7 @@ import java.io.IOException;
 import java.net.URL;
 import java.util.LinkedList;
 
+import org.graphstream.graph.Node;
 import org.graphstream.graph.implementations.SingleGraph;
 
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
@@ -44,9 +45,27 @@ public class GraphMLImporter {
 			e.printStackTrace();
 		}
 		fs.removeSink(g);
+		addDefaultAttributes(g);
 		return g;
 	}
 
+	/**
+	 * adds default values for typeofNode and typeofDevice to all Nodes
+	 * 
+	 * @param g
+	 *            the graph that the attributes will be added onto
+	 */
+	private void addDefaultAttributes(MyGraph g) {
+		for (Node n : g.getNodeSet()) {
+			if (!n.hasAttribute("typeOfNode")) {
+				n.addAttribute("typeOfNode", "standard");
+			}
+			if (!n.hasAttribute("typeofDevice")) {
+				n.addAttribute("typeofDevice", "unknown");
+			}
+		}
+	}
+
 	/**
 	 * Imports a GraphML file. Opens a open dialog. Returns null if the process
 	 * is aborted.
@@ -89,6 +108,7 @@ public class GraphMLImporter {
 			e.printStackTrace();
 		}
 		fs.removeSink(g);
+		addDefaultAttributes(g);
 		return g;
 	}
 

+ 12 - 5
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/MyFileSourceGraphML.java

@@ -1,4 +1,6 @@
-/*
+/*This is a modified version of the class org.graphstream.stream.file.FileSourceGraphML
+ * It was modified by Jascha Bohne <jaschabohne@web.de> for use in the scopviz project 
+ * 
  * Copyright 2006 - 2015
  *     Stefan Balev     <stefan.balev@graphstream-project.org>
  *     Julien Baudry    <julien.baudry@graphstream-project.org>
@@ -570,9 +572,8 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 
 	// TODO: handle malformed files on state switches
 	/**
-	 * <pre>
-	 * <!ELEMENT graphml  ((desc)?,(key)*,((data)|(graph))*)>
-	 * </pre>
+	 * parses a Stream of xml Events to a graphstream graph it has limited
+	 * support for yEd attributes
 	 * 
 	 * @throws IOException
 	 * @throws XMLStreamException
@@ -1094,8 +1095,14 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 		return d;
 	}
 
+	// TODO color parsing
 	/**
-	 * Parses a yEdattribute returns null if the Attribute is unknown.
+	 * Parses a yEdattribute. returns null if the Attribute is unknown.
+	 * 
+	 * The known Attributes are:
+	 * <li>position of nodes</li>
+	 * <li>The label of Nodes</li>
+	 * <li>color of nodes</li>
 	 * 
 	 * @return the parsed yEd Attribute as a Data object
 	 * @throws IOException

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

@@ -1,4 +1,7 @@
-/*
+/*This is a modified version of the class org.graphstream.stream.SourceBase
+ * It was modified by Jascha Bohne <jaschabohne@web.de> for use in the scopviz project
+ * This class is based on the 1.3 release of graphstream 
+ *
  * Copyright 2006 - 2015
  *     Stefan Balev     <stefan.balev@graphstream-project.org>
  *     Julien Baudry    <julien.baudry@graphstream-project.org>

+ 10 - 25
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/GraphManager.java

@@ -17,7 +17,6 @@ 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.handlers.MyMouseManager;
-import scala.xml.MalformedAttributeException;
 
 /**
  * Interface between GUI and internal Graph representation. Manages internal
@@ -96,7 +95,6 @@ public class GraphManager {
 		// and need the Node to still be in the Graph
 		deleteEdgesOfNode(id);
 		deletedNode = g.removeNode(id);
-		// System.out.println("test-del");
 	}
 
 	/**
@@ -108,6 +106,7 @@ public class GraphManager {
 	 *            the ID of the Edge that will be removed
 	 */
 	public void deleteEdge(final String id) {
+		deselect();
 		deletedEdges.removeAll(deletedEdges);
 		deletedNode = null;
 		deletedEdges.add(g.removeEdge(id));
@@ -122,6 +121,7 @@ public class GraphManager {
 	 *            the Id of the Node, whose Edges shall be removed
 	 */
 	public void deleteEdgesOfNode(final String id) {
+		deselect();
 		Node node = g.getNode(id);
 		deletedEdges.removeAll(deletedEdges);
 		deletedNode = null;
@@ -516,38 +516,23 @@ public class GraphManager {
 	}
 
 	/**
-	 * Updates the implicit Stylesheet, causing any changes to it to come into effect.
+	 * Updates the implicit Stylesheet, causing any changes to it to come into
+	 * effect.
 	 */
 	public void updateStylesheet() {
 		setStylesheet(this.stylesheet);
 	}
-	
+
 	/**
-	 * Sets typeofNode or typeofDevice as the ui.class of all Nodes depending on the layer.
+	 * Sets typeofNode as the ui.class of all Nodes.
 	 * 
-	 * <li>Underlay uses typeofNode</li>
-	 * <li>Operator uses typeofNode</li>
-	 * <li>Mapping uses typeofNode</li>
-	 * <li>Symbol Representation uses typeofDevice</li>
 	 */
-	public void convertUiClass (){
+	public void convertUiClass() {
 		Collection<Node> allNodes = g.getNodeSet();
-		for(Node n : allNodes) {
+		for (Node n : allNodes) {
 			n.removeAttribute("typeofNode");
-			switch ((Layer) g.getAttribute("layer")){
-			case UNDERLAY:
-			case OPERATOR:
-			case MAPPING:
-				if(n.hasAttribute("typeofNode")){
-					n.addAttribute("ui.class", n.getAttribute("typeofNode"));
-				}
-				break;
-			case SYMBOL:
-				if(n.hasAttribute("typeofDevice")){
-					n.addAttribute("ui.class", n.getAttribute("typeofDevice"));
-				}
-				break;
-			default: throw new MalformedAttributeException("This graph has is attached to an invalid layer");
+			if (n.hasAttribute("typeofNode")) {
+				n.addAttribute("ui.class", n.getAttribute("typeofNode"));
 			}
 		}
 	}

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

@@ -177,7 +177,7 @@ public final class GraphDisplayManager {
 			// return theIdOfTheMergedGraph;
 		}
 
-		//set ui.class
+		// set ui.class
 		v.convertUiClass();
 		// set basic style
 		v.setStylesheet(OptionsManager.DEFAULT_STYLESHEET);