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 203994
Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewAttachmentWizard.java (-4 / +24 lines)
Lines 8-13 Link Here
8
8
9
package org.eclipse.mylyn.internal.tasks.ui.wizards;
9
package org.eclipse.mylyn.internal.tasks.ui.wizards;
10
10
11
import java.io.ByteArrayOutputStream;
11
import java.io.File;
12
import java.io.File;
12
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
13
14
Lines 172-185 Link Here
172
						attachment.setFile(new File(fileName));
173
						attachment.setFile(new File(fileName));
173
						attachment.setFilename(SCREENSHOT_FILENAME);
174
						attachment.setFilename(SCREENSHOT_FILENAME);
174
					} else if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(path)) {
175
					} else if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(path)) {
175
						String contents = inputPage.getClipboardContents();
176
						Object contents = inputPage.getClipboardContents();
176
						if (contents == null) {
177
						if (contents == null) {
177
							throw new InvocationTargetException(new CoreException(new RepositoryStatus(IStatus.ERROR,
178
							throw new InvocationTargetException(new CoreException(new RepositoryStatus(IStatus.ERROR,
178
									TasksUiPlugin.ID_PLUGIN, RepositoryStatus.ERROR_INTERNAL, "Clipboard is empty",
179
									TasksUiPlugin.ID_PLUGIN, RepositoryStatus.ERROR_INTERNAL, "Clipboard is empty",
179
									null)));
180
									null)));
180
						}
181
						}
181
						attachment.setContent(contents.getBytes());
182
						
182
						attachment.setFilename(CLIPBOARD_FILENAME);
183
						if(contents instanceof String) {
184
							attachment.setContent(((String) contents).getBytes());
185
							attachment.setContentType("text/plain");
186
							attachment.setFilename(CLIPBOARD_FILENAME);
187
						} else if(contents instanceof ImageData) {
188
							ImageData data = (ImageData) contents;
189
							
190
							ByteArrayOutputStream bos = new ByteArrayOutputStream();
191
							ImageLoader loader = new ImageLoader();
192
							loader.data = new ImageData[] {data};
193
							loader.save(bos, SWT.IMAGE_PNG);
194
							
195
							attachment.setContent(bos.toByteArray());
196
							attachment.setContentType("image/png");
197
							attachment.setFilename("clipboard.png");
198
						} else {
199
							throw new InvocationTargetException(new CoreException(new RepositoryStatus(IStatus.ERROR,
200
									TasksUiPlugin.ID_PLUGIN, RepositoryStatus.ERROR_INTERNAL, "Unsupported clipboard type",
201
									null)));
202
						}
183
					} else {
203
					} else {
184
						File file = new File(path);
204
						File file = new File(path);
185
						attachment.setFile(file);
205
						attachment.setFile(file);
Lines 338-344 Link Here
338
		this.dialog = dialog;
358
		this.dialog = dialog;
339
	}
359
	}
340
360
341
	public String getClipboardContents() {
361
	public Object getClipboardContents() {
342
		return inputPage.getClipboardContents();
362
		return inputPage.getClipboardContents();
343
	}
363
	}
344
364
(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/PreviewAttachmentPage.java (-4 / +11 lines)
Lines 29-34 Link Here
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.GC;
31
import org.eclipse.swt.graphics.Image;
31
import org.eclipse.swt.graphics.Image;
32
import org.eclipse.swt.graphics.ImageData;
32
import org.eclipse.swt.graphics.Rectangle;
33
import org.eclipse.swt.graphics.Rectangle;
33
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.layout.GridLayout;
Lines 94-104 Link Here
94
		setControl(composite);
95
		setControl(composite);
95
96
96
		if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(attachment.getFilePath())) {
97
		if (InputAttachmentSourcePage.CLIPBOARD_LABEL.equals(attachment.getFilePath())) {
97
			createTextPreview(composite, ((NewAttachmentWizard) getWizard()).getClipboardContents());
98
			Object contents = ((NewAttachmentWizard) getWizard()).getClipboardContents();
99
			if(contents instanceof String) {
100
				createTextPreview(composite, (String) contents);
101
			} else if(contents instanceof ImageData) {
102
				Image originalImage = new Image(composite.getDisplay(), (ImageData) contents);
103
				createImagePreview(composite, originalImage);
104
			}
98
		} else if (PreviewAttachmentPage.isTextAttachment(attachment.getContentType())) {
105
		} else if (PreviewAttachmentPage.isTextAttachment(attachment.getContentType())) {
99
			createTextPreview(composite, attachment);
106
			createTextPreview(composite, attachment);
100
		} else if (PreviewAttachmentPage.isImageAttachment(attachment.getContentType())) {
107
		} else if (PreviewAttachmentPage.isImageAttachment(attachment.getContentType())) {
101
			createImagePreview(composite, attachment);
108
			Image originalImage = new Image(composite.getDisplay(), attachment.getFilePath());
109
			createImagePreview(composite, originalImage);
102
		} else {
110
		} else {
103
			createGenericPreview(composite, attachment);
111
			createGenericPreview(composite, attachment);
104
		}
112
		}
Lines 132-141 Link Here
132
		}
140
		}
133
	}
141
	}
