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

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

Introduction

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

Prototype

public static ImageDescriptor createFromURL(URL url) 

Source Link

Document

Creates and returns a new image descriptor from a URL.

Usage

From source file:com.rohanclan.afae.AfaePlugin.java

License:Open Source License

/**
 * Loads an image from the icons/ directory
 * //from  w  w w. j  av a  2  s  .  c  o m
 * @param imageName
 * @return
 */
protected static ImageDescriptor getImageDescriptor(String imageName) {
    String iconPath = "icons/";
    try {
        URL installURL = getDefault().getBundle().getEntry("/");
        URL url = new URL(installURL, iconPath + imageName);

        return ImageDescriptor.createFromURL(url);
    } catch (MalformedURLException e) {
        AfaePlugin.logWarn("Asked for unknown image: " + imageName, null, AfaePlugin.class);
        // should not happen
        return ImageDescriptor.getMissingImageDescriptor();
    }
}

From source file:com.rohanclan.snippets.PluginImages.java

License:Open Source License

/**
 * add and image to the image registry/*from w  w w .  ja va2 s .co m*/
 */
protected static ImageDescriptor addImageToRegistry(String offset, String name) {
    try {
        //System.err.println(createIconFileURL(offset,name));
        ImageDescriptor result = ImageDescriptor.createFromURL(createIconFileURL(offset, name));

        //System.err.println("adding: " + name + " " + result.toString());
        IMAGE_REGISTRY.put(name, result);

        return result;
    } catch (MalformedURLException e) {
        e.printStackTrace(System.err);
        return ImageDescriptor.getMissingImageDescriptor();
    }
}

From source file:com.rohanclan.snippets.PluginImages.java

License:Open Source License

/** 
 * create an image descriptor from an offset and name 
 *//*from ww w.  j  ava  2  s.c  om*/
protected static ImageDescriptor createDescriptor(String offset, String name) {
    try {
        return ImageDescriptor.createFromURL(createIconFileURL(offset, name));
    } catch (MalformedURLException e) {
        return ImageDescriptor.getMissingImageDescriptor();
    }
}

From source file:com.runwaysdk.manager.general.MainWindow.java

License:Open Source License

@Override
protected Control createContents(final Composite parent) {
    Display display = parent.getDisplay();
    Monitor monitor = display.getPrimaryMonitor();

    parent.getShell().setSize(900, 900);
    parent.getShell().setText(shellText);
    parent.getShell().setImage(/*  w  w  w.java 2s. com*/
            ImageDescriptor.createFromURL(Object.class.getResource("/icons/Transfer.png")).createImage());

    Rectangle windowRect = parent.getShell().getBounds();
    Rectangle monitorRect = monitor.getBounds();

    int x = (monitorRect.width - windowRect.width) / 2;
    int y = (monitorRect.height - windowRect.height) / 2;

    parent.getShell().setLocation(x, y);

    Splash splash = this.createSplash(monitor);
    splash.open();

    try {
        display.syncExec(new Runnable() {
            @Override
            public void run() {
                SashForm form = new SashForm(parent, SWT.HORIZONTAL | SWT.FILL);

                ClassListView classList = new ClassListView(MainWindow.this);
                classList.createPartControl(form);
                classList.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));

                CTabFolder tabFolder = new CTabFolder(form, SWT.NONE);
                tabFolder.setUnselectedCloseVisible(false);
                tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 2, 1));
                tabFolder.setLayout(new FillLayout());
                tabFolder.setSimple(false);

                manager = new TabManager(tabFolder);

                form.setWeights(new int[] { 1, 3 });

                for (IModule module : modules) {
                    module.init(MainWindow.this);
                }
            }
        });
    } catch (Exception e) {
        splash.close();

        MainWindow.this.getConfiguration().handleError(e);

        try {
            CacheShutdown.shutdown();
        } catch (Exception exception) {
            // Do nothing
        }

        /*
         * An error has occured while trying to build the contents of the window.
         * As a result the window will never appear on screen, however the process
         * will continue to run silently. Therefore, the only solution is to have
         * the system exit when an error occurs.
         */
        System.exit(-1);
    } finally {
        if (!splash.isDisposed()) {
            splash.close();
        }
    }

    return parent;
}

