933d00ad
rlentieu
add JPaint
|
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
* SubToolBox contains special features for certain differnet tools. Such as
* setting the line width, setting the radius of the spray, choosing a brush,
* selecting whether you want to draw a normal, outline or filled shape.
*/
public class SubToolBox extends JPanel
{
private JButton current;
/** Creates a default SubToolBox. **/
public SubToolBox()
{
// sets the default stuff and then starts off the choose panel method
setSize(40,66);
setLayout(null);
setVisible(true);
choosePanel();
}
/** Handles a switch in the toolbox panel with the corresponding tool. **/
public void choosePanel()
{
// removes the current panel and adds the one corresponding to the selected tool.
removeAll();
int tbs = ToolBox.toolSelected;
if(tbs == ToolBox.RECTANGLE || tbs == ToolBox.OVAL || tbs == ToolBox.ROUNDRECTANGLE)
shapePanel();
else if(tbs == ToolBox.LINE)
linePanel();
else if(tbs == ToolBox.SPRAY)
sprayPanel();
else if(tbs == ToolBox.BRUSH)
brushPanel();
else if(tbs == ToolBox.DRAG)
dragPanel();
else if(tbs == ToolBox.RANDOMDRAW)
randomPanel();
repaint();
}
/** Allows user to select settings for drawing random lines. **/
public void randomPanel()
{
JTextField field = new JTextField();
JButton submit = new JButton();
field.setBounds(25,0,40,22);
submit.setBounds(25,22,40,22);
add(field);
add(submit);
submit.addActionListener(new JRandom(field));
}
/** Allows the user to set the thickness of a line. **/
public void linePanel()
{
// creates a textbox and a button to submit the size of the line
JTextField field = new JTextField();
JButton submit = new JButton();
field.setBounds(25,0,40,22);
submit.setBounds(25,22,40,22);
add(field);
add(submit);
submit.addActionListener(new JTextListener(field));
}
/** Allows the user to set the size of the spray. **/
public void sprayPanel()
{
// creates a field to set the size of the spray
JTextField field = new JTextField();
JButton submit = new JButton();
field.setBounds(25,0,40,22);
submit.setBounds(25,22,40,22);
add(field);
add(submit);
submit.addActionListener(new JSprayListener(field));
}
/** Allows the user to select the item to drag. **/
public void dragPanel()
{
JButton rect = new JButton(new ImageIcon("Images//box.gif"));
JButton oval = new JButton(new ImageIcon("Images//oval.gif"));
rect.setSelectedIcon(new ImageIcon("Images//boxPressed.gif"));
oval.setSelectedIcon(new ImageIcon("Images//ovalPressed.gif"));
rect.setBounds(25,0,40,22);
oval.setBounds(25,22,40,22);
add(rect);
add(oval);
rect.addActionListener(new RectListener(rect));
oval.addActionListener(new OvalListener(oval));
JButton line = new JButton(new ImageIcon("Images//line.gif"));
line.setSelectedIcon(new ImageIcon("Images//linePressed.gif"));
line.setBounds(25,44,40,22);
add(line);
line.addActionListener(new LineListener(line));
setCurrent(line);
DrawingCanvas.extraOperations = DrawingCanvas.LINE;
}
/** Allows the user to select a style of brush. **/
public void brushPanel()
{
// loads up the images when its pressed and when its not and sets
// its location and adds it to the screen.
JButton rect = new JButton(new ImageIcon("Images//box.gif"));
JButton oval = new JButton(new ImageIcon("Images//oval.gif"));
rect.setSelectedIcon(new ImageIcon("Images//boxPressed.gif"));
oval.setSelectedIcon(new ImageIcon("Images//ovalPressed.gif"));
rect.setBounds(25,0,40,22);
oval.setBounds(25,22,40,22);
add(rect);
add(oval);
rect.addActionListener(new RectListener(rect));
oval.addActionListener(new OvalListener(oval));
setCurrent(rect);
DrawingCanvas.extraOperations = DrawingCanvas.RECT;
}
/** Creates a shapes panel and allows the user to choose the type. **/
public void shapePanel()
{
// loads up the images when its pressed and when its not and sets
// its location and adds it to the screen.
JButton normal = new JButton(new ImageIcon("Images//normal.gif"));
JButton fill = new JButton(new ImageIcon("Images//fill.gif"));
JButton outline = new JButton(new ImageIcon("Images//outline.gif"));
normal.setSelectedIcon(new ImageIcon("Images//normalPressed.gif"));
fill.setSelectedIcon(new ImageIcon("Images//fillPressed.gif"));
outline.setSelectedIcon(new ImageIcon("Images//outlinePressed.gif"));
normal.setBounds(25,0,40,22);
fill.setBounds(25,22,40,22);
outline.setBounds(25,44,40,22);
add(normal);
add(fill);
add(outline);
normal.addActionListener(new NormalListener(normal));
fill.addActionListener(new FillListener(fill));
outline.addActionListener(new OutlineListener(outline));
setCurrent(normal);
DrawingCanvas.extraOperations = DrawingCanvas.NORMAL;
}
/** Sets the current special selection to the field. **/
public void setCurrent(JButton b)
{
current = b;
current.setSelected(true);
}
/** Rectangle Listener, if button is pressed change field. **/
public class RectListener implements ActionListener
{
private JButton b;
public RectListener(JButton b){this.b=b;}
public void actionPerformed(ActionEvent e)
{
current.setSelected(false);
setCurrent(b);
DrawingCanvas.extraOperations = DrawingCanvas.RECT;
}
}
/** Oval Listener, if button is pressed change field. **/
public class OvalListener implements ActionListener
{
private JButton b;
public OvalListener(JButton b){this.b=b;}
public void actionPerformed(ActionEvent e)
{
current.setSelected(false);
setCurrent(b);
DrawingCanvas.extraOperations = DrawingCanvas.OVAL;
}
}
/** Line Listener, if button is pressed change field. **/
public class LineListener implements ActionListener
{
private JButton b;
public LineListener(JButton b){this.b=b;}
public void actionPerformed(ActionEvent e)
{
current.setSelected(false);
setCurrent(b);
DrawingCanvas.extraOperations = DrawingCanvas.LINE;
}
}
/** Spray Listener, changes size of spray and brush. **/
public class JSprayListener implements ActionListener
{
private JTextField f;
public JSprayListener(JTextField f){this.f=f;}
public void actionPerformed(ActionEvent e)
{
DrawingCanvas.radius = Math.abs(Integer.parseInt(f.getText()));
}
}
/** Random Listener, changes amount of lines. **/
public class JRandom implements ActionListener
{
private JTextField f;
public JRandom (JTextField f){this.f=f;}
public void actionPerformed(ActionEvent e)
{
DrawingCanvas.amtLines = Integer.parseInt(f.getText());
}
}
/** Text Listener, changes size of line. **/
public class JTextListener implements ActionListener
{
private JTextField f;
public JTextListener(JTextField f){this.f=f;}
public void actionPerformed(ActionEvent e)
{
DrawingCanvas.lineWidth = Integer.parseInt(f.getText());
}
}
/** Normal Listener, extra operations is set to normal. **/
public class NormalListener implements ActionListener
{
private JButton b;
public NormalListener(JButton b){this.b=b;}
public void actionPerformed(ActionEvent e)
{
current.setSelected(false);
setCurrent(b);
DrawingCanvas.extraOperations = DrawingCanvas.NORMAL;
}
}
/** Fill Listener, extra operations is set to fill. **/
public class FillListener implements ActionListener
{
private JButton b;
public FillListener(JButton b){this.b=b;}
public void actionPerformed(ActionEvent e)
{
current.setSelected(false);
setCurrent(b);
DrawingCanvas.extraOperations = DrawingCanvas.FILL;
}
}
/** Outline Listener, extra operations is set to outline. **/
public class OutlineListener implements ActionListener
{
private JButton b;
public OutlineListener(JButton b){this.b=b;}
public void actionPerformed(ActionEvent e)
{
current.setSelected(false);
setCurrent(b);
DrawingCanvas.extraOperations = DrawingCanvas.OUTLINE;
}
}
}
|