Add copyright header.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / drawings / impl / ImageImpl.java
CommitLineData
73005152 1/**********************************************************************
df0b8ff4
BH
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
4 *
73005152
BH
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
73005152
BH
9 *
10 * Contributors:
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14package org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.impl;
15
e6ace8bb 16import java.net.MalformedURLException;
73005152
BH
17import java.net.URL;
18
df0b8ff4
BH
19import org.eclipse.core.runtime.IStatus;
20import org.eclipse.core.runtime.Status;
73005152 21import org.eclipse.jface.resource.ImageDescriptor;
df0b8ff4 22import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin;
73005152
BH
23import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage;
24import org.eclipse.swt.graphics.Image;
25
26/**
df0b8ff4
BH
27 * Default implementation of the IImage interface.
28 *
29 * @version 1.0
73005152
BH
30 * @author sveyrier
31 *
32 */
33public class ImageImpl implements IImage {
34
df0b8ff4
BH
35 // ------------------------------------------------------------------------
36 // Attributes
37 // ------------------------------------------------------------------------
38
eb63f5ff
BH
39 /**
40 * The image reference
41 */
42 protected Image fImage = null;
73005152 43
df0b8ff4
BH
44 // ------------------------------------------------------------------------
45 // Constructors
46 // ------------------------------------------------------------------------
47 /**
48 * Default constructor.
49 *
50 * @param file A file name of image file.
51 */
73005152 52 public ImageImpl(String file) {
eb63f5ff 53 fImage = createResourceImage(file);
73005152
BH
54 }
55
df0b8ff4
BH
56 /**
57 * Copy constructor
58 *
eb63f5ff 59 * @param image THe image to copy
df0b8ff4 60 */
eb63f5ff
BH
61 public ImageImpl(Image image) {
62 fImage = image;
73005152 63 }
df0b8ff4
BH
64
65 // ------------------------------------------------------------------------
66 // Methods
67 // ------------------------------------------------------------------------
68 /**
69 * Returns Image object from file name.
70 *
eb63f5ff 71 * @param name File name of image file
df0b8ff4
BH
72 * @return image object or <code>null</code>
73 */
eb63f5ff
BH
74 public Image getResourceImage(String name) {
75 return createResourceImage(name);
73005152
BH
76 }
77
df0b8ff4
BH
78 /*
79 * (non-Javadoc)
80 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage#getImage()
81 */
73005152
BH
82 @Override
83 public Object getImage() {
eb63f5ff 84 return fImage;
73005152
BH
85 }
86
df0b8ff4
BH
87 /*
88 * (non-Javadoc)
89 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage#dispose()
90 */
73005152
BH
91 @Override
92 public void dispose() {
eb63f5ff
BH
93 if (fImage != null) {
94 fImage.dispose();
95 }
96 }
97
98 /**
99 * Returns Image object from file name.
100 *
101 * @param name File name of image file
102 * @return image object or <code>null</code>
103 */
104 private Image createResourceImage(String name) {
105 try {
106 URL BASIC_URL = new URL("platform", "localhost", "plugin");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
107 URL url = new URL(BASIC_URL, "plugin/org.eclipse.linuxtools.tmf.ui/icons/" + name);//$NON-NLS-1$
108 ImageDescriptor img = ImageDescriptor.createFromURL(url);
109 return img.createImage();
110 } catch (MalformedURLException e) {
9fa32496 111 TmfUiPlugin.getDefault().logError("Error opening image file", e); //$NON-NLS-1$
df0b8ff4 112 }
eb63f5ff 113 return null;
73005152 114 }
eb63f5ff 115
73005152 116}
This page took 0.032073 seconds and 5 git commands to generate.