Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 266123 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/ScreenshotCreationPage.java (-176 / +929 lines)
Lines 9-14 Link Here
9
 *     Balazs Brinkus - initial API and implementation
9
 *     Balazs Brinkus - initial API and implementation
10
 *     Tasktop Technologies - improvements
10
 *     Tasktop Technologies - improvements
11
 *     Willian Mitsuda - improvements
11
 *     Willian Mitsuda - improvements
12
 *     Hiroyuki Inaba - improvements
12
 *******************************************************************************/
13
 *******************************************************************************/
13
14
14
package org.eclipse.mylyn.internal.provisional.commons.ui;
15
package org.eclipse.mylyn.internal.provisional.commons.ui;
Lines 16-21 Link Here
16
import java.util.ArrayList;
17
import java.util.ArrayList;
17
import java.util.EnumSet;
18
import java.util.EnumSet;
18
import java.util.HashMap;
19
import java.util.HashMap;
20
import java.util.HashSet;
19
import java.util.List;
21
import java.util.List;
20
import java.util.Map;
22
import java.util.Map;
21
import java.util.Set;
23
import java.util.Set;
Lines 32-44 Link Here
32
import org.eclipse.jface.layout.GridDataFactory;
34
import org.eclipse.jface.layout.GridDataFactory;
33
import org.eclipse.jface.resource.ImageDescriptor;
35
import org.eclipse.jface.resource.ImageDescriptor;
34
import org.eclipse.jface.wizard.WizardPage;
36
import org.eclipse.jface.wizard.WizardPage;
35
import org.eclipse.mylyn.internal.commons.ui.ColorSelectionWindow;
36
import org.eclipse.mylyn.internal.commons.ui.Messages;
37
import org.eclipse.mylyn.internal.commons.ui.Messages;
37
import org.eclipse.swt.SWT;
38
import org.eclipse.swt.SWT;
38
import org.eclipse.swt.custom.ScrolledComposite;
39
import org.eclipse.swt.custom.ScrolledComposite;
39
import org.eclipse.swt.custom.ViewForm;
40
import org.eclipse.swt.custom.ViewForm;
40
import org.eclipse.swt.events.ControlAdapter;
41
import org.eclipse.swt.events.ControlAdapter;
41
import org.eclipse.swt.events.ControlEvent;
42
import org.eclipse.swt.events.ControlEvent;
43
import org.eclipse.swt.events.MenuDetectEvent;
44
import org.eclipse.swt.events.MenuDetectListener;
42
import org.eclipse.swt.events.MouseAdapter;
45
import org.eclipse.swt.events.MouseAdapter;
43
import org.eclipse.swt.events.MouseEvent;
46
import org.eclipse.swt.events.MouseEvent;
44
import org.eclipse.swt.events.MouseMoveListener;
47
import org.eclipse.swt.events.MouseMoveListener;
Lines 46-63 Link Here
46
import org.eclipse.swt.events.PaintListener;
49
import org.eclipse.swt.events.PaintListener;
47
import org.eclipse.swt.graphics.Color;
50
import org.eclipse.swt.graphics.Color;
48
import org.eclipse.swt.graphics.Cursor;
51
import org.eclipse.swt.graphics.Cursor;
52
import org.eclipse.swt.graphics.Font;
53
import org.eclipse.swt.graphics.FontData;
49
import org.eclipse.swt.graphics.GC;
54
import org.eclipse.swt.graphics.GC;
50
import org.eclipse.swt.graphics.Image;
55
import org.eclipse.swt.graphics.Image;
51
import org.eclipse.swt.graphics.Point;
56
import org.eclipse.swt.graphics.Point;
52
import org.eclipse.swt.graphics.RGB;
57
import org.eclipse.swt.graphics.RGB;
53
import org.eclipse.swt.graphics.Rectangle;
58
import org.eclipse.swt.graphics.Rectangle;
54
import org.eclipse.swt.graphics.Region;
59
import org.eclipse.swt.graphics.Region;
60
import org.eclipse.swt.layout.GridData;
61
import org.eclipse.swt.layout.GridLayout;
62
import org.eclipse.swt.layout.RowLayout;
55
import org.eclipse.swt.widgets.Canvas;
63
import org.eclipse.swt.widgets.Canvas;
56
import org.eclipse.swt.widgets.Composite;
64
import org.eclipse.swt.widgets.Composite;
57
import org.eclipse.swt.widgets.Display;
65
import org.eclipse.swt.widgets.Display;
58
import org.eclipse.swt.widgets.Event;
66
import org.eclipse.swt.widgets.Event;
67
import org.eclipse.swt.widgets.Listener;
68
import org.eclipse.swt.widgets.Menu;
69
import org.eclipse.swt.widgets.MenuItem;
59
import org.eclipse.swt.widgets.Shell;
70
import org.eclipse.swt.widgets.Shell;
60
import org.eclipse.swt.widgets.ToolItem;
71
import org.eclipse.swt.widgets.Text;
61
import org.eclipse.ui.progress.UIJob;
72
import org.eclipse.ui.progress.UIJob;
62
73
63
/**
74
/**
Lines 71-91 Link Here
71
 */
82
 */
