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:de.instanttouch.ui.scaffolding.swt.util.SnakeSwtUtils.java

License:Open Source License

public static Image createImage(String urlStr) {

    if (urlStr != null && urlStr.length() > 0) {
        try {/*  ww  w . j a va 2s .co m*/
            URL url = new URL(urlStr);
            ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url);
            Image image = imageDescriptor.createImage();
            return image;
        } catch (Exception e) {
            try {
                Image image = new Image(Display.getCurrent(), urlStr);
                return image;
            } catch (Exception e1) {
            }
        }
    }

    return null;
}

From source file:de.jcup.egradle.eclipse.api.EGradleUtil.java

License:Apache License

public static ImageDescriptor createImageDescriptor(String path, String pluginId) {
    Bundle bundle = Platform.getBundle(pluginId);

    URL url = FileLocator.find(bundle, new Path(path), null);

    ImageDescriptor imageDesc = ImageDescriptor.createFromURL(url);
    return imageDesc;
}

From source file:de.jcup.egradle.eclipse.util.EclipseUtil.java

License:Apache License

public static ImageDescriptor createImageDescriptor(String path, String pluginId) {
    if (path == null) {
        /* fall back if path null , so avoid NPE in eclipse framework */
        return ImageDescriptor.getMissingImageDescriptor();
    }/*from w  w w.  ja  va  2s  .c  o m*/
    if (pluginId == null) {
        /* fall back if pluginId null , so avoid NPE in eclipse framework */
        return ImageDescriptor.getMissingImageDescriptor();
    }
    Bundle bundle = Platform.getBundle(pluginId);
    if (bundle == null) {
        /*
         * fall back if bundle not available, so avoid NPE in eclipse
         * framework
         */
        return ImageDescriptor.getMissingImageDescriptor();
    }
    URL url = FileLocator.find(bundle, new Path(path), null);

    ImageDescriptor imageDesc = ImageDescriptor.createFromURL(url);
    return imageDesc;
}

From source file:de.openali.odysseus.chart.factory.config.StyleFactory.java

License:Open Source License

public static IPointStyle createPointStyle(final PointStyleType pst, final URL context) {
    final IPointStyle style = StyleUtils.getDefaultPointStyle();

    // style.setTitle( pst.getTitle() );

    // visible/*  w ww.  j  a v a2  s.  c  o  m*/
    if (pst.isSetIsVisible())
        style.setVisible(pst.getIsVisible());

    // alpha
    if (pst.isSetAlpha())
        style.setAlpha(StyleHelper.byteToInt(pst.getAlpha()[0]));

    // width
    if (pst.isSetWidth())
        style.setWidth(pst.getWidth());

    // height
    if (pst.isSetHeight())
        style.setHeight(pst.getHeight());

    // fill color
    final ColorFillType fillColor = pst.getFillColor();
    if (fillColor != null) {
        if (fillColor.isSetIsVisible())
            style.setFillVisible(fillColor.getIsVisible());
        final byte[] color = fillColor.getColor();
        if (color != null)
            style.setInlineColor(StyleHelper.colorByteToRGB(color));
    }

    // marker

    if (pst.isSetPolygonMarker()) {
        final PolygonMarkerType polygonMarker = pst.getPolygonMarker();
        final PointType[] configPointArray = polygonMarker.getPointArray();

        final Point[] pointArray = new Point[configPointArray.length];
        for (int i = 0; i < pointArray.length; i++) {
            final PointType configPoint = configPointArray[i];
            pointArray[i] = new Point(configPoint.getX(), configPoint.getY());
        }
        style.setMarker(new PolygonMarker(pointArray));
    } else if (pst.isSetImageMarker()) {
        final ImageMarkerType imageMarker = pst.getImageMarker();
        final String imgPath = imageMarker.getImageFile();
        // ImageData id = ChartFactoryUtilities.loadImageData( context, imgPath, -1, -1 );
        ImageDescriptor id;
        try {
            id = ImageDescriptor.createFromURL(new URL(context, imgPath));
            style.setMarker(new ImageMarker(id));
        } catch (final MalformedURLException e) {
            Logger.logError(Logger.TOPIC_LOG_STYLE, "Can not load image from '" + context + imgPath + "'"); //$NON-NLS-1$ //$NON-NLS-2$
            style.setMarker(new OvalMarker());
        }
    } else if (pst.isSetOvalMarker())
        style.setMarker(new OvalMarker());

    final StrokeType strokeStyle = pst.getStroke();
    if (strokeStyle != null) {
        final ILineStyle ls = StyleUtils.getDefaultLineStyle();
        setStrokeAttributes(ls, strokeStyle);
        style.setStroke(ls);
    }

    return style;
}

