3. Metawidgets

Metawidget ships with native widgets for different UI frameworks. Whilst all Metawidgets are broadly similar, they are tailored to take advantage of their native environment. This chapter covers each Metawidget in detail. For an explanation of the overall architecture of Metawidget, see Chapter 2, Architecture.

3.1 Desktop Metawidgets

Metawidget supports multiple desktop frameworks, so that you can choose the one that matches your preferred UI environment.

3.1.1 SwingMetawidget

SwingMetawidget is a Swing JComponent. For an introduction to SwingMetawidget, see Section 1.1, “Part 1 (Java version) - The First Metawidget Application” and Section 1.3.1, “Desktop Address Book”.

Installation

There are two steps to installing SwingMetawidget within a Swing application:

  1. Add metawidget-all.jar to your CLASSPATH.

  2. Optionally configure the Metawidget, as described below.

Configuration

SwingMetawidget is preconfigured with sensible defaults for Swing. You can change this configuration either programmatically (as detailed in Section 1.1.5, “Inspectors”) or using a metawidget.xml file (as detailed in Section 1.1.9, “Configuring Metawidget Externally”).

Customizing Look and Feel

Since inception, Swing has had built-in, and extensive, Look and Feel support. Metawidget does not overlap this. For layouts, Swing supports a multitude of LayoutManagers. Metawidget leverages these, and automates them to construct UIs automatically. The layout manager can be configured through either metawidget.xml or programmatically using setMetawidgetLayout.

Internationalization

SwingMetawidget supports localization through the setBundle method. This method takes a ResourceBundle object. Keys are looked up based on the name of each business property.

Under The Hood

SwingMetawidget inspects objects and populates child widgets automatically in response to the standard JComponent.paintComponent event. There is no need to explicitly trigger population. SwingMetwidget also populates itself just-in-time if clients interrogate it through standard methods such as JComponent.getComponentCount or JComponent.getBounds.

3.1.2 SwtMetawidget

SwtMetawidget is an SWT Composite. For an introduction to SwtMetawidget, see Section 1.3.1, “Desktop Address Book”.

Installation

There are two steps to installing SwtMetawidget within an SWT application:

  1. Add metawidget-all.jar to your CLASSPATH.

  2. Optionally configure the Metawidget, as described below.

Configuration

SwtMetawidget is preconfigured with sensible defaults for SWT. You can change this configuration either programmatically (as detailed for Swing in Section 1.1.5, “Inspectors”, but the SWT API is the same) or using a metawidget.xml file (as detailed in Section 1.1.9, “Configuring Metawidget Externally”).

Customizing Look and Feel

Since inception, SWT has had built-in, and extensive, Look and Feel support. Metawidget does not overlap this. For layouts, SWT supports a multitude of LayoutManagers. Metawidget leverages these, and automates them to construct UIs automatically. The layout manager can be configured through either metawidget.xml or programmatically using setMetawidgetLayout.

Internationalization

SwtMetawidget supports localization through the setBundle method. This method takes a ResourceBundle object. Keys are looked up based on the name of each business property.