View Javadoc

1   /*
2    *  File: ResourceImageDescriptor.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Common Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/cpl-v10.html
10   */
11  package de.jaret.util.ui;
12  
13  import org.eclipse.jface.resource.ImageDescriptor;
14  import org.eclipse.swt.graphics.Image;
15  import org.eclipse.swt.graphics.ImageData;
16  import org.eclipse.swt.widgets.Display;
17  
18  /**
19   * @author Peter Kliem
20   * @version $Id: ResourceImageDescriptor.java 297 2007-03-12 21:38:00Z olk $
21   */
22  public class ResourceImageDescriptor extends ImageDescriptor {
23      String _rscString;
24      Class<?> _loadingClass;
25  
26      /**
27       * 
28       */
29      public ResourceImageDescriptor(String rscString, Class<?> loadingClass) {
30          this._rscString = rscString;
31          _loadingClass = loadingClass;
32      }
33  
34      public ResourceImageDescriptor(String rscString) {
35          this(rscString, null);
36      }
37  
38      /*
39       * (non-Javadoc)
40       * 
41       * @see org.eclipse.jface.resource.ImageDescriptor#getImageData()
42       */
43      public ImageData getImageData() {
44          Class<?> clazz = _loadingClass != null ? _loadingClass : this.getClass();
45          Image img = new Image(Display.getCurrent(), clazz.getResourceAsStream(_rscString));
46          return img.getImageData();
47      }
48  }