summaryrefslogtreecommitdiffstats
path: root/lib/example/RadTool.java
diff options
context:
space:
mode:
Diffstat (limited to 'lib/example/RadTool.java')
-rw-r--r--lib/example/RadTool.java620
1 files changed, 299 insertions, 321 deletions
diff --git a/lib/example/RadTool.java b/lib/example/RadTool.java
index 8ef0c55..75e7635 100644
--- a/lib/example/RadTool.java
+++ b/lib/example/RadTool.java
@@ -1,22 +1,33 @@
1package example; 1package example;
2 2
3 3
4 4import java.awt.Choice;
5import java.awt.*; 5import java.awt.Color;
6import java.awt.event.*; 6import java.awt.Component;
7import java.util.*; 7import java.awt.Container;
8import javax.swing.*; 8import java.awt.Dimension;
9import java.awt.Frame;
10import java.awt.Graphics;
11import java.awt.Panel;
12import java.awt.TextArea;
13import java.awt.event.ActionEvent;
14import java.awt.event.ActionListener;
15import java.awt.event.MouseListener;
16import java.awt.event.WindowAdapter;
17import java.awt.event.WindowEvent;
18import java.util.ArrayList;
19import javax.swing.JButton;
20import javax.swing.JLabel;
21import javax.swing.JPanel;
22import javax.swing.JTextField;
9import layout.TableLayout; 23import layout.TableLayout;
10import layout.TableLayoutConstraints; 24import layout.TableLayoutConstraints;
11import support.GeneralDialog; 25import support.GeneralDialog;
12 26
13 27
28public class RadTool extends Frame implements ActionListener {
14 29
15public class RadTool extends Frame implements ActionListener
16{
17 30
18
19
20 private JTextField textfieldColumnNumber; 31 private JTextField textfieldColumnNumber;
21 private JTextField textfieldColumnSize; 32 private JTextField textfieldColumnSize;
22 private JTextField textfieldRowNumber; 33 private JTextField textfieldRowNumber;
@@ -37,20 +48,11 @@ public class RadTool extends Frame implements ActionListener
37 private ArrayList boxList; 48 private ArrayList boxList;
38 49
39 50
40
41 public static void main (String args[])
42 {
43 new RadTool();
44 }
45
46
47
48 /** 51 /**
49 * Constructs the user interface. 52 * Constructs the user interface.
50 */ 53 */
51 54
52 public RadTool() 55 public RadTool() {
53 {
54 // Create frame 56 // Create frame
55 super("Example of Dynamic Rows and Columns"); 57 super("Example of Dynamic Rows and Columns");
56 58
@@ -61,9 +63,9 @@ public class RadTool extends Frame implements ActionListener
61 double p = TableLayout.PREFERRED; 63 double p = TableLayout.PREFERRED;
62 double size[][] = 64 double size[][] =
63 {{b, p, s, p, s, p, s, p, s, p, s, p, s, p, f, b}, 65 {{b, p, s, p, s, p, s, p, s, p, s, p, s, p, f, b},
64 {f, s, p, s, p, s, 100, s, p, b}}; 66 {f, s, p, s, p, s, 100, s, p, b}};
65 67
66 setLayout (new TableLayout(size)); 68 setLayout(new TableLayout(size));
67 69
68 // Create static controls 70 // Create static controls
69 JLabel labelColumn = new JLabel("Column"); 71 JLabel labelColumn = new JLabel("Column");
@@ -81,106 +83,105 @@ public class RadTool extends Frame implements ActionListener
81 buttonAddRow = new JButton("Add"); 83 buttonAddRow = new JButton("Add");
82 buttonRemoveRow = new JButton("Remove"); 84 buttonRemoveRow = new JButton("Remove");
83 buttonResizeRow = new JButton("Resize"); 85 buttonResizeRow = new JButton("Resize");
84 86
85 textArea = new TextArea(); 87 textArea = new TextArea();
86 columnHeader = new ArrayList(); 88 columnHeader = new ArrayList();
87 rowHeader = new ArrayList(); 89 rowHeader = new ArrayList();
88 boxList = new ArrayList(); 90 boxList = new ArrayList();
89 buttonShowLayout = new JButton("Show Layout"); 91 buttonShowLayout = new JButton("Show Layout");
90 buttonGenerateCode = new JButton("Generate Code"); 92 buttonGenerateCode = new JButton("Generate Code");
91 93
92 // Add static controls 94 // Add static controls
93 add (labelColumn, " 1, 2"); 95 add(labelColumn, " 1, 2");
94 add (textfieldColumnNumber, " 3, 2"); 96 add(textfieldColumnNumber, " 3, 2");
95 add (labelColumnSize, " 5, 2"); 97 add(labelColumnSize, " 5, 2");
96 add (textfieldColumnSize, " 7, 2"); 98 add(textfieldColumnSize, " 7, 2");
97 add (buttonAddColumn, " 9, 2"); 99 add(buttonAddColumn, " 9, 2");
98 add (buttonRemoveColumn, "11, 2"); 100 add(buttonRemoveColumn, "11, 2");
99 add (buttonResizeColumn, "13, 2"); 101 add(buttonResizeColumn, "13, 2");
100 102
101 add (labelRow, " 1, 4"); 103 add(labelRow, " 1, 4");
102 add (textfieldRowNumber, " 3, 4"); 104 add(textfieldRowNumber, " 3, 4");
103 add (labelRowSize, " 5, 4"); 105 add(labelRowSize, " 5, 4");
104 add (textfieldRowSize, " 7, 4"); 106 add(textfieldRowSize, " 7, 4");
105 add (buttonAddRow, " 9, 4"); 107 add(buttonAddRow, " 9, 4");
106 add (buttonRemoveRow, "11, 4"); 108 add(buttonRemoveRow, "11, 4");
107 add (buttonResizeRow, "13, 4"); 109 add(buttonResizeRow, "13, 4");
108 110
109 add (textArea, "1, 6, 14, 6"); 111 add(textArea, "1, 6, 14, 6");
110 add (buttonShowLayout, "1, 8, 7, 6"); 112 add(buttonShowLayout, "1, 8, 7, 6");
111 add (buttonGenerateCode, "9, 8, 12, 8"); 113 add(buttonGenerateCode, "9, 8, 12, 8");
112 114
113 // Listen for button events 115 // Listen for button events
114 buttonAddColumn.addActionListener (this); 116 buttonAddColumn.addActionListener(this);
115 buttonRemoveColumn.addActionListener (this); 117 buttonRemoveColumn.addActionListener(this);
116 buttonResizeColumn.addActionListener (this); 118 buttonResizeColumn.addActionListener(this);
117 buttonAddRow.addActionListener (this); 119 buttonAddRow.addActionListener(this);
118 buttonRemoveRow.addActionListener (this); 120 buttonRemoveRow.addActionListener(this);
119 buttonResizeRow.addActionListener (this); 121 buttonResizeRow.addActionListener(this);
120 buttonShowLayout.addActionListener (this); 122 buttonShowLayout.addActionListener(this);
121 buttonGenerateCode.addActionListener (this); 123 buttonGenerateCode.addActionListener(this);
122 124
123 // Add a panel for RadTool controls 125 // Add a panel for RadTool controls
124 panel = new JPanel(); 126 panel = new JPanel();
125 panel.setBackground (Color.white); 127 panel.setBackground(Color.white);
126 add (panel, "0, 0, 15, 0"); 128 add(panel, "0, 0, 15, 0");
127 129
128 // Create the layout manager for the panel 130 // Create the layout manager for the panel
129 double size2[][] = {{p, -1}, {p, -1}}; 131 double size2[][] = {{p, -1}, {p, -1}};
130 layout = new TableLayout(size2); 132 layout = new TableLayout(size2);
131 panel.setLayout (layout); 133 panel.setLayout(layout);
132 updateHeader(); 134 updateHeader();
133 updateBox(); 135 updateBox();
134 136
135 // Allow user to close the window to terminate the program 137 // Allow user to close the window to terminate the program
136 addWindowListener 138 addWindowListener
137 (new WindowAdapter() 139 (new WindowAdapter() {
138 { 140 public void windowClosing(WindowEvent e) {
139 public void windowClosing (WindowEvent e) 141 System.exit(0);
140 { 142 }
141 System.exit (0); 143 }
142 }
143 }
144 ); 144 );
145 145
146 // Show frame 146 // Show frame
147 setBackground (Color.lightGray); 147 setBackground(Color.lightGray);
148 setBounds (100, 100, 500, 400); 148 setBounds(100, 100, 500, 400);
149 show(); 149 show();
150 } 150 }
151 151
152 152 public static void main(String args[]) {
153 153 new RadTool();
154 }
155
154 /** 156 /**
155 * Handles all action events. 157 * Handles all action events.
156 */ 158 */
157 159
158 public void actionPerformed (ActionEvent e) 160 public void actionPerformed(ActionEvent e) {
159 {
160 // Get row and column information from text fields 161 // Get row and column information from text fields
161 int row = getInt(textfieldRowNumber); 162 int row = getInt(textfieldRowNumber);
162 int col = getInt(textfieldColumnNumber); 163 int col = getInt(textfieldColumnNumber);
163 double rowSize = getDouble(textfieldRowSize); 164 double rowSize = getDouble(textfieldRowSize);
164 double colSize = getDouble(textfieldColumnSize); 165 double colSize = getDouble(textfieldColumnSize);
165 166
166 // Get source of the event 167 // Get source of the event
167 Object source = e.getSource(); 168 Object source = e.getSource();
168 169
169 try 170 try {
170 {
171 // Update layout 171 // Update layout
172 if (source == buttonAddColumn) 172 if (source == buttonAddColumn) {
173 layout.insertColumn (col, colSize); 173 layout.insertColumn(col, colSize);
174 else if (source == buttonRemoveColumn) 174 } else if (source == buttonRemoveColumn) {
175 layout.deleteColumn (col); 175 layout.deleteColumn(col);
176 else if (source == buttonResizeColumn) 176 } else if (source == buttonResizeColumn) {
177 layout.setColumn (col, colSize); 177 layout.setColumn(col, colSize);
178 else if (source == buttonAddRow) 178 } else if (source == buttonAddRow) {
179 layout.insertRow (row, rowSize); 179 layout.insertRow(row, rowSize);
180 else if (source == buttonRemoveRow) 180 } else if (source == buttonRemoveRow) {
181 layout.deleteRow (row); 181 layout.deleteRow(row);
182 else if (source == buttonResizeRow) 182 } else if (source == buttonResizeRow) {
183 layout.setRow (row, rowSize); 183 layout.setRow(row, rowSize);
184 }
184 185
185 // Update headers, etc. to reflect layout's change 186 // Update headers, etc. to reflect layout's change
186 updateHeader(); 187 updateHeader();
@@ -189,258 +190,242 @@ public class RadTool extends Frame implements ActionListener
189 // Layout and repaint panel since the layout has changed 190 // Layout and repaint panel since the layout has changed
190 panel.doLayout(); 191 panel.doLayout();
191 panel.repaint(); 192 panel.repaint();
192 193
193 // Update layout's description 194 // Update layout's description
194 textArea.setText(layout.toString()); 195 textArea.setText(layout.toString());
195 196
196 // Generate code if desired 197 // Generate code if desired
197 if (source == buttonGenerateCode) 198 if (source == buttonGenerateCode) {
198 generateCode(); 199 generateCode();
199 } 200 }
200 catch (Throwable error) 201 } catch (Throwable error) {
201 {
202 error.printStackTrace(); 202 error.printStackTrace();
203 textArea.setText (error.toString()); 203 textArea.setText(error.toString());
204 } 204 }
205 } 205 }
206 206
207 207
208
209 /** 208 /**
210 * Converts the text in a text field to an integer. 209 * Converts the text in a text field to an integer.
211 */ 210 */
212 211
213 private int getInt (JTextField field) 212 private int getInt(JTextField field) {
214 {
215 int value = 0; 213 int value = 0;
216 214
217 try 215 try {
218 {
219 value = Integer.parseInt(field.getText()); 216 value = Integer.parseInt(field.getText());
217 } catch (NumberFormatException e) {
220 } 218 }
221 catch (NumberFormatException e) {} 219
222
223 return value; 220 return value;
224 } 221 }
225 222
226 223
227
228 /** 224 /**
229 * Converts the text in a text field to a double. 225 * Converts the text in a text field to a double.
230 */ 226 */
231 227
232 private double getDouble (JTextField field) 228 private double getDouble(JTextField field) {
233 {
234 double value = -1.0; 229 double value = -1.0;
235 230
236 try 231 try {
237 {
238 value = Double.parseDouble(field.getText()); 232 value = Double.parseDouble(field.getText());
233 } catch (NumberFormatException e) {
239 } 234 }
240 catch (NumberFormatException e) {} 235
241
242 return value; 236 return value;
243 } 237 }
244 238
245
246 239
247 /** 240 /**
248 * Updates all the row and columns headers by bruce force. The headers 241 * Updates all the row and columns headers by bruce force. The headers
249 * are removed and then recreated based on the current layout configuration. 242 * are removed and then recreated based on the current layout configuration.
250 */ 243 */
251 244
252 private void updateHeader () 245 private void updateHeader() {
253 {
254 TableLayoutConstraints c = new TableLayoutConstraints 246 TableLayoutConstraints c = new TableLayoutConstraints
255 (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL); 247 (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL);
256 248
257 double size[] = layout.getColumn(); 249 double size[] = layout.getColumn();
258 250
259 for (int i = columnHeader.size() - 1; i >= 0; i--) 251 for (int i = columnHeader.size() - 1; i >= 0; i--) {
260 {
261 JButton header = (JButton) columnHeader.remove(i); 252 JButton header = (JButton) columnHeader.remove(i);
262 panel.remove(header); 253 panel.remove(header);
263 } 254 }
264 255
265 for (int i = 0; i < size.length; i++) 256 for (int i = 0; i < size.length; i++) {
266 {
267 c.col1 = c.col2 = i; 257 c.col1 = c.col2 = i;
268 JButton header = new JButton("" + i + ": " + size[i]); 258 JButton header = new JButton("" + i + ": " + size[i]);
269 columnHeader.add(i, header); 259 columnHeader.add(i, header);
270 panel.add (header, c); 260 panel.add(header, c);
271 } 261 }
272 262
273 c.col1 = c.col2 = 0; 263 c.col1 = c.col2 = 0;
274 size = layout.getRow(); 264 size = layout.getRow();
275 265
276 for (int i = rowHeader.size() - 1; i >= 0; i--) 266 for (int i = rowHeader.size() - 1; i >= 0; i--) {
277 {
278 JButton header = (JButton) rowHeader.remove(i); 267 JButton header = (JButton) rowHeader.remove(i);
279 panel.remove(header); 268 panel.remove(header);
280 } 269 }
281 270
282 for (int i = 0; i < size.length; i++) 271 for (int i = 0; i < size.length; i++) {
283 {
284 c.row1 = c.row2 = i; 272 c.row1 = c.row2 = i;
285 JButton header = new JButton("" + i + ": " + size[i]); 273 JButton header = new JButton("" + i + ": " + size[i]);
286 rowHeader.add(i, header); 274 rowHeader.add(i, header);
287 panel.add (header, c); 275 panel.add(header, c);
288 } 276 }
289 } 277 }
290 278
291 279
292
293 /** 280 /**
294 * Updates the boxes used to illustrate cells. This is a brute force, 281 * Updates the boxes used to illustrate cells. This is a brute force,
295 * unoptimized method. 282 * unoptimized method.
296 */ 283 */
297 284
298 private void updateBox () 285 private void updateBox() {
299 { 286 for (int i = boxList.size() - 1; i >= 0; i--) {
300 for (int i = boxList.size() - 1; i >= 0; i--)
301 {
302 Box box = (Box) boxList.remove(i); 287 Box box = (Box) boxList.remove(i);
303 panel.remove(box); 288 panel.remove(box);
304 } 289 }
305 290
306 TableLayoutConstraints constraint = new TableLayoutConstraints 291 TableLayoutConstraints constraint = new TableLayoutConstraints
307 (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL); 292 (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL);
308 293
309 double col[] = layout.getColumn(); 294 double col[] = layout.getColumn();
310 double row[] = layout.getRow(); 295 double row[] = layout.getRow();
311 296
312 for (int c = 1; c < col.length; c++) 297 for (int c = 1; c < col.length; c++) {
313 for (int r = 1; r < row.length; r++) 298 for (int r = 1; r < row.length; r++) {
314 {
315 constraint.col1 = constraint.col2 = c; 299 constraint.col1 = constraint.col2 = c;
316 constraint.row1 = constraint.row2 = r; 300 constraint.row1 = constraint.row2 = r;
317 Box box = new Box(); 301 Box box = new Box();
318 panel.add (box, constraint); 302 panel.add(box, constraint);
319 } 303 }
304 }
320 } 305 }
321 306
322 307
323
324 /** 308 /**
325 * Generates code based on the current layout and Smiley controls. 309 * Generates code based on the current layout and Smiley controls.
326 */ 310 */
327 311
328 private void generateCode () 312 private void generateCode() {
329 {
330 String code = 313 String code =
331 "import java.awt.*;\n" + 314 "import java.awt.*;\n" +
332 "import java.awt.event.*;\n" + 315 "import java.awt.event.*;\n" +
333 "import layout.TableLayout;\n\n" + 316 "import layout.TableLayout;\n\n" +
334 317
335 "public class MyClass\n" + 318 "public class MyClass\n" +
336 "{\n\n" + 319 "{\n\n" +
337 320
338 " public static void main (String args[])\n" + 321 " public static void main (String args[])\n" +
339 " {\n" + 322 " {\n" +
340 " Frame frame = new Frame(\"MyTitle\");\n" + 323 " Frame frame = new Frame(\"MyTitle\");\n" +
341 " frame.setBounds (100, 100, 300, 300);\n\n" + 324 " frame.setBounds (100, 100, 300, 300);\n\n" +
325
326 " double size[][] =\n" +
327 " {{";
342 328
343 " double size[][] =\n" +
344 " {{";
345
346 double size[] = layout.getColumn(); 329 double size[] = layout.getColumn();
347 330
348 if (size.length > 0) 331 if (size.length > 0) {
349 code += size[0]; 332 code += size[0];
333 }
350 334
351 for (int i = 1; i < size.length; i++) 335 for (int i = 1; i < size.length; i++) {
352 code += ", " + size[i]; 336 code += ", " + size[i];
337 }
353 338
354 code += "}, // Columns\n" + 339 code += "}, // Columns\n" +
355 " {"; 340 " {";
356 341
357 size = layout.getRow(); 342 size = layout.getRow();
358 343
359 if (size.length > 0) 344 if (size.length > 0) {
360 code += size[0]; 345 code += size[0];
346 }
361 347
362 for (int i = 1; i < size.length; i++) 348 for (int i = 1; i < size.length; i++) {
363 code += ", " + size[i]; 349 code += ", " + size[i];
350 }
364 351
365 code += "}}; // Rows\n\n" + 352 code += "}}; // Rows\n\n" +
366 " frame.setLayout (new TableLayout(size));\n\n" + 353 " frame.setLayout (new TableLayout(size));\n\n" +
367 " Button button;\n"; 354 " Button button;\n";
368 355
369 Component component[] = panel.getComponents(); 356 Component component[] = panel.getComponents();
370 357
371 for (int i = 0; i < component.length; i++) 358 for (int i = 0; i < component.length; i++) {
372 { 359 if (component[i] instanceof Smiley) {
373 if (component[i] instanceof Smiley)
374 {
375 TableLayoutConstraints c = layout.getConstraints(component[i]); 360 TableLayoutConstraints c = layout.getConstraints(component[i]);
376 String constraint = "" + c.col1 + ", " + c.row1 + ", "; 361 String constraint = "" + c.col1 + ", " + c.row1 + ", ";
377 362
378 if ((c.col1 == c.col2) && (c.row1 == c.row2)) 363 if ((c.col1 == c.col2) && (c.row1 == c.row2)) {
379 {
380 String h[] = {"L", "C", "F", "R"}; 364 String h[] = {"L", "C", "F", "R"};
381 String v[] = {"T", "C", "F", "B"}; 365 String v[] = {"T", "C", "F", "B"};
382 constraint += h[c.hAlign] + ", " + v[c.vAlign]; 366 constraint += h[c.hAlign] + ", " + v[c.vAlign];
383 } 367 } else {
384 else
385 constraint += c.col2 + ", " + c.row2; 368 constraint += c.col2 + ", " + c.row2;
386 369 }
370
387 code += 371 code +=
388 " button = new Button(\"" + constraint + "\");\n" + 372 " button = new Button(\"" + constraint + "\");\n" +
389 " frame.add (button, \"" + constraint + "\");\n"; 373 " frame.add (button, \"" + constraint + "\");\n";
390 } 374 }
391 } 375 }
392 376
393 code += 377 code +=
394 "\n" + 378 "\n" +
395 " frame.addWindowListener\n" + 379 " frame.addWindowListener\n" +
396 " (new WindowAdapter()\n" + 380 " (new WindowAdapter()\n" +
397 " {\n" + 381 " {\n" +
398 " public void windowClosing (WindowEvent e)\n" + 382 " public void windowClosing (WindowEvent e)\n" +
399 " {\n" + 383 " {\n" +
400 " System.exit (0);\n" + 384 " System.exit (0);\n" +
401 " }\n" + 385 " }\n" +
402 " }\n" + 386 " }\n" +
403 " );\n\n" + 387 " );\n\n" +
404 " frame.show();\n" + 388 " frame.show();\n" +
405 " }\n" + 389 " }\n" +
406 "}\n"; 390 "}\n";
407 391
408 textArea.setText (code); 392 textArea.setText(code);
409 } 393 }
410 394
411 395
412
413 /** 396 /**
414 * This inner class is a component that looks like a box. 397 * This inner class is a component that looks like a box.
415 */ 398 */
416 399
417 public class Box extends Component implements MouseListener 400 public class Box extends Component implements MouseListener {
418 { 401 public Box() {
419 public Box ()
420 {
421 super(); 402 super();
422 addMouseListener(this); 403 addMouseListener(this);
423 } 404 }
424 405
425 public void update (Graphics g) 406 public void update(Graphics g) {
426 { 407 paint(g);
427 paint (g);
428 } 408 }
429 409
430 public void paint (Graphics g) 410 public void paint(Graphics g) {
431 {
432 Dimension d = getSize(); 411 Dimension d = getSize();
433 g.setColor (Color.black); 412 g.setColor(Color.black);
434 g.drawRect (0, 0, d.width - 1, d.height - 1); 413 g.drawRect(0, 0, d.width - 1, d.height - 1);
414 }
415
416 public void mouseExited(java.awt.event.MouseEvent mouseEvent) {
417 }
418
419 public void mousePressed(java.awt.event.MouseEvent mouseEvent) {
420 }
421
422 public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {
435 } 423 }
436 424
437 public void mouseExited(java.awt.event.MouseEvent mouseEvent) {} 425 public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {
438 public void mousePressed(java.awt.event.MouseEvent mouseEvent) {} 426 }
439 public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {} 427
440 public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {} 428 public void mouseReleased(java.awt.event.MouseEvent mouseEvent) {
441
442 public void mouseReleased(java.awt.event.MouseEvent mouseEvent)
443 {
444 TableLayoutConstraints c = layout.getConstraints(this); 429 TableLayoutConstraints c = layout.getConstraints(this);
445 Smiley smiley = new Smiley(); 430 Smiley smiley = new Smiley();
446 Container container = getParent(); 431 Container container = getParent();
@@ -449,32 +434,26 @@ public class RadTool extends Frame implements ActionListener
449 } 434 }
450 } 435 }
451 436
452
453 437
454 /** 438 /**
455 * This inner class is a component that looks like a smiley face. 439 * This inner class is a component that looks like a smiley face.
456 */ 440 */
457 441
458 public class Smiley extends Component implements MouseListener 442 public class Smiley extends Component implements MouseListener {
459 { 443 public Smiley() {
460 public Smiley ()
461 {
462 super(); 444 super();
463 addMouseListener (this); 445 addMouseListener(this);
464 } 446 }
465 447
466 public Dimension getPreferredSize () 448 public Dimension getPreferredSize() {
467 {
468 return new Dimension(64, 64); 449 return new Dimension(64, 64);
469 } 450 }
470 451
471 public void update (Graphics g) 452 public void update(Graphics g) {
472 { 453 paint(g);
473 paint (g);
474 } 454 }
475 455
476 public void paint (Graphics g) 456 public void paint(Graphics g) {
477 {
478 Dimension d = getSize(); 457 Dimension d = getSize();
479 int width_1_8 = d.width >> 3; 458 int width_1_8 = d.width >> 3;
480 int width_7_8 = d.width - width_1_8; 459 int width_7_8 = d.width - width_1_8;
@@ -487,131 +466,132 @@ public class RadTool extends Frame implements ActionListener
487 int height_1_4 = d.height >> 2; 466 int height_1_4 = d.height >> 2;
488 int height_3_4 = d.height - height_1_4; 467 int height_3_4 = d.height - height_1_4;
489 int height_5_8 = height_7_8 - height_1_4; 468 int height_5_8 = height_7_8 - height_1_4;
490 469
491 g.setColor (Color.yellow); 470 g.setColor(Color.yellow);
492 g.fillArc (0, 0, d.width - 1, d.height - 1, 0, 360); 471 g.fillArc(0, 0, d.width - 1, d.height - 1, 0, 360);
493 g.setColor (Color.blue); 472 g.setColor(Color.blue);
494 g.fillArc (width_1_4, height_1_4, width_1_8, height_1_8, 0, 360); 473 g.fillArc(width_1_4, height_1_4, width_1_8, height_1_8, 0, 360);
495 g.fillArc (width_5_8, height_1_4, width_1_8, height_1_8, 0, 360); 474 g.fillArc(width_5_8, height_1_4, width_1_8, height_1_8, 0, 360);
496 g.setColor (Color.red); 475 g.setColor(Color.red);
497 g.fillArc (width_1_4, height_5_8, width_1_2, height_1_4, 180, 180); 476 g.fillArc(width_1_4, height_5_8, width_1_2, height_1_4, 180, 180);
477 }
478
479 public void mouseExited(java.awt.event.MouseEvent mouseEvent) {
480 }
481
482 public void mousePressed(java.awt.event.MouseEvent mouseEvent) {
483 }
484
485 public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {
486 }
487
488 public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {
498 } 489 }
499 490
500 public void mouseExited(java.awt.event.MouseEvent mouseEvent) {} 491 public void mouseReleased(java.awt.event.MouseEvent mouseEvent) {
501 public void mousePressed(java.awt.event.MouseEvent mouseEvent) {}
502 public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {}
503 public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {}
504
505 public void mouseReleased(java.awt.event.MouseEvent mouseEvent)
506 {
507 // Get constraints applied to this Smiley 492 // Get constraints applied to this Smiley
508 TableLayoutConstraints c = layout.getConstraints(this); 493 TableLayoutConstraints c = layout.getConstraints(this);
509 494
510 // Create controls 495 // Create controls
511 Panel panel = new Panel(); 496 Panel panel = new Panel();
512 497
513 int numRow = layout.getNumRow(); 498 int numRow = layout.getNumRow();
514 int numColumn = layout.getNumColumn(); 499 int numColumn = layout.getNumColumn();
515 500
516 Choice choiceCol1 = new Choice(); 501 Choice choiceCol1 = new Choice();
517 Choice choiceCol2 = new Choice(); 502 Choice choiceCol2 = new Choice();
518 Choice choiceRow1 = new Choice(); 503 Choice choiceRow1 = new Choice();
519 Choice choiceRow2 = new Choice(); 504 Choice choiceRow2 = new Choice();
520 505
521 for (int i = 1; i < numColumn; i++) 506 for (int i = 1; i < numColumn; i++) {
522 { 507 choiceCol1.add("" + i);
523 choiceCol1.add ("" + i); 508 choiceCol2.add("" + i);
524 choiceCol2.add ("" + i);
525 } 509 }
526 510
527 for (int i = 1; i < numRow; i++) 511 for (int i = 1; i < numRow; i++) {
528 { 512 choiceRow1.add("" + i);
529 choiceRow1.add ("" + i); 513 choiceRow2.add("" + i);
530 choiceRow2.add ("" + i);
531 } 514 }
532 515
533 choiceCol1.select (c.col1 - 1); 516 choiceCol1.select(c.col1 - 1);
534 choiceCol2.select (c.col2 - 1); 517 choiceCol2.select(c.col2 - 1);
535 choiceRow1.select (c.row1 - 1); 518 choiceRow1.select(c.row1 - 1);
536 choiceRow2.select (c.row2 - 1); 519 choiceRow2.select(c.row2 - 1);
537 520
538 Choice choiceAlignH = new Choice(); 521 Choice choiceAlignH = new Choice();
539 choiceAlignH.add ("Left"); 522 choiceAlignH.add("Left");
540 choiceAlignH.add ("Center"); 523 choiceAlignH.add("Center");
541 choiceAlignH.add ("Full"); 524 choiceAlignH.add("Full");
542 choiceAlignH.add ("Right"); 525 choiceAlignH.add("Right");
543 choiceAlignH.select (c.hAlign); 526 choiceAlignH.select(c.hAlign);
544 527
545 Choice choiceAlignV = new Choice(); 528 Choice choiceAlignV = new Choice();
546 choiceAlignV.add ("Top"); 529 choiceAlignV.add("Top");
547 choiceAlignV.add ("Center"); 530 choiceAlignV.add("Center");
548 choiceAlignV.add ("Full"); 531 choiceAlignV.add("Full");
549 choiceAlignV.add ("Bottom"); 532 choiceAlignV.add("Bottom");
550 choiceAlignV.select (c.vAlign); 533 choiceAlignV.select(c.vAlign);
551 534
552 JLabel labelCol1 = new JLabel("Column 1"); 535 JLabel labelCol1 = new JLabel("Column 1");
553 JLabel labelCol2 = new JLabel("Column 2"); 536 JLabel labelCol2 = new JLabel("Column 2");
554 JLabel labelRow1 = new JLabel("Row 1"); 537 JLabel labelRow1 = new JLabel("Row 1");
555 JLabel labelRow2 = new JLabel("Row 2"); 538 JLabel labelRow2 = new JLabel("Row 2");
556 JLabel labelAlignH = new JLabel("Horizontal Justification"); 539 JLabel labelAlignH = new JLabel("Horizontal Justification");
557 JLabel labelAlignV = new JLabel("Vertical Justification"); 540 JLabel labelAlignV = new JLabel("Vertical Justification");
558 labelAlignH.setHorizontalAlignment (JLabel.RIGHT); 541 labelAlignH.setHorizontalAlignment(JLabel.RIGHT);
559 labelAlignV.setHorizontalAlignment (JLabel.RIGHT); 542 labelAlignV.setHorizontalAlignment(JLabel.RIGHT);
560 543
561 // Create layout 544 // Create layout
562 double f = TableLayout.FILL; 545 double f = TableLayout.FILL;
563 double p = TableLayout.PREFERRED; 546 double p = TableLayout.PREFERRED;
564 double s = 10; 547 double s = 10;
565 548
566 double size[][] = 549 double size[][] =
567 {{f, p, s, p, s, p, s, p, f}, 550 {{f, p, s, p, s, p, s, p, f},
568 {p, s, p, s, p, s, p, s, p, s, p}}; 551 {p, s, p, s, p, s, p, s, p, s, p}};
569 552
570 TableLayout panelLayout = new TableLayout(size); 553 TableLayout panelLayout = new TableLayout(size);
571 panel.setLayout (panelLayout); 554 panel.setLayout(panelLayout);
572 555
573 // Add controls 556 // Add controls
574 panel.add (labelCol1, "1, 0, R, B"); 557 panel.add(labelCol1, "1, 0, R, B");
575 panel.add (choiceCol1, "3, 0, L, B"); 558 panel.add(choiceCol1, "3, 0, L, B");
576 panel.add (labelRow1, "5, 0, R, B"); 559 panel.add(labelRow1, "5, 0, R, B");
577 panel.add (choiceRow1, "7, 0, L, B"); 560 panel.add(choiceRow1, "7, 0, L, B");
578 panel.add (labelCol2, "1, 2, R, B"); 561 panel.add(labelCol2, "1, 2, R, B");
579 panel.add (choiceCol2, "3, 2, L, B"); 562 panel.add(choiceCol2, "3, 2, L, B");
580 panel.add (labelRow2, "5, 2, R, B"); 563 panel.add(labelRow2, "5, 2, R, B");
581 panel.add (choiceRow2, "7, 2, L, B"); 564 panel.add(choiceRow2, "7, 2, L, B");
582 panel.add (labelAlignH, "0, 4, 3, 4"); 565 panel.add(labelAlignH, "0, 4, 3, 4");
583 panel.add (choiceAlignH, "5, 4, 7, 4"); 566 panel.add(choiceAlignH, "5, 4, 7, 4");
584 panel.add (labelAlignV, "0, 6, 3, 6"); 567 panel.add(labelAlignV, "0, 6, 3, 6");
585 panel.add (choiceAlignV, "5, 6, 7, 6"); 568 panel.add(choiceAlignV, "5, 6, 7, 6");
586 569
587 // Prompt user 570 // Prompt user
588 String button[] = {"Update Smiley", "Remove Smiley", "Cancel"}; 571 String button[] = {"Update Smiley", "Remove Smiley", "Cancel"};
589 572
590 GeneralDialog dialog = new GeneralDialog 573 GeneralDialog dialog = new GeneralDialog
591 (RadTool.this, "Update Smiley", "", button, null, panel); 574 (RadTool.this, "Update Smiley", "", button, null, panel);
592 575
593 String answer = dialog.promptUser(); 576 String answer = dialog.promptUser();
594 577
595 // Update constraints applied to this Smiley 578 // Update constraints applied to this Smiley
596 if (answer.equals("Update Smiley")) 579 if (answer.equals("Update Smiley")) {
597 {
598 // Get columns 580 // Get columns
599 int col1 = choiceCol1.getSelectedIndex() + 1; 581 int col1 = choiceCol1.getSelectedIndex() + 1;
600 int col2 = choiceCol2.getSelectedIndex() + 1; 582 int col2 = choiceCol2.getSelectedIndex() + 1;
601 int row1 = choiceRow1.getSelectedIndex() + 1; 583 int row1 = choiceRow1.getSelectedIndex() + 1;
602 int row2 = choiceRow2.getSelectedIndex() + 1; 584 int row2 = choiceRow2.getSelectedIndex() + 1;
603 585
604 // Make sure col1 < col2 586 // Make sure col1 < col2
605 if (col1 > col2) 587 if (col1 > col2) {
606 {
607 int temp = col1; 588 int temp = col1;
608 col1 = col2; 589 col1 = col2;
609 col2 = temp; 590 col2 = temp;
610 } 591 }
611 592
612 // Make sure row1 < row2 593 // Make sure row1 < row2
613 if (row1 > row2) 594 if (row1 > row2) {
614 {
615 int temp = row1; 595 int temp = row1;
616 row1 = row2; 596 row1 = row2;
617 row2 = temp; 597 row2 = temp;
@@ -624,7 +604,7 @@ public class RadTool extends Frame implements ActionListener
624 c.row2 = row2; 604 c.row2 = row2;
625 c.hAlign = choiceAlignH.getSelectedIndex(); 605 c.hAlign = choiceAlignH.getSelectedIndex();
626 c.vAlign = choiceAlignV.getSelectedIndex(); 606 c.vAlign = choiceAlignV.getSelectedIndex();
627 layout.setConstraints (this, c); 607 layout.setConstraints(this, c);
628 608
629 // Repaint and layout container since layout has changed 609 // Repaint and layout container since layout has changed
630 Container container = getParent(); 610 Container container = getParent();
@@ -632,16 +612,14 @@ public class RadTool extends Frame implements ActionListener
632 container.repaint(); 612 container.repaint();
633 } 613 }
634 // Remove Smiley 614 // Remove Smiley
635 else if (answer.equals("Remove Smiley")) 615 else if (answer.equals("Remove Smiley")) {
636 {
637 Container container = getParent(); 616 Container container = getParent();
638 container.remove (this); 617 container.remove(this);
639 container.doLayout(); 618 container.doLayout();
640 container.repaint(); 619 container.repaint();
641 } 620 }
642 } 621 }
643 } 622 }
644 623
645 624
646
647} 625}