[Today's Reading] Standard Widget Toolkit (SWT) Part 1
March 28, 2009
While I’m learning developing eclipse plugins, I et a chapter for java SWT. SWT stands for standard widget toolkit.
Basic points for SWT application
- Each SWT-based application has one Display instance that represents the link between the underlying platform and SWT. SWT will be responsible for managing event loop and provides access to the platform resources SWT needs.
- Each window has a Shell representing the window frame with which the user interacts. It handles the familiar moving and sizing behavior common to all windows and acts as the parent for any widgets displayed within its bounds.
Some basic facts and requirements achieved in SWT
- SWT is a layer built on the java platform.
- SWT is required to be small, and hence widget state would be stored in the platform widget rather than in the SWT widget. Hence also SWT widgets cannot properly exist by themselves. When an SWT widget is created, its underlying platform counterpart is immediately created. Almost all requests for widget state information go to the platform widget.
- Most platforms require that widgets be created within the context of a specific parent, so SWT requires that a parent widget be supplied as one of its constructor arguments.
- SWT style settings must be supplied at creation time. Style bits are represented by int constants defined in the SWT class. Styles are then OR’ed together and passed as another constructor argument to create the initial style of a widget.
- SWT resources for the platform should be explicitly disposed when they are no longer needed. if you create a widget, you must destroy the widget using its dispose() method. a widget that is a child of another widget is automatically destroyed when its parent is destroyed. As a rule, disposing a shell will dispose all children in the shell.
Widget Events
- An event is the mechanism that notifies an application when a user performs a specific action.
- Events are handled by adding a listener to a widget.
- For each type of event, SWT defines:
- a listener interface (for example, <EventName>Listener)
- an event class.
- if necessary, an adapter class (in cases where the listener interface defines more than one method).
- For each widget that implements a specific event, there are corresponding add<EventName>Listener and remove<EventName>Listener methods. For every widget property, there is a get<PropertyName> and a set<PropertyName> method.
- All the UI objects in the system are derived from the abstract classes Widget and Control.
- The Widget class is the abstract superclass of the following classes: Caret, Control (discussed below), DragSource, DropTarget, Item, Menu, ScrollBar, and Tracker.
- The Control class is the abstract superclass of all the dialog and window component classes such as Button, Label, ProgressBar, Sash, Scrollable, and Slider.