Example usage for org.eclipse.jface.resource ImageDescriptor createImage

List of usage examples for org.eclipse.jface.resource ImageDescriptor createImage

Introduction

In this page you can find the example usage for org.eclipse.jface.resource ImageDescriptor createImage.

Prototype

public Image createImage() 

Source Link

Document

Creates and returns a new SWT image for this image descriptor.

Usage

From source file:net.enilink.komma.edit.ui.provider.ExtendedImageRegistry.java

License:Open Source License

public Image getImage(Object object) {
    if (object instanceof Image) {
        return (Image) object;
    } else {//  w  ww. ja  va2  s .co m
        Display display = Display.getCurrent();
        Image result = null;
        Map<Object, Image> cache = null;
        if (display != null) {
            synchronized (display) {
                cache = images.get(display);
                if (cache == null) {
                    hookDisplayDispose(display);
                    cache = new HashMap<Object, Image>();
                    images.put(display, cache);
                }
                result = cache.get(object);
            }
        }
        if (result == null) {
            if (object instanceof ImageDescriptor) {
                ImageDescriptor imageDescriptor = (ImageDescriptor) object;
                result = imageDescriptor.createImage();
            } else if (object instanceof URL || object instanceof URI) {
                String urlString = object.toString();
                ImageDescriptor imageDescriptor = null;
                if (urlString.startsWith(modelURLPrefix)) {
                    imageDescriptor = PlatformUI.getWorkbench().getEditorRegistry()
                            .getImageDescriptor("dummy." + urlString.substring(modelURLPrefix.length()));
                } else if (urlString.startsWith(itemURLPrefix)) {
                    try {
                        URL url = new URL(urlString.substring(0, itemURLPrefix.length()));
                        String key1 = urlString.substring(itemURLPrefix.length());
                        imageDescriptor = new URLImageDescriptor(url, key1, null);
                    } catch (IOException exception) {
                        // Ignore
                    }
                } else if (urlString.startsWith(createChildURLPrefix)) {
                    try {
                        URL url = new URL(urlString.substring(0, createChildURLPrefix.length()));
                        String key1 = urlString.substring(createChildURLPrefix.length() + 1);
                        String key2 = null;
                        int index = key1.indexOf("/");
                        if (index != -1) {
                            key2 = key1.substring(index + 1);
                            key1 = key1.substring(0, index);
                        }
                        imageDescriptor = new URLImageDescriptor(url, key1, key2);
                    } catch (IOException exception) {
                        // Ignore
                    }
                } else {
                    try {
                        imageDescriptor = ImageDescriptor.createFromURL(new URL(urlString));
                    } catch (IOException exception) {
                        // Ignore
                    }
                }
                if (imageDescriptor != null) {
                    result = imageDescriptor.createImage();
                }
            } else if (object instanceof ComposedImage) {
                ImageDescriptor composedImageDescriptor = new ComposedImageDescriptor((ComposedImage) object);
                result = composedImageDescriptor.createImage();
            }

            if (result != null && display != null) {
                synchronized (display) {
                    cache.put(object, result);
                }
            }
        }
        return result;
    }
}

From source file:net.java.treaty.eclipse.vocabulary.java.ui.IconProvider.java

License:Apache License

protected Image getIcon(URI type, boolean isVariable) {

    Image result;//from ww  w. j a va 2 s .co  m

    String typeURI;
    typeURI = type.toString();

    ImageDescriptor imageDescriptor = null;

    if (JavaVocabulary.TYPE_INSTANTIABLE_CLASS.equals(typeURI)) {

        if (isVariable) {
            imageDescriptor = this.getImageDescriptor("icons/class_var.gif");
        }

        else {
            imageDescriptor = this.getImageDescriptor("icons/class.gif");
        }
    } else if (JavaVocabulary.TYPE_ABSTRACT_TYPE.equals(typeURI)) {

        if (isVariable) {
            imageDescriptor = this.getImageDescriptor("icons/interface_var.gif");
        }

        else {
            imageDescriptor = this.getImageDescriptor("icons/interface.gif");
        }
    }

    if (imageDescriptor != null) {
        result = imageDescriptor.createImage();
    }

    else {
        result = null;
    }

    return result;
}

From source file:net.java.treaty.eclipse.vocabulary.junit.ui.IconProvider.java

License:Apache License

/**
 * Get the icon//from   ww  w  .jav a  2 s.com
 * 
 * @param type
 *          the type
 * @param isVariable
 *          whether the resource is a variable
 * @return
 */
