|
Lines 12-29
Link Here
|
| 12 |
import org.eclipse.jface.wizard.IWizardPage; |
12 |
import org.eclipse.jface.wizard.IWizardPage; |
| 13 |
import org.eclipse.jface.wizard.WizardPage; |
13 |
import org.eclipse.jface.wizard.WizardPage; |
| 14 |
import org.eclipse.mylyn.internal.tasks.core.LocalAttachment; |
14 |
import org.eclipse.mylyn.internal.tasks.core.LocalAttachment; |
|
|
15 |
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin; |
| 15 |
import org.eclipse.swt.SWT; |
16 |
import org.eclipse.swt.SWT; |
| 16 |
import org.eclipse.swt.custom.ScrolledComposite; |
17 |
import org.eclipse.swt.custom.ScrolledComposite; |
|
|
18 |
import org.eclipse.swt.events.ControlAdapter; |
| 19 |
import org.eclipse.swt.events.ControlEvent; |
| 20 |
import org.eclipse.swt.events.MouseEvent; |
| 21 |
import org.eclipse.swt.events.MouseListener; |
| 22 |
import org.eclipse.swt.events.MouseMoveListener; |
| 17 |
import org.eclipse.swt.events.PaintEvent; |
23 |
import org.eclipse.swt.events.PaintEvent; |
| 18 |
import org.eclipse.swt.events.PaintListener; |
24 |
import org.eclipse.swt.events.PaintListener; |
| 19 |
import org.eclipse.swt.events.SelectionEvent; |
25 |
import org.eclipse.swt.events.SelectionEvent; |
| 20 |
import org.eclipse.swt.events.SelectionListener; |
26 |
import org.eclipse.swt.events.SelectionListener; |
|
|
27 |
import org.eclipse.swt.graphics.Cursor; |
| 21 |
import org.eclipse.swt.graphics.GC; |
28 |
import org.eclipse.swt.graphics.GC; |
| 22 |
import org.eclipse.swt.graphics.Image; |
29 |
import org.eclipse.swt.graphics.Image; |
| 23 |
import org.eclipse.swt.graphics.Point; |
30 |
import org.eclipse.swt.graphics.Point; |
| 24 |
import org.eclipse.swt.graphics.Rectangle; |
31 |
import org.eclipse.swt.graphics.Rectangle; |
| 25 |
import org.eclipse.swt.layout.FillLayout; |
|
|
| 26 |
import org.eclipse.swt.layout.GridData; |
| 27 |
import org.eclipse.swt.layout.GridLayout; |
32 |
import org.eclipse.swt.layout.GridLayout; |
| 28 |
import org.eclipse.swt.widgets.Button; |
33 |
import org.eclipse.swt.widgets.Button; |
| 29 |
import org.eclipse.swt.widgets.Canvas; |
34 |
import org.eclipse.swt.widgets.Canvas; |
|
Lines 44-55
Link Here
|
| 44 |
|
49 |
|
| 45 |
private Button makeShotButton; |
50 |
private Button makeShotButton; |
| 46 |
|
51 |
|
| 47 |
private Button showShotButton; |
52 |
private Button cropShotButton; |
|
|
53 |
|
| 54 |
private Button fitShopButton; |
| 48 |
|
55 |
|
| 49 |
private Image screenshotImage; |
56 |
private Image screenshotImage; |
| 50 |
|
57 |
|
| 51 |
private Canvas canvas; |
58 |
private Canvas canvas; |
| 52 |
|
59 |
|
|
|
60 |
private ScrolledComposite scrolledComposite; |
| 61 |
|
| 53 |
protected ScreenShotAttachmentPage(LocalAttachment attachment) { |
62 |
protected ScreenShotAttachmentPage(LocalAttachment attachment) { |
| 54 |
super("ScreenShotAttachment"); |
63 |
super("ScreenShotAttachment"); |
| 55 |
setTitle("Create a screenshot"); |
64 |
setTitle("Create a screenshot"); |
|
Lines 58-121
Link Here
|
| 58 |
} |
67 |
} |
| 59 |
|
68 |
|
| 60 |
public void createControl(Composite parent) { |
69 |
public void createControl(Composite parent) { |
|
|
70 |
|
| 61 |
Composite composite = new Composite(parent, SWT.NONE); |
71 |
Composite composite = new Composite(parent, SWT.NONE); |
| 62 |
GridLayout gridLayout = new GridLayout(); |
72 |
composite.setLayout(new GridLayout()); |
| 63 |
gridLayout.numColumns = 2; |
|
|
| 64 |
composite.setLayout(gridLayout); |
| 65 |
setControl(composite); |
73 |
setControl(composite); |
| 66 |
|
74 |
|
| 67 |
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
75 |
Composite buttonsComposite = new Composite(composite, SWT.NONE); |
| 68 |
composite.setLayout(new GridLayout(3, false)); |
76 |
buttonsComposite.setLayout(new GridLayout(3, false)); |
| 69 |
|
77 |
makeShotButton = new Button(buttonsComposite, SWT.PUSH); |
| 70 |
makeShotButton = new Button(composite, SWT.PUSH); |
78 |
makeShotButton.setText("Capture full screen"); |
| 71 |
makeShotButton.setText("Take a screenshot"); |
79 |
makeShotButton.setImage(TasksUiPlugin.imageDescriptorFromPlugin(TasksUiPlugin.ID_PLUGIN, |
|
|
80 |
"icons/etool16/scr-fullscreen.gif").createImage()); |
| 72 |
makeShotButton.addSelectionListener(new SelectionListener() { |
81 |
makeShotButton.addSelectionListener(new SelectionListener() { |
| 73 |
|
82 |
|
| 74 |
public void widgetSelected(SelectionEvent e) { |
83 |
public void widgetSelected(SelectionEvent e) { |
| 75 |
storeScreenshotContent(); |
84 |
storeScreenshotContent(); |
| 76 |
page.setErrorMessage(null); |
85 |
page.setErrorMessage(null); |
| 77 |
showShotButton.setEnabled(true); |
86 |
cropShotButton.setEnabled(true); |
|
|
87 |
fitShopButton.setEnabled(true); |
| 88 |
} |
| 89 |
|
| 90 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 91 |
//ignore |
| 92 |
} |
| 93 |
|
| 94 |
}); |
| 95 |
|
| 96 |
cropShotButton = new Button(buttonsComposite, SWT.PUSH); |
| 97 |
cropShotButton.setText("Crop a region"); |
| 98 |
cropShotButton.setImage(TasksUiPlugin.imageDescriptorFromPlugin(TasksUiPlugin.ID_PLUGIN, |
| 99 |
"icons/etool16/scr-crop.gif").createImage()); |
| 100 |
cropShotButton.addSelectionListener(new SelectionListener() { |
| 101 |
|
| 102 |
public void widgetSelected(SelectionEvent e) { |
| 103 |
cropScreenshotContent(); |
| 78 |
} |
104 |
} |
| 79 |
|
105 |
|
| 80 |
public void widgetDefaultSelected(SelectionEvent e) { |
106 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
|
107 |
//ignore |
| 81 |
} |
108 |
} |
| 82 |
|
109 |
|
| 83 |
}); |
110 |
}); |
|
|
111 |
cropShotButton.setEnabled(false); |
| 84 |
|
112 |
|
| 85 |
showShotButton = new Button(composite, SWT.PUSH); |
113 |
fitShopButton = new Button(buttonsComposite, SWT.TOGGLE); |
| 86 |
showShotButton.setText("Show the screenshot"); |
114 |
fitShopButton.setText("Fit image"); |
| 87 |
showShotButton.addSelectionListener(new SelectionListener() { |
115 |
fitShopButton.setImage(TasksUiPlugin.imageDescriptorFromPlugin(TasksUiPlugin.ID_PLUGIN, |
|
|
116 |
"icons/etool16/scr-fit.gif").createImage()); |
| 117 |
fitShopButton.addSelectionListener(new SelectionListener() { |
| 88 |
|
118 |
|
| 89 |
public void widgetSelected(SelectionEvent e) { |
119 |
public void widgetSelected(SelectionEvent e) { |
| 90 |
showScreenshotContent(); |
120 |
drawCanvas(); |
| 91 |
} |
121 |
} |
| 92 |
|
122 |
|
| 93 |
public void widgetDefaultSelected(SelectionEvent e) { |
123 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
|
124 |
// ignore |
| 94 |
} |
125 |
} |
| 95 |
|
126 |
|
| 96 |
}); |
127 |
}); |
|
|
128 |
fitShopButton.setSelection(true); |
| 129 |
fitShopButton.setEnabled(false); |
| 97 |
|
130 |
|
| 98 |
canvas = new Canvas(composite, SWT.BORDER); |
131 |
scrolledComposite = new ScrolledComposite(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); |
| 99 |
canvas.setLayoutData(GridDataFactory.fillDefaults() |
132 |
scrolledComposite.setLayoutData(GridDataFactory.fillDefaults() |
| 100 |
.align(SWT.FILL, SWT.FILL) |
133 |
.align(SWT.FILL, SWT.FILL) |
| 101 |
.grab(true, true) |
134 |
.grab(true, true) |
| 102 |
.span(2, 1) |
|
|
| 103 |
.create()); |
135 |
.create()); |
| 104 |
|
136 |
|
|
|
137 |
canvas = new Canvas(scrolledComposite, SWT.DOUBLE_BUFFERED | SWT.NONE); |
| 138 |
scrolledComposite.setContent(canvas); |
| 105 |
canvas.addPaintListener(new PaintListener() { |
139 |
canvas.addPaintListener(new PaintListener() { |
| 106 |
public void paintControl(PaintEvent e) { |
140 |
public void paintControl(PaintEvent e) { |
| 107 |
if (screenshotImage != null) { |
141 |
if (screenshotImage != null) { |
| 108 |
Rectangle screenBounds = screenshotImage.getBounds(); |
142 |
if (fitShopButton.getSelection()) { |
| 109 |
Rectangle canvasBounds = canvas.getBounds(); |
143 |
Rectangle imageBounds = screenshotImage.getBounds(); |
| 110 |
e.gc.drawImage(screenshotImage, 0, 0, screenBounds.width, screenBounds.height, 0, 0, |
144 |
Rectangle canvasBounds = canvas.getBounds(); |
| 111 |
canvasBounds.width, canvasBounds.height); |
145 |
e.gc.drawImage(screenshotImage, 0, 0, imageBounds.width, imageBounds.height, 0, 0, |
|
|
146 |
canvasBounds.width, canvasBounds.height); |
| 147 |
} else |
| 148 |
e.gc.drawImage(screenshotImage, 0, 0); |
| 112 |
} else { |
149 |
} else { |
| 113 |
page.setErrorMessage("Screenshot required"); |
150 |
page.setErrorMessage("Screenshot required"); |
| 114 |
showShotButton.setEnabled(false); |
151 |
cropShotButton.setEnabled(false); |
|
|
152 |
fitShopButton.setEnabled(false); |
| 115 |
} |
153 |
} |
| 116 |
} |
154 |
} |
| 117 |
}); |
155 |
}); |
| 118 |
|
156 |
|
|
|
157 |
scrolledComposite.addControlListener(new ControlAdapter() { |
| 158 |
@Override |
| 159 |
public void controlResized(ControlEvent e) { |
| 160 |
drawCanvas(); |
| 161 |
} |
| 162 |
}); |
| 163 |
|
| 119 |
} |
164 |
} |
| 120 |
|
165 |
|
| 121 |
@Override |
166 |
@Override |
|
Lines 139-144
Link Here
|
| 139 |
return isPageComplete(); |
184 |
return isPageComplete(); |
| 140 |
} |
185 |
} |
| 141 |
|
186 |
|
|
|
187 |
private void drawCanvas() { |
| 188 |
if (fitShopButton.getSelection()) { |
| 189 |
Rectangle bounds = scrolledComposite.getBounds(); |
| 190 |
bounds.width -= 5; |
| 191 |
bounds.height -= 5; |
| 192 |
canvas.setBounds(bounds); |
| 193 |
} else { |
| 194 |
canvas.setBounds(screenshotImage.getBounds()); |
| 195 |
} |
| 196 |
scrolledComposite.redraw(); |
| 197 |
canvas.redraw(); |
| 198 |
} |
| 199 |
|
| 142 |
private void storeScreenshotContent() { |
200 |
private void storeScreenshotContent() { |
| 143 |
|
201 |
|
| 144 |
final Display display = Display.getDefault(); |
202 |
final Display display = Display.getDefault(); |
|
Lines 148-157
Link Here
|
| 148 |
display.asyncExec(new Runnable() { |
206 |
display.asyncExec(new Runnable() { |
| 149 |
public void run() { |
207 |
public void run() { |
| 150 |
GC gc = new GC(display); |
208 |
GC gc = new GC(display); |
| 151 |
screenshotImage = new Image(display, display.getBounds()); |
209 |
Rectangle displayBounds = display.getBounds(); |
|
|
210 |
screenshotImage = new Image(display, displayBounds); |
| 152 |
gc.copyArea(screenshotImage, 0, 0); |
211 |
gc.copyArea(screenshotImage, 0, 0); |
|
|
212 |
gc.drawRectangle(0, 0, displayBounds.width - 1, displayBounds.height - 1); |
| 153 |
gc.dispose(); |
213 |
gc.dispose(); |
| 154 |
canvas.redraw(); |
214 |
drawCanvas(); |
| 155 |
wizardShell.setVisible(true); |
215 |
wizardShell.setVisible(true); |
| 156 |
if (screenshotImage != null) |
216 |
if (screenshotImage != null) |
| 157 |
setPageComplete(true); |
217 |
setPageComplete(true); |
|
Lines 159-192
Link Here
|
| 159 |
}); |
219 |
}); |
| 160 |
} |
220 |
} |
| 161 |
|
221 |
|
| 162 |
private void showScreenshotContent() { |
222 |
private void cropScreenshotContent() { |
| 163 |
Display display = Display.getDefault(); |
223 |
|
|
|
224 |
final Point downPoint = new Point(-1, -1); |
| 225 |
final Rectangle newImageBounds = new Rectangle(-1, -1, -1, -1); |
| 226 |
|
| 227 |
final Display display = Display.getDefault(); |
| 228 |
final Rectangle displayBounds = display.getBounds(); |
| 164 |
|
229 |
|
| 165 |
Shell popup = new Shell(display.getActiveShell(), SWT.SHELL_TRIM); |
230 |
final Shell popup = new Shell(display.getActiveShell(), SWT.SHELL_TRIM); |
| 166 |
popup.setLayout(new FillLayout()); |
231 |
popup.setLayout(new GridLayout()); |
| 167 |
popup.setText("Screenshot Image"); |
232 |
popup.setText("Crop a region of the screenshot"); |
| 168 |
|
233 |
|
| 169 |
Rectangle displayBounds = Display.getDefault().getBounds(); |
|
|
| 170 |
Point dialogSize = new Point(0, 0); |
234 |
Point dialogSize = new Point(0, 0); |
| 171 |
dialogSize.x = displayBounds.width / 2; |
235 |
dialogSize.x = displayBounds.width - 100; |
| 172 |
dialogSize.y = displayBounds.height / 2; |
236 |
dialogSize.y = displayBounds.height - 100; |
| 173 |
Point dialoglocation = new Point(0, 0); |
237 |
Point dialoglocation = new Point(0, 0); |
| 174 |
dialoglocation.x = displayBounds.x + displayBounds.width / 2 - dialogSize.x / 2; |
238 |
dialoglocation.x = displayBounds.x + displayBounds.width / 2 - dialogSize.x / 2; |
| 175 |
dialoglocation.y = displayBounds.y + displayBounds.height / 2 - dialogSize.y / 2; |
239 |
dialoglocation.y = displayBounds.y + displayBounds.height / 2 - dialogSize.y / 2; |
| 176 |
popup.setSize(dialogSize); |
240 |
popup.setSize(dialogSize); |
| 177 |
popup.setLocation(dialoglocation); |
241 |
popup.setLocation(dialoglocation); |
| 178 |
|
242 |
|
| 179 |
ScrolledComposite sc = new ScrolledComposite(popup, SWT.V_SCROLL | SWT.H_SCROLL); |
243 |
final Rectangle originalBounds = screenshotImage.getBounds(); |
| 180 |
Canvas canvas = new Canvas(sc, SWT.NONE); |
244 |
final Image bufferedImage = new Image(display, originalBounds); |
| 181 |
sc.setContent(canvas); |
245 |
GC gc = new GC(bufferedImage); |
| 182 |
canvas.setBounds(display.getBounds()); |
246 |
gc.setBackground(popup.getBackground()); |
| 183 |
canvas.addPaintListener(new PaintListener() { |
247 |
gc.fillRectangle(originalBounds); |
|
|
248 |
gc.drawImage(screenshotImage, 0, 0); |
| 249 |
gc.dispose(); |
| 250 |
|
| 251 |
Composite bc = new Composite(popup, SWT.NONE); |
| 252 |
bc.setLayout(new GridLayout(3, false)); |
| 253 |
|
| 254 |
final Button saveButton = new Button(bc, SWT.PUSH); |
| 255 |
saveButton.setText("Save"); |
| 256 |
saveButton.addSelectionListener(new SelectionListener() { |
| 257 |
public void widgetSelected(SelectionEvent e) { |
| 258 |
if (newImageBounds.x != -1 && newImageBounds.y != -1) { |
| 259 |
screenshotImage = new Image(display, newImageBounds); |
| 260 |
GC drawGc = new GC(screenshotImage); |
| 261 |
drawGc.drawImage(bufferedImage, newImageBounds.x, newImageBounds.y, newImageBounds.width, |
| 262 |
newImageBounds.height, 0, 0, newImageBounds.width, newImageBounds.height); |
| 263 |
drawGc.drawRectangle(0, 0, newImageBounds.width - 1, newImageBounds.height - 1); |
| 264 |
drawGc.dispose(); |
| 265 |
drawCanvas(); |
| 266 |
popup.close(); |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 271 |
// ignore |
| 272 |
} |
| 273 |
}); |
| 274 |
saveButton.setEnabled(false); |
| 275 |
|
| 276 |
final Button cancelButton = new Button(bc, SWT.PUSH); |
| 277 |
cancelButton.setText("Cancel"); |
| 278 |
cancelButton.addSelectionListener(new SelectionListener() { |
| 279 |
public void widgetSelected(SelectionEvent e) { |
| 280 |
popup.close(); |
| 281 |
} |
| 282 |
|
| 283 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 284 |
// ignore |
| 285 |
} |
| 286 |
}); |
| 287 |
|
| 288 |
final ScrolledComposite sc = new ScrolledComposite(popup, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); |
| 289 |
sc.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).create()); |
| 290 |
final Canvas scCanvas = new Canvas(sc, SWT.DOUBLE_BUFFERED | SWT.NONE); |
| 291 |
scCanvas.setBounds(originalBounds); |
| 292 |
scCanvas.addPaintListener(new PaintListener() { |
| 184 |
public void paintControl(PaintEvent e) { |
293 |
public void paintControl(PaintEvent e) { |
| 185 |
if (screenshotImage != null) |
294 |
if (screenshotImage != null) |
| 186 |
e.gc.drawImage(screenshotImage, 0, 0); |
295 |
e.gc.drawImage(bufferedImage, 0, 0); |
| 187 |
} |
296 |
} |
| 188 |
}); |
297 |
}); |
|
|
298 |
sc.setContent(scCanvas); |
| 299 |
|
| 300 |
final GC selectionGc = new GC(scCanvas); |
| 301 |
|
| 302 |
final MouseMoveListener mouseMoveListener = new MouseMoveListener() { |
| 303 |
public void mouseMove(MouseEvent e) { |
| 304 |
if (downPoint.x != -1 && downPoint.y != -1) { |
| 305 |
int width = e.x - downPoint.x; |
| 306 |
int height = e.y - downPoint.y; |
| 307 |
scCanvas.redraw(); |
| 308 |
selectionGc.drawRectangle(downPoint.x, downPoint.y, width, height); |
| 309 |
} |
| 310 |
} |
| 311 |
}; |
| 312 |
|
| 313 |
final MouseListener mouseListener = new MouseListener() { |
| 314 |
public void mouseUp(MouseEvent e) { |
| 315 |
if (downPoint.x != -1 && downPoint.y != -1) { |
| 316 |
|
| 317 |
int width; |
| 318 |
if (e.x > originalBounds.width) { |
| 319 |
width = originalBounds.width - downPoint.x; |
| 320 |
} else if (e.x < 0) { |
| 321 |
width = downPoint.x; |
| 322 |
downPoint.x = 0; |
| 323 |
} else { |
| 324 |
width = e.x - downPoint.x; |
| 325 |
} |
| 326 |
|
| 327 |
int height; |
| 328 |
if (e.y > originalBounds.height) { |
| 329 |
height = originalBounds.height - downPoint.y; |
| 330 |
} else if (e.y < 0) { |
| 331 |
height = downPoint.y; |
| 332 |
downPoint.y = 0; |
| 333 |
} else { |
| 334 |
height = e.y - downPoint.y; |
| 335 |
} |
| 336 |
|
| 337 |
display.getActiveShell().setCursor(new Cursor(null, SWT.CURSOR_ARROW)); |
| 338 |
|
| 339 |
selectionGc.drawRectangle(downPoint.x, downPoint.y, width, height); |
| 340 |
|
| 341 |
newImageBounds.x = downPoint.x; |
| 342 |
newImageBounds.y = downPoint.y; |
| 343 |
newImageBounds.width = width; |
| 344 |
newImageBounds.height = height; |
| 345 |
|
| 346 |
sc.removeMouseMoveListener(mouseMoveListener); |
| 347 |
sc.removeMouseListener(this); |
| 348 |
downPoint.x = -1; |
| 349 |
downPoint.y = -1; |
| 350 |
|
| 351 |
saveButton.setEnabled(true); |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
public void mouseDown(MouseEvent e) { |
| 356 |
if (downPoint.x == -1 && downPoint.y == -1) { |
| 357 |
display.getActiveShell().setCursor(new Cursor(null, SWT.CURSOR_CROSS)); |
| 358 |
downPoint.x = e.x; |
| 359 |
downPoint.y = e.y; |
| 360 |
selectionGc.setLineStyle(SWT.LINE_DASH); |
| 361 |
scCanvas.addMouseMoveListener(mouseMoveListener); |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
public void mouseDoubleClick(MouseEvent e) { |
| 366 |
// ignore |
| 367 |
} |
| 368 |
}; |
| 369 |
|
| 370 |
scCanvas.addMouseListener(mouseListener); |
| 371 |
|
| 189 |
popup.open(); |
372 |
popup.open(); |
|
|
373 |
|
| 190 |
} |
374 |
} |
| 191 |
|
375 |
|
| 192 |
public Image getScreenshotImage() { |
376 |
public Image getScreenshotImage() { |