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:ext.org.eclipse.jdt.internal.ui.workingsets.WorkingSetMenuContributionItem.java

License:Open Source License

@Override
public void fill(Menu menu, int index) {
    MenuItem mi = new MenuItem(menu, SWT.RADIO, index);

    String name = fWorkingSet.getLabel();

    mi.setText("&" + fId + " " + name); //$NON-NLS-1$  //$NON-NLS-2$
    if (fImage == null) {
        ImageDescriptor imageDescriptor = fWorkingSet.getImageDescriptor();
        if (imageDescriptor != null)
            fImage = imageDescriptor.createImage();
    }/*from w w  w . ja  v a 2  s  .  c  om*/
    mi.setImage(fImage);
    mi.setSelection(fWorkingSet.equals(fActionGroup.getWorkingSet()));
    mi.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
            fActionGroup.setWorkingSet(fWorkingSet, true);
            manager.addRecentWorkingSet(fWorkingSet);
        }
    });
}

From source file:fable.framework.toolbox.LookAndFeel.java

License:Open Source License

public static Button getValidatePushButton(Composite parent) {
    Button btn = new Button(parent, SWT.PUSH);
    try {//  www . j  a  v  a 2s.  c  o m
        //Platform.getBundle("YourPluginID").getEntry("/") 
        ImageDescriptor imageRequired = ImageDescriptor.createFromURL(new URL(IImagesKeys.BTN_IMG_FORWARD));
        btn.setToolTipText("Validate View");
        btn.setImage(imageRequired.createImage());
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //btn.setImage(image);
    return btn;
}

From source file:fable.framework.ui.dialog.CrystalSymmetryDialog.java

License:Open Source License

private void createButtons() {
    Composite composite = new Composite(shell, SWT.NONE);
    GridLayout gridLayout = new GridLayout(2, true);
    gridLayout.marginHeight = 0;/*from  w w  w  . j  a  v a2  s. c  om*/
    gridLayout.marginWidth = 0;

    composite.setLayout(gridLayout);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
    Button ok = new Button(composite, SWT.PUSH | SWT.RESIZE);
    ok.setText("Ok");
    ImageDescriptor descriptor = Activator.getImageDescriptor("images/add.gif");
    if (descriptor != null) {
        Image image = descriptor.createImage();
        if (image != null) {
            ok.setImage(image);

        }
    }
    ok.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    ok.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            shell.close();
        }
    });

    // Create the cancel button and add a handler
    // so that pressing it will set input to null
    Button cancel = new Button(composite, SWT.PUSH | SWT.RESIZE);
    cancel.setText("Cancel");
    descriptor = Activator.getImageDescriptor("images/delete.gif");
    if (descriptor != null) {
        Image image = descriptor.createImage();
        if (image != null) {
            cancel.setImage(image);

        }
    }
    cancel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    cancel.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            spaceGroup = 0;
            shell.close();
        }
    });

    // Set the OK button as the default, so
    // user can type input and press Enter
    // to dismiss
    shell.setDefaultButton(ok);
}

From source file:fable.imageviewer.rcp.Activator.java

License:Open Source License

/**
 * Creates the image, this should be disposed later.
 * @param path// ww  w.j av  a2 s.  c  o  m
 * @return Image
 */
public static Image getImage(String path) {
    ImageDescriptor des = imageDescriptorFromPlugin(PLUGIN_ID, path);
    return des.createImage();
}

From source file:fable.python.labelprovider.SampleTablelabelProvider.java

License:Open Source License

public Image getColumnImage(Object element, int columnIndex) {
    ImageDescriptor descriptor = null;
    ImageDescriptor sampleNotvalideDescriptor = null;
    if (element instanceof Sample) {
        Sample mySample = (Sample) element;

        if (mySample.isDirectory()) {
            descriptor = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, IImagesKeys.IMG_FOLDER);
            sampleNotvalideDescriptor = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
                    IImagesKeys.IMG_LABEL_SAMPLE_UNVALIDE);

        } else {//  w ww .jav  a 2s .co m
            descriptor = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, IImagesKeys.IMG_FILES);
            sampleNotvalideDescriptor = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
                    IImagesKeys.IMG_LABEL_SAMPLE_UNVALIDE);

        }
        // obtain the cached image corresponding to the descriptor
        if (((Sample) element).isValide()) {
            sampleImage = descriptor.createImage();
        } else {
            sampleImage = sampleNotvalideDescriptor.createImage();
        }

        return sampleImage;
    } else {
        return null;
    }
}

From source file:fede.workspace.tool.view.menu.MenuActionContributionItem.java

License:Apache License