From source file:de.openali.odysseus.chart.factory.config.StyleFactory.java

License:Open Source License

public static IAreaStyle createAreaStyle(final AreaStyleType ast, final URL context) {
    final IAreaStyle style = StyleUtils.getDefaultAreaStyle();

    // style.setTitle( ast.getTitle() );
    // visible/*from  ww  w.  j  ava  2  s .c om*/
    if (ast.isSetIsVisible()) {
        final boolean isVisible = ast.getIsVisible();
        style.setVisible(isVisible);
    }

    // alpha
    if (ast.isSetAlpha()) {
        final int alpha = StyleHelper.byteToInt(ast.getAlpha()[0]);
        style.setAlpha(alpha);
    }

    if (ast.isSetFill()) {
        final FillType fill = ast.getFill();
        if (fill.getColorFill() != null) {
            final ColorFillType cft = fill.getColorFill();
            final ColorFill colorFill = new ColorFill(StyleHelper.colorByteToRGB(cft.getColor()));
            style.setFill(colorFill);
        } else if (fill.getImageFill() != null) {
            final ImageFillType ift = fill.getImageFill();
            final String imgPath = ift.getImageFile();

            try {
                final ImageDescriptor id = ImageDescriptor.createFromURL(new URL(context, imgPath));
                // style.setMarker( new ImageMarker( id ) );
                final ImageFill imageFill = new ImageFill(id);
                style.setFill(imageFill);
            } catch (final MalformedURLException e) {
                Logger.logError(Logger.TOPIC_LOG_STYLE, "Can not load image from '" + context + imgPath + "'"); //$NON-NLS-1$ //$NON-NLS-2$
                style.setFill(new ColorFill(new RGB(255, 0, 0)));
            }

        }
        // else: use default fill
    }

    // outline
    if (ast.isSetStroke()) {
        final ILineStyle ls = StyleUtils.getDefaultLineStyle();
        setStrokeAttributes(ls, ast.getStroke());
        style.setStroke(ls);
    }

    return style;
}

From source file:de.ovgu.featureide.ui.decorators.ActiveConfigurationDecorator.java

License:Open Source License

public ActiveConfigurationDecorator() {
    URL url = de.ovgu.featureide.ui.UIPlugin.getDefault().getBundle()
            .getEntry("/icons/currentconfiguration.gif");
    icon = ImageDescriptor.createFromURL(url);
    listeners = new LinkedList<ILabelProviderListener>();

    // add Listener to Activator
    de.ovgu.featureide.core.CorePlugin.getDefault().addCurrentConfigurationListener(this);
}

From source file:de.quamoco.qm.application.QmEditorAdvisor.java

License:Apache License

/**
 * Declares an IDE-specific workbench image.
 * /*from  ww  w.  j  av  a 2 s .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,
        IWorkbenchConfigurer configurer) {
    URL url = FileLocator.find(ideBundle, new Path(path), null);
    ImageDescriptor desc = ImageDescriptor.createFromURL(url);
    configurer.declareImage(symbolicName, desc, shared);
}

From source file:de.thischwa.pmcms.tool.swt.SWTUtils.java

License:LGPL

public static void putImage(String key, URL url) {
    imageRegistry.put(key, ImageDescriptor.createFromURL(url));
}

From source file:de.uniluebeck.itm.spyglass.drawing.primitive.Image.java

License:Open Source License

public Image(final String imageFileName) {

    // first try to load the given file. if that failes, use the brokenImageFile.
    final ImageDescriptor desc = ImageDescriptor.createFromFile(null, imageFileName);
    org.eclipse.swt.graphics.Image i = desc.createImage(false);
    if (i == null) {
        final ImageDescriptor descBad = ImageDescriptor.createFromURL(Image.class.getResource(brokenImageFile));
        i = descBad.createImage();/*  w w w . j a va 2s  .c o m*/
    }

    this.image = i;
}

From source file:de.uniluebeck.itm.spyglass.gui.actions.Action.java

License:Open Source License

protected ImageDescriptor getImageDescriptor(final String fileName) {
    return ImageDescriptor.createFromURL(getResourceUrl(fileName));
}