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

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

Introduction

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

Prototype

@Deprecated
public ImageData getImageData() 

Source Link

Document

Creates and returns a new SWT ImageData object for this image descriptor.

Usage

From source file:org.eclipse.emfforms.internal.editor.ui.EditorToolBar.java

License:Open Source License

/**
 * Creates a new Toolbar.//  w ww.  ja v  a 2  s .c o m
 *
 * @param parent The parent
 * @param style The Style (SWT.NONE)
 * @param titleText The text in the toolbar
 * @param toolbarActions a List of actions for the toolbar
 */
public EditorToolBar(Composite parent, int style, String titleText, List<Action> toolbarActions) {
    super(parent, style);

    background = new Color(parent.getDisplay(), 207, 222, 238);

    setBackground(background);

    final FormLayout layout = new FormLayout();
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    setLayout(layout);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(this);

    // Create the Icon on the Left
    final Label titleImage = new Label(this, SWT.FILL);
    final ImageDescriptor imageDescriptor = ImageDescriptor
            .createFromURL(Activator.getDefault().getBundle().getResource("icons/view.png"));
    titleImage.setImage(new Image(parent.getDisplay(), imageDescriptor.getImageData()));

    final FormData titleImageData = new FormData();
    final int imageOffset = -titleImage.computeSize(SWT.DEFAULT, SWT.DEFAULT).y / 2;
    titleImageData.top = new FormAttachment(50, imageOffset);
    titleImageData.left = new FormAttachment(0, 10);
    titleImage.setLayoutData(titleImageData);

    // Create the label for the Title Text
    final Label title = new Label(this, SWT.WRAP);
    final FontDescriptor boldDescriptor = FontDescriptor.createFrom(title.getFont()).setHeight(12)
            .setStyle(SWT.BOLD);
    final Font boldFont = boldDescriptor.createFont(title.getDisplay());
    title.setForeground(new Color(parent.getDisplay(), 25, 76, 127));
    title.setFont(boldFont);
    title.setText(titleText);
    final FormData titleData = new FormData();
    title.setLayoutData(titleData);
    titleData.left = new FormAttachment(titleImage, 5, SWT.DEFAULT);

    // Create the toolbar and add it to the header
    final ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
    final FormData formData = new FormData();
    formData.right = new FormAttachment(100, 0);
    toolBar.setLayoutData(formData);
    toolBar.layout();
    toolBarManager = new ToolBarManager(toolBar);

    // Add the provided actions
    if (toolbarActions != null) {
        for (final Action a : toolbarActions) {
            toolBarManager.add(a);
        }
    }

    toolBarManager.update(true);
    this.layout();
}

From source file:org.eclipse.epf.authoring.ui.internal.MethodElementImageDescriptor.java

License:Open Source License

private ImageData getImageData(ImageDescriptor descriptor) {
    ImageData data = descriptor.getImageData(); // see bug 51965: getImageData can return null
    if (data == null) {
        data = DEFAULT_IMAGE_DATA;//from   w w  w. j a  v  a2 s  .c  o m
        AuthoringUIPlugin.getDefault().getLogger()
                .logError("Image data not available: " + descriptor.toString()); //$NON-NLS-1$
    }
    return data;
}

From source file:org.eclipse.equinox.jmx.internal.client.ui.viewsupport.BundleImageDescriptor.java

License:Open Source License

private ImageData getImageData(ImageDescriptor descriptor) {
    ImageData data = descriptor.getImageData();
    if (data == null) {
        data = DEFAULT_IMAGE_DATA;//from   ww  w.  j a  v a  2 s.  c om
    }
    return data;
}

From source file:org.eclipse.equinox.p2.authoring.internal.P2AuthoringLabelProvider.java

/**
 * Returns an image for a descriptor for the default Display. Use this methods for 
 * created images (that should not be disposed).
 * @param imageDescriptor//from  w w w . ja v  a 2  s .co  m
 * @return
 */
public static Image getImageFromDescriptor(ImageDescriptor imageDescriptor) {
    return new Image(Display.getDefault(), imageDescriptor.getImageData());
}

From source file:org.eclipse.gmf.runtime.common.ui.util.ShiftedImageDescriptor.java

License:Open Source License

/**
 * Make a new image descriptor of an image that is shifted.
 * //from  w w w  .ja  v a 2 s  .  com
 * @param shiftX
 *            how much to shift from the left
 * @param shiftY
 *            how much to shift from the top
 * @param imageDescriptor
 *            original image to shift by shiftX and shiftY
 */
