Browse Source

added multiple export Types

fixed concurrentModification exception
jascha Bohne 8 years ago
parent
commit
94dc71ee1a

+ 27 - 6
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLExporter.java

@@ -34,15 +34,13 @@ public class GraphMLExporter {
 	 */
 	public void writeGraph(final MyGraph g, final String fileName) {
 		MyFileSinkGraphML writer = new MyFileSinkGraphML();
+		String newFileName = fileName;
 		if(g.isComposite()){
-			for(int i = 0; i < g.getChildren().toArray().length; i++){
-				writer.exportGraphs(g.getAllSubGraphs(), fileName);
-				return;
-			}
-			return;
+			writer.exportGraphs(g.getAllSubGraphs(), fileNameAppend(fileName, "appended"));
+			newFileName = fileNameAppend(fileName, "merged");
 		}
 		try {
-			writer.writeAll(g, new FileOutputStream(fileName));
+			writer.writeAll(g, new FileOutputStream(newFileName));
 		} catch (IOException e) {
 			System.out.println("cannot Acces File or invalid path");
 			e.printStackTrace();
@@ -72,4 +70,27 @@ public class GraphMLExporter {
 
 		}
 	}
+	
+	/** 
+	 * Appends a string to the fileName before the fileExtension
+	 * 
+	 * @param fileName the fileName
+	 * @param append the string that will be appended
+	 */
+	public String fileNameAppend(String fileName, String append){
+		String[] parts = fileName.split(".");
+		if (parts.length < 2) {
+			fileName = fileName.concat(append);
+		} else {
+			fileName = "";
+			int i = 0;
+			for (; i < parts.length-1; i++){
+				fileName = fileName.concat(parts[0]);
+			}
+			fileName.concat(append);
+			fileName.concat(parts[i]);
+		}
+		
+		return fileName;
+	}
 }

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

@@ -2,6 +2,7 @@ package de.tu_darmstadt.informatik.tk.scopviz.io;
 
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedList;
 
 import org.graphstream.graph.Edge;
@@ -214,14 +215,13 @@ public class MyFileSinkGraphML extends FileSinkGraphML{
 	 * 
 	 * @param graphs
 	 */
-	//TODO fileName as parameter
 	public void exportGraphs(LinkedList<MyGraph> graphs, String fileName){
-		for(MyGraph g : graphs){
-			if(g.isComposite()){
-				graphs.remove(g);
+		Iterator<MyGraph> graphIter = graphs.iterator();
+		while(graphIter.hasNext()){
+			if(graphIter.next().isComposite()){
+				graphIter.remove();
 			}
 		}
-		//TODO setup
 		try {
 			begin(fileName);
 			isWritingMultigraph = true;