/******************************************************************************* * Copyright (c) 2013 Bundlemaker project team. * 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 * * Contributors: * Bundlemaker project team - initial API and implementation ******************************************************************************/ package org.bundlemaker.core.ui.view.stage.actions; import org.bundlemaker.core.ui.view.stage.internal.Activator; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.swt.graphics.Image; /** * @author Nils Hartmann (nils@nilshartmann.net) * */ public enum StageIcons { // -*- Add Mode Icons -*- ADD_ARTIFACTS_ICON("icons/stage-view-add.png"), // ADD_CHILD_ARTIFACTS_ICON("icons/stage-view-add-children.png"), // ADD_MANUALLY_ICON("icons/stage-view-add-manual.png"), // // -*- CLEAR_STAGE("icons/clear-stage.gif"), // REMOVE_FROM_STAGE("icons/remove-artifact.gif"); /** * The bundle-relative path to the icon */ private final String path; private StageIcons(final String path) { this.path = path; } /** * Returns an image. Clients do not need to dispose the image, it will be disposed automatically. * * @return an {@link Image} */ public Image getImage() { final ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry(); Image image = imageRegistry.get(this.path); if (image == null) { addImageDescriptor(); image = imageRegistry.get(this.path); } return image; } /** * Returns an image descriptor. * * @return an {@link ImageDescriptor} */ public ImageDescriptor getImageDescriptor() { final ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry(); ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(this.path); if (imageDescriptor == null) { addImageDescriptor(); imageDescriptor = imageRegistry.getDescriptor(this.path); } return imageDescriptor; } private void addImageDescriptor() { final Activator plugin = Activator.getDefault(); final ImageDescriptor id = ImageDescriptor.createFromURL(plugin.getBundle().getEntry(this.path)); plugin.getImageRegistry().put(this.path, id); } }