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

Return to bug 266123