public class Window {
private String currentImage;
/** * GUI-Elemente ** */
private Shell toplevelShell;
private static final int[] OUTLINE = new int[] { 60, 0, 240, 0, 240, 180, 300, 180, 300, 410, 290, 420, 10, 420, 0, 410, 0, 180, 60, 180};
private static final int[] HOLLOW = new int[] { 90,30,210,30,210,180,90,180 };
private Display display;
private Canvas canvas;
public static void main(String args[]) {
Window window = new Window();
window.run();
}
private void run() {
display = new Display();
toplevelShell = new Shell(display, SWT.NO_TRIM);
toplevelShell.setText("Verschlüsseln");
Color bgColor = new Color(display, 200, 200, 190);
toplevelShell.setBackground(bgColor);
Region region = new Region();
region.add(OUTLINE);
region.subtract(HOLLOW);
toplevelShell.setRegion(region);
Rectangle size = region.getBounds();
Monitor mon1 = display.getPrimaryMonitor();
Rectangle r = mon1.getClientArea();
toplevelShell.setBounds(r.x + 20, r.y + 20, size.width, size.height);
Listener listener = new Listener() {
Point origin;
public void handleEvent(Event e) {
switch (e.type) {
case SWT.MouseDown:
origin = new Point(e.x, e.y);
break;
case SWT.MouseUp:
origin = null;
break;
case SWT.MouseMove:
if (origin != null) {
Point p = display.map(toplevelShell, null, e.x, e.y);
toplevelShell.setLocation(p.x - origin.x, p.y
- origin.y);
}
break;
}
}
};
toplevelShell.addListener(SWT.MouseDown, listener);
toplevelShell.addListener(SWT.MouseUp, listener);
toplevelShell.addListener(SWT.MouseMove, listener);
toplevelShell.open();
while (!toplevelShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
System.exit(0);
}
private void paintCanvas(GC gc) {
Rectangle area = canvas.getClientArea();
if (doesFileExist(currentImage)) {
Image image = new Image(display, currentImage);
Rectangle bounds = image.getBounds();
gc.drawImage(image, bounds.x, bounds.y, bounds.width,
bounds.height, area.x, area.y, area.width, area.height);
image.dispose();
} else {
gc.setBackground(toplevelShell.getBackground());
gc.fillRectangle(area);
}
}
private static boolean doesFileExist(String filename) {
return (filename != null && filename.length() > 0 && openFile(filename)
.exists());
}
private static File openFile(String file) {
return new File(file);
}
}