From source file:com.sabre.buildergenerator.ui.wizard.GenerateBuilderWizard.java

License:Open Source License

/**
 * @return/*  ww w. jav  a2s.  c  o  m*/
 */
private ImageDescriptor createLogoDescriptor() {
    URL url = null;

    try {
        url = new URL(Activator.getDefault().getBundle().getEntry("/"), IMAGE_URL_STRING);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }

    return ImageDescriptor.createFromURL(url);
}

From source file:com.safi.workshop.navigator.DirtyDecorator.java

License:Open Source License

private void doDecorate(IDecoration decoration, DirtyMode mode) {
    String iconPath = null;//from w  w  w  . j a v a  2  s . c om
    switch (mode) {

    case NOT_COMMITTED:
        decoration.addPrefix(">");
    case COMMITTED:
        iconPath = syncedIcon;
        break;
    case NOT_PERSISTED:
        iconPath = nonPersistedIcon;

    }
    ImageDescriptor descriptor = imageMap.get(iconPath);
    if (descriptor == null) {
        URL url = Platform.find(Platform.getBundle("AsteriskSafletDesigner.diagram"), new Path(iconPath)); // NON-NLS-1
        if (url == null)
            return;
        descriptor = ImageDescriptor.createFromURL(url);
        imageMap.put(iconPath, descriptor);
    }
    decoration.addOverlay(descriptor, IDecoration.BOTTOM_LEFT);
}

From source file:com.safi.workshop.sqlexplorer.util.ImageUtil.java

License:Open Source License

/**
 * Create an image descriptor for the given image property in the text.properties file.
 * /*from  ww  w.  ja v a2s  . c o m*/
 * @param propertyName
 * @return
 */
public static ImageDescriptor getDescriptor(String propertyName) {

    try {

        if (propertyName == null) {
            return null;
        }

        // get image path
        String path = Messages.getString(propertyName);

        if (path == null || path.trim().length() == 0) {
            SQLExplorerPlugin.error("Missing image path for " + propertyName, null);
            return null;
        }

        // create image
        URL url = URLUtil.getResourceURL(path);
        return ImageDescriptor.createFromURL(url);

    } catch (Exception e) {
        SQLExplorerPlugin.error("Couldn't create image for " + propertyName, e);
        return null;
    }

}

From source file:com.safi.workshop.sqlexplorer.util.ImageUtil.java

License:Open Source License

public static ImageDescriptor getFragmentDescriptor(String fragmentId, String path) {

    try {/*from w ww . ja  v a 2s. c o m*/

        if (path == null || path.trim().length() == 0) {
            return null;
        }

        // create image
        URL url = URLUtil.getFragmentResourceURL(fragmentId, path);
        return ImageDescriptor.createFromURL(url);

    } catch (Exception e) {
        SQLExplorerPlugin.error("Couldn't create image for " + fragmentId + ": " + path, e);
        return null;
    }

}

From source file:com.safi.workshop.sqlexplorer.util.ImageUtil.java

License:Open Source License

public static Image getFragmentImage(String fragmentId, String path) {

    try {/*from  w ww .j  a  v a 2 s  .c  o m*/

        if (path == null || path.trim().length() == 0) {
            return null;
        }

        // create image
        URL url = URLUtil.getFragmentResourceURL(fragmentId, path);
        ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
        if (descriptor == null) {
            return null;
        }
        return descriptor.createImage();

    } catch (Exception e) {
        SQLExplorerPlugin.error("Couldn't create image for " + fragmentId + ": " + path, e);
        return null;
    }
}

From source file:com.salesforce.ide.ui.internal.ForceImages.java

License:Open Source License

private static ImageDescriptor create(String prefix, String name) {
    ImageDescriptor desc = ImageDescriptor.createFromURL(getImageURL(prefix, name));
    return desc;
}