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.android.ide.eclipse.ddms.ImageLoader.java

License:Apache License

/**
 * default method. only need a filename. the 2 interface methods call this one.
 * @param filename the filename of the image to load. The filename is searched for under /icons.
 * @return//  w ww .  j  a va  2 s. co  m
 */
public ImageDescriptor loadDescriptor(String filename) {
    try {
        URL newUrl = new URL(mBaseUrl, "/icons/" + filename); // $NON-NLS-1$
        return ImageDescriptor.createFromURL(newUrl);
    } catch (MalformedURLException e) {
        // we'll just return null;
    }
    return null;
}

From source file:com.aptana.browser.ImageResource.java

License:Open Source License

private static void registerImage(String key, String partialURL) {
    try {//w w  w .  jav a 2 s .co  m
        URL url = FileLocator.find(BrowserPlugin.getDefault().getBundle(), new Path(partialURL), null);
        ImageDescriptor id = ImageDescriptor.createFromURL(url);
        imageRegistry.put(key, id);
    } catch (Exception e) {
        IdeLog.logError(BrowserPlugin.getDefault(),
                MessageFormat.format("Error registering image {0} from {1}", key, partialURL), e); //$NON-NLS-1$
    }
}

From source file:com.aptana.editor.common.CommonContentAssistProcessor.java

License:Open Source License

/**
 * Do the dirty work of executing the content assist element, and then inserting it's resulting proposals. Executed
 * once per contributed content assist. This allows subclasses to manipulate individual elements or skip them if
 * necessary.//from ww  w . j av a 2 s . c o m
 * 
 * @param viewer
 * @param offset
 * @param ruby
 *            shared Ruby interpreter we're launching the content assist inside.
 * @param ce
 *            The content assist element contributed by a ruble.
 * @return
 */
protected Collection<? extends ICompletionProposal> addRubleCAProposals(ITextViewer viewer, int offset,
        Ruby ruby, ContentAssistElement ce) {
    final boolean recordPerf = PerformanceStats.isEnabled(RUBLE_PERF);
    PerformanceStats stats = null;

    CommandContext context = ce.createCommandContext();
    context.setInputStream(new ByteArrayInputStream(viewer.getDocument().get().getBytes()));
    if (recordPerf) {
        stats = PerformanceStats.getStats(RUBLE_PERF, ce.getDisplayName());
        stats.startRun();
    }
    CommandResult result = ce.execute(context);
    if (recordPerf) {
        stats.endRun();
    }
    if (result == null || !result.executedSuccessfully()) {
        return Collections.emptyList();
    }
    String output = result.getOutputString();
    if (StringUtil.isEmpty(output)) {
        return Collections.emptyList();
    }
    // This assumes that the command is returning an array that is output as a
    // string I can eval (via inspect)!
    RubyArray object = (RubyArray) ruby.evalScriptlet(output);
    RubySymbol insertSymbol = RubySymbol.newSymbol(ruby, INSERT);
    RubySymbol displaySymbol = RubySymbol.newSymbol(ruby, DISPLAY);
    RubySymbol imageSymbol = RubySymbol.newSymbol(ruby, IMAGE);
    RubySymbol tooltipSymbol = RubySymbol.newSymbol(ruby, TOOL_TIP);
    RubySymbol locationSymbol = RubySymbol.newSymbol(ruby, LOCATION);
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
    for (IRubyObject element : object.toJavaArray()) {
        String name;
        String displayName;
        String description = null;
        int length;
        String location = null;
        IContextInformation contextInfo = null;
        int replaceLength = 0;
        Image image = UIUtils.getImage(CommonEditorPlugin.getDefault(), DEFAULT_IMAGE);
        if (element instanceof RubyHash) {
            Map<?, ?> hash = (RubyHash) element;
            if (!hash.containsKey(insertSymbol)) {
                continue;
            }
            name = hash.get(insertSymbol).toString();
            length = name.length();
            if (hash.containsKey(displaySymbol)) {
                displayName = hash.get(displaySymbol).toString();
            } else {
                displayName = name;
            }
            if (hash.containsKey(locationSymbol)) {
                location = hash.get(locationSymbol).toString();
            }
            if (hash.containsKey(imageSymbol)) {
                String imagePath = hash.get(imageSymbol).toString();
                // Turn into image!
                ImageRegistry reg = CommonEditorPlugin.getDefault().getImageRegistry();
                Image fromReg = reg.get(imagePath);
                if (fromReg == null) {
                    URL imageURL = null;
                    try {
                        imageURL = new URL(imagePath);
                    } catch (MalformedURLException e) {
                        try {
                            imageURL = new File(imagePath).toURI().toURL();
                        } catch (MalformedURLException e1) {
                            IdeLog.logError(CommonEditorPlugin.getDefault(), e1);
                        }
                    }
                    if (imageURL != null) {
                        ImageDescriptor desc = ImageDescriptor.createFromURL(imageURL);
                        reg.put(imagePath, desc);
                        image = reg.get(imagePath);
                    }
                } else {
                    image = fromReg;
                }
            }
            if (hash.containsKey(tooltipSymbol)) {
                description = hash.get(tooltipSymbol).toString();
            }
            // TODO Allow hash to set offset to insert and replace length?
        } else {
            // Array of strings
            name = element.toString();
            displayName = name;
            length = name.length();
        }
        // build proposal
        CommonCompletionProposal proposal = new CommonCompletionProposal(name, offset, replaceLength, length,
                image, displayName, contextInfo, description);
        if (location != null) {
            proposal.setFileLocation(location);
        }
        // add it to the list
        proposals.add(proposal);
    }
    return proposals;
}

