Search in sources :

Example 76 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 77 with ImageData

use of org.eclipse.swt.graphics.ImageData in project translationstudio8 by heartsome.

the class Activator method getIconDescriptor.

/**
	 * 提供一个图片文件对插件的相对路径,返回该图片被伸缩变换为16*16像素的描述信息。
	 * @param path
	 *            the path
	 * @return the icon descriptor
	 */
public static ImageDescriptor getIconDescriptor(String path) {
    ImageDescriptor image = getImageDescriptor(path);
    ImageData data = image.getImageData();
    data = data.scaledTo(16, 16);
    image = ImageDescriptor.createFromImageData(data);
    return image;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)

Example 78 with ImageData

use of org.eclipse.swt.graphics.ImageData in project translationstudio8 by heartsome.

the class SpellPage method addLangAndDicToTable.

/**
	 * 将语言与词典对进行加载到列表中,
	 * @param aspellDicList	第一个数据为 语言, 第二个数据为 词典
	 */
private void addLangAndDicToTable(List<String[]> aspellDicList) {
    for (String[] dicArray : aspellDicList) {
        String lang = dicArray[0];
        String dic = dicArray[1];
        TableItem item = null;
        for (int i = 0; i < table.getItemCount(); i++) {
            TableItem currItem = table.getItem(i);
            if (TextUtil.getLanguageCode(currItem.getText(0)).equals(lang)) {
                item = currItem;
            }
        }
        if (item == null) {
            item = new TableItem(table, 0);
        }
        //$NON-NLS-1$
        String[] data = { TextUtil.getLanguageName(lang), "->", dic };
        String imgPath = langMap.get(lang).getImagePath();
        if (imgPath != null && !imgPath.equals("")) {
            imgPath = bundlePath + imgPath;
            Image image = new Image(getShell().getDisplay(), imgPath);
            if (image != null) {
                ImageData imgData = image.getImageData().scaledTo(16, 12);
                image = new Image(getShell().getDisplay(), imgData);
                item.setImage(0, image);
            }
        }
        item.setText(data);
    }
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) TableItem(org.eclipse.swt.widgets.TableItem) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point)

Example 79 with ImageData

use of org.eclipse.swt.graphics.ImageData in project translationstudio8 by heartsome.

the class Activator method getIconDescriptor.

/**
	 * 提供一个图片文件对插件的相对路径,返回该图片被伸缩变换为16*16像素的描述信息。
	 * @param path
	 *            the path
	 * @return the icon descriptor
	 */
public static ImageDescriptor getIconDescriptor(String path) {
    ImageDescriptor image = getImageDescriptor(path);
    ImageData data = image.getImageData();
    data = data.scaledTo(16, 16);
    image = ImageDescriptor.createFromImageData(data);
    return image;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)

Example 80 with ImageData

use of org.eclipse.swt.graphics.ImageData in project dbeaver by serge-rider.

the class ImageViewCanvas method loadImage.

/**
	 * Reload image from a file
	 * @return swt image created from image file
	 */
public Image loadImage(InputStream inputStream) {
    if (sourceImage != null && !sourceImage.isDisposed()) {
        sourceImage.dispose();
        sourceImage = null;
        imageData = null;
    }
    this.error = null;
    if (inputStream != null) {
        try {
            imageData = new ImageData(inputStream);
            sourceImage = new Image(getDisplay(), imageData);
        } catch (SWTException e) {
            this.error = e;
        }
    }
    showOriginal();
    return sourceImage;
}
Also used : SWTException(org.eclipse.swt.SWTException) ImageData(org.eclipse.swt.graphics.ImageData) Image(org.eclipse.swt.graphics.Image)

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