tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / drawings / impl / ImageImpl.java
index 83e4f437072e72faff6c38250f54ad51e0628d22..cbf60ecafff2e45e561ca1cd91f1fe346001bf30 100755 (executable)
 /**********************************************************************
- * Copyright (c) 2005, 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation, Ericsson
  * All rights reserved.   This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * $Id: ImageImpl.java,v 1.3 2008/01/24 02:28:50 apnan Exp $
- * 
- * Contributors: 
- * IBM - Initial API and implementation
- * Bernd Hufmann - Updated for TMF
+ *
+ * Contributors:
+ *     IBM - Initial API and implementation
+ *     Bernd Hufmann - Updated for TMF
  **********************************************************************/
+
 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.impl;
 
+import java.net.MalformedURLException;
 import java.net.URL;
 
 import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage;
 import org.eclipse.swt.graphics.Image;
 
 /**
+ * Default implementation of the IImage interface.
+ *
+ * @version 1.0
  * @author sveyrier
- * 
+ *
  */
 public class ImageImpl implements IImage {
 
-    protected Image img = null;
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     * The image reference
+     */
+    protected Image fImage = null;
 
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+    /**
+     * Default constructor.
+     *
+     * @param file A file name of image file.
+     */
     public ImageImpl(String file) {
-        img = getResourceImage(file);
+        fImage = createResourceImage(file);
     }
 
-    public ImageImpl(Image img_) {
-        img = img_;
+    /**
+     * Copy constructor
+     *
+     * @param image THe image to copy
+     */
+    public ImageImpl(Image image) {
+        fImage = image;
     }
 
-    protected static URL BASIC_URL = null;
-    static {
-        // URL to get images from plug-ins
-        // perhaps we can found better code to load images ...
-        // but at this time I know this:
-        try {
-            BASIC_URL = new URL("platform", "localhost", "plugin");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        } catch (Exception E) {
-            System.err.println(E);
+    // ------------------------------------------------------------------------
+    // Methods
+    // ------------------------------------------------------------------------
+    /**
+     * Returns Image object from file name.
+     *
+     * @param name File name of image file
+     * @return image object or <code>null</code>
+     */
+    public Image getResourceImage(String name) {
+        return createResourceImage(name);
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage#getImage()
+     */
+    @Override
+    public Object getImage() {
+        return fImage;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage#dispose()
+     */
+    @Override
+    public void dispose() {
+        if (fImage != null) {
+            fImage.dispose();
         }
     }
 
-    public Image getResourceImage(String _name) {
+    /**
+     * Returns Image object from file name.
+     *
+     * @param name File name of image file
+     * @return image object or <code>null</code>
+     */
+    private static Image createResourceImage(String name) {
         try {
-            // FIXME: bhufmann: don't use org.eclipse.linuxtools.tmf.ui
-            URL url = new URL(BASIC_URL, "plugin/org.eclipse.linuxtools.tmf.ui/icons/" + _name);//$NON-NLS-1$
+            URL BASIC_URL = new URL("platform", "localhost", "plugin");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+            URL url = new URL(BASIC_URL, "plugin/org.eclipse.linuxtools.tmf.ui/icons/" + name);//$NON-NLS-1$
             ImageDescriptor img = ImageDescriptor.createFromURL(url);
             return img.createImage();
-        } catch (Exception E) {
-            System.err.println(E);
+        } catch (MalformedURLException e) {
+            Activator.getDefault().logError("Error opening image file", e);  //$NON-NLS-1$
         }
         return null;
     }
 
-    @Override
-    public Object getImage() {
-        return img;
-    }
-
-    @Override
-    public void dispose() {
-        if (img != null)
-            img.dispose();
-    }
 }
This page took 0.026249 seconds and 5 git commands to generate.