There are a number of style bits that are applicable to windows, and some useful methods to affect how the window appears. For example, it might be desirable to make the clock appear semi-transparently, which allows the clock to float above other windows. SWT's Shell
has a number of these options that can be set.
Shell
inside the widgetSelected()
method in the Activator
class's inner class to add SWT.NO_TRIM
(no close/minimize/maximize widgets) and SWT.ON_TOP
(floating on top of other windows):shell = new Shell(trayItem.getDisplay(),SWT.NO_TRIM|SWT.ON_TOP);
128
, which is semi-transparent:shell.setAlpha(128);
SWT.APPLICATION_MODAL
:shell = new Shell(trayItem.getDisplay(),SWT.APPLICATION_MODAL);
setFullScreen()
or setMaximized()
depending on the platform:shell.setFullScreen(true); shell.setMaximized(true);
Shell
back to use SWT.NO_TRIM
and SWT.ON_TOP
.circle()
method to the Activator
class, which has been taken from Snippet134.java
(taken from the SWT snippets page at http://www.eclipse.org/swt/snippets/):private static int[] circle(int r, int offsetX, int offsetY) { int[] polygon = new int[8 * r + 4]; //x^2 + y^2 = r^2 for (int i = 0; i < 2 * r + 1; i++) { int x = i – r; int y = (int)Math.sqrt(r*r – x*x); polygon[2*i] = offsetX + x; polygon[2*i+1] = offsetY + y; polygon[8*r - 2*i - 2] = offsetX + x; polygon[8*r - 2*i - 1] = offsetY – y; } return polygon; }
Region
on the Shell
. This will have the effect of making it look like the clock itself is floating. Add the following code after the Shell
is created in the widgetSelected()
method:final Region region = new Region(); region.add(circle(25, 25, 25)); shell.setRegion(region);
Region
is cleaned up:shell.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { if (region != null && !region.isDisposed()) region.dispose(); } });
Varying the flags used to create the shell affects how that window is displayed and interacts with the user. Other calls on the shell can programmatically drive transitions to full-screen and maximized or minimized status, which can be useful in specific circumstances. Some windowing systems differentiate maximized and full-screen; others have distinct characteristics.
The SWT.NO_TRIM
flag is used to display a window without the normal window furniture. This can be combined with setting a region via setRegion()
, which allows creation of a non-rectangular shape.
Often, windows without trim are floating, that is, they should stay on top of the application window even when it hasn't got the focus. To achieve this, set the SWT.ON_TOP
flag as well, and adjust the alpha (transparency) value with setAlpha()
. The alpha value is between 0 (fully transparent) and 255 (fully opaque).
A Region
can be defined from a set of connected points, or set on a pixel-by-pixel basis. It's important to note that a Region
is also a Resource
, and thus must be disposed of after use (which is typically when the Shell
is closed). The clean-up operation is similar to that of the others discussed earlier, via the addDisposeListener()
on the Shell
.