RWT Theming

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.

Introduction

Capabilities of the RWT Theming

In general, the RWT theming allows to define

for RWT controls. However, which aspects are actually customizable depends on the particular control. Some controls allow for more flexibility, others are more hard-wired.

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:

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, 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

...
  

Register the New Theme

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>
  

Activate the Theme

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.

Syntax for Property Values

Property values specified in a theme file must conform to the following syntactical rules:

Colors

Colors can be specified in one of these ways:

Examples for valid color definitions:

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:

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:

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:

Images

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:

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:

SWT System Color Theming Key
SWT.COLOR_WIDGET_DARK_SHADOWwidget.darkshadow
SWT.COLOR_WIDGET_NORMAL_SHADOWwidget.shadow
SWT.COLOR_WIDGET_LIGHT_SHADOWwidget.lightshadow
SWT.COLOR_WIDGET_HIGHLIGHT_SHADOWwidget.highlight
SWT.COLOR_WIDGET_BACKGROUNDwidget.background
SWT.COLOR_WIDGET_BORDERwidget.thinborder
SWT.COLOR_WIDGET_FOREGROUNDwidget.foreground
SWT.COLOR_LIST_FOREGROUNDlist.foreground
SWT.COLOR_LIST_BACKGROUNDlist.background
SWT.COLOR_LIST_SELECTIONlist.selection.background
SWT.COLOR_LIST_SELECTION_TEXTlist.selection.foreground
SWT.COLOR_INFO_FOREGROUNDwidget.info.foreground
SWT.COLOR_INFO_BACKGROUNDwidget.info.background
SWT.COLOR_TITLE_FOREGROUNDshell.title.foreground
SWT.COLOR_TITLE_BACKGROUNDshell.title.background
SWT.COLOR_TITLE_BACKGROUND_GRADIENTshell.title.background.gradient
SWT.COLOR_TITLE_INACTIVE_FOREGROUNDshell.title.inactive.foreground
SWT.COLOR_TITLE_INACTIVE_BACKGROUNDshell.title.inactive.background
SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENTshell.title.inactive.background.gradient