Search in sources :

Example 26 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cubrid-manager by CUBRID.

the class ImageViewer method createImageByImageData.

/**
	 * 
	 * Create the image by image data
	 * 
	 */
private void createImageByImageData() {
    images = new Image[imageDatas.length];
    //Get the image size
    int width = imageDatas[0].width;
    int height = imageDatas[0].height;
    //Create every image
    int disposalMethod = SWT.DM_FILL_BACKGROUND;
    for (int i = 0; i < imageDatas.length; i++) {
        ImageData currImageData = imageDatas[i];
        images[i] = new Image(display, width, height);
        GC currImageGC = new GC(images[i]);
        switch(disposalMethod) {
            case SWT.DM_FILL_PREVIOUS:
                //Draw the second last image. 
                currImageGC.drawImage(images[i - 2], 0, 0);
                break;
            case SWT.DM_FILL_NONE:
            case SWT.DM_UNSPECIFIED:
                //Draw the last image. 
                currImageGC.drawImage(images[i - 1], 0, 0);
                break;
            default:
                //If DM_FILL_BACKGROUND or anything else, fill with default background
                currImageGC.setBackground(background);
                currImageGC.fillRectangle(0, 0, width, height);
                break;
        }
        //Draw the current image,then clean up
        Image currImage = new Image(display, currImageData);
        currImageGC.drawImage(currImage, 0, 0, currImageData.width, currImageData.height, currImageData.x, currImageData.y, currImageData.width, currImageData.height);
        currImage.dispose();
        currImageGC.dispose();
        //Compute the next disposal method.
        disposalMethod = currImageData.disposalMethod;
        if (i == 0 && disposalMethod == SWT.DM_FILL_PREVIOUS) {
            disposalMethod = SWT.DM_FILL_NONE;
        }
    }
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 27 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.

the class HCIPACmd method buildActionStepInsert.

protected static void buildActionStepInsert(AUndertaking task, AScriptStep step, Demonstration demo, StringBuilder php) {
    int hcipaStep = task.getTaskGroup().getUndertakings().indexOf(task) + 1;
    Frame curFrame = step.getCurrentFrame();
    TransitionSource src = step.getStepFocus();
    String labelAction;
    if (src == null) {
        labelAction = "None";
    } else {
        labelAction = quotePHP(quoteSQL(src.getLabel()));
    }
    int order = demo.getSteps().indexOf(step) + 1;
    byte[] bkgImage = curFrame.getBackgroundImage();
    if (bkgImage != null) {
        ImageData imgData = new ImageData(new ByteArrayInputStream(bkgImage));
        bkgImage = GraphicsUtil.convertImageType(imgData, SWT.IMAGE_JPEG);
        int imgSize = bkgImage.length;
        String imgName = (String) curFrame.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
        php.append("\t$imgType = \"'image/jpeg'\";\n\t");
        php.append("$imgLength = " + imgSize + ";\n\t");
        php.append("$bkgImage = '0x' . bin2hex(base64_decode(str_replace(array('.', '_', '-'), array('+', '/', '='), \"");
        php.append(Base64.encode(bkgImage));
        php.append("\")));\n\n\t");
        if ((imgName == null) || NullSafe.equals(WidgetAttributes.NO_IMAGE, imgName)) {
            php.append("$imgName = 'null';\n\t");
        } else {
            php.append("$imgName = \"'\" . mysql_real_escape_string(basename(\n<<<SQL__INSERT__STRING\n");
            php.append(imgName);
            php.append("\nSQL__INSERT__STRING\n)) . \"'\";\n\n\t");
        }
    } else {
        php.append("\t$imgType = 'null';\n\t");
        php.append("$imgLength = 'null';\n\t");
        php.append("$bkgImage = 'null';\n\t");
        php.append("$imgName = 'null';\n\n\t");
    }
    php.append("Add_Task_Action($deviceId,\n\t");
    php.append(hcipaStep + ",\n\t" + order + ",\n\t");
    php.append("$bkgImage,\n\t$imgName,\n\t$imgLength,\n\t$imgType,\n\t");
    php.append("\"" + quotePHP(quoteSQL(curFrame.getName())) + "\",\n\t");
    php.append("\"" + labelAction + "\");\n\n");
//        php.append("$sqlStmt =\n<<<SQL__INSERT__STRING\n\t");
//        php.append(SQL_INSERT + "HCIPA_Actions (hcipa_id,\n\thcipa_step,\n\t");
//        php.append("hcipa_order,\n\tImage,\n\tImage_Name,\n\tImage_Size,\n\tImage_Type,\n\t");
//        php.append("Next_User_Action,\n\tLabel_User_Action)\n\t");
//        php.append(SQL_VALUES + " ($deviceId,\n\t" + hcipaStep + ",\n\t" + order + ",\n\t");
//        php.append("$bkgImage,\n\t$imgName,\n\t$imgLength,\n\t$imgType,\n\t");
//        php.append("'" + quoteSQL(curFrame.getName()) + "',\n\t'" + labelAction + "'");
//        php.append(")\n");
//        php.append("SQL__INSERT__STRING\n;\n\n\t");
//        php.append("mysql_query($sqlStmt);\n\n");
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageData(org.eclipse.swt.graphics.ImageData)

Example 28 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.

the class WindowsImageTransfer method main.

public static void main(String[] args) throws Exception {
    Display display = new Display();
    Shell shell = new Shell(display);
    Clipboard c = new Clipboard(display);
    System.out.println("types on the clipboard: " + Arrays.asList(c.getAvailableTypeNames()));
    Object o = c.getContents(WindowsImageTransfer.getInstance());
    ImageData d = (ImageData) o;
    if (d == null) {
        System.out.println("no image found on clipboard. try hitting the printscreen key, or using MS Paint to put an image on the clipboard.");
        return;
    }
    //Change what's on the clipboard to show we can also put images on the
    // clipboard.
    c.setContents(new Object[] { "howdy" }, new Transfer[] { TextTransfer.getInstance() });
    System.out.println("types on the clipboard: " + Arrays.asList(c.getAvailableTypeNames()));
    //now put the ImageData back onto the clipboard.
    c.setContents(new Object[] { d }, new Transfer[] { WindowsImageTransfer.getInstance() });
    System.out.println("types on the clipboard: " + Arrays.asList(c.getAvailableTypeNames()));
    //now read the CF_DIB (ImageData) back off the clipboard.
    // and display it by using it as the image for the button.
    ImageData imgData = (ImageData) c.getContents(WindowsImageTransfer.getInstance());
    Image img = new Image(display, imgData);
    Button button = new Button(shell, SWT.NONE);
    button.setImage(img);
    shell.pack();
    button.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
    button.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) ImageData(org.eclipse.swt.graphics.ImageData) Clipboard(org.eclipse.swt.dnd.Clipboard) Image(org.eclipse.swt.graphics.Image) Display(org.eclipse.swt.widgets.Display)

Example 29 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.

the class ZoomRenderer method paintBackground.

public void paintBackground(Graphics g) {
    g.pushState();
    try {
        // This is the clip to the figure. We must clip to this the whole time!
        Rectangle mainClip = getBounds();
        g.setClip(mainClip);
        ImageData scaledImgData = image.getImageData().scaledTo(widgetBounds.width, widgetBounds.height);
        Image scaledImage = new Image(Display.getCurrent(), scaledImgData);
        try {
            g.drawImage(scaledImage, widgetBounds.y, widgetBounds.x);
        } finally {
            scaledImage.dispose();
        }
        // TODO: Is this useless, since the graphics state gets popped?
        //       Also, seems redundant to the setClip call above!
        // Reset the clip to the main clip, the entire size of the frame.
        g.setClip(mainClip);
    } finally {
        g.popState();
    }
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Image(org.eclipse.swt.graphics.Image)

Example 30 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.

the class WindowUtil method getClosedHandCursor.

public static Cursor getClosedHandCursor() {
    if (CLOSED_HAND_CURSOR == null) {
        ImageData curData = GraphicsUtil.getImageDataFromResource("edu/cmu/cs/hcii/cogtool/resources/closed_hand.gif");
        if (curData == null) {
            return null;
        }
        CLOSED_HAND_CURSOR = new Cursor(GLOBAL_DISPLAY, curData, 8, 8);
    }
    return CLOSED_HAND_CURSOR;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Cursor(org.eclipse.swt.graphics.Cursor)

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