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

Collapse All | Expand All

(-)src/org/eclipse/jface/resource/ImageDescriptor.java (-1 / +37 lines)
Lines 12-17 Link Here
12
12
13
import java.net.URL;
13
import java.net.URL;
14
14
15
import org.eclipse.jface.internal.JFaceActivator;
15
import org.eclipse.swt.SWTException;
16
import org.eclipse.swt.SWTException;
16
import org.eclipse.swt.graphics.Device;
17
import org.eclipse.swt.graphics.Device;
17
import org.eclipse.swt.graphics.Image;
18
import org.eclipse.swt.graphics.Image;
Lines 19-24 Link Here
19
import org.eclipse.swt.graphics.PaletteData;
20
import org.eclipse.swt.graphics.PaletteData;
20
import org.eclipse.swt.graphics.RGB;
21
import org.eclipse.swt.graphics.RGB;
21
import org.eclipse.swt.widgets.Display;
22
import org.eclipse.swt.widgets.Display;
23
import org.osgi.framework.Bundle;
24
import org.osgi.framework.BundleContext;
25
import org.osgi.framework.ServiceReference;
22
26
23
/**
27
/**
24
 * An image descriptor is an object that knows how to create
28
 * An image descriptor is an object that knows how to create
Lines 155-161 Link Here
155
        if (url == null) {
159
        if (url == null) {
156
            return getMissingImageDescriptor();
160
            return getMissingImageDescriptor();
157
        }
161
        }
158
        return new URLImageDescriptor(url);
162
        return new URLImageDescriptor(transformImageLocation(url));
159
    }
163
    }
160
164
161
    /* (non-Javadoc)
165
    /* (non-Javadoc)
Lines 326-329 Link Here
326
    public static ImageDescriptor getMissingImageDescriptor() {
330
    public static ImageDescriptor getMissingImageDescriptor() {
327
        return MissingImageDescriptor.getInstance();
331
        return MissingImageDescriptor.getInstance();
328
    }
332
    }
333
    
334
    /**
335
     * Transforms the {@link URL} by using an available implementation of
336
     * {@link IImageLocationTransformer}.
337
     * 
338
     * @param url
339
     *            Given image {@link URL}.
340
     * @return Transformed {@link URL}.
341
     */
342
    private static URL transformImageLocation(URL url) {
343
	URL result = url;
344
345
	Bundle bundle = JFaceActivator.getBundle();
346
	if (bundle != null) {
347
	    BundleContext bundleContext = JFaceActivator.getBundle()
348
		    .getBundleContext();
349
	    if (bundleContext != null) {
350
		ServiceReference serviceReference = bundleContext
351
			.getServiceReference(IImageLocationTransformer.class
352
				.getName());
353
		if (serviceReference != null) {
354
		    Object service = bundleContext.getService(serviceReference);
355
		    if (service != null) {
356
			IImageLocationTransformer transformer = (IImageLocationTransformer) service;
357
			result = transformer.transform(url);
358
		    }
359
		}
360
	    }
361
	}
362
363
	return result;
364
    }    
329
}
365
}
(-)src/org/eclipse/jface/resource/IImageLocationTransformer.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
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
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.resource;
13
14
import java.net.URL;
15
16
/**
17
 * An image location {@link URL} transformer. The implementation of this service
18
 * influence the loaded image within {@link ImageDescriptor#createFromURL(URL)}.
19
 * 
20
 * @since 3.4
21
 */
22
public interface IImageLocationTransformer {
23
24
	/**
25
	 * Transforms the given image location {@link URL} and returns the result.
26
	 * 
27
	 * @param url
28
	 *            Image's location {@link URL}.
29
	 * @return Transformed image location {@link URL}.
30
	 */
31
	public URL transform(URL url);
32
33
}

Return to bug 267844