Sun Java Solaris Communities My SDN Account Join SDN
 
Archive - Java Technology Products Download

Truffle Graphical Toolkit Customization Guide: Architecture

 

Architecture

Previous   |   TOC   |   Next

The Truffle graphical toolkit was designed to meet several requirements. It supplies an AWT peer set written in the Java programming language. Furthermore, it provides a framework for supplying alternate look & feel designs that are targeted at different kinds of platforms, including consumer devices and desktop systems. This section describes how the Truffle graphical toolkit's architecture supports these goals.

The figure below illustrates the major components of the Truffle graphical toolkit's architecture and compares them with desktop implementations of the JDK. The Truffle graphical toolkit fulfills the goal of providing a cross-platform GUI toolkit by providing a set of peer components and the window and graphics system necessary to support them. The Truffle graphical toolkit plays the same role in a Java application environment like the PJAE that native peer sets perform in desktop implementations of the JDK. In fact, the Truffle graphical toolkit can be used to replace these native peer sets.

It is much easier to understand the Truffle Graphical Toolkit's purpose and design by thinking of the Truffle Graphical Toolkit in its relationship with the AWT rather than seeing it as sitting on top of a window and graphics system. The reason lies in the Truffle Graphical Toolkit's goal of providing just enough GUI services to meet the requirements of the AWT. In other words, the Truffle Graphical Toolkit is not a general-purpose GUI toolkit with a large number of widgets like Motif and JFC. It is specifically designed to support the API requirements of the AWT and the human-interface needs of consumer devices.

Truffle Graphical Toolkit Architecture [Click on image for larger view]

Truffle graphical toolkit architecture

Object Toolkit

The Truffle graphical toolkit contains a toolkit-within-a-toolkit named Object Toolkit (OTK) that can be used by licensees to construct new look & feel designs. For example, the Touchable look & feel design is represented by a set of classes in sun.awt.touchable that use OTK classes to implement AWT peer components that appear and behave in a way that is suitable for touchscreen-based consumer devices like screenphones. Another look & feel design could be an implementation of Metal, the Java look & feel design used in JFC.

The Truffle Graphical Toolkit uses the Model-View-Controller (MVC) architecture to organize the peer set implementation into groups of classes that perform different roles:

Modeldata state
Viewappearance
Controllersynchronization or behavior

MVC is an example of a design pattern. See Design Patterns: Elements of Reusable Object-Oriented Software. for a more thorough introduction to design patterns.

MVC allows effective use of code sharing that leverages functionality between components and thus reduces code size. From a licensee's perspective, OTK reduces the software development task for creating a platform-specific look & feel design by focusing effort on the appearance and behavior of the peer components and avoiding the implementation of the underlying support systems.

Internal Toolkit Components

The Truffle Graphical Toolkit allows implementations to create two types of components: peer components that correspond to the java.awt.peer interfaces and internal toolkit components. This second category contains components without external application-level APIs. Instead these internal components are used by the toolkit itself to provide platform-level services (e.g. Taskbar) or alternate input techniques (e.g. VirtualKeyboard).

Look & Feel Implementation Strategies

There are a number of approaches to take in implementing a look & feel design with the Truffle Graphical Toolkit. The sections below describe the major alternatives.

Configure Touchable

The term configuration is used to indicate ways in which Touchable can be changed without many source code changes. Touchable was designed to be configurable in two ways:

  • Scaling Factors. By default, Touchable supports a display size of 640x480. This can easily be switched by using a scaling factor defined in DrawUtils. The PersonalJava emulation environment (PJEE) also has some runtime properties (sun.graphicssystem.height and sun.graphicssystem.width) that are useful in testing different scaling factors.

  • Color Schemes. Touchable has a color palette which is based on a subset of the symbolic color names in java.awt.SystemColor. Each palette entry identifies colors used for various component elements. For example, user text is displayed with the color defined by the symbolic color java.awt.SystemColor.TEXT_TEXT. This symbolic name is mapped to a named color value defined in a palette.

    The default color palette used by Touchable is based on the color orange. Touchable can be configured to use a different predefined color palette (by using the PJEE runtime property sun.awt.palette) or defining a new color palette in reference/classes/lib/touchable.palettes.

Modify Touchable

Modifying Touchable is the most common approach to developing a new look & feel design. This involves a moderate amount of source code changes. Here are some possible scenarios:
  • Develop a new feel. Add or subtract Controllers attached to the View classes. This modification is easy to do and represents a modified feel.

  • Develop a new look. The two approaches to take with this task are organized around where the implementation for the painting code resides:

    • Directly extend a View class. This approach is easier to understand at first, but it fails to take advantage of the benefits of factoring shared drawing code. Still, some of the more complex components in Touchable use this approach.

    • Share design elements in DrawUtils. This approach steamlines the implementation of components by coordinating their design features and reducing their implementation footprint.

Build an OTK-based Toolkit

Developing an entirely new toolkit based on OTK is a significant amount of work. This approach usually indicates that some architectural goal of the new look & feel is not being met by Touchable and it is better to start from scratch. Even so, it is still best to have a solid understanding of the Touchable implementation before starting on a new toolkit.

OTK contains the minimal common subset of toolkit functionality. Therefore, a full Truffle-based toolkit requires substantially more than the functionality that sun.awt.otk provides. For example, the ColorPolicy, DrawUtils and TouchableToolkit classes are all outside of sun.awt.otk.

Replaceable Look & Feel Designs

The Truffle Graphical Toolkit can support a variety of look & feel designs. A specific look & feel design is attached to a given Java application environment at startup time. So only a single look & feel design is available for that platform during a user session. This is called a replaceable look & feel architecture to distinguish it from JFC's pluggable look & feel architecture which allows each application to select a look & feel design at runtime.

Look & Feel DesignTarget System
Touchabletouchscreen-based screen phones
Couchableremote control-based set-top boxes
Metalnetwork computers & PCs

In addition, licensees can use OTK to build product-specific look & feel designs that support their product identity or product design needs. This can be done by modifying an existing design like Touchable with a different color scheme or by developing a new look & feel design from scratch.

Truffle Graphical Toolkit Software and Different Java Technology-based Application Environments

The Truffle Graphical Toolkit is part of the PJES but it can also be used with other Java application environments like the EmbeddedJava application environment, JavaOS and JDK-based systems.

Window and Graphics System

The Truffle Graphical Toolkit includes a special-purpose window and graphics system written mostly in the Java programming language. The platform-dependent portion of the graphics system is usually based on a platform's graphics library.

I18N Support

The Truffle Graphical Toolkit provides I18N services required by the AWT. In particular, The Truffle Graphical Toolkit includes an input method framework written in the Java programming language and virtual keyboard support. Native input methods can be integrated with this input method framework with an adapter class. Beyond portability, the main advantages of the Truffle Graphical Toolkit input method framework is its integration with both virtual keyboards and lightweight components.
Previous   |   TOC   |   Next