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) {
}
}
}
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) {
}
}
}
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) {
}
}
};
}
}
}
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);
}
}
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);
// }
}
Aggregations