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.nokia.sdt.component.symbian.properties.TypeDescriptors.java

License:Open Source License

private static Image loadImage(Bundle emfEditPlugin, String fileName) {
    Image result = null;/*from ww w  .j a  va 2 s.  c  o  m*/
    Path path = new Path("/icons/full/obj16/" + fileName); //$NON-NLS-1$
    URL url = FileLocator.find(emfEditPlugin, path, null);
    ImageDescriptor id = ImageDescriptor.createFromURL(url);
    result = id.createImage();
    return result;
}

From source file:com.nokia.testfw.resultview.ResultViewPlugin.java

License:Open Source License

/**
 * retrieve an image based on its name (from the plug-in standard image folder)
 * @param imageName//from  www  . ja  va 2s .  c om
 * @return <code>ImageDescriptor</code> of the image if found or the standard missing image descriptor
 */
public static final ImageDescriptor getImageDescriptor(Bundle bundle, String imageName) {
    URL url = getImageUrl(bundle, imageName);

    return (url != null) ? ImageDescriptor.createFromURL(url) : ImageDescriptor.getMissingImageDescriptor();
}

From source file:com.nokia.tools.carbide.ui.dialogs.CarbideAboutDialog.java

License:Open Source License

/**
 * Creates and returns the contents of the upper part of the dialog (above
 * the button bar). Subclasses should overide.
 * /*from w  ww .j a  v a  2s  .  c  o  m*/
 * @param parent the parent composite to contain the dialog area
 * @return the dialog area control
 */
