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:com.android.ide.eclipse.adt.internal.editors.IconFactory.java

License:Apache License

/**
 * Returns an Image for a given icon name.
 * <p/>/*from  w w  w  . j a v a2  s  .  c  om*/
 * Callers should not dispose it.
 *
 * @param osName The leaf name, without the extension, of an existing icon
 *            in the editor's "icons" directory. If it doesn't exist, the
 *            fallback will be used instead.
 * @param fallback the fallback icon name to use if the primary icon does
 *            not exist, or null if the method should return null if the
 *            image does not exist
 * @return the icon, which should not be disposed by the caller, or null
 * if the image does not exist *and*
 */
@Nullable
public Image getIcon(@NonNull String osName, @Nullable String fallback) {
    String key = osName;
    Image icon = mIconMap.get(key);
    if (icon == null && !mIconMap.containsKey(key)) {
        ImageDescriptor id = getImageDescriptor(osName, fallback);
        if (id != null) {
            icon = id.createImage();
        }
        // Note that we store null references in the icon map, to avoid looking them
        // up every time. If it didn't exist once, it will not exist later.
        mIconMap.put(key, icon);
    }
    return icon;
}

From source file:com.android.ide.eclipse.adt.internal.editors.IconFactory.java

License:Apache License

/**
 * Returns the image indicated by the given URL
 *
 * @param url the url to the image resources
 * @return the image for the url, or null if it cannot be initialized
 *//*from   w ww  .ja  v a2 s . c o m*/
public Image getIcon(URL url) {
    Image image = mUrlMap.get(url);
    if (image == null) {
        ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
        image = descriptor.createImage();
        mUrlMap.put(url, image);
    }

    return image;
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.PaletteControl.java

License:Open Source License

private Control createItem(Composite parent, ViewElementDescriptor desc) {
    Control item = null;/*from  w w w .j av  a 2 s.c o m*/
    switch (mPaletteMode) {
    case SMALL_PREVIEW:
    case TINY_PREVIEW:
    case PREVIEW: {
        ImageDescriptor descriptor = mPreviewIconFactory.getImageDescriptor(desc);
        if (descriptor != null) {
            Image image = descriptor.createImage();
            ImageControl imageControl = new ImageControl(parent, SWT.None, image);
            if (mPaletteMode.isScaledPreview()) {
                // Try to preserve the overall size since rendering sizes typically
                // vary with the dpi - so while the scaling factor for a 160 dpi
                // rendering the scaling factor should be 0.5, for a 320 dpi one the
                // scaling factor should be half that, 0.25.
                float scale = 1.0f;
                if (mPaletteMode == PaletteMode.SMALL_PREVIEW) {
                    scale = 0.75f;
                } else if (mPaletteMode == PaletteMode.TINY_PREVIEW) {
                    scale = 0.5f;
                }
                ConfigurationChooser chooser = mEditor.getConfigurationChooser();
                int dpi = chooser.getConfiguration().getDensity().getDpiValue();
                while (dpi > 160) {
                    scale = scale / 2;
                    dpi = dpi / 2;
                }
                imageControl.setScale(scale);
            }
            imageControl.setHoverColor(getDisplay().getSystemColor(SWT.COLOR_WHITE));
            if (mBackground != null) {
                imageControl.setBackground(mBackground);
            }
            String toolTip = desc.getUiName();
            // It appears pretty much none of the descriptors have tooltips
            //String descToolTip = desc.getTooltip();
            //if (descToolTip != null && descToolTip.length() > 0) {
            //    toolTip = toolTip + "\n" + descToolTip;
            //}
            imageControl.setToolTipText(toolTip);

            item = imageControl;
        } else {
            // Just use an Icon+Text item for these for now
            item = new IconTextItem(parent, desc);
            if (mForeground != null) {
                item.setForeground(mForeground);
                item.setBackground(mBackground);
            }
        }
        break;
    }
    case ICON_TEXT: {
        item = new IconTextItem(parent, desc);
        break;
    }
    case ICON_ONLY: {
        item = new ImageControl(parent, SWT.None, desc.getGenericIcon());
        item.setToolTipText(desc.getUiName());
        break;
    }
    default:
        throw new IllegalArgumentException("Not yet implemented");
    }

    final DragSource source = new DragSource(item, DND.DROP_COPY);
    source.setTransfer(new Transfer[] { SimpleXmlTransfer.getInstance() });
    source.addDragListener(new DescDragSourceListener(desc));
    item.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            source.dispose();
        }
    });
    addMenu(item);

    return item;
}