72
public class ScreenshotCreationPage extends WizardPage {
83
public class ScreenshotCreationPage extends WizardPage {
73
84
74
	private IAction captureAction;
85
	private SelectToolAction captureAction;
75
86
76
	private IAction fitAction;
87
	private SelectToolAction fitAction;
77
88
78
	private IAction cropAction;
89
	private IAction cropAction;
79
90
80
	private IAction markAction;
91
	private IAction markAction;
81
92
82
	private IAction colorAction;
93
	private IAction clearAction;
83
94
84
	private Image colorIcon;
95
	private IAction undoAction;
85
96
86
	private Color markColor;
97
	private IAction redoAction;
87
98
88
	private IAction clearAction;
99
	private Composite paletteArea;
100
101
	private SelectToolAction drawLineToolbar;
102
103
	private SelectToolAction drawArrowToolbar;
104
105
	private SelectToolAction drawBoxToolbar;
106
107
	private SelectToolAction drawTextToolbar;
108
109
	private SelectToolAction lineTypeToolbar;
110
111
	private SelectToolAction lineBoldToolbar;
112
113
	private SelectToolAction drawColorToolbar;
89
114
90
	private boolean imageDirty;
115
	private boolean imageDirty;
91
116
Lines 99-104 Link Here
99
	 */
124
	 */
100
	private Image workImage;
125
	private Image workImage;
101
126
127
	private Image previousImage;
128
102
	/**
129
	/**
103
	 * Used to draw into {@link #workImage}
130
	 * Used to draw into {@link #workImage}
104
	 */
131
	 */
Lines 155-160 Link Here
155
	 */
182
	 */
156
	private EditorAction currentAction = EditorAction.CROPPING;
183
	private EditorAction currentAction = EditorAction.CROPPING;
157
184
185
	private boolean isFirstCapture = true;
186
187
	private Text textArea;
188
189
	/**
190
	 * Mouse event history. Entry is [0] MouseDown/MouseMove/MouseUp, [1] x, [2] y
191
	 */
192
	private List<int[]> historyMouseEvent = new ArrayList<int[]>();
193
194
	/**
195
	 * Draw tool history. Entry is [0] drawHistory index, [1] FREE/LINE/BOX/OVAL, [2] Line type, [3] Bold, [4] R/G/B
196
	 */
197
	private List<int[]> historyDrawTool = new ArrayList<int[]>();
198
199
	private List<StringBuffer> historyDrawText = new ArrayList<StringBuffer>();
200
201
	private List<String> historyDrawFont = new ArrayList<String>();
202
203
	private int historyCheckpoint = 0;
204
158
	public ScreenshotCreationPage() {
205
	public ScreenshotCreationPage() {
159
		super("ScreenShotAttachment"); //$NON-NLS-1$
206
		super("ScreenShotAttachment"); //$NON-NLS-1$
160
		setTitle(Messages.ScreenshotCreationPage_CAPTURE_SCRRENSHOT);
207
		setTitle(Messages.ScreenshotCreationPage_CAPTURE_SCRRENSHOT);
Lines 173-185 Link Here
173
220
174
		// TODO: need disabled versions of all toolbar icons
221
		// TODO: need disabled versions of all toolbar icons
175
		ToolBarManager tbm = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
222
		ToolBarManager tbm = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
176
		captureAction = new Action(Messages.ScreenshotCreationPage_Capture_Desktop_C, IAction.AS_PUSH_BUTTON) {
177
223
178
			private boolean isFirstCapture = true;
224
		captureAction = new SelectToolAction(getShell(), Messages.ScreenshotCreationPage_Capture_Desktop_C,
225
				SelectToolAction.CAPTURE_DROP_DOWN_MENU) {
179
226
180
			@Override
227
			@Override
181
			public void run() {
228
			public void run() {
182
				captureScreenshotContent();
229
				if (captureAction.getSelect() == SelectToolAction.CAPTURE_DESKTOP) {
230
					captureScreenshotContent();
231
				} else if (captureAction.getSelect() == SelectToolAction.CAPTURE_CLIPBOARD) {
232
					captureScreenshotContent(captureAction.getClipboardImage());
233
				} else if (captureAction.getSelect() == SelectToolAction.CAPTURE_RECTANGLE) {
234
					captureScreenshotContentFromSelection();
235
				} else {
236
					captureScreenshotContent(captureAction.getFileImage());
237
				}
183
				setErrorMessage(null);
238
				setErrorMessage(null);
184
				if (isFirstCapture) {
239
				if (isFirstCapture) {
185
					isFirstCapture = false;
240
					isFirstCapture = false;
Lines 189-199 Link Here
189
					markAction.setEnabled(true);
244
					markAction.setEnabled(true);
190
					clearAction.setEnabled(false);
245
					clearAction.setEnabled(false);
191
				}
246
				}
247
248
				historyMouseEvent = new ArrayList<int[]>();
249
				historyDrawTool = new ArrayList<int[]>();
250
				historyDrawText = new ArrayList<StringBuffer>();
251
				historyDrawFont = new ArrayList<String>();
252
				historyCheckpoint = 0;
253
				undoAction.setEnabled(false);
254
				redoAction.setEnabled(false);
192
			}
255
			}
193
256
257
			@Override
258
			protected boolean isEnableRectangle() {
259
				return (currentSelection != null);
260
			}
194
		};
261
		};
195
		captureAction.setToolTipText(Messages.ScreenshotCreationPage_Capture_Desktop);
262
		captureAction.setToolTipText(Messages.ScreenshotCreationPage_Capture_Desktop);
196
		captureAction.setImageDescriptor(ImageDescriptor.createFromImage(CommonImages.getImage(CommonImages.IMAGE_CAPTURE)));
263
		captureAction.setImageDescriptor(ImageDescriptor.createFromImage(CommonImages.getImage(CommonImages.IMAGE_CAPTURE)));
264
		captureAction.setShowMenuAlways(false);
197
265
198
//		captureDelayedButton = new Button(buttonsComposite, SWT.PUSH);
266
//		captureDelayedButton = new Button(buttonsComposite, SWT.PUSH);
199
//		final String captureIn = "Capture in ";
267
//		final String captureIn = "Capture in ";
Lines 228-243 Link Here
228
//			}
296
//			}
229
//		});
297
//		});
230
298
231
		fitAction = new Action("", IAction.AS_CHECK_BOX) { //$NON-NLS-1$
299
		fitAction = new SelectToolAction(Messages.ScreenshotCreationPage_Fit_Image_F,
300
				SelectToolAction.ZOOM_DROP_DOWN_MENU) {
232
			@Override
301
			@Override
233
			public void run() {
302
			public void run() {
234
				refreshCanvasSize();
303
				refreshCanvasSize();
235
			}
304
			}
236
		};
305
		};
237
		fitAction.setToolTipText(Messages.ScreenshotCreationPage_Fit_Image);
306
		fitAction.setToolTipText(Messages.ScreenshotCreationPage_Fit_Image);
238
		fitAction.setText(Messages.ScreenshotCreationPage_Fit_Image_F);
239
		fitAction.setImageDescriptor(ImageDescriptor.createFromImage(CommonImages.getImage(CommonImages.IMAGE_FIT)));
307
		fitAction.setImageDescriptor(ImageDescriptor.createFromImage(CommonImages.getImage(CommonImages.IMAGE_FIT)));
240
		fitAction.setChecked(true);
308
		//fitAction.setChecked(true);
241
		fitAction.setEnabled(false);
309
		fitAction.setEnabled(false);
242
310
243
		cropAction = new Action(Messages.ScreenshotCreationPage_Crop_R, IAction.AS_RADIO_BUTTON) {
311
		cropAction = new Action(Messages.ScreenshotCreationPage_Crop_R, IAction.AS_RADIO_BUTTON) {
Lines 246-252 Link Here
246
				currentAction = EditorAction.CROPPING;
314
				currentAction = EditorAction.CROPPING;
247
				cropAction.setChecked(true);
315
				cropAction.setChecked(true);
248
				markAction.setChecked(false);
316
				markAction.setChecked(false);
249
				colorAction.setEnabled(false);
317
				undoAction.setEnabled(false);
318
				redoAction.setEnabled(false);
250
				canvas.redraw();
319
				canvas.redraw();
251
			}
320
			}
252
		};
321
		};
Lines 256-266 Link Here
256
325
257
		markAction = new Action(Messages.ScreenshotCreationPage_Annotate, IAction.AS_RADIO_BUTTON) {
326
		markAction = new Action(Messages.ScreenshotCreationPage_Annotate, IAction.AS_RADIO_BUTTON) {
258
			@Override
327
			@Override
328
			public void setChecked(boolean checked) {
329
				super.setChecked(checked);
330
				if (paletteArea != null) {
331
					boolean isDrawText = (drawTextToolbar.getSelect() >= 0) ? false : checked;
332
					drawLineToolbar.setEnabled(checked);
333
					drawArrowToolbar.setEnabled(checked);
334
					drawBoxToolbar.setEnabled(checked);
335
					drawTextToolbar.setEnabled(checked);
336
					drawColorToolbar.setEnabled(isDrawText);
337
					lineTypeToolbar.setEnabled(isDrawText);
338
					lineBoldToolbar.setEnabled(isDrawText);
339
				}
340
			}
341
342
			@Override
259
			public void run() {
343
			public void run() {
260
				currentAction = EditorAction.MARKING;
344
				currentAction = EditorAction.MARKING;
261
				cropAction.setChecked(false);
345
				cropAction.setChecked(false);
262
				markAction.setChecked(true);
346
				markAction.setChecked(true);
263
				colorAction.setEnabled(true);
347
				undoAction.setEnabled(false);
348
				redoAction.setEnabled(false);
264
				canvas.redraw();
349
				canvas.redraw();
265
			}
350
			}
266
		};
351
		};
Lines 269-326 Link Here
269
//		markAction.setDisabledImageDescriptor(ImageDescriptor.createFromFile(getClass(), "mark_disabled.gif"));
354
//		markAction.setDisabledImageDescriptor(ImageDescriptor.createFromFile(getClass(), "mark_disabled.gif"));
270
		markAction.setEnabled(false);
355
		markAction.setEnabled(false);
271
356
272
		colorAction = new Action("", IAction.AS_DROP_DOWN_MENU) { //$NON-NLS-1$
357
		clearAction = new Action(Messages.ScreenshotCreationPage_Clear, IAction.AS_PUSH_BUTTON) {
273
			@Override
274
			public void runWithEvent(final Event e) {
275
				final ColorSelectionWindow colorWindow = new ColorSelectionWindow(getControl().getShell()) {
276
277
					@Override
278
					protected Point getInitialLocation(Point initialSize) {
279
						ToolItem toolItem = (ToolItem) e.widget;
280
						Rectangle itemBounds = toolItem.getBounds();
281
						Point location = toolItem.getParent().toDisplay(itemBounds.x + itemBounds.width,
282
								itemBounds.y + itemBounds.height);
283
						location.x -= initialSize.x;
284
						return location;
285
					}
286
287
				};
288
				colorWindow.setBlockOnOpen(true);
289
				colorWindow.open();
290
				RGB color = colorWindow.getSelectedRGB();
291
				if (color != null) {
292
					setMarkColor(color);
293
				}
294
			}
295
		};
296
		colorAction.setToolTipText(Messages.ScreenshotCreationPage_Change_pen_color);
297
		colorIcon = new Image(getShell().getDisplay(), 16, 16);
298
		setMarkColor(new RGB(255, 85, 85));
299
		colorAction.setEnabled(false);
300
301
		clearAction = new Action(Messages.ScreenshotCreationPage_Clear_Annotations, IAction.AS_PUSH_BUTTON) {
302
			@Override
358
			@Override
303
			public void run() {
359
			public void run() {
304
				clearAction.setEnabled(false);
360
				clearAction.setEnabled(false);
305
				workImageGC.drawImage(originalImage, 0, 0);
361
				workImageGC.drawImage(originalImage, 0, 0);
306
				canvas.redraw();
362
				canvas.redraw();
307
				setImageDirty(true);
363
				setImageDirty(true);
364
365
				historyMouseEvent = new ArrayList<int[]>();
366
				historyDrawTool = new ArrayList<int[]>();
367
				historyDrawText = new ArrayList<StringBuffer>();
368
				historyDrawFont = new ArrayList<String>();
369
				historyCheckpoint = 0;
370
				undoAction.setEnabled(false);
371
				redoAction.setEnabled(false);
308
			}
372
			}
309
		};
373
		};
310
		clearAction.setToolTipText(Messages.ScreenshotCreationPage_Clear_all_annotations_made_on_screenshot_image);
374
		clearAction.setToolTipText(Messages.ScreenshotCreationPage_Clear_all_annotations_made_on_screenshot_image);
311
		clearAction.setImageDescriptor(CommonImages.CLEAR);
375
		clearAction.setImageDescriptor(CommonImages.CLEAR);
312
		clearAction.setEnabled(false);
376
		clearAction.setEnabled(false);
313
377
378
		undoAction = new Action(Messages.ScreenshotCreationPage_Undo) {
379
			@Override
380
			public void run() {
381
				if (historyCheckpoint > 0) {
382
					historyCheckpoint--;
383
					drawAnnotationHistory();
384
				}
385
				if (historyCheckpoint == 0) {
386
					undoAction.setEnabled(false);
387
				}
388
				if (historyCheckpoint < historyDrawTool.size()) {
389
					redoAction.setEnabled(true);
390
				}
391
			}
392
		};
393
		undoAction.setToolTipText(Messages.ScreenshotCreationPage_Undo_annotation);
394
		undoAction.setImageDescriptor(CommonImages.EDIT_UNDO);
395
		undoAction.setEnabled(false);
396
397
		redoAction = new Action(Messages.ScreenshotCreationPage_Redo) {
398
			@Override
399
			public void run() {
400
				if (historyCheckpoint < historyDrawTool.size()) {
401
					historyCheckpoint++;
402
					drawAnnotationHistory();
403
				}
404
				if (historyCheckpoint > 0) {
405
					undoAction.setEnabled(true);
406
				}
407
				if (historyCheckpoint >= historyDrawTool.size()) {
408
					redoAction.setEnabled(false);
409
				}
410
			}
411
		};
412
		redoAction.setToolTipText(Messages.ScreenshotCreationPage_Redo_annotation);
413
		redoAction.setImageDescriptor(CommonImages.EDIT_REDO);
414
		redoAction.setEnabled(false);
415
314
		tbm.add(createAndConfigureCI(captureAction));
416
		tbm.add(createAndConfigureCI(captureAction));
315
		tbm.add(createAndConfigureCI(fitAction));
316
		tbm.add(new Separator());
417
		tbm.add(new Separator());
418
		tbm.add(createAndConfigureCI(fitAction));
317
		tbm.add(createAndConfigureCI(cropAction));
419
		tbm.add(createAndConfigureCI(cropAction));
318
		tbm.add(createAndConfigureCI(markAction));
420
		tbm.add(createAndConfigureCI(markAction));
319
		tbm.add(createAndConfigureCI(colorAction));
320
		tbm.add(new Separator());
421
		tbm.add(new Separator());
321
		tbm.add(createAndConfigureCI(clearAction));
422
		tbm.add(createAndConfigureCI(clearAction));
423
		tbm.add(createAndConfigureCI(undoAction));
424
		tbm.add(createAndConfigureCI(redoAction));
425
		tbm.add(new Separator());
426
427
		Composite body = new Composite(vf, SWT.NONE);
428
		GridLayout layout = new GridLayout(2, false);
429
		layout.horizontalSpacing = 0;
430
		layout.verticalSpacing = 0;
431
		layout.marginWidth = 0;
432
		layout.marginHeight = 0;
433
		body.setLayout(layout);
434
		createPaletteBars(body);
322
435
323
		scrolledComposite = new ScrolledComposite(vf, SWT.V_SCROLL | SWT.H_SCROLL);
436
		scrolledComposite = new ScrolledComposite(body, SWT.V_SCROLL | SWT.H_SCROLL);
437
		scrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
324
		canvas = new Canvas(scrolledComposite, SWT.DOUBLE_BUFFERED);
438
		canvas = new Canvas(scrolledComposite, SWT.DOUBLE_BUFFERED);
325
		scrolledComposite.setContent(canvas);
439
		scrolledComposite.setContent(canvas);
326
		canvas.addPaintListener(new PaintListener() {
440
		canvas.addPaintListener(new PaintListener() {
Lines 330-340 Link Here
330
					Rectangle imageBounds = workImage.getBounds();
444
					Rectangle imageBounds = workImage.getBounds();
331
					Rectangle canvasBounds = canvas.getClientArea();
445
					Rectangle canvasBounds = canvas.getClientArea();
332
446
333
					if (fitAction.isChecked()) {
447
					int zoom = fitAction.getSelect();
334
						e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, 0, 0,
448
					switch (zoom) {
335
								canvasBounds.width, canvasBounds.height);
449
					case SelectToolAction.ZOOM_FIT:
336
					} else {
450
						e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, //
451
								0, 0, canvasBounds.width, canvasBounds.height);
452
						break;
453
					case 50:
454
						e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, //
455
								0, 0, imageBounds.width / 2, imageBounds.height / 2);
456
						break;
457
					case 100:
337
						e.gc.drawImage(workImage, 0, 0);
458
						e.gc.drawImage(workImage, 0, 0);
459
						break;
460
					default:
461
						e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, //
462
								0, 0, imageBounds.width * zoom / 100, imageBounds.height * zoom / 100);
463
						break;
338
					}
464
					}
339
					drawSelection(e.gc);
465
					drawSelection(e.gc);
340
				} else {
466
				} else {
Lines 347-353 Link Here
347
		scrolledComposite.addControlListener(new ControlAdapter() {
473
		scrolledComposite.addControlListener(new ControlAdapter() {
348
			@Override
474
			@Override
349
			public void controlResized(ControlEvent e) {
475
			public void controlResized(ControlEvent e) {
350
				if (fitAction.isChecked()) {
476
				if (fitAction.getSelect() == SelectToolAction.ZOOM_FIT) {
351
					refreshCanvasSize();
477
					refreshCanvasSize();
352
				}
478
				}
353
			}
479
			}
Lines 355-399 Link Here
355
		scrolledComposite.setEnabled(false);
481
		scrolledComposite.setEnabled(false);
356
482
357
		vf.setTopLeft(tbm.createControl(vf));
483
		vf.setTopLeft(tbm.createControl(vf));
358
		vf.setContent(scrolledComposite);
484
		vf.setContent(body);
359
		registerMouseListeners();
485
		registerMouseListeners();
360
486
487
		vf.setLayoutData(new GridData(GridData.FILL_BOTH));
488
361
		Dialog.applyDialogFont(vf);
489
		Dialog.applyDialogFont(vf);
362
	}
490
	}
363
491
364
	private ActionContributionItem createAndConfigureCI(IAction action) {
492
	private void createPaletteBars(Composite body) {
365
		ActionContributionItem ci = new ActionContributionItem(action);
493
		paletteArea = new Composite(body, SWT.NONE);
366
		ci.setMode(ActionContributionItem.MODE_FORCE_TEXT);
494
		paletteArea.setLayoutData(new GridData(GridData.FILL_VERTICAL));
367
		return ci;
495
		RowLayout rowlayout = new RowLayout(SWT.VERTICAL);
368
	}
496
		rowlayout.marginRight += 1;
497
		paletteArea.setLayout(rowlayout);
498
499
		paletteArea.addListener(SWT.Paint, new Listener() {
500
			public void handleEvent(Event e) {
501
				Color gcForeground = e.gc.getForeground();
502
				Rectangle bounds = ((Composite) e.widget).getBounds();
503
				Color border = e.widget.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
504
				e.gc.setForeground(border);
505
				e.gc.drawLine(bounds.width - 1, 0, bounds.width - 1, bounds.height);
506
				e.gc.setForeground(gcForeground);
507
			}
508
		});
509
		paletteArea.addMenuDetectListener(new MenuDetectListener() {
510
511
			public void menuDetected(MenuDetectEvent e) {
512
				Menu rightClickMenu = new Menu(Display.getDefault().getActiveShell(), SWT.POP_UP);
513
				MenuItem menuItem = new MenuItem(rightClickMenu, SWT.CHECK);
514
				menuItem.setText(Messages.ScreenshotCreationPage_Show_Line_Type_Selector);
515
				menuItem.setSelection(lineTypeToolbar.getVisible());
516
				menuItem.addListener(SWT.Selection, new Listener() {
517
					public void handleEvent(final Event event) {
518
						lineTypeToolbar.setVisible(!lineTypeToolbar.getVisible());
519
						paletteArea.layout();
520
					}
521
				});
522
				menuItem = new MenuItem(rightClickMenu, SWT.CHECK);
523
				menuItem.setText(Messages.ScreenshotCreationPage_Show_Line_Bold_Selector);
524
				menuItem.setSelection(lineBoldToolbar.getVisible());
525
				menuItem.addListener(SWT.Selection, new Listener() {
526
					public void handleEvent(final Event event) {
527
						lineBoldToolbar.setVisible(!lineBoldToolbar.getVisible());
528
						paletteArea.layout();
529
					}
530
				});
531
				rightClickMenu.setLocation(e.x, e.y);
532
				rightClickMenu.setVisible(true);
533
			}
534
		});
535
		drawLineToolbar = new SelectToolAction(paletteArea, SelectToolAction.DRAWLINE_TOOLBAR) {
536
537
			@Override
538
			public void run() {
539
				drawArrowToolbar.setUnselect();
540
				drawBoxToolbar.setUnselect();
541
				drawTextToolbar.setUnselect();
542
			}
543
		};
544
		drawLineToolbar.setEnabled(false);
545
		drawArrowToolbar = new SelectToolAction(paletteArea, SelectToolAction.DRAWARROW_TOOLBAR) {
369
546
370
	private void setMarkColor(RGB color) {
547
			@Override
371
		if (markColor != null) {
548
			public void run() {
372
			markColor.dispose();
549
				drawLineToolbar.setUnselect();
550
				drawBoxToolbar.setUnselect();
551
				drawTextToolbar.setUnselect();
552
				drawColorToolbar.setEnabled(true);
553
				lineTypeToolbar.setEnabled(true);
554
				lineBoldToolbar.setEnabled(true);
555
			}
556
		};
557
		drawArrowToolbar.setEnabled(false);
558
		drawBoxToolbar = new SelectToolAction(paletteArea, SelectToolAction.DRAWBOX_TOOLBAR) {
559
560
			@Override
561
			public void run() {
562
				drawLineToolbar.setUnselect();
563
				drawArrowToolbar.setUnselect();
564
				drawTextToolbar.setUnselect();
565
				drawColorToolbar.setEnabled(true);
566
				lineTypeToolbar.setEnabled(true);
567
				lineBoldToolbar.setEnabled(true);
568
			}
569
		};
570
		drawBoxToolbar.setEnabled(false);
571
		drawTextToolbar = new SelectToolAction(paletteArea, SelectToolAction.DRAWTEXT_TOOLBAR) {
572
573
			@Override
574
			public void run() {
575
				drawLineToolbar.setUnselect();
576
				drawArrowToolbar.setUnselect();
577
				drawBoxToolbar.setUnselect();
578
				drawColorToolbar.setEnabled(false);
579
				lineTypeToolbar.setEnabled(false);
580
				lineBoldToolbar.setEnabled(false);
581
			}
582
		};
583
		drawTextToolbar.setEnabled(false);
584
		drawColorToolbar = new SelectToolAction(paletteArea, SelectToolAction.COLOR_TOOLBAR);
585
		drawColorToolbar.setEnabled(false);
586
		lineTypeToolbar = new SelectToolAction(paletteArea, SelectToolAction.LINETYPE_TOOLBAR);
587
		lineTypeToolbar.setEnabled(false);
588
		lineTypeToolbar.setVisible(false);
589
		lineBoldToolbar = new SelectToolAction(paletteArea, SelectToolAction.LINEBOLD_TOOLBAR);
590
		lineBoldToolbar.setEnabled(false);
591
		lineBoldToolbar.setVisible(false);
592
	}
593
594
	private int getSelectDrawToolbar() {
595
		int drawTool;
596
		if ((drawTool = drawLineToolbar.getSelect()) >= 0) {
597
			return drawTool;
373
		}
598
		}
374
		markColor = new Color(getShell().getDisplay(), color);
599
		if ((drawTool = drawArrowToolbar.getSelect()) >= 0) {
375
		if (workImageGC != null) {
600
			return drawTool;
376
			workImageGC.setForeground(markColor);
377
		}
601
		}
602
		if ((drawTool = drawBoxToolbar.getSelect()) >= 0) {
603
			return drawTool;
604
		}
605
		return SelectToolAction.DRAW_TEXT;
606
	}
378
607
379
		GC colorGC = new GC(colorIcon);
608
	private ActionContributionItem createAndConfigureCI(IAction action) {
380
		colorGC.setBackground(markColor);
609
		ActionContributionItem ci = new ActionContributionItem(action);
381
		colorGC.fillRectangle(0, 0, 16, 16);
610
		ci.setMode(ActionContributionItem.MODE_FORCE_TEXT);
382
		colorGC.drawRectangle(0, 0, 15, 15);
611
		return ci;
383
		colorGC.dispose();
384
385
		colorAction.setImageDescriptor(ImageDescriptor.createFromImage(colorIcon));
386
	}
612
	}
387
613
388
	@Override
614
	@Override
389
	public void dispose() {
615
	public void dispose() {
390
		disposeImageResources();
616
		disposeImageResources();
391
		if (markColor != null) {
392
			markColor.dispose();
393
		}
394
		if (colorIcon != null) {
395
			colorIcon.dispose();
396
		}
397
617
398
		canvas.setCursor(null);
618
		canvas.setCursor(null);
399
		for (Cursor cursor : cursors.values()) {
619
		for (Cursor cursor : cursors.values()) {
Lines 440-450 Link Here
440
		int y = (int) Math.round(currentSelection.y * scaleFactor);
660
		int y = (int) Math.round(currentSelection.y * scaleFactor);
441
		int right = (int) Math.round((currentSelection.x + currentSelection.width) * scaleFactor);
661
		int right = (int) Math.round((currentSelection.x + currentSelection.width) * scaleFactor);
442
		int bottom = (int) Math.round((currentSelection.y + currentSelection.height) * scaleFactor);
662
		int bottom = (int) Math.round((currentSelection.y + currentSelection.height) * scaleFactor);
443
		int width = Math.min(right, (int) Math.round((workImage.getBounds().width - 1) * scaleFactor)) - x;
663
		int width = Math.min(right, (int) Math.round(workImage.getBounds().width * scaleFactor)) - x;
444
		int height = Math.min(bottom, (int) Math.round((workImage.getBounds().height - 1) * scaleFactor)) - y;
664
		int height = Math.min(bottom, (int) Math.round(workImage.getBounds().height * scaleFactor)) - y;
445
		return new Rectangle(x, y, width, height);
665
		return new Rectangle(x, y, width, height);
446
	}
666
	}
447
667
668
	private Rectangle getOutsideSelection(Rectangle rectangle) {
669
		if (rectangle == null) {
670
			return null;
671
		}
672
		return new Rectangle(rectangle.x - SQUARE_SIZE * 2, rectangle.y - SQUARE_SIZE * 2, //
673
				rectangle.width + SQUARE_SIZE * 4 + 1, rectangle.height + SQUARE_SIZE * 4 + 1);
674
	}
675
676
	private static final int[][] grapGroupPoints = { //
677
	/*    */{ 0, 0, 0 }, { 1, 0, 0 }, { 2, 0, 1 }, { 3, 0, 2 }, { 4, 0, 2 }, //
678
			{ 0, 1, 0 }, /*         *//*         *//*         */{ 4, 1, 2 }, //
679
			{ 0, 2, 3 }, /*         *//*         *//*         */{ 4, 2, 4 }, //
680
			{ 0, 3, 5 }, /*         *//*         *//*         */{ 4, 3, 7 }, //
681
			{ 0, 4, 5 }, { 1, 4, 5 }, { 2, 4, 6 }, { 3, 4, 7 }, { 4, 4, 7 } };
682
683
	private static final int[] grapScanOrder = { 0, 4, 1, 3, 2 };
684
685
	private int getGrabPoint(int x, int y) {
686
		if (currentSelection == null) {
687
			return -1;
688
		}
689
690
		Rectangle inside = getScaledSelection();
691
		Rectangle outside = getOutsideSelection(inside);
692
		int[] xGroupPoint = { outside.x, //
693
				inside.x, //
694
				inside.x + SQUARE_SIZE * 4, //
695
				inside.x + inside.width - SQUARE_SIZE * 4, //
696
				inside.x + inside.width, //
697
				outside.x + outside.width };
698
		int[] yGroupPoint = { outside.y, //
699
				inside.y, //
700
				inside.y + SQUARE_SIZE * 4, //
701
				inside.y + inside.height - SQUARE_SIZE * 4, //
702
				inside.y + inside.height, //
703
				outside.y + outside.height };
704
		int xGroup = -1, yGroup = -1;
705
		for (int element : grapScanOrder) {
706
			if (xGroupPoint[element] <= x && x <= xGroupPoint[element + 1]) {
707
				xGroup = element;
708
				break;
709
			}
710
		}
711
		if (xGroup < 0) {
712
			return -1;
713
		}
714
		for (int element : grapScanOrder) {
715
			if (yGroupPoint[element] <= y && y <= yGroupPoint[element + 1]) {
716
				yGroup = element;
717
				break;
718
			}
719
		}
720
		if (yGroup < 0) {
721
			return -1;
722
		}
723
		for (int[] element : grapGroupPoints) {
724
			if (element[0] == xGroup && element[1] == yGroup) {
725
				return element[2];
726
			}
727
		}
728
		return -1;
729
	}
730
448
	@Override
731
	@Override
449
	public boolean isPageComplete() {
732
	public boolean isPageComplete() {
450
		return workImage != null;
733
		return workImage != null;
Lines 455-460 Link Here
455
		return isPageComplete();
738
		return isPageComplete();
456
	}
739
	}
457
740
741
	private void captureScreenshotContent(Image image) {
742
		final Display display = getShell().getDisplay();
743
		disposeImageResources();
744
		originalImage = image;
745
		Rectangle displayBounds = originalImage.getBounds();
746
		workImage = new Image(display, displayBounds.width, displayBounds.height);
747
		GC gc = new GC(workImage);
748
		gc.drawImage(originalImage, 0, 0);
749
		gc.dispose();
750
751
		workImageGC = new GC(workImage);
752
		workImageGC.setLineCap(SWT.CAP_ROUND);
753
754
		scrolledComposite.setEnabled(true);
755
		clearSelection();
756
		refreshCanvasSize();
757
758
		setPageComplete(true);
759
	}
760
761
	private void captureScreenshotContentFromSelection() {
762
		Display display = getShell().getDisplay();
763
764
		Image image = new Image(display, currentSelection);
765
		GC gc = new GC(image);
766
		gc.drawImage(workImage, currentSelection.x, currentSelection.y, currentSelection.width,
767
				currentSelection.height, 0, 0, currentSelection.width, currentSelection.height);
768
		gc.dispose();
769
		disposeImageResources();
770
771
		originalImage = image;
772
		Rectangle displayBounds = originalImage.getBounds();
773
		workImage = new Image(display, displayBounds.width, displayBounds.height);
774
		gc = new GC(workImage);
775
		gc.drawImage(originalImage, 0, 0);
776
		gc.dispose();
777
778
		workImageGC = new GC(workImage);
779
		workImageGC.setLineCap(SWT.CAP_ROUND);
780
781
		scrolledComposite.setEnabled(true);
782
		clearSelection();
783
		refreshCanvasSize();
784
785
		setPageComplete(true);
786
	}
787
458
	private void captureScreenshotContent() {
788
	private void captureScreenshotContent() {
459
		final Display display = getShell().getDisplay();
789
		final Display display = getShell().getDisplay();
460
		final Shell wizardShell = getWizard().getContainer().getShell();
790
		final Shell wizardShell = getWizard().getContainer().getShell();
Lines 476-483 Link Here
476
				gc.dispose();
806
				gc.dispose();
477
807
478
				workImageGC = new GC(workImage);
808
				workImageGC = new GC(workImage);
479
				workImageGC.setForeground(markColor);
480
				workImageGC.setLineWidth(4);
481
				workImageGC.setLineCap(SWT.CAP_ROUND);
809
				workImageGC.setLineCap(SWT.CAP_ROUND);
482
810
483
				scrolledComposite.setEnabled(true);
811
				scrolledComposite.setEnabled(true);
Lines 514-547 Link Here
514
		currentSelection.intersect(imageBounds);
842
		currentSelection.intersect(imageBounds);
515
	}
843
	}
516
844
517
	/**
845
	private static final int grabPointCurosr[] = { SWT.CURSOR_SIZENWSE, SWT.CURSOR_SIZENS, SWT.CURSOR_SIZENESW,
518
	 * Create the grab points to resize the selection; this method should be called every time the selection or zoom
846
			SWT.CURSOR_SIZEWE, SWT.CURSOR_SIZEWE, SWT.CURSOR_SIZENESW, SWT.CURSOR_SIZENS, SWT.CURSOR_SIZENWSE };
519
	 * level is changed
520
	 */
521
	private void setUpGrabPoints() {
522
		grabPoints.clear();
523
		if (currentSelection == null) {
524
			return;
525
		}
526
847
527
		Rectangle scaledSelection = getScaledSelection();
848
	private static final SelectionSide[][] grabPointResizableSides = { { SelectionSide.LEFT, SelectionSide.TOP },
528
		grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x, scaledSelection.y, SWT.CURSOR_SIZENWSE, EnumSet.of(
849
			{ SelectionSide.TOP }, { SelectionSide.TOP, SelectionSide.RIGHT }, { SelectionSide.LEFT },
529
				SelectionSide.LEFT, SelectionSide.TOP)));
850
			{ SelectionSide.RIGHT }, { SelectionSide.LEFT, SelectionSide.BOTTOM }, { SelectionSide.BOTTOM },
530
		grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x + scaledSelection.width / 2, scaledSelection.y,
851
			{ SelectionSide.BOTTOM, SelectionSide.RIGHT } };
531
				SWT.CURSOR_SIZENS, EnumSet.of(SelectionSide.TOP)));
532
		grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x + scaledSelection.width, scaledSelection.y,
533
				SWT.CURSOR_SIZENESW, EnumSet.of(SelectionSide.TOP, SelectionSide.RIGHT)));
534
		grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x, scaledSelection.y + scaledSelection.height / 2,
535
				SWT.CURSOR_SIZEWE, EnumSet.of(SelectionSide.LEFT)));
