Procházet zdrojové kódy

Example.graphML
added (Example Graph)
GraphMLImporter
removed deprecated Code
no longer throws IOException
added Exception Handling

Jascha Bohne před 8 roky
rodič
revize
d942361e31

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

@@ -10,18 +10,16 @@ import org.graphstream.stream.file.*;
 
 public class GraphMLImporter {
 
-	public Graph readGraph(String fileName) throws IOException{
+	public Graph readGraph(String fileName) {
 		Graph g = new DefaultGraph("g");
 		FileSource fs = new FileSourceGraphML();
 		fs.addSink(g);
-		fs.readAll(fileName);
-		/*while (fs.nextEvents()) {
-			// Optionally some code here ...
+		try {
+			fs.readAll(fileName);
+		} catch (IOException e) {
+			System.out.println("GraphML File doesn't exist or can't be accessed");
+			e.printStackTrace();
 		}
-		if(fs!=null){
-			//fs.end();
-		}
-		fs.removeSink(g);*/
 		return g;
 	}
 }

+ 46 - 0
scopviz/src/main/resources/Example.graphml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
+	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	 xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
+	   http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
+	<key id="attr0000" for="node" attr.name="Eigenschaft" attr.type="string"/>
+	<key id="attr0001" for="node" attr.name="ui.label" attr.type="string"/>
+	<key id="attr0002" for="node" attr.name="y" attr.type="int"/>
+	<key id="attr0003" for="node" attr.name="x" attr.type="int"/>
+	<graph id="Example" edgedefault="undirected">
+		<node id="A">
+			<data key="attr0000">test</data>
+			<data key="attr0001">A</data>
+			<data key="attr0002">100</data>
+			<data key="attr0003">100</data>
+		</node>
+		<node id="B">
+			<data key="attr0001">B</data>
+			<data key="attr0002">200</data>
+			<data key="attr0003">100</data>
+		</node>
+		<node id="C">
+			<data key="attr0001">C</data>
+			<data key="attr0002">100</data>
+			<data key="attr0003">200</data>
+		</node>
+		<node id="D">
+			<data key="attr0001">D</data>
+			<data key="attr0002">200</data>
+			<data key="attr0003">200</data>
+		</node>
+		<node id="E">
+			<data key="attr0001">E</data>
+			<data key="attr0002">185</data>
+			<data key="attr0003">135</data>
+		</node>
+		<edge id="AB" source="A" target="B" directed="false">
+		</edge>
+		<edge id="BC" source="B" target="C" directed="false">
+		</edge>
+		<edge id="CD" source="C" target="D" directed="false">
+		</edge>
+		<edge id="DB" source="D" target="B" directed="false">
+		</edge>
+	</graph>
+</graphml>