From source file:com.android.ide.eclipse.auidt.internal.editors.IconFactory.java

License:Apache License

/**
 * Returns an Image for a given icon name.
 * <p/>//from   w w  w  .j a v a 2  s. c o m
 * Callers should not dispose it.
 *
 * @param osName The leaf name, without the extension, of an existing icon in the
 *        editor's "icons" directory. If it doesn't exist, a default icon will be
 *        generated automatically based on the name.
 * @param color The color of the text in the automatically generated icons,
 *        one of COLOR_DEFAULT, COLOR_RED, COLOR_BLUE or COLOR_RED.
 * @param shape The shape of the icon in the automatically generated icons,
 *        one of SHAPE_DEFAULT, SHAPE_CIRCLE or SHAPE_RECT.
 */
public Image getIcon(String osName, int color, int shape) {
    String key = Character.toString((char) shape) + Integer.toString(color) + osName;
    Image icon = mIconMap.get(key);
    if (icon == null && !mIconMap.containsKey(key)) {
        ImageDescriptor id = getImageDescriptor(osName, color, shape);
        if (id != null) {
            icon = id.createImage();
        }
        // Note that we store null references in the icon map, to avoid looking them
        // up every time. If it didn't exist once, it will not exist later.

        mIconMap.put(key, icon);
    }
    return icon;
}

From source file:com.android.ide.eclipse.auidt.internal.editors.layout.gle2.PaletteControl.java

License:Open Source License

private Control createItem(Composite parent, ViewElementDescriptor desc) {
    Control item = null;/*from   w  ww  .  j  a  va 2 s. c  o m*/
    switch (mPaletteMode) {
    case SMALL_PREVIEW:
    case TINY_PREVIEW:
    case PREVIEW: {
        ImageDescriptor descriptor = mPreviewIconFactory.getImageDescriptor(desc);
        if (descriptor != null) {
            Image image = descriptor.createImage();
            ImageControl imageControl = new ImageControl(parent, SWT.None, image);
            if (mPaletteMode.isScaledPreview()) {
                // Try to preserve the overall size since rendering sizes typically
                // vary with the dpi - so while the scaling factor for a 160 dpi
                // rendering the scaling factor should be 0.5, for a 320 dpi one the
                // scaling factor should be half that, 0.25.
                float scale = 1.0f;
                if (mPaletteMode == PaletteMode.SMALL_PREVIEW) {
                    scale = 0.75f;
                } else if (mPaletteMode == PaletteMode.TINY_PREVIEW) {
                    scale = 0.5f;
                }
                int dpi = mEditor.getConfigurationComposite().getDensity().getDpiValue();
                while (dpi > 160) {
                    scale = scale / 2;
                    dpi = dpi / 2;
                }
                imageControl.setScale(scale);
            }
            imageControl.setHoverColor(getDisplay().getSystemColor(SWT.COLOR_WHITE));
            if (mBackground != null) {
                imageControl.setBackground(mBackground);
            }
            String toolTip = desc.getUiName();
            // It appears pretty much none of the descriptors have tooltips
            //String descToolTip = desc.getTooltip();
            //if (descToolTip != null && descToolTip.length() > 0) {
            //    toolTip = toolTip + "\n" + descToolTip;
            //}
            imageControl.setToolTipText(toolTip);

            item = imageControl;
        } else {
            // Just use an Icon+Text item for these for now
            item = new IconTextItem(parent, desc);
            if (mForeground != null) {
                item.setForeground(mForeground);
                item.setBackground(mBackground);
            }
        }
        break;
    }
    case ICON_TEXT: {
        item = new IconTextItem(parent, desc);
        break;
    }
    case ICON_ONLY: {
        item = new ImageControl(parent, SWT.None, desc.getGenericIcon());
        item.setToolTipText(desc.getUiName());
        break;
    }
    default:
        throw new IllegalArgumentException("Not yet implemented");
    }

    final DragSource source = new DragSource(item, DND.DROP_COPY);
    source.setTransfer(new Transfer[] { SimpleXmlTransfer.getInstance() });
    source.addDragListener(new DescDragSourceListener(desc));
    item.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            source.dispose();
        }
    });
    addMenu(item);

    return item;
}

