Begin SVG.
This commit is contained in:
76
src/ecoparasite/svg/SVGFactory.java
Normal file
76
src/ecoparasite/svg/SVGFactory.java
Normal file
@@ -0,0 +1,76 @@
|
||||
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.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user