-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDoilyArea.java
228 lines (175 loc) · 4.66 KB
/
DoilyArea.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**
* Created by Iason Koulas (ik5g15)
*/
import java.util.ArrayList;
import java.awt.image.BufferedImage;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class DoilyArea extends JPanel {
/**
* Get and Set methods
*/
private static final long serialVersionUID = 1L;
public Integer getPenSize() {
return penSize;
}
public void setPenSize(Integer penSize) {
this.penSize = penSize;
}
public Color getInkColor() {
return inkColor;
}
public void setInkColor(Color inkColor) {
this.inkColor = inkColor;
}
public Integer getNumberOfSectors() {
return numberOfSectors;
}
public void setNumberOfSectors(Integer numberOfSectors) {
this.numberOfSectors = numberOfSectors;
}
public double getAngleSectors() {
return angleSectors;
}
public void setAngleSectors(double angleSectors) {
this.angleSectors = angleSectors;
}
public boolean isToggleSectorLines() {
return toggleSectorLines;
}
public void setToggleSectorLines(boolean toggleSectorLines) {
this.toggleSectorLines = toggleSectorLines;
}
public boolean isReflectDrawing() {
return reflectDrawing;
}
public void setReflectDrawing(boolean reflectDrawing) {
this.reflectDrawing = reflectDrawing;
}
public BufferedImage getPaint() {
return paint;
}
public void setPaint(BufferedImage paint) {
this.paint = paint;
}
Stroke getPointList() {
return pointList;
}
public void setPointList(Stroke pointList) {
this.pointList = pointList;
}
public void setColorPointList(Color color) {
this.pointList.setColor(color);
}
public void setPenSizePointList(int size) {
this.pointList.setPenSize(size);
}
public void setRefPointList(boolean reflection) {
this.pointList.setReflected(reflection);
}
public ArrayList<Stroke> getStrokes() {
return strokes;
}
public void setStrokes(ArrayList<Stroke> strokes) {
this.strokes = strokes;
}
public void removeStrokes() {
this.strokes.clear();
}
public void removeStrokes(int index) {
this.strokes.remove(index);
}
// Adds the new point to the PointList
public void addPoint(MouseEvent e) {
if (numberOfSectors % 2 == 0) {
int tempY = e.getY() - getHeight() / 2;
int tempX = e.getX() - getWidth() / 2;
pointList.addPoint(new Point(-tempX, -tempY));
} else {
int tempY = e.getY() - getHeight() / 2;
int tempX = e.getX() - getWidth() / 2;
pointList.addPoint(new Point(tempX, tempY));
}
repaint();
}
private Integer penSize = 2;
private Color inkColor = Color.WHITE;
private Integer numberOfSectors = 6;
private double angleSectors = 360 / numberOfSectors;
private boolean toggleSectorLines = true;
private boolean reflectDrawing = false;
public BufferedImage paint;
public Stroke pointList = new Stroke(this);
public ArrayList<Stroke> strokes = new ArrayList<>();
public DoilyArea() {
super();
this.setBackground(Color.BLACK);
paint = new BufferedImage(600, 600, BufferedImage.TYPE_4BYTE_ABGR);
inkColor = Color.WHITE;
numberOfSectors = 6;
penSize = 2;
angleSectors = 360 / numberOfSectors;
addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
addPoint(e);
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
/**
* It creates a new list with for the next set of points (stroke)
* and saves the old one
*/
public void mouseReleased(MouseEvent e) {
strokes.add(pointList);
pointList = new Stroke(DoilyArea.this);
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
addPoint(e);
}
@Override
public void mouseMoved(MouseEvent e) {
}
});
}
public void paint(Graphics g) {
super.paint(g);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
g2d.translate(this.getWidth() / 2, this.getHeight() / 2);
// Draws the lines that divide the sectors
if (toggleSectorLines)
for (int i = 0; i < numberOfSectors; i++) {
g2d.setStroke(new BasicStroke(1));
g2d.setColor(Color.GREEN);
g2d.drawLine(0, 0, 0, -360);
g2d.rotate(Math.toRadians(angleSectors));
}
g2d.setStroke(new BasicStroke(penSize));
g2d.setColor(Color.BLACK);
for (int i = 0; i < strokes.size(); i++) {
strokes.get(i).drawStroke(g2d);
}
pointList.drawStroke(g2d);
}
public BufferedImage getScreenShot(JPanel panel) {
BufferedImage image = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB);
panel.paint(image.getGraphics());
return image;
}
}