|
Lines 23-42
Link Here
|
| 23 |
import org.eclipse.core.runtime.IProgressMonitor; |
23 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 24 |
import org.eclipse.core.runtime.IStatus; |
24 |
import org.eclipse.core.runtime.IStatus; |
| 25 |
import org.eclipse.core.runtime.Status; |
25 |
import org.eclipse.core.runtime.Status; |
| 26 |
import org.eclipse.jface.action.Action; |
|
|
| 27 |
import org.eclipse.jface.action.ActionContributionItem; |
| 28 |
import org.eclipse.jface.action.IAction; |
| 29 |
import org.eclipse.jface.action.Separator; |
| 30 |
import org.eclipse.jface.action.ToolBarManager; |
| 31 |
import org.eclipse.jface.dialogs.Dialog; |
26 |
import org.eclipse.jface.dialogs.Dialog; |
| 32 |
import org.eclipse.jface.layout.GridDataFactory; |
27 |
import org.eclipse.jface.layout.GridDataFactory; |
| 33 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
|
| 34 |
import org.eclipse.jface.wizard.WizardPage; |
28 |
import org.eclipse.jface.wizard.WizardPage; |
| 35 |
import org.eclipse.mylyn.internal.commons.ui.ColorSelectionWindow; |
|
|
| 36 |
import org.eclipse.mylyn.internal.commons.ui.Messages; |
29 |
import org.eclipse.mylyn.internal.commons.ui.Messages; |
| 37 |
import org.eclipse.swt.SWT; |
30 |
import org.eclipse.swt.SWT; |
| 38 |
import org.eclipse.swt.custom.ScrolledComposite; |
31 |
import org.eclipse.swt.custom.ScrolledComposite; |
| 39 |
import org.eclipse.swt.custom.ViewForm; |
|
|
| 40 |
import org.eclipse.swt.events.ControlAdapter; |
32 |
import org.eclipse.swt.events.ControlAdapter; |
| 41 |
import org.eclipse.swt.events.ControlEvent; |
33 |
import org.eclipse.swt.events.ControlEvent; |
| 42 |
import org.eclipse.swt.events.MouseAdapter; |
34 |
import org.eclipse.swt.events.MouseAdapter; |
|
Lines 46-63
Link Here
|
| 46 |
import org.eclipse.swt.events.PaintListener; |
38 |
import org.eclipse.swt.events.PaintListener; |
| 47 |
import org.eclipse.swt.graphics.Color; |
39 |
import org.eclipse.swt.graphics.Color; |
| 48 |
import org.eclipse.swt.graphics.Cursor; |
40 |
import org.eclipse.swt.graphics.Cursor; |
|
|
41 |
import org.eclipse.swt.graphics.Font; |
| 42 |
import org.eclipse.swt.graphics.FontData; |
| 49 |
import org.eclipse.swt.graphics.GC; |
43 |
import org.eclipse.swt.graphics.GC; |
| 50 |
import org.eclipse.swt.graphics.Image; |
44 |
import org.eclipse.swt.graphics.Image; |
| 51 |
import org.eclipse.swt.graphics.Point; |
45 |
import org.eclipse.swt.graphics.Point; |
| 52 |
import org.eclipse.swt.graphics.RGB; |
46 |
import org.eclipse.swt.graphics.RGB; |
| 53 |
import org.eclipse.swt.graphics.Rectangle; |
47 |
import org.eclipse.swt.graphics.Rectangle; |
| 54 |
import org.eclipse.swt.graphics.Region; |
48 |
import org.eclipse.swt.graphics.Region; |
|
|
49 |
import org.eclipse.swt.layout.GridData; |
| 50 |
import org.eclipse.swt.layout.GridLayout; |
| 55 |
import org.eclipse.swt.widgets.Canvas; |
51 |
import org.eclipse.swt.widgets.Canvas; |
| 56 |
import org.eclipse.swt.widgets.Composite; |
52 |
import org.eclipse.swt.widgets.Composite; |
| 57 |
import org.eclipse.swt.widgets.Display; |
53 |
import org.eclipse.swt.widgets.Display; |
| 58 |
import org.eclipse.swt.widgets.Event; |
54 |
import org.eclipse.swt.widgets.Event; |
|
|
55 |
import org.eclipse.swt.widgets.Listener; |
| 59 |
import org.eclipse.swt.widgets.Shell; |
56 |
import org.eclipse.swt.widgets.Shell; |
| 60 |
import org.eclipse.swt.widgets.ToolItem; |
57 |
import org.eclipse.swt.widgets.Text; |
| 61 |
import org.eclipse.ui.progress.UIJob; |
58 |
import org.eclipse.ui.progress.UIJob; |
| 62 |
|
59 |
|
| 63 |
/** |
60 |
/** |
|
Lines 71-92
Link Here
|
| 71 |
*/ |
68 |
*/ |
| 72 |
public class ScreenshotCreationPage extends WizardPage implements IImageCreator { |
69 |
public class ScreenshotCreationPage extends WizardPage implements IImageCreator { |
| 73 |
|
70 |
|
| 74 |
private IAction captureAction; |
71 |
private ScreenshotToolbar toolbar; |
| 75 |
|
72 |
|
| 76 |
private IAction fitAction; |
73 |
private Font markFont; |
| 77 |
|
74 |
|
| 78 |
private IAction cropAction; |
75 |
private Color markFontColor; |
| 79 |
|
|
|
| 80 |
private IAction markAction; |
| 81 |
|
| 82 |
private IAction colorAction; |
| 83 |
|
| 84 |
private Image colorIcon; |
| 85 |
|
76 |
|
| 86 |
private Color markColor; |
77 |
private Color markColor; |
| 87 |
|
78 |
|
| 88 |
private IAction clearAction; |
|
|
| 89 |
|
| 90 |
private boolean imageDirty; |
79 |
private boolean imageDirty; |
| 91 |
|
80 |
|
| 92 |
/** |
81 |
/** |
|
Lines 99-104
Link Here
|
| 99 |
*/ |
88 |
*/ |
| 100 |
private Image workImage; |
89 |
private Image workImage; |
| 101 |
|
90 |
|
|
|
91 |
private Image previousImage; |
| 92 |
|
| 102 |
/** |
93 |
/** |
| 103 |
* Used to draw into {@link #workImage} |
94 |
* Used to draw into {@link #workImage} |
| 104 |
*/ |
95 |
*/ |
|
Lines 145-153
Link Here
|
| 145 |
* Available actions for the screenshot editor |
136 |
* Available actions for the screenshot editor |
| 146 |
*/ |
137 |
*/ |
| 147 |
private static enum EditorAction { |
138 |
private static enum EditorAction { |
| 148 |
|
|
|
| 149 |
CROPPING, SELECTING, RESIZING_SELECTION, MOVING_SELECTION, MARKING; |
139 |
CROPPING, SELECTING, RESIZING_SELECTION, MOVING_SELECTION, MARKING; |
| 150 |
|
|
|
| 151 |
}; |
140 |
}; |
| 152 |
|
141 |
|
| 153 |
/** |
142 |
/** |
|
Lines 155-160
Link Here
|
| 155 |
*/ |
144 |
*/ |
| 156 |
private EditorAction currentAction = EditorAction.CROPPING; |
145 |
private EditorAction currentAction = EditorAction.CROPPING; |
| 157 |
|
146 |
|
|
|
147 |
private boolean isFirstCapture = true; |
| 148 |
|
| 149 |
/** |
| 150 |
* Mouse event history. |
| 151 |
* |
| 152 |
* [0] MouseDown/MouseMove/MouseUp, [1] x, [2] y |
| 153 |
*/ |
| 154 |
private List<int[]> historyMouseEvent = new ArrayList<int[]>(); |
| 155 |
|
| 156 |
/** |
| 157 |
* Draw tool history. |
| 158 |
* |
| 159 |
* [0] drawHistory index, [1] TEXT/FREE/LINE/..., [2] Line type, [3] Bold, [4] R/G/B |
| 160 |
*/ |
| 161 |
private List<int[]> historyDrawTool = new ArrayList<int[]>(); |
| 162 |
|
| 163 |
private List<String> historyDrawFont = new ArrayList<String>(); |
| 164 |
|
| 165 |
private int historyCheckpoint = 0; |
| 166 |
|
| 167 |
private Text textArea; |
| 168 |
|
| 169 |
private List<StringBuffer> historyDrawText = new ArrayList<StringBuffer>(); |
| 170 |
|
| 158 |
public ScreenshotCreationPage() { |
171 |
public ScreenshotCreationPage() { |
| 159 |
super("ScreenShotAttachment"); //$NON-NLS-1$ |
172 |
super("ScreenShotAttachment"); //$NON-NLS-1$ |
| 160 |
setTitle(Messages.ScreenshotCreationPage_CAPTURE_SCRRENSHOT); |
173 |
setTitle(Messages.ScreenshotCreationPage_CAPTURE_SCRRENSHOT); |
|
Lines 163-326
Link Here
|
| 163 |
} |
176 |
} |
| 164 |
|
177 |
|
| 165 |
public void createControl(Composite parent) { |
178 |
public void createControl(Composite parent) { |
| 166 |
ViewForm vf = new ViewForm(parent, SWT.BORDER | SWT.FLAT); |
179 |
Composite vf = new Composite(parent, SWT.NONE); |
| 167 |
vf.horizontalSpacing = 0; |
|
|
| 168 |
vf.verticalSpacing = 0; |
| 169 |
setControl(vf); |
180 |
setControl(vf); |
| 170 |
vf.setLayoutData(GridDataFactory.fillDefaults().create()); |
181 |
vf.setLayoutData(GridDataFactory.fillDefaults().create()); |
|
|
182 |
GridLayout layout = new GridLayout(2, false); |
| 183 |
layout.marginWidth = 0; |
| 184 |
layout.marginHeight = 0; |
| 185 |
layout.verticalSpacing = 0; |
| 186 |
layout.horizontalSpacing = 2; |
| 187 |
vf.setLayout(layout); |
| 171 |
|
188 |
|
| 172 |
allocateCursors(); |
189 |
toolbar = new ScreenshotToolbar(vf, SWT.BORDER) { |
| 173 |
|
|
|
| 174 |
// TODO: need disabled versions of all toolbar icons |
| 175 |
ToolBarManager tbm = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT); |
| 176 |
captureAction = new Action(Messages.ScreenshotCreationPage_Capture_Desktop_C, IAction.AS_PUSH_BUTTON) { |
| 177 |
|
| 178 |
private boolean isFirstCapture = true; |
| 179 |
|
190 |
|
| 180 |
@Override |
191 |
@Override |
| 181 |
public void run() { |
192 |
public void run(ScreenshotToolbar.Capture action) { |
| 182 |
captureScreenshotContent(); |
193 |
if (action == ScreenshotToolbar.Capture.CLIPBOARD) { |
|
|
194 |
Image newimage = toolbar.getClipboardImage(); |
| 195 |
if (newimage == null) { |
| 196 |
// TODO show messagebox |
| 197 |
return; |
| 198 |
} |
| 199 |
captureScreenshotContent(newimage); |
| 200 |
} else if (action == ScreenshotToolbar.Capture.FILE) { |
| 201 |
Image newimage = toolbar.getFileImage(); |
| 202 |
if (newimage == null) { |
| 203 |
// TODO show messagebox |
| 204 |
return; |
| 205 |
} |
| 206 |
captureScreenshotContent(newimage); |
| 207 |
} else if (action == ScreenshotToolbar.Capture.CUT) { |
| 208 |
captureScreenshotContentFromSelection(); |
| 209 |
} else { |
| 210 |
captureScreenshotContent(); |
| 211 |
} |
| 183 |
setErrorMessage(null); |
212 |
setErrorMessage(null); |
| 184 |
if (isFirstCapture) { |
213 |
if (isFirstCapture) { |
| 185 |
isFirstCapture = false; |
214 |
isFirstCapture = false; |
| 186 |
fitAction.setEnabled(true); |
215 |
toolbar.setEnabled((ScreenshotToolbar.Tool) null, true); |
| 187 |
cropAction.setEnabled(true); |
|
|
| 188 |
cropAction.setChecked(true); |
| 189 |
markAction.setEnabled(true); |
| 190 |
clearAction.setEnabled(false); |
| 191 |
} |
216 |
} |
|
|
217 |
|
| 218 |
historyMouseEvent = new ArrayList<int[]>(); |
| 219 |
historyDrawTool = new ArrayList<int[]>(); |
| 220 |
historyDrawText = new ArrayList<StringBuffer>(); |
| 221 |
historyDrawFont = new ArrayList<String>(); |
| 222 |
historyCheckpoint = 0; |
| 223 |
toolbar.setEnabled(ScreenshotToolbar.Clear.CLEAR, false); |
| 224 |
toolbar.setEnabled(ScreenshotToolbar.Clear.UNDO, false); |
| 225 |
toolbar.setEnabled(ScreenshotToolbar.Clear.REDO, false); |
| 192 |
} |
226 |
} |
| 193 |
|
227 |
|
| 194 |
}; |
228 |
@Override |
| 195 |
captureAction.setToolTipText(Messages.ScreenshotCreationPage_Capture_Desktop); |
229 |
public void run(ScreenshotToolbar.Clear action) { |
| 196 |
captureAction.setImageDescriptor(ImageDescriptor.createFromImage(CommonImages.getImage(CommonImages.IMAGE_CAPTURE))); |
230 |
if (action == ScreenshotToolbar.Clear.CLEAR) { |
|
|
231 |
toolbar.setEnabled(ScreenshotToolbar.Clear.CLEAR, false); |
| 197 |
|
232 |
|
| 198 |
// captureDelayedButton = new Button(buttonsComposite, SWT.PUSH); |
233 |
workImageGC.drawImage(originalImage, 0, 0); |
| 199 |
// final String captureIn = "Capture in "; |
234 |
canvas.redraw(); |
| 200 |
// final int secondsDelay = 1; |
235 |
setImageDirty(true); |
| 201 |
// captureDelayedButton.setText(captureIn + secondsDelay +" seconds"); |
|
|
| 202 |
// captureDelayedButton.setImage(TasksUiImages.getImage(TasksUiImages.IMAGE_CAPTURE)); |
| 203 |
// captureDelayedButton.addSelectionListener(new SelectionListener() { |
| 204 |
// |
| 205 |
// public void widgetSelected(SelectionEvent e) { |
| 206 |
// PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { |
| 207 |
// public void run() { |
| 208 |
// getShell().setVisible(false); |
| 209 |
// for (int i = 1; i <= secondsDelay; i++) { |
| 210 |
// try { |
| 211 |
// Thread.sleep(1000); |
| 212 |
//// captureDelayedButton.setText("Capture in " + (secondsDelay-i) + " seconds"); |
| 213 |
// } catch (InterruptedException e1) { |
| 214 |
// // ignore |
| 215 |
// } |
| 216 |
// } |
| 217 |
// captureScreenshotContent(); |
| 218 |
// page.setErrorMessage(null); |
| 219 |
// fitButton.setEnabled(true); |
| 220 |
// captureDelayedButton.setText(captureIn + secondsDelay +" seconds"); |
| 221 |
// getShell().setVisible(true); |
| 222 |
// } |
| 223 |
// }); |
| 224 |
// } |
| 225 |
// |
| 226 |
// public void widgetDefaultSelected(SelectionEvent e) { |
| 227 |
// //ignore |
| 228 |
// } |
| 229 |
// }); |
| 230 |
|
236 |
|
| 231 |
fitAction = new Action("", IAction.AS_CHECK_BOX) { //$NON-NLS-1$ |
237 |
historyMouseEvent = new ArrayList<int[]>(); |
| 232 |
@Override |
238 |
historyDrawTool = new ArrayList<int[]>(); |
| 233 |
public void run() { |
239 |
historyDrawText = new ArrayList<StringBuffer>(); |
| 234 |
refreshCanvasSize(); |
240 |
historyDrawFont = new ArrayList<String>(); |
|
|
241 |
historyCheckpoint = 0; |
| 242 |
toolbar.setEnabled(ScreenshotToolbar.Clear.UNDO, false); |
| 243 |
toolbar.setEnabled(ScreenshotToolbar.Clear.REDO, false); |
| 244 |
} else if (action == ScreenshotToolbar.Clear.UNDO) { |
| 245 |
if (historyCheckpoint > 0) { |
| 246 |
historyCheckpoint--; |
| 247 |
drawAnnotationHistory(); |
| 248 |
} |
| 249 |
if (historyCheckpoint == 0) { |
| 250 |
toolbar.setEnabled(ScreenshotToolbar.Clear.UNDO, false); |
| 251 |
} |
| 252 |
if (historyCheckpoint < historyDrawTool.size()) { |
| 253 |
toolbar.setEnabled(ScreenshotToolbar.Clear.REDO, true); |
| 254 |
} |
| 255 |
} else if (action == ScreenshotToolbar.Clear.REDO) { |
| 256 |
if (historyCheckpoint < historyDrawTool.size()) { |
| 257 |
historyCheckpoint++; |
| 258 |
drawAnnotationHistory(); |
| 259 |
} |
| 260 |
if (historyCheckpoint > 0) { |
| 261 |
toolbar.setEnabled(ScreenshotToolbar.Clear.UNDO, true); |
| 262 |
} |
| 263 |
if (historyCheckpoint >= historyDrawTool.size()) { |
| 264 |
toolbar.setEnabled(ScreenshotToolbar.Clear.REDO, false); |
| 265 |
} |
| 266 |
} |
| 235 |
} |
267 |
} |
| 236 |
}; |
|
|
| 237 |
fitAction.setToolTipText(Messages.ScreenshotCreationPage_Fit_Image); |
| 238 |
fitAction.setText(Messages.ScreenshotCreationPage_Fit_Image_F); |
| 239 |
fitAction.setImageDescriptor(ImageDescriptor.createFromImage(CommonImages.getImage(CommonImages.IMAGE_FIT))); |
| 240 |
fitAction.setChecked(true); |
| 241 |
fitAction.setEnabled(false); |
| 242 |
|
268 |
|
| 243 |
cropAction = new Action(Messages.ScreenshotCreationPage_Crop_R, IAction.AS_RADIO_BUTTON) { |
|
|
| 244 |
@Override |
269 |
@Override |
| 245 |
public void run() { |
270 |
public void selectedTool(ScreenshotToolbar.Tool tool) { |
| 246 |
currentAction = EditorAction.CROPPING; |
271 |
if (tool == ScreenshotToolbar.Tool.RECT) { |
| 247 |
cropAction.setChecked(true); |
272 |
currentAction = EditorAction.CROPPING; |
| 248 |
markAction.setChecked(false); |
273 |
toolbar.setEnabled(ScreenshotToolbar.Clear.UNDO, false); |
| 249 |
colorAction.setEnabled(false); |
274 |
toolbar.setEnabled(ScreenshotToolbar.Clear.REDO, false); |
| 250 |
canvas.redraw(); |
275 |
canvas.redraw(); |
|
|
276 |
} else if (tool == ScreenshotToolbar.Tool.DRAW) { |
| 277 |
currentAction = EditorAction.MARKING; |
| 278 |
toolbar.setEnabled(ScreenshotToolbar.Clear.UNDO, false); |
| 279 |
toolbar.setEnabled(ScreenshotToolbar.Clear.REDO, false); |
| 280 |
canvas.redraw(); |
| 281 |
} else if (tool == ScreenshotToolbar.Tool.TEXT) { |
| 282 |
currentAction = EditorAction.MARKING; |
| 283 |
toolbar.setEnabled(ScreenshotToolbar.Clear.UNDO, false); |
| 284 |
toolbar.setEnabled(ScreenshotToolbar.Clear.REDO, false); |
| 285 |
canvas.redraw(); |
| 286 |
} |
| 251 |
} |
287 |
} |
| 252 |
}; |
|
|
| 253 |
cropAction.setToolTipText(Messages.ScreenshotCreationPage_Crop); |
| 254 |
cropAction.setImageDescriptor(CommonImages.CUT); |
| 255 |
cropAction.setEnabled(false); |
| 256 |
|
288 |
|
| 257 |
markAction = new Action(Messages.ScreenshotCreationPage_Annotate, IAction.AS_RADIO_BUTTON) { |
|
|
| 258 |
@Override |
289 |
@Override |
| 259 |
public void run() { |
290 |
public void selectedZoom(Zoom zoom) { |
| 260 |
currentAction = EditorAction.MARKING; |
291 |
refreshCanvasSize(); |
| 261 |
cropAction.setChecked(false); |
|
|
| 262 |
markAction.setChecked(true); |
| 263 |
colorAction.setEnabled(true); |
| 264 |
canvas.redraw(); |
| 265 |
} |
292 |
} |
| 266 |
}; |
|
|
| 267 |
markAction.setToolTipText(Messages.ScreenshotCreationPage_DRAW_ANNOTATION_ON_SCREENSHOT_IMAGE); |
| 268 |
markAction.setImageDescriptor(CommonImages.EDIT); |
| 269 |
// markAction.setDisabledImageDescriptor(ImageDescriptor.createFromFile(getClass(), "mark_disabled.gif")); |
| 270 |
markAction.setEnabled(false); |
| 271 |
|
293 |
|
| 272 |
colorAction = new Action("", IAction.AS_DROP_DOWN_MENU) { //$NON-NLS-1$ |
|
|
| 273 |
@Override |
294 |
@Override |
| 274 |
public void runWithEvent(final Event e) { |
295 |
public void selectedColor(RGB rgb) { |
| 275 |
final ColorSelectionWindow colorWindow = new ColorSelectionWindow(getControl().getShell()) { |
296 |
setMarkColor(rgb); |
| 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 |
} |
297 |
} |
| 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 |
|
298 |
|
| 301 |
clearAction = new Action(Messages.ScreenshotCreationPage_Clear_Annotations, IAction.AS_PUSH_BUTTON) { |
|
|
| 302 |
@Override |
299 |
@Override |
| 303 |
public void run() { |
300 |
public void selectedFont(Font font, RGB rgb) { |
| 304 |
clearAction.setEnabled(false); |
301 |
setMarkFont(toolbar.getTextFont().getFontData(), toolbar.getTextColor()); |
| 305 |
workImageGC.drawImage(originalImage, 0, 0); |
|
|
| 306 |
canvas.redraw(); |
| 307 |
setImageDirty(true); |
| 308 |
} |
302 |
} |
| 309 |
}; |
303 |
}; |
| 310 |
clearAction.setToolTipText(Messages.ScreenshotCreationPage_Clear_all_annotations_made_on_screenshot_image); |
|
|
| 311 |
clearAction.setImageDescriptor(CommonImages.CLEAR); |
| 312 |
clearAction.setEnabled(false); |
| 313 |
|
| 314 |
tbm.add(createAndConfigureCI(captureAction)); |
| 315 |
tbm.add(createAndConfigureCI(fitAction)); |
| 316 |
tbm.add(new Separator()); |
| 317 |
tbm.add(createAndConfigureCI(cropAction)); |
| 318 |
tbm.add(createAndConfigureCI(markAction)); |
| 319 |
tbm.add(createAndConfigureCI(colorAction)); |
| 320 |
tbm.add(new Separator()); |
| 321 |
tbm.add(createAndConfigureCI(clearAction)); |
| 322 |
|
304 |
|
| 323 |
scrolledComposite = new ScrolledComposite(vf, SWT.V_SCROLL | SWT.H_SCROLL); |
305 |
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_VERTICAL); |
|
|
306 |
toolbar.setLayoutData(gd); |
| 307 |
toolbar.setEnabled((ScreenshotToolbar.Tool) null, false); |
| 308 |
toolbar.setEnabled(ScreenshotToolbar.Capture.CUT, false); |
| 309 |
toolbar.setEnabled(ScreenshotToolbar.Clear.CLEAR, false); |
| 310 |
toolbar.setEnabled(ScreenshotToolbar.Clear.UNDO, false); |
| 311 |
toolbar.setEnabled(ScreenshotToolbar.Clear.REDO, false); |
| 312 |
|
| 313 |
allocateCursors(); |
| 314 |
|
| 315 |
ScreenshotToolbar.Tool tool = toolbar.getTool(); |
| 316 |
if (tool == ScreenshotToolbar.Tool.RECT) { |
| 317 |
currentAction = EditorAction.CROPPING; |
| 318 |
} else if (tool == ScreenshotToolbar.Tool.DRAW) { |
| 319 |
currentAction = EditorAction.MARKING; |
| 320 |
} else if (tool == ScreenshotToolbar.Tool.TEXT) { |
| 321 |
currentAction = EditorAction.MARKING; |
| 322 |
} |
| 323 |
setMarkColor(toolbar.getDrawColor()); |
| 324 |
setMarkFont(toolbar.getTextFont().getFontData(), toolbar.getTextColor()); |
| 325 |
|
| 326 |
scrolledComposite = new ScrolledComposite(vf, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); |
| 324 |
canvas = new Canvas(scrolledComposite, SWT.DOUBLE_BUFFERED); |
327 |
canvas = new Canvas(scrolledComposite, SWT.DOUBLE_BUFFERED); |
| 325 |
scrolledComposite.setContent(canvas); |
328 |
scrolledComposite.setContent(canvas); |
| 326 |
canvas.addPaintListener(new PaintListener() { |
329 |
canvas.addPaintListener(new PaintListener() { |
|
Lines 330-345
Link Here
|
| 330 |
Rectangle imageBounds = workImage.getBounds(); |
333 |
Rectangle imageBounds = workImage.getBounds(); |
| 331 |
Rectangle canvasBounds = canvas.getClientArea(); |
334 |
Rectangle canvasBounds = canvas.getClientArea(); |
| 332 |
|
335 |
|
| 333 |
if (fitAction.isChecked()) { |
336 |
ScreenshotToolbar.Zoom zoom = toolbar.getZoom(); |
| 334 |
e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, 0, 0, |
337 |
if (zoom == ScreenshotToolbar.Zoom.FIT) { |
| 335 |
canvasBounds.width, canvasBounds.height); |
338 |
e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, // |
|
|
339 |
0, 0, canvasBounds.width, canvasBounds.height); |
| 340 |
} else if (zoom == ScreenshotToolbar.Zoom.ZOOM8X) { |
| 341 |
e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, // |
| 342 |
0, 0, imageBounds.width * 8, imageBounds.height * 8); |
| 343 |
} else if (zoom == ScreenshotToolbar.Zoom.ZOOM4X) { |
| 344 |
e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, // |
| 345 |
0, 0, imageBounds.width * 4, imageBounds.height * 4); |
| 346 |
} else if (zoom == ScreenshotToolbar.Zoom.ZOOM2X) { |
| 347 |
e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, // |
| 348 |
0, 0, imageBounds.width * 2, imageBounds.height * 2); |
| 349 |
} else if (zoom == ScreenshotToolbar.Zoom.ZOOMHALF) { |
| 350 |
e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, // |
| 351 |
0, 0, imageBounds.width / 2, imageBounds.height / 2); |
| 336 |
} else { |
352 |
} else { |
| 337 |
e.gc.drawImage(workImage, 0, 0); |
353 |
e.gc.drawImage(workImage, 0, 0); |
| 338 |
} |
354 |
} |
| 339 |
drawSelection(e.gc); |
355 |
drawSelection(e.gc); |
| 340 |
} else { |
356 |
} else { |
| 341 |
// page.setErrorMessage("Screenshot required"); |
357 |
// page.setErrorMessage("Screenshot required"); |
| 342 |
fitAction.setEnabled(false); |
358 |
toolbar.setEnabled(ScreenshotToolbar.Tool.ZOOM, false); |
| 343 |
} |
359 |
} |
| 344 |
} |
360 |
} |
| 345 |
}); |
361 |
}); |
|
Lines 347-370
Link Here
|
| 347 |
scrolledComposite.addControlListener(new ControlAdapter() { |
363 |
scrolledComposite.addControlListener(new ControlAdapter() { |
| 348 |
@Override |
364 |
@Override |
| 349 |
public void controlResized(ControlEvent e) { |
365 |
public void controlResized(ControlEvent e) { |
| 350 |
if (fitAction.isChecked()) { |
366 |
if (toolbar.getZoom() == ScreenshotToolbar.Zoom.FIT) { |
| 351 |
refreshCanvasSize(); |
367 |
refreshCanvasSize(); |
| 352 |
} |
368 |
} |
| 353 |
} |
369 |
} |
| 354 |
}); |
370 |
}); |
| 355 |
scrolledComposite.setEnabled(false); |
371 |
scrolledComposite.setEnabled(false); |
| 356 |
|
372 |
|
| 357 |
vf.setTopLeft(tbm.createControl(vf)); |
373 |
scrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 358 |
vf.setContent(scrolledComposite); |
374 |
|
| 359 |
registerMouseListeners(); |
375 |
registerMouseListeners(); |
| 360 |
|
376 |
|
| 361 |
Dialog.applyDialogFont(vf); |
377 |
Dialog.applyDialogFont(vf); |
| 362 |
} |
378 |
} |
| 363 |
|
379 |
|
| 364 |
private ActionContributionItem createAndConfigureCI(IAction action) { |
380 |
private void setMarkFont(FontData[] fontData, RGB fontColor) { |
| 365 |
ActionContributionItem ci = new ActionContributionItem(action); |
381 |
if (markFont != null) { |
| 366 |
ci.setMode(ActionContributionItem.MODE_FORCE_TEXT); |
382 |
markFont.dispose(); |
| 367 |
return ci; |
383 |
} |
|
|
384 |
markFont = new Font(getShell().getDisplay(), fontData[0]); |
| 385 |
markFontColor = new Color(getShell().getDisplay(), fontColor); |
| 368 |
} |
386 |
} |
| 369 |
|
387 |
|
| 370 |
private void setMarkColor(RGB color) { |
388 |
private void setMarkColor(RGB color) { |
|
Lines 375-388
Link Here
|
| 375 |
if (workImageGC != null) { |
393 |
if (workImageGC != null) { |
| 376 |
workImageGC.setForeground(markColor); |
394 |
workImageGC.setForeground(markColor); |
| 377 |
} |
395 |
} |
| 378 |
|
|
|
| 379 |
GC colorGC = new GC(colorIcon); |
| 380 |
colorGC.setBackground(markColor); |
| 381 |
colorGC.fillRectangle(0, 0, 16, 16); |
| 382 |
colorGC.drawRectangle(0, 0, 15, 15); |
| 383 |
colorGC.dispose(); |
| 384 |
|
| 385 |
colorAction.setImageDescriptor(ImageDescriptor.createFromImage(colorIcon)); |
| 386 |
} |
396 |
} |
| 387 |
|
397 |
|
| 388 |
@Override |
398 |
@Override |
|
Lines 391-399
Link Here
|
| 391 |
if (markColor != null) { |
401 |
if (markColor != null) { |
| 392 |
markColor.dispose(); |
402 |
markColor.dispose(); |
| 393 |
} |
403 |
} |
| 394 |
if (colorIcon != null) { |
|
|
| 395 |
colorIcon.dispose(); |
| 396 |
} |
| 397 |
|
404 |
|
| 398 |
canvas.setCursor(null); |
405 |
canvas.setCursor(null); |
| 399 |
for (Cursor cursor : cursors.values()) { |
406 |
for (Cursor cursor : cursors.values()) { |
|
Lines 455-460
Link Here
|
| 455 |
return isPageComplete(); |
462 |
return isPageComplete(); |
| 456 |
} |
463 |
} |
| 457 |
|
464 |
|
|
|
465 |
private void captureScreenshotContent(Image image) { |
| 466 |
Display display = getShell().getDisplay(); |
| 467 |
disposeImageResources(); |
| 468 |
originalImage = image; |
| 469 |
Rectangle displayBounds = originalImage.getBounds(); |
| 470 |
workImage = new Image(display, displayBounds.width, displayBounds.height); |
| 471 |
GC gc = new GC(workImage); |
| 472 |
gc.drawImage(originalImage, 0, 0); |
| 473 |
gc.dispose(); |
| 474 |
|
| 475 |
workImageGC = new GC(workImage); |
| 476 |
workImageGC.setBackground(new Color(getShell().getDisplay(), 255, 255, 255)); |
| 477 |
workImageGC.setForeground(markColor); |
| 478 |
workImageGC.setLineWidth(4); |
| 479 |
workImageGC.setLineCap(SWT.CAP_ROUND); |
| 480 |
|
| 481 |
scrolledComposite.setEnabled(true); |
| 482 |
clearSelection(); |
| 483 |
refreshCanvasSize(); |
| 484 |
|
| 485 |
setPageComplete(true); |
| 486 |
} |
| 487 |
|
| 488 |
private void captureScreenshotContentFromSelection() { |
| 489 |
Display display = getShell().getDisplay(); |
| 490 |
|
| 491 |
Image image = new Image(display, currentSelection); |
| 492 |
GC gc = new GC(image); |
| 493 |
gc.drawImage(workImage, currentSelection.x, currentSelection.y, currentSelection.width, |
| 494 |
currentSelection.height, 0, 0, currentSelection.width, currentSelection.height); |
| 495 |
gc.dispose(); |
| 496 |
disposeImageResources(); |
| 497 |
|
| 498 |
originalImage = image; |
| 499 |
Rectangle displayBounds = originalImage.getBounds(); |
| 500 |
workImage = new Image(display, displayBounds.width, displayBounds.height); |
| 501 |
gc = new GC(workImage); |
| 502 |
gc.drawImage(originalImage, 0, 0); |
| 503 |
gc.dispose(); |
| 504 |
|
| 505 |
workImageGC = new GC(workImage); |
| 506 |
workImageGC.setBackground(new Color(getShell().getDisplay(), 255, 255, 255)); |
| 507 |
workImageGC.setForeground(markColor); |
| 508 |
workImageGC.setLineWidth(4); |
| 509 |
workImageGC.setLineCap(SWT.CAP_ROUND); |
| 510 |
|
| 511 |
scrolledComposite.setEnabled(true); |
| 512 |
clearSelection(); |
| 513 |
refreshCanvasSize(); |
| 514 |
|
| 515 |
setPageComplete(true); |
| 516 |
} |
| 517 |
|
| 458 |
private void captureScreenshotContent() { |
518 |
private void captureScreenshotContent() { |
| 459 |
final Display display = getShell().getDisplay(); |
519 |
final Display display = getShell().getDisplay(); |
| 460 |
final Shell wizardShell = getWizard().getContainer().getShell(); |
520 |
final Shell wizardShell = getWizard().getContainer().getShell(); |
|
Lines 507-512
Link Here
|
| 507 |
int height = Math.abs(startPoint.y - y); |
567 |
int height = Math.abs(startPoint.y - y); |
| 508 |
currentSelection = new Rectangle(startX, startY, width, height); |
568 |
currentSelection = new Rectangle(startX, startY, width, height); |
| 509 |
|
569 |
|
|
|
570 |
toolbar.setEnabled(ScreenshotToolbar.Capture.CUT, true); |
| 571 |
|
| 510 |
// Decreases 1 pixel size from original image because Rectangle.intersect() consider them as right-bottom limit |
572 |
// Decreases 1 pixel size from original image because Rectangle.intersect() consider them as right-bottom limit |
| 511 |
Rectangle imageBounds = workImage.getBounds(); |
573 |
Rectangle imageBounds = workImage.getBounds(); |
| 512 |
imageBounds.width--; |
574 |
imageBounds.width--; |
|
Lines 546-551
Link Here
|
| 546 |
private void refreshSelectionResize(int x, int y) { |
608 |
private void refreshSelectionResize(int x, int y) { |
| 547 |
currentSelection = new Rectangle(originalSelection.x, originalSelection.y, originalSelection.width, |
609 |
currentSelection = new Rectangle(originalSelection.x, originalSelection.y, originalSelection.width, |
| 548 |
originalSelection.height); |
610 |
originalSelection.height); |
|
|
611 |
|
| 612 |
toolbar.setEnabled(ScreenshotToolbar.Capture.CUT, true); |
| 613 |
|
| 549 |
int deltaX = x - startPoint.x; |
614 |
int deltaX = x - startPoint.x; |
| 550 |
int deltaY = y - startPoint.y; |
615 |
int deltaY = y - startPoint.y; |
| 551 |
Rectangle imageBounds = workImage.getBounds(); |
616 |
Rectangle imageBounds = workImage.getBounds(); |
|
Lines 613-618
Link Here
|
| 613 |
} |
678 |
} |
| 614 |
currentSelection = new Rectangle(newX, newY, originalSelection.width, originalSelection.height); |
679 |
currentSelection = new Rectangle(newX, newY, originalSelection.width, originalSelection.height); |
| 615 |
|
680 |
|
|
|
681 |
toolbar.setEnabled(ScreenshotToolbar.Capture.CUT, true); |
| 682 |
|
| 616 |
setUpGrabPoints(); |
683 |
setUpGrabPoints(); |
| 617 |
} |
684 |
} |
| 618 |
|
685 |
|
|
Lines 659-664
Link Here
|
| 659 |
canvas.setCursor(crossCursor); |
726 |
canvas.setCursor(crossCursor); |
| 660 |
} |
727 |
} |
| 661 |
} else if (currentAction == EditorAction.MARKING) { |
728 |
} else if (currentAction == EditorAction.MARKING) { |
|
|
729 |
if (startPoint != null) { |
| 730 |
if (toolbar.getDrawTool() == ScreenshotToolbar.Draw.FREE) { |
| 731 |
int[] history = new int[3]; |
| 732 |
history[0] = SWT.MouseMove; |
| 733 |
history[1] = scaledX; |
| 734 |
history[2] = scaledY; |
| 735 |
historyMouseEvent.add(history); |
| 736 |
} else { |
| 737 |
int[] history = historyMouseEvent.get(historyMouseEvent.size() - 1); |
| 738 |
if (history[0] == SWT.MouseMove) { |
| 739 |
history[1] = scaledX; |
| 740 |
history[2] = scaledY; |
| 741 |
} else { |
| 742 |
history = new int[3]; |
| 743 |
history[0] = SWT.MouseMove; |
| 744 |
history[1] = scaledX; |
| 745 |
history[2] = scaledY; |
| 746 |
historyMouseEvent.add(history); |
| 747 |
} |
| 748 |
} |
| 749 |
} |
| 750 |
|
| 662 |
drawMarkLine(scaledX, scaledY); |
751 |
drawMarkLine(scaledX, scaledY); |
| 663 |
|
752 |
|
| 664 |
Cursor markCursor = cursors.get(CURSOR_MARK_TOOL); |
753 |
Cursor markCursor = cursors.get(CURSOR_MARK_TOOL); |
|
Lines 691-696
Link Here
|
| 691 |
} |
780 |
} |
| 692 |
if (currentSelection.width == 0 && currentSelection.height == 0) { |
781 |
if (currentSelection.width == 0 && currentSelection.height == 0) { |
| 693 |
currentSelection = null; |
782 |
currentSelection = null; |
|
|
783 |
|
| 784 |
toolbar.setEnabled(ScreenshotToolbar.Capture.CUT, false); |
| 694 |
} |
785 |
} |
| 695 |
setUpGrabPoints(); |
786 |
setUpGrabPoints(); |
| 696 |
startPoint = null; |
787 |
startPoint = null; |
|
Lines 699-707
Link Here
|
| 699 |
canvas.redraw(); |
790 |
canvas.redraw(); |
| 700 |
setImageDirty(true); |
791 |
setImageDirty(true); |
| 701 |
} else if (currentAction == EditorAction.MARKING) { |
792 |
} else if (currentAction == EditorAction.MARKING) { |
|
|
793 |
if (startPoint != null) { |
| 794 |
if (toolbar.getTool() == ScreenshotToolbar.Tool.DRAW) { |
| 795 |
if (toolbar.getDrawTool() != ScreenshotToolbar.Draw.FREE) { |
| 796 |
previousImage.dispose(); |
| 797 |
previousImage = null; |
| 798 |
} |
| 799 |
|
| 800 |
int[] history = new int[3]; |
| 801 |
history[0] = SWT.MouseUp; |
| 802 |
history[1] = 0; |
| 803 |
history[2] = 0; |
| 804 |
historyMouseEvent.add(history); |
| 805 |
} else if (toolbar.getTool() == ScreenshotToolbar.Tool.TEXT) { |
| 806 |
drawAnnotationText(); |
| 807 |
|
| 808 |
int[] history = new int[3]; |
| 809 |
history[0] = SWT.MouseUp; |
| 810 |
history[1] = 0; |
| 811 |
history[2] = 0; |
| 812 |
historyMouseEvent.add(history); |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 702 |
startPoint = null; |
816 |
startPoint = null; |
| 703 |
setImageDirty(true); |
817 |
setImageDirty(true); |
|
|
818 |
|
| 819 |
} |
| 820 |
} |
| 821 |
|
| 822 |
/** |
| 823 |
* Input annotation text and draw text |
| 824 |
*/ |
| 825 |
private void drawAnnotationText() { |
| 826 |
workImageGC.drawImage(previousImage, 0, 0); |
| 827 |
|
| 828 |
int[] history = historyMouseEvent.get(historyMouseEvent.size() - 1); |
| 829 |
if (history[0] != SWT.MouseMove) { |
| 830 |
historyCheckpoint--; |
| 831 |
updateAnnotationHistory(); |
| 832 |
return; |
| 833 |
} |
| 834 |
|
| 835 |
final Rectangle bounds = new Rectangle(startPoint.x, startPoint.y, history[1] - startPoint.x, |
| 836 |
history[2] - startPoint.y); |
| 837 |
|
| 838 |
textArea = new Text(canvas, SWT.MULTI | SWT.WRAP); |
| 839 |
textArea.addListener(SWT.Deactivate, new Listener() { |
| 840 |
|
| 841 |
public void handleEvent(Event event) { |
| 842 |
String text = textArea.getText(); |
| 843 |
{ |
| 844 |
String newtext = ""; //$NON-NLS-1$ |
| 845 |
int currpos = 0; |
| 846 |
int charpos = currpos; |
| 847 |
textArea.setTopIndex(0); |
| 848 |
textArea.setSelection(currpos); |
| 849 |
int linepos = textArea.getCaretLineNumber(); |
| 850 |
boolean remove1st = false; |
| 851 |
String line; |
| 852 |
while (currpos < text.length()) { |
| 853 |
int y = textArea.getCaretLineNumber(); |
| 854 |
if (linepos != y) { |
| 855 |
line = text.substring(charpos, currpos); |
| 856 |
if (line.endsWith("\n")) { //$NON-NLS-1$ |
| 857 |
line = line.substring(0, line.length() - 1); |
| 858 |
} |
| 859 |
newtext = newtext + "\n" + line; //$NON-NLS-1$ |
| 860 |
remove1st = true; |
| 861 |
charpos = currpos; |
| 862 |
linepos = y; |
| 863 |
} |
| 864 |
currpos++; |
| 865 |
textArea.setSelection(currpos); |
| 866 |
} |
| 867 |
line = text.substring(charpos, currpos); |
| 868 |
if (line.endsWith("\n")) { //$NON-NLS-1$ |
| 869 |
line = line.substring(0, line.length() - 1); |
| 870 |
} |
| 871 |
if (line.length() > 0) { |
| 872 |
newtext = newtext + "\n" + text.substring(charpos, currpos); //$NON-NLS-1$ |
| 873 |
remove1st = true; |
| 874 |
} |
| 875 |
currpos = newtext.indexOf("\r"); //$NON-NLS-1$ |
| 876 |
while (currpos > 0) { |
| 877 |
newtext = newtext.substring(0, currpos) + newtext.substring(currpos + 1); |
| 878 |
currpos = newtext.indexOf("\r"); //$NON-NLS-1$ |
| 879 |
} |
| 880 |
newtext = newtext.replace("\t", " "); //$NON-NLS-1$ //$NON-NLS-2$ |
| 881 |
if (remove1st) { |
| 882 |
newtext = newtext.substring(1); |
| 883 |
} |
| 884 |
text = newtext; |
| 885 |
} |
| 886 |
|
| 887 |
textArea.dispose(); |
| 888 |
textArea = null; |
| 889 |
|
| 890 |
if (text.length() > 0) { |
| 891 |
historyDrawText.get(historyCheckpoint - 1).append(text); |
| 892 |
workImageGC.setFont(markFont); |
| 893 |
workImageGC.setForeground(markFontColor); |
| 894 |
workImageGC.setClipping(bounds); |
| 895 |
workImageGC.drawText(text, bounds.x, bounds.y, true); |
| 896 |
workImageGC.setClipping((Rectangle) null); |
| 897 |
workImageGC.setForeground(markColor); |
| 898 |
} else { |
| 899 |
historyCheckpoint--; |
| 900 |
updateAnnotationHistory(); |
| 901 |
} |
| 902 |
canvas.redraw(); |
| 903 |
} |
| 904 |
}); |
| 905 |
|
| 906 |
textArea.setFocus(); |
| 907 |
int xs = (int) Math.round(startPoint.x * scaleFactor); |
| 908 |
int ys = (int) Math.round(startPoint.y * scaleFactor); |
| 909 |
int xe = (int) Math.round(history[1] * scaleFactor); |
| 910 |
int ye = (int) Math.round(history[2] * scaleFactor); |
| 911 |
textArea.setBounds(new Rectangle(xs, ys, xe - xs, ye - ys)); |
| 912 |
if (scaleFactor != 1.0) { |
| 913 |
FontData[] fd = markFont.getFontData(); |
| 914 |
fd[0].setHeight((int) Math.round(fd[0].getHeight() * scaleFactor)); |
| 915 |
textArea.setFont(new Font(getShell().getDisplay(), fd[0])); |
| 916 |
} else { |
| 917 |
textArea.setFont(markFont); |
| 704 |
} |
918 |
} |
|
|
919 |
textArea.setForeground(markFontColor); |
| 920 |
textArea.setTabs(1); |
| 921 |
Point point = textArea.getCaretLocation(); |
| 922 |
textArea.setBounds(new Rectangle(xs - point.x, ys, xe - xs + point.x + point.x, ye - ys)); |
| 705 |
} |
923 |
} |
| 706 |
|
924 |
|
| 707 |
/** |
925 |
/** |
|
Lines 713-718
Link Here
|
| 713 |
int scaledY = (int) (e.y / scaleFactor); |
931 |
int scaledY = (int) (e.y / scaleFactor); |
| 714 |
|
932 |
|
| 715 |
if (currentAction == EditorAction.MARKING) { |
933 |
if (currentAction == EditorAction.MARKING) { |
|
|
934 |
updateAnnotationHistory(); |
| 935 |
|
| 936 |
ScreenshotToolbar.Tool toolKind = toolbar.getTool(); |
| 937 |
int[] history = new int[5]; |
| 938 |
history[0] = historyMouseEvent.size(); |
| 939 |
history[1] = toolbar.getDrawTool().hashCode(); |
| 940 |
history[2] = toolbar.getLineStyle(); |
| 941 |
history[3] = toolbar.getLineBold(); |
| 942 |
if (toolKind == ScreenshotToolbar.Tool.TEXT) { |
| 943 |
history[1] = toolKind.hashCode(); |
| 944 |
history[4] = (markFontColor.getRed() << 16) // |
| 945 |
+ (markFontColor.getGreen() << 8) // |
| 946 |
+ markFontColor.getBlue(); |
| 947 |
} else { |
| 948 |
history[4] = (markColor.getRed() << 16) // |
| 949 |
+ (markColor.getGreen() << 8) // |
| 950 |
+ markColor.getBlue(); |
| 951 |
} |
| 952 |
historyDrawTool.add(history); |
| 953 |
historyDrawText.add(new StringBuffer()); |
| 954 |
if (toolKind == ScreenshotToolbar.Tool.TEXT) { |
| 955 |
FontData[] fd = markFont.getFontData(); |
| 956 |
historyDrawFont.add(fd[0].toString()); |
| 957 |
} else { |
| 958 |
historyDrawFont.add(""); //$NON-NLS-1$ |
| 959 |
} |
| 960 |
historyCheckpoint = historyDrawTool.size(); |
| 961 |
|
| 962 |
history = new int[3]; |
| 963 |
history[0] = SWT.MouseDown; |
| 964 |
history[1] = scaledX; |
| 965 |
history[2] = scaledY; |
| 966 |
historyMouseEvent.add(history); |
| 967 |
toolbar.setEnabled(ScreenshotToolbar.Clear.UNDO, true); |
| 968 |
|
| 969 |
if (toolKind != ScreenshotToolbar.Tool.TEXT) { |
| 970 |
if (toolbar.getDrawTool() != ScreenshotToolbar.Draw.FREE) { |
| 971 |
Display display = getShell().getDisplay(); |
| 972 |
previousImage = new Image(display, workImage.getBounds()); |
| 973 |
GC gc = new GC(previousImage); |
| 974 |
gc.drawImage(workImage, 0, 0); |
| 975 |
gc.dispose(); |
| 976 |
} |
| 977 |
|
| 978 |
workImageGC.setLineStyle(toolbar.getLineStyle()); |
| 979 |
workImageGC.setLineWidth(toolbar.getLineBold()); |
| 980 |
workImageGC.setForeground(markColor); |
| 981 |
} else { |
| 982 |
Display display = getShell().getDisplay(); |
| 983 |
previousImage = new Image(display, workImage.getBounds()); |
| 984 |
GC gc = new GC(previousImage); |
| 985 |
gc.drawImage(workImage, 0, 0); |
| 986 |
gc.dispose(); |
| 987 |
|
| 988 |
workImageGC.setLineStyle(SWT.LINE_DOT); |
| 989 |
workImageGC.setLineWidth(1); |
| 990 |
workImageGC.setForeground(new Color(getShell().getDisplay(), 0, 0, 0)); |
| 991 |
} |
| 992 |
|
| 716 |
startPoint = new Point(scaledX, scaledY); |
993 |
startPoint = new Point(scaledX, scaledY); |
| 717 |
drawMarkLine(scaledX, scaledY); |
994 |
drawMarkLine(scaledX, scaledY); |
| 718 |
canvas.setCursor(cursors.get(CURSOR_MARK_TOOL)); |
995 |
canvas.setCursor(cursors.get(CURSOR_MARK_TOOL)); |
|
Lines 748-753
Link Here
|
| 748 |
canvas.setCursor(cursors.get(SWT.CURSOR_CROSS)); |
1025 |
canvas.setCursor(cursors.get(SWT.CURSOR_CROSS)); |
| 749 |
currentAction = EditorAction.SELECTING; |
1026 |
currentAction = EditorAction.SELECTING; |
| 750 |
currentSelection = null; |
1027 |
currentSelection = null; |
|
|
1028 |
|
| 1029 |
toolbar.setEnabled(ScreenshotToolbar.Capture.CUT, false); |
| 1030 |
|
| 751 |
startPoint = new Point(scaledX, scaledY); |
1031 |
startPoint = new Point(scaledX, scaledY); |
| 752 |
setUpGrabPoints(); |
1032 |
setUpGrabPoints(); |
| 753 |
canvas.redraw(); |
1033 |
canvas.redraw(); |
|
Lines 759-764
Link Here
|
| 759 |
|
1039 |
|
| 760 |
private void clearSelection() { |
1040 |
private void clearSelection() { |
| 761 |
currentSelection = null; |
1041 |
currentSelection = null; |
|
|
1042 |
|
| 1043 |
toolbar.setEnabled(ScreenshotToolbar.Capture.CUT, false); |
| 1044 |
|
| 762 |
startPoint = null; |
1045 |
startPoint = null; |
| 763 |
setImageDirty(true); |
1046 |
setImageDirty(true); |
| 764 |
} |
1047 |
} |
|
Lines 779-785
Link Here
|
| 779 |
* Calling this method under other circumstances may lead to strange behavior in the scrolled composite |
1062 |
* Calling this method under other circumstances may lead to strange behavior in the scrolled composite |
| 780 |
*/ |
1063 |
*/ |
| 781 |
private void refreshCanvasSize() { |
1064 |
private void refreshCanvasSize() { |
| 782 |
if (fitAction.isChecked()) { |
1065 |
ScreenshotToolbar.Zoom zoom = toolbar.getZoom(); |
|
|
1066 |
if (zoom == ScreenshotToolbar.Zoom.FIT) { |
| 783 |
// This little hack is necessary to get the client area without scrollbars; |
1067 |
// This little hack is necessary to get the client area without scrollbars; |
| 784 |
// they'll be automatically restored if necessary after Canvas.setBounds() |
1068 |
// they'll be automatically restored if necessary after Canvas.setBounds() |
| 785 |
scrolledComposite.getHorizontalBar().setVisible(false); |
1069 |
scrolledComposite.getHorizontalBar().setVisible(false); |
|
Lines 798-809
Link Here
|
| 798 |
} |
1082 |
} |
| 799 |
canvas.setBounds(bounds); |
1083 |
canvas.setBounds(bounds); |
| 800 |
} else { |
1084 |
} else { |
| 801 |
scaleFactor = 1.0; |
1085 |
if (zoom == ScreenshotToolbar.Zoom.ZOOM8X) { |
|
|
1086 |
scaleFactor = 8.0; |
| 1087 |
} else if (zoom == ScreenshotToolbar.Zoom.ZOOM4X) { |
| 1088 |
scaleFactor = 4.0; |
| 1089 |
} else if (zoom == ScreenshotToolbar.Zoom.ZOOM2X) { |
| 1090 |
scaleFactor = 2.0; |
| 1091 |
} else if (zoom == ScreenshotToolbar.Zoom.ZOOMHALF) { |
| 1092 |
scaleFactor = 0.5; |
| 1093 |
} else { |
| 1094 |
scaleFactor = 1.0; |
| 1095 |
} |
| 802 |
Rectangle bounds = scrolledComposite.getClientArea(); |
1096 |
Rectangle bounds = scrolledComposite.getClientArea(); |
| 803 |
if (workImage != null) { |
1097 |
if (workImage != null) { |
| 804 |
Rectangle imageBounds = workImage.getBounds(); |
1098 |
Rectangle imageBounds = workImage.getBounds(); |
| 805 |
bounds.width = imageBounds.width; |
1099 |
bounds.width = (int) Math.round(imageBounds.width * scaleFactor); |
| 806 |
bounds.height = imageBounds.height; |
1100 |
bounds.height = (int) Math.round(imageBounds.height * scaleFactor); |
| 807 |
} |
1101 |
} |
| 808 |
canvas.setBounds(bounds); |
1102 |
canvas.setBounds(bounds); |
| 809 |
} |
1103 |
} |
|
Lines 811-816
Link Here
|
| 811 |
canvas.redraw(); |
1105 |
canvas.redraw(); |
| 812 |
} |
1106 |
} |
| 813 |
|
1107 |
|
|
|
1108 |
private void updateAnnotationHistory() { |
| 1109 |
int[] history; |
| 1110 |
if (historyCheckpoint < historyDrawTool.size()) { |
| 1111 |
history = historyDrawTool.get(historyCheckpoint); |
| 1112 |
while (history[0] < historyMouseEvent.size()) { |
| 1113 |
historyMouseEvent.remove(historyMouseEvent.size() - 1); |
| 1114 |
} |
| 1115 |
while (historyCheckpoint < historyDrawTool.size()) { |
| 1116 |
historyDrawTool.remove(historyDrawTool.size() - 1); |
| 1117 |
} |
| 1118 |
while (historyCheckpoint < historyDrawText.size()) { |
| 1119 |
historyDrawText.remove(historyDrawText.size() - 1); |
| 1120 |
} |
| 1121 |
while (historyCheckpoint < historyDrawFont.size()) { |
| 1122 |
historyDrawFont.remove(historyDrawFont.size() - 1); |
| 1123 |
} |
| 1124 |
toolbar.setEnabled(ScreenshotToolbar.Clear.REDO, false); |
| 1125 |
} |
| 1126 |
|
| 1127 |
toolbar.setEnabled(ScreenshotToolbar.Clear.UNDO, historyCheckpoint > 0); |
| 1128 |
} |
| 1129 |
|
| 1130 |
/** |
| 1131 |
* Draw Annotation with history |
| 1132 |
*/ |
| 1133 |
private void drawAnnotationHistory() { |
| 1134 |
workImageGC.drawImage(originalImage, 0, 0); |
| 1135 |
int[] history; |
| 1136 |
for (int c = 0; c < historyCheckpoint; c++) { |
| 1137 |
history = historyDrawTool.get(c); |
| 1138 |
int toolKind = history[1]; |
| 1139 |
int boldlKind = history[3]; |
| 1140 |
workImageGC.setLineStyle(history[2]); |
| 1141 |
workImageGC.setLineWidth(boldlKind); |
| 1142 |
workImageGC.setForeground(new Color(getShell().getDisplay(), // |
| 1143 |
history[4] >> 16, // |
| 1144 |
(history[4] >> 8) & 0x00ff, // |
| 1145 |
history[4] & 0x00ff)); |
| 1146 |
|
| 1147 |
int h = history[0]; |
| 1148 |
history = historyMouseEvent.get(h); |
| 1149 |
int start_x = history[1]; |
| 1150 |
int start_y = history[2]; |
| 1151 |
for (h++; h < historyMouseEvent.size(); h++) { |
| 1152 |
history = historyMouseEvent.get(h); |
| 1153 |
if (history[0] == SWT.MouseUp) { |
| 1154 |
break; |
| 1155 |
} |
| 1156 |
int x = history[1]; |
| 1157 |
int y = history[2]; |
| 1158 |
if (toolKind == ScreenshotToolbar.Draw.FREE.hashCode()) { |
| 1159 |
workImageGC.drawLine(start_x, start_y, x, y); |
| 1160 |
start_x = x; |
| 1161 |
start_y = y; |
| 1162 |
} else { |
| 1163 |
if (start_x == x && start_y == y) { |
| 1164 |
workImageGC.drawLine(start_x, start_y, x, y); |
| 1165 |
} else { |
| 1166 |
Color backColor; |
| 1167 |
int rounded; |
| 1168 |
int width = x - start_x; |
| 1169 |
int height = y - start_y; |
| 1170 |
if (toolKind == ScreenshotToolbar.Draw.LINE.hashCode()) { |
| 1171 |
workImageGC.drawLine(start_x, start_y, x, y); |
| 1172 |
} else if (toolKind == ScreenshotToolbar.Draw.BOX.hashCode()) { |
| 1173 |
workImageGC.drawRectangle(start_x, start_y, width, height); |
| 1174 |
} else if (toolKind == ScreenshotToolbar.Draw.RBOX.hashCode()) { |
| 1175 |
rounded = boldlKind * 8; |
| 1176 |
workImageGC.drawRoundRectangle(start_x, start_y, width, height, rounded, rounded); |
| 1177 |
} else if (toolKind == ScreenshotToolbar.Draw.OVAL.hashCode()) { |
| 1178 |
workImageGC.drawOval(start_x, start_y, width, height); |
| 1179 |
} else if (toolKind == ScreenshotToolbar.Draw.FILL_BOX.hashCode()) { |
| 1180 |
backColor = workImageGC.getBackground(); |
| 1181 |
workImageGC.setBackground(workImageGC.getForeground()); |
| 1182 |
workImageGC.fillRectangle(start_x, start_y, width, height); |
| 1183 |
workImageGC.setBackground(backColor); |
| 1184 |
} else if (toolKind == ScreenshotToolbar.Draw.FILL_RBOX.hashCode()) { |
| 1185 |
rounded = boldlKind * 8; |
| 1186 |
backColor = workImageGC.getBackground(); |
| 1187 |
workImageGC.setBackground(workImageGC.getForeground()); |
| 1188 |
workImageGC.fillRoundRectangle(start_x, start_y, width, height, rounded, rounded); |
| 1189 |
workImageGC.setBackground(backColor); |
| 1190 |
} else if (toolKind == ScreenshotToolbar.Draw.FILL_OVAL.hashCode()) { |
| 1191 |
backColor = workImageGC.getBackground(); |
| 1192 |
workImageGC.setBackground(workImageGC.getForeground()); |
| 1193 |
workImageGC.fillOval(start_x, start_y, width, height); |
| 1194 |
workImageGC.setBackground(backColor); |
| 1195 |
} else if (toolKind == ScreenshotToolbar.Tool.TEXT.hashCode()) { |
| 1196 |
StringBuffer text = historyDrawText.get(c); |
| 1197 |
FontData fontData = new FontData(historyDrawFont.get(c)); |
| 1198 |
workImageGC.setFont(new Font(getShell().getDisplay(), fontData)); |
| 1199 |
workImageGC.setClipping(start_x, start_y, width, height); |
| 1200 |
workImageGC.drawText(text.toString(), start_x, start_y, true); |
| 1201 |
workImageGC.setClipping((Rectangle) null); |
| 1202 |
} |
| 1203 |
} |
| 1204 |
} |
| 1205 |
} |
| 1206 |
} |
| 1207 |
|
| 1208 |
workImageGC.setForeground(markColor); |
| 1209 |
workImageGC.setLineStyle(toolbar.getLineStyle()); |
| 1210 |
workImageGC.setLineWidth(toolbar.getLineBold()); |
| 1211 |
workImageGC.setFont(markFont); |
| 1212 |
canvas.redraw(); |
| 1213 |
} |
| 1214 |
|
| 814 |
/** |
1215 |
/** |
| 815 |
* Decorates the screenshot canvas with the selection rectangle, resize grab points and other adornments |
1216 |
* Decorates the screenshot canvas with the selection rectangle, resize grab points and other adornments |
| 816 |
*/ |
1217 |
*/ |
|
Lines 850-863
Link Here
|
| 850 |
} |
1251 |
} |
| 851 |
|
1252 |
|
| 852 |
/** |
1253 |
/** |
| 853 |
* Connects the previous mark point to the new reference point, by drawing a new line |
1254 |
* Connects the previous mark point to the new reference point, by drawing a new line, rectangle or oval |
| 854 |
*/ |
1255 |
*/ |
| 855 |
private void drawMarkLine(int x, int y) { |
1256 |
private void drawMarkLine(int x, int y) { |
| 856 |
if (startPoint != null) { |
1257 |
if (startPoint != null) { |
| 857 |
clearAction.setEnabled(true); |
1258 |
toolbar.setEnabled(ScreenshotToolbar.Clear.CLEAR, true); |
| 858 |
workImageGC.drawLine(startPoint.x, startPoint.y, x, y); |
1259 |
if (toolbar.getTool() == ScreenshotToolbar.Tool.TEXT) { |
| 859 |
startPoint.x = x; |
1260 |
workImageGC.drawImage(previousImage, 0, 0); |
| 860 |
startPoint.y = y; |
1261 |
if (startPoint.x == x && startPoint.y == y) { |
|
|
1262 |
workImageGC.drawLine(startPoint.x, startPoint.y, x, y); |
| 1263 |
} else { |
| 1264 |
int width = x - startPoint.x; |
| 1265 |
int height = y - startPoint.y; |
| 1266 |
workImageGC.fillRectangle(startPoint.x, startPoint.y, width, height); |
| 1267 |
workImageGC.drawRectangle(startPoint.x, startPoint.y, width, height); |
| 1268 |
} |
| 1269 |
} else { |
| 1270 |
ScreenshotToolbar.Draw draw = toolbar.getDrawTool(); |
| 1271 |
if (draw == ScreenshotToolbar.Draw.FREE) { |
| 1272 |
workImageGC.drawLine(startPoint.x, startPoint.y, x, y); |
| 1273 |
startPoint.x = x; |
| 1274 |
startPoint.y = y; |
| 1275 |
} else { |
| 1276 |
workImageGC.drawImage(previousImage, 0, 0); |
| 1277 |
if (startPoint.x == x && startPoint.y == y) { |
| 1278 |
workImageGC.drawLine(startPoint.x, startPoint.y, x, y); |
| 1279 |
} else { |
| 1280 |
int width = x - startPoint.x; |
| 1281 |
int height = y - startPoint.y; |
| 1282 |
if (draw == ScreenshotToolbar.Draw.LINE) { |
| 1283 |
workImageGC.drawLine(startPoint.x, startPoint.y, x, y); |
| 1284 |
} else if (draw == ScreenshotToolbar.Draw.BOX) { |
| 1285 |
workImageGC.drawRectangle(startPoint.x, startPoint.y, width, height); |
| 1286 |
} else if (draw == ScreenshotToolbar.Draw.RBOX) { |
| 1287 |
int rounded = toolbar.getLineBold() * 8; |
| 1288 |
workImageGC.drawRoundRectangle(startPoint.x, startPoint.y, width, height, rounded, rounded); |
| 1289 |
} else if (draw == ScreenshotToolbar.Draw.OVAL) { |
| 1290 |
workImageGC.drawOval(startPoint.x, startPoint.y, width, height); |
| 1291 |
} else if (draw == ScreenshotToolbar.Draw.FILL_BOX) { |
| 1292 |
Color backColor = workImageGC.getBackground(); |
| 1293 |
workImageGC.setBackground(markColor); |
| 1294 |
workImageGC.fillRectangle(startPoint.x, startPoint.y, width, height); |
| 1295 |
workImageGC.setBackground(backColor); |
| 1296 |
} else if (draw == ScreenshotToolbar.Draw.FILL_RBOX) { |
| 1297 |
int rounded = toolbar.getLineBold() * 8; |
| 1298 |
Color backColor = workImageGC.getBackground(); |
| 1299 |
workImageGC.setBackground(markColor); |
| 1300 |
workImageGC.fillRoundRectangle(startPoint.x, startPoint.y, width, height, rounded, rounded); |
| 1301 |
workImageGC.setBackground(backColor); |
| 1302 |
} else if (draw == ScreenshotToolbar.Draw.FILL_OVAL) { |
| 1303 |
Color backColor = workImageGC.getBackground(); |
| 1304 |
workImageGC.setBackground(markColor); |
| 1305 |
workImageGC.fillOval(startPoint.x, startPoint.y, width, height); |
| 1306 |
workImageGC.setBackground(backColor); |
| 1307 |
} |
| 1308 |
} |
| 1309 |
} |
| 1310 |
} |
| 861 |
canvas.redraw(); |
1311 |
canvas.redraw(); |
| 862 |
} |
1312 |
} |
| 863 |
} |
1313 |
} |