Search in sources :

Example 16 with ImageData

use of org.eclipse.swt.graphics.ImageData in project yyl_example by Relucent.

the class ImageCanvasTest method main.

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    ImageViewer ic = new ImageViewer(shell);
    shell.setLayout(new FillLayout());
    FileDialog dialog = new FileDialog(shell, SWT.OPEN);
    dialog.setText("Open an image file or cancel");
    String string = dialog.open();
    ImageLoader loader = new ImageLoader();
    ImageData[] imageDatas = loader.load(string);
    if (imageDatas.length == 0)
        return;
    else if (imageDatas.length == 1) {
        ic.setImage(imageDatas[0]);
    } else {
        ic.setImages(imageDatas, loader.repeatCount);
    }
    ic.pack();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ImageData(org.eclipse.swt.graphics.ImageData) FillLayout(org.eclipse.swt.layout.FillLayout) ImageLoader(org.eclipse.swt.graphics.ImageLoader) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display)

Example 17 with ImageData

use of org.eclipse.swt.graphics.ImageData in project tdi-studio-se by Talend.

the class IconSelectionController method createCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
     */
public Command createCommand(Button button) {
    Object data = button.getData(NAME);
    if (data != null) {
        if (ICON_SELECTION.equals(data)) {
            FileDialog dial = new FileDialog(composite.getShell(), SWT.NONE);
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            dial.setFilterExtensions(new String[] { "*.jpg", "*.png", "*.gif" });
            String propertyName = (String) button.getData(PARAMETER_NAME);
            String file = dial.open();
            if (file != null) {
                if (!file.equals("")) {
                    //$NON-NLS-1$
                    if (!elem.getPropertyValue(propertyName).equals(file)) {
                        ImageData imageData = new ImageData(file);
                        if (ImageUtils.checkSize(ImageDescriptor.createFromImageData(imageData), ImageUtils.ICON_SIZE.ICON_32)) {
                            if (elem instanceof IProcess2) {
                                refreshIcon(imageData);
                                return new IconSelectionCommand((IProcess2) elem, ImageDescriptor.createFromImageData(imageData), file);
                            }
                        } else {
                            MessageDialog.openError(composite.getShell(), //$NON-NLS-1$ 
                            Messages.getString("IconSelectionController.MessageTitle"), //$NON-NLS-1$ 
                            Messages.getString("IconSelectionController.Messages"));
                        }
                    }
                }
            }
        } else if (ICON_REVERT.equals(data)) {
            if (elem instanceof IProcess2) {
                Image defaultIcon = RepositoryLabelProvider.getDefaultJobletImage(((IProcess2) elem).getProperty().getItem());
                ImageDescriptor imageData = ImageDescriptor.createFromImage(defaultIcon);
                refreshIcon(defaultIcon.getImageData());
                return new IconSelectionCommand((IProcess2) elem, imageData, null);
            }
        }
    }
    return null;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) IProcess2(org.talend.core.model.process.IProcess2) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 18 with ImageData

use of org.eclipse.swt.graphics.ImageData in project tdi-studio-se by Talend.

the class InsertionIndicator method addListeners.

/**
     * DOC amaumont Comment method "addListeners".
     */
