|
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 |
} |
|
|
| 363 |
|
477 |
|
| 364 |
private ActionContributionItem createAndConfigureCI(IAction action) { |
478 |
createBottomToolbars(); |
| 365 |
ActionContributionItem ci = new ActionContributionItem(action); |
479 |
disposeBottomToolbars(); |
| 366 |
ci.setMode(ActionContributionItem.MODE_FORCE_TEXT); |
|
|
| 367 |
return ci; |
| 368 |
} |
480 |
} |
| 369 |
|
481 |
|
| 370 |
private void setMarkColor(RGB color) { |
482 |
private void disposeBottomToolbars() { |
| 371 |
if (markColor != null) { |
483 |
if (bottomArea == null) { |
| 372 |
markColor.dispose(); |
484 |
return; |
| 373 |
} |
485 |
} |
| 374 |
markColor = new Color(getShell().getDisplay(), color); |
486 |
if (drawToolbar != null) { |
| 375 |
if (workImageGC != null) { |
487 |
drawToolbar.dispose(); |
| 376 |
workImageGC.setForeground(markColor); |
488 |
drawToolbar = null; |
|
|
489 |
} |
| 490 |
if (lineToolbar != null) { |
| 491 |
lineToolbar.dispose(); |
| 492 |
lineToolbar = null; |
| 493 |
} |
| 494 |
if (boldToolbar != null) { |
| 495 |
boldToolbar.dispose(); |
| 496 |
boldToolbar = null; |
| 497 |
} |
| 498 |
if (colorToolbar != null) { |
| 499 |
colorToolbar.dispose(); |
| 500 |
colorToolbar = null; |
| 501 |
} |
| 502 |
if (fontToolbar != null) { |
| 503 |
fontToolbar.dispose(); |
| 504 |
fontToolbar = null; |
| 505 |
} |
| 506 |
bottomArea.dispose(); |
| 507 |
bottomArea = null; |
| 508 |
getControl().getParent().layout(); |
| 509 |
} |
| 510 |
|
| 511 |
private void createBottomToolbars() { |
| 512 |
Composite body = getControl().getParent(); |
| 513 |
if (bottomArea == null) { |
| 514 |
bottomArea = new Composite(body, SWT.NONE); |
| 515 |
bottomArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 516 |
RowLayout layout = new RowLayout(); |
| 517 |
layout.marginTop = 0; |
| 518 |
layout.marginBottom = 1; |
| 519 |
layout.marginLeft = 1; |
| 520 |
layout.marginRight = 1; |
| 521 |
layout.marginRight = 1; |
| 522 |
bottomArea.setLayout(layout); |
| 523 |
bottomArea.addListener(SWT.Paint, new Listener() { |
| 524 |
public void handleEvent(Event e) { |
| 525 |
Color gcForeground = e.gc.getForeground(); |
| 526 |
Rectangle bounds = ((Composite) e.widget).getBounds(); |
| 527 |
Color border = e.widget.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); |
| 528 |
e.gc.setForeground(border); |
| 529 |
e.gc.drawLine(0, 0, 0, bounds.height - 1); |
| 530 |
e.gc.drawLine(0, bounds.height - 1, bounds.width - 1, bounds.height - 1); |
| 531 |
e.gc.drawLine(bounds.width - 1, 0, bounds.width - 1, bounds.height - 1); |
| 532 |
e.gc.setForeground(gcForeground); |
| 533 |
} |
| 534 |
}); |
| 377 |
} |
535 |
} |
| 378 |
|
536 |
|
| 379 |
GC colorGC = new GC(colorIcon); |
537 |
if (drawToolbar == null) { |
| 380 |
colorGC.setBackground(markColor); |
538 |
drawToolbar = new SelectToolAction(bottomArea, SelectToolAction.DRAW_TOOLBAR) { |
| 381 |
colorGC.fillRectangle(0, 0, 16, 16); |
539 |
|
| 382 |
colorGC.drawRectangle(0, 0, 15, 15); |
540 |
@Override |
| 383 |
colorGC.dispose(); |
541 |
public void run() { |
|
|
542 |
if (drawToolbar.getSelect() != SelectToolAction.DRAW_TEXT) { |
| 543 |
if (fontToolbar != null) { |
| 544 |
createBottomToolbars(); |
| 545 |
} |
| 546 |
} else { |
| 547 |
if (fontToolbar == null) { |
| 548 |
createBottomToolbars(); |
| 549 |
} |
| 550 |
} |
| 551 |
} |
| 552 |
}; |
| 553 |
} |
| 554 |
if (drawToolbar.getSelect() != SelectToolAction.DRAW_TEXT) { |
| 555 |
if (fontToolbar != null) { |
| 556 |
fontToolbar.dispose(); |
| 557 |
fontToolbar = null; |
| 558 |
} |
| 559 |
if (lineToolbar == null) { |
| 560 |
lineToolbar = new SelectToolAction(bottomArea, SelectToolAction.LINE_TOOLBAR); |
| 561 |
} |
| 562 |
if (boldToolbar == null) { |
| 563 |
boldToolbar = new SelectToolAction(bottomArea, SelectToolAction.BOLD_TOOLBAR); |
| 564 |
} |
| 565 |
if (colorToolbar == null) { |
| 566 |
colorToolbar = new SelectToolAction(bottomArea, SelectToolAction.COLOR_TOOLBAR); |
| 567 |
} |
| 568 |
} else { |
| 569 |
if (lineToolbar != null) { |
| 570 |
lineToolbar.dispose(); |
| 571 |
lineToolbar = null; |
| 572 |
} |
| 573 |
if (boldToolbar != null) { |
| 574 |
boldToolbar.dispose(); |
| 575 |
boldToolbar = null; |
| 576 |
} |
| 577 |
if (colorToolbar != null) { |
| 578 |
colorToolbar.dispose(); |
| 579 |
colorToolbar = null; |
| 580 |
} |
| 581 |
if (fontToolbar == null) { |
| 582 |
fontToolbar = new SelectToolAction(bottomArea, SelectToolAction.FONT_TOOLBAR); |
| 583 |
} |
| 584 |
} |
| 384 |
|
585 |
|
| 385 |
colorAction.setImageDescriptor(ImageDescriptor.createFromImage(colorIcon)); |
586 |
Dialog.applyDialogFont(bottomArea); |
|
|
587 |
bottomArea.layout(); |
| 588 |
body.layout(); |
| 589 |
} |
| 590 |
|
| 591 |
private ActionContributionItem createAndConfigureCI(IAction action) { |
| 592 |
ActionContributionItem ci = new ActionContributionItem(action); |
| 593 |
ci.setMode(ActionContributionItem.MODE_FORCE_TEXT); |
| 594 |
return ci; |
| 386 |
} |
595 |
} |
| 387 |
|
596 |
|
| 388 |
@Override |
597 |
@Override |
| 389 |
public void dispose() { |
598 |
public void dispose() { |
|
|
599 |
disposeBottomToolbars(); |
| 390 |
disposeImageResources(); |
600 |
disposeImageResources(); |
| 391 |
if (markColor != null) { |
|
|
| 392 |
markColor.dispose(); |
| 393 |
} |
| 394 |
if (colorIcon != null) { |
| 395 |
colorIcon.dispose(); |
| 396 |
} |
| 397 |
|
601 |
|
| 398 |
canvas.setCursor(null); |
602 |
canvas.setCursor(null); |
| 399 |
for (Cursor cursor : cursors.values()) { |
603 |
for (Cursor cursor : cursors.values()) { |
|
Lines 440-450
Link Here
|
| 440 |
int y = (int) Math.round(currentSelection.y * scaleFactor); |
644 |
int y = (int) Math.round(currentSelection.y * scaleFactor); |
| 441 |
int right = (int) Math.round((currentSelection.x + currentSelection.width) * scaleFactor); |
645 |
int right = (int) Math.round((currentSelection.x + currentSelection.width) * scaleFactor); |
| 442 |
int bottom = (int) Math.round((currentSelection.y + currentSelection.height) * scaleFactor); |
646 |
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; |
647 |
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; |
648 |
int height = Math.min(bottom, (int) Math.round(workImage.getBounds().height * scaleFactor)) - y; |
| 445 |
return new Rectangle(x, y, width, height); |
649 |
return new Rectangle(x, y, width, height); |
| 446 |
} |
650 |
} |
| 447 |
|
651 |
|
|
|
652 |
private Rectangle getOutsideSelection(Rectangle rectangle) { |
| 653 |
if (rectangle == null) { |
| 654 |
return null; |
| 655 |
} |
| 656 |
return new Rectangle(rectangle.x - SQUARE_SIZE * 2, rectangle.y - SQUARE_SIZE * 2, // |
| 657 |
rectangle.width + SQUARE_SIZE * 4 + 1, rectangle.height + SQUARE_SIZE * 4 + 1); |
| 658 |
} |
| 659 |
|
| 660 |
private static final int[][] grapGroupPoints = { // |
| 661 |
/* */{ 0, 0, 0 }, { 1, 0, 0 }, { 2, 0, 1 }, { 3, 0, 2 }, { 4, 0, 2 }, // |
| 662 |
{ 0, 1, 0 }, /* *//* *//* */{ 4, 1, 2 }, // |
| 663 |
{ 0, 2, 3 }, /* *//* *//* */{ 4, 2, 4 }, // |
| 664 |
{ 0, 3, 5 }, /* *//* *//* */{ 4, 3, 7 }, // |
| 665 |
{ 0, 4, 5 }, { 1, 4, 5 }, { 2, 4, 6 }, { 3, 4, 7 }, { 4, 4, 7 } }; |
| 666 |
|
| 667 |
private static final int[] grapScanOrder = { 0, 4, 1, 3, 2 }; |
| 668 |
|
| 669 |
private int getGrabPoint(int x, int y) { |
| 670 |
if (currentSelection == null) { |
| 671 |
return -1; |
| 672 |
} |
| 673 |
|
| 674 |
Rectangle inside = getScaledSelection(); |
| 675 |
Rectangle outside = getOutsideSelection(inside); |
| 676 |
int[] xGroupPoint = { outside.x, // |
| 677 |
inside.x, // |
| 678 |
inside.x + SQUARE_SIZE * 4, // |
| 679 |
inside.x + inside.width - SQUARE_SIZE * 4, // |
| 680 |
inside.x + inside.width, // |
| 681 |
outside.x + outside.width }; |
| 682 |
int[] yGroupPoint = { outside.y, // |
| 683 |
inside.y, // |
| 684 |
inside.y + SQUARE_SIZE * 4, // |
| 685 |
inside.y + inside.height - SQUARE_SIZE * 4, // |
| 686 |
inside.y + inside.height, // |
| 687 |
outside.y + outside.height }; |
| 688 |
int xGroup = -1, yGroup = -1; |
| 689 |
for (int element : grapScanOrder) { |
| 690 |
if (xGroupPoint[element] <= x && x <= xGroupPoint[element + 1]) { |
| 691 |
xGroup = element; |
| 692 |
break; |
| 693 |
} |
| 694 |
} |
| 695 |
if (xGroup < 0) { |
| 696 |
return -1; |
| 697 |
} |
| 698 |
for (int element : grapScanOrder) { |
| 699 |
if (yGroupPoint[element] <= y && y <= yGroupPoint[element + 1]) { |
| 700 |
yGroup = element; |
| 701 |
break; |
| 702 |
} |
| 703 |
} |
| 704 |
if (yGroup < 0) { |
| 705 |
return -1; |
| 706 |
} |
| 707 |
for (int[] element : grapGroupPoints) { |
| 708 |
if (element[0] == xGroup && element[1] == yGroup) { |
| 709 |
return element[2]; |
| 710 |
} |
| 711 |
} |
| 712 |
return -1; |
| 713 |
} |
| 714 |
|
| 448 |
@Override |
715 |
@Override |
| 449 |
public boolean isPageComplete() { |
716 |
public boolean isPageComplete() { |
| 450 |
return workImage != null; |
717 |
return workImage != null; |
|
Lines 455-460
Link Here
|
| 455 |
return isPageComplete(); |
722 |
return isPageComplete(); |
| 456 |
} |
723 |
} |
| 457 |
|
724 |
|
|
|
725 |
private void captureScreenshotContent(Image image) { |
| 726 |
final Display display = getShell().getDisplay(); |
| 727 |
disposeImageResources(); |
| 728 |
originalImage = image; |
| 729 |
Rectangle displayBounds = originalImage.getBounds(); |
| 730 |
workImage = new Image(display, displayBounds.width, displayBounds.height); |
| 731 |
GC gc = new GC(workImage); |
| 732 |
gc.drawImage(originalImage, 0, 0); |
| 733 |
gc.dispose(); |
| 734 |
|
| 735 |
workImageGC = new GC(workImage); |
| 736 |
workImageGC.setLineCap(SWT.CAP_ROUND); |
| 737 |
|
| 738 |
scrolledComposite.setEnabled(true); |
| 739 |
clearSelection(); |
| 740 |
refreshCanvasSize(); |
| 741 |
|
| 742 |
setPageComplete(true); |
| 743 |
} |
| 744 |
|
| 745 |
private void captureScreenshotContentFromSelection() { |
| 746 |
Display display = getShell().getDisplay(); |
| 747 |
|
| 748 |
Image image = new Image(display, currentSelection); |
| 749 |
GC gc = new GC(image); |
| 750 |
gc.drawImage(workImage, currentSelection.x, currentSelection.y, currentSelection.width, |
| 751 |
currentSelection.height, 0, 0, currentSelection.width, currentSelection.height); |
| 752 |
gc.dispose(); |
| 753 |
disposeImageResources(); |
| 754 |
|
| 755 |
originalImage = image; |
| 756 |
Rectangle displayBounds = originalImage.getBounds(); |
| 757 |
workImage = new Image(display, displayBounds.width, displayBounds.height); |
| 758 |
gc = new GC(workImage); |
| 759 |
gc.drawImage(originalImage, 0, 0); |
| 760 |
gc.dispose(); |
| 761 |
|
| 762 |
workImageGC = new GC(workImage); |
| 763 |
workImageGC.setLineCap(SWT.CAP_ROUND); |
| 764 |
|
| 765 |
scrolledComposite.setEnabled(true); |
| 766 |
clearSelection(); |
| 767 |
refreshCanvasSize(); |
| 768 |
|
| 769 |
setPageComplete(true); |
| 770 |
} |
| 771 |
|
| 458 |
private void captureScreenshotContent() { |
772 |
private void captureScreenshotContent() { |
| 459 |
final Display display = getShell().getDisplay(); |
773 |
final Display display = getShell().getDisplay(); |
| 460 |
final Shell wizardShell = getWizard().getContainer().getShell(); |
774 |
final Shell wizardShell = getWizard().getContainer().getShell(); |
|
Lines 476-483
Link Here
|
| 476 |
gc.dispose(); |
790 |
gc.dispose(); |
| 477 |
|
791 |
|
| 478 |
workImageGC = new GC(workImage); |
792 |
workImageGC = new GC(workImage); |
| 479 |
workImageGC.setForeground(markColor); |
|
|
| 480 |
workImageGC.setLineWidth(4); |
| 481 |
workImageGC.setLineCap(SWT.CAP_ROUND); |
793 |
workImageGC.setLineCap(SWT.CAP_ROUND); |
| 482 |
|
794 |
|
| 483 |
scrolledComposite.setEnabled(true); |
795 |
scrolledComposite.setEnabled(true); |
|
Lines 514-547
Link Here
|
| 514 |
currentSelection.intersect(imageBounds); |
826 |
currentSelection.intersect(imageBounds); |
| 515 |
} |
827 |
} |
| 516 |
|
828 |
|
| 517 |
/** |
829 |
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 |
830 |
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 |
|
831 |
|
| 527 |
Rectangle scaledSelection = getScaledSelection(); |
832 |
private static final SelectionSide[][] grabPointResizableSides = { { SelectionSide.LEFT, SelectionSide.TOP }, |
| 528 |
grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x, scaledSelection.y, SWT.CURSOR_SIZENWSE, EnumSet.of( |
833 |
{ SelectionSide.TOP }, { SelectionSide.TOP, SelectionSide.RIGHT }, { SelectionSide.LEFT }, |
| 529 |
SelectionSide.LEFT, SelectionSide.TOP))); |
834 |
{ SelectionSide.RIGHT }, { SelectionSide.LEFT, SelectionSide.BOTTOM }, { SelectionSide.BOTTOM }, |
| 530 |
grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x + scaledSelection.width / 2, scaledSelection.y, |
835 |
{ 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 |
|
836 |
|
| 546 |
private void refreshSelectionResize(int x, int y) { |
837 |
private void refreshSelectionResize(int x, int y) { |
| 547 |
currentSelection = new Rectangle(originalSelection.x, originalSelection.y, originalSelection.width, |
838 |
currentSelection = new Rectangle(originalSelection.x, originalSelection.y, originalSelection.width, |
|
Lines 559-565
Link Here
|
| 559 |
} |
850 |
} |
| 560 |
if (resizableSides.contains(SelectionSide.RIGHT)) { |
851 |
if (resizableSides.contains(SelectionSide.RIGHT)) { |
| 561 |
deltaX = Math.max(deltaX, -originalSelection.width); |
852 |
deltaX = Math.max(deltaX, -originalSelection.width); |
| 562 |
if (originalSelection.x + originalSelection.width + deltaX - 1 > imageBounds.width) { |
853 |
if (originalSelection.x + originalSelection.width + deltaX > imageBounds.width) { |
| 563 |
deltaX = imageBounds.width - (originalSelection.x + originalSelection.width); |
854 |
deltaX = imageBounds.width - (originalSelection.x + originalSelection.width); |
| 564 |
} |
855 |
} |
| 565 |
} |
856 |
} |
|
Lines 571-577
Link Here
|
| 571 |
} |
862 |
} |
| 572 |
if (resizableSides.contains(SelectionSide.BOTTOM)) { |
863 |
if (resizableSides.contains(SelectionSide.BOTTOM)) { |
| 573 |
deltaY = Math.max(deltaY, -originalSelection.height); |
864 |
deltaY = Math.max(deltaY, -originalSelection.height); |
| 574 |
if (originalSelection.y + originalSelection.height + deltaY - 1 > imageBounds.height) { |
865 |
if (originalSelection.y + originalSelection.height + deltaY > imageBounds.height) { |
| 575 |
deltaY = imageBounds.height - (originalSelection.y + originalSelection.height); |
866 |
deltaY = imageBounds.height - (originalSelection.y + originalSelection.height); |
| 576 |
} |
867 |
} |
| 577 |
} |
868 |
} |
|
Lines 591-598
Link Here
|
| 591 |
if (resizableSides.contains(SelectionSide.BOTTOM)) { |
882 |
if (resizableSides.contains(SelectionSide.BOTTOM)) { |
| 592 |
currentSelection.height += deltaY; |
883 |
currentSelection.height += deltaY; |
| 593 |
} |
884 |
} |
| 594 |
|
|
|
| 595 |
setUpGrabPoints(); |
| 596 |
} |
885 |
} |
| 597 |
|
886 |
|
| 598 |
private void refreshSelectionPosition(int x, int y) { |
887 |
private void refreshSelectionPosition(int x, int y) { |
|
Lines 605-619
Link Here
|
| 605 |
newY = 0; |
894 |
newY = 0; |
| 606 |
} |
895 |
} |
| 607 |
Rectangle imageBounds = workImage.getBounds(); |
896 |
Rectangle imageBounds = workImage.getBounds(); |
| 608 |
if (newX + originalSelection.width - 1 > imageBounds.width) { |
897 |
if (newX + originalSelection.width > imageBounds.width) { |
| 609 |
newX = imageBounds.width - originalSelection.width; |
898 |
newX = imageBounds.width - originalSelection.width; |
| 610 |
} |
899 |
} |
| 611 |
if (newY + originalSelection.height - 1 > imageBounds.height) { |
900 |
if (newY + originalSelection.height > imageBounds.height) { |
| 612 |
newY = imageBounds.height - originalSelection.height; |
901 |
newY = imageBounds.height - originalSelection.height; |
| 613 |
} |
902 |
} |
| 614 |
currentSelection = new Rectangle(newX, newY, originalSelection.width, originalSelection.height); |
903 |
currentSelection = new Rectangle(newX, newY, originalSelection.width, originalSelection.height); |
| 615 |
|
|
|
| 616 |
setUpGrabPoints(); |
| 617 |
} |
904 |
} |
| 618 |
|
905 |
|
| 619 |
private void registerMouseListeners() { |
906 |
private void registerMouseListeners() { |
|
Lines 639-650
Link Here
|
| 639 |
boolean cursorSet = false; |
926 |
boolean cursorSet = false; |
| 640 |
|
927 |
|
| 641 |
// No selection in course, but have something selected; first test if I'm hovering some grab point |
928 |
// No selection in course, but have something selected; first test if I'm hovering some grab point |
| 642 |
for (GrabPoint point : grabPoints) { |
929 |
int info = getGrabPoint(e.x, e.y); |
| 643 |
if (point.grabArea.contains(e.x, e.y)) { |
930 |
if (info >= 0) { |
| 644 |
canvas.setCursor(cursors.get(point.cursorType)); |
931 |
canvas.setCursor(cursors.get(grabPointCurosr[info])); |
| 645 |
cursorSet = true; |
932 |
cursorSet = true; |
| 646 |
break; |
|
|
| 647 |
} |
| 648 |
} |
933 |
} |
| 649 |
|
934 |
|
| 650 |
// Test if I'm inside selection, so I can move it |
935 |
// Test if I'm inside selection, so I can move it |
|
Lines 659-664
Link Here
|
| 659 |
canvas.setCursor(crossCursor); |
944 |
canvas.setCursor(crossCursor); |
| 660 |
} |
945 |
} |
| 661 |
} else if (currentAction == EditorAction.MARKING) { |
946 |
} else if (currentAction == EditorAction.MARKING) { |
|
|
947 |
if (startPoint != null) { |
| 948 |
if (drawToolbar.getSelect() == SelectToolAction.DRAW_FREE) { |
| 949 |
int[] history = new int[3]; |
| 950 |
history[0] = SWT.MouseMove; |
| 951 |
history[1] = scaledX; |
| 952 |
history[2] = scaledY; |
| 953 |
historyMouseEvent.add(history); |
| 954 |
} else { |
| 955 |
int[] history = historyMouseEvent.get(historyMouseEvent.size() - 1); |
| 956 |
if (history[0] == SWT.MouseMove) { |
| 957 |
history[1] = scaledX; |
| 958 |
history[2] = scaledY; |
| 959 |
} else { |
| 960 |
history = new int[3]; |
| 961 |
history[0] = SWT.MouseMove; |
| 962 |
history[1] = scaledX; |
| 963 |
history[2] = scaledY; |
| 964 |
historyMouseEvent.add(history); |
| 965 |
} |
| 966 |
} |
| 967 |
} |
| 968 |
|
| 662 |
drawMarkLine(scaledX, scaledY); |
969 |
drawMarkLine(scaledX, scaledY); |
| 663 |
|
970 |
|
| 664 |
Cursor markCursor = cursors.get(CURSOR_MARK_TOOL); |
971 |
Cursor markCursor = cursors.get(CURSOR_MARK_TOOL); |
|
Lines 667-673
Link Here
|
| 667 |
} |
974 |
} |
| 668 |
} |
975 |
} |
| 669 |
} |
976 |
} |
| 670 |
|
|
|
| 671 |
}); |
977 |
}); |
| 672 |
|
978 |
|
| 673 |
canvas.addMouseListener(new MouseAdapter() { |
979 |
canvas.addMouseListener(new MouseAdapter() { |
|
Lines 692-710
Link Here
|
| 692 |
if (currentSelection.width == 0 && currentSelection.height == 0) { |
998 |
if (currentSelection.width == 0 && currentSelection.height == 0) { |
| 693 |
currentSelection = null; |
999 |
currentSelection = null; |
| 694 |
} |
1000 |
} |
| 695 |
setUpGrabPoints(); |
1001 |
|
| 696 |
startPoint = null; |
1002 |
startPoint = null; |
| 697 |
currentAction = EditorAction.CROPPING; |
1003 |
currentAction = EditorAction.CROPPING; |
| 698 |
|
1004 |
|
| 699 |
canvas.redraw(); |
1005 |
canvas.redraw(); |
| 700 |
setImageDirty(true); |
1006 |
setImageDirty(true); |
| 701 |
} else if (currentAction == EditorAction.MARKING) { |
1007 |
} else if (currentAction == EditorAction.MARKING) { |
|
|
1008 |
if (startPoint != null) { |
| 1009 |
if (drawToolbar.getSelect() != SelectToolAction.DRAW_FREE) { |
| 1010 |
if (drawToolbar.getSelect() == SelectToolAction.DRAW_TEXT) { |
| 1011 |
drawAnnotationText(); |
| 1012 |
} |
| 1013 |
previousImage.dispose(); |
| 1014 |
previousImage = null; |
| 1015 |
} |
| 1016 |
|
| 1017 |
int[] history = new int[3]; |
| 1018 |
history[0] = SWT.MouseUp; |
| 1019 |
history[1] = 0; |
| 1020 |
history[2] = 0; |
| 1021 |
historyMouseEvent.add(history); |
| 1022 |
} |
| 1023 |
|
| 702 |
startPoint = null; |
1024 |
startPoint = null; |
| 703 |
setImageDirty(true); |
1025 |
setImageDirty(true); |
| 704 |
} |
1026 |
} |
| 705 |
} |
1027 |
} |
| 706 |
|
1028 |
|
| 707 |
/** |
1029 |
/** |
|
|
1030 |
* Input annotation text and draw text |
| 1031 |
*/ |
| 1032 |
private void drawAnnotationText() { |
| 1033 |
workImageGC.drawImage(previousImage, 0, 0); |
| 1034 |
canvas.redraw(); |
| 1035 |
|
| 1036 |
int[] history = historyMouseEvent.get(historyMouseEvent.size() - 1); |
| 1037 |
if (history[0] != SWT.MouseMove) { |
| 1038 |
historyCheckpoint--; |
| 1039 |
updateAnnotationHistory(); |
| 1040 |
return; |
| 1041 |
} |
| 1042 |
|
| 1043 |
int endedPoint_x, endedPoint_y; |
| 1044 |
if (history[1] < startPoint.x) { |
| 1045 |
endedPoint_x = startPoint.x; |
| 1046 |
startPoint.x = history[1]; |
| 1047 |
} else { |
| 1048 |
endedPoint_x = history[1]; |
| 1049 |
} |
| 1050 |
if (history[2] < startPoint.y) { |
| 1051 |
endedPoint_y = startPoint.y; |
| 1052 |
startPoint.y = history[2]; |
| 1053 |
} else { |
| 1054 |
endedPoint_y = history[2]; |
| 1055 |
} |
| 1056 |
final Rectangle bounds = new Rectangle(startPoint.x, startPoint.y, endedPoint_x - startPoint.x, |
| 1057 |
endedPoint_y - startPoint.y); |
| 1058 |
textArea = new Text(canvas, SWT.MULTI | SWT.WRAP); |
| 1059 |
int xs = (int) Math.round(startPoint.x * scaleFactor); |
| 1060 |
int ys = (int) Math.round(startPoint.y * scaleFactor); |
| 1061 |
int xe = (int) Math.round(endedPoint_x * scaleFactor); |
| 1062 |
int ye = (int) Math.round(endedPoint_y * scaleFactor); |
| 1063 |
textArea.setBounds(new Rectangle(xs, ys, xe - xs, ye - ys)); |
| 1064 |
FontData fontData = new FontData(fontToolbar.getStringCustom()); |
| 1065 |
if (scaleFactor != 1.0) { |
| 1066 |
fontData.setHeight((int) Math.round(fontData.getHeight() * scaleFactor)); |
| 1067 |
} |
| 1068 |
textArea.setFont(new Font(getShell().getDisplay(), fontData)); |
| 1069 |
textArea.setForeground(new Color(getShell().getDisplay(), |
| 1070 |
SelectToolAction.int2rgb(fontToolbar.getIntgerCustom()))); |
| 1071 |
textArea.setTabs(1); |
| 1072 |
Point point = textArea.getCaretLocation(); |
| 1073 |
textArea.setBounds(new Rectangle(xs - point.x, ys, xe - xs + point.x + point.x, ye - ys)); |
| 1074 |
textArea.setFocus(); |
| 1075 |
textArea.addListener(SWT.Deactivate, new Listener() { |
| 1076 |
|
| 1077 |
public void handleEvent(Event event) { |
| 1078 |
String text = textArea.getText(); |
| 1079 |
{ |
| 1080 |
String newtext = ""; //$NON-NLS-1$ |
| 1081 |
int currpos = 0; |
| 1082 |
int charpos = currpos; |
| 1083 |
textArea.setTopIndex(0); |
| 1084 |
textArea.setSelection(currpos); |
| 1085 |
int linepos = textArea.getCaretLineNumber(); |
| 1086 |
boolean remove1st = false; |
| 1087 |
String line; |
| 1088 |
while (currpos < text.length()) { |
| 1089 |
int y = textArea.getCaretLineNumber(); |
| 1090 |
if (linepos != y) { |
| 1091 |
line = text.substring(charpos, currpos); |
| 1092 |
if (line.endsWith("\n")) { //$NON-NLS-1$ |
| 1093 |
line = line.substring(0, line.length() - 1); |
| 1094 |
} |
| 1095 |
newtext = newtext + "\n" + line; //$NON-NLS-1$ |
| 1096 |
remove1st = true; |
| 1097 |
charpos = currpos; |
| 1098 |
linepos = y; |
| 1099 |
} |
| 1100 |
currpos++; |
| 1101 |
textArea.setSelection(currpos); |
| 1102 |
} |
| 1103 |
line = text.substring(charpos, currpos); |
| 1104 |
if (line.endsWith("\n")) { //$NON-NLS-1$ |
| 1105 |
line = line.substring(0, line.length() - 1); |
| 1106 |
} |
| 1107 |
if (line.length() > 0) { |
| 1108 |
newtext = newtext + "\n" + text.substring(charpos, currpos); //$NON-NLS-1$ |
| 1109 |
remove1st = true; |
| 1110 |
} |
| 1111 |
currpos = newtext.indexOf("\r"); //$NON-NLS-1$ |
| 1112 |
while (currpos > 0) { |
| 1113 |
newtext = newtext.substring(0, currpos) + newtext.substring(currpos + 1); |
| 1114 |
currpos = newtext.indexOf("\r"); //$NON-NLS-1$ |
| 1115 |
} |
| 1116 |
newtext = newtext.replace("\t", " "); //$NON-NLS-1$//$NON-NLS-2$ |
| 1117 |
if (remove1st) { |
| 1118 |
newtext = newtext.substring(1); |
| 1119 |
} |
| 1120 |
text = newtext; |
| 1121 |
} |
| 1122 |
|
| 1123 |
textArea.dispose(); |
| 1124 |
textArea = null; |
| 1125 |
|
| 1126 |
if (text.length() > 0) { |
| 1127 |
historyDrawText.get(historyCheckpoint - 1).append(text); |
| 1128 |
Color color = workImageGC.getForeground(); |
| 1129 |
FontData fontData = new FontData(fontToolbar.getStringCustom()); |
| 1130 |
workImageGC.setFont(new Font(getShell().getDisplay(), fontData)); |
| 1131 |
workImageGC.setForeground(new Color(getShell().getDisplay(), |
| 1132 |
SelectToolAction.int2rgb(fontToolbar.getIntgerCustom()))); |
| 1133 |
workImageGC.setClipping(bounds); |
| 1134 |
workImageGC.drawText(text, bounds.x, bounds.y, true); |
| 1135 |
workImageGC.setClipping((Rectangle) null); |
| 1136 |
workImageGC.setForeground(color); |
| 1137 |
} else { |
| 1138 |
historyCheckpoint--; |
| 1139 |
updateAnnotationHistory(); |
| 1140 |
} |
| 1141 |
canvas.redraw(); |
| 1142 |
} |
| 1143 |
}); |
| 1144 |
} |
| 1145 |
|
| 1146 |
/** |
| 708 |
* Pressing mouse button starts a selection or a drawing; normalizes and marks the start point |
1147 |
* Pressing mouse button starts a selection or a drawing; normalizes and marks the start point |
| 709 |
*/ |
1148 |
*/ |
| 710 |
@Override |
1149 |
@Override |
|
Lines 713-718
Link Here
|
| 713 |
int scaledY = (int) (e.y / scaleFactor); |
1152 |
int scaledY = (int) (e.y / scaleFactor); |
| 714 |
|
1153 |
|
| 715 |
if (currentAction == EditorAction.MARKING) { |
1154 |
if (currentAction == EditorAction.MARKING) { |
|
|
1155 |
updateAnnotationHistory(); |
| 1156 |
|
| 1157 |
int toolKind = drawToolbar.getSelect(); |
| 1158 |
int[] history = new int[5]; |
| 1159 |
history[0] = historyMouseEvent.size(); |
| 1160 |
history[1] = drawToolbar.getSelect(); |
| 1161 |
history[2] = (lineToolbar != null) ? lineToolbar.getSelect() : SWT.LINE_DOT; |
| 1162 |
history[3] = (boldToolbar != null) ? boldToolbar.getSelect() : 1; |
| 1163 |
RGB rgb; |
| 1164 |
if (toolKind == SelectToolAction.DRAW_TEXT) { |
| 1165 |
rgb = SelectToolAction.int2rgb(fontToolbar.getIntgerCustom()); |
| 1166 |
} else { |
| 1167 |
rgb = SelectToolAction.int2rgb(colorToolbar.getSelect()); |
| 1168 |
} |
| 1169 |
history[4] = (rgb.red << 16) + (rgb.green << 8) + rgb.blue; |
| 1170 |
historyDrawTool.add(history); |
| 1171 |
historyDrawText.add(new StringBuffer()); |
| 1172 |
if (toolKind == SelectToolAction.DRAW_TEXT) { |
| 1173 |
FontData fontData = new FontData(fontToolbar.getStringCustom()); |
| 1174 |
historyDrawFont.add(fontData.toString()); |
| 1175 |
} else { |
| 1176 |
historyDrawFont.add(""); //$NON-NLS-1$ |
| 1177 |
} |
| 1178 |
historyCheckpoint = historyDrawTool.size(); |
| 1179 |
|
| 1180 |
history = new int[3]; |
| 1181 |
history[0] = SWT.MouseDown; |
| 1182 |
history[1] = scaledX; |
| 1183 |
history[2] = scaledY; |
| 1184 |
historyMouseEvent.add(history); |
| 1185 |
undoAction.setEnabled(true); |
| 1186 |
|
| 1187 |
if (toolKind != SelectToolAction.DRAW_FREE) { |
| 1188 |
Display display = getShell().getDisplay(); |
| 1189 |
previousImage = new Image(display, workImage.getBounds()); |
| 1190 |
GC gc = new GC(previousImage); |
| 1191 |
gc.drawImage(workImage, 0, 0); |
| 1192 |
gc.dispose(); |
| 1193 |
} |
| 1194 |
|
| 1195 |
if (toolKind != SelectToolAction.DRAW_TEXT) { |
| 1196 |
workImageGC.setLineStyle(lineToolbar.getSelect()); |
| 1197 |
workImageGC.setLineWidth(boldToolbar.getSelect()); |
| 1198 |
workImageGC.setForeground(new Color(getShell().getDisplay(), |
| 1199 |
SelectToolAction.int2rgb(colorToolbar.getSelect()))); |
| 1200 |
} else { |
| 1201 |
workImageGC.setLineStyle(SWT.LINE_DOT); |
| 1202 |
workImageGC.setLineWidth(1); |
| 1203 |
workImageGC.setForeground(new Color(getShell().getDisplay(), 0, 0, 0)); |
| 1204 |
} |
| 1205 |
|
| 716 |
startPoint = new Point(scaledX, scaledY); |
1206 |
startPoint = new Point(scaledX, scaledY); |
| 717 |
drawMarkLine(scaledX, scaledY); |
1207 |
drawMarkLine(scaledX, scaledY); |
| 718 |
canvas.setCursor(cursors.get(CURSOR_MARK_TOOL)); |
1208 |
canvas.setCursor(cursors.get(CURSOR_MARK_TOOL)); |
|
Lines 723-737
Link Here
|
| 723 |
|
1213 |
|
| 724 |
// Check the most appropriate action to follow; first check if I'm on some grab point |
1214 |
// Check the most appropriate action to follow; first check if I'm on some grab point |
| 725 |
if (currentSelection != null) { |
1215 |
if (currentSelection != null) { |
| 726 |
for (GrabPoint point : grabPoints) { |
1216 |
int info = getGrabPoint(e.x, e.y); |
| 727 |
if (point.grabArea.contains(e.x, e.y)) { |
1217 |
if (info >= 0) { |
| 728 |
originalSelection = currentSelection; |
1218 |
originalSelection = currentSelection; |
| 729 |
currentAction = EditorAction.RESIZING_SELECTION; |
1219 |
currentAction = EditorAction.RESIZING_SELECTION; |
| 730 |
resizableSides = point.resizableSides; |
1220 |
resizableSides = new HashSet<SelectionSide>(); |
| 731 |
startPoint = new Point(scaledX, scaledY); |
1221 |
for (SelectionSide side : grabPointResizableSides[info]) { |
| 732 |
canvas.redraw(); |
1222 |
resizableSides.add(side); |
| 733 |
return; |
|
|
| 734 |
} |
1223 |
} |
|
|
1224 |
startPoint = new Point(scaledX, scaledY); |
| 1225 |
canvas.redraw(); |
| 1226 |
return; |
| 735 |
} |
1227 |
} |
| 736 |
} |
1228 |
} |
| 737 |
|
1229 |
|
|
Lines 749-760
Link Here
|
| 749 |
currentAction = EditorAction.SELECTING; |
1241 |
currentAction = EditorAction.SELECTING; |
| 750 |
currentSelection = null; |
1242 |
currentSelection = null; |
| 751 |
startPoint = new Point(scaledX, scaledY); |
1243 |
startPoint = new Point(scaledX, scaledY); |
| 752 |
setUpGrabPoints(); |
1244 |
|
| 753 |
canvas.redraw(); |
1245 |
canvas.redraw(); |
| 754 |
} |
1246 |
} |
| 755 |
|
|
|
| 756 |
}); |
1247 |
}); |
| 757 |
|
|
|
| 758 |
} |
1248 |
} |
| 759 |
|
1249 |
|
| 760 |
private void clearSelection() { |
1250 |
private void clearSelection() { |
|
Lines 779-785
Link Here
|
| 779 |
* Calling this method under other circumstances may lead to strange behavior in the scrolled composite |
1269 |
* Calling this method under other circumstances may lead to strange behavior in the scrolled composite |
| 780 |
*/ |
1270 |
*/ |
| 781 |
private void refreshCanvasSize() { |
1271 |
private void refreshCanvasSize() { |
| 782 |
if (fitAction.isChecked()) { |
1272 |
if (fitAction.getSelect() == SelectToolAction.ZOOM_FIT) { |
| 783 |
// This little hack is necessary to get the client area without scrollbars; |
1273 |
// This little hack is necessary to get the client area without scrollbars; |
| 784 |
// they'll be automatically restored if necessary after Canvas.setBounds() |
1274 |
// they'll be automatically restored if necessary after Canvas.setBounds() |
| 785 |
scrolledComposite.getHorizontalBar().setVisible(false); |
1275 |
scrolledComposite.getHorizontalBar().setVisible(false); |
|
Lines 798-813
Link Here
|
| 798 |
} |
1288 |
} |
| 799 |
canvas.setBounds(bounds); |
1289 |
canvas.setBounds(bounds); |
| 800 |
} else { |
1290 |
} else { |
| 801 |
scaleFactor = 1.0; |
1291 |
scaleFactor = fitAction.getSelect(); // 50, 100, 200, 400 or 800 |
|
|
1292 |
scaleFactor = scaleFactor / 100; |
| 802 |
Rectangle bounds = scrolledComposite.getClientArea(); |
1293 |
Rectangle bounds = scrolledComposite.getClientArea(); |
| 803 |
if (workImage != null) { |
1294 |
if (workImage != null) { |
| 804 |
Rectangle imageBounds = workImage.getBounds(); |
1295 |
Rectangle imageBounds = workImage.getBounds(); |
| 805 |
bounds.width = imageBounds.width; |
1296 |
bounds.width = (int) Math.round(imageBounds.width * scaleFactor); |
| 806 |
bounds.height = imageBounds.height; |
1297 |
bounds.height = (int) Math.round(imageBounds.height * scaleFactor); |
| 807 |
} |
1298 |
} |
| 808 |
canvas.setBounds(bounds); |
1299 |
canvas.setBounds(bounds); |
| 809 |
} |
1300 |
} |
| 810 |
setUpGrabPoints(); |
1301 |
|
|
|
1302 |
canvas.redraw(); |
| 1303 |
} |
| 1304 |
|
| 1305 |
private void updateAnnotationHistory() { |
| 1306 |
int[] history; |
| 1307 |
if (historyCheckpoint < historyDrawTool.size()) { |
| 1308 |
history = historyDrawTool.get(historyCheckpoint); |
| 1309 |
while (history[0] < historyMouseEvent.size()) { |
| 1310 |
historyMouseEvent.remove(historyMouseEvent.size() - 1); |
| 1311 |
} |
| 1312 |
while (historyCheckpoint < historyDrawTool.size()) { |
| 1313 |
historyDrawTool.remove(historyDrawTool.size() - 1); |
| 1314 |
} |
| 1315 |
while (historyCheckpoint < historyDrawText.size()) { |
| 1316 |
historyDrawText.remove(historyDrawText.size() - 1); |
| 1317 |
} |
| 1318 |
while (historyCheckpoint < historyDrawFont.size()) { |
| 1319 |
historyDrawFont.remove(historyDrawFont.size() - 1); |
| 1320 |
} |
| 1321 |
redoAction.setEnabled(false); |
| 1322 |
} |
| 1323 |
|
| 1324 |
undoAction.setEnabled(historyCheckpoint > 0); |
| 1325 |
} |
| 1326 |
|
| 1327 |
/** |
| 1328 |
* Draw Annotation with history |
| 1329 |
*/ |
| 1330 |
private void drawAnnotationHistory() { |
| 1331 |
workImageGC.drawImage(originalImage, 0, 0); |
| 1332 |
Color backBackground = workImageGC.getBackground(); |
| 1333 |
Color backForeground = workImageGC.getForeground(); |
| 1334 |
int backLineStyle = workImageGC.getLineStyle(); |
| 1335 |
int backLineWidth = workImageGC.getLineWidth(); |
| 1336 |
int[] history; |
| 1337 |
for (int c = 0; c < historyCheckpoint; c++) { |
| 1338 |
history = historyDrawTool.get(c); |
| 1339 |
int toolKind = history[1]; |
| 1340 |
int boldlKind = history[3]; |
| 1341 |
workImageGC.setLineStyle(history[2]); |
| 1342 |
workImageGC.setLineWidth(boldlKind); |
| 1343 |
workImageGC.setForeground(new Color(getShell().getDisplay(), // |
| 1344 |
history[4] >> 16, // |
| 1345 |
(history[4] >> 8) & 0x00ff, // |
| 1346 |
history[4] & 0x00ff)); |
| 1347 |
|
| 1348 |
int h = history[0]; |
| 1349 |
history = historyMouseEvent.get(h); |
| 1350 |
int start_x = history[1]; |
| 1351 |
int start_y = history[2]; |
| 1352 |
for (h++; h < historyMouseEvent.size(); h++) { |
| 1353 |
history = historyMouseEvent.get(h); |
| 1354 |
if (history[0] == SWT.MouseUp) { |
| 1355 |
break; |
| 1356 |
} |
| 1357 |
int x = history[1]; |
| 1358 |
int y = history[2]; |
| 1359 |
if (toolKind == SelectToolAction.DRAW_FREE) { |
| 1360 |
workImageGC.drawLine(start_x, start_y, x, y); |
| 1361 |
start_x = x; |
| 1362 |
start_y = y; |
| 1363 |
} else { |
| 1364 |
if (start_x == x && start_y == y) { |
| 1365 |
workImageGC.drawLine(start_x, start_y, x, y); |
| 1366 |
} else { |
| 1367 |
int rounded; |
| 1368 |
int width = x - start_x; |
| 1369 |
int height = y - start_y; |
| 1370 |
switch (toolKind) { |
| 1371 |
case SelectToolAction.DRAW_LINE: |
| 1372 |
workImageGC.drawLine(start_x, start_y, x, y); |
| 1373 |
break; |
| 1374 |
case SelectToolAction.DRAW_ARROW1: |
| 1375 |
workImageGC.setBackground(workImageGC.getForeground()); |
| 1376 |
drawArrowLine(start_x, start_y, x, y, false); |
| 1377 |
break; |
| 1378 |
case SelectToolAction.DRAW_ARROW2: |
| 1379 |
workImageGC.setBackground(workImageGC.getForeground()); |
| 1380 |
drawArrowLine(start_x, start_y, x, y, true); |
| 1381 |
break; |
| 1382 |
case SelectToolAction.DRAW_BOX: |
| 1383 |
workImageGC.drawRectangle(start_x, start_y, width, height); |
| 1384 |
break; |
| 1385 |
case SelectToolAction.DRAW_RBOX: |
| 1386 |
rounded = boldlKind * 8; |
| 1387 |
workImageGC.drawRoundRectangle(start_x, start_y, width, height, rounded, rounded); |
| 1388 |
break; |
| 1389 |
case SelectToolAction.DRAW_OVAL: |
| 1390 |
workImageGC.drawOval(start_x, start_y, width, height); |
| 1391 |
break; |
| 1392 |
case SelectToolAction.DRAW_FILL_BOX: |
| 1393 |
workImageGC.setBackground(workImageGC.getForeground()); |
| 1394 |
workImageGC.fillRectangle(start_x, start_y, width, height); |
| 1395 |
break; |
| 1396 |
case SelectToolAction.DRAW_FILL_RBOX: |
| 1397 |
rounded = boldlKind * 8; |
| 1398 |
workImageGC.setBackground(workImageGC.getForeground()); |
| 1399 |
workImageGC.fillRoundRectangle(start_x, start_y, width, height, rounded, rounded); |
| 1400 |
break; |
| 1401 |
case SelectToolAction.DRAW_FILL_OVAL: |
| 1402 |
workImageGC.setBackground(workImageGC.getForeground()); |
| 1403 |
workImageGC.fillOval(start_x, start_y, width, height); |
| 1404 |
break; |
| 1405 |
case SelectToolAction.DRAW_TEXT: |
| 1406 |
StringBuffer text = historyDrawText.get(c); |
| 1407 |
{ |
| 1408 |
Font backFont = workImageGC.getFont(); |
| 1409 |
FontData fontData = new FontData(historyDrawFont.get(c)); |
| 1410 |
workImageGC.setFont(new Font(getShell().getDisplay(), fontData)); |
| 1411 |
workImageGC.setClipping(start_x, start_y, width, height); |
| 1412 |
workImageGC.drawText(text.toString(), start_x, start_y, true); |
| 1413 |
workImageGC.setClipping((Rectangle) null); |
| 1414 |
workImageGC.setFont(backFont); |
| 1415 |
} |
| 1416 |
break; |
| 1417 |
} |
| 1418 |
} |
| 1419 |
} |
| 1420 |
} |
| 1421 |
} |
| 1422 |
workImageGC.setBackground(backBackground); |
| 1423 |
workImageGC.setForeground(backForeground); |
| 1424 |
workImageGC.setLineStyle(backLineStyle); |
| 1425 |
workImageGC.setLineWidth(backLineWidth); |
| 1426 |
|
| 811 |
canvas.redraw(); |
1427 |
canvas.redraw(); |
| 812 |
} |
1428 |
} |
| 813 |
|
1429 |
|
|
Lines 818-824
Link Here
|
| 818 |
if (currentSelection == null) { |
1434 |
if (currentSelection == null) { |
| 819 |
return; |
1435 |
return; |
| 820 |
} |
1436 |
} |
| 821 |
Rectangle scaledSelection = getScaledSelection(); |
1437 |
Rectangle inside = getScaledSelection(); |
| 822 |
|
1438 |
|
| 823 |
// Draw shadow |
1439 |
// Draw shadow |
| 824 |
gc.setBackground(CommonColors.GRAY_MID); |
1440 |
gc.setBackground(CommonColors.GRAY_MID); |
|
Lines 827-833
Link Here
|
| 827 |
|
1443 |
|
| 828 |
Region invertedSelection = new Region(); |
1444 |
Region invertedSelection = new Region(); |
| 829 |
invertedSelection.add(canvas.getClientArea()); |
1445 |
invertedSelection.add(canvas.getClientArea()); |
| 830 |
invertedSelection.subtract(scaledSelection); |
1446 |
invertedSelection.subtract(inside); |
| 831 |
gc.setClipping(invertedSelection); |
1447 |
gc.setClipping(invertedSelection); |
| 832 |
gc.fillRectangle(canvas.getClientArea()); |
1448 |
gc.fillRectangle(canvas.getClientArea()); |
| 833 |
gc.setClipping((Region) null); |
1449 |
gc.setClipping((Region) null); |
|
Lines 838-867
Link Here
|
| 838 |
// Draw selection rectangle |
1454 |
// Draw selection rectangle |
| 839 |
gc.setLineStyle(SWT.LINE_SOLID); |
1455 |
gc.setLineStyle(SWT.LINE_SOLID); |
| 840 |
gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); |
1456 |
gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); |
| 841 |
gc.drawRectangle(scaledSelection); |
1457 |
gc.drawRectangle(inside); |
| 842 |
|
1458 |
|
| 843 |
// Draw grab points |
1459 |
// // Draw grab points |
| 844 |
gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE)); |
1460 |
// gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE)); |
| 845 |
gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK)); |
1461 |
// gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK)); |
| 846 |
for (GrabPoint point : grabPoints) { |
1462 |
// for (GrabPoint point : grabPoints) { |
| 847 |
gc.fillRectangle(point.grabArea); |
1463 |
// gc.fillRectangle(point.grabArea); |
| 848 |
gc.drawRectangle(point.grabArea); |
1464 |
// gc.drawRectangle(point.grabArea); |
| 849 |
} |
1465 |
// } |
|
|
1466 |
gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); |
| 1467 |
Rectangle outside = getOutsideSelection(inside); |
| 1468 |
gc.drawRectangle(outside); |
| 1469 |
gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); |
| 1470 |
gc.fillRectangle(outside.x, outside.y, // |
| 1471 |
SQUARE_SIZE * 6, SQUARE_SIZE * 2); |
| 1472 |
gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 6, outside.y, // |
| 1473 |
SQUARE_SIZE * 6, SQUARE_SIZE * 2); |
| 1474 |
gc.fillRectangle(outside.x, outside.y, // |
| 1475 |
SQUARE_SIZE * 2, SQUARE_SIZE * 6); |
| 1476 |
gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 2, outside.y, // |
| 1477 |
SQUARE_SIZE * 2, SQUARE_SIZE * 6); |
| 1478 |
gc.fillRectangle(outside.x, outside.y + outside.height - SQUARE_SIZE * 6, // |
| 1479 |
SQUARE_SIZE * 2, SQUARE_SIZE * 6); |
| 1480 |
gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 2, outside.y + outside.height - SQUARE_SIZE * 6, // |
| 1481 |
SQUARE_SIZE * 2, SQUARE_SIZE * 6); |
| 1482 |
gc.fillRectangle(outside.x, outside.y + outside.height - SQUARE_SIZE * 2, // |
| 1483 |
SQUARE_SIZE * 6, SQUARE_SIZE * 2); |
| 1484 |
gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 6, outside.y + outside.height - SQUARE_SIZE * 2, // |
| 1485 |
SQUARE_SIZE * 6, SQUARE_SIZE * 2); |
| 850 |
} |
1486 |
} |
| 851 |
|
1487 |
|
| 852 |
/** |
1488 |
/** |
| 853 |
* Connects the previous mark point to the new reference point, by drawing a new line |
1489 |
* Connects the previous mark point to the new reference point, by drawing a new line, rectangle or oval |
| 854 |
*/ |
1490 |
*/ |
| 855 |
private void drawMarkLine(int x, int y) { |
1491 |
private void drawMarkLine(int x, int y) { |
| 856 |
if (startPoint != null) { |
1492 |
if (startPoint != null) { |
| 857 |
clearAction.setEnabled(true); |
1493 |
clearAction.setEnabled(true); |
| 858 |
workImageGC.drawLine(startPoint.x, startPoint.y, x, y); |
1494 |
if (drawToolbar.getSelect() == SelectToolAction.DRAW_FREE) { |
| 859 |
startPoint.x = x; |
1495 |
workImageGC.drawLine(startPoint.x, startPoint.y, x, y); |
| 860 |
startPoint.y = y; |
1496 |
startPoint.x = x; |
|
|
1497 |
startPoint.y = y; |
| 1498 |
} else { |
| 1499 |
workImageGC.drawImage(previousImage, 0, 0); |
| 1500 |
if (startPoint.x == x && startPoint.y == y) { |
| 1501 |
workImageGC.drawLine(startPoint.x, startPoint.y, x, y); |
| 1502 |
} else { |
| 1503 |
Color backColor; |
| 1504 |
Color markColor; |
| 1505 |
int rounded; |
| 1506 |
int width = x - startPoint.x; |
| 1507 |
int height = y - startPoint.y; |
| 1508 |
switch (drawToolbar.getSelect()) { |
| 1509 |
case SelectToolAction.DRAW_LINE: |
| 1510 |
workImageGC.drawLine(startPoint.x, startPoint.y, x, y); |
| 1511 |
break; |
| 1512 |
case SelectToolAction.DRAW_ARROW1: |
| 1513 |
backColor = workImageGC.getBackground(); |
| 1514 |
markColor = new Color(getShell().getDisplay(), |
| 1515 |
SelectToolAction.int2rgb(colorToolbar.getSelect())); |
| 1516 |
workImageGC.setBackground(markColor); |
| 1517 |
drawArrowLine(startPoint.x, startPoint.y, x, y, false); |
| 1518 |
workImageGC.setBackground(backColor); |
| 1519 |
break; |
| 1520 |
case SelectToolAction.DRAW_ARROW2: |
| 1521 |
backColor = workImageGC.getBackground(); |
| 1522 |
markColor = new Color(getShell().getDisplay(), |
| 1523 |
SelectToolAction.int2rgb(colorToolbar.getSelect())); |
| 1524 |
workImageGC.setBackground(markColor); |
| 1525 |
drawArrowLine(startPoint.x, startPoint.y, x, y, true); |
| 1526 |
workImageGC.setBackground(backColor); |
| 1527 |
break; |
| 1528 |
case SelectToolAction.DRAW_BOX: |
| 1529 |
workImageGC.drawRectangle(startPoint.x, startPoint.y, width, height); |
| 1530 |
break; |
| 1531 |
case SelectToolAction.DRAW_RBOX: |
| 1532 |
rounded = boldToolbar.getSelect() * 8; |
| 1533 |
workImageGC.drawRoundRectangle(startPoint.x, startPoint.y, width, height, rounded, rounded); |
| 1534 |
break; |
| 1535 |
case SelectToolAction.DRAW_OVAL: |
| 1536 |
workImageGC.drawOval(startPoint.x, startPoint.y, width, height); |
| 1537 |
break; |
| 1538 |
case SelectToolAction.DRAW_FILL_BOX: |
| 1539 |
backColor = workImageGC.getBackground(); |
| 1540 |
markColor = new Color(getShell().getDisplay(), |
| 1541 |
SelectToolAction.int2rgb(colorToolbar.getSelect())); |
| 1542 |
workImageGC.setBackground(markColor); |
| 1543 |
workImageGC.fillRectangle(startPoint.x, startPoint.y, width, height); |
| 1544 |
workImageGC.setBackground(backColor); |
| 1545 |
break; |
| 1546 |
case SelectToolAction.DRAW_FILL_RBOX: |
| 1547 |
rounded = boldToolbar.getSelect() * 8; |
| 1548 |
backColor = workImageGC.getBackground(); |
| 1549 |
markColor = new Color(getShell().getDisplay(), |
| 1550 |
SelectToolAction.int2rgb(colorToolbar.getSelect())); |
| 1551 |
workImageGC.setBackground(markColor); |
| 1552 |
workImageGC.fillRoundRectangle(startPoint.x, startPoint.y, width, height, rounded, rounded); |
| 1553 |
workImageGC.setBackground(backColor); |
| 1554 |
break; |
| 1555 |
case SelectToolAction.DRAW_FILL_OVAL: |
| 1556 |
backColor = workImageGC.getBackground(); |
| 1557 |
markColor = new Color(getShell().getDisplay(), |
| 1558 |
SelectToolAction.int2rgb(colorToolbar.getSelect())); |
| 1559 |
workImageGC.setBackground(markColor); |
| 1560 |
workImageGC.fillOval(startPoint.x, startPoint.y, width, height); |
| 1561 |
workImageGC.setBackground(backColor); |
| 1562 |
break; |
| 1563 |
case SelectToolAction.DRAW_TEXT: |
| 1564 |
workImageGC.fillRectangle(startPoint.x, startPoint.y, width, height); |
| 1565 |
workImageGC.drawRectangle(startPoint.x, startPoint.y, width, height); |
| 1566 |
break; |
| 1567 |
} |
| 1568 |
} |
| 1569 |
} |
| 861 |
canvas.redraw(); |
1570 |
canvas.redraw(); |
| 862 |
} |
1571 |
} |
| 863 |
} |
1572 |
} |
| 864 |
|
1573 |
|
|
|
1574 |
public void drawArrowLine(int xs, int ys, int xe, int ye, boolean bothsides) { |
| 1575 |
int width = xe - xs, height = ye - ys; |
| 1576 |
int bold = workImageGC.getLineWidth(); |
| 1577 |
int leng = (bold == 8) ? bold * 4 : (bold == 4) ? bold * 6 : (bold == 2) ? bold * 8 : bold * 10; |
| 1578 |
double delta = Math.PI / 6.0; |
| 1579 |
double theta = Math.atan2(height, width); |
| 1580 |
|
| 1581 |
// Draw line |
| 1582 |
if (bothsides) { |
| 1583 |
workImageGC.drawLine( // |
| 1584 |
xs + (int) (leng / 2 * Math.cos(theta)), // |
| 1585 |
ys + (int) (leng / 2 * Math.sin(theta)), // |
| 1586 |
xe - (int) (leng / 2 * Math.cos(theta)), // |
| 1587 |
ye - (int) (leng / 2 * Math.sin(theta))); |
| 1588 |
} else { |
| 1589 |
workImageGC.drawLine( // |
| 1590 |
xs, // |
| 1591 |
ys, // |
| 1592 |
xe - (int) (leng / 2 * Math.cos(theta)), // |
| 1593 |
ye - (int) (leng / 2 * Math.sin(theta))); |
| 1594 |
} |
| 1595 |
|
| 1596 |
// Draw ending side arrow |
| 1597 |
workImageGC.setLineWidth(1); |
| 1598 |
|
| 1599 |
int[] point = { xe, ye, // |
| 1600 |
xe - (int) (leng * Math.cos(theta - delta)), // |
| 1601 |
ye - (int) (leng * Math.sin(theta - delta)), // |
| 1602 |
xe - (int) (leng * Math.cos(theta + delta)), // |
| 1603 |
ye - (int) (leng * Math.sin(theta + delta)) }; |
| 1604 |
workImageGC.fillPolygon(point); |
| 1605 |
|
| 1606 |
// Draw starting side arrow |
| 1607 |
if (bothsides) { |
| 1608 |
int[] point2 = { xs, ys, // |
| 1609 |
xs + (int) (leng * Math.cos(theta - delta)), // |
| 1610 |
ys + (int) (leng * Math.sin(theta - delta)), // |
| 1611 |
xs + (int) (leng * Math.cos(theta + delta)), // |
| 1612 |
ys + (int) (leng * Math.sin(theta + delta)) }; |
| 1613 |
workImageGC.fillPolygon(point2); |
| 1614 |
} |
| 1615 |
|
| 1616 |
workImageGC.setLineWidth(bold); |
| 1617 |
} |
| 1618 |
|
| 865 |
private static enum SelectionSide { |
1619 |
private static enum SelectionSide { |
| 866 |
|
1620 |
|
| 867 |
LEFT, RIGHT, TOP, BOTTOM; |
1621 |
LEFT, RIGHT, TOP, BOTTOM; |
|
Lines 870-895
Link Here
|
| 870 |
|
1624 |
|
| 871 |
private static final int SQUARE_SIZE = 3; |
1625 |
private static final int SQUARE_SIZE = 3; |
| 872 |
|
1626 |
|
| 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 |
/** |
1627 |
/** |
| 894 |
* Creates the final screenshot |
1628 |
* Creates the final screenshot |
| 895 |
* |
1629 |
* |