From source file:com.android.ide.eclipse.ddms.ImageLoader.java

License:Apache License

public Image loadImage(String filename, Display display) {
    ImageDescriptor descriptor = loadDescriptor(filename);
    if (descriptor != null) {
        return descriptor.createImage();
    }//from   ww  w.j  a  v a 2  s . c om
    return null;
}

From source file:com.android.ide.eclipse.gltrace.editors.GLFunctionTraceViewer.java

License:Apache License

private void createOptionsBar(Composite parent) {
    int numColumns = mShowContextSwitcher ? 4 : 3;

    Composite c = new Composite(parent, SWT.NONE);
    c.setLayout(new GridLayout(numColumns, false));
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    c.setLayoutData(gd);//  w w  w.j  a v  a2s .co m

    Label l = new Label(c, SWT.NONE);
    l.setText("Filter:");

    mFilterText = new Text(c, SWT.BORDER | SWT.ICON_SEARCH | SWT.SEARCH | SWT.ICON_CANCEL);
    mFilterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    mFilterText.setMessage(DEFAULT_FILTER_MESSAGE);
    mFilterText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            updateAppliedFilters();
        }
    });

    if (mShowContextSwitcher) {
        mContextSwitchCombo = new Combo(c, SWT.BORDER | SWT.READ_ONLY);

        // Setup the combo such that "All Contexts" is the first item,
        // and then we have an item for each context.
        mContextSwitchCombo.add("All Contexts");
        mContextSwitchCombo.select(0);
        mCurrentlyDisplayedContext = -1; // showing all contexts
        for (int i = 0; i < mTrace.getContexts().size(); i++) {
            mContextSwitchCombo.add("Context " + i);
        }

        mContextSwitchCombo.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                selectContext(mContextSwitchCombo.getSelectionIndex() - 1);
            }
        });
    } else {
        mCurrentlyDisplayedContext = 0;
    }

    ToolBar toolBar = new ToolBar(c, SWT.FLAT | SWT.BORDER);

    mExpandAllToolItem = new ToolItem(toolBar, SWT.PUSH);
    mExpandAllToolItem.setToolTipText("Expand All");
    if (sExpandAllIcon == null) {
        ImageDescriptor id = GlTracePlugin.getImageDescriptor("/icons/expandall.png");
        sExpandAllIcon = id.createImage();
    }
    if (sExpandAllIcon != null) {
        mExpandAllToolItem.setImage(sExpandAllIcon);
    }

    mCollapseAllToolItem = new ToolItem(toolBar, SWT.PUSH);
    mCollapseAllToolItem.setToolTipText("Collapse All");
    mCollapseAllToolItem
            .setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_COLLAPSEALL));

    mSaveAsToolItem = new ToolItem(toolBar, SWT.PUSH);
    mSaveAsToolItem.setToolTipText("Export Trace");
    mSaveAsToolItem.setImage(
            PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_SAVEAS_EDIT));

    SelectionListener toolbarSelectionListener = new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.getSource() == mCollapseAllToolItem) {
                setTreeItemsExpanded(false);
            } else if (e.getSource() == mExpandAllToolItem) {
                setTreeItemsExpanded(true);
            } else if (e.getSource() == mSaveAsToolItem) {
                exportTrace();
            }
        }
    };
    mExpandAllToolItem.addSelectionListener(toolbarSelectionListener);
    mCollapseAllToolItem.addSelectionListener(toolbarSelectionListener);
    mSaveAsToolItem.addSelectionListener(toolbarSelectionListener);
}