134
142
135
	private void createImagePreview(Composite composite, LocalAttachment attachment) {
143
	private void createImagePreview(Composite composite, Image originalImage) {
136
		// Uses double buffering to paint the image; there was a weird behavior
144
		// Uses double buffering to paint the image; there was a weird behavior
137
		// with transparent images and flicker with large images
145
		// with transparent images and flicker with large images
138
		Image originalImage = new Image(composite.getDisplay(), attachment.getFilePath());
139
		final Image bufferedImage = new Image(composite.getDisplay(), originalImage.getBounds());
146
		final Image bufferedImage = new Image(composite.getDisplay(), originalImage.getBounds());
140
		GC gc = new GC(bufferedImage);
147
		GC gc = new GC(bufferedImage);
141
		gc.setBackground(composite.getBackground());
148
		gc.setBackground(composite.getBackground());
(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/InputAttachmentSourcePage.java (-15 / +32 lines)
Lines 41-46 Link Here
41
import org.eclipse.jface.wizard.WizardPage;
41
import org.eclipse.jface.wizard.WizardPage;
42
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.SWT;
43
import org.eclipse.swt.dnd.Clipboard;
43
import org.eclipse.swt.dnd.Clipboard;
44
import org.eclipse.swt.dnd.ImageTransfer;
44
import org.eclipse.swt.dnd.TextTransfer;
45
import org.eclipse.swt.dnd.TextTransfer;
45
import org.eclipse.swt.events.ModifyEvent;
46
import org.eclipse.swt.events.ModifyEvent;
46
import org.eclipse.swt.events.ModifyListener;
47
import org.eclipse.swt.events.ModifyListener;
Lines 48-53 Link Here
48
import org.eclipse.swt.events.SelectionEvent;
49
import org.eclipse.swt.events.SelectionEvent;
49
import org.eclipse.swt.events.ShellAdapter;
50
import org.eclipse.swt.events.ShellAdapter;
50
import org.eclipse.swt.events.ShellEvent;
51
import org.eclipse.swt.events.ShellEvent;
52
import org.eclipse.swt.graphics.ImageData;
51
import org.eclipse.swt.graphics.Point;
53
import org.eclipse.swt.graphics.Point;
52
import org.eclipse.swt.layout.GridData;
54
import org.eclipse.swt.layout.GridData;
53
import org.eclipse.swt.layout.GridLayout;
55
import org.eclipse.swt.layout.GridLayout;
Lines 114-120 Link Here
114
116
115
	private NewAttachmentWizard wizard;
117
	private NewAttachmentWizard wizard;
116
118
117
	private String clipboardContents;
119
	private Object clipboardContents;
118
120
119
	private boolean initUseClipboard = false;
121
	private boolean initUseClipboard = false;
120
122
Lines 424-442 Link Here
424
		if (inputMethod == CLIPBOARD) {
426
		if (inputMethod == CLIPBOARD) {
425
			Control c = getControl();
427
			Control c = getControl();
426
			if (c != null) {
428
			if (c != null) {
427
				Clipboard clipboard = new Clipboard(c.getDisplay());
429
				Object o = retrieveClipboardContents();
428
				Object o = clipboard.getContents(TextTransfer.getInstance());
429
				clipboard.dispose();
430
				if (o instanceof String) {
430
				if (o instanceof String) {
431
					String s = ((String) o).trim();
431
					String s = ((String) o).trim();
432
					if (s.length() > 0)
432
					if (s.length() > 0) {
433
						attachmentFound = true;
433
						attachmentFound = true;
434
					else
434
					} else {
435
						error = "Clipboard is empty";
435
						error = "Clipboard is empty";
436
				} else
436
					}
437
					error = "Clipboard does not contain text";
437
				} else if(o instanceof ImageData) {
438
			} else
438
					attachmentFound = true;
439
				} else {
440
					error = "Unsupported clipboard content";
441
				}
442
			} else {
439
				error = "Cannot retrieve clipboard contents";
443
				error = "Cannot retrieve clipboard contents";
444
			}
440
		} else if (inputMethod == SCREENSHOT) {
445
		} else if (inputMethod == SCREENSHOT) {
441
			attachmentFound = true;
446
			attachmentFound = true;
442
		} else if (inputMethod == FILE) {
447
		} else if (inputMethod == FILE) {
Lines 620-641 Link Here
620
	}
625
	}
621
626
622
	private void storeClipboardContents() {
627
	private void storeClipboardContents() {
628
		clipboardContents = retrieveClipboardContents();
629
	}
630
631
	private Object retrieveClipboardContents() {
623
		Control c = getControl();
632
		Control c = getControl();
624
		if (c != null) {
633
		if (c != null) {
625
			Clipboard clipboard = new Clipboard(c.getDisplay());
634
			Clipboard clipboard = new Clipboard(c.getDisplay());
626
			Object o = clipboard.getContents(TextTransfer.getInstance());
635
			
627
			clipboard.dispose();
636
			Object o = clipboard.getContents(ImageTransfer.getInstance());
628
			if (o instanceof String) {
637
			if(o instanceof ImageData) {
629
				clipboardContents = ((String) o).trim();
638
				return o;
639
			} else {
640
				o = clipboard.getContents(TextTransfer.getInstance());
641
				if (o instanceof String) {
642
					return ((String) o).trim();
643
				}
630
			}
644
			}
645
			
646
			clipboard.dispose();
631
		}
647
		}
648
		return null;
632
	}
649
	}
633
650
634
	public String getClipboardContents() {
651
	public Object getClipboardContents() {
635
		return clipboardContents;
652
		return clipboardContents;
636
	}
653
	}
637
654
638
	public void setClipboardContents(String attachContents) {
655
	public void setClipboardContents(Object attachContents) {
639
		clipboardContents = attachContents;
656
		clipboardContents = attachContents;
640
	}
657
	}

Return to bug 203994