-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextBoxComponent.java
386 lines (366 loc) · 9.01 KB
/
TextBoxComponent.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
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/*
* Nikhil Pandeti
* Mrs. Gallatin
* Period 2
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
A component that holds the text fields
*/
public class TextBoxComponent extends JComponent
{
private JTextField x, y, z, length, width, height, radius, radius2, roll, pitch, yaw, quality, sides;
private double lengthNum, widthNum, heightNum, radiusNum, radius2Num, rollNum, pitchNum, yawNum;
private int qualityNum, sidesNum;
private JLabel xText, yText, zText, lengthText, widthText, heightText, radiusText, radius2Text, rollText, pitchText, yawText, qualityText, sidesText;
private JButton draw;
/**
* A constructor for TextBoxComponent
* @param draw A draw button
*/
public TextBoxComponent(JButton draw)
{
setLayout(new FlowLayout());
setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
qualityNum = sidesNum = 0;
lengthNum = widthNum = heightNum = 1;
radiusNum = radius2Num = rollNum = pitchNum = yawNum = 0;
xText = new JLabel(" X:");
yText = new JLabel(" Y:");
zText = new JLabel(" Z:");
lengthText = new JLabel(" Length:");
widthText = new JLabel(" Width:");
heightText = new JLabel(" Height:");
radiusText = new JLabel(" Radius:");
radius2Text = new JLabel(" Radius 2:");
rollText = new JLabel(" Roll:");
pitchText = new JLabel(" Pitch:");
yawText = new JLabel(" Yaw:");
qualityText = new JLabel(" Quality:");
sidesText = new JLabel(" # of Sides:");
x = new JTextField(12);
y = new JTextField(12);
z = new JTextField(12);
length = new JTextField(5);
width = new JTextField(5);
height = new JTextField(5);
radius = new JTextField(5);
radius2 = new JTextField(5);
roll = new JTextField(5);
pitch = new JTextField(5);
yaw = new JTextField(5);
quality = new JTextField(5);
sides = new JTextField(5);
//radius.addActionListener(this);
//radius.addMouseListener(this);
add(xText);
add(x);
add(yText);
add(y);
add(zText);
add(z);
add(lengthText);
add(length);
add(widthText);
add(width);
add(heightText);
add(height);
add(radiusText);
add(radius);
add(radius2Text);
add(radius2);
add(qualityText);
add(quality);
add(sidesText);
add(sides);
add(yawText);
add(yaw);
add(pitchText);
add(pitch);
add(rollText);
add(roll);
setShape("Cube");
add(draw);
setVisible(true);
//setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
}
/**
* Returns the X textfield's text
* @return the X textfield's text
*/
public String getx()
{
return x.getText();
}
/**
* Returns the Y textfield's text
* @return the Y textfield's text
*/
public String gety()
{
return y.getText();
}
/**
* Returns the Z textfield's text
* @return the Z textfield's text
*/
public String getz()
{
return z.getText();
}
/**
* Returns the Length textfield's text
* @return the Length textfield's text
*/
public String getlength()
{
return length.getText();
}
/**
* Returns the Width textfield's text
* @return the Width textfield's text
*/
public String getwidth()
{
return width.getText();
}
/**
* Returns the Height textfield's text
* @return the Height textfield's text
*/
public String getheight()
{
return height.getText();
}
/**
* Returns the Radius textfield's text
* @return the Radius textfield's text
*/
public String getRadius()
{
return radius.getText();
}
/**
* Returns the Radius2 textfield's text
* @return the Radius2 textfield's text
*/
public String getRadius2()
{
return radius2.getText();
}
/**
* Returns the Quality textfield's text
* @return the Quality textfield's text
*/
public String getQuality()
{
return quality.getText();
}
/**
* Returns the Sides textfield's text
* @return the Sides textfield's text
*/
public String getSides()
{
return sides.getText();
}
/**
* Returns the Roll textfield's text
* @return the Roll textfield's text
*/
public String getRoll()
{
return roll.getText();
}
/**
* Returns the Pitch textfield's text
* @return the Pitch textfield's text
*/
public String getPitch()
{
return pitch.getText();
}
/**
* Returns the Yaw textfield's text
* @return the Yaw textfield's text
*/
public String getYaw()
{
return yaw.getText();
}
/**
* Sets the X textfield's text
* @param s X textfield's text
*/
public void setX(String s)
{
x.setText(s);
}
/**
* Sets the Y textfield's text
* @param s Y textfield's text
*/
public void setY(String s)
{
y.setText(s);
}
/**
* Sets the Z textfield's text
* @param s Z textfield's text
*/
public void setZ(String s)
{
z.setText(s);
}
/**
* Sets the required textfields to be visible
* @param shape the specified shape
*/
public void setShape(String shape)
{
length.setVisible(false);
width.setVisible(false);
height.setVisible(false);
radius.setVisible(false);
radius2.setVisible(false);
roll.setVisible(false);
pitch.setVisible(false);
yaw.setVisible(false);
quality.setVisible(false);
sides.setVisible(false);
lengthText.setVisible(false);
widthText.setVisible(false);
heightText.setVisible(false);
radiusText.setVisible(false);
radius2Text.setVisible(false);
rollText.setVisible(false);
pitchText.setVisible(false);
yawText.setVisible(false);
qualityText.setVisible(false);
sidesText.setVisible(false);
if(shape.equals("Cube"))
{
lengthText.setVisible(true);
length.setVisible(true);
widthText.setVisible(true);
width.setVisible(true);
heightText.setVisible(true);
height.setVisible(true);
rollText.setVisible(true);
roll.setVisible(true);
pitchText.setVisible(true);
pitch.setVisible(true);
yawText.setVisible(true);
yaw.setVisible(true);
length.setText("1");
width.setText("1");
height.setText("1");
roll.setText("0");
pitch.setText("0");
yaw.setText("0");
}
else if(shape.equals("Sphere"))
{
radiusText.setVisible(true);
radius.setVisible(true);
qualityText.setVisible(true);
quality.setVisible(true);
radius.setText("1");
quality.setText("15");
}
else if(shape.equals("Prism"))
{
heightText.setVisible(true);
height.setVisible(true);
radiusText.setVisible(true);
radius.setVisible(true);
sidesText.setVisible(true);
sides.setVisible(true);
rollText.setVisible(true);
roll.setVisible(true);
pitchText.setVisible(true);
pitch.setVisible(true);
yawText.setVisible(true);
yaw.setVisible(true);
height.setText("1");
radius.setText("1");
sides.setText("4");
roll.setText("0");
pitch.setText("0");
yaw.setText("0");
}
else if(shape.equals("Cylinder"))
{
heightText.setVisible(true);
height.setVisible(true);
radiusText.setVisible(true);
radius.setVisible(true);
rollText.setVisible(true);
roll.setVisible(true);
pitchText.setVisible(true);
pitch.setVisible(true);
//yawText.setVisible(true);
//yaw.setVisible(true);
height.setText("1");
radius.setText("1");
roll.setText("0");
pitch.setText("0");
//yaw.setText("0");
}
else if(shape.equals("Torus"))
{
radiusText.setVisible(true);
radius.setVisible(true);
radius2Text.setVisible(true);
radius2.setVisible(true);
qualityText.setVisible(true);
quality.setVisible(true);
rollText.setVisible(true);
roll.setVisible(true);
pitchText.setVisible(true);
pitch.setVisible(true);
yawText.setVisible(true);
yaw.setVisible(true);
radius.setText("1");
radius2.setText("2");
quality.setText("15");
roll.setText("0");
pitch.setText("0");
yaw.setText("0");
}
}
/**
* Corrects any user errors
*/
public void checkText()
{
try
{
qualityNum = Integer.parseInt(quality.getText());
sidesNum = Integer.parseInt(sides.getText());
lengthNum = Double.parseDouble(length.getText());
widthNum = Double.parseDouble(width.getText());
heightNum = Double.parseDouble(height.getText());
radiusNum = Double.parseDouble(radius.getText());
radius2Num = Double.parseDouble(radius2.getText());
rollNum = Double.parseDouble(roll.getText());
pitchNum = Double.parseDouble(pitch.getText());
yawNum = Double.parseDouble(yaw.getText());
}
catch(Exception ex)
{
}
quality.setText(Integer.toString(qualityNum));
sides.setText(Integer.toString(sidesNum));
length.setText(Double.toString(lengthNum));
width.setText(Double.toString(widthNum));
height.setText(Double.toString(heightNum));
radius.setText(Double.toString(radiusNum));
radius2.setText(Double.toString(radius2Num));
roll.setText(Double.toString(rollNum));
pitch.setText(Double.toString(pitchNum));
yaw.setText(Double.toString(yawNum));
}
}