Search in sources :

Example 91 with ImageData

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

the class GenericWizardService method getNodeImage.

@Override
public Image getNodeImage(String typeName) {
    InputStream imageStream = internalService.getComponentService().getWizardPngImage(typeName, WizardImageType.TREE_ICON_16X16);
    if (imageStream == null) {
        return null;
    }
    // node image
    ImageData id = new ImageData(imageStream);
    Image image = new Image(null, id);
    return image;
}
Also used : InputStream(java.io.InputStream) ImageData(org.eclipse.swt.graphics.ImageData) Image(org.eclipse.swt.graphics.Image)

Example 92 with ImageData

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

the class StatusManagerSettingPage method getItemsImage.

private Image getItemsImage(IImage iImage) {
    if (iImage == null) {
        iImage = EImage.DEFAULT_IMAGE;
    }
    Image image = cacheItemImages.get(iImage);
    if (image == null) {
        Image oImage = ImageProvider.getImage(iImage);
        ImageData imageData = oImage.getImageData();
        // enlarge image
        final int larger = 4;
        ImageData newData = imageData.scaledTo(imageData.width + larger, imageData.height + larger);
        image = new Image(oImage.getDevice(), newData);
        cacheItemImages.put(iImage, image);
    }
    return image;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) IImage(org.talend.commons.ui.runtime.image.IImage) Image(org.eclipse.swt.graphics.Image) EImage(org.talend.commons.ui.runtime.image.EImage)

Example 93 with ImageData

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

the class ImageController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createControl()
     */
@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow, final int nbInRow, final int top, final Control lastControl) {
    // String fileName = (String) param.getValue();
    // IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    // String filePath = service.getPathFileName(RepositoryConstants.IMG_DIRECTORY, fileName).toPortableString();
    boolean hasScreenshots = false;
    byte[] screenshot = null;
    if (param.getElement() instanceof INode && ((INode) param.getElement()).getExternalNode() != null) {
        String componentType = ((INode) param.getElement()).getComponent().getName();
        if ("tMap".equals(componentType)) {
            IProcess process = ((INode) param.getElement()).getProcess();
            if (process instanceof IProcess2) {
                IProcess2 processtmp = (IProcess2) process;
                Item item = processtmp.getProperty().getItem();
                if (item instanceof ProcessItem) {
                    ProcessItem processItem = (ProcessItem) item;
                    screenshot = (byte[]) processItem.getProcess().getScreenshots().get(((INode) param.getElement()).getUniqueName());
                    if (screenshot != null) {
                        hasScreenshots = true;
                    }
                } else if (item instanceof JobletProcessItem) {
                    JobletProcessItem jobletItem = (JobletProcessItem) item;
                    screenshot = (byte[]) jobletItem.getJobletProcess().getScreenshots().get(((INode) param.getElement()).getUniqueName());
                    if (screenshot != null) {
                        hasScreenshots = true;
                    }
                }
            }
        }
    }
    if (hasScreenshots) {
        ImageDescriptor imageDesc = ImageUtils.createImageFromData(screenshot);
        ((INode) param.getElement()).getExternalNode().setScreenshot(imageDesc);
        // ImageDescriptor imageDesc = ((INode) param.getElement()).getExternalNode().getScreenshot();
        // File fileOrFolder = new java.io.File(filePath);
        // if (!fileOrFolder.isFile() || !fileOrFolder.canRead()) {
        // return lastControl;
        // }
        final Composite compositeImage = new Composite(subComposite, SWT.BORDER);
        final Image image = imageDesc.createImage();
        addResourceDisposeListener(compositeImage, image);
        //$NON-NLS-1$
        CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName() + " :");
        FormData formDataLabel = new FormData();
        labelLabel.setVisible(true);
        if (numInRow != 1) {
            labelLabel.setAlignment(SWT.RIGHT);
        }
        if (lastControl != null) {
            formDataLabel.left = new FormAttachment(lastControl, 0);
        } else {
            formDataLabel.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
            formDataLabel.top = new FormAttachment(0, top);
        }
        labelLabel.setLayoutData(formDataLabel);
        compositeImage.setToolTipText(param.getDisplayName());
        Point size = new Point(image.getImageData().width, image.getImageData().height);
        FormData formData = new FormData((int) (size.x * 0.8), (int) (size.y * 0.8));
        formData.top = new FormAttachment(0, top);
        formData.left = new FormAttachment(labelLabel);
        ImageData data = image.getImageData();
        compositeImage.setLayoutData(formData);
        data = data.scaledTo((int) (size.x * 0.8), (int) (size.y * 0.8));
        Image im = new Image(image.getDevice(), data);
        compositeImage.setBackgroundImage(im);
        return compositeImage;
    } else {
        return lastControl;
    }
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) FormData(org.eclipse.swt.layout.FormData) INode(org.talend.core.model.process.INode) Composite(org.eclipse.swt.widgets.Composite) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ImageData(org.eclipse.swt.graphics.ImageData) IProcess2(org.talend.core.model.process.IProcess2) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IProcess(org.talend.core.model.process.IProcess) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 94 with ImageData

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

the class ColorController method createColorImage.

private ImageData createColorImage(Button button, RGB color) {
    int width = SIZE_X - 5;
    int height = SIZE_Y - 5;
    RGB black = new RGB(0, 0, 0);
    PaletteData dataPalette = new PaletteData(new RGB[] { black, black, color });
    ImageData data = new ImageData(width, height, 4, dataPalette);
    data.transparentPixel = 0;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (x == 0 || y == 0 || x == (width - 1) || y == (height - 1)) {
                data.setPixel(x, y, 1);
            } else {
                data.setPixel(x, y, 2);
            }
        }
    }
    return data;
}
Also used : PaletteData(org.eclipse.swt.graphics.PaletteData) ImageData(org.eclipse.swt.graphics.ImageData) RGB(org.eclipse.swt.graphics.RGB) Point(org.eclipse.swt.graphics.Point)

Example 95 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)

Aggregations

ImageData (org.eclipse.swt.graphics.ImageData)132 Image (org.eclipse.swt.graphics.Image)78 PaletteData (org.eclipse.swt.graphics.PaletteData)38 RGB (org.eclipse.swt.graphics.RGB)33 Point (org.eclipse.swt.graphics.Point)32 Test (org.junit.Test)26 InputStream (java.io.InputStream)24 GC (org.eclipse.swt.graphics.GC)19 IOException (java.io.IOException)18 SWTException (org.eclipse.swt.SWTException)14 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)13 Rectangle (org.eclipse.swt.graphics.Rectangle)12 Color (org.eclipse.swt.graphics.Color)11 ImageLoader (org.eclipse.swt.graphics.ImageLoader)11 Display (org.eclipse.swt.widgets.Display)11 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Cursor (org.eclipse.swt.graphics.Cursor)7 Composite (org.eclipse.swt.widgets.Composite)7 GradientPaint (java.awt.GradientPaint)5 URL (java.net.URL)5