From source file:com.aptana.ide.core.ui.update.PluginsImageRegistry.java

License:Open Source License

public Image getImage(Plugin plugin) {
    Image image = null;//from w  w  w .j a  v  a  2 s .  c o  m
    String path = plugin.getImagePath();
    if (path != null) {
        image = fImages.get(path);
        if (image == null) {
            // generates the image from the path
            ImageDescriptor descriptor = Activator.getImageDescriptor(path);
            if (descriptor == null) {
                // could be a local file path
                try {
                    image = ImageDescriptor.createFromURL(getURL(path)).createImage();
                } catch (MalformedURLException e) {
                    // ignore
                }
            } else {
                image = descriptor.createImage();
            }
            if (image != null) {
                fImages.put(path, image);
            }
        }
    }
    return image == null ? DEFAULT_IMAGE : image;
}

From source file:com.aptana.ide.debug.internal.ui.DebugUIImages.java

License:Open Source License

/**
 * Declare an Image in the registry table.
 * /* w  ww.j av  a  2  s  .c  o  m*/
 * @param key
 *            The key to use when registering the image
 * @param path
 *            The path where the image can be found. This path is relative to where this plugin class is found (i.e.
 *            typically the packages directory)
 */
private static void declareRegistryImage(String key, String path) {
    ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
    Bundle bundle = Platform.getBundle(DebugUiPlugin.getUniqueIdentifier());
    URL url = null;
    if (bundle != null) {
        url = FileLocator.find(bundle, new Path(path), null);
        desc = ImageDescriptor.createFromURL(url);
    }
    fgImageRegistry.put(key, desc);
}

From source file:com.aptana.ide.editors.unified.actions.ToolBarContributionRegistryImpl.java

License:Open Source License

private static void loadToolBarContributions() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint ep = registry.getExtensionPoint(TOOLBAR_ID);

    if (ep != null) {
        IExtension[] extensions = ep.getExtensions();

        for (int i = 0; i < extensions.length; i++) {
            IExtension extension = extensions[i];
            IConfigurationElement[] elements = extension.getConfigurationElements();
            // initialize contributors first
            for (int j = 0; j < elements.length; j++) {
                try {
                    IConfigurationElement element = elements[j];
                    String elementName = element.getName();
                    if (elementName.equals(TAG_CONTRIBUTOR)) {
                        IToolbarRegistryContributor contributor = (IToolbarRegistryContributor) element
                                .createExecutableExtension(ATTR_CLASS);
                        contributor.contributeToToolbarRegistry(toolbarContributionRegistry);
                    }/*from w  w  w  . ja v  a 2s.  c om*/
                } catch (Exception e) {
                    IdeLog.log(UnifiedEditorsPlugin.getDefault(), IStatus.ERROR,
                            "Exception while initializing toolbar contribution registry", e); //$NON-NLS-1$
                }
            }
            for (int j = 0; j < elements.length; j++) {
                IConfigurationElement element = elements[j];
                String elementName = element.getName();
                try {
                    if (elementName.equals(TAG_ELEMENT)) {
                        String parserClass = element.getAttribute(ATTR_CLASS);
                        String language = element.getAttribute(ATTR_LANGUAGE);
                        String icon = element.getAttribute("icon"); //$NON-NLS-1$
                        String text = element.getAttribute("name"); //$NON-NLS-1$
                        String tooltip = element.getAttribute("tooltip"); //$NON-NLS-1$
                        InstanceCreator creator = null;
                        if (parserClass != null && language != null && language.length() > 0) {
                            creator = new InstanceCreator(element, ATTR_CLASS);
                        }
                        String namespaceIdentifier = extension.getNamespaceIdentifier();
                        ImageDescriptor desc = null;
                        if (icon != null && icon.length() > 0) {
                            desc = ImageDescriptor
                                    .createFromURL(Platform.getBundle(namespaceIdentifier).getEntry(icon));
                        }
                        ToolBarContribution tc = new ToolBarContribution(text, tooltip, desc, creator);
                        addContribution(language, tc);
                    }

                } catch (Exception e) {
                    IdeLog.log(UnifiedEditorsPlugin.getDefault(), IStatus.ERROR,
                            "Exception while initializing toolbar contribution registry", e); //$NON-NLS-1$
                }
            }
        }
    }
}

