Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 160572 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/ScreenShotAttachmentPage.java (-10 / +186 lines)
Lines 14-23 Link Here
14
import org.eclipse.mylyn.internal.tasks.core.LocalAttachment;
14
import org.eclipse.mylyn.internal.tasks.core.LocalAttachment;
15
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.custom.ScrolledComposite;
16
import org.eclipse.swt.custom.ScrolledComposite;
17
import org.eclipse.swt.events.MouseEvent;
18
import org.eclipse.swt.events.MouseListener;
19
import org.eclipse.swt.events.MouseMoveListener;
17
import org.eclipse.swt.events.PaintEvent;
20
import org.eclipse.swt.events.PaintEvent;
18
import org.eclipse.swt.events.PaintListener;
21
import org.eclipse.swt.events.PaintListener;
19
import org.eclipse.swt.events.SelectionEvent;
22
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.events.SelectionListener;
23
import org.eclipse.swt.events.SelectionListener;
24
import org.eclipse.swt.graphics.Cursor;
21
import org.eclipse.swt.graphics.GC;
25
import org.eclipse.swt.graphics.GC;
22
import org.eclipse.swt.graphics.Image;
26
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.graphics.Point;
27
import org.eclipse.swt.graphics.Point;
Lines 44-49 Link Here
44
48
45
	private Button makeShotButton;
49
	private Button makeShotButton;
46
50
51
	private Button cropShotButton;
52
47
	private Button showShotButton;
53
	private Button showShotButton;
48
54
49
	private Image screenshotImage;
55
	private Image screenshotImage;