536
		grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x + scaledSelection.width, scaledSelection.y
537
				+ scaledSelection.height / 2, SWT.CURSOR_SIZEWE, EnumSet.of(SelectionSide.RIGHT)));
538
		grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x, scaledSelection.y + scaledSelection.height,
539
				SWT.CURSOR_SIZENESW, EnumSet.of(SelectionSide.LEFT, SelectionSide.BOTTOM)));
540
		grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x + scaledSelection.width / 2, scaledSelection.y
541
				+ scaledSelection.height, SWT.CURSOR_SIZENS, EnumSet.of(SelectionSide.BOTTOM)));
542
		grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x + scaledSelection.width, scaledSelection.y
543
				+ scaledSelection.height, SWT.CURSOR_SIZENWSE, EnumSet.of(SelectionSide.BOTTOM, SelectionSide.RIGHT)));
544
	}
545
852
546
	private void refreshSelectionResize(int x, int y) {
853
	private void refreshSelectionResize(int x, int y) {
547
		currentSelection = new Rectangle(originalSelection.x, originalSelection.y, originalSelection.width,
854
		currentSelection = new Rectangle(originalSelection.x, originalSelection.y, originalSelection.width,
Lines 559-565 Link Here
559
		}
866
		}
560
		if (resizableSides.contains(SelectionSide.RIGHT)) {
867
		if (resizableSides.contains(SelectionSide.RIGHT)) {
561
			deltaX = Math.max(deltaX, -originalSelection.width);
868
			deltaX = Math.max(deltaX, -originalSelection.width);
562
			if (originalSelection.x + originalSelection.width + deltaX - 1 > imageBounds.width) {
869
			if (originalSelection.x + originalSelection.width + deltaX > imageBounds.width) {
563
				deltaX = imageBounds.width - (originalSelection.x + originalSelection.width);
870
				deltaX = imageBounds.width - (originalSelection.x + originalSelection.width);
564
			}
871
			}
565
		}
872
		}
Lines 571-577 Link Here
571
		}
878
		}
572
		if (resizableSides.contains(SelectionSide.BOTTOM)) {
879
		if (resizableSides.contains(SelectionSide.BOTTOM)) {
573
			deltaY = Math.max(deltaY, -originalSelection.height);
880
			deltaY = Math.max(deltaY, -originalSelection.height);
574
			if (originalSelection.y + originalSelection.height + deltaY - 1 > imageBounds.height) {
881
			if (originalSelection.y + originalSelection.height + deltaY > imageBounds.height) {
575
				deltaY = imageBounds.height - (originalSelection.y + originalSelection.height);
882
				deltaY = imageBounds.height - (originalSelection.y + originalSelection.height);
576
			}
883
			}
577
		}
884
		}
Lines 591-598 Link Here
591
		if (resizableSides.contains(SelectionSide.BOTTOM)) {
898
		if (resizableSides.contains(SelectionSide.BOTTOM)) {
592
			currentSelection.height += deltaY;
899
			currentSelection.height += deltaY;
593
		}
900
		}
594
595
		setUpGrabPoints();
596
	}
901
	}
597
902
598
	private void refreshSelectionPosition(int x, int y) {
903
	private void refreshSelectionPosition(int x, int y) {
Lines 605-619 Link Here
605
			newY = 0;
910
			newY = 0;
606
		}
911
		}
607
		Rectangle imageBounds = workImage.getBounds();
912
		Rectangle imageBounds = workImage.getBounds();
608
		if (newX + originalSelection.width - 1 > imageBounds.width) {
913
		if (newX + originalSelection.width > imageBounds.width) {
609
			newX = imageBounds.width - originalSelection.width;
914
			newX = imageBounds.width - originalSelection.width;
610
		}
915
		}
611
		if (newY + originalSelection.height - 1 > imageBounds.height) {
916
		if (newY + originalSelection.height > imageBounds.height) {
612
			newY = imageBounds.height - originalSelection.height;
917
			newY = imageBounds.height - originalSelection.height;
613
		}
918
		}
614
		currentSelection = new Rectangle(newX, newY, originalSelection.width, originalSelection.height);
919
		currentSelection = new Rectangle(newX, newY, originalSelection.width, originalSelection.height);
615
616
		setUpGrabPoints();
617
	}
920
	}
618
921
619
	private void registerMouseListeners() {
922
	private void registerMouseListeners() {
Lines 639-650 Link Here
639
					boolean cursorSet = false;
942
					boolean cursorSet = false;
640
943
641
					// No selection in course, but have something selected; first test if I'm hovering some grab point
944
					// No selection in course, but have something selected; first test if I'm hovering some grab point
642
					for (GrabPoint point : grabPoints) {
945
					int info = getGrabPoint(e.x, e.y);
643
						if (point.grabArea.contains(e.x, e.y)) {
946
					if (info >= 0) {
644
							canvas.setCursor(cursors.get(point.cursorType));
947
						canvas.setCursor(cursors.get(grabPointCurosr[info]));
645
							cursorSet = true;
948
						cursorSet = true;
646
							break;
647
						}
648
					}
949
					}
649
950
650
					// Test if I'm inside selection, so I can move it
951
					// Test if I'm inside selection, so I can move it
Lines 659-664 Link Here
659
						canvas.setCursor(crossCursor);
960
						canvas.setCursor(crossCursor);
660
					}
961
					}
661
				} else if (currentAction == EditorAction.MARKING) {
962
				} else if (currentAction == EditorAction.MARKING) {
963
					if (startPoint != null) {
964
						int drawTool = getSelectDrawToolbar();
965
						if (drawTool == SelectToolAction.DRAW_FREE) {
966
							int[] history = new int[3];
967
							history[0] = SWT.MouseMove;
968
							history[1] = scaledX;
969
							history[2] = scaledY;
970
							historyMouseEvent.add(history);
971
						} else {
972
							int[] history = historyMouseEvent.get(historyMouseEvent.size() - 1);
973
							if (history[0] == SWT.MouseMove) {
974
								history[1] = scaledX;
975
								history[2] = scaledY;
976
							} else {
977
								history = new int[3];
978
								history[0] = SWT.MouseMove;
979
								history[1] = scaledX;
980
								history[2] = scaledY;
981
								historyMouseEvent.add(history);
982
							}
983
						}
984
					}
985
662
					drawMarkLine(scaledX, scaledY);
986
					drawMarkLine(scaledX, scaledY);
663
987
664
					Cursor markCursor = cursors.get(CURSOR_MARK_TOOL);
988
					Cursor markCursor = cursors.get(CURSOR_MARK_TOOL);
Lines 667-673 Link Here
667
					}
991
					}
668
				}
992
				}
669
			}
993
			}
670
671
		});
994
		});
