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