@Override
public void fill(Menu menu, int index) {
    int style = SWT.PUSH;
    widget = new MenuItem[dy.length];
    boolean appendsepartor = false;
    for (int i = 0; i < dy.length; i++) {
        final IMenuAction aMenuAction = dy[i];

        if (aMenuAction.isMenu()) {
            IMenuAction[] menuChildren = aMenuAction.getChildren();
            if (menuChildren.length != 0) {
                MenuManager subMenuManager = new MenuManager(aMenuAction.getLabel(), aMenuAction.getId());
                subMenuManager.add(//from w w  w .j  a  v  a  2s.  co  m
                        new MenuActionContributionItem(this.workbenchWindow, this.selection, menuChildren));
                subMenuManager.fill(menu, index);
                if (index >= 0) {
                    index++;
                }
                appendsepartor = true;
            }
            continue;
        }
        if (aMenuAction.isSeparator()) {
            if (appendsepartor) {
                if (index >= 0) {
                    new MenuItem(menu, SWT.SEPARATOR, index++);
                } else {
                    new MenuItem(menu, SWT.SEPARATOR);
                }
                appendsepartor = false;
            }
            continue;
        }
        if (aMenuAction.isGroup()) {
            continue;
        }

        MenuItem mi;
        if (index >= 0) {
            mi = new MenuItem(menu, style, index++);
        } else {
            mi = new MenuItem(menu, style);
        }
        mi.setText(aMenuAction.getLabel());
        mi.setData(aMenuAction);
        appendsepartor = true;

        try {
            String url = aMenuAction.getImage();
            if (url != null && url.length() > 0) {
                Image image = WSPlugin.getDefault().getImageFromURL(url);
                ;
                if (image != null) {
                    mi.setImage(image);
                }
            } else {
                ImageDescriptor desc = (ImageDescriptor) aMenuAction.getImageDescriptor();
                if (desc != null) {
                    Image image = desc.createImage();
                    if (image != null) {
                        mi.setImage(image);
                    }
                }
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
        widget[i] = mi;
        mi.setData(REF, aMenuAction);
        mi.addListener(SWT.Dispose, this);
        mi.addListener(SWT.Selection, this);

    }
    super.fill(menu, index + dy.length);
}

From source file:fr.inria.atlanmod.emfviews.ui.EmfViewsUIPlugin.java

License:Open Source License

/**
 * Looks for an image in the icons folder.
 * //from w  w  w . j ava2 s .  c o  m
 * @param path
 *            the image path
 * @return the searched Image
 */
public static Image getImage(String path) {
    Image result = path2image.get(path);
    if (result == null && !path2image.containsKey(path)) {
        ImageDescriptor descriptor = getImageDescriptor(path);
        if (descriptor != null) {
            result = descriptor.createImage();
            path2image.put(path, result);
        }
    }
    if (result != null) {
        if (result.isDisposed()) {
            result = null;
        }
    }
    return result;
}

From source file:fr.inria.linuxtools.tmf.ui.project.model.TmfNavigatorLabelProvider.java

License:Open Source License

private static Image loadIcon(Bundle bundle, String url) {
    Activator plugin = Activator.getDefault();
    String key = bundle.getSymbolicName() + "/" + url; //$NON-NLS-1$
    Image icon = plugin.getImageRegistry().get(key);
    if (icon == null) {
        URL imageURL = bundle.getResource(url);
        ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL);
        if (descriptor != null) {
            icon = descriptor.createImage();
            plugin.getImageRegistry().put(key, icon);
        }//from  w  w  w . j a  va 2  s.c  o  m
    }
    return icon;
}

From source file:fr.inria.linuxtools.tmf.ui.views.uml2sd.drawings.impl.ImageImpl.java

License:Open Source License

/**
 * Returns Image object from file name./*from   w ww.ja  v  a 2s. com*/
 *
 * @param name File name of image file
 * @return image object or <code>null</code>
 */
private static Image createResourceImage(String name) {
    try {
        URL BASIC_URL = new URL("platform", "localhost", "plugin");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        URL url = new URL(BASIC_URL, "plugin/fr.inria.linuxtools.tmf.ui/icons/" + name);//$NON-NLS-1$
        ImageDescriptor img = ImageDescriptor.createFromURL(url);
        return img.createImage();
    } catch (MalformedURLException e) {
        Activator.getDefault().logError("Error opening image file", e); //$NON-NLS-1$
    }
    return null;
}

From source file:fr.liglab.adele.cilia.workbench.common.misc.ImageBuilder.java

License:Apache License

private static Image createImage(String imagePath) {
    Bundle bundle = Activator.getInstance().getBundle();
    URL url = FileLocator.find(bundle, new Path(imagePath), null);
    try {/*from  w w  w  . ja  va 2 s.co m*/
        url = new URL("platform:/plugin/fr.liglab.adele.cilia.workbench.common/" + imagePath);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    ImageDescriptor imageDesc = ImageDescriptor.createFromURL(url);

    return imageDesc.createImage();
}