protected Image getIcon(URI type, boolean isVariable) {

    String typeName;
    typeName = type.toString();

    ImageDescriptor imageDescriptor;
    imageDescriptor = null;

    if (JUnitVocabulary.TESTCASE.equals(typeName)) {

        if (isVariable) {
            imageDescriptor = this.getImageDescriptor("icons/junit_var.gif");
        }

        else {
            imageDescriptor = this.getImageDescriptor("icons/junit.gif");
        }
    }
    // no else.

    if (imageDescriptor != null) {
        return imageDescriptor.createImage();
    }
    // no else.

    return null;
}

From source file:net.java.treaty.eclipse.vocabulary.ocl.ui.IconProvider.java

License:Open Source License

/**
 * <p>//from  ww  w  .ja v  a  2 s.c om
 * Returns the {@link Image} icon for a given type (as {@link URI}) of the
 * {@link OCLVocabulary}.
 * </p>
 * 
 * @param aType
 *            The type whose icon shall be returned.
 * @param isVariable
 *            Indicates whether or not the resource is a variable.
 * @return The icon as an {@link Image}.
 */
public Image getIcon(URI aType, boolean isVariable) {

    Image result;

    String typeName;
    ImageDescriptor anImageDescricptor;

    typeName = aType.toString();
    anImageDescricptor = null;

    /* Get the image depending on the given type. */

    /* Model types. */
    if (OCLVocabulary.TYPE_MODEL_UML2.equals(typeName)) {

        if (isVariable) {
            anImageDescricptor = this.getImageDescriptor("icons/uml2_model_var.gif");
        }

        else {
            anImageDescricptor = this.getImageDescriptor("icons/uml2_model.gif");
        }
    }

    else if (OCLVocabulary.TYPE_MODEL_EMF_ECORE.equals(typeName)) {

        if (isVariable) {
            anImageDescricptor = this.getImageDescriptor("icons/ecore_model_var.gif");
        }

        else {
            anImageDescricptor = this.getImageDescriptor("icons/ecore_model.gif");
        }
    }

    else if (OCLVocabulary.TYPE_MODEL_JAVA.equals(typeName)) {

        if (isVariable) {
            anImageDescricptor = this.getImageDescriptor("icons/java_model_var.gif");
        }

        else {
            anImageDescricptor = this.getImageDescriptor("icons/java_model.gif");
        }
    }

    /* Model instance types. */
    else if (OCLVocabulary.TYPE_MODELINSTANCE_JAVA.equals(typeName)) {

        if (isVariable) {
            anImageDescricptor = this.getImageDescriptor("icons/java_instance_var.gif");
        }

        else {
            anImageDescricptor = this.getImageDescriptor("icons/java_instance.gif");
        }
    }

    /* Constraint type. */
    else if (OCLVocabulary.TYPE_OCL_FILE.equals(typeName)) {

        if (isVariable) {
            anImageDescricptor = this.getImageDescriptor("icons/ocl_var.gif");
        }

        else {
            anImageDescricptor = this.getImageDescriptor("icons/ocl.gif");
        }
    }

    /* Create the image. */
    if (anImageDescricptor != null) {
        result = anImageDescricptor.createImage();
    }

    else {
        result = null;
    }

    return result;
}

From source file:net.java.treaty.eclipse.vocabulary.owl.ui.IconProvider.java

License:Apache License

protected org.eclipse.swt.graphics.Image getIcon(URI type, boolean isVariable) {

    String typeName = type.toString();
    ImageDescriptor imageDescriptor = null;

    if (OWLVocabulary.TYPE_NAME_ONTOLOGY.equals(typeName)) {

        if (isVariable) {
            imageDescriptor = getImageDescriptor("icons/ontology_var.gif");
        }/*ww w.j a  v a2  s. c o  m*/

        else {
            imageDescriptor = getImageDescriptor("icons/ontology.gif");
        }
    }
    // no else.

    if (imageDescriptor != null) {
        return imageDescriptor.createImage();
    }
    return null;
}

From source file:net.java.treaty.eclipse.vocabulary.xml.ui.IconProvider.java

License:Apache License

/**
 * <p>/*from   w w w.  ja  va 2s  .co  m*/
 * Returns the icon for a given type (as {@link URI}).
 * </p>
 * 
 * @param type
 *          The type (as {@link URI}) whose icon shall be returned.
 * @param isVariable
 *          Indicates whether or not the resource is a variable.
 * @return The icon for a given type (as {@link URI}).
 */
