Aligning the Items with Layout
You can align your items with the layout attribute. The layout attribute defines how the affected item should be aligned and laid out. Possible layout values are, for example, left, right, and center. All layout values of the MIDP 2.0 standard can be used, as shown in Table 12-9. If you want to use the complete available width and center the item horizontally, you can specify layout center expand , for example. You can use several signs for separating the layout values use the , , or, or and...
Integrating Source Code ThirdParty APIs
When a third-party API is available in source code, you can integrate it by modifying the sourceDir attribute of the lt build gt element in the build.xml file. Consider the case where your normal application code is in the source src directory and the source code of the third-party API is in the source thirdparty folder. You can now add the third-party API with the lt sources gt element, as shown in Listing 7-35. As most other elements, you can use if and unless conditions for your sources....
Programming the TabbedForm
The de.enough.polish.ui.TabbedForm is a Form that arranges the included GUI elements on several tabs. You can use any Form methods, such as setItemStateListener , in the TabbedForm as well. Table 12-4 lists the additional methods for configuring the tabs of aTabbedForm. Table 12-4. Additional TabbedForm Methods TabbedForm String title, String tabNames, Image tabImages set int tabIndex, int itemIndex, Item item setScreenStateListener ScreenStateListener listener style myTabbedForm TabbedForm...
Setting a Foreground Image
Each screen can have a so-called foreground image that is painted on top of all other elements. You can use this feature for displaying a figure that seems to hold the menu options, for example. Table 12-17 summarizes the relevant attributes for setting a foreground image. Table 12-17. Additional Attributes for Setting a Foreground Image Table 12-17. Additional Attributes for Setting a Foreground Image The URL of a image that should be painted at the front of the screen, for example,...
Using Different Packagers
The packager is responsible for creating the final JAR bundles from the application classes and the resources. You can integrate your own packager by defining the lt packager gt element inside the lt build gt element in your build.xml script. Ifyou call an Ant target with lt packager name antcall target package gt , you can use the additional Ant properties polish.package.source in which all resources, classes, and the manifest reside and polish.package.target which points to the file in which...
Arranging Items on a Screen
Usually J2ME Polish arranges each GUI item on its own row, as shown in Figure 12-15. You can change the arrangement of the items either by using the view-type attribute or by using a tabular layout with the columns and columns-width attributes. You can apply view types to any screens that contain items, for example, Lists or Forms. Several view types are available, which are usually defined in a screen style, for example, .mainScreen view-type dropping . You can use either a predefined name of...
Colors
You can define colors in the colors section and in each attribute that ends in -color, such as font-color and border-color, for example. You can use predefined colors, RGB definitions, and ARGB definitions. You can use the standard Windows colors directly, such as background-color yellow , for example. Table 12-10 lists all the available predefined colors. Table 12-10. The Predefined Colors of J2ME Polish Another predefined color is transparent, which results in a transparent area. transparent...
Fonts
Many GUI items have text elements that you can design with the font attributes of the corresponding style. Table 12-11 explains the available attributes. Table 12-11. Available Font Attributes Reference to a color or direct declaration of the color. medium default, normal large big The name of the bitmap font. The extension .bmf is not needed. Depending on the number of colors the device supports, colors can look differently on the actual device. The default font face used when the font-face or...
Bitmap Fonts
You can use bitmap fonts instead of the usual predefined fonts for any text elements such as titles, Stringltems, and so on. Please refer to Chapter 10 to learn more about these fonts and how you can create them using the polish.home bin fonteditor tool. You can integrate bitmap fonts with the font-bitmap attribute. You don't need to give the .bmf extension, by the way. Listing 12-28 uses the china.bmffont for the currently focused item. Listing 12-28. Using a Bitmap Font for the Currently...
Using a Postcompiler
A postcompiler is called after the sources have been successfully compiled. You can use it to modify the bytecode of your application, which is a source of never-ending fun if you happen to like this sort of humor, that is. Several bytecode modification libraries are available, most notably BCEL http jakarta.apache.org bcel and ASM http asm.objectweb.org . When you are at home with the bytecode level, you can gain some amazing benefits. The Floater tool of Enough Software uses this mechanism...
MathFP
The MathFP library by Onno Hommes offers fast calculations and is licensed under the Liberal Source License. You can download it from You can use the MathFP library either in the long mode for higher precision using the net.jscience.math.MathFP class or in the less resource int mode using the net.jscience. math.kvm.MathFP class . Instead of using float or double values, you need to convert Strings into the internal MathFP format first. After the conversion you will get an internal integer...
public Displayable initApp
e.g., read data from the record store, etc. now create the main menu screen e.g., this.mainScreen new Form Main Menu public void destroyApp boolean unconditional For long operations such as loading data over the network or searching for data in record stores, you should give some thought to how you can measure and visualize the progress. The best case is when you know in advance how long the operation lasts and how many steps it involves. In such a case, you can just show a progress meter...
MicroFloat
The MicroFloat library by Dave Clausen is known for its high precision. Calculations with MicroFloat yield the results similar to native Java floating-point calculations, since MircoFloat follows the international IEEE 754 standard http grouper.ieee.org groups 754 . You can download MicroFloat at The usage of MicroFloat is similar to MathFP You can use either the net.dclausen. microfloat.MicroFloat class for emulating float or the net.dclausen.microfloat.MicroDouble class for emulating double...
MIDP Platforms
MIDP-compatible platforms based on JSRs 37, 118, and 271 form the vast majority of available mobile Java implementations. Symbian http www.symbian.com developer provides the most widely used operating system and with it the MIDP profile. The UIQ 2.x version from Symbian additionally supports the Personal Java profile. The current Symbian OS uses Sun's CLDC HI 1.1 implementation, which features a dynamic adaptive compiler. This DAC compiler can compile selected bytecode on demand and hotswap it...
The SysInfo MIDlet
J2ME Polish also contains the MIDPSysInfo MIDlet, which allows you to check the capabilities of your device quickly. It is located in the polish.home samples sysinfo folder and needs to be built first, either by calling ant from the command line or by executing the build.xml script from within your IDE. You will then find the files MIDPSyslnfo.jar and MIDPSyslnfo.jad in the dist folder. Figure 10-6 shows the SysInfo application in action. Figure 10-6. Checking the capabilities of your device...
Programming the FramedForm
The de.enough.polish.ui.FramedForm splits the screen into a main area and four possible frames at the top, bottom, left, or right side of the screen. Only the main area is scrolled while the frames remain in their positions. You can use frames for positioning buttons at fixed positions or for including a TextField to filter the shown items, for example. Table 12-5 lists the additional methods of the FramedForm. Table 12-5. Additional FramedForm Methods append int frameOrientation, Item item...
Setting the Compiler
You can use another compiler or configure the compiler by using the lt compiler gt element, as shown in Listing 13-12. Ant supports the following compilers classic, modern, jikes, jvc, kjc, gcj, sj, and extJavac. You can use any attributes and nested elements that are supported by Ant s lt javac gt task. Usually, debugging information is included only when you activate the logging framework with the lt debug gt element, but with the settings of Listing 13-12 you will always include debugging...
Identifying Platforms
In addition to the MIDP platforms, several similar mobile Java platforms are available that are partly compatible with the J2ME standard. Table 15-4 lists the most important platforms. Tip From J2ME Polish 1.3 onward, you can build for any of these platforms and even define additional platforms in the poHsh.home custom-platforms.xml file. Table 15-4. Important Mobile Java Platforms Table 15-4. Important Mobile Java Platforms Leading standard for creating mobile Java applications. Additional...
Other Utility Classes
J2ME Polish contains a few more utility classes, which are discussed in other chapters The de.enough.polish.util.Locale class retrieves localized messages, provides additional information about the locale, and offers locale-specific methods like date formatting. Localization of mobile applications is discussed in Chapter 7. The de.enough.polish.util.Debug class allows you to log messages and is used by the debug preprocessing directive. Debugging is discussed in Chapter 9. J2ME Polish also...
public void processClass StringList lines String className
if this.doProcessClass return int extendsIndex line.indexOf extends Canvas line line.substring 0, extendsIndex extends this.fullScreenClass line.substring extendsIndex extends Canvas.length lines.setCurrent line In the FullScreenPreprocessor, you are searching for extends Canvas terms in the complete source code. For making this efficient, you start the parsing only when the current target device has a fullscreen class defined. You check this in the overridden notifyDevice method that is called...
The BitMapFont Class
The J2ME standard isn t really overwhelming when it comes to font support. It provides for only the following Three different font faces proportional, monospace, and system , but often the system and the proportional fonts are the same. Three different sizes small, medium, and large , with the actual size depending on the implementation. You can check the size with the polish.Font.small, polish.Font.medium, and polish.Font.large preprocessing variables. Font styles of bold, italic, underlined,...
Series
Series 40 devices are manufactured for the mass market they feature small sizes and low prices but also are more resource restrained than other Nokia devices. All Series 40 models are based on Nokia s proprietary operating system. The screen size is usually 128X128 pixels and can be used fully by either using Nokia s FullCanvas class or setting the Canvas to full-screen mode on MIDP 2.0-based devices. Few Series 40 devices have screens with 128X160 pixels, and some even have screens with 96X65...
