Search in sources :

Example 36 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class AdvancedGraphics method loadImage.

static Image loadImage(Device device, Class<AdvancedGraphics> clazz, String string) {
    InputStream stream = clazz.getResourceAsStream(string);
    if (stream == null)
        return null;
    Image image = null;
    try {
        image = new Image(device, stream);
    } catch (SWTException ex) {
    } finally {
        try {
            stream.close();
        } catch (IOException ex) {
        }
    }
    return image;
}
Also used : SWTException(org.eclipse.swt.SWTException) InputStream(java.io.InputStream) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image)

Example 37 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class AdvancedGraphics method open.

public Shell open(final Display display) {
    final Shell shell = new Shell(display);
    // $NON-NLS-1$
    shell.setText(RESOURCE_BUNDLE.getString("AdvancedGraphics"));
    try {
        Path path = new Path(display);
        path.dispose();
    } catch (SWTException e) {
        MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
        // $NON-NLS-1$
        dialog.setText(RESOURCE_BUNDLE.getString("Warning"));
        // $NON-NLS-1$
        dialog.setMessage(RESOURCE_BUNDLE.getString("LibNotFound"));
        dialog.open();
        shell.dispose();
        return null;
    }
    FontData fd = shell.getFont().getFontData()[0];
    final Font font = new Font(display, fd.getName(), 96, SWT.BOLD | SWT.ITALIC);
    final Image image = loadImage(display, AdvancedGraphics.class, "irmaos.jpg");
    final Rectangle rect = image.getBounds();
    shell.addListener(SWT.Paint, event -> {
        GC gc = event.gc;
        Transform tr = new Transform(display);
        tr.translate(rect.width / 4, rect.height / 2);
        tr.rotate(-30);
        if (image != null) {
            gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width, rect.height);
        }
        gc.setAlpha(100);
        gc.setTransform(tr);
        Path path = new Path(display);
        path.addString("SWT", 0, 0, font);
        gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
        gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
        gc.fillPath(path);
        gc.drawPath(path);
        tr.dispose();
        path.dispose();
    });
    shell.setSize(shell.computeSize(rect.width, rect.height));
    shell.open();
    shell.addListener(SWT.Dispose, event -> {
        if (image != null)
            image.dispose();
        font.dispose();
    });
    return shell;
}
Also used : Path(org.eclipse.swt.graphics.Path) Shell(org.eclipse.swt.widgets.Shell) SWTException(org.eclipse.swt.SWTException) FontData(org.eclipse.swt.graphics.FontData) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Transform(org.eclipse.swt.graphics.Transform) Font(org.eclipse.swt.graphics.Font) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 38 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class GraphicsExample method checkAdvancedGraphics.

boolean checkAdvancedGraphics() {
    if (advanceGraphicsInit)
        return advanceGraphics;
    advanceGraphicsInit = true;
    Display display = parent.getDisplay();
    try {
        Path path = new Path(display);
        path.dispose();
    } catch (SWTException e) {
        Shell shell = display.getActiveShell(), newShell = null;
        if (shell == null)
            shell = newShell = new Shell(display);
        MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
        // $NON-NLS-1$
        dialog.setText(RESOURCE_BUNDLE.getString("Warning"));
        // $NON-NLS-1$
        dialog.setMessage(RESOURCE_BUNDLE.getString("LibNotFound"));
        dialog.open();
        if (newShell != null)
            newShell.dispose();
        return false;
    }
    return advanceGraphics = true;
}
Also used : Path(org.eclipse.swt.graphics.Path) Shell(org.eclipse.swt.widgets.Shell) SWTException(org.eclipse.swt.SWTException) Display(org.eclipse.swt.widgets.Display) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 39 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class GraphicsExample method loadImage.

static Image loadImage(Device device, Class<GraphicsExample> clazz, String string) {
    InputStream stream = clazz.getResourceAsStream(string);
    if (stream == null)
        return null;
    Image image = null;
    try {
        image = new Image(device, stream);
    } catch (SWTException ex) {
    } finally {
        try {
            stream.close();
        } catch (IOException ex) {
        }
    }
    return image;
}
Also used : SWTException(org.eclipse.swt.SWTException) InputStream(java.io.InputStream) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image)

Example 40 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class ImageAnalyzer method menuSave.

void menuSave() {
    if (image == null)
        return;
    // stop any animation in progress
    animate = false;
    // so we have to use 'Save As...'.
    if (imageData.type == SWT.IMAGE_UNDEFINED || fileName == null) {
        menuSaveAs();
        return;
    }
    Cursor waitCursor = display.getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);
    imageCanvas.setCursor(waitCursor);
    try {
        // Save the current image to the current file.
        loader.data = new ImageData[] { imageData };
        if (imageData.type == SWT.IMAGE_JPEG)
            loader.compression = compressionCombo.indexOf(compressionCombo.getText()) + 1;
        if (imageData.type == SWT.IMAGE_PNG)
            loader.compression = compressionCombo.indexOf(compressionCombo.getText());
        loader.save(fileName, imageData.type);
    } catch (SWTException e) {
        showErrorDialog(bundle.getString("Saving_lc"), fileName, e);
    } catch (SWTError e) {
        showErrorDialog(bundle.getString("Saving_lc"), fileName, e);
    } finally {
        shell.setCursor(null);
        imageCanvas.setCursor(crossCursor);
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) SWTException(org.eclipse.swt.SWTException) Cursor(org.eclipse.swt.graphics.Cursor)

Aggregations

SWTException (org.eclipse.swt.SWTException)57 Test (org.junit.Test)29 Image (org.eclipse.swt.graphics.Image)21 Rectangle (org.eclipse.swt.graphics.Rectangle)14 ImageData (org.eclipse.swt.graphics.ImageData)13 IOException (java.io.IOException)8 Region (org.eclipse.swt.graphics.Region)8 Display (org.eclipse.swt.widgets.Display)8 SWTError (org.eclipse.swt.SWTError)7 PaletteData (org.eclipse.swt.graphics.PaletteData)7 RGB (org.eclipse.swt.graphics.RGB)7 InputStream (java.io.InputStream)6 Point (org.eclipse.swt.graphics.Point)6 MessageBox (org.eclipse.swt.widgets.MessageBox)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Cursor (org.eclipse.swt.graphics.Cursor)4 ImageLoader (org.eclipse.swt.graphics.ImageLoader)4 FileDialog (org.eclipse.swt.widgets.FileDialog)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Shell (org.eclipse.swt.widgets.Shell)3