672
995
673
		canvas.addMouseListener(new MouseAdapter() {
996
		canvas.addMouseListener(new MouseAdapter() {
Lines 692-710 Link Here
692
					if (currentSelection.width == 0 && currentSelection.height == 0) {
1015
					if (currentSelection.width == 0 && currentSelection.height == 0) {
693
						currentSelection = null;
1016
						currentSelection = null;
694
					}
1017
					}
695
					setUpGrabPoints();
1018
696
					startPoint = null;
1019
					startPoint = null;
697
					currentAction = EditorAction.CROPPING;
1020
					currentAction = EditorAction.CROPPING;
698
1021
699
					canvas.redraw();
1022
					canvas.redraw();
700
					setImageDirty(true);
1023
					setImageDirty(true);
701
				} else if (currentAction == EditorAction.MARKING) {
1024
				} else if (currentAction == EditorAction.MARKING) {
1025
					if (startPoint != null) {
1026
						int drawTool = getSelectDrawToolbar();
1027
						if (drawTool != SelectToolAction.DRAW_FREE) {
1028
							if (drawTool == SelectToolAction.DRAW_TEXT) {
1029
								drawAnnotationText();
1030
							}
1031
							previousImage.dispose();
1032
							previousImage = null;
1033
						}
1034
1035
						int[] history = new int[3];
1036
						history[0] = SWT.MouseUp;
1037
						history[1] = 0;
1038
						history[2] = 0;
1039
						historyMouseEvent.add(history);
1040
					}
1041
702
					startPoint = null;
1042
					startPoint = null;
703
					setImageDirty(true);
1043
					setImageDirty(true);
704
				}
1044
				}
705
			}
1045
			}
706
1046
707
			/**
1047
			/**
1048
			 * Input annotation text and draw text
1049
			 */
1050
			private void drawAnnotationText() {
1051
				workImageGC.drawImage(previousImage, 0, 0);
1052
				canvas.redraw();
1053
1054
				int[] history = historyMouseEvent.get(historyMouseEvent.size() - 1);
1055
				if (history[0] != SWT.MouseMove) {
1056
					historyCheckpoint--;
1057
					updateAnnotationHistory();
1058
					return;
1059
				}
1060
1061
				int endedPoint_x, endedPoint_y;
1062
				if (history[1] < startPoint.x) {
1063
					endedPoint_x = startPoint.x;
1064
					startPoint.x = history[1];
1065
				} else {
1066
					endedPoint_x = history[1];
1067
				}
1068
				if (history[2] < startPoint.y) {
1069
					endedPoint_y = startPoint.y;
1070
					startPoint.y = history[2];
1071
				} else {
1072
					endedPoint_y = history[2];
1073
				}
1074
				final Rectangle bounds = new Rectangle(startPoint.x, startPoint.y, endedPoint_x - startPoint.x,
1075
						endedPoint_y - startPoint.y);
1076
				textArea = new Text(canvas, SWT.MULTI | SWT.WRAP);
1077
				int xs = (int) Math.round(startPoint.x * scaleFactor);
1078
				int ys = (int) Math.round(startPoint.y * scaleFactor);
1079
				int xe = (int) Math.round(endedPoint_x * scaleFactor);
1080
				int ye = (int) Math.round(endedPoint_y * scaleFactor);
1081
				textArea.setBounds(new Rectangle(xs, ys, xe - xs, ye - ys));
1082
				FontData fontData = new FontData(drawTextToolbar.getStringCustom());
1083
				if (scaleFactor != 1.0) {
1084
					fontData.setHeight((int) Math.round(fontData.getHeight() * scaleFactor));
1085
				}
1086
				textArea.setFont(new Font(getShell().getDisplay(), fontData));
1087
				textArea.setForeground(new Color(getShell().getDisplay(),
1088
						SelectToolAction.int2rgb(drawTextToolbar.getIntgerCustom())));
1089
				textArea.setTabs(1);
1090
				Point point = textArea.getCaretLocation();
1091
				textArea.setBounds(new Rectangle(xs - point.x, ys, xe - xs + point.x + point.x, ye - ys));
1092
				textArea.setFocus();
1093
				textArea.addListener(SWT.Deactivate, new Listener() {
1094
1095
					public void handleEvent(Event event) {
1096
						String text = textArea.getText();
1097
						{
1098
							String newtext = ""; //$NON-NLS-1$
1099
							int currpos = 0;
1100
							int charpos = currpos;
1101
							textArea.setTopIndex(0);
1102
							textArea.setSelection(currpos);
1103
							int linepos = textArea.getCaretLineNumber();
1104
							boolean remove1st = false;
1105
							String line;
1106
							while (currpos < text.length()) {
1107
								int y = textArea.getCaretLineNumber();
1108
								if (linepos != y) {
1109
									line = text.substring(charpos, currpos);
1110
									if (line.endsWith("\n")) { //$NON-NLS-1$
1111
										line = line.substring(0, line.length() - 1);
1112
									}
1113
									newtext = newtext + "\n" + line; //$NON-NLS-1$
1114
									remove1st = true;
1115
									charpos = currpos;
1116
									linepos = y;
1117
								}
1118
								currpos++;
1119
								textArea.setSelection(currpos);
1120
							}
1121
							line = text.substring(charpos, currpos);
1122
							if (line.endsWith("\n")) { //$NON-NLS-1$
1123
								line = line.substring(0, line.length() - 1);
1124
							}
1125
							if (line.length() > 0) {
1126
								newtext = newtext + "\n" + text.substring(charpos, currpos); //$NON-NLS-1$
1127
								remove1st = true;
1128
							}
1129
							currpos = newtext.indexOf("\r"); //$NON-NLS-1$
1130
							while (currpos > 0) {
1131
								newtext = newtext.substring(0, currpos) + newtext.substring(currpos + 1);
1132
								currpos = newtext.indexOf("\r"); //$NON-NLS-1$
1133
							}
1134
							newtext = newtext.replace("\t", " "); //$NON-NLS-1$//$NON-NLS-2$
1135
							if (remove1st) {
1136
								newtext = newtext.substring(1);
1137
							}
1138
							text = newtext;
1139
						}
1140
1141
						textArea.dispose();
1142
						textArea = null;
1143
1144
						if (text.length() > 0) {
1145
							historyDrawText.get(historyCheckpoint - 1).append(text);
1146
							Color color = workImageGC.getForeground();
1147
							FontData fontData = new FontData(drawTextToolbar.getStringCustom());
1148
							workImageGC.setFont(new Font(getShell().getDisplay(), fontData));
1149
							workImageGC.setForeground(new Color(getShell().getDisplay(),
1150
									SelectToolAction.int2rgb(drawTextToolbar.getIntgerCustom())));
1151
							workImageGC.setClipping(bounds);
1152
							workImageGC.drawText(text, bounds.x, bounds.y, true);
1153
							workImageGC.setClipping((Rectangle) null);
1154
							workImageGC.setForeground(color);
1155
						} else {
1156
							historyCheckpoint--;
1157
							updateAnnotationHistory();
1158
						}
1159
						canvas.redraw();
1160
					}
1161
				});
1162
			}
1163
1164
			/**
708
			 * Pressing mouse button starts a selection or a drawing; normalizes and marks the start point
1165
			 * Pressing mouse button starts a selection or a drawing; normalizes and marks the start point
709
			 */
1166
			 */
710
			@Override
1167
			@Override
Lines 713-718 Link Here
713
				int scaledY = (int) (e.y / scaleFactor);
1170
				int scaledY = (int) (e.y / scaleFactor);
714
1171
715
				if (currentAction == EditorAction.MARKING) {
1172
				if (currentAction == EditorAction.MARKING) {
1173
					updateAnnotationHistory();
1174
1175
					int drawTool = getSelectDrawToolbar();
1176
					int[] history = new int[5];
1177
					history[0] = historyMouseEvent.size();
1178
					history[1] = drawTool;
1179
					history[2] = (lineTypeToolbar != null) ? lineTypeToolbar.getSelect() : SWT.LINE_DOT;
1180
					history[3] = (lineBoldToolbar != null) ? lineBoldToolbar.getSelect() : 1;
1181
					RGB rgb;
1182
					if (drawTool == SelectToolAction.DRAW_TEXT) {
1183
						rgb = SelectToolAction.int2rgb(drawTextToolbar.getIntgerCustom());
1184
					} else {
1185
						rgb = SelectToolAction.int2rgb(drawColorToolbar.getSelect());
1186
					}
1187
					history[4] = (rgb.red << 16) + (rgb.green << 8) + rgb.blue;
1188
					historyDrawTool.add(history);
1189
					historyDrawText.add(new StringBuffer());
1190
					if (drawTool == SelectToolAction.DRAW_TEXT) {
1191
						FontData fontData = new FontData(drawTextToolbar.getStringCustom());
1192
						historyDrawFont.add(fontData.toString());
1193
					} else {
1194
						historyDrawFont.add(""); //$NON-NLS-1$
1195
					}
1196
					historyCheckpoint = historyDrawTool.size();
1197
1198
					history = new int[3];
1199
					history[0] = SWT.MouseDown;
1200
					history[1] = scaledX;
1201
					history[2] = scaledY;
1202
					historyMouseEvent.add(history);
1203
					undoAction.setEnabled(true);
1204
1205
					if (drawTool != SelectToolAction.DRAW_FREE) {
1206
						Display display = getShell().getDisplay();
1207
						previousImage = new Image(display, workImage.getBounds());
1208
						GC gc = new GC(previousImage);
1209
						gc.drawImage(workImage, 0, 0);
1210
						gc.dispose();
1211
					}
1212
1213
					if (drawTool != SelectToolAction.DRAW_TEXT) {
1214
						workImageGC.setLineStyle(lineTypeToolbar.getSelect());
1215
						workImageGC.setLineWidth(lineBoldToolbar.getSelect());
1216
						workImageGC.setForeground(new Color(getShell().getDisplay(),
1217
								SelectToolAction.int2rgb(drawColorToolbar.getSelect())));
1218
					} else {
1219
						workImageGC.setLineStyle(SWT.LINE_DOT);
1220
						workImageGC.setLineWidth(1);
1221
						workImageGC.setForeground(new Color(getShell().getDisplay(), 0, 0, 0));
1222
					}
1223
716
					startPoint = new Point(scaledX, scaledY);
1224
					startPoint = new Point(scaledX, scaledY);
717
					drawMarkLine(scaledX, scaledY);
1225
					drawMarkLine(scaledX, scaledY);
718
					canvas.setCursor(cursors.get(CURSOR_MARK_TOOL));
1226
					canvas.setCursor(cursors.get(CURSOR_MARK_TOOL));
Lines 723-737 Link Here
723
1231
724
				// Check the most appropriate action to follow; first check if I'm on some grab point
1232
				// Check the most appropriate action to follow; first check if I'm on some grab point
725
				if (currentSelection != null) {
1233
				if (currentSelection != null) {
726
					for (GrabPoint point : grabPoints) {
1234
					int info = getGrabPoint(e.x, e.y);
727
						if (point.grabArea.contains(e.x, e.y)) {
1235
					if (info >= 0) {
728
							originalSelection = currentSelection;
1236
						originalSelection = currentSelection;
729
							currentAction = EditorAction.RESIZING_SELECTION;
1237
						currentAction = EditorAction.RESIZING_SELECTION;
730
							resizableSides = point.resizableSides;
1238
						resizableSides = new HashSet<SelectionSide>();
731
							startPoint = new Point(scaledX, scaledY);
1239
						for (SelectionSide side : grabPointResizableSides[info]) {
732
							canvas.redraw();
1240
							resizableSides.add(side);
733
							return;
734
						}
1241
						}
1242
						startPoint = new Point(scaledX, scaledY);
1243
						canvas.redraw();
1244
						return;
735
					}
1245
					}
736
				}
1246
				}
737
1247
Lines 749-760 Link Here
749
				currentAction = EditorAction.SELECTING;
1259
				currentAction = EditorAction.SELECTING;
750
				currentSelection = null;
1260
				currentSelection = null;
751
				startPoint = new Point(scaledX, scaledY);
1261
				startPoint = new Point(scaledX, scaledY);
752
				setUpGrabPoints();
1262
753
				canvas.redraw();
1263
				canvas.redraw();
754
			}
1264
			}
755
756
		});
1265
		});
757
758
	}
1266
	}
759
1267
760
	private void clearSelection() {
1268
	private void clearSelection() {
Lines 779-785 Link Here
779
	 * Calling this method under other circumstances may lead to strange behavior in the scrolled composite
1287
	 * Calling this method under other circumstances may lead to strange behavior in the scrolled composite
780
	 */
1288
	 */
781
	private void refreshCanvasSize() {
1289
	private void refreshCanvasSize() {
782
		if (fitAction.isChecked()) {
1290
		if (fitAction.getSelect() == SelectToolAction.ZOOM_FIT) {
783
			// This little hack is necessary to get the client area without scrollbars; 
1291
			// This little hack is necessary to get the client area without scrollbars; 
784
			// they'll be automatically restored if necessary after Canvas.setBounds()
1292
			// they'll be automatically restored if necessary after Canvas.setBounds()
785
			scrolledComposite.getHorizontalBar().setVisible(false);
1293
			scrolledComposite.getHorizontalBar().setVisible(false);
Lines 798-813 Link Here
798
			}
1306
			}
799
			canvas.setBounds(bounds);
1307
			canvas.setBounds(bounds);
800
		} else {
1308
		} else {
801
			scaleFactor = 1.0;
1309
			scaleFactor = fitAction.getSelect(); // 50, 100, 200, 400 or 800
1310
			scaleFactor = scaleFactor / 100;
802
			Rectangle bounds = scrolledComposite.getClientArea();
1311
			Rectangle bounds = scrolledComposite.getClientArea();
803
			if (workImage != null) {
1312
			if (workImage != null) {
804
				Rectangle imageBounds = workImage.getBounds();
1313
				Rectangle imageBounds = workImage.getBounds();
805
				bounds.width = imageBounds.width;
1314
				bounds.width = (int) Math.round(imageBounds.width * scaleFactor);
806
				bounds.height = imageBounds.height;
1315
				bounds.height = (int) Math.round(imageBounds.height * scaleFactor);
807
			}
1316
			}
808
			canvas.setBounds(bounds);
1317
			canvas.setBounds(bounds);
809
		}
1318
		}
810
		setUpGrabPoints();
1319
1320
		canvas.redraw();
1321
	}
1322
1323
	private void updateAnnotationHistory() {
1324
		int[] history;
1325
		if (historyCheckpoint < historyDrawTool.size()) {
1326
			history = historyDrawTool.get(historyCheckpoint);
1327
			while (history[0] < historyMouseEvent.size()) {
1328
				historyMouseEvent.remove(historyMouseEvent.size() - 1);
1329
			}
1330
			while (historyCheckpoint < historyDrawTool.size()) {
1331
				historyDrawTool.remove(historyDrawTool.size() - 1);
1332
			}
1333
			while (historyCheckpoint < historyDrawText.size()) {
1334
				historyDrawText.remove(historyDrawText.size() - 1);
1335
			}
1336
			while (historyCheckpoint < historyDrawFont.size()) {
1337
				historyDrawFont.remove(historyDrawFont.size() - 1);
1338
			}
1339
			redoAction.setEnabled(false);
1340
		}
1341
1342
		undoAction.setEnabled(historyCheckpoint > 0);
1343
	}
1344
1345
	/**
1346
	 * Draw Annotation with history
1347
	 */
1348
	private void drawAnnotationHistory() {
1349
		workImageGC.drawImage(originalImage, 0, 0);
1350
		Color backBackground = workImageGC.getBackground();
1351
		Color backForeground = workImageGC.getForeground();
1352
		int backLineStyle = workImageGC.getLineStyle();
1353
		int backLineWidth = workImageGC.getLineWidth();
1354
		int[] history;
1355
		for (int c = 0; c < historyCheckpoint; c++) {
1356
			history = historyDrawTool.get(c);
1357
			int toolKind = history[1];
1358
			int boldlKind = history[3];
1359
			workImageGC.setLineStyle(history[2]);
1360
			workImageGC.setLineWidth(boldlKind);
1361
			workImageGC.setForeground(new Color(getShell().getDisplay(), //
1362
					history[4] >> 16, //
1363
					(history[4] >> 8) & 0x00ff, //
1364
					history[4] & 0x00ff));
1365
1366
			int h = history[0];
1367
			history = historyMouseEvent.get(h);
1368
			int start_x = history[1];
1369
			int start_y = history[2];
1370
			for (h++; h < historyMouseEvent.size(); h++) {
1371
				history = historyMouseEvent.get(h);
1372
				if (history[0] == SWT.MouseUp) {
1373
					break;
1374
				}
1375
				int x = history[1];
1376
				int y = history[2];
1377
				if (toolKind == SelectToolAction.DRAW_FREE) {
1378
					workImageGC.drawLine(start_x, start_y, x, y);
1379
					start_x = x;
1380
					start_y = y;
1381
				} else {
1382
					if (start_x == x && start_y == y) {
1383
						workImageGC.drawLine(start_x, start_y, x, y);
1384
					} else {
1385
						int rounded;
1386
						int width = x - start_x;
1387
						int height = y - start_y;
1388
						switch (toolKind) {
1389
						case SelectToolAction.DRAW_LINE:
1390
							workImageGC.drawLine(start_x, start_y, x, y);
1391
							break;
1392
						case SelectToolAction.DRAW_ARROW1:
1393
							workImageGC.setBackground(workImageGC.getForeground());
1394
							drawArrowLine(start_x, start_y, x, y, false);
1395
							break;
1396
						case SelectToolAction.DRAW_ARROW2:
1397
							workImageGC.setBackground(workImageGC.getForeground());
1398
							drawArrowLine(start_x, start_y, x, y, true);
1399
							break;
1400
						case SelectToolAction.DRAW_BOX:
1401
							workImageGC.drawRectangle(start_x, start_y, width, height);
1402
							break;
1403
						case SelectToolAction.DRAW_RBOX:
1404
							rounded = boldlKind * 8;
1405
							workImageGC.drawRoundRectangle(start_x, start_y, width, height, rounded, rounded);
1406
							break;
1407
						case SelectToolAction.DRAW_OVAL:
1408
							workImageGC.drawOval(start_x, start_y, width, height);
1409
							break;
1410
						case SelectToolAction.DRAW_FILL_BOX:
1411
							workImageGC.setBackground(workImageGC.getForeground());
1412
							workImageGC.fillRectangle(start_x, start_y, width, height);
1413
							break;
1414
						case SelectToolAction.DRAW_FILL_RBOX:
1415
							rounded = boldlKind * 8;
1416
							workImageGC.setBackground(workImageGC.getForeground());
1417
							workImageGC.fillRoundRectangle(start_x, start_y, width, height, rounded, rounded);
1418
							break;
1419
						case SelectToolAction.DRAW_FILL_OVAL:
1420
							workImageGC.setBackground(workImageGC.getForeground());
1421
							workImageGC.fillOval(start_x, start_y, width, height);
1422
							break;
1423
						case SelectToolAction.DRAW_TEXT:
1424
							StringBuffer text = historyDrawText.get(c);
1425
							{
1426
								Font backFont = workImageGC.getFont();
1427
								FontData fontData = new FontData(historyDrawFont.get(c));
1428
								workImageGC.setFont(new Font(getShell().getDisplay(), fontData));
1429
								workImageGC.setClipping(start_x, start_y, width, height);
1430
								workImageGC.drawText(text.toString(), start_x, start_y, true);
1431
								workImageGC.setClipping((Rectangle) null);
1432
								workImageGC.setFont(backFont);
1433
							}
1434
							break;
1435
						}
1436
					}
1437
				}
1438
			}
1439
		}
1440
		workImageGC.setBackground(backBackground);
1441
		workImageGC.setForeground(backForeground);
1442
		workImageGC.setLineStyle(backLineStyle);
1443
		workImageGC.setLineWidth(backLineWidth);
1444
811
		canvas.redraw();
1445
		canvas.redraw();
812
	}
1446
	}
