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 (-11 / +122 lines)
Lines 12-23 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.monitor.core.StatusHandler;
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;
17
import org.eclipse.swt.events.PaintEvent;
18
import org.eclipse.swt.events.PaintEvent;
18
import org.eclipse.swt.events.PaintListener;
19
import org.eclipse.swt.events.PaintListener;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.events.SelectionListener;
21
import org.eclipse.swt.events.SelectionListener;
22
import org.eclipse.swt.graphics.Cursor;
21
import org.eclipse.swt.graphics.GC;
23
import org.eclipse.swt.graphics.GC;
22
import org.eclipse.swt.graphics.Image;
24
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.graphics.Point;
25
import org.eclipse.swt.graphics.Point;
Lines 29-34 Link Here
29
import org.eclipse.swt.widgets.Canvas;
31
import org.eclipse.swt.widgets.Canvas;
30
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.swt.widgets.Display;
33
import org.eclipse.swt.widgets.Display;
34
import org.eclipse.swt.widgets.Event;
35
import org.eclipse.swt.widgets.Listener;
32
import org.eclipse.swt.widgets.Shell;
36
import org.eclipse.swt.widgets.Shell;
33
37
34
/**
38
/**
Lines 42-48 Link Here
42
46
43
	private LocalAttachment attachment;
47
	private LocalAttachment attachment;
44
48
45
	private Button makeShotButton;
49
	private Button makeFullShotButton;
50
51
	private Button makeRegionShotButton;
46
52
47
	private Button showShotButton;
53
	private Button showShotButton;
48
54
Lines 50-55 Link Here
50
56
51
	private Canvas canvas;
57
	private Canvas canvas;
52
58
59
	private Point downPoint;
60
61
	private Point upPoint;
62
53
	protected ScreenShotAttachmentPage(LocalAttachment attachment) {
63
	protected ScreenShotAttachmentPage(LocalAttachment attachment) {
54
		super("ScreenShotAttachment");
64
		super("ScreenShotAttachment");
55
		setTitle("Create a screenshot");
65
		setTitle("Create a screenshot");
Lines 60-78 Link Here
60
	public void createControl(Composite parent) {
70
	public void createControl(Composite parent) {
61
		Composite composite = new Composite(parent, SWT.NONE);
71
		Composite composite = new Composite(parent, SWT.NONE);
62
		GridLayout gridLayout = new GridLayout();
72
		GridLayout gridLayout = new GridLayout();
63
		gridLayout.numColumns = 2;
73
		gridLayout.numColumns = 3;
64
		composite.setLayout(gridLayout);
74
		composite.setLayout(gridLayout);
65
		setControl(composite);
75
		setControl(composite);
66
76
67
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
77
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
68
		composite.setLayout(new GridLayout(3, false));
78
		composite.setLayout(new GridLayout(3, false));
69
79
70
		makeShotButton = new Button(composite, SWT.PUSH);
80
		makeFullShotButton = new Button(composite, SWT.PUSH);
71
		makeShotButton.setText("Take a screenshot");
81
		makeFullShotButton.setText("Capture full screen");
72
		makeShotButton.addSelectionListener(new SelectionListener() {
82
		makeFullShotButton.addSelectionListener(new SelectionListener() {
83
84
			public void widgetSelected(SelectionEvent e) {
85
				storeFullScreenshotContent();
86
				page.setErrorMessage(null);
87
				showShotButton.setEnabled(true);
88
			}
89
90
			public void widgetDefaultSelected(SelectionEvent e) {
91
			}
92
93
		});
94
95
		makeRegionShotButton = new Button(composite, SWT.PUSH);
96
		makeRegionShotButton.setText("Capture region");
97
		makeRegionShotButton.addSelectionListener(new SelectionListener() {
73
98
74
			public void widgetSelected(SelectionEvent e) {
99
			public void widgetSelected(SelectionEvent e) {
75
				storeScreenshotContent();
100
				storeRegionScreenshotContent();
76
				page.setErrorMessage(null);
101
				page.setErrorMessage(null);
77
				showShotButton.setEnabled(true);
102
				showShotButton.setEnabled(true);
78
			}
103
			}
Lines 99-114 Link Here
99
		canvas.setLayoutData(GridDataFactory.fillDefaults()
124
		canvas.setLayoutData(GridDataFactory.fillDefaults()
100
				.align(SWT.FILL, SWT.FILL)
125
				.align(SWT.FILL, SWT.FILL)
101
				.grab(true, true)
126
				.grab(true, true)
102
				.span(2, 1)
127
				.span(3, 1)
103
				.create());
128
				.create());
104
129
105
		canvas.addPaintListener(new PaintListener() {
130
		canvas.addPaintListener(new PaintListener() {
106
			public void paintControl(PaintEvent e) {
131
			public void paintControl(PaintEvent e) {
107
				if (screenshotImage != null) {
132
				if (screenshotImage != null) {
108
					Rectangle screenBounds = screenshotImage.getBounds();
133
					Rectangle imageBounds = screenshotImage.getBounds();
109
					Rectangle canvasBounds = canvas.getBounds();
134
					Rectangle canvasBounds = canvas.getBounds();
110
					e.gc.drawImage(screenshotImage, 0, 0, screenBounds.width, screenBounds.height, 0, 0,
135
					if ((imageBounds.width > canvasBounds.width) || (imageBounds.height > canvasBounds.height))
111
							canvasBounds.width, canvasBounds.height);
136
						e.gc.drawImage(screenshotImage, 0, 0, imageBounds.width, imageBounds.height, 0, 0,
137
								canvasBounds.width, canvasBounds.height);
138
					else
139
						e.gc.drawImage(screenshotImage, 0, 0);
112
				} else {
140
				} else {
113
					page.setErrorMessage("Screenshot required");
141
					page.setErrorMessage("Screenshot required");
114
					showShotButton.setEnabled(false);
142
					showShotButton.setEnabled(false);
Lines 139-145 Link Here
139
		return isPageComplete();
167
		return isPageComplete();
140
	}
168
	}
141
169
142
	private void storeScreenshotContent() {
170
	private void storeFullScreenshotContent() {
143
171
144
		final Display display = Display.getDefault();
172
		final Display display = Display.getDefault();
145
		final Shell wizardShell = getWizard().getContainer().getShell();
173
		final Shell wizardShell = getWizard().getContainer().getShell();
Lines 159-164 Link Here
159
		});
187
		});
160
	}
188
	}
161
189
190
	private void storeRegionScreenshotContent() {
191
192
		final Display display = Display.getDefault();
193
		final Rectangle displayBounds = display.getBounds();
194
		final Shell wizardShell = getWizard().getContainer().getShell();
195
196
		final GC selectionGc = new GC(display);
197
198
		final Listener moveListener = new Listener() {
199
			public void handleEvent(Event event) {
200
201
				Point cursorLocation = event.display.getCursorLocation();
202
				final int width = cursorLocation.x - downPoint.x;
203
				final int height = cursorLocation.y - downPoint.y;
204
205
				display.getActiveShell().redraw(0, 0, displayBounds.width, displayBounds.height, true);
206
				selectionGc.drawRectangle(downPoint.x, downPoint.y, width, height);
207
208
			}
209
		};
210
211
		final Listener upListener = new Listener() {
212
			public void handleEvent(Event event) {
213
				upPoint = event.display.getCursorLocation();
214
215
				display.getActiveShell().setCursor(new Cursor(null, SWT.CURSOR_ARROW));
216
				selectionGc.dispose();
217
				display.getActiveShell().redraw(0, 0, displayBounds.width, displayBounds.height, true);
218
219
				display.removeFilter(SWT.MouseMove, moveListener);
220
				display.removeFilter(SWT.MouseUp, this);
221
222
				display.asyncExec(new Runnable() {
223
					public void run() {
224
						try {
225
							int width = upPoint.x - downPoint.x;
226
							int height = upPoint.y - downPoint.y;
227
228
							Rectangle size = new Rectangle(0, 0, width, height);
229
230
							Image fullscreen = new Image(display, display.getBounds());
231
							screenshotImage = new Image(display, size);
232
233
							GC displayGc = new GC(display);
234
							displayGc.copyArea(fullscreen, 0, 0);
235
							displayGc.dispose();
236
237
							GC drawGc = new GC(screenshotImage);
238
							drawGc.drawImage(fullscreen, downPoint.x, downPoint.y, width, height, 0, 0, width, height);
239
							drawGc.dispose();
240
241
							canvas.redraw();
242
							wizardShell.setVisible(true);
243
							if (screenshotImage != null)
244
								setPageComplete(true);
245
246
						} catch (Exception e) {
247
							StatusHandler.log(e, "Take screenshot failed!");
248
							wizardShell.setVisible(true);
249
						}
250
					}
251
				});
252
			}
253
		};
254
255
		final Listener downListener = new Listener() {
256
			public void handleEvent(Event event) {
257
				downPoint = event.display.getCursorLocation();
258
259
				display.getActiveShell().setCursor(new Cursor(null, SWT.CURSOR_CROSS));
260
				selectionGc.setLineStyle(SWT.LINE_DASH);
261
262
				display.addFilter(SWT.MouseMove, moveListener);
263
				display.addFilter(SWT.MouseUp, upListener);
264
				display.removeFilter(SWT.MouseDown, this);
265
			}
266
		};
267
268
		wizardShell.setVisible(false);
269
		display.addFilter(SWT.MouseDown, downListener);
270
271
	}
272
162
	private void showScreenshotContent() {
273
	private void showScreenshotContent() {
163
		Display display = Display.getDefault();
274
		Display display = Display.getDefault();
164
275

Return to bug 160572