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 165169 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylar/internal/tasks/ui/wizards/PreviewAttachmentPage.java (-20 / +38 lines)
Lines 27-32 Link Here
27
import org.eclipse.swt.events.DisposeListener;
27
import org.eclipse.swt.events.DisposeListener;
28
import org.eclipse.swt.events.PaintEvent;
28
import org.eclipse.swt.events.PaintEvent;
29
import org.eclipse.swt.events.PaintListener;
29
import org.eclipse.swt.events.PaintListener;
30
import org.eclipse.swt.graphics.GC;
30
import org.eclipse.swt.graphics.Image;
31
import org.eclipse.swt.graphics.Image;
31
import org.eclipse.swt.graphics.Rectangle;
32
import org.eclipse.swt.graphics.Rectangle;
32
import org.eclipse.swt.layout.GridData;
33
import org.eclipse.swt.layout.GridData;
Lines 54-59 Link Here
54
55
55
	private static HashMap<String, String> imageTypes;
56
	private static HashMap<String, String> imageTypes;
56
57
58
	private ScrolledComposite scrolledComposite;
59
57
	static {
60
	static {
58
		textTypes = new HashMap<String, String>();
61
		textTypes = new HashMap<String, String>();
59
		imageTypes = new HashMap<String, String>();
62
		imageTypes = new HashMap<String, String>();
Lines 129-158 Link Here
129
	}
132
	}
130
133
131
	private void createImagePreview(Composite composite, LocalAttachment attachment) {
134
	private void createImagePreview(Composite composite, LocalAttachment attachment) {
132
		final Image image = new Image(composite.getDisplay(), attachment.getFilePath());
135
		// Uses double buffering to paint the image; there was a weird behavior
133
		final ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL
136
		// with transparent images and flicker with large images
134
				| SWT.BORDER);
137
		Image originalImage = new Image(composite.getDisplay(), attachment.getFilePath());
138
		final Image bufferedImage = new Image(composite.getDisplay(), originalImage.getBounds());
139
		GC gc = new GC(bufferedImage);
140
		gc.setBackground(composite.getBackground());
141
		gc.fillRectangle(originalImage.getBounds());
142
		gc.drawImage(originalImage, 0, 0);
143
		gc.dispose();
144
		originalImage.dispose();
145
146
		scrolledComposite = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
135
		scrolledComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
147
		scrolledComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
136
		scrolledComposite.setExpandHorizontal(true);
148
		scrolledComposite.setExpandHorizontal(true);
137
		scrolledComposite.setExpandVertical(true);
149
		scrolledComposite.setExpandVertical(true);
138
150
139
		Composite canvasComposite = new Composite(scrolledComposite, SWT.NONE);
151
		Composite canvasComposite = new Composite(scrolledComposite, SWT.NONE);
140
		canvasComposite.setLayout(GridLayoutFactory.fillDefaults().create());
152
		canvasComposite.setLayout(GridLayoutFactory.fillDefaults().create());
141
		Canvas canvas = new Canvas(canvasComposite, SWT.NONE);
153
		Canvas canvas = new Canvas(canvasComposite, SWT.NO_BACKGROUND);
142
		final Rectangle imgSize = image.getBounds();
154
		final Rectangle imgSize = bufferedImage.getBounds();
143
		canvas.setLayoutData(GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, true).hint(
155
		canvas.setLayoutData(GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, true).hint(
144
				imgSize.width, imgSize.height).create());
156
				imgSize.width, imgSize.height).create());
145
		canvas.addPaintListener(new PaintListener() {
157
		canvas.addPaintListener(new PaintListener() {
146
158
147
			public void paintControl(PaintEvent e) {
159
			public void paintControl(PaintEvent e) {
148
				e.gc.drawImage(image, 0, 0);
160
				e.gc.drawImage(bufferedImage, 0, 0);
149
			}
161
			}
150
162
151
		});
163
		});
152
		canvas.addDisposeListener(new DisposeListener() {
164
		canvas.addDisposeListener(new DisposeListener() {
153
165
154
			public void widgetDisposed(DisposeEvent e) {
166
			public void widgetDisposed(DisposeEvent e) {
155
				image.dispose();
167
				bufferedImage.dispose();
156
			}
168
			}
157
169
158
		});
170
		});
Lines 163-184 Link Here
163
175
164
			@Override
176
			@Override
165
			public void controlResized(ControlEvent e) {
177
			public void controlResized(ControlEvent e) {
166
				Rectangle clientArea = scrolledComposite.getClientArea();
178
				adjustScrollbars(imgSize);
167
168
				ScrollBar hBar = scrolledComposite.getHorizontalBar();
169
				hBar.setMinimum(1);
170
				hBar.setMaximum(clientArea.width - imgSize.width);
171
				hBar.setPageIncrement(hBar.getThumb());
172
				hBar.setIncrement(10);
173
174
				ScrollBar vBar = scrolledComposite.getVerticalBar();
175
				vBar.setMinimum(0);
176
				vBar.setMaximum(clientArea.height - imgSize.height);
177
				vBar.setPageIncrement(vBar.getThumb());
178
				vBar.setIncrement(10);
179
			}
179
			}
180
180
181
		});
181
		});
182
		adjustScrollbars(imgSize);
183
	}
184
185
	private void adjustScrollbars(Rectangle imgSize) {
186
		Rectangle clientArea = scrolledComposite.getClientArea();
187
188
		ScrollBar hBar = scrolledComposite.getHorizontalBar();
189
		hBar.setMinimum(0);
190
		hBar.setMaximum(imgSize.width - 1);
191
		hBar.setPageIncrement(clientArea.width);
192
		hBar.setIncrement(10);
193
194
		ScrollBar vBar = scrolledComposite.getVerticalBar();
195
		vBar.setMinimum(0);
196
		vBar.setMaximum(imgSize.height - 1);
197
		vBar.setPageIncrement(clientArea.height);
198
		vBar.setIncrement(10);
182
	}
199
	}
183
200
184
	private void createGenericPreview(Composite composite, LocalAttachment attachment) {
201
	private void createGenericPreview(Composite composite, LocalAttachment attachment) {
Lines 193-196 Link Here
193
		label.setLayoutData(new GridData(GridData.FILL_BOTH));
210
		label.setLayoutData(new GridData(GridData.FILL_BOTH));
194
		label.setText(message);
211
		label.setText(message);
195
	}
212
	}
213
196
}
214
}

Return to bug 165169