[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Re: [solved] Where to put picture files?

I created a folder in the root of the project named icons.
I use this piece of code to wrap a resource that provides the location for it.
I hope it helps.


/**
* Convenience class for storing references to image descriptors
*/
public class VDImages {
static final URL BASE_URL = PicPlugin.getDefault().getBundle().getEntry("/"); //$NON-NLS-1$
static final String iconPath = "icons/"; //$NON-NLS-1$
static final String prefix = iconPath; //$NON-NLS-1$


public static final ImageDescriptor COMMENT_ACTION_IMAGE = createImageDescriptor(prefix + "commentAction.gif"); //$NON-NLS-1$

public static final ImageDescriptor LABEL_ACTION_IMAGE = createImageDescriptor(prefix + "labelAction.gif"); //$NON-NLS-1$;

    /**
     * Utility method to create an <code>ImageDescriptor</code>
     * from a path to a file.
     */
    private static ImageDescriptor createImageDescriptor(String path) {
        try {
            URL url = new URL(BASE_URL, path);
            return ImageDescriptor.createFromURL(url);
        } catch (MalformedURLException e) {
            // do nothing
        }
        return ImageDescriptor.getMissingImageDescriptor();
    }
}


Ray