From source file:com.aptana.ide.installer.views.PluginImages.java

License:Open Source License

/**
 * Declare an Image in the registry table.
 * //  w w  w  .  j av  a2s .  co m
 * @param key
 *            The key to use when registering the image
 * @param path
 *            The path where the image can be found. This path is relative
 *            to where this plugin class is found (i.e. typically the
 *            packages directory)
 */
private final static void declareRegistryImage(String key, String path) {
    ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
    Bundle bundle = Activator.getDefault().getBundle();
    if (bundle != null) {
        URL url = FileLocator.find(bundle, new Path(path), null);
        desc = ImageDescriptor.createFromURL(url);
    }
    imageRegistry.put(key, desc);
}

From source file:com.aptana.ide.rcp.IDEWorkbenchAdvisor.java

License:Open Source License

/**
 * Declares an IDE-specific workbench image.
 * //from w  ww .  ja  va2s  . c o  m
 * @param symbolicName
 *            the symbolic name of the image
 * @param path
 *            the path of the image file; this path is relative to the base
 *            of the IDE plug-in
 * @param shared
 *            <code>true</code> if this is a shared image, and
 *            <code>false</code> if this is not a shared image
 * @see IWorkbenchConfigurer#declareImage
 */
private void declareWorkbenchImage(Bundle ideBundle, String symbolicName, String path, boolean shared) {
    URL url = FileLocator.find(ideBundle, new Path(path), null);
    ImageDescriptor desc = ImageDescriptor.createFromURL(url);
    getWorkbenchConfigurer().declareImage(symbolicName, desc, shared);
}

From source file:com.aptana.ide.ui.io.CoreIOImages.java

License:Open Source License

/**
 * Declare an Image in the registry table.
 * //from  w ww.j av a 2  s.  c om
 * @param key
 *            The key to use when registering the image
 * @param path
 *            The path where the image can be found. This path is relative to where this plugin class is found (i.e.
 *            typically the packages directory)
 */
private static void declareRegistryImage(String key, String path) {
    ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
    Bundle bundle = Platform.getBundle(IOUIPlugin.PLUGIN_ID);
    URL url = null;
    if (bundle != null) {
        url = FileLocator.find(bundle, new Path(path), null);
        desc = ImageDescriptor.createFromURL(url);
    }
    fgImageRegistry.put(key, desc);
}

From source file:com.aptana.ide.views.outline.UnifiedOutlineProvider.java

License:Open Source License

/**
 * processFilters//from  w w  w  .j a  va2  s. com
 * 
 * @param elements
 */
private void loadFilters(IConfigurationElement[] elements) {
    for (int i = 0; i < elements.length; i++) {
        IConfigurationElement element = elements[i];

        if (element.getName().equals(TAG_FILTER)) {
            String languages = element.getAttribute(ATTR_LANGUAGES);
            String name = element.getAttribute(ATTR_NAME);
            String toolTip = element.getAttribute(ATTR_TOOL_TIP);
            InstanceCreator filterCreator = new InstanceCreator(element, ATTR_CLASS);

            IExtension ext = element.getDeclaringExtension();
            String pluginId = ext.getNamespaceIdentifier();
            Bundle bundle = Platform.getBundle(pluginId);
            String resourceName = element.getAttribute(ATTR_ICON);
            URL resource = bundle.getResource(resourceName);

            if (resource == null) {
                resource = bundle.getEntry(ATTR_ICON);
            }

            ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(resource);

            for (String language : languages.split("\\s+")) //$NON-NLS-1$
            {
                this.addFilter(language, name, toolTip, filterCreator, imageDescriptor);
            }
        }
    }
}