public ShiftedImageDescriptor(short shiftX, short shiftY, ImageDescriptor imageDescriptor) {

    assert (shiftX >= 0);
    assert (shiftY >= 0);
    assert (imageDescriptor.getImageData().width >= 0);
    assert (imageDescriptor.getImageData().height >= 0);
    assert null != imageDescriptor;

    this.shiftX = shiftX;
    this.shiftY = shiftY;
    this.imageData = imageDescriptor.getImageData();
}

From source file:org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.ColorsAndFontsPropertySection.java

License:Open Source License

/**
 * @param event -/*from  ww  w . j av a 2s  . c om*/
 *            selection event
 * @param button -
 *            event source
 * @param propertyId -
 *            id of the property
 * @param commandName -
 *            name of the command
 * @param imageDescriptor -
 *            the image to draw overlay on the button after the new color is
 *            set
 * @return - new RGB color, or null if none selected
 */
protected RGB changeColor(SelectionEvent event, Button button, final String propertyId, String commandName,
        ImageDescriptor imageDescriptor) {

    ColorPalettePopup popup = new ColorPalettePopup(button.getParent().getShell(),
            IDialogConstants.BUTTON_BAR_HEIGHT);
    popup.setPreviousColor(previousColor);
    Rectangle r = button.getBounds();
    Point location = button.getParent().toDisplay(r.x, r.y);
    popup.open(new Point(location.x, location.y + r.height));
    if (popup.getSelectedColor() == null && !popup.useDefaultColor()) {
        return null;
    }
    // selectedColor should be null if we are to use the default color
    final RGB selectedColor = popup.getSelectedColor();

    final EStructuralFeature feature = (EStructuralFeature) PackageUtil.getElement(propertyId);

    // Update model in response to user

    List commands = new ArrayList();
    Iterator it = getInputIterator();

    RGB colorToReturn = selectedColor;
    RGB color = selectedColor;
    while (it.hasNext()) {
        final IGraphicalEditPart ep = (IGraphicalEditPart) it.next();

        color = selectedColor;
        if (popup.useDefaultColor()) {
            Object preferredValue = ep.getPreferredValue(feature);
            if (preferredValue instanceof Integer) {
                color = FigureUtilities.integerToRGB((Integer) preferredValue);
            }
        }

        // If we are using default colors, we want to return the color of the first selected element to be consistent
        if (colorToReturn == null) {
            colorToReturn = color;
        }

        if (color != null) {
            final RGB finalColor = color; // need a final variable
            commands.add(createCommand(commandName, ((View) ep.getModel()).eResource(), new Runnable() {

                public void run() {
                    ENamedElement element = PackageUtil.getElement(propertyId);
                    if (element instanceof EStructuralFeature)
                        ep.setStructuralFeatureValue(feature, FigureUtilities.RGBToInteger(finalColor));
                }
            }));
        }
    }
    if (!commands.isEmpty()) {
        executeAsCompositeCommand(commandName, commands);
        Image overlyedImage = new ColorOverlayImageDescriptor(imageDescriptor.getImageData(), color)
                .createImage();
        disposeImage(button.getImage());
        button.setImage(overlyedImage);
    }
    return colorToReturn;
}

From source file:org.eclipse.gmf.tooling.simplemap.diagram.properties.figure.FigurePropertiesSection.java

License:Open Source License

/**
 * @param event -// w  w  w .  ja  v  a2s .c om
 *            selection event
 * @param button -
 *            event source
 * @param propertyId -
 *            id of the property
 * @param commandName -
 *            name of the command
 * @param imageDescriptor -
 *            the image to draw overlay on the button after the new color is
 *            set
 * @return - new RGB color, or null if none selected
 */
protected RGB changeColor(SelectionEvent event, Button button, String commandName,
        ImageDescriptor imageDescriptor, final RGBColor inputColor, int previousColor) {

    ColorPalettePopup popup = new ColorPalettePopup(button.getParent().getShell(),
            IDialogConstants.BUTTON_BAR_HEIGHT);
    popup.setPreviousColor(previousColor);
    Rectangle r = button.getBounds();
    Point location = button.getParent().toDisplay(r.x, r.y);
    popup.open(new Point(location.x, location.y + r.height));
    if (popup.getSelectedColor() == null && !popup.useDefaultColor()) {
        return null;
    }
    // selectedColor should be null if we are to use the default color
    final RGB selectedColor = popup.getSelectedColor();

    // Update model in response to user

    List<ICommand> commands = new ArrayList<ICommand>();

    RGB colorToReturn = selectedColor;
    RGB color = selectedColor;

    color = selectedColor;
    //        if (popup.useDefaultColor()) {
    //            Object preferredValue = ep.getPreferredValue(feature);
    //            if (preferredValue instanceof Integer) {
    //                color = FigureUtilities
    //                    .integerToRGB((Integer) preferredValue);
    //            }
    //        }

    // If we are using default colors, we want to return the color of the first selected element to be consistent
    if (colorToReturn == null) {
        colorToReturn = color;
    }

    if (color != null) {
        final RGB finalColor = color; // need a final variable
        commands.add(createCommand(commandName, inputColor.eResource(), new Runnable() {

            public void run() {
                inputColor.setBlue(finalColor.blue);
                inputColor.setGreen(finalColor.green);
                inputColor.setRed(finalColor.red);
            }
        }));
    }

    if (!commands.isEmpty()) {
        executeAsCompositeCommand(commandName, commands);
        Image overlyedImage = new ColorOverlayImageDescriptor(imageDescriptor.getImageData(), color)
                .createImage();
        disposeImage(button.getImage());
        button.setImage(overlyedImage);
    }
    return colorToReturn;
}

