Search in sources :

Example 16 with SWTException

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

the class Test_org_eclipse_swt_graphics_ImageLoader method test_loadLjava_io_InputStream.

@Test
public void test_loadLjava_io_InputStream() {
    ImageLoader loader = new ImageLoader();
    try (InputStream stream = null) {
        loader.load(stream);
        fail("No exception thrown for load inputStream == null");
    } catch (IllegalArgumentException | IOException e) {
    }
    try (InputStream stream = SwtTestUtil.class.getResourceAsStream("empty.txt")) {
        loader.load(stream);
        fail("No exception thrown for load from invalid inputStream");
    } catch (IOException | SWTException e) {
    }
    int numFormats = SwtTestUtil.imageFormats.length;
    String fileName = SwtTestUtil.imageFilenames[0];
    for (int i = 0; i < numFormats; i++) {
        String format = SwtTestUtil.imageFormats[i];
        try (InputStream stream = SwtTestUtil.class.getResourceAsStream(fileName + "." + format)) {
            loader.load(stream);
        } catch (IOException e) {
        }
    }
}
Also used : SWTException(org.eclipse.swt.SWTException) InputStream(java.io.InputStream) IOException(java.io.IOException) ImageLoader(org.eclipse.swt.graphics.ImageLoader) Test(org.junit.Test)

Example 17 with SWTException

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

the class Test_org_eclipse_swt_graphics_ImageLoader method test_saveLjava_io_OutputStreamI.

@Test
public void test_saveLjava_io_OutputStreamI() {
    ImageLoader loader = new ImageLoader();
    ByteArrayOutputStream outStream = null;
    try {
        try {
            loader.save(outStream, 0);
            fail("No exception thrown for save outputStream == null");
        } catch (IllegalArgumentException e) {
        }
        outStream = new ByteArrayOutputStream();
        try {
            loader.save(outStream, -1);
            fail("No exception thrown for save to invalid outputStream format");
        } catch (SWTException e) {
        }
        boolean jpgSupported = false;
        for (int i = 0; i < SwtTestUtil.imageFormats.length; i++) {
            if (SwtTestUtil.imageFormats[i].equals("jpg")) {
                jpgSupported = true;
                break;
            }
        }
        if (jpgSupported) {
            String filename = SwtTestUtil.imageFilenames[0];
            // must use jpg since save is not implemented yet in png format
            String filetype = "jpg";
            try (InputStream inStream = SwtTestUtil.class.getResourceAsStream(filename + "." + filetype)) {
                loader.load(inStream);
            } catch (IOException e) {
            }
            for (int i = 0; i < SwtTestUtil.imageFormats.length; i++) {
                if (SwtTestUtil.imageFormats[i].equals(filetype)) {
                    // save using the appropriate format
                    loader.save(outStream, i);
                    break;
                }
            }
        }
    } finally {
        try {
            outStream.close();
        } catch (Exception e) {
        }
    }
}
Also used : SWTException(org.eclipse.swt.SWTException) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ImageLoader(org.eclipse.swt.graphics.ImageLoader) IOException(java.io.IOException) SWTException(org.eclipse.swt.SWTException) Test(org.junit.Test)

Example 18 with SWTException

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

the class PaintExample method initActions.

/**
 * Sets the action field of the tools
 */
private void initActions() {
    for (Tool tool2 : tools) {
        final Tool tool = tool2;
        String group = tool.group;
        if (group.equals("tool")) {
            tool.action = () -> setPaintTool(tool.id);
        } else if (group.equals("fill")) {
            tool.action = () -> setFillType(tool.id);
        } else if (group.equals("linestyle")) {
            tool.action = () -> setLineStyle(tool.id);
        } else if (group.equals("options")) {
            tool.action = () -> {
                FontDialog fontDialog = new FontDialog(paintSurface.getShell(), SWT.PRIMARY_MODAL);
                FontData[] fontDatum = toolSettings.commonFont.getFontData();
                if (fontDatum != null && fontDatum.length > 0) {
                    fontDialog.setFontList(fontDatum);
                }
                fontDialog.setText(getResourceString("options.Font.dialog.title"));
                paintSurface.hideRubberband();
                FontData fontData = fontDialog.open();
                paintSurface.showRubberband();
                if (fontData != null) {
                    try {
                        Font font = new Font(mainComposite.getDisplay(), fontData);
                        toolSettings.commonFont = font;
                        updateToolSettings();
                    } catch (SWTException ex) {
                    }
                }
            };
        }
    }
}
Also used : FontDialog(org.eclipse.swt.widgets.FontDialog) SWTException(org.eclipse.swt.SWTException) FontData(org.eclipse.swt.graphics.FontData) Font(org.eclipse.swt.graphics.Font)