813
1447
Lines 818-824 Link Here
818
		if (currentSelection == null) {
1452
		if (currentSelection == null) {
819
			return;
1453
			return;
820
		}
1454
		}
821
		Rectangle scaledSelection = getScaledSelection();
1455
		Rectangle inside = getScaledSelection();
822
1456
823
		// Draw shadow
1457
		// Draw shadow
824
		gc.setBackground(CommonColors.GRAY_MID);
1458
		gc.setBackground(CommonColors.GRAY_MID);
Lines 827-833 Link Here
827
1461
828
		Region invertedSelection = new Region();
1462
		Region invertedSelection = new Region();
829
		invertedSelection.add(canvas.getClientArea());
1463
		invertedSelection.add(canvas.getClientArea());
830
		invertedSelection.subtract(scaledSelection);
1464
		invertedSelection.subtract(inside);
831
		gc.setClipping(invertedSelection);
1465
		gc.setClipping(invertedSelection);
832
		gc.fillRectangle(canvas.getClientArea());
1466
		gc.fillRectangle(canvas.getClientArea());
833
		gc.setClipping((Region) null);
1467
		gc.setClipping((Region) null);
Lines 838-867 Link Here
838
		// Draw selection rectangle
1472
		// Draw selection rectangle
839
		gc.setLineStyle(SWT.LINE_SOLID);
1473
		gc.setLineStyle(SWT.LINE_SOLID);
840
		gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
1474
		gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
841
		gc.drawRectangle(scaledSelection);
1475
		gc.drawRectangle(inside);
842
1476
843
		// Draw grab points
1477
//		// Draw grab points
844
		gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
1478
//		gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
845
		gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
1479
//		gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
846
		for (GrabPoint point : grabPoints) {
1480
//		for (GrabPoint point : grabPoints) {
847
			gc.fillRectangle(point.grabArea);
1481
//			gc.fillRectangle(point.grabArea);
848
			gc.drawRectangle(point.grabArea);
1482
//			gc.drawRectangle(point.grabArea);
849
		}
1483
//		}
1484
		gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
1485
		Rectangle outside = getOutsideSelection(inside);
1486
		gc.drawRectangle(outside);
1487
		gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
1488
		gc.fillRectangle(outside.x, outside.y, //
1489
				SQUARE_SIZE * 6, SQUARE_SIZE * 2);
1490
		gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 6, outside.y, //
1491
				SQUARE_SIZE * 6, SQUARE_SIZE * 2);
1492
		gc.fillRectangle(outside.x, outside.y, //
1493
				SQUARE_SIZE * 2, SQUARE_SIZE * 6);
1494
		gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 2, outside.y, //
1495
				SQUARE_SIZE * 2, SQUARE_SIZE * 6);
1496
		gc.fillRectangle(outside.x, outside.y + outside.height - SQUARE_SIZE * 6, //
1497
				SQUARE_SIZE * 2, SQUARE_SIZE * 6);
1498
		gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 2, outside.y + outside.height - SQUARE_SIZE * 6, //
1499
				SQUARE_SIZE * 2, SQUARE_SIZE * 6);
1500
		gc.fillRectangle(outside.x, outside.y + outside.height - SQUARE_SIZE * 2, //
1501
				SQUARE_SIZE * 6, SQUARE_SIZE * 2);
1502
		gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 6, outside.y + outside.height - SQUARE_SIZE * 2, //
1503
				SQUARE_SIZE * 6, SQUARE_SIZE * 2);
850
	}
1504
	}
851
1505
852
	/**
1506
	/**
853
	 * Connects the previous mark point to the new reference point, by drawing a new line
1507
	 * Connects the previous mark point to the new reference point, by drawing a new line, rectangle or oval
854
	 */
1508
	 */
855
	private void drawMarkLine(int x, int y) {
1509
	private void drawMarkLine(int x, int y) {
856
		if (startPoint != null) {
1510
		if (startPoint != null) {
857
			clearAction.setEnabled(true);
1511
			clearAction.setEnabled(true);
858
			workImageGC.drawLine(startPoint.x, startPoint.y, x, y);
1512
			int drawTool = getSelectDrawToolbar();
859
			startPoint.x = x;
1513
			if (drawTool == SelectToolAction.DRAW_FREE) {
860
			startPoint.y = y;
1514
				workImageGC.drawLine(startPoint.x, startPoint.y, x, y);
1515
				startPoint.x = x;
1516
				startPoint.y = y;
1517
			} else {
1518
				workImageGC.drawImage(previousImage, 0, 0);
1519
				if (startPoint.x == x && startPoint.y == y) {
1520
					workImageGC.drawLine(startPoint.x, startPoint.y, x, y);
1521
				} else {
1522
					Color backColor;
1523
					Color markColor;
1524
					int rounded;
1525
					int width = x - startPoint.x;
1526
					int height = y - startPoint.y;
1527
					switch (drawTool) {
1528
					case SelectToolAction.DRAW_LINE:
1529
						workImageGC.drawLine(startPoint.x, startPoint.y, x, y);
1530
						break;
1531
					case SelectToolAction.DRAW_ARROW1:
1532
						backColor = workImageGC.getBackground();
1533
						markColor = new Color(getShell().getDisplay(),
1534
								SelectToolAction.int2rgb(drawColorToolbar.getSelect()));
1535
						workImageGC.setBackground(markColor);
1536
						drawArrowLine(startPoint.x, startPoint.y, x, y, false);
1537
						workImageGC.setBackground(backColor);
1538
						break;
1539
					case SelectToolAction.DRAW_ARROW2:
1540
						backColor = workImageGC.getBackground();
1541
						markColor = new Color(getShell().getDisplay(),
1542
								SelectToolAction.int2rgb(drawColorToolbar.getSelect()));
1543
						workImageGC.setBackground(markColor);
1544
						drawArrowLine(startPoint.x, startPoint.y, x, y, true);
1545
						workImageGC.setBackground(backColor);
1546
						break;
1547
					case SelectToolAction.DRAW_BOX:
1548
						workImageGC.drawRectangle(startPoint.x, startPoint.y, width, height);
1549
						break;
1550
					case SelectToolAction.DRAW_RBOX:
1551
						rounded = lineBoldToolbar.getSelect() * 8;
1552
						workImageGC.drawRoundRectangle(startPoint.x, startPoint.y, width, height, rounded, rounded);
1553
						break;
1554
					case SelectToolAction.DRAW_OVAL:
1555
						workImageGC.drawOval(startPoint.x, startPoint.y, width, height);
1556
						break;
1557
					case SelectToolAction.DRAW_FILL_BOX:
1558
						backColor = workImageGC.getBackground();
1559
						markColor = new Color(getShell().getDisplay(),
1560
								SelectToolAction.int2rgb(drawColorToolbar.getSelect()));
1561
						workImageGC.setBackground(markColor);
1562
						workImageGC.fillRectangle(startPoint.x, startPoint.y, width, height);
1563
						workImageGC.setBackground(backColor);
1564
						break;
1565
					case SelectToolAction.DRAW_FILL_RBOX:
1566
						rounded = lineBoldToolbar.getSelect() * 8;
1567
						backColor = workImageGC.getBackground();
1568
						markColor = new Color(getShell().getDisplay(),
1569
								SelectToolAction.int2rgb(drawColorToolbar.getSelect()));
1570
						workImageGC.setBackground(markColor);
1571
						workImageGC.fillRoundRectangle(startPoint.x, startPoint.y, width, height, rounded, rounded);
1572
						workImageGC.setBackground(backColor);
1573
						break;
1574
					case SelectToolAction.DRAW_FILL_OVAL:
1575
						backColor = workImageGC.getBackground();
1576
						markColor = new Color(getShell().getDisplay(),
1577
								SelectToolAction.int2rgb(drawColorToolbar.getSelect()));
1578
						workImageGC.setBackground(markColor);
1579
						workImageGC.fillOval(startPoint.x, startPoint.y, width, height);
1580
						workImageGC.setBackground(backColor);
1581
						break;
1582
					case SelectToolAction.DRAW_TEXT:
1583
						workImageGC.fillRectangle(startPoint.x, startPoint.y, width, height);
1584
						workImageGC.drawRectangle(startPoint.x, startPoint.y, width, height);
1585
						break;
1586
					}
1587
				}
1588
			}
861
			canvas.redraw();
1589
			canvas.redraw();
862
		}
1590
		}
863
	}
1591
	}
864
1592
1593
	public void drawArrowLine(int xs, int ys, int xe, int ye, boolean bothsides) {
1594
		int width = xe - xs, height = ye - ys;
1595
		int bold = workImageGC.getLineWidth();
1596
		int leng = (bold == 8) ? bold * 4 : (bold == 4) ? bold * 6 : (bold == 2) ? bold * 8 : bold * 10;
1597
		double delta = Math.PI / 6.0;
1598
		double theta = Math.atan2(height, width);
1599
1600
		// Draw line
1601
		if (bothsides) {
1602
			workImageGC.drawLine( // 
1603
					xs + (int) (leng / 2 * Math.cos(theta)), //
1604
					ys + (int) (leng / 2 * Math.sin(theta)), //
1605
					xe - (int) (leng / 2 * Math.cos(theta)), //
1606
					ye - (int) (leng / 2 * Math.sin(theta)));
1607
		} else {
1608
			workImageGC.drawLine( //
1609
					xs, //
1610
					ys, //
1611
					xe - (int) (leng / 2 * Math.cos(theta)), //
1612
					ye - (int) (leng / 2 * Math.sin(theta)));
1613
		}
1614
1615
		// Draw ending side arrow
1616
		workImageGC.setLineWidth(1);
1617
1618
		int[] point = { xe, ye, //
1619
				xe - (int) (leng * Math.cos(theta - delta)), //
1620
				ye - (int) (leng * Math.sin(theta - delta)), //
1621
				xe - (int) (leng * Math.cos(theta + delta)), //
1622
				ye - (int) (leng * Math.sin(theta + delta)) };
1623
		workImageGC.fillPolygon(point);
1624
1625
		// Draw starting side arrow
1626
		if (bothsides) {
1627
			int[] point2 = { xs, ys, //
1628
					xs + (int) (leng * Math.cos(theta - delta)), //
1629
					ys + (int) (leng * Math.sin(theta - delta)), //
1630
					xs + (int) (leng * Math.cos(theta + delta)), //
1631
					ys + (int) (leng * Math.sin(theta + delta)) };
1632
			workImageGC.fillPolygon(point2);
1633
		}
1634
1635
		workImageGC.setLineWidth(bold);
1636
	}
