-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShapeDataList.java
88 lines (68 loc) · 2.06 KB
/
ShapeDataList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.util.*;
import java.awt.geom.*;
import java.awt.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
import jankovicsandras.imagetracer.ImageTracer;
public class ShapeDataList implements Serializable {
static final long serialVersionUID = 1L;
private ArrayList<ShapeData> shapeDataList;
public ShapeDataList() {
shapeDataList = new ArrayList<>();
}
public ShapeData get(int n) {
return shapeDataList.get(n);
}
public Shape getShape(int n) {
return get(n).getShape();
}
public void add(ShapeData shapeData) {
if (shapeData.isEmpty()) return;
shapeDataList.add(shapeData);
}
public void draw(Graphics2D g2d) {
for (int i = 0; i < shapeDataList.size(); i++) {
ShapeData shapeData = shapeDataList.get(i);
shapeData.draw(g2d);
}
}
public void save(BufferedImage bImage) throws Exception {
System.out.println("saving image...");
Graphics g = bImage.getGraphics();
draw((Graphics2D)g);
String filename = System.nanoTime() + ".png";
File outputfile = new File(filename);
ImageIO.write(bImage, "png", outputfile);
System.out.println("saved at: " + outputfile.toString());
}
public void saveSVG(BufferedImage bImage) throws Exception {
System.out.println("saving image...");
Graphics g = bImage.getGraphics();
draw((Graphics2D)g);
String filename = System.nanoTime() + ".svg";
String svgString = ImageTracer.imageToSVG(bImage, null, null);
ImageTracer.saveString(filename,svgString);
System.out.println("saved at: " + filename);
}
public void removeLast() {
if (isEmpty()) return;
shapeDataList.remove(shapeDataList.size()-1);
}
public boolean isEmpty() {
if (shapeDataList == null || shapeDataList.isEmpty()) return true;
return false;
}
public void clear() {
shapeDataList.clear();
}
@Override
public String toString() {
String printString = "------------ShapedataList------------\n";
for (int i = 0; i < shapeDataList.size(); i++) {
ShapeData shapeData = shapeDataList.get(i);
printString += shapeData.toString() + "\n";
}
return printString;
}
}