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