protected Image getIcon(URI type, boolean isVariable) {

    String typeName;
    typeName = type.toString();

    ImageDescriptor imageDescriptor;
    imageDescriptor = null;

    if (XMLVocabulary.TYPE_NAME_XML_SCHEMA.equals(typeName)) {
        imageDescriptor = isVariable ? getImageDescriptor("icons/xsd_var.gif")
                : getImageDescriptor("icons/xsd.gif");
    }

    else if (XMLVocabulary.TYPE_NAME_XML_INSTANCE.equals(typeName)) {
        imageDescriptor = isVariable ? getImageDescriptor("icons/xml_var.gif")
                : getImageDescriptor("icons/xml.gif");
    }

    else if (XMLVocabulary.TYPE_NAME_DTD.equals(typeName)) {
        imageDescriptor = isVariable ? getImageDescriptor("icons/dtd_var.gif")
                : getImageDescriptor("icons/dtd.gif");
    }
    // no else.

    if (imageDescriptor != null) {
        return imageDescriptor.createImage();
    }

    else {
        return null;
    }
}

From source file:net.officefloor.eclipse.skin.standard.woof.StandardAccessFigure.java

License:Open Source License

/**
 * Initiate./*from  ww  w  .  ja va  2 s  .c  o m*/
 * 
 * @param context
 *            {@link AccessFigureContext}.
 */
public StandardAccessFigure(AccessFigureContext context) {

    final Color titleBarTopColour = new Color(null, 255, 248, 220);
    final Color titleBarBottomColour = new Color(null, 131, 76, 36);

    // Create the rounded rectangle container
    RoundedRectangle container = new RoundedRectangle();
    NoSpacingGridLayout containerLayout = new NoSpacingGridLayout(1);
    container.setLayoutManager(containerLayout);
    container.setBackgroundColor(titleBarTopColour);
    container.setOutline(false);

    // Create the access image
    final String ACCESS_IMAGE_KEY = WoofPlugin.PLUGIN_ID + ".access";
    Image accessImage = JFaceResources.getImageRegistry().get(ACCESS_IMAGE_KEY);
    if (accessImage == null) {
        // Create and register the image
        ImageDescriptor secureImageData = WoofPlugin.getImageDescriptor("icons/key.png");
        accessImage = secureImageData.createImage();
        JFaceResources.getImageRegistry().put(ACCESS_IMAGE_KEY, accessImage);
    }

    // Add the title bar
    TitleBarFigure titleBar = new TitleBarFigure(titleBarTopColour, titleBarBottomColour,
            new ImageFigure(accessImage));
    container.add(titleBar);
    containerLayout.setConstraint(titleBar, new GridData(SWT.FILL, 0, true, false));

    // Provide window border to content
    Figure contentPane = new Figure();
    contentPane.setLayoutManager(new NoSpacingGridLayout(1));
    contentPane.setBorder(new MarginBorder(2, 2, 2, 2));
    container.add(contentPane);
    containerLayout.setConstraint(contentPane, new GridData(SWT.FILL, 0, true, false));

    // Specify the figures
    this.setFigure(container);
    this.setContentPane(contentPane);
}

From source file:net.officefloor.eclipse.skin.standard.woof.StandardTemplateFigure.java

License:Open Source License

/**
 * Initiate./*from   w w w .jav a 2  s  .c o m*/
 * 
 * @param context
 *            {@link TemplateFigureContext}.
 */
