Commit | Line | Data |
---|---|---|
73005152 BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2005, 2008, 2011 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 | * $Id: ImageImpl.java,v 1.3 2008/01/24 02:28:50 apnan Exp $ | |
8 | * | |
9 | * Contributors: | |
10 | * IBM - Initial API and implementation | |
11 | * Bernd Hufmann - Updated for TMF | |
12 | **********************************************************************/ | |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.impl; | |
14 | ||
15 | import java.net.URL; | |
16 | ||
17 | import org.eclipse.jface.resource.ImageDescriptor; | |
18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage; | |
19 | import org.eclipse.swt.graphics.Image; | |
20 | ||
21 | /** | |
22 | * @author sveyrier | |
23 | * | |
24 | */ | |
25 | public class ImageImpl implements IImage { | |
26 | ||
27 | protected Image img = null; | |
28 | ||
29 | public ImageImpl(String file) { | |
30 | img = getResourceImage(file); | |
31 | } | |
32 | ||
33 | public ImageImpl(Image img_) { | |
34 | img = img_; | |
35 | } | |
36 | ||
37 | protected static URL BASIC_URL = null; | |
38 | static { | |
39 | // URL to get images from plug-ins | |
40 | // perhaps we can found better code to load images ... | |
41 | // but at this time I know this: | |
42 | try { | |
43 | BASIC_URL = new URL("platform", "localhost", "plugin");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
44 | } catch (Exception E) { | |
45 | System.err.println(E); | |
46 | } | |
47 | } | |
48 | ||
49 | public Image getResourceImage(String _name) { | |
50 | try { | |
51 | // FIXME: bhufmann: don't use org.eclipse.linuxtools.tmf.ui | |
52 | URL url = new URL(BASIC_URL, "plugin/org.eclipse.linuxtools.tmf.ui/icons/" + _name);//$NON-NLS-1$ | |
53 | ImageDescriptor img = ImageDescriptor.createFromURL(url); | |
54 | return img.createImage(); | |
55 | } catch (Exception E) { | |
56 | System.err.println(E); | |
57 | } | |
58 | return null; | |
59 | } | |
60 | ||
61 | @Override | |
62 | public Object getImage() { | |
63 | return img; | |
64 | } | |
65 | ||
66 | @Override | |
67 | public void dispose() { | |
68 | if (img != null) | |
69 | img.dispose(); | |
70 | } | |
71 | } |