Lines 59-79 Link Here
59
65
60
	public void createControl(Composite parent) {
66
	public void createControl(Composite parent) {
61
		Composite composite = new Composite(parent, SWT.NONE);
67
		Composite composite = new Composite(parent, SWT.NONE);
62
		GridLayout gridLayout = new GridLayout();
63
		gridLayout.numColumns = 2;
64
		composite.setLayout(gridLayout);
65
		setControl(composite);
68
		setControl(composite);
66
67
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
69
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
68
		composite.setLayout(new GridLayout(3, false));
70
		composite.setLayout(new GridLayout(3, false));
69
71
70
		makeShotButton = new Button(composite, SWT.PUSH);
72
		makeShotButton = new Button(composite, SWT.PUSH);
71
		makeShotButton.setText("Take a screenshot");
73
		makeShotButton.setText("Capture full screen");
72
		makeShotButton.addSelectionListener(new SelectionListener() {
74
		makeShotButton.addSelectionListener(new SelectionListener() {
73
75
74
			public void widgetSelected(SelectionEvent e) {
76
			public void widgetSelected(SelectionEvent e) {
75
				storeScreenshotContent();
77
				storeScreenshotContent();
76
				page.setErrorMessage(null);
78
				page.setErrorMessage(null);
79
				cropShotButton.setEnabled(true);
77
				showShotButton.setEnabled(true);
80
				showShotButton.setEnabled(true);
78
			}
81
			}
79
82
Lines 82-87 Link Here
82
85
83
		});
86
		});
84
87
88
		cropShotButton = new Button(composite, SWT.PUSH);
89
		cropShotButton.setText("Crop a region");
90
		cropShotButton.addSelectionListener(new SelectionListener() {
91
92
			public void widgetSelected(SelectionEvent e) {
93
				cropScreenshotContent();
94
			}
95
96
			public void widgetDefaultSelected(SelectionEvent e) {
97
			}
98
99
		});
100
85
		showShotButton = new Button(composite, SWT.PUSH);
101
		showShotButton = new Button(composite, SWT.PUSH);
86
		showShotButton.setText("Show the screenshot");
102
		showShotButton.setText("Show the screenshot");
87
		showShotButton.addSelectionListener(new SelectionListener() {
103
		showShotButton.addSelectionListener(new SelectionListener() {
Lines 99-116 Link Here
99
		canvas.setLayoutData(GridDataFactory.fillDefaults()
115
		canvas.setLayoutData(GridDataFactory.fillDefaults()
100
				.align(SWT.FILL, SWT.FILL)
116
				.align(SWT.FILL, SWT.FILL)
101
				.grab(true, true)
117
				.grab(true, true)
102
				.span(2, 1)
118
				.span(3, 1)
103
				.create());
119
				.create());
104
120
105
		canvas.addPaintListener(new PaintListener() {
121
		canvas.addPaintListener(new PaintListener() {
106
			public void paintControl(PaintEvent e) {
122
			public void paintControl(PaintEvent e) {
107
				if (screenshotImage != null) {
123
				if (screenshotImage != null) {
108
					Rectangle screenBounds = screenshotImage.getBounds();
124
					Rectangle imageBounds = screenshotImage.getBounds();
109
					Rectangle canvasBounds = canvas.getBounds();
125
					Rectangle canvasBounds = canvas.getBounds();
110
					e.gc.drawImage(screenshotImage, 0, 0, screenBounds.width, screenBounds.height, 0, 0,
126
					if ((imageBounds.width > canvasBounds.width) || (imageBounds.height > canvasBounds.height))
111
							canvasBounds.width, canvasBounds.height);
127
						e.gc.drawImage(screenshotImage, 0, 0, imageBounds.width, imageBounds.height, 0, 0,
128
								canvasBounds.width, canvasBounds.height);
129
					else
130
						e.gc.drawImage(screenshotImage, 0, 0);
112
				} else {
131
				} else {
113
					page.setErrorMessage("Screenshot required");
132
					page.setErrorMessage("Screenshot required");
133
					cropShotButton.setEnabled(false);
114
					showShotButton.setEnabled(false);
134
					showShotButton.setEnabled(false);
115
				}
135
				}
116
			}
136
			}
Lines 148-155 Link Here
148
		display.asyncExec(new Runnable() {
168
		display.asyncExec(new Runnable() {
149
			public void run() {
169
			public void run() {
150
				GC gc = new GC(display);
170
				GC gc = new GC(display);
151
				screenshotImage = new Image(display, display.getBounds());
171
				Rectangle displayBounds = display.getBounds();
172
				screenshotImage = new Image(display, displayBounds);
152
				gc.copyArea(screenshotImage, 0, 0);
173
				gc.copyArea(screenshotImage, 0, 0);
174
				gc.drawRectangle(0, 0, displayBounds.width - 1, displayBounds.height - 1);
153
				gc.dispose();
175
				gc.dispose();
154
				canvas.redraw();
176
				canvas.redraw();
155
				wizardShell.setVisible(true);
177
				wizardShell.setVisible(true);
Lines 159-164 Link Here
159
		});
181
		});
160
	}
182
	}
161
183
184
	private void cropScreenshotContent() {
185
186
		final Point downPoint = new Point(-1, -1);
187
188
		final Rectangle newImageBounds = new Rectangle(-1, -1, -1, -1);
189
190
		final Display display = Display.getDefault();
191
		final Rectangle displayBounds = display.getBounds();
192
193
		final Shell popup = new Shell(display.getActiveShell(), SWT.SHELL_TRIM);
194
		popup.setLayout(new GridLayout());
195
		popup.setText("Crop a region of the screenshot");
196
197
		Point dialogSize = new Point(0, 0);
198
		dialogSize.x = displayBounds.width - 100;
199
		dialogSize.y = displayBounds.height - 100;
200
		Point dialoglocation = new Point(0, 0);
201
		dialoglocation.x = displayBounds.x + displayBounds.width / 2 - dialogSize.x / 2;
202
		dialoglocation.y = displayBounds.y + displayBounds.height / 2 - dialogSize.y / 2;
203
		popup.setSize(dialogSize);
204
		popup.setLocation(dialoglocation);
205
206
		final Rectangle originalBounds = screenshotImage.getBounds();
207
		final Image bufferedImage = new Image(display, originalBounds);
208
		GC gc = new GC(bufferedImage);
209
		gc.setBackground(popup.getBackground());
210
		gc.fillRectangle(originalBounds);
211
		gc.drawImage(screenshotImage, 0, 0);
212
		gc.dispose();
213
214
		Composite bc = new Composite(popup, SWT.NONE);
215
		bc.setLayout(new GridLayout(2, false));
216
217
		final Button saveButton = new Button(bc, SWT.PUSH);
218
		saveButton.setText("Save");
219
		saveButton.addSelectionListener(new SelectionListener() {
220
			public void widgetSelected(SelectionEvent e) {
221
				if (newImageBounds.x != -1 && newImageBounds.y != -1) {
222
					screenshotImage = new Image(display, newImageBounds);
223
					GC drawGc = new GC(screenshotImage);
224
					drawGc.drawImage(bufferedImage, newImageBounds.x, newImageBounds.y, newImageBounds.width,
225
							newImageBounds.height, 0, 0, newImageBounds.width, newImageBounds.height);
226
					drawGc.drawRectangle(0, 0, newImageBounds.width - 1, newImageBounds.height - 1);
227
					drawGc.dispose();
228
					canvas.redraw();
229
					popup.close();
230
				}
231
			}
232
233
			public void widgetDefaultSelected(SelectionEvent e) {
234
				// ignore		
235
			}
236
		});
237
		saveButton.setEnabled(false);
238
239
		final Button cancelButton = new Button(bc, SWT.PUSH);
240
		cancelButton.setText("Cancel");
241
		cancelButton.addSelectionListener(new SelectionListener() {
242
			public void widgetSelected(SelectionEvent e) {
243
				popup.close();
244
			}
245
246
			public void widgetDefaultSelected(SelectionEvent e) {
247
				// ignore		
248
			}
249
		});
250
251
		final ScrolledComposite sc = new ScrolledComposite(popup, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
252
		sc.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).create());
253
		final Canvas scCanvas = new Canvas(sc, SWT.DOUBLE_BUFFERED | SWT.NONE);
254
		scCanvas.setBounds(originalBounds);
255
		scCanvas.addPaintListener(new PaintListener() {
256
			public void paintControl(PaintEvent e) {
257
				if (screenshotImage != null)
258
					e.gc.drawImage(bufferedImage, 0, 0);
259
			}
260
		});
261
		sc.setContent(scCanvas);
262
263
		final GC selectionGc = new GC(scCanvas);
264
265
		final MouseMoveListener mouseMoveListener = new MouseMoveListener() {
266
			public void mouseMove(MouseEvent e) {
267
				if (downPoint.x != -1 && downPoint.y != -1) {
268
					int width = e.x - downPoint.x;
269
					int height = e.y - downPoint.y;
270
					scCanvas.redraw();
271
					selectionGc.drawRectangle(downPoint.x, downPoint.y, width, height);
272
				}
273
			}
274
		};
275
276
		final MouseListener mouseListener = new MouseListener() {
277
			public void mouseUp(MouseEvent e) {
278
				if (downPoint.x != -1 && downPoint.y != -1) {
279
280
					int width;
281
					if (e.x > originalBounds.width)
282
						width = originalBounds.width - downPoint.x;
283
					else if (e.x < 0) {
284
						width = downPoint.x;
285
						downPoint.x = 0;
286
					}
287
					else
288
						width = e.x - downPoint.x;
289
290
					int height;
291
					if (e.y > originalBounds.height)
292
						height = originalBounds.height - downPoint.y;
293
					else if (e.y < 0) {
294
						height = downPoint.y;
295
						downPoint.y = 0;
296
					} else
297
						height = e.y - downPoint.y;
298
299
					display.getActiveShell().setCursor(new Cursor(null, SWT.CURSOR_ARROW));
300
301
					selectionGc.drawRectangle(downPoint.x, downPoint.y, width, height);
302
303
					newImageBounds.x = downPoint.x;
304
					newImageBounds.y = downPoint.y;
305
					newImageBounds.width = width;
306
					newImageBounds.height = height;
307
308
					sc.removeMouseMoveListener(mouseMoveListener);
309
					sc.removeMouseListener(this);
310
					downPoint.x = -1;
311
					downPoint.y = -1;
312
313
					saveButton.setEnabled(true);
314
				}
315
			}
316
317
			public void mouseDown(MouseEvent e) {
318
				if (downPoint.x == -1 && downPoint.y == -1) {
319
					display.getActiveShell().setCursor(new Cursor(null, SWT.CURSOR_CROSS));
320
					downPoint.x = e.x;
321
					downPoint.y = e.y;
322
					selectionGc.setLineStyle(SWT.LINE_DASH);
323
					scCanvas.addMouseMoveListener(mouseMoveListener);
324
				}
325
			}
326
327
			public void mouseDoubleClick(MouseEvent e) {
328
				// ignore
329
			}
330
		};
331
332
		scCanvas.addMouseListener(mouseListener);
333
334
		popup.open();
335
336
	}
337
162
	private void showScreenshotContent() {
338
	private void showScreenshotContent() {
163
		Display display = Display.getDefault();
339
		Display display = Display.getDefault();
164
340

Return to bug 160572