-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleDraw.java
703 lines (580 loc) · 19.5 KB
/
SimpleDraw.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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.awt.Container;
import java.awt.Component;
import java.awt.Graphics;
// import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.omg.CORBA.FloatSeqHelper;
import javax.swing.ButtonGroup;
import javax.swing.BoxLayout;
import javax.swing.BorderFactory;
// This stores a polygonal line, creating by a stroke of the pointing device.
class Stroke {
// the points that make up the stroke, in world space coordinates
private ArrayList<Point2D> points = new ArrayList<Point2D>();
private AlignedRectangle2D boundingRectangle = new AlignedRectangle2D();
private boolean isBoundingRectangleDirty = false;
private Color color = new Color(0, 0, 0);
public Color getRgbSelect() {
return color;
}
public void setRgbSelect(Color rgbSelect) {
this.color = rgbSelect;
}
public void addPoint(Point2D p) {
points.add(p);
isBoundingRectangleDirty = true;
}
public ArrayList<Point2D> getPoints() {
return points;
}
public AlignedRectangle2D getBoundingRectangle() {
if (isBoundingRectangleDirty) {
boundingRectangle.clear();
for (Point2D p : points) {
boundingRectangle.bound(p);
}
isBoundingRectangleDirty = false;
}
return boundingRectangle;
}
public void markBoundingRectangleDirty() {
isBoundingRectangleDirty = true;
}
public boolean isContainedInRectangle(AlignedRectangle2D r) {
return r.contains(getBoundingRectangle());
}
public boolean isContainedInLassoPolygon(ArrayList<Point2D> polygonPoints) {
for (Point2D p : points) {
if (!Point2DUtil.isPointInsidePolygon(polygonPoints, p))
return false;
}
return true;
}
public void translate(Vector2D v) {
for (Point2D p : points) {
p.copy(Point2D.sum(p, v));
}
markBoundingRectangleDirty();
}
public void rotate(float angle /* in radians */,
Point2D center /* center of rotation */ ) {
float sine = (float) Math.sin(angle);
float cosine = (float) Math.cos(angle);
for (Point2D p : points) {
float delta_x = p.x() - center.x();
float delta_y = p.y() - center.y();
float new_x = center.x() + delta_x * cosine - delta_y * sine;
float new_y = center.y() + delta_x * sine + delta_y * cosine;
p.copy(new_x, new_y);
}
markBoundingRectangleDirty();
}
public void draw(GraphicsWrapper gw) {
gw.drawPolyline(points);
}
}
// This stores a set of strokes.
class Drawing {
public ArrayList<Stroke> strokes = new ArrayList<Stroke>();
private AlignedRectangle2D boundingRectangle = new AlignedRectangle2D();
private boolean isBoundingRectangleDirty = false;
public void addStroke(Stroke s) {
strokes.add(s);
isBoundingRectangleDirty = true;
}
public void clear() {
strokes.clear();
boundingRectangle.clear();
}
public AlignedRectangle2D getBoundingRectangle() {
if (isBoundingRectangleDirty) {
boundingRectangle.clear();
for (Stroke s : strokes) {
boundingRectangle.bound(s.getBoundingRectangle());
}
isBoundingRectangleDirty = false;
}
return boundingRectangle;
}
public void markBoundingRectangleDirty() {
isBoundingRectangleDirty = true;
}
public void draw(GraphicsWrapper gw) {
gw.setLineWidth(5);
for (Stroke s : strokes) {
// **
if (s.getRgbSelect() == Color.red) {
gw.setColor(Color.red);
} else if (s.getRgbSelect() == Color.green) {
gw.setColor(Color.green);
} else
gw.setColor(Color.black);
s.draw(gw);
}
gw.setLineWidth(1);
}
}
class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
SimpleDraw simpleDraw;
GraphicsWrapper gw = new GraphicsWrapper();
Stroke stroke = new Stroke();
RadialMenuWidget radialMenu = new RadialMenuWidget();
// Stores all the strokes on the canvas,
// except for any stroke currently being created.
Drawing drawing = new Drawing();
// stores a subset of the strokes
ArrayList<Stroke> selectedStrokes = new ArrayList<Stroke>();
int mouse_x, mouse_y, previous_mouse_x, previous_mouse_y, drag_start_x, drag_start_y;
ArrayList<Point2D> pointerHistory = new ArrayList<Point2D>();
private static final int DRAG_MODE_NONE = 0;
private static final int DRAG_MODE_PAN = 1;
private static final int DRAG_MODE_ZOOM = 2;
private static final int DRAG_MODE_TOOL = 3;
private int currentDragMode = DRAG_MODE_NONE;
public MyCanvas(SimpleDraw sd) {
simpleDraw = sd;
setBorder(BorderFactory.createLineBorder(Color.black));
setBackground(Color.white);
addMouseListener(this);
addMouseMotionListener(this);
radialMenu.setItemLabelAndID(RadialMenuWidget.CENTRAL_ITEM, "", -1);
radialMenu.setItemLabelAndID(RadialMenuWidget.NORTH, sd.modeNames[sd.MODE_PENCIL], sd.MODE_PENCIL);
radialMenu.setItemLabelAndID(RadialMenuWidget.EAST, sd.modeNames[sd.MODE_RECT_SELECT], sd.MODE_RECT_SELECT);
radialMenu.setItemLabelAndID(RadialMenuWidget.WEST, sd.modeNames[sd.MODE_MOVE_SELECTION],
sd.MODE_MOVE_SELECTION);
}
public Dimension getPreferredSize() {
return new Dimension(Constant.INITIAL_WINDOW_WIDTH, Constant.INITIAL_WINDOW_HEIGHT);
}
public void clear() {
selectedStrokes.clear();
drawing.clear();
repaint();
}
public void deleteSelection() {
for (Stroke s : selectedStrokes) {
drawing.strokes.remove(s);
}
drawing.markBoundingRectangleDirty();
selectedStrokes.clear();
}
public void frameDrawing() {
gw.frame(drawing.getBoundingRectangle(), true);
}
public void flipSelection() {
for (Stroke s : selectedStrokes) {
Stroke sNew = new Stroke();
for (Point2D point2d : s.getPoints()) {
}
drawing.strokes.add(sNew);
}
drawing.markBoundingRectangleDirty();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
gw.set(g);
if (getWidth() != gw.getWidth() || getHeight() != gw.getHeight())
gw.resize(getWidth(), getHeight());
gw.clear(1, 1, 1);
gw.setupForDrawing();
gw.setCoordinateSystemToWorldSpaceUnits();
gw.enableAlphaBlending();
gw.setColor(1.0f, 0.5f, 0, 0.3f); // transparent orange
// draw filled rectangles over the selected strokes
for (Stroke s : selectedStrokes) {
AlignedRectangle2D r = s.getBoundingRectangle();
Vector2D diagonal = r.getDiagonal();
gw.fillRect(r.getMin().x(), r.getMin().y(), diagonal.x(), diagonal.y());
}
gw.setColor(0, 0, 0);
drawing.draw(gw);
gw.setCoordinateSystemToPixels();
if (currentDragMode == DRAG_MODE_TOOL) {
switch (simpleDraw.currentMode) {
case SimpleDraw.MODE_PENCIL:
gw.setColor(stroke.getRgbSelect());
gw.drawPolyline(pointerHistory);
break;
case SimpleDraw.MODE_RECT_SELECT:
gw.setColor(1.0f, 0.5f, 0, 0.3f); // transparent orange
gw.fillRect(drag_start_x, drag_start_y, mouse_x - drag_start_x, mouse_y - drag_start_y);
gw.setColor(1.0f, 0, 0); // red
gw.drawRect(drag_start_x, drag_start_y, mouse_x - drag_start_x, mouse_y - drag_start_y);
break;
case SimpleDraw.MODE_MOVE_SELECTION:
break;
}
}
if (radialMenu.isVisible())
radialMenu.draw(gw);
}
public void mouseClicked(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
if (currentDragMode != DRAG_MODE_NONE)
// The user is already dragging with a previously pressed button,
// so ignore the press event from this new button.
return;
// **
/*
* if (SwingUtilities.isLeftMouseButton(e) && e.isControlDown()) {
* //javax.swing.JOptionPane.showMessageDialog(null,"OK OK"); }
*/
drag_start_x = previous_mouse_x = mouse_x = e.getX();
drag_start_y = previous_mouse_y = mouse_y = e.getY();
if (radialMenu.isVisible() || (SwingUtilities.isRightMouseButton(e) && !e.isShiftDown())) {
int returnValue = radialMenu.pressEvent(mouse_x, mouse_y);
if (returnValue == CustomWidget.S_REDRAW)
repaint();
if (returnValue != CustomWidget.S_EVENT_NOT_CONSUMED)
return;
} else if (SwingUtilities.isRightMouseButton(e) && e.isShiftDown()) {
currentDragMode = DRAG_MODE_ZOOM;
} else if (SwingUtilities.isLeftMouseButton(e) && e.isShiftDown()) {
currentDragMode = DRAG_MODE_PAN;
} else if (SwingUtilities.isLeftMouseButton(e) && !e.isShiftDown()) {
pointerHistory.clear();
pointerHistory.add(new Point2D(mouse_x, mouse_y));
currentDragMode = DRAG_MODE_TOOL;
}
}
public void mouseReleased(MouseEvent e) {
if (radialMenu.isVisible() && SwingUtilities.isRightMouseButton(e)) {
int returnValue = radialMenu.releaseEvent(mouse_x, mouse_y);
int itemID = radialMenu.getIDOfSelection();
if (0 <= itemID && itemID < SimpleDraw.NUM_MODES) {
simpleDraw.setCurrentMode(itemID);
}
if (returnValue == CustomWidget.S_REDRAW)
repaint();
if (returnValue != CustomWidget.S_EVENT_NOT_CONSUMED)
return;
} else if (currentDragMode == DRAG_MODE_ZOOM && SwingUtilities.isRightMouseButton(e)) {
currentDragMode = DRAG_MODE_NONE;
} else if (currentDragMode == DRAG_MODE_PAN && SwingUtilities.isLeftMouseButton(e)) {
currentDragMode = DRAG_MODE_NONE;
} else if (currentDragMode == DRAG_MODE_TOOL && SwingUtilities.isLeftMouseButton(e)) {
Stroke newStroke;
switch (simpleDraw.currentMode) {
case SimpleDraw.MODE_PENCIL:
newStroke = new Stroke();
for (Point2D p : pointerHistory) {
newStroke.addPoint(gw.convertPixelsToWorldSpaceUnits(p));
}
newStroke.setRgbSelect(stroke.getRgbSelect());
drawing.addStroke(newStroke);
break;
case SimpleDraw.MODE_RECT_SELECT:
// complete a rectangle selection
AlignedRectangle2D selectedRectangle = new AlignedRectangle2D(
gw.convertPixelsToWorldSpaceUnits(new Point2D(drag_start_x, drag_start_y)),
gw.convertPixelsToWorldSpaceUnits(new Point2D(mouse_x, mouse_y)));
if (selectedRectangle.getCenter().equals(gw.convertPixelsToWorldSpaceUnits(new Point2D(mouse_x, mouse_y)))) {
selectedStrokes.clear();
List<Float> listDist = new ArrayList<Float>();
float i;
float min = 1000000000;
Stroke sTmp = new Stroke();
for (Stroke s : drawing.strokes) {
if (!s.isContainedInRectangle(selectedRectangle)) {
for (Point2D point2d : s.getPoints()) {
i = (point2d).distance(selectedRectangle.getCenter());
listDist.add(i);
}
if (min > Collections.min(listDist)) {
min = Collections.min(listDist);
sTmp = s;
}
}
}
selectedStrokes.add(sTmp);
}
if (SwingUtilities.isLeftMouseButton(e) && e.isControlDown()) {
for (Stroke s : drawing.strokes) {
if (s.isContainedInRectangle(selectedRectangle)) {
if (!selectedStrokes.contains(s))
selectedStrokes.add(s);
}
else {
for (Point2D point2d : s.getPoints()) {
if (selectedRectangle.contains(point2d)) {
if (!selectedStrokes.contains(s)) {
selectedStrokes.add(s);
}
}
}
}
}
} else if (SwingUtilities.isLeftMouseButton(e) && !(selectedRectangle.getCenter()
.equals(gw.convertPixelsToWorldSpaceUnits(new Point2D(mouse_x, mouse_y))))) {
selectedStrokes.clear();
for (Stroke s : drawing.strokes) {
if (s.isContainedInRectangle(selectedRectangle)) {
if (!selectedStrokes.contains(s))
selectedStrokes.add(s);
} else {
for (Point2D point2d : s.getPoints()) {
if (selectedRectangle.contains(point2d)) {
if (!selectedStrokes.contains(s))
selectedStrokes.add(s);
}
}
}
}
}
break;
case SimpleDraw.MODE_MOVE_SELECTION:
break;
}
currentDragMode = DRAG_MODE_NONE;
repaint();
}
}
public void mouseMoved(MouseEvent e) {
mouse_x = e.getX();
mouse_y = e.getY();
if (e.isShiftDown()) {
// For debugging only:
Point2D pointInWorldSpace = gw.convertPixelsToWorldSpaceUnits(new Point2D(mouse_x, mouse_y));
System.out.println("Pixel coordinates: " + mouse_x + "," + mouse_y + " World coordinates: "
+ pointInWorldSpace.x() + "," + pointInWorldSpace.y());
}
}
public void mouseDragged(MouseEvent e) {
previous_mouse_x = mouse_x;
previous_mouse_y = mouse_y;
mouse_x = e.getX();
mouse_y = e.getY();
int delta_x = mouse_x - previous_mouse_x;
int delta_y = mouse_y - previous_mouse_y;
if (radialMenu.isVisible()) {
int returnValue = radialMenu.dragEvent(mouse_x, mouse_y);
if (returnValue == CustomWidget.S_REDRAW)
repaint();
if (returnValue != CustomWidget.S_EVENT_NOT_CONSUMED)
return;
} else if (currentDragMode == DRAG_MODE_PAN) {
gw.pan(delta_x, delta_y);
repaint();
} else if (currentDragMode == DRAG_MODE_ZOOM) {
gw.zoomIn((float) Math.pow(Constant.zoomFactorPerPixelDragged, delta_x - delta_y));
repaint();
} else if (currentDragMode == DRAG_MODE_TOOL) {
switch (simpleDraw.currentMode) {
case SimpleDraw.MODE_PENCIL:
pointerHistory.add(new Point2D(mouse_x, mouse_y));
break;
case SimpleDraw.MODE_RECT_SELECT:
break;
case SimpleDraw.MODE_MOVE_SELECTION:
Vector2D v = Point2D.diff(gw.convertPixelsToWorldSpaceUnits(new Point2D(mouse_x, mouse_y)),
gw.convertPixelsToWorldSpaceUnits(new Point2D(previous_mouse_x, previous_mouse_y)));
for (Stroke s : selectedStrokes) {
s.translate(v);
}
drawing.markBoundingRectangleDirty();
break;
}
repaint();
}
}
}
public class SimpleDraw implements ActionListener {
static final String applicationName = "Simple Draw";
JFrame frame;
Container toolPanel;
MyCanvas canvas;
JMenuItem clearMenuItem, quitMenuItem, aboutMenuItem;
JCheckBoxMenuItem toolsMenuItem;
public static final int MODE_PENCIL = 0;
public static final int MODE_RECT_SELECT = 1;
public static final int MODE_MOVE_SELECTION = 2;
public static final int NUM_MODES = 3;
public static final int BLACK_PEN = 0;
public static final int RED_PEN = 1;
public static final int GREEN_PEN = 2;
public static final int NUM_COLORS = 3;
JRadioButton[] modeButtons = new JRadioButton[NUM_MODES];
JRadioButton[] colorButtons = new JRadioButton[NUM_MODES];
public String[] modeNames = new String[NUM_MODES];
public String[] colorsNames = new String[NUM_COLORS];
public int currentMode = MODE_PENCIL;
JButton deleteButton;
JButton frameButton;
JButton flipSelectionButton;
public void setCurrentMode(int mode) {
currentMode = mode;
modeButtons[mode].setSelected(true);
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == clearMenuItem) {
canvas.clear();
} else if (source == quitMenuItem) {
int response = JOptionPane.showConfirmDialog(frame, "Really quit?", "Confirm Quit",
JOptionPane.YES_NO_OPTION);
if (response == JOptionPane.YES_OPTION) {
System.exit(0);
}
} else if (source == toolsMenuItem) {
Container pane = frame.getContentPane();
if (toolsMenuItem.isSelected()) {
pane.removeAll();
pane.add(toolPanel);
pane.add(canvas);
} else {
pane.removeAll();
pane.add(canvas);
}
frame.invalidate();
frame.validate();
} else if (source == aboutMenuItem) {
JOptionPane.showMessageDialog(frame, "'" + applicationName + "' sample program\n" + "written July 2012\n",
"About", JOptionPane.INFORMATION_MESSAGE);
} else if (source == deleteButton) {
canvas.deleteSelection();
canvas.repaint();
} else if (source == frameButton) {
canvas.frameDrawing();
canvas.repaint();
} else if (source == flipSelectionButton) {
canvas.flipSelection();
canvas.repaint();
} else {
for (int i = 0; i < NUM_MODES; ++i) {
if (source == modeButtons[i]) {
currentMode = i;
return;
}
}
}
}
// For thread safety, this should be invoked
// from the event-dispatching thread.
//
private void createUI() {
if (!SwingUtilities.isEventDispatchThread()) {
System.out.println("Warning: UI is not being created in the Event Dispatch Thread!");
assert false;
}
modeNames[MODE_PENCIL] = "Pencil";
modeNames[MODE_RECT_SELECT] = "Rectangle Select";
modeNames[MODE_MOVE_SELECTION] = "Move Selection";
colorsNames[BLACK_PEN] = "Black";
colorsNames[RED_PEN] = "Red";
colorsNames[GREEN_PEN] = "Green";
frame = new JFrame(applicationName);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
clearMenuItem = new JMenuItem("Clear");
clearMenuItem.addActionListener(this);
menu.add(clearMenuItem);
menu.addSeparator();
quitMenuItem = new JMenuItem("Quit");
quitMenuItem.addActionListener(this);
menu.add(quitMenuItem);
menuBar.add(menu);
menu = new JMenu("View");
toolsMenuItem = new JCheckBoxMenuItem("Show Tools");
toolsMenuItem.setSelected(true);
toolsMenuItem.addActionListener(this);
menu.add(toolsMenuItem);
menuBar.add(menu);
menu = new JMenu("Help");
aboutMenuItem = new JMenuItem("About");
aboutMenuItem.addActionListener(this);
menu.add(aboutMenuItem);
menuBar.add(menu);
frame.setJMenuBar(menuBar);
toolPanel = new JPanel();
toolPanel.setLayout(new BoxLayout(toolPanel, BoxLayout.Y_AXIS));
canvas = new MyCanvas(this);
Container pane = frame.getContentPane();
pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
pane.add(toolPanel);
pane.add(canvas);
ButtonGroup group = new ButtonGroup();
for (int i = 0; i < NUM_MODES; ++i) {
modeButtons[i] = new JRadioButton(modeNames[i]);
modeButtons[i].setAlignmentX(Component.LEFT_ALIGNMENT);
modeButtons[i].addActionListener(this);
if (i == currentMode)
modeButtons[i].setSelected(true);
toolPanel.add(modeButtons[i]);
group.add(modeButtons[i]);
}
ButtonGroup group2 = new ButtonGroup();
toolPanel.add(new JLabel("=> Select the color"));
for (int i = 0; i < NUM_MODES; ++i) {
colorButtons[i] = new JRadioButton(colorsNames[i]);
colorButtons[i].setAlignmentX(Component.LEFT_ALIGNMENT);
colorButtons[i].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (e.getActionCommand().equals("Red")) {
canvas.stroke.setRgbSelect(Color.red);
}
if (e.getActionCommand().equals("Green")) {
canvas.stroke.setRgbSelect(Color.green);
}
if (e.getActionCommand().equals("Black")) {
canvas.stroke.setRgbSelect(Color.black);
}
}
});
colorButtons[0].setSelected(true);
toolPanel.add(colorButtons[i]);
group2.add(colorButtons[i]);
}
deleteButton = new JButton("Delete Selection");
deleteButton.setAlignmentX(Component.LEFT_ALIGNMENT);
deleteButton.addActionListener(this);
toolPanel.add(deleteButton);
frameButton = new JButton("Frame Drawing");
frameButton.setAlignmentX(Component.LEFT_ALIGNMENT);
frameButton.addActionListener(this);
toolPanel.add(frameButton);
flipSelectionButton = new JButton("Flip Selection");
flipSelectionButton.setAlignmentX(Component.LEFT_ALIGNMENT);
flipSelectionButton.addActionListener(this);
toolPanel.add(flipSelectionButton);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
// Schedule the creation of the UI for the event-dispatching thread.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
SimpleDraw sp = new SimpleDraw();
sp.createUI();
}
});
}
}