public StandardTemplateFigure(TemplateFigureContext context) {

    // Colours
    final Color titleBarTextColor = new Color(null, 0, 0, 0);
    final Color titleBarTopColour = new Color(null, 203, 235, 255);
    final Color titleBarBottomColour = new Color(null, 0, 139, 255);
    final Color windowColour = new Color(null, 229, 229, 229);
    final Color contentColour = new Color(null, 240, 249, 255);

    // Create the figure
    Figure figure = new Figure();
    NoSpacingGridLayout layout = new NoSpacingGridLayout(2);
    figure.setLayoutManager(layout);

    // Link to template
    ConnectorFigure templateInput = new ConnectorFigure(ConnectorDirection.WEST,
            CommonWoofColours.CONNECTIONS());
    templateInput.setBorder(new MarginBorder(10, 0, 0, 0));
    ConnectionAnchor templateInputAnchor = templateInput.getConnectionAnchor();
    this.registerConnectionAnchor(WoofTemplateOutputToWoofTemplateModel.class, templateInputAnchor);
    this.registerConnectionAnchor(WoofSectionOutputToWoofTemplateModel.class, templateInputAnchor);
    this.registerConnectionAnchor(WoofAccessOutputToWoofTemplateModel.class, templateInputAnchor);
    this.registerConnectionAnchor(WoofExceptionToWoofTemplateModel.class, templateInputAnchor);
    layout.setConstraint(templateInput, new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
    figure.add(templateInput);

    // Create the rounded rectangle container
    final RoundedRectangle window = new RoundedRectangle();
    NoSpacingGridLayout windowLayout = new NoSpacingGridLayout(1);
    window.setLayoutManager(windowLayout);
    window.setBackgroundColor(windowColour);
    window.setOutline(false);
    figure.add(window);

    // Create the label for the template name
    this.templateNameFigure = new Label(context.getTemplateDisplayName());
    this.templateNameFigure.setForegroundColor(titleBarTextColor);

    // Create the image for identifying the template as secure
    final String SECURE_IMAGE_KEY = WoofPlugin.PLUGIN_ID + ".secure";
    Image secureImage = JFaceResources.getImageRegistry().get(SECURE_IMAGE_KEY);
    if (secureImage == null) {
        // Create and register the image
        ImageDescriptor secureImageData = WoofPlugin.getImageDescriptor("icons/padlock.png");
        secureImage = secureImageData.createImage();
        JFaceResources.getImageRegistry().put(SECURE_IMAGE_KEY, secureImage);
    }
    this.secureFigure = new ImageFigure(secureImage);
    this.secureFigure.setVisible(context.isTemplateSecure());

    // Create the title bar for URI and security
    TitleBarFigure titleBar = new TitleBarFigure(titleBarTopColour, titleBarBottomColour,
            this.templateNameFigure, this.secureFigure);
    window.add(titleBar);
    windowLayout.setConstraint(titleBar, new GridData(SWT.FILL, 0, true, false));

    // Provide window border to content
    Figure contentPaneWrap = new Figure();
    NoSpacingGridLayout contentPaneWrapLayout = new NoSpacingGridLayout(1);
    contentPaneWrap.setLayoutManager(contentPaneWrapLayout);
    contentPaneWrap.setBorder(new MarginBorder(4, 4, 4, 4));
    window.add(contentPaneWrap);
    windowLayout.setConstraint(contentPaneWrap, new GridData(SWT.FILL, 0, true, false));

    // Add content pane
    RectangleFigure contentPane = new RectangleFigure();
    contentPane.setLayoutManager(new NoSpacingToolbarLayout(false));
    contentPane.setBorder(new MarginBorder(2, 2, 2, 2));
    contentPane.setBackgroundColor(contentColour);
    contentPane.setOutline(false);
    contentPaneWrap.add(contentPane);
    contentPaneWrapLayout.setConstraint(contentPane, new GridData(SWT.FILL, 0, true, false));

    // Specify the figures
    this.setFigure(figure);
    this.setContentPane(contentPane);
}

From source file:net.refractions.udig.browser.ui.BrowserContainerView.java

License:Open Source License

/**
 *
 * @param name/*from ww w.j  a  va 2s . c om*/
 * @param url
 * @param desc
 * @param listen 
 */
public void addTab(String name, String url, ImageDescriptor desc, LocationListener listen) {
    if (desc != null)
        addTab(name, url, desc.createImage(), listen);
    else
        addTab(name, url, (Image) null, listen);
}

From source file:net.refractions.udig.catalog.imageio.mosaicwizard.MosaicImportWizard.java

License:Open Source License

public void init(IWorkbench workbench, IStructuredSelection selection) {
    setWindowTitle("Imagery to Mosaic import");
    ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry();
    ImageDescriptor banner = imageRegistry.getDescriptor(WIZBAN_GIF);
    if (banner == null) {
        URL bannerURL = Activator.getDefault().getBundle().getEntry(WIZBAN_GIF);
        banner = ImageDescriptor.createFromURL(bannerURL);
        imageRegistry.put(WIZBAN_GIF, banner);
    }// w w w  . j a  va2s  .co m
    Image image = banner.createImage();

    setDefaultPageImageDescriptor(banner);
    setNeedsProgressMonitor(true);
    mainPage = new MosaicImportWizardPage("Imagery to Mosaic import"); //$NON-NLS-1$
}