protected Control createDialogArea(Composite parent) {
    // brand the about box if there is product info
    Image aboutImage = null;
    AboutItem item = null;
    if (product != null) {
        ImageDescriptor imageDescriptor = ProductProperties.getAboutImage(product);
        if (imageDescriptor != null) {
            aboutImage = imageDescriptor.createImage();
        }

        // if the about image is small enough, then show the text
        if (aboutImage == null || aboutImage.getBounds().width <= MAX_IMAGE_WIDTH_FOR_TEXT) {
            String aboutText = ProductProperties.getAboutText(product);
            if (aboutText != null) {
                item = AboutTextManager.scan(aboutText);
            }
        }

        if (aboutImage != null) {
            images.add(aboutImage);
        }
    }

    // create a composite which is the parent of the top area and the bottom
    // button bar, this allows there to be a second child of this composite
    // with
    // a banner background on top but not have on the bottom
    Composite workArea = new Composite(parent, SWT.NONE);
    GridLayout workLayout = new GridLayout();
    workLayout.marginHeight = 0;
    workLayout.marginWidth = 0;
    workLayout.verticalSpacing = 0;
    workLayout.horizontalSpacing = 0;
    workArea.setLayout(workLayout);
    workArea.setLayoutData(new GridData(GridData.FILL_BOTH));

    // page group
    Color background = JFaceColors.getBannerBackground(parent.getDisplay());
    Color foreground = JFaceColors.getBannerForeground(parent.getDisplay());
    Composite top = (Composite) super.createDialogArea(workArea);

    // override any layout inherited from createDialogArea
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    top.setLayout(layout);
    top.setLayoutData(new GridData(GridData.FILL_BOTH));
    top.setBackground(background);
    top.setForeground(foreground);

    // the image & text
    final Composite topContainer = new Composite(top, SWT.NONE);
    topContainer.setBackground(background);
    topContainer.setForeground(foreground);

    layout = new GridLayout();
    layout.numColumns = (aboutImage == null || item == null ? 1 : 2);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    topContainer.setLayout(layout);

    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    topContainer.setLayoutData(data);

    GC gc = new GC(parent);
    // arbitrary default
    int topContainerHeightHint = 100;
    try {
        // default height enough for 6 lines of text
        topContainerHeightHint = Math.max(topContainerHeightHint, gc.getFontMetrics().getHeight() * 6);
    } finally {
        gc.dispose();
    }

    // image on left side of dialog
    if (aboutImage != null) {
        Label imageLabel = new Label(topContainer, SWT.NONE);
        imageLabel.setBackground(background);
        imageLabel.setForeground(foreground);

        data = new GridData();
        data.horizontalAlignment = GridData.FILL;
        data.verticalAlignment = GridData.BEGINNING;
        data.grabExcessHorizontalSpace = false;
        imageLabel.setLayoutData(data);
        imageLabel.setImage(aboutImage);
        // topContainerHeightHint = Math.max(topContainerHeightHint,
        // aboutImage.getBounds().height);
    }

    // data = new GridData();
    // data.horizontalAlignment = GridData.FILL;
    // data.verticalAlignment = GridData.FILL;
    // data.grabExcessHorizontalSpace = true;
    // data.grabExcessVerticalSpace = true;
    // data.heightHint = topContainerHeightHint;
    // topContainer.setLayoutData(data);

    if (item != null) {
        final int minWidth = 400; // This value should really be calculated
        // from the computeSize(SWT.DEFAULT,
        // SWT.DEFAULT) of all the
        // children in infoArea excluding the
        // wrapped styled text
        // There is no easy way to do this.
        final ScrolledComposite scroller = new ScrolledComposite(topContainer, SWT.V_SCROLL | SWT.H_SCROLL);
        data = new GridData(GridData.FILL_BOTH);
        data.widthHint = minWidth;
        scroller.setLayoutData(data);

        final Composite textComposite = new Composite(scroller, SWT.NONE);
        textComposite.setBackground(background);

        layout = new GridLayout();
        layout.numColumns = 1;
        layout.marginRight = 17;
        layout.marginTop = 0;
        textComposite.setLayout(layout);
        data = new GridData();
        data.horizontalAlignment = GridData.FILL;
        data.verticalAlignment = GridData.BEGINNING;
        data.grabExcessHorizontalSpace = true;
        textComposite.setLayoutData(data);

        // Image on the right
        Label textImageLabel = new Label(textComposite, SWT.NONE);
        URL url = BrandingProperties.getUrl(product.getProperty("aboutTextImage"), product.getDefiningBundle());
        Image textImage = ImageDescriptor.createFromURL(url).createImage();
        images.add(textImage);
        textImageLabel.setImage(textImage);
        textImageLabel.setBackground(background);
        textImageLabel.setForeground(foreground);
        data = new GridData();
        data.horizontalAlignment = SWT.RIGHT;
        data.verticalIndent = 7;
        textImageLabel.setLayoutData(data);

        // Version information on the right
        Label versionLabel = new Label(textComposite, SWT.NONE);
        data = new GridData();
        data.horizontalAlignment = SWT.RIGHT;
        data.verticalIndent = 8;
        versionLabel.setText(product.getProperty("versionText"));
        versionLabel.setBackground(background);
        versionLabel.setForeground(foreground);
        versionLabel.setLayoutData(data);

        String buildId = product.getProperty("buildId");
        if (buildId != null && !buildId.startsWith("@")) {
            // don't show build id if it's not resolved, @buildId@
            Label buildIdLabel = new Label(textComposite, SWT.NONE);
            data = new GridData();
            data.horizontalAlignment = SWT.RIGHT;
            data.verticalIndent = 8;
            buildIdLabel.setText(Messages.BuildId_Label + " " + buildId);
            buildIdLabel.setBackground(background);
            buildIdLabel.setForeground(foreground);
            buildIdLabel.setLayoutData(data);
        }

        text = new StyledText(textComposite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
        text.setCaret(null);
        text.setFont(parent.getFont());
        text.setText(item.getText());
        text.setCursor(null);
        text.setBackground(background);
        text.setForeground(foreground);

        aboutTextManager = new AboutTextManager(text);
        aboutTextManager.setItem(item);

        createTextMenu();

        GridData gd = new GridData();
        gd.verticalAlignment = GridData.BEGINNING;
        gd.horizontalAlignment = GridData.FILL;
        gd.grabExcessHorizontalSpace = true;
        text.setLayoutData(gd);

        // Adjust the scrollbar increments
        scroller.getHorizontalBar().setIncrement(20);
        scroller.getVerticalBar().setIncrement(20);

        final boolean[] inresize = new boolean[1]; // flag to stop
        // unneccesary
        // recursion
        textComposite.addControlListener(new ControlAdapter() {
            public void controlResized(ControlEvent e) {
                if (inresize[0])
                    return;
                inresize[0] = true;
                // required because of bugzilla report 4579
                textComposite.layout(true);
                // required because you want to change the height that the
                // scrollbar will scroll over when the width changes.
                int width = textComposite.getClientArea().width;
                Point p = textComposite.computeSize(width, SWT.DEFAULT);
                scroller.setMinSize(minWidth, p.y);
                inresize[0] = false;
            }
        });

        scroller.setExpandHorizontal(true);
        scroller.setExpandVertical(true);
        Point p = textComposite.computeSize(minWidth, SWT.DEFAULT);
        textComposite.setSize(p.x, p.y);
        scroller.setMinWidth(minWidth);
        scroller.setMinHeight(p.y);

        scroller.setContent(textComposite);
    }

    // horizontal bar
    Label bar = new Label(workArea, SWT.HORIZONTAL | SWT.SEPARATOR);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    bar.setLayoutData(data);
    String[] s = new String[1];
    URL url = Platform.getBundle(Activator.PLUGIN_ID).getEntry("doc/data.html");
    try {
        s[0] = FileLocator.toFileURL(url).toString();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    int[][] index = { { Messages.Oss_Liense_Info.indexOf("Click"),
            Messages.Oss_Liense_Info.length() - Messages.Oss_Liense_Info.indexOf("Click") - 1 } };
    AboutItem licenceItem = new AboutItem(Messages.Oss_Liense_Info, index, s);

    final Composite licenceTextComposite = new Composite(workArea, SWT.NONE);
    licenceTextComposite.setBackground(background);

    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginRight = 17;
    layout.marginTop = 0;
    licenceTextComposite.setLayout(layout);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    data.grabExcessHorizontalSpace = true;
    licenceTextComposite.setLayoutData(data);

    StyledText licenceText = new StyledText(licenceTextComposite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
    licenceText.setCaret(null);
    licenceText.setText(licenceItem.getText());
    licenceText.setCursor(null);
    aboutTextManager = new AboutTextManager(licenceText);
    aboutTextManager.setItem(licenceItem);

    bar = new Label(workArea, SWT.HORIZONTAL | SWT.SEPARATOR);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    bar.setLayoutData(data);
    AboutItem ossItem = AboutTextManager.scan(Messages.Oss_Download_Info);

    final Composite ossTextComposite = new Composite(workArea, SWT.NONE);
    ossTextComposite.setBackground(background);

    layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginRight = 17;
    layout.marginTop = 0;
    ossTextComposite.setLayout(layout);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    data.grabExcessHorizontalSpace = true;
    ossTextComposite.setLayoutData(data);

    StyledText ossText = new StyledText(ossTextComposite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
    ossText.setCaret(null);
    ossText.setText(licenceItem.getText());
    ossText.setCursor(null);
    aboutTextManager = new AboutTextManager(ossText);
    aboutTextManager.setItem(ossItem);

    bar = new Label(workArea, SWT.HORIZONTAL | SWT.SEPARATOR);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    bar.setLayoutData(data);

    // add image buttons for bundle groups that have them
    Composite bottom = (Composite) super.createDialogArea(workArea);
    // override any layout inherited from createDialogArea
    layout = new GridLayout();
    bottom.setLayout(layout);
    data = new GridData();
    data.horizontalAlignment = SWT.FILL;
    data.verticalAlignment = SWT.FILL;
    data.grabExcessHorizontalSpace = true;

    bottom.setLayoutData(data);

    createFeatureImageButtonRow(bottom);

    // spacer
    bar = new Label(bottom, SWT.NONE);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    bar.setLayoutData(data);

    return workArea;
}

From source file:com.nokia.tools.carbidect.cone.ui.ConeUIPlugin.java

License:Open Source License

@Override
protected void initializeImageRegistry(ImageRegistry reg) {
    super.initializeImageRegistry(reg);

    ImageDescriptor image = ImageDescriptor
            .createFromURL(FileLocator.find(getBundle(), new Path("icons/args.gif"), null));
    reg.put(IMAGE_ID_ARGUMENTS_TAB, image);

    image = ImageDescriptor.createFromURL(FileLocator.find(getBundle(), new Path("icons/main.gif"), null));
    reg.put(IMAGE_ID_MAIN_TAB, image);//from  w  ww.jav  a  2s. c  o m
}

From source file:com.nokia.tools.media.utils.tooltip.DynamicTooltip.java

License:Open Source License

@SuppressWarnings("unchecked")
protected static void initializeData() {
    IConfigurationElement[] elements = Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT)
            .getConfigurationElements();
    for (IConfigurationElement element : elements) {
        if (ELEMENT_TOOLBAR_ITEM.equalsIgnoreCase(element.getName())) {
            ToolbarItemContribution def = new ToolbarItemContribution();

            String contributorName = element.getContributor().getName();

            String iconPath = element.getAttribute(ATTRIBUTE_ICON);
            if (iconPath != null) {
                URL url = FileLocator.find(Platform.getBundle(contributorName), new Path(iconPath), null);
                if (url != null) {
                    def.icon = ImageDescriptor.createFromURL(url);
                } else {
                    def.icon = ImageDescriptor.getMissingImageDescriptor();
                }//w w w .j  a  v a  2  s. c o m
            }

            String disabledIconPath = element.getAttribute(ATTRIBUTE_DISABLED_ICON);
            if (disabledIconPath != null) {
                URL url = FileLocator.find(Platform.getBundle(contributorName), new Path(disabledIconPath),
                        null);
                if (url != null) {
                    def.disabledIcon = ImageDescriptor.createFromURL(url);
                }
            }

            String hoverIconPath = element.getAttribute(ATTRIBUTE_HOVER_ICON);
            if (hoverIconPath != null) {
                URL url = FileLocator.find(Platform.getBundle(contributorName), new Path(hoverIconPath), null);
                if (url != null) {
                    def.hoverIcon = ImageDescriptor.createFromURL(url);
                }
            }

            def.label = element.getAttribute(ATTRIBUTE_LABEL);

            String priority = element.getAttribute(ATTRIBUTE_PRIORITY);
            if (priority != null && priority.length() > 0) {
                try {
                    def.priority = new Integer(priority);
                } catch (NumberFormatException nfe) {
                    System.err.println("Invalid definition:\n" + element.toString());
                    System.err.println("Specified priority is not a number!");
                }
            }

            def.tooltip = element.getAttribute(ATTRIBUTE_TOOLTIP);

            def.tooltipStyle = element.getAttribute(ATTRIBUTE_TOOLTIP_STYLE);

            def.target = element.getAttribute(ATTRIBUTE_TARGET);

            Bundle contributor = Platform.getBundle(contributorName);

            def.actionId = element.getAttribute(ATTRIBUTE_ACTION);

            def.contributor = contributor;

            String actionProviderClassName = element.getAttribute(ATTRIBUTE_ACTION_PROVIDER);

            if (actionProviderClassName != null) {
                try {
                    Class actionProviderClass = contributor.loadClass(actionProviderClassName);

                    if (ITooltipActionProvider.class.isAssignableFrom(actionProviderClass)) {
                        def.actionProvider = (ITooltipActionProvider) actionProviderClass.newInstance();
                    } else {
                        System.err.println("Invalid definition:\n" + element.toString());
                        System.err.println("actionProvider class must implement interface "
                                + ITooltipActionProvider.class.getName());
                    }
                } catch (ClassNotFoundException cnfe) {
                    System.err.println("Invalid definition:\n" + element.toString());
                    System.err.println("actionProvider class not found: " + actionProviderClassName);
                } catch (Throwable t) {
                    System.err.println("Invalid definition:\n" + element.toString());
                    t.printStackTrace();
                }
            }

            def.enablements = parseEnablements(element);

            toolbarContributions.add(def);
        }

        if (ELEMENT_SECTION.equalsIgnoreCase(element.getName())) {
            SectionContribution def = new SectionContribution();

            String priority = element.getAttribute(ATTRIBUTE_PRIORITY);
            if (priority != null && priority.length() > 0) {
                try {
                    def.priority = new Integer(priority);
                } catch (NumberFormatException nfe) {
                    System.err.println("Invalid definition:\n" + element.toString());
                    System.err.println("Specified priority is not a number!");
                }
            }

            String uiClassName = element.getAttribute(ATTRIBUTE_UICLASS);
            Bundle contributor = Platform.getBundle(element.getContributor().getName());
            try {
                Class uiClass = contributor.loadClass(uiClassName);

                if (IDynamicTooltipUIContribution.class.isAssignableFrom(uiClass)) {
                    def.uiClass = (Class<IDynamicTooltipUIContribution>) uiClass;
                } else {
                    System.err.println("Invalid definition:\n" + element.toString());
                    System.err.println("UI class must implement interface "
                            + IDynamicTooltipUIContribution.class.getName());
                }
            } catch (ClassNotFoundException cnfe) {
                System.err.println("Invalid definition:\n" + element.toString());
                System.err.println("UI class not found: " + uiClassName);
            }

            def.enablements = parseEnablements(element);

            sectionContributions.add(def);
        }
    }
}

From source file:com.nokia.tools.platform.extension.PlatformExtensionManager.java

License:Open Source License

private static ImageDescriptor createImageDescriptor(IConfigurationElement element, String path) {
    if (!StringUtils.isEmpty(path)) {
        URL url = FileUtils.getURL(element, path);
        if (FileUtils.resourceExists(url)) {
            return ImageDescriptor.createFromURL(url);
        }/*from   w ww. ja v a  2 s  . c  om*/
    }
    return null;
}

From source file:com.nokia.tools.theme.s60.general.PlatformSuppportInfoProvider.java

License:Open Source License

public static Image getImage(IPlatform platform) {
    IExtension[] extensions = PlatformExtensionManager.getExtensions(PLATFORM_SUPPORT_INFO_EXTENSION_POINT_ID);
    if (extensions != null) {
        for (IExtension extension : extensions) {
            IConfigurationElement[] configurationElements = extension.getConfigurationElements();
            if (configurationElements != null) {
                for (IConfigurationElement configurationElement : configurationElements) {
                    if (configurationElement != null
                            && PLATFORM_SUPPORT_INFO_ELEMENT_NAME.equals(configurationElement.getName())) {
                        if (platform.getId().equals(configurationElement.getAttribute(PLATFORM_ID_ATTRIBUTE))) {
                            String iconFilePath = configurationElement.getAttribute(ICON_FILE_PATH_ATTRIBUTE);
                            Bundle bundle = Platform.getBundle(extension.getNamespaceIdentifier());
                            URL iconFileURL = null;
                            if (bundle != null) {
                                iconFileURL = bundle.getEntry(iconFilePath);
                            }//ww  w.ja  v  a 2 s.c  o  m
                            return ImageDescriptor.createFromURL(iconFileURL).createImage();
                        }
                    }
                }
            }
        }
    }
    return null;
}

From source file:com.nokia.tools.vct.confml.editor.include.xincmodel.presentation.BadIncludeReferenceDecorator.java

License:Open Source License

private void lazyInit() {
    if (descr == null) {
        URL url = XIncludeEditorPlugin.getPlugin().getBundle().getEntry("icons/full/ovr16/ErrorObject.gif");
        descr = ImageDescriptor.createFromURL(url);
    }//from   w  ww. j  a  va 2s . c o  m
}

From source file:com.nokia.tools.vct.confml.editor.view.viewers.ViewTreeViewerLabelDecorator.java

License:Open Source License

private void lazyInit() {
    if (errorDescriptor == null) {
        URL url = ViewsEditorPlugin.getDefault().getBundle().getEntry("icons/full/ovr16/ErrorObject.gif");
        errorDescriptor = ImageDescriptor.createFromURL(url);
        url = ViewsEditorPlugin.getDefault().getBundle().getEntry("icons/full/ovr16/WarningObject.gif");
        warningDescriptor = ImageDescriptor.createFromURL(url);
        url = ViewsEditorPlugin.getDefault().getBundle().getEntry("icons/full/ovr16/ReadOnlySetting.gif");
        readOnlyDescriptor = ImageDescriptor.createFromURL(url);
    }// w  w w. jav  a2 s . c o m

    Display d = getStandardDisplay();
    d.syncExec(new Runnable() {
        public void run() {
            fonts = new FontRegistry(getStandardDisplay());
            DEFAULT_FONT = fonts.defaultFont();
            BOLD_FONT = fonts.getBold("bold");
        }
    });

}

From source file:com.nokia.tools.vct.navigator.confml.ConfMLMarkerDecorator.java

License:Open Source License

private void lasyInit() {
    if (errorDescriptor == null) {
        URL url = ConfmlNavigatorPlugin.getPlugin().getBundle().getEntry("icons/full/ovr16/ErrorObject.gif");
        errorDescriptor = ImageDescriptor.createFromURL(url);
        url = ConfmlNavigatorPlugin.getPlugin().getBundle().getEntry("icons/full/ovr16/WarningObject.gif");
        warningDescriptor = ImageDescriptor.createFromURL(url);
    }/*from w w  w  . ja v  a2s .c om*/
}