Example 19 with SWTException

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

the class Test_org_eclipse_swt_graphics_Region method test_subtract$I.

@Test
public void test_subtract$I() {
    Region reg = new Region(display);
    try {
        reg.subtract((int[]) null);
        reg.dispose();
        fail("no exception thrown for subtract a null array");
    } catch (IllegalArgumentException e) {
    }
    reg.dispose();
    try {
        reg.subtract(new int[] {});
        reg.dispose();
        fail("no exception thrown on disposed region");
    } catch (SWTException e) {
    }
    reg.dispose();
    reg = new Region(display);
    reg.add(new int[] { 0, 0, 50, 0, 50, 25, 0, 25 });
    reg.subtract(new int[] { 0, 0, 50, 0, 50, 20, 0, 20 });
    Rectangle box = reg.getBounds();
    reg.dispose();
    Rectangle expected = new Rectangle(0, 20, 50, 5);
    if (!box.equals(expected)) {
        fail("subtract 1 failed - expected: " + expected + " actual: " + box);
    }
    reg = new Region(display);
    reg.add(new int[] { 0, 0, 50, 0, 50, 25, 0, 25 });
    reg.add(new int[] { 0, 25, 50, 25, 50, 40, 0, 40 });
    reg.subtract(new int[] { 0, 25, 50, 25, 50, 40, 0, 40 });
    box = reg.getBounds();
    reg.dispose();
    expected = new Rectangle(0, 0, 50, 25);
    if (!box.equals(expected)) {
        fail("subtract 2 failed - expected: " + expected + " actual: " + box);
    }
}
Also used : SWTException(org.eclipse.swt.SWTException) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

Example 20 with SWTException

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

the class Test_org_eclipse_swt_graphics_Region method test_add$I.

@Test
public void test_add$I() {
    Region reg = new Region(display);
    try {
        reg.add((int[]) null);
        reg.dispose();
        fail("no exception thrown for adding a null rectangle");
    } catch (IllegalArgumentException e) {
    }
    reg.dispose();
    try {
        reg.add(new int[] {});
        reg.dispose();
        fail("no exception thrown on disposed region");
    } catch (SWTException e) {
    }
    reg.dispose();
    reg = new Region(display);
    reg.add(new int[] { 0, 0, 50, 0, 50, 25, 0, 25 });
    Rectangle box = reg.getBounds();
    reg.dispose();
    Rectangle expected = new Rectangle(0, 0, 50, 25);
    if (!box.equals(expected)) {
        fail("add 1 failed - expected: " + expected + " actual: " + box);
    }
    reg = new Region(display);
    reg.add(new int[] { 0, 0, 50, 0, 50, 25, 0, 25 });
    reg.add(new int[] { 0, 25, 50, 25, 50, 40, 0, 40 });
    box = reg.getBounds();
    reg.dispose();
    expected = new Rectangle(0, 0, 50, 40);
    if (!box.equals(expected)) {
        fail("add 2 failed - expected: " + expected + " actual: " + box);
    }
// reg = new Region(display);
// reg.add(new int[] {10,10, 40,30, 20,60, 5,55});
// box = reg.getBounds();
// reg.dispose();
// expected = new Rectangle (5,10,35,50);
// if (!box.equals(expected)) {
// fail("add 3 failed - expected: "+expected+" actual: "+box);
// }
}
Also used : SWTException(org.eclipse.swt.SWTException) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

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