From source file:com.appnativa.studio.Studio.java

License:Open Source License

private static Image loadSWTImage(String path) {
    ImageDescriptor id = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, path);

    return id.createImage();
}

From source file:com.aptana.browser.parts.WebBrowserEditor.java

License:Open Source License

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);/* w  ww. j  a  va 2  s .c  o  m*/
    setInput(input);
    if (input instanceof WebBrowserEditorInput) {
        WebBrowserEditorInput wbei = (WebBrowserEditorInput) input;
        initialURL = null;
        if (wbei.getURL() != null)
            initialURL = wbei.getURL().toExternalForm();
        if (webBrowser != null) {
            webBrowser.setURL(initialURL);
            site.getWorkbenchWindow().getActivePage().activate(this);
        }

        setPartName(wbei.getName());
        setTitleToolTip(wbei.getToolTipText());
        Image oldImage = image;
        ImageDescriptor id = wbei.getImageDescriptor();
        image = id.createImage();

        setTitleImage(image);
        if (oldImage != null && !oldImage.isDisposed())
            oldImage.dispose();
    }
}

From source file:com.aptana.ide.core.ui.browser.WebBrowserEditor.java

License:Open Source License

public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    Trace.trace(Trace.FINEST, "Opening browser: " + input); //$NON-NLS-1$
    if (input instanceof IPathEditorInput) {
        IPathEditorInput pei = (IPathEditorInput) input;
        IPath path = pei.getPath();/*  w  ww .j a v  a2  s .c  o  m*/
        URL url = null;
        try {
            if (path != null)
                url = path.toFile().toURL();
            initialURL = url.toExternalForm();
        } catch (Exception e) {
            Trace.trace(Trace.SEVERE, "Error getting URL to file"); //$NON-NLS-1$
        }
        if (webBrowser != null) {
            if (initialURL != null)
                webBrowser.setURL(initialURL);
            site.getWorkbenchWindow().getActivePage().activate(this);
        }

        setPartName(path.lastSegment());
        if (url != null)
            setTitleToolTip(url.getFile());

        Image oldImage = image;
        ImageDescriptor id = ImageResource.getImageDescriptor(ImageResource.IMG_INTERNAL_BROWSER);
        image = id.createImage();

        setTitleImage(image);
        if (oldImage != null && !oldImage.isDisposed())
            oldImage.dispose();
        //addResourceListener(file);
    } else if (input instanceof WebBrowserEditorInput) {
        WebBrowserEditorInput wbei = (WebBrowserEditorInput) input;
        initialURL = null;
        if (wbei.getURL() != null)
            initialURL = wbei.getURL().toExternalForm();
        if (webBrowser != null) {
            webBrowser.setURL(initialURL);
            site.getWorkbenchWindow().getActivePage().activate(this);
        }

        setPartName(wbei.getName());
        setTitleToolTip(wbei.getToolTipText());
        lockName = wbei.isNameLocked();

        Image oldImage = image;
        ImageDescriptor id = wbei.getImageDescriptor();
        image = id.createImage();

        setTitleImage(image);
        if (oldImage != null && !oldImage.isDisposed())
            oldImage.dispose();
    } else {
        IPathEditorInput pinput = (IPathEditorInput) input.getAdapter(IPathEditorInput.class);
        if (pinput != null) {
            init(site, pinput);
        } else {
            throw new PartInitException(NLS.bind(Messages.errorInvalidEditorInput, input.getName()));
        }
    }

    setSite(site);
    setInput(input);
}