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.
In general, the RWT theming allows to define
A theme setting always affects all instances of a control equally. It is not possible to define different presentation schemes for the same widget, such as blue buttons, large buttons and oval buttons. If this is what you need, you probably need a custom widget.
As an example, the difference between the default look and feel and a custom
theme could look like this:
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, undefined properties stay at their default value.
See below for the syntax of the property values.
The following is an example for a simple theme file:
# My Aquablue Theme # # Frame border for group boxes # default: 1 solid #aca899 group.frame.border: 2 dotted #56a0ea # Font for title bar of Shells # default: bold 11 "Segoe UI", Corbel, Calibri, Tahoma, "Lucida Sans Unicode", sans-serif shell.title.font: bold 15 "Trebuchet MS", Arial, Helvetica, sans-serif # Height of the title bar of Shells # default: 18 shell.title.height: 25 ...
In order to make your theme available, you have to register it with the
extension point org.eclipse.rap.swt.themes.
In the plugin.xml of your application project, add an extension
like this:
<extension
point="org.eclipse.rap.swt.themes">
<theme
id="my.application.aquablue"
name="Aqua Blue Test Theme"
file="aqua-blue.properties" />
</extension>
To make your application use the custom theme you have to register a branding as shown in the example below. For details, refer to the article on RAP branding).
<extension
point="org.eclipse.rap.ui.branding">
<branding
id="my.application.aquabranding"
servletName="aqua"
defaultEntrypointId="my.application.entrypoint1"
themeId="my.application.aquablue">
</branding>
</extension>
For testing purposes, a custom theme can also be activated by passing the
theme id in the URL parameter theme (e.g.
http://localhost:9090/rap?startup=controls&theme=my.application.aquablue).
There is no support for programmatic activation of custom themes yet.
Property values specified in a theme file must conform to the following syntactical rules:
Colors can be specified in one of these ways:
0 .. 255 that denote the red, green, and blue portion of the
color, respectively.
#rgb or
#rrggbb, that is commonly used for HTML pages.
Examples for valid color definitions:
white0, 128, 128#fffaf0
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 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.
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:
none1px inset2px groove1px solid black2px solid #fffa00
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 10pxHelvetica 10px bold10px Helvetica bold italic12px Tahoma, "Lucida Sans Unicode", sans-serif italic
Custom images may be defined using a '/'-separated path name that
identifies the location of an image resource within the bundle.
You can also specify the keyword none to indicate that no image
must be used.
Examples:
resource/images/upper-left.pngnone
The SWT system colors, as returned by Display#getSystemColor(),
are also themeable.
The following list indicates which theme parameters manipulate these colors:
| SWT System Color | Theming Key |
|---|---|
| SWT.COLOR_WIDGET_DARK_SHADOW | widget.darkshadow |
| SWT.COLOR_WIDGET_NORMAL_SHADOW | widget.shadow |
| SWT.COLOR_WIDGET_LIGHT_SHADOW | widget.lightshadow |
| SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW | widget.highlight |
| SWT.COLOR_WIDGET_BACKGROUND | widget.background |
| SWT.COLOR_WIDGET_BORDER | widget.thinborder |
| SWT.COLOR_WIDGET_FOREGROUND | widget.foreground |
| SWT.COLOR_LIST_FOREGROUND | list.foreground |
| SWT.COLOR_LIST_BACKGROUND | list.background |
| SWT.COLOR_LIST_SELECTION | list.selection.background |
| SWT.COLOR_LIST_SELECTION_TEXT | list.selection.foreground |
| SWT.COLOR_INFO_FOREGROUND | widget.info.foreground |
| SWT.COLOR_INFO_BACKGROUND | widget.info.background |
| SWT.COLOR_TITLE_FOREGROUND | shell.title.foreground |
| SWT.COLOR_TITLE_BACKGROUND | shell.title.background |
| SWT.COLOR_TITLE_BACKGROUND_GRADIENT | shell.title.background.gradient |
| SWT.COLOR_TITLE_INACTIVE_FOREGROUND | shell.title.inactive.foreground |
| SWT.COLOR_TITLE_INACTIVE_BACKGROUND | shell.title.inactive.background |
| SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT | shell.title.inactive.background.gradient |