private void addListeners() {
    Listener paintListener = new Listener() {

        public void handleEvent(Event event) {
            Composite composite = (Composite) event.widget;
            Rectangle bounds = composite.getBounds();
            // //////////////////////////////////////////////////////////
            // draw image filled with transparent pixels
            RGB transparentColor = new RGB(0, 255, 0);
            PaletteData paletteData = new PaletteData(new RGB[] { transparentColor });
            ImageData imageData = new ImageData(bounds.width, bounds.height, 1, paletteData);
            int transparentPixelValue = imageData.palette.getPixel(transparentColor);
            imageData.transparentPixel = transparentPixelValue;
            GC gc = event.gc;
            final Image image = new Image(gc.getDevice(), imageData);
            gc.drawImage(image, 0, 0);
            image.dispose();
            // ////////////////////////////////////////////////////////////////////////////
            // //////////////////////////////////////////////////////////
            // draw left arrow
            int yCenter = bounds.height / 2;
            int widthExternalArrow = 10;
            gc.setBackground(colorIndicator);
            gc.setForeground(colorIndicator);
            if (composite == leftArrowDraggingIndicator) {
                // external left arrow
                Point leftCrossPoint = new Point(widthExternalArrow, yCenter);
                gc.fillPolygon(new int[] { 0, 0, leftCrossPoint.x, leftCrossPoint.y, 0, bounds.height });
                gc.drawLine(leftCrossPoint.x, leftCrossPoint.y, bounds.width, leftCrossPoint.y);
            } else {
                // external right arrow
                Point rightCrossPoint = new Point(bounds.width - widthExternalArrow, yCenter);
                gc.fillPolygon(new int[] { bounds.width, 0, rightCrossPoint.x, rightCrossPoint.y, bounds.width, bounds.height });
                gc.drawLine(rightCrossPoint.x, rightCrossPoint.y, -bounds.width, rightCrossPoint.y);
            }
        }
    };
    leftArrowDraggingIndicator.addListener(SWT.Paint, paintListener);
    rightArrowDraggingIndicator.addListener(SWT.Paint, paintListener);
}
Also used : PaletteData(org.eclipse.swt.graphics.PaletteData) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) ImageData(org.eclipse.swt.graphics.ImageData) Rectangle(org.eclipse.swt.graphics.Rectangle) Event(org.eclipse.swt.widgets.Event) Point(org.eclipse.swt.graphics.Point) RGB(org.eclipse.swt.graphics.RGB) GC(org.eclipse.swt.graphics.GC) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point)

Example 19 with ImageData

use of org.eclipse.swt.graphics.ImageData in project tdi-studio-se by Talend.

the class AttributeLabelProvider method getAttributeImage.

/**
     * Gets the attribute image.
     * 
     * @return The attribute image
     */
private Image getAttributeImage() {
    if (attributeImage == null || attributeImage.isDisposed()) {
        ImageData imageData = Activator.getImageDescriptor(ISharedImages.ATTRIBUTE_IMG_PATH).getImageData();
        attributeImage = new OverlayImageDescriptor(imageData, new ImageDescriptor[0], new Point(IMAGE_WIDTH, IMAGE_HEIGHT)).createImage();
    }
    return attributeImage;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Point(org.eclipse.swt.graphics.Point)

Example 20 with ImageData

use of org.eclipse.swt.graphics.ImageData in project tdi-studio-se by Talend.

the class ColorController method setButtonColor.

/**
     * yzhang Comment method "resetButtonColor".
     * 
     * @param colorBtn
     * @param value
     */
private void setButtonColor(Button colorBtn, RGB rgb) {
    if (colorBtn.getImage() != null) {
        colorBtn.getImage().dispose();
    }
    ImageData id = createColorImage(colorBtn, rgb);
    Image image = new Image(colorBtn.getDisplay(), id, id.getTransparencyMask());
    addResourceDisposeListener(colorBtn, image);
    colorBtn.setImage(image);
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Image(org.eclipse.swt.graphics.Image)

Aggregations

ImageData (org.eclipse.swt.graphics.ImageData)54 Image (org.eclipse.swt.graphics.Image)29 Point (org.eclipse.swt.graphics.Point)15 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)11 ByteArrayInputStream (java.io.ByteArrayInputStream)7 GC (org.eclipse.swt.graphics.GC)7 ImageLoader (org.eclipse.swt.graphics.ImageLoader)7 Display (org.eclipse.swt.widgets.Display)6 Composite (org.eclipse.swt.widgets.Composite)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 PaletteData (org.eclipse.swt.graphics.PaletteData)3 RGB (org.eclipse.swt.graphics.RGB)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Event (org.eclipse.swt.widgets.Event)3 FileDialog (org.eclipse.swt.widgets.FileDialog)3 Listener (org.eclipse.swt.widgets.Listener)3 EImage (org.talend.commons.ui.runtime.image.EImage)3 IImage (org.talend.commons.ui.runtime.image.IImage)3