1637
865
	private static enum SelectionSide {
1638
	private static enum SelectionSide {
866
1639
867
		LEFT, RIGHT, TOP, BOTTOM;
1640
		LEFT, RIGHT, TOP, BOTTOM;
Lines 870-895 Link Here
870
1643
871
	private static final int SQUARE_SIZE = 3;
1644
	private static final int SQUARE_SIZE = 3;
872
1645
873
	private static class GrabPoint {
874
875
		public Rectangle grabArea;
876
877
		public int cursorType;
878
879
		public Set<SelectionSide> resizableSides;
880
881
		public static GrabPoint createGrabPoint(int x, int y, int cursorType, Set<SelectionSide> resizableSides) {
882
			GrabPoint point = new GrabPoint();
883
			point.grabArea = new Rectangle(x - SQUARE_SIZE, y - SQUARE_SIZE, SQUARE_SIZE * 2 + 1, SQUARE_SIZE * 2 + 1);
884
			point.cursorType = cursorType;
885
			point.resizableSides = resizableSides;
886
			return point;
887
		}
888
889
	}
890
891
	private final List<GrabPoint> grabPoints = new ArrayList<GrabPoint>(8);
892
893
	/**
1646
	/**
894
	 * Creates the final screenshot
1647
	 * Creates the final screenshot
895
	 * 
1648
	 * 
(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImages.java (+52 lines)
Lines 45-50 Link Here
45
45
46
	private static final String T_OVR = "ovr16"; //$NON-NLS-1$
46
	private static final String T_OVR = "ovr16"; //$NON-NLS-1$
47
47
48
	private static final String T_DRAW = "draw16"; //$NON-NLS-1$
49
48
	// Priorities
50
	// Priorities
49
51
50
	public static final ImageDescriptor PRIORITY_1 = create(T_OBJ, "priority-1.gif"); //$NON-NLS-1$
52
	public static final ImageDescriptor PRIORITY_1 = create(T_OBJ, "priority-1.gif"); //$NON-NLS-1$
Lines 155-160 Link Here
155
157
156
	public static final ImageDescriptor EDIT = create(T_TOOL, "edit.gif"); //$NON-NLS-1$
158
	public static final ImageDescriptor EDIT = create(T_TOOL, "edit.gif"); //$NON-NLS-1$
157
159
160
	public static final ImageDescriptor EDIT_FREE = create(T_DRAW, "edit_free.gif"); //$NON-NLS-1$
161
162
	public static final ImageDescriptor EDIT_LINE = create(T_DRAW, "edit_line.gif"); //$NON-NLS-1$
163
164
	public static final ImageDescriptor EDIT_BOX = create(T_DRAW, "edit_box.gif"); //$NON-NLS-1$
165
166
	public static final ImageDescriptor EDIT_RBOX = create(T_DRAW, "edit_rbox.gif"); //$NON-NLS-1$
167
168
	public static final ImageDescriptor EDIT_OVAL = create(T_DRAW, "edit_oval.gif"); //$NON-NLS-1$
169
170
	public static final ImageDescriptor EDIT_FILL_BOX = create(T_DRAW, "edit_fill_box.gif"); //$NON-NLS-1$
171
172
	public static final ImageDescriptor EDIT_FILL_RBOX = create(T_DRAW, "edit_fill_rbox.gif"); //$NON-NLS-1$
173
174
	public static final ImageDescriptor EDIT_FILL_OVAL = create(T_DRAW, "edit_fill_oval.gif"); //$NON-NLS-1$
175
176
	public static final ImageDescriptor EDIT_ARROW1 = create(T_DRAW, "edit_arrow1.gif"); //$NON-NLS-1$
177
178
	public static final ImageDescriptor EDIT_ARROW2 = create(T_DRAW, "edit_arrow2.gif"); //$NON-NLS-1$
179
180
	public static final ImageDescriptor EDIT_UNDO = create(T_TOOL, "undo_edit.gif"); //$NON-NLS-1$
181
182
	public static final ImageDescriptor EDIT_REDO = create(T_TOOL, "redo_edit.gif"); //$NON-NLS-1$
183
158
	public static final ImageDescriptor CUT = create(T_TOOL, "cut.gif"); //$NON-NLS-1$
184
	public static final ImageDescriptor CUT = create(T_TOOL, "cut.gif"); //$NON-NLS-1$
159
185
160
	public static final ImageDescriptor STATUS_NORMAL = create(T_EVIEW, "status-normal.gif"); //$NON-NLS-1$
186
	public static final ImageDescriptor STATUS_NORMAL = create(T_EVIEW, "status-normal.gif"); //$NON-NLS-1$
Lines 201-206 Link Here
201
227
202
	public static final ImageDescriptor FIND = create(T_TOOL, "find.gif"); //$NON-NLS-1$
228
	public static final ImageDescriptor FIND = create(T_TOOL, "find.gif"); //$NON-NLS-1$
203
229
230
	public static final ImageDescriptor FILE_OBJ = create(T_TOOL, "file_obj.gif"); //$NON-NLS-1$
231
232
	public static final ImageDescriptor CLIPBOARD_OBJ = create(T_TOOL, "clipboard_obj.gif"); //$NON-NLS-1$
233
234
	public static final ImageDescriptor MINITOR_OBJ = create(T_TOOL, "monitor_obj.gif"); //$NON-NLS-1$
235
236
	public static final ImageDescriptor LINE_SOLD = create(T_DRAW, "line_sold.gif"); //$NON-NLS-1$
237
238
	public static final ImageDescriptor LINE_DOT = create(T_DRAW, "line_dot.gif"); //$NON-NLS-1$
239
240
	public static final ImageDescriptor LINE_DASH = create(T_DRAW, "line_dash.gif"); //$NON-NLS-1$
241
242
	public static final ImageDescriptor LINE_DASH1D = create(T_DRAW, "line_dash1d.gif"); //$NON-NLS-1$
243
244
	public static final ImageDescriptor LINE_DASH2D = create(T_DRAW, "line_dash2d.gif"); //$NON-NLS-1$
245
246
	public static final ImageDescriptor LINE_BOLD1 = create(T_DRAW, "line_bold1.gif"); //$NON-NLS-1$
247
248
	public static final ImageDescriptor LINE_BOLD2 = create(T_DRAW, "line_bold2.gif"); //$NON-NLS-1$
249
250
	public static final ImageDescriptor LINE_BOLD4 = create(T_DRAW, "line_bold4.gif"); //$NON-NLS-1$
251
252
	public static final ImageDescriptor LINE_BOLD8 = create(T_DRAW, "line_bold8.gif"); //$NON-NLS-1$
253
254
	public static final ImageDescriptor SEL_RECT = create(T_TOOL, "select_rect.gif"); //$NON-NLS-1$
255
204
	private static ImageDescriptor create(String prefix, String name) {
256
	private static ImageDescriptor create(String prefix, String name) {
205
		try {
257
		try {
206
			return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
258
			return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
(-)src/org/eclipse/mylyn/internal/commons/ui/messages.properties (-5 / +46 lines)
Lines 15-29 Link Here
15
15
16
ScreenshotCreationPage_After_capturing=After capturing, you can crop the image and make drawings on it. This window will not be captured. 
16
ScreenshotCreationPage_After_capturing=After capturing, you can crop the image and make drawings on it. This window will not be captured. 
17
ScreenshotCreationPage_Annotate=&Annotate
17
ScreenshotCreationPage_Annotate=&Annotate
18
ScreenshotCreationPage_Capture_Desktop=Capture Desktop
18
ScreenshotCreationPage_Capture_Desktop=Capture Desktop, Clipboard or File
19
ScreenshotCreationPage_Capture_Desktop_C=&Capture Desktop
19
ScreenshotCreationPage_Capture_Desktop_C=&Capture
20
ScreenshotCreationPage_CAPTURE_SCRRENSHOT=Capture Screenshot
20
ScreenshotCreationPage_CAPTURE_SCRRENSHOT=Capture Screenshot
21
ScreenshotCreationPage_Change_pen_color=Change pen color
22
ScreenshotCreationPage_Clear_all_annotations_made_on_screenshot_image=Clear all annotations made on screenshot image
21
ScreenshotCreationPage_Clear_all_annotations_made_on_screenshot_image=Clear all annotations made on screenshot image
23
ScreenshotCreationPage_Clear_Annotations=C&lear Annotations
22
ScreenshotCreationPage_Clear=C&lear
23
ScreenshotCreationPage_Undo=&Undo
24
ScreenshotCreationPage_Undo_annotation=Undo annotation
25
ScreenshotCreationPage_Redo=Re&do
26
ScreenshotCreationPage_Redo_annotation=Redo annotation
24
ScreenshotCreationPage_Crop=Crop
27
ScreenshotCreationPage_Crop=Crop
25
ScreenshotCreationPage_Crop_R=C&rop
28
ScreenshotCreationPage_Crop_R=C&rop
26
ScreenshotCreationPage_DRAW_ANNOTATION_ON_SCREENSHOT_IMAGE=Draw annotations on screenshot image
29
ScreenshotCreationPage_DRAW_ANNOTATION_ON_SCREENSHOT_IMAGE=Draw annotations on screenshot image
27
ScreenshotCreationPage_Fit_Image=Fit Image
30
ScreenshotCreationPage_Fit_Image=Fit Image
28
ScreenshotCreationPage_Fit_Image_F=&Fit Image
31
#ScreenshotCreationPage_Fit_Image_F=&Fit Image
32
ScreenshotCreationPage_Fit_Image_F=&Fit
29
ScreenshotCreationPage_NOTE_THAT_YOU_CONTINUTE=Note that you can continue to interact with the workbench in order to set up the screenshot.
33
ScreenshotCreationPage_NOTE_THAT_YOU_CONTINUTE=Note that you can continue to interact with the workbench in order to set up the screenshot.
34
ScreenshotCreationPage_Show_Line_Type_Selector=Show Line Type Selector
35
ScreenshotCreationPage_Show_Line_Bold_Selector=Show Line Bold Selector
36
37
SelectToolAction_Font_Bold=, Bold
38
SelectToolAction_Font_Italic=, Italic
39
SelectToolAction_Font_Name_Size={0}, {1} pt
40
SelectToolAction_1dot=1 dot
41
SelectToolAction_2dots=2 dots
42
SelectToolAction_4dots=4 dots
43
SelectToolAction_8dots=8 dots
44
SelectToolAction_Clipboard=Clipboard
45
SelectToolAction_Desktop=Desktop
46
SelectToolAction_File=File...
47
SelectToolAction_Selected_Rectangle=Selected Rectangle
48
SelectToolAction_Rectangle=Rectangle
49
SelectToolAction_Round_Rectangle=Round Rectangle
50
SelectToolAction_Oval=Oval
51
SelectToolAction_Fill_Rectangle=Fill Rectangle
52
SelectToolAction_Fill_Round_Rectangle=Fill Round Rectangle
53
SelectToolAction_Fill_Oval=Fill Oval
54
SelectToolAction_Free=Free
55
SelectToolAction_Line=Line
56
SelectToolAction_Single_Side_Arrow=Single Side Arrow
57
SelectToolAction_Both_Side_Arrow=Both Side Arrow
58
SelectToolAction_Dashed_Line=Dashed Line
59
SelectToolAction_Dashed_Line_1_dot=1 dots Dashed Line
60
SelectToolAction_Dashed_Line_2_dots=2 dots Dashed Line
61
SelectToolAction_Dotted_Line=Dotted Line
62
SelectToolAction_Solid_Line=Solid Line
63
SelectToolAction_Fit=Fit
64
SelectToolAction_ZoomHalf=50%
65
SelectToolAction_Zoom1X=100%
66
SelectToolAction_Zoom2X=200%
67
SelectToolAction_Zoom4X=400%
68
SelectToolAction_Zoom8X=800%
69
SelectToolAction_Font_=Font...
70
SelectToolAction_Color_=Color...
(-)src/org/eclipse/mylyn/internal/commons/ui/Messages.java (-3 / +81 lines)
Lines 53-63 Link Here
53
53
54
	public static String ScreenshotCreationPage_CAPTURE_SCRRENSHOT;
54
	public static String ScreenshotCreationPage_CAPTURE_SCRRENSHOT;
55
55
56
	public static String ScreenshotCreationPage_Change_pen_color;
57
58
	public static String ScreenshotCreationPage_Clear_all_annotations_made_on_screenshot_image;
56
	public static String ScreenshotCreationPage_Clear_all_annotations_made_on_screenshot_image;
59
57
60
	public static String ScreenshotCreationPage_Clear_Annotations;
58
	public static String ScreenshotCreationPage_Clear;
59
60
	public static String ScreenshotCreationPage_Undo;
61
62
	public static String ScreenshotCreationPage_Undo_annotation;
63
64
	public static String ScreenshotCreationPage_Redo;
65
66
	public static String ScreenshotCreationPage_Redo_annotation;
61
67
62
	public static String ScreenshotCreationPage_Crop;
68
	public static String ScreenshotCreationPage_Crop;
63
69
Lines 70-73 Link Here
70
	public static String ScreenshotCreationPage_Fit_Image_F;
76
	public static String ScreenshotCreationPage_Fit_Image_F;
71
77
72
	public static String ScreenshotCreationPage_NOTE_THAT_YOU_CONTINUTE;
78
	public static String ScreenshotCreationPage_NOTE_THAT_YOU_CONTINUTE;
79
80
	public static String ScreenshotCreationPage_Show_Line_Type_Selector;
81
82
	public static String ScreenshotCreationPage_Show_Line_Bold_Selector;
83
84
	public static String SelectToolAction_Font_Bold;
85
86
	public static String SelectToolAction_Font_Italic;
87
88
	public static String SelectToolAction_Font_Name_Size;
89
90
	public static String SelectToolAction_1dot;
91
92
	public static String SelectToolAction_2dots;
93
94
	public static String SelectToolAction_4dots;
95
96
	public static String SelectToolAction_8dots;
97
98
	public static String SelectToolAction_Clipboard;
99
100
	public static String SelectToolAction_Desktop;
101
102
	public static String SelectToolAction_File;
103
104
	public static String SelectToolAction_Rectangle;
105
106
	public static String SelectToolAction_Round_Rectangle;
107
108
	public static String SelectToolAction_Oval;
109
110
	public static String SelectToolAction_Fill_Rectangle;
111
112
	public static String SelectToolAction_Fill_Round_Rectangle;
113
114
	public static String SelectToolAction_Fill_Oval;
115
116
	public static String SelectToolAction_Free;
117
118
	public static String SelectToolAction_Line;
119
120
	public static String SelectToolAction_Single_Side_Arrow;
121
122
	public static String SelectToolAction_Both_Side_Arrow;
123
124
	public static String SelectToolAction_Dashed_Line;
125
126
	public static String SelectToolAction_Dashed_Line_1_dot;
127
128
	public static String SelectToolAction_Dashed_Line_2_dots;
129
130
	public static String SelectToolAction_Dotted_Line;
131
132
	public static String SelectToolAction_Solid_Line;
133
134
	public static String SelectToolAction_Fit;
135
136
	public static String SelectToolAction_ZoomHalf;
137
138
	public static String SelectToolAction_Zoom1X;
139
140
	public static String SelectToolAction_Zoom2X;
141
142
	public static String SelectToolAction_Zoom4X;
143
144
	public static String SelectToolAction_Zoom8X;
145
146
	public static String SelectToolAction_Selected_Rectangle;
147
148
	public static String SelectToolAction_Font_;
149
150
	public static String SelectToolAction_Color_;
73
}
151
}
(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/SelectToolAction.java (+858 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Hiroyuki Inaba - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylyn.internal.provisional.commons.ui;
12
13
import org.eclipse.core.runtime.Platform;
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.ActionContributionItem;
16
import org.eclipse.jface.action.IMenuCreator;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.mylyn.internal.commons.ui.Messages;
19
import org.eclipse.osgi.util.NLS;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.dnd.Clipboard;
22
import org.eclipse.swt.dnd.ImageTransfer;
23
import org.eclipse.swt.events.MouseAdapter;
24
import org.eclipse.swt.events.MouseEvent;
25
import org.eclipse.swt.graphics.Color;
26
import org.eclipse.swt.graphics.Font;
27
import org.eclipse.swt.graphics.FontData;
28
import org.eclipse.swt.graphics.GC;
29
import org.eclipse.swt.graphics.Image;
30
import org.eclipse.swt.graphics.ImageData;
31
import org.eclipse.swt.graphics.Point;
32
import org.eclipse.swt.graphics.RGB;
33
import org.eclipse.swt.graphics.Rectangle;
34
import org.eclipse.swt.widgets.ColorDialog;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Control;
37
import org.eclipse.swt.widgets.Display;
38
import org.eclipse.swt.widgets.Event;
39
import org.eclipse.swt.widgets.FileDialog;
40
import org.eclipse.swt.widgets.FontDialog;
41
import org.eclipse.swt.widgets.Listener;
42
import org.eclipse.swt.widgets.Menu;
43
import org.eclipse.swt.widgets.MenuItem;
44
import org.eclipse.swt.widgets.ToolItem;
45
import org.eclipse.swt.widgets.Widget;
46
47
public class SelectToolAction extends Action implements IMenuCreator {
48
49
	public static final int CAPTURE_DROP_DOWN_MENU = 1;
50
51
	public static final int ZOOM_DROP_DOWN_MENU = 2;
52
53
	public static final int DRAWLINE_TOOLBAR = 3;
54
55
	public static final int DRAWARROW_TOOLBAR = 4;
56
57
	public static final int DRAWBOX_TOOLBAR = 5;
58
59
	public static final int DRAWTEXT_TOOLBAR = 6;
60
61
	public static final int LINETYPE_TOOLBAR = 7;
62
63
	public static final int LINEBOLD_TOOLBAR = 8;
64
65
	public static final int COLOR_TOOLBAR = 9;
66
67
	public SelectToolAction(Composite parent, int tool) {
68
		this(parent, "", tool); //$NON-NLS-1$
69
	}
70
71
	public SelectToolAction(String label, int tool) {
72
		this(null, label, tool);
73
	}
74
75
	public SelectToolAction(Composite parent, String label, int tool) {
76
		super(label, AS_DROP_DOWN_MENU);
77
		setMenuCreator(this);
78
		showMenuAlways = true;
79
		this.parent = parent;
80
		setToolAction(tool);
81
	}
82
83
	private void setToolAction(int tool) {
84
		if (tool == CAPTURE_DROP_DOWN_MENU) {
85
			selectedItemID = CAPTURE_DESKTOP;
86
			initMenu(tool, new ToolActionItem[] {
87
					new ToolActionItem(CAPTURE_DESKTOP, Messages.SelectToolAction_Desktop, CommonImages.MINITOR_OBJ), //
88
					new ToolActionItem(CAPTURE_CLIPBOARD, Messages.SelectToolAction_Clipboard,
89
							CommonImages.CLIPBOARD_OBJ), //
90
					new ToolActionItem(CAPTURE_FILE, Messages.SelectToolAction_File, CommonImages.FILE_OBJ),
91
					new ToolActionItem(CAPTURE_RECTANGLE, Messages.SelectToolAction_Selected_Rectangle,
92
							CommonImages.SEL_RECT) });
93
			return;
94
		}
95
96
		if (tool == ZOOM_DROP_DOWN_MENU) {
97
			selectedItemID = ZOOM_FIT;
98
			initMenu(tool, new ToolActionItem[] { new ToolActionItem(ZOOM_FIT, Messages.SelectToolAction_Fit, null),
99
					new ToolActionItem(50, Messages.SelectToolAction_ZoomHalf, null),
100
					new ToolActionItem(100, Messages.SelectToolAction_Zoom1X, null),
101
					new ToolActionItem(200, Messages.SelectToolAction_Zoom2X, null),
102
					new ToolActionItem(400, Messages.SelectToolAction_Zoom4X, null),
103
					new ToolActionItem(800, Messages.SelectToolAction_Zoom8X, null) });
104
			return;
105
		}
106
107
		if (tool == LINETYPE_TOOLBAR) {
108
			selectedItemID = SWT.LINE_SOLID;
109
			initBar(tool, new ToolActionItem[] {
110
					new ToolActionItem(SWT.LINE_SOLID, Messages.SelectToolAction_Solid_Line, CommonImages.LINE_SOLD),
111
					new ToolActionItem(SWT.LINE_DOT, Messages.SelectToolAction_Dotted_Line, CommonImages.LINE_DOT),
112
					new ToolActionItem(SWT.LINE_DASH, Messages.SelectToolAction_Dashed_Line, CommonImages.LINE_DASH),
113
					new ToolActionItem(SWT.LINE_DASHDOT, Messages.SelectToolAction_Dashed_Line_1_dot,
114
							CommonImages.LINE_DASH1D),
115
					new ToolActionItem(SWT.LINE_DASHDOTDOT, Messages.SelectToolAction_Dashed_Line_2_dots,
116
							CommonImages.LINE_DASH2D) });
117
			return;
118
		}
119
120
		if (tool == DRAWLINE_TOOLBAR) {
121
			showSelection = true;
122
			selectedItemID = DRAW_FREE;
123
			initBar(tool, new ToolActionItem[] {
124
					new ToolActionItem(DRAW_FREE, Messages.SelectToolAction_Free, CommonImages.EDIT_FREE),
125
					new ToolActionItem(DRAW_LINE, Messages.SelectToolAction_Line, CommonImages.EDIT_LINE) });
126
			return;
127
		}
128
		if (tool == DRAWARROW_TOOLBAR) {
129
			showSelection = true;
130
			selectedItemID = DRAW_ARROW1;
131
			initBar(tool,
132
					new ToolActionItem[] {
133
							new ToolActionItem(DRAW_ARROW1, Messages.SelectToolAction_Single_Side_Arrow,
134
									CommonImages.EDIT_ARROW1),
135
							new ToolActionItem(DRAW_ARROW2, Messages.SelectToolAction_Both_Side_Arrow,
136
									CommonImages.EDIT_ARROW2) });
137
			selectedItemID = -1;
138
			return;
139
		}
140
		if (tool == DRAWBOX_TOOLBAR) {
141
			showSelection = true;
142
			selectedItemID = DRAW_RBOX;
143
			initBar(tool,
144
					new ToolActionItem[] {
145
							new ToolActionItem(DRAW_BOX, Messages.SelectToolAction_Rectangle, CommonImages.EDIT_BOX),
146
							new ToolActionItem(DRAW_RBOX, Messages.SelectToolAction_Round_Rectangle,
147
									CommonImages.EDIT_RBOX),
148
							new ToolActionItem(DRAW_OVAL, Messages.SelectToolAction_Oval, CommonImages.EDIT_OVAL),
149
							new ToolActionItem(DRAW_FILL_BOX, Messages.SelectToolAction_Fill_Rectangle,
150
									CommonImages.EDIT_FILL_BOX),
151
							new ToolActionItem(DRAW_FILL_RBOX, Messages.SelectToolAction_Fill_Round_Rectangle,
152
									CommonImages.EDIT_FILL_RBOX),
153
							new ToolActionItem(DRAW_FILL_OVAL, Messages.SelectToolAction_Fill_Oval,
154
									CommonImages.EDIT_FILL_OVAL) });
155
			selectedItemID = -1;
156
			return;
157
		}
158
		if (tool == DRAWTEXT_TOOLBAR) {
159
			showSelection = true;
160
			selectedItemID = DRAW_TEXT;
161
			FontData fontData = parent.getShell().getFont().getFontData()[0];
162
			stringCustom = fontData.toString();
163
			intgerCustom = rgb2int(255, 0, 0);
164
			selectedItemID = intgerCustom;
165
			initFont(tool);
166
			selectedItemID = -1;
167
			return;
168
		}
169
170
		if (tool == LINEBOLD_TOOLBAR) {
171
			selectedItemID = 4;
172
			initBar(tool, new ToolActionItem[] {
173
					new ToolActionItem(1, Messages.SelectToolAction_1dot, CommonImages.LINE_BOLD1),
174
					new ToolActionItem(2, Messages.SelectToolAction_2dots, CommonImages.LINE_BOLD2),
175
					new ToolActionItem(4, Messages.SelectToolAction_4dots, CommonImages.LINE_BOLD4),
176
					new ToolActionItem(8, Messages.SelectToolAction_8dots, CommonImages.LINE_BOLD8) });
177
			return;
178
		}
179
180
		if (tool == COLOR_TOOLBAR) {
181
			intgerCustom = rgb2int(255, 85, 85);
182
			selectedItemID = intgerCustom;
183
			initColor(tool);
184
			return;
185
		}
186
	}
187
188
	private void initBar(int tool, ToolActionItem[] items) {
189
		this.items = items;
190
		setId(tool + ""); //$NON-NLS-1$
191
		toolButton = new ToolComposite(parent, SWT.CASCADE) {
192
193
			@Override
194
			public void clickBody() {
195
				selectItem(getToolTipText(), null);
196
			}
197
198
			@Override
199
			public void clickMenu(int x, int y) {
200
				dropDownMenu = new Menu(parent.getShell(), SWT.POP_UP);
201
				addActionsToMenu();
202
				Point p = parent.toDisplay(x, y);
203
				dropDownMenu.setLocation(p.x, p.y);
204
				dropDownMenu.setVisible(true);
205
				dropDownMenu = null;
206
			}
207
208
			@Override
209
			public boolean isSelect() {
210
				return (selectedItemID >= 0);
211
			}
212
		};
213
214
		if (items != null) {
215
			for (ToolActionItem actionItem : items) {
216
				if (actionItem.id == selectedItemID) {
217
					toolButton.setImage(actionItem.image.createImage());
218
					toolButton.setToolTipText(actionItem.label);
219
				}
220
			}
221
		}
222
	}
223
224
	private void initFont(int tool) {
225
		this.items = null;
226
		setId(tool + ""); //$NON-NLS-1$
227
		toolButton = new ToolComposite(parent, SWT.CASCADE) {
228
229
			@Override
230
			public void clickBody() {
231
				selectedItemID = DRAW_TEXT;
232
				if (toolButton != null) {
233
					FontData fontData = new FontData(stringCustom);
234
					toolButton.setImage(createFontImage(fontData, int2rgb(intgerCustom), true));
235
					toolButton.redraw();
236
				}
237
				run();
238
			}
239
240
			@Override
241
			public void clickMenu(int x, int y) {
242
				if (Platform.getWS().equalsIgnoreCase(Platform.WS_WIN32)
243
						|| Platform.getWS().equalsIgnoreCase(Platform.WS_WPF)) {
244
					invokeFontDialog();
245
				} else {
246
					Menu rightClickMenu = new Menu(parent.getShell(), SWT.POP_UP);
247
					MenuItem menuItem = new MenuItem(rightClickMenu, SWT.PUSH);
248
					menuItem.setText(Messages.SelectToolAction_Font_);
249
					menuItem.addListener(SWT.Selection, new Listener() {
250
						public void handleEvent(final Event event) {
251
							invokeFontDialog();
252
						}
253
					});
254
					menuItem = new MenuItem(rightClickMenu, SWT.PUSH);
255
					menuItem.setText(Messages.SelectToolAction_Color_);
256
					menuItem.addListener(SWT.Selection, new Listener() {
257
						public void handleEvent(final Event event) {
258
							invokeColorDialog();
259
						}
260
					});
261
					Point p = parent.toDisplay(x, y);
262
					rightClickMenu.setLocation(p.x, p.y);
263
					rightClickMenu.setVisible(true);
264
				}
265
			}
266
267
			@Override
268
			public boolean isSelect() {
269
				return (selectedItemID >= 0);
270
			}
271
272
			public void invokeFontDialog() {
273
				FontData fontData = new FontData(stringCustom);
274
				FontDialog fontWindow = new FontDialog(parent.getShell());
275
				fontWindow.setFontList(new FontData[] { fontData });
276
				fontWindow.setRGB(int2rgb(intgerCustom));
277
				fontData = fontWindow.open();
278
				if (fontData != null) {
279
					intgerCustom = rgb2int(fontWindow.getRGB());
280
					stringCustom = fontData.toString();
281
					toolButton.setToolTipText(font2string(fontData));
282
					clickBody();
283
				}
284
			}
285
286
			public void invokeColorDialog() {
287
				ColorDialog colorWindow = new ColorDialog(parent.getShell());
288
				colorWindow.setRGB(int2rgb(intgerCustom));
289
				RGB rgb = colorWindow.open();
290
				if (rgb != null) {
291
					intgerCustom = rgb2int(rgb);
292
					clickBody();
293
				}
294
			}
295
		};
296
297
		FontData fontData = new FontData(stringCustom);
298
		toolButton.setToolTipText(font2string(fontData));
299
		toolButton.setImage(createFontImage(fontData, int2rgb(intgerCustom), false));
300
	}
301
302
	private void initColor(int tool) {
303
		this.items = null;
304
		setId(tool + ""); //$NON-NLS-1$
305
		toolButton = new ToolComposite(parent, SWT.NONE) {
306
307
			@Override
308
			public void clickMenu(int x, int y) {
309
				ColorDialog colorWindow = new ColorDialog(parent.getShell());
310
				colorWindow.setRGB(int2rgb(intgerCustom));
311
				RGB rgb = colorWindow.open();
312
				if (rgb != null) {
313
					intgerCustom = rgb2int(rgb);
314
					selectedItemID = intgerCustom;
315
					toolButton.setImage(createColorImage(int2rgb(intgerCustom)));
316
					toolButton.redraw();
317
				}
318
			}
319
		};
320
		toolButton.setToolTipText(""); //$NON-NLS-1$
321
		toolButton.setImage(createColorImage(int2rgb(intgerCustom)));
322
	}
323
324
	private Image createColorImage(RGB rgb) {
325
		Display display = parent.getDisplay();
326
		Color BACKGROUND = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
327
		Color DARK_GRAY = display.getSystemColor(SWT.COLOR_DARK_GRAY);
328
		int x = 16, y = 16;
329
		Image image = new Image(display, x, y);
330
		GC gc = new GC(image);
331
		gc.setForeground(DARK_GRAY);
332
		gc.setBackground(BACKGROUND);
333
		gc.fillRectangle(0, 0, x, y);
334
		gc.setBackground(new Color(display, rgb));
335
		gc.fillRectangle(1, 2, x - 2, y - 4);
336
		gc.drawRectangle(1, 2, x - 3, y - 5);
337
		gc.dispose();
338
		return image;
339
	}
340
341
	private Image createFontImage(FontData fontData, RGB rgb, boolean select) {
342
		Display display = parent.getDisplay();
343
		Color ButtonFace = display.getSystemColor((select) ? SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW
344
				: SWT.COLOR_WIDGET_BACKGROUND);
345
		int x = 16, y = 16;
346
		Image image = new Image(display, x, y);
347
		GC gc = new GC(image);
348
		gc.setBackground(ButtonFace);
349
		gc.fillRectangle(0, 0, x, y);
350
		String label = "A"; //$NON-NLS-1$
351
		fontData.height = 11;
352
		gc.setFont(new Font(display, fontData));
353
		gc.setForeground(new Color(display, rgb));
354
		Point sz = gc.textExtent(label);
355
		gc.drawText(label, (x - sz.x) / 2, (y - sz.y) / 2 + 1, true);
356
		gc.dispose();
357
		return image;
358
	}
359
360
	private void initMenu(int tool, ToolActionItem[] items) {
361
		this.items = items;
362
		setId(tool + ""); //$NON-NLS-1$
363
		if (items != null) {
364
			setImageDescriptor(items[0].image);
365
			setToolTipText(items[0].label);
366
			selectedItemID = items[0].id;
367
		}
368
	}
369
370
	private class ToolActionItem {
371
		int id;
372
373
		String label;
374
375
		ImageDescriptor image;
376
377
		ToolActionItem(int id, String label, ImageDescriptor image) {
378
			this.id = id;
379
			this.label = label;
380
			this.image = image;
381
		}
382
	}
383
384
	private class ToolComposite extends Composite {
385
		private Image image;
386
387
		private final boolean bMenu;
388
389
		private boolean bMouse;
390
391
		private static final int S = 1; // Border for Selected rectangle
392
393
		private static final int B = 2; // Border for Shadow rectangle  
394
395
		private static final int G = 3; // Gap
396
397
		private static final int M = 4; // Image width for Sub menu  
398
399
		private final Point iconSize = new Point(S + B + 16 + B + S, S + B + 16 + B + S);
400
401
		private final Point maxSize = new Point(iconSize.x + G + M + G, iconSize.y);
402
403
		public ToolComposite(Composite parent, int style) {
404
			super(parent, style);
405
			bMenu = (style & SWT.CASCADE) != 0;
406
407
			addListener(SWT.Paint, new Listener() {
408
				public void handleEvent(Event e) {
409
					Color background = e.gc.getBackground();
410
					Color foreground = e.gc.getForeground();
411
					Display display = e.widget.getDisplay();
412
					Color NORMAL_SHADOW = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
413
					boolean enabled = getEnabled();
414
					if (bMouse && enabled) {
415
						e.gc.setForeground(NORMAL_SHADOW);
416
						if (bMenu) {
417
							e.gc.drawRectangle(0, 0, maxSize.x - 1, maxSize.y - 1);
418
							e.gc.drawLine(iconSize.x, 0, iconSize.x, maxSize.y);
419
						} else {
420
							e.gc.drawRectangle(0, 0, iconSize.x - 1, iconSize.y - 1);
421
						}
422
					}
423
					if (showSelection && isSelect() && enabled) {
424
						Color HIGHLIGHT_SHADOW = display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
425
						Color LIGHT_SHADOW = display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
426
						Color SELECTION = display.getSystemColor(SWT.COLOR_LIST_SELECTION);
427
						e.gc.setBackground(HIGHLIGHT_SHADOW);
428
						e.gc.fillRectangle(0, 0, iconSize.x, iconSize.y);
429
						e.gc.setForeground(NORMAL_SHADOW);
430
						e.gc.drawLine(S, S, iconSize.x - S - 1, S);
431
						e.gc.drawLine(S + 1, S + 1, iconSize.x - S - 2, S + 1);
432
						e.gc.drawLine(S, S, S, iconSize.y - S - 1);
433
						e.gc.drawLine(S + 1, S + 1, S + 1, iconSize.y - S - 2);
434
						e.gc.setForeground(HIGHLIGHT_SHADOW);
435
						e.gc.drawLine(iconSize.x - S - 1, S + 1, iconSize.x - S - 1, iconSize.y - S - 1);
436
						e.gc.drawLine(S, iconSize.y - S - 1, iconSize.x - S - 1, iconSize.y - S - 1);
437
						e.gc.setForeground(LIGHT_SHADOW);
438
						e.gc.drawLine(iconSize.x - S - 2, S + 2, iconSize.x - S - 2, iconSize.y - S - 2);
439
						e.gc.drawLine(S + 1, iconSize.x - S - 2, iconSize.x - S - 2, iconSize.y - S - 2);
440
						e.gc.setForeground(SELECTION);
441
						e.gc.drawRectangle(0, 0, iconSize.x - 1, iconSize.y - 1);
442
					}
443
444
					if (getEnabled()) {
445
						e.gc.drawImage(image, S + B, S + B);
446
					} else {
447
						Image disabled = new Image(display, image, SWT.IMAGE_DISABLE);
448
						e.gc.drawImage(disabled, S + B, S + B);
449
					}
450
451
					if (bMenu) {
452
						if (Platform.getWS().equalsIgnoreCase(Platform.WS_WIN32)
453
								|| Platform.getWS().equalsIgnoreCase(Platform.WS_WPF)) {
454
							Color FOREGROUND = display.getSystemColor((getEnabled()) ? SWT.COLOR_WIDGET_FOREGROUND
455
									: SWT.COLOR_WIDGET_DARK_SHADOW);
456
							e.gc.setForeground(FOREGROUND);
457
							int x = iconSize.x + G;
458
							int y = S + B + M;
459
							int h = 6;
460
							while (h >= 0) {
461
								e.gc.drawLine(x, y, x, y + h);
462
								x++;
463
								y++;
464
								h -= 2;
465
							}
466
						} else {
467
							Color FOREGROUND = display.getSystemColor((getEnabled()) ? SWT.COLOR_WIDGET_DARK_SHADOW
468
									: SWT.COLOR_WIDGET_NORMAL_SHADOW);
469
							e.gc.setForeground(FOREGROUND);
470
							int x = iconSize.x + G;
471
							int y = S + B + M;
472
							int h = 4;
473
							e.gc.drawLine(x, y, x + h / 2 + 1, y + h / 2 + 1);
474
							e.gc.drawLine(x, y + 1, x + h / 2, y + h / 2 + 1);
475
							e.gc.drawLine(x, y + h + 1, x + h / 2, y + h / 2 + 1);
476
							e.gc.drawLine(x, y + h + 2, x + h / 2, y + h / 2 + 2);
477
						}
478
					}
479
					e.gc.setBackground(background);
480
					e.gc.setForeground(foreground);
481
					//System.out.println(e.toString());
482
				}
483
			});
484
485
			addMouseListener(new MouseAdapter() {
486
				@Override
487
				public void mouseDown(MouseEvent e) {
488
					if (e.x < iconSize.x && e.y < iconSize.y) {
489
						if (showSelection) {
490
							clickBody();
491
							return;
492
						} else {
493
							invokeMenu((Composite) e.widget);
494
						}
495
					} else {
496
						invokeMenu((Composite) e.widget);
497
					}
498
				}
499
500
				private void invokeMenu(Composite widget) {
501
					Rectangle b = widget.getBounds();
502
					Point p = widget.getLocation();
503
					p.x += b.width + 3;
504
					bMouse = false;
505
					redraw();
506
					clickMenu(p.x, p.y);
507
				}
508
			});
509
510
			addListener(SWT.MouseEnter, new Listener() {
511
512
				public void handleEvent(Event event) {
513
					if (getEnabled()) {
514
						bMouse = true;
515
						redraw();
516
					}
517
				}
518
			});
519
			addListener(SWT.MouseMove, new Listener() {
520
521
				public void handleEvent(Event event) {
522
					if (getEnabled()) {
523
						bMouse = true;
524
						redraw();
525
					}
526
				}
527
			});
528
			addListener(SWT.MouseExit, new Listener() {
529
530
				public void handleEvent(Event event) {
531
					if (getEnabled()) {
532
						bMouse = false;
533
						redraw();
534
					}
535
				}
536
			});
537
		}
538
539
		@Override
540
		public Point computeSize(int wHint, int hHint, boolean changed) {
541
			if (!getVisible()) {
542
				return new Point(0, 0);
543
			}
544
			return maxSize;
545
		}
546
547
		public void setImage(Image image) {
548
			this.image = image;
549
		}
550
551
		public void clickBody() {
552
		}
553
554
		public void clickMenu(int x, int y) {
555
		}
556
557
		public boolean isSelect() {
558
			return false;
559
		}
560
	}
561
562
	private ToolActionItem[] items;
563
564
	private int selectedItemID;
565
566
	private ToolComposite toolButton;
567
568
	private Menu dropDownMenu;
569
570
	private int intgerCustom;
571
572
	private String stringCustom;
573
574
	private boolean showMenuAlways;
575
576
	public boolean isShowMenuAlways() {
577
		return showMenuAlways;
578
	}
579
580
	public void setShowMenuAlways(boolean showMenuAlways) {
581
		this.showMenuAlways = showMenuAlways;
582
	}
583
584
	@Override
585
	public void runWithEvent(Event event) {
586
		if (showMenuAlways) {
587
			IMenuCreator mc = getMenuCreator();
588
			if (mc != null) {
589
				Widget item = event.widget;
590
				ToolItem ti = (ToolItem) item;
591
				Menu m = mc.getMenu(ti.getParent());
592
				if (m != null) {
593
					// position the menu below the drop down item
594
					Rectangle itemBounds = ti.getBounds();
595
					Point point = ti.getParent().toDisplay(itemBounds.x, itemBounds.y + itemBounds.height);
596
					m.setLocation(point.x, point.y); // waiting for SWT
597
					m.setVisible(true);
598
					return; // we don't fire the action
599
				}
600
			}
601
		}
602
		super.runWithEvent(event);
603
	}
604
605
	public static final int ZOOM_FIT = 0;
606
607
	public static final int DRAW_FREE = 0;
608
609
	public static final int DRAW_LINE = 1;
610
611
	public static final int DRAW_ARROW1 = 2;
612
613
	public static final int DRAW_ARROW2 = 3;
614
615
	public static final int DRAW_BOX = 10;
616
617
	public static final int DRAW_RBOX = 11;
618
619
	public static final int DRAW_FILL_BOX = 12;
620
621
	public static final int DRAW_FILL_RBOX = 13;
622
623
	public static final int DRAW_OVAL = 20;
624
625
	public static final int DRAW_FILL_OVAL = 21;
626
627
	public static final int DRAW_TEXT = 30;
628
629
	public static final int CAPTURE_DESKTOP = 0;
630
631
	public static final int CAPTURE_CLIPBOARD = 1;
632
633
	public static final int CAPTURE_FILE = 2;
634
635
	public static final int CAPTURE_RECTANGLE = 3;
636
637
	public int getSelect() {
638
		return selectedItemID;
639
	}
640
641
	public void setUnselect() {
642
		selectedItemID = -1;
643
		if (toolButton != null) {
644
			if (getId().equals(DRAWTEXT_TOOLBAR + "")) { //$NON-NLS-1$
645
				FontData fontData = new FontData(stringCustom);
646
				toolButton.setImage(createFontImage(fontData, int2rgb(intgerCustom), false));
647
			}
648
			toolButton.redraw();
649
		}
650
	}
651
652
	public int getIntgerCustom() {
653
		return intgerCustom;
654
	}
655
656
	public String getStringCustom() {
657
		return stringCustom;
658
	}
659
660
	protected void selectItem(String label, ImageDescriptor image) {
661
		for (ToolActionItem actionItem : items) {
662
			if (actionItem.label.equals(label)) {
663
				selectedItemID = actionItem.id;
664
				if (getId().equals(CAPTURE_DROP_DOWN_MENU + "")) { //$NON-NLS-1$
665
					if (selectedItemID == CAPTURE_FILE) {
666
						FileDialog dialog = new FileDialog(parent.getShell());
667
						dialog.setFileName(filename);
668
						dialog.setFilterExtensions(new String[] { "*.bmp;*.jpg;*.png", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
669
						String result = dialog.open();
670
						if (result != null && result.length() > 0) {
671
							filename = result;
672
							run();
673
						}
674
					} else {
675
						run();
676
					}
677
					selectedItemID = CAPTURE_DESKTOP;
678
				} else {
679
					setToolTipText(label);
680
					if (image != null) {
681
						setImageDescriptor(image);
682
					}
683
					if (toolButton != null) {
684
						toolButton.setToolTipText(label);
685
						if (image != null) {
686
							toolButton.setImage(image.createImage());
687
						}
688
						toolButton.redraw();
689
					}
690
					run();
691
				}
692
				break;
693
			}
694
		}
695
	}
696
697
	private void addActionsToMenu() {
698
		for (ToolActionItem actionItem : items) {
699
			Action action = new Action() {
700
				@Override
701
				public void run() {
702
					selectItem(getText(), getImageDescriptor());
703
				}
704
			};
705
			action.setText(actionItem.label);
706
			if (actionItem.image != null) {
707
				action.setImageDescriptor(actionItem.image);
708
			}
709
			updateAction(action, actionItem.id);
710
			ActionContributionItem contributionItem = new ActionContributionItem(action);
711
			contributionItem.fill(dropDownMenu, -1);
712
		}
713
	}
714
715
	private void updateAction(Action action, int id) {
716
		action.setChecked(id == selectedItemID);
717
		if (getId().equals(CAPTURE_DROP_DOWN_MENU + "")) { //$NON-NLS-1$
718
			if (id == CAPTURE_CLIPBOARD) {
719
				action.setEnabled(existImageOnClipboard());
720
			} else if (id == CAPTURE_RECTANGLE) {
721
				action.setEnabled(isEnableRectangle());
722
			}
723
		}
724
	}
725
726
	protected boolean isEnableRectangle() {
727
		return false;
728
	}
729
730
	public void dispose() {
731
		if (toolButton != null) {
732
			toolButton.dispose();
733
			toolButton = null;
734
		}
735
		if (dropDownMenu != null) {
736
			dropDownMenu.dispose();
737
			dropDownMenu = null;
738
		}
739
	}
740
741
	public Menu getMenu(Control parent) {
742
		if (dropDownMenu != null) {
743
			dropDownMenu.dispose();
744
		}
745
		dropDownMenu = new Menu(parent);
746
		addActionsToMenu();
747
		return dropDownMenu;
748
	}
749
750
	public Menu getMenu(Menu parent) {
751
		if (dropDownMenu != null) {
752
			dropDownMenu.dispose();
753
		}
754
		dropDownMenu = new Menu(parent);
755
		addActionsToMenu();
756
		return dropDownMenu;
757
	}
758
759
	private final Composite parent;
760
761
	private boolean showSelection;
762
763
	private String filename;
764
765
	public boolean getVisible() {
766
		if (toolButton != null) {
767
			return toolButton.getVisible();
768
		}
769
		return false;
770
	}
771
772
	public void setVisible(boolean visible) {
773
		if (toolButton != null) {
774
			toolButton.setVisible(visible);
775
			toolButton.redraw();
776
		}
777
	}
778
779
	public boolean getEnabled() {
780
		if (toolButton != null) {
781
			return toolButton.getEnabled();
782
		}
783
		return false;
784
	}
785
786
	@Override
787
	public void setEnabled(boolean enabled) {
788
		super.setEnabled(enabled);
789
		if (toolButton != null) {
790
			toolButton.setEnabled(enabled);
791
			toolButton.redraw();
792
		}
793
	}
794
795
	public Image getFileImage() {
796
		try {
797
			Image image = new Image(parent.getShell().getDisplay(), filename);
798
			return image;
799
		} catch (Exception e) {
800
			// None
801
		}
802
		return null;
803
	}
804
805
	public Image getClipboardImage() {
806
		try {
807
			Clipboard clipboard = new Clipboard(parent.getShell().getDisplay());
808
			ImageTransfer imageTransfer = ImageTransfer.getInstance();
809
			Object data = clipboard.getContents(imageTransfer);
810
			if (data instanceof ImageData) {
811
				Image image = new Image(parent.getShell().getDisplay(), (ImageData) data);
812
				return image;
813
			}
814
		} catch (Exception e) {
815
			// None
816
		}
817
		return null;
818
	}
819
820
	private boolean existImageOnClipboard() {
821
		try {
822
			Clipboard clipboard = new Clipboard(parent.getShell().getDisplay());
823
			ImageTransfer imageTransfer = ImageTransfer.getInstance();
824
			Object data = clipboard.getContents(imageTransfer);
825
			if (data instanceof ImageData) {
826
				return true;
827
			}
828
		} catch (Exception e) {
829
			// None
830
		}
831
		return false;
832
	}
833
834
	public static int rgb2int(RGB rgb) {
835
		return rgb2int(rgb.red, rgb.green, rgb.blue);
836
	}
837
838
	public static int rgb2int(int r, int g, int b) {
839
		return (r << 16) + (g << 8) + b;
840
	}
841
842
	public static RGB int2rgb(int rgb) {
843
		return new RGB(rgb >> 16, (rgb >> 8) & 0x00ff, rgb & 0x00ff);
844
	}
845
846
	private String font2string(FontData fontData) {
847
		String info = NLS.bind(Messages.SelectToolAction_Font_Name_Size, //
848
				new Object[] { fontData.getName(), fontData.getHeight() + "" }); //$NON-NLS-1$
849
		int style = fontData.getStyle();
850
		if ((style & SWT.BOLD) != 0) {
851
			info = info + Messages.SelectToolAction_Font_Bold;
852
		}
853
		if ((style & SWT.ITALIC) != 0) {
854
			info = info + Messages.SelectToolAction_Font_Italic;
855
		}
856
		return info;
857
	}
858
}

Return to bug 266123