Revision as of 07:28, 17 August 2007

This article describes the theming functionality of RWT, the RAP Widget Toolkit.
This theming defines the default look and feel of the basic RWT controls like Shell, Button, Text etc.
It must not be mixed up with the theming of the Eclipse workbench. Instead, it can be compared to the theming functionality of a desktop system that allows the user to set custom colors for title bars, text background and the like.

State of Development

The RWT theming mechanism has been introduced with the M4 milestone and extended in M5.
Currently, the RWT theming allows to define custom colors, fonts, borders, dimensions, box dimensions (paddings etc.), and icons.

However, is still not much field-tested and some details are still likely to change, as our experience with this approach grows.
Your comments and suggestions are welcome.

How to define a custom RWT Theme

Create a custom theme file

RWT theme files are simple Java Property files.
A template named theme-template.properties can be found in the src/ directory of the RWT plug-in (org.eclipse.rap.rwt).
You only have to specify those properties that are relevant for your customization, as undefined properties will stay at their default value.
Note that some property names are likely to be changed in the future, other properties will emerge and a few properties will even be dropped.
Please refer to the template file shipped with your current version.
See below for the syntax of the property values.

Register the new theme with the extension point org.eclipse.rap.swt.themes

In the plugin.xml of your application project, add an extension like this:

A comma separated list of three decimal integer numbers in the range 0 .. 255 that denote the red, green, and blue portion of the color, respectively.

A hexadecimal color notation in the format #rgb or #rrggbb, that is commonly used for HTML pages.

Dimensions

Dimensions are given as integer numbers with the unit suffix px.
As all size calculations in SWT are pixel-based, only the unit "px" is allowed.

Example: 1px

Box Dimensions

Box dimensions like margins and paddings can be provided in the shorthand syntax known from CSS2.
One, two, three, or four dimensions may be specified, separated by spaces.
If four dimensions are given, they stand for the values in clock-wise order: top, right, bottom, left.
Three values stand for: top, right and left, bottom.
Two values stand for: top and bottom, right and left.
One values stands for: all four values.

Examples for valid box dimension definitions are:

5px means: 5px for top, right, bottom, and left edge.

3px 5px means: 3px for top and bottom edge, 5px for left and right.

2px 4px 0px means: 2px for the top edge, 4px for left and right, and 0px for the bottom.

2px 4px 0px 2px means: 2px top, 4px left, 0px bottom, 2px left.

Borders

A border definition may contain a size in pixels, a style keyword, and a color.
All parameters are optional.
The valid style keywords are
solid,
dotted,
dashed,
double,
inset,
outset,
groove,
ridge, and
none.

If one of the complex styles inset, outset, groove, or ridge is used without a color definition, the default system shadow colors (SWT.COLOR_WIDGET_NORMAL_SHADOW, SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW, etc., see below) are used to paint the border.

Examples for valid border definitions are:

none

1px inset

2px groove

1px solid black

2px solid #fffa00

Fonts

The syntax for font definitions is very similar to the CSS shorthand property font.
A font definition contains the font size in pixels, a comma-separated list of font-family names, and the optional keywords bold and italic. The order of the parts does not matter.

Examples of valid font definitions are:

Helvetica 10px

Helvetica 10px bold

10px Helvetica bold italic

12px Tahoma, "Lucida Sans Unicode", sans-serif italic

Images

Custom images must be referred to using a '/'-separated path name that identifies the location of an image resource within the bundle.

SWT System Colors

The SWT system colors, as returned by Display#getSystemColor(), are also themeable.
The following list indicates which theme parameters manipulate these colors: