Section 10.4. USING FIDGET


10.4. USING FIDGET

To build a Fidget library, we first select the SDK or J2ME Hardware Abstraction Layer (HAL) based on the target device's underlying Java support. PCs use the SDK; Palm devices and cell phones use J2ME. As described in Section 10.3.1, the HAL provides a small set of line and curve drawing primitives that is consistent across all platforms.

Next, we specify and compile the features we need in our library. The code implementing the different features resides in mixin layers in the kernel package, which corresponds to the Kernel layer in Figure 10-3. The actual Fidget libraries are assembled in the User layer, which we implement in the widget package. The code in Listing 10-7 shows the feature selection for two different libraries.

Both of the preceding libraries are lightweight implementations (Section 10.3.1), the only kind currently available in Fidget. The first library supports all events and, by overriding the drawing methods in LightWeightFidget, provides an alternative look and feel. The second library supports color displays, resettable labels, and key and mouse event handling. If a library feature is not supported by the device on which it runs, then executing the feature code either has no effect or throws an exception.

Listing 10-7. Feature selection for different libraries
 package widget; class Fidget extends AltLook<EventFidget<   LightWeightFidget<BaseFidget<>>>> {} class Fidget extends ColorFidget<   ButtonSetLabel<EventKey<EventMouse<   EventBase<LightWeightFidget<   BaseFidget<>>>>>>> {} 

In addition to the Fidget class, the User layer contains wrapper classes for each widget. These classes allow Fidget widgets to replace AWT widgets in application code. For example, the definitions for the Button and Window wrapper classes are shown in Listing 10-8.

Listing 10-8. Wrapper class definitions
 public class Button extends Fidget.Button{} public class Window extends Fidget.Window{} 

To use a Fidget library, application code simply imports widget.* and uses the Fidget widgets in the same way that AWT widgets are used. The sample code in Listing 10-9 functions in a similar way using either Fidget or AWT. The code creates a window with a single button. The button's label is set to "ButtonLabel," and then the window is displayed on the screen.

Listing 10-9. Replacing AWT widgets
 // import widget.* or java.awt.* public class Sample {   public static void main(String[] args) {     Window win = new Window(...);     Button b = new Button("ButtonLabel");     win.add(b);     win.setVisible(true)   } } 



Aspect-Oriented Software Development
Aspect-Oriented Software Development with Use Cases
ISBN: 0321268881
EAN: 2147483647
Year: 2003
Pages: 307

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net