Files
ecoparasite-data-analyse/src/ecoparasite/svg/SVGFactory.java
2026-04-08 14:47:42 +02:00

77 lines
1.7 KiB
Java

package ecoparasite.svg;
import ecoparasite.svg.elements.Element;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.UUID;
public class SVGFactory {
static final private String EXPORT_PATH = "export/";
static final private String EXTENSION = ".svg";
public static boolean createSVG(ArrayList<Element> mesElements){
String code = createSVGCode(mesElements);
try {
createFile(code);
} catch (Exception e) {
return false;
}
return true;
}
public static boolean createSVG(ArrayList<Element> mesElements, String filename) {
String code = createSVGCode(mesElements);
try {
createFile(code,filename);
} catch (Exception e) {
return false;
}
return true;
}
public static String createSVGCode(ArrayList<Element> mesElements){
String code = "<svg height=\"800\" width=\"800\" >";
for (Element e : mesElements){
code += e.toSVG();
}
code += "</svg>";
return code;
}
public static void createFile(String data) throws IOException {
String id = UUID.randomUUID().toString();
createFile(data,id);
}
public static void createFile(String data, String filename) throws IOException {
// create a FileWriter object with the file name
FileWriter writer = new FileWriter(EXPORT_PATH + filename + EXTENSION);
// write the string to the file
writer.write(data);
// close the writer
writer.close();
System.out.println("Successfully wrote text to file.");
}
}