From source file:org.eclipse.graphiti.ui.internal.services.impl.ImageService.java

License:Open Source License

/**
 * This method fixes a problem for ImageDescriptors. It returns a corrected
 * ImageDescriptor for problematic ImageDescriptors.
 * <p>/*from   w w w  .  j  a  v  a 2 s . c  o  m*/
 * There is a problem with transparent GIFs. If the RGB value of the
 * transparent color index is identical to the RGB value of other colors
 * indices in the palette, then all those color indices are considered as
 * transparent. So as a result the transparency seems to be on an RGB value
 * instead of a color index.
 */
private ImageDescriptor fixImageDescriptor(ImageDescriptor descriptor) {
    // Typically the incoming ImageDescriptor is an URLImageDescriptor. The following lines create an ImageDataImageDescriptor
    // from it, which basically describes the same image. But that one works. So there seems to be an error in the
    // URLImageDescriptor.
    ImageData data = descriptor.getImageData();
    return ImageDescriptor.createFromImageData(data);

}

From source file:org.eclipse.jpt.common.ui.internal.jface.OverlayImageDescriptor.java

License:Open Source License

/**
 * Construct the overlay image descriptor for the specified base image,
 * overlaid by the image descriptors in the specified array.
 * The indices of the array correspond to the values
 * of the 6 overlay constants defined on {@link IDecoration}:<ol start=0>
 * <li>{@link IDecoration#TOP_LEFT}
 * <li>{@link IDecoration#TOP_RIGHT}
 * <li>{@link IDecoration#BOTTOM_LEFT}
 * <li>{@link IDecoration#BOTTOM_RIGHT}
 * <li>{@link IDecoration#UNDERLAY}
 * <li>{@link IDecoration#REPLACE}
 * </ol>/*from w  w w  . j  a  v  a 2 s  .  c o  m*/
 * The resulting image will have the same size as the specified base image.
 */
public OverlayImageDescriptor(ImageDescriptor base, ImageDescriptor[] overlays) {
    this(base, overlays, new Point(base.getImageData().width, base.getImageData().height));
}

From source file:org.eclipse.jpt.common.ui.internal.jface.OverlayImageDescriptor.java

License:Open Source License

/**
 * Draw the underlay image first, followed by either the base image or the
 * replacement image, followed by the overlay images in the order indicated
 * by the overlay constants defined on {@link IDecoration}.
 *//*from  w w  w . j  a v  a  2s .c om*/
@Override
protected void drawCompositeImage(int width, int height) {
    if (this.overlays.length > IDecoration.UNDERLAY) {
        ImageDescriptor underlay = this.overlays[IDecoration.UNDERLAY];
        if (underlay != null) {
            this.drawImage(underlay.getImageData(), 0, 0);
        }
    }

    ImageDescriptor temp = this.base;
    if (this.overlays.length > IDecoration.REPLACE) {
        ImageDescriptor replace = this.overlays[IDecoration.REPLACE];
        if (replace != null) {
            temp = replace;
        }
    }
    this.drawImage(this.convertToImageData(temp), 0, 0);

    for (int i = 0; i < this.overlays.length; i++) {
        ImageDescriptor overlay = this.overlays[i];
        if (overlay == null) {
            continue;
        }
        ImageData overlayData = this.convertToImageData(overlay);
        switch (i) {
        case IDecoration.TOP_LEFT:
            this.drawImage(overlayData, 0, 0);
            break;
        case IDecoration.TOP_RIGHT:
            this.drawImage(overlayData, (this.size.x - overlayData.width), 0);
            break;
        case IDecoration.BOTTOM_LEFT:
            this.drawImage(overlayData, 0, (this.size.y - overlayData.height));
            break;
        case IDecoration.BOTTOM_RIGHT:
            this.drawImage(overlayData, (this.size.x - overlayData.width), (this.size.y - overlayData.height));
            break;
        default:
            // NOP
        }
    }
}