View | Details | Raw Unified | Return to bug 343602 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 9-12 Link Here
9
Bundle-RequiredExecutionEnvironment: J2SE-1.5
9
Bundle-RequiredExecutionEnvironment: J2SE-1.5
10
Require-Bundle: org.eclipse.core.runtime
10
Require-Bundle: org.eclipse.core.runtime
11
Bundle-ActivationPolicy: lazy
11
Bundle-ActivationPolicy: lazy
12
Export-Package: org.eclipse.mylyn.commons.identity;x-internal:=true
12
Export-Package: org.eclipse.mylyn.commons.identity;x-internal:=true,
13
 org.eclipse.mylyn.commons.identity.gravatar;x-internal:=true
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 10-16 Link Here
10
 org.eclipse.ui.editors;resolution:=optional,
10
 org.eclipse.ui.editors;resolution:=optional,
11
 org.eclipse.ui.forms;resolution:=optional,
11
 org.eclipse.ui.forms;resolution:=optional,
12
 org.eclipse.ui.browser;resolution:=optional,
12
 org.eclipse.ui.browser;resolution:=optional,
13
 org.eclipse.mylyn.commons.screenshots;bundle-version="1.0.0"
13
 org.eclipse.mylyn.commons.screenshots;bundle-version="1.0.0",
14
 org.eclipse.mylyn.commons.identity;bundle-version="0.8.0"
14
Bundle-ActivationPolicy: lazy
15
Bundle-ActivationPolicy: lazy
15
Bundle-RequiredExecutionEnvironment: J2SE-1.5
16
Bundle-RequiredExecutionEnvironment: J2SE-1.5
16
Bundle-Activator: org.eclipse.mylyn.internal.commons.ui.CommonsUiPlugin
17
Bundle-Activator: org.eclipse.mylyn.internal.commons.ui.CommonsUiPlugin
(-)src/org/eclipse/mylyn/internal/commons/ui/identity/gravatar/GravatarDisplayCallback.java (+90 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2011 GitHub Inc.
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 *  Contributors:
9
 *    Kevin Sawicki (GitHub Inc.) - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.commons.ui.identity.gravatar;
13
14
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.mylyn.commons.identity.gravatar.Gravatar;
16
import org.eclipse.mylyn.commons.identity.gravatar.GravatarCallbackAdapter;
17
import org.eclipse.mylyn.commons.identity.gravatar.IGravatarCallback;
18
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.ui.PlatformUI;
20
21
/**
22
 * Class to wrap an {@link IGravatarCallback} instance and run it as a runnable on the UI-thread.
23
 * 
24
 * @author Kevin Sawicki (kevin@github.com)
25
 */
26
public class GravatarDisplayCallback extends GravatarCallbackAdapter {
27
28
	private final IGravatarCallback wrapped;
29
30
	private boolean async = true;
31
32
	/**
33
	 * Create gravatar display callback
34
	 * 
35
	 * @param callback
36
	 */
37
	public GravatarDisplayCallback(IGravatarCallback callback) {
38
		Assert.isNotNull(callback, "Callback cannot be null"); //$NON-NLS-1$
39
		this.wrapped = callback;
40
	}
41
42
	/**
43
	 * Set async execution of wrapped callback
44
	 * 
45
	 * @param async
46
	 * @return this callback
47
	 */
48
	public GravatarDisplayCallback setAsync(boolean async) {
49
		this.async = async;
50
		return this;
51
	}
52
53
	private void displayExec(Runnable runnable) {
54
		Display display = PlatformUI.getWorkbench().getDisplay();
55
		if (this.async) {
56
			display.asyncExec(runnable);
57
		} else {
58
			display.syncExec(runnable);
59
		}
60
	}
61
62
	/**
63
	 * @see org.eclipse.mylyn.commons.identity.gravatar.GravatarCallbackAdapter#loaded(org.eclipse.mylyn.commons.identity.gravatar.Gravatar)
64
	 */
65
	@Override
66
	public void loaded(final Gravatar avatar) {
67
		Runnable runnable = new Runnable() {
68
69
			public void run() {
70
				wrapped.loaded(avatar);
71
			}
72
		};
73
		displayExec(runnable);
74
	}
75
76
	/**
77
	 * @see org.eclipse.mylyn.commons.identity.gravatar.GravatarCallbackAdapter#error(java.lang.Exception)
78
	 */
79
	@Override
80
	public void error(final Exception exception) {
81
		Runnable runnable = new Runnable() {
82
83
			public void run() {
84
				wrapped.error(exception);
85
			}
86
		};
87
		displayExec(runnable);
88
	}
89
90
}
(-)src/org/eclipse/mylyn/internal/commons/ui/identity/gravatar/GravatarImage.java (+105 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2011 GitHub Inc.
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 *  Contributors:
9
 *    Kevin Sawicki (GitHub Inc.) - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.commons.ui.identity.gravatar;
13
14
import java.io.ByteArrayInputStream;
15
16
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.mylyn.commons.identity.gravatar.Gravatar;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWTException;
21
import org.eclipse.swt.graphics.GC;
22
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.graphics.ImageData;
24
import org.eclipse.swt.graphics.ImageLoader;
25
import org.eclipse.swt.graphics.Rectangle;
26
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.ui.PlatformUI;
28
29
/**
30
 * Gravatar image class.
31
 * 
32
 * @author Kevin Sawicki (kevin@github.com)
33
 */
34
public class GravatarImage {
35
36
	private final Gravatar gravatar;
37
38
	private ImageData data;
39
40
	/**
41
	 * Create avatar image from avatar
42
	 * 
43
	 * @param avatar
44
	 */
45
	public GravatarImage(Gravatar avatar) {
46
		Assert.isNotNull(avatar, "Avatar cannot be null"); //$NON-NLS-1$
47
		this.gravatar = avatar;
48
	}
49
50
	/**
51
	 * Get avatar image data
52
	 * 
53
	 * @return image data
54
	 */
55
	public ImageData getData() {
56
		if (this.data != null) {
57
			return this.data;
58
		}
59
60
		try {
61
			ImageData[] images = new ImageLoader().load(new ByteArrayInputStream(gravatar.getBytes()));
62
			if (images.length > 0) {
63
				this.data = images[0];
64
			} else {
65
				this.data = ImageDescriptor.getMissingImageDescriptor().getImageData();
66
			}
67
		} catch (SWTException exception) {
68
			this.data = ImageDescriptor.getMissingImageDescriptor().getImageData();
69
		}
70
		return this.data;
71
	}
72
73
	/**
74
	 * Get avatar image scaled to specified size. The returned image should be managed and properly disposed of by the
75
	 * caller.
76
	 * 
77
	 * @param size
78
	 * @return scaled image
79
	 */
80
	public Image getScaledImage(int size) {
81
		Display display = PlatformUI.getWorkbench().getDisplay();
82
		Image image = new Image(display, getData());
83
		Rectangle sourceBounds = image.getBounds();
84
85
		// Return original image and don't scale if size matches request
86
		if (sourceBounds.width == size) {
87
			return image;
88
		}
89
90
		Image scaled = new Image(display, size, size);
91
		GC gc = new GC(scaled);
92
		try {
93
			gc.setAntialias(SWT.ON);
94
			gc.setInterpolation(SWT.HIGH);
95
			Rectangle targetBounds = scaled.getBounds();
96
			gc.drawImage(image, 0, 0, sourceBounds.width, sourceBounds.height, 0, 0, targetBounds.width,
97
					targetBounds.height);
98
		} finally {
99
			gc.dispose();
100
			image.dispose();
101
		}
102
		return scaled;
103
	}
104
105
}

Return to bug 343602