Java Doc and API clean up of TMF UML Sequence diagram framework
[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
73005152
BH
39 protected Image img = null;
40
df0b8ff4
BH
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44 /**
45 * Default constructor.
46 *
47 * @param file A file name of image file.
48 */
73005152
BH
49 public ImageImpl(String file) {
50 img = getResourceImage(file);
51 }
52
df0b8ff4
BH
53 /**
54 * Copy constructor
55 *
56 * @param img_ THe image to copy
57 */
73005152
BH
58 public ImageImpl(Image img_) {
59 img = img_;
60 }
df0b8ff4
BH
61
62 // ------------------------------------------------------------------------
63 // Methods
64 // ------------------------------------------------------------------------
65 /**
66 * Returns Image object from file name.
67 *
68 * @param _name File name of image file
69 * @return image object or <code>null</code>
70 */
73005152
BH
71 public Image getResourceImage(String _name) {
72 try {
e6ace8bb 73 URL BASIC_URL = new URL("platform", "localhost", "plugin");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
73005152
BH
74 URL url = new URL(BASIC_URL, "plugin/org.eclipse.linuxtools.tmf.ui/icons/" + _name);//$NON-NLS-1$
75 ImageDescriptor img = ImageDescriptor.createFromURL(url);
76 return img.createImage();
df0b8ff4
BH
77 } catch (MalformedURLException e) {
78 TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error opening image file", e)); //$NON-NLS-1$
73005152
BH
79 }
80 return null;
81 }
82
df0b8ff4
BH
83 /*
84 * (non-Javadoc)
85 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage#getImage()
86 */
73005152
BH
87 @Override
88 public Object getImage() {
89 return img;
90 }
91
df0b8ff4
BH
92 /*
93 * (non-Javadoc)
94 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage#dispose()
95 */
73005152
BH
96 @Override
97 public void dispose() {
df0b8ff4 98 if (img != null) {
73005152 99 img.dispose();
df0b8ff4 100 }
73005152
BH
101 }
102}
This page took 0.032028 seconds and 5 git commands to generate.