Professional Documents
Culture Documents
1
Table of Contents
Preamble.............................................................................................................................9
Introduction to J2ME Polish............................................................................................11
Installation......................................................................................................................11
An Example Application..................................................................................................11
Building the Application..................................................................................................11
Designing the Application with CSS...............................................................................12
Debugging and Logging.................................................................................................14
Easy Device-Optimizations with Preprocessing and the Device-Database....................15
Fun Fun Fun: The Game-Engine....................................................................................16
Extending J2ME Polish..................................................................................................17
Installation........................................................................................................................18
Requirements.................................................................................................................18
Installation of J2ME Polish.............................................................................................18
Updating J2ME Polish....................................................................................................18
Integrating J2ME Polish into Eclipse..............................................................................18
Integrating J2ME Polish into Borland's JBuilder.............................................................19
Integrating J2ME Polish into NetBeans..........................................................................20
NetBeans 3.6..........................................................................................................................20
NetBeans 4.x..........................................................................................................................20
NetBeans 5.x...........................................................................................................................21
Setup and Configuration of Ant......................................................................................21
Integrating J2ME Polish with an Existing Project...........................................................22
The Device Database.......................................................................................................23
vendors.xml....................................................................................................................23
groups.xml......................................................................................................................23
devices.xml.....................................................................................................................24
apis.xml..........................................................................................................................25
Extending the Devic Database.......................................................................................26
Device Capabilities.........................................................................................................26
The Build Process............................................................................................................28
Introduction....................................................................................................................28
Definition of the J2ME Polish-task.................................................................................28
Example.........................................................................................................................28
The <info>-Section.........................................................................................................31
The <deviceRequirements>-Section..............................................................................33
The <build>-Section.......................................................................................................36
Attributes of the build-Section.................................................................................................36
Elements of the build-Section.................................................................................................39
<sources>..........................................................................................................................39
<midlet> and <midlets>......................................................................................................40
2
<iappli>...............................................................................................................................40
<resources>.......................................................................................................................41
The <filter> Subelement..............................................................................................................................42
The <fileset> Subelement............................................................................................................................42
The <localization> Subelement...................................................................................................................43
The <copier> Subelement............................................................................................................................43
The antcall Resource Copier..................................................................................................................44
The renamer Resource Copier................................................................................................................44
The svgconverter Resource Copier........................................................................................................45
<compiler>.........................................................................................................................45
The <compilerargs> Subelement.................................................................................................................47
<obfuscator>......................................................................................................................48
The <keep> Subelement..............................................................................................................................49
The <parameter> Subelement......................................................................................................................49
Combining Several Obfuscators..................................................................................................................50
Specific Obfuscator Settings........................................................................................................................50
ProGuard................................................................................................................................................50
yGuard....................................................................................................................................................50
RetroGuard.............................................................................................................................................51
Zelix KlassMaster...................................................................................................................................51
DashO Pro..............................................................................................................................................51
JODE......................................................................................................................................................52
<variables> and <variable>................................................................................................52
<debug>.............................................................................................................................54
<jad>..................................................................................................................................55
Sorting and Filtering JAD attributes............................................................................................................56
<manifestFilter>.................................................................................................................57
<preprocessor>..................................................................................................................58
<java>................................................................................................................................59
<packager>........................................................................................................................60
The <emulator>-Section.................................................................................................61
Attributes of the <emulator>-Section......................................................................................62
The <parameter> Subelement................................................................................................63
Emulator-Settings in the Device Database and in the build.xml.............................................63
WTK Emulators..................................................................................................................63
Nokia Emulators.................................................................................................................64
Siemens Emulators............................................................................................................64
Motorola Emulators............................................................................................................64
Launching any Emulator with the GenericEmulator-Implementation.................................64
Automatic Resolving of Stack Traces and Exceptions............................................................65
Resource Assembling......................................................................................................67
Concepts........................................................................................................................67
Often Used Groups........................................................................................................67
Fine Tuning the Resource Assembling..........................................................................69
Localization.......................................................................................................................70
Concepts........................................................................................................................70
The <localization>-Element and Localized Resource Assembling.................................71
Managing Translations...................................................................................................71
The Locale Class....................................................................................................................71
3
Dynamic Translations..............................................................................................................72
Defining Translations...............................................................................................................73
Setting and Using Localized Variables....................................................................................74
Using Localized Attributes.......................................................................................................74
Coping with Dates and Currencies.................................................................................74
Common Traps...............................................................................................................75
Adjusting the JAR-name.........................................................................................................75
Using Quotation Marks and Other Special Characters in Translations..................................75
Invalid Locale Calls.................................................................................................................75
Localizing the J2ME Polish GUI.....................................................................................76
The World of Preprocessing............................................................................................78
Checking a Single Symbol with #ifdef, #ifndef, #else, #elifdef, #elifndef and #endif......78
Checking Several Symbols and Variables with #if, #else, #elif and #endif....................79
Using Variable-Functions for Comparing Values....................................................................81
Hiding Code...................................................................................................................82
Debugging with #debug, #mdebug and #enddebug......................................................82
Debug Levels..........................................................................................................................83
The Debug Utility Class..........................................................................................................84
Using Variables with #=..................................................................................................84
Variable-Functions..................................................................................................................85
Setting CSS Styles with #style.......................................................................................86
Exclude or Include Complete Files with #condition........................................................87
Defining Temporary Symbols or Variables with #define and #undefine.........................87
Inserting Code Fragments with #include........................................................................88
Analyzing the Preprocessing-Phase with #message and #todo....................................88
Handling Several Values in Variables with #foreach .....................................................89
Useful Symbols..............................................................................................................90
APIs and MIDP-Version..........................................................................................................90
J2ME Polish Symbols.............................................................................................................90
Useful Variables.............................................................................................................90
File Operations........................................................................................................................91
The J2ME Polish GUI.......................................................................................................92
Overview........................................................................................................................92
Activation of the GUI......................................................................................................92
Configuring the J2ME Polish GUI..................................................................................93
Using the GUI in Full-Screen-Mode........................................................................................93
Configuring Commands, Labels and Programming of the GUI..............................................95
The J2ME Polish GUI for Programmers.........................................................................96
Setting Styles..........................................................................................................................97
Using Dynamic and Predefined Styles....................................................................................98
Porting MIDP/2.0 Applications to MIDP/1.0 Platforms............................................................99
Programming Specific Items and Screens..............................................................................99
Programming the TabbedForm..........................................................................................99
The J2ME Polish GUI for Designers............................................................................102
A Quick Glance.....................................................................................................................102
4
Designing for Specific Devices or Device-Groups................................................................103
The Hierarchy of the “resources” Folder..........................................................................103
Groups..............................................................................................................................104
API- and Java-Platform-Groups.................................................................................................................104
BitsPerPixel-Groups...................................................................................................................................104
Dynamic, Static and Predefined Styles.................................................................................105
Static Styles......................................................................................................................106
Predefined Styles.............................................................................................................106
Dynamic Styles.................................................................................................................107
Extending Styles...................................................................................................................109
CSS Syntax...........................................................................................................................109
Structure of a CSS Declaration.............................................................................................109
Naming.............................................................................................................................110
Grouping of Attributes.......................................................................................................110
Referring to Other Styles..................................................................................................110
Comments........................................................................................................................110
Common Design Attributes....................................................................................................111
Structure of polish.css......................................................................................................111
Structure of a Style Definition...........................................................................................111
The CSS Box Model: Margins and Paddings...................................................................112
The Layout Attribute.........................................................................................................113
Colors...............................................................................................................................114
Predefined Colors.......................................................................................................................................114
The colors Section......................................................................................................................................115
How to Define Colors................................................................................................................................115
Alpha Blending...........................................................................................................................................116
Fonts.................................................................................................................................116
Bitmap-Fonts....................................................................................................................117
Creating Bitmap-Fonts...............................................................................................................................117
Using Bitmap-Fonts in the J2ME Polish GUI............................................................................................117
Using Bitmap-Fonts Directly ....................................................................................................................118
Labels...............................................................................................................................118
Backgrounds and Borders................................................................................................119
Before and After Attributes...............................................................................................119
Specific Design Attributes.....................................................................................................120
Backgrounds....................................................................................................................120
Simple Background....................................................................................................................................120
Round-Rect Background............................................................................................................................120
Image Background.....................................................................................................................................121
Circle Background.....................................................................................................................................122
Pulsating Background................................................................................................................................123
Pulsating Circle Background.....................................................................................................................123
Pulsating Circles Background....................................................................................................................124
Opening Background.................................................................................................................................124
Opening-Round-Rect Background.............................................................................................................125
Round-Tab Background.............................................................................................................................126
Smooth-Color Background....................................................................................................126
Tiger-Stripes Background......................................................................................................127
Ball-Games Background.......................................................................................................127
Borders.............................................................................................................................128
5
Simple Border............................................................................................................................................128
Round-Rect Border....................................................................................................................................129
Shadow Border...........................................................................................................................................129
Top, Bottom, Left and Right Border..........................................................................................................130
Circle Border..............................................................................................................................................130
Screens: List, Form and TextBox.....................................................................................131
Predefined Styles for Lists, Forms and TextBoxes.....................................................................................131
Additional Attributes for Screens...............................................................................................................131
Dynamic Styles for Screens.......................................................................................................................133
List........................................................................................................................................................133
Form.....................................................................................................................................................133
TextBox................................................................................................................................................133
Commands.................................................................................................................................................133
Example.....................................................................................................................................................134
View Types.......................................................................................................................136
Dropping View...........................................................................................................................................136
Shuffle View..............................................................................................................................................137
MIDP/2.0 View..........................................................................................................................................137
The StringItem: Text, Hyperlink or Button........................................................................137
The IconItem....................................................................................................................138
The ChoiceItem................................................................................................................138
The ChoiceGroup.............................................................................................................139
The Gauge.......................................................................................................................140
The TextField....................................................................................................................141
TextField-Commands.................................................................................................................................142
Direct Input Mode......................................................................................................................................142
The DateField...................................................................................................................144
The Ticker........................................................................................................................145
The Menu Bar...................................................................................................................145
The Extended Menu Bar..................................................................................................146
The TabbedForm..............................................................................................................148
The MIDP/2.0-Compatible Game-Engine......................................................................149
How It Works................................................................................................................149
Limitations....................................................................................................................149
Optimizations................................................................................................................149
Using a Fullscreen-GameCanvas ........................................................................................150
Backbuffer Optimization for the TiledLayer...........................................................................150
Splitting an Image into Single Tiles.......................................................................................151
Defining the Grid Type of a TiledLayer..................................................................................151
Using the Game-Engine for MIDP/2.0 Devices.....................................................................151
Porting a MIDP/2.0 Game to MIDP/1.0 Platforms........................................................152
Building the Existing Application...........................................................................................152
Adjusting the build.xml.....................................................................................................152
Managing the Resources.................................................................................................153
Building the Game............................................................................................................154
Porting the Game to MIDP/1.0..............................................................................................154
Necessary Source Code Changes...................................................................................154
Working Around the Limitations of the Game-Engine......................................................154
Pixel-Level Collision Detection.................................................................................................................154
6
Sprite Transformations...............................................................................................................................154
Using Preprocessing for Device Specific Adjustments....................................................156
Extending J2ME Polish..................................................................................................157
Integrating a Custom Obfuscator.................................................................................157
Preparations..........................................................................................................................157
Creating the Obfuscator Class..............................................................................................157
Integrating the Obfuscator into the build.xml........................................................................158
Configuring the Obfuscator with Parameters........................................................................158
Creating and Using Custom Preprocessing Directives.................................................159
Preparations..........................................................................................................................159
Creating the Preprocessor Class..........................................................................................159
Using the registerDirective()-Method...............................................................................159
Using the processClass()-Method....................................................................................160
Integrating the Preprocessor into the build.xml.....................................................................160
Configuring the Preprocessor with Parameters....................................................................161
Extending the J2ME Polish GUI...................................................................................161
Using Custom Items..............................................................................................................161
Initialisation.......................................................................................................................161
Interaction Modes.............................................................................................................161
Traversal...........................................................................................................................161
Using CSS for Designing the CustomItem.......................................................................162
Registering Custom CSS Attributes...........................................................................................................163
Backgrounds and Borders................................................................................................164
Adding a Custom Background..............................................................................................164
Creating the Client-Side Background-Class.....................................................................164
Creating the Server-Side Background-Class...................................................................166
Integrating the Custom Background.................................................................................167
Adding a Custom Border.......................................................................................................168
Creating the Client-Side Border-Class.............................................................................168
Creating the Server-Side Border-Class............................................................................169
Integrating the Custom Border.........................................................................................170
Contributing Your Extensions.......................................................................................171
Standalone Tools............................................................................................................172
The Binary Data Editor.................................................................................................172
The Font Editor.............................................................................................................173
Non-MIDP Platforms.......................................................................................................175
Developing for BlackBerry Devices..............................................................................175
Preparations..........................................................................................................................175
Converting JARs into CODs..................................................................................................175
Signing COD Files.................................................................................................................175
Using the J2ME Polish GUI on BlackBerry Devices.............................................................176
Developing Native BlackBerry Applications..........................................................................176
Troubleshooting.....................................................................................................................176
Deactivate Obfuscation....................................................................................................176
Library...............................................................................................................................176
Developing for Palm Devices.......................................................................................177
7
Preparations..........................................................................................................................177
Converting JARs into PRCs..................................................................................................177
Starting the Palm Simulator..................................................................................................178
Developing DoJa Applications with J2ME Polish..........................................................178
Preparations..........................................................................................................................178
J2ME Polish Setup................................................................................................................178
Optional JAM Attributes.........................................................................................................179
Developing DoJa Applications under Linux and Mac OS X..................................................179
Developing for MIDP and DoJa at the Same Time...............................................................180
Cooking Tips and How-Tos............................................................................................181
Building How-Tos..........................................................................................................181
How to Use Several Source Folders.....................................................................................181
How to Integrate Third Party APIs........................................................................................181
How to Integrate a Source Code Third Party API ...........................................................181
How to Integrate a Binary Third Party API ......................................................................182
How to Integrate a Device API ........................................................................................182
How to Use Several Obfuscators Combined........................................................................183
How to Minimize the Memory Footprint................................................................................183
polish.skipArgumentCheck and polish.debugVerbose.....................................................183
Image Load Strategy........................................................................................................183
Optimizing the "polish.css" File........................................................................................183
Using Optimal Resources................................................................................................184
Use Preprocessing...........................................................................................................184
Remove Debug Code.......................................................................................................186
General Optimization Tips................................................................................................186
How to Sign MIDlets with J2ME Polish.................................................................................186
GUI How-Tos................................................................................................................187
How to Use Tables................................................................................................................187
How to Apply the J2ME Polish GUI for Existing Applications...............................................187
How to Apply Different Designs to One Application..............................................................188
How to Change the Labels of Standard-Commands and Menu-Labels...............................189
How to Enable or Disable the Usage of the GUI for a Specific Device.................................189
Trouble Shooting..........................................................................................................190
Using Subfolders for Resources...........................................................................................190
Compile Error........................................................................................................................190
Preverify Error.......................................................................................................................190
Appendix.........................................................................................................................191
Introduction to Ant........................................................................................................191
How to Use Quotation-Marks in Attributes............................................................................192
How to Specify Properties on the Command Line................................................................193
Licenses.......................................................................................................................194
GNU GPL..............................................................................................................................194
Commercial Licenses............................................................................................................194
Contact............................................................................................................................195
8
Preamble
Preamble
J2ME developers face a serious problem: either they use only the lowest-common-denominator of
J2ME devices – the MIDP/1.0 standard – or they choose to support only a few handsets, for which
they optimize their applications with a lot of energy. The open source tool J2ME Polish promises a
solution to this problem – and more.
J2ME Polish is actually a whole collection of different tools for wireless Java programmers. The
tools range from standard build tools for compiling, preverifying and packaging the applications to a
sophisticated optional GUI which can be designed with simple CSS text-files.
Following tools are included:
! Build-Tools / J2ME Polish Task: preprocessing, resource assembling, localization, compilation,
preverification, obfucation and packaging of J2ME applications. You can optimize your
application for multiple devices and languages/locales at the same time. J2ME Polish can also
invoke any emulators for you.
! Device Database: An XML-based device database provides a convenient and portable way for
adjusting your application to different devices. Together with the powerful preprocessing
capabilities you can use this database directly in your application.
! Logging Framework: The logging framework can be used to enable or disable logging levels for
classes or complete packages just by modifying some settings in the central build.xml. Messages
which are given out with System.out.println() can be shown on real devices as well! Of course
you can disable all logging completely, so that no traces are left in the application. This saves
runtime as well as memory.
! Automatic Resource Assembling: All resources like images and soundfiles are assembled
automatically for you. You can use specific resources for vendors like Nokia or for devices which
support a specific format easily. You can even include resources on conditions, so that MIDI-
soundfiles are only included when the target-device does not support MP3 but supports the MIDI
format, for example.
! Localization: It's easy to create localized applications – just provide the translations and – if you
like – other locale specific resources and J2ME Polish will embed them into the application. In
contrast to all other solutions, localized applications do not have an overhead compared with
non-localized applications, since the translations are actually integrated on the source-code level.
! GUI: The standard J2ME widgets cannot be designed at all. With J2ME Polish you can use the
standard MIDP/1.0 as well as MIDP/2.0 widgets in your program and design them with simple
CSS-directives like “!"#$%&'()*+,-"%./0(&120!%34)%056”. Web-designers can now design
the application independently of programmers and designs can be adjusted easily for different
handsets. You can even use MIDP/2.0 widgets like the 7(89'-:9.- on MIDP/1.0 phones!
! Utilities: Some often used components like the fast ;&&"<=,89 or the >.?9@9,1 for managing
font-based texts can be used for solving day-to-day problems.
! Game-Engine: With the highly-optimized game-engine you can use the MIDP/2.0 API for
MIDP/1.0 devices as well. J2ME Polish takes care for the porting! You can also adjust the API,
e.g. by specifying that a backbuffer-optimization should be used for >,1.*="<.& etc.
9
Preamble
! Stand-alone Tools: The binary data editor can be used for editing any structured binary data files
much more comfortable than a hex-editor. An often needed feature are level-data files, which are
easy to manage with the binary data editor. Another tool is the bitmap font editor, which can be
used for creating bitmap fonts out of any True Type fonts.
Obviously you can also extend and use the more advanced features of the J2ME Polish framework.
You can use your own widgets, add your own preprocessor, or integrate your own obfuscator with
ease.
Migrating to J2ME Polish is easy, since it is based on Ant. Ant is the standard for building Java
applications and is supported by all IDEs. You can invoke J2ME Polish either from within your IDE
of choice or from the command line.
I hope you find J2ME Polish useful and have fun with it!
10
Introduction to J2ME Polish
Installation !"#$%&'()*+,%-./0.)/1
Editions: GPL (for Open Source
J2ME Polish contains a graphical installer which can be products), Single License (199,-€ valid
started by double-clicking the downloaded jar-File or by for one J2ME application), Runtime
calling “java -jar j2mepolish-[VERSION].jar” from the License (199,-€ valid for an arbitrary
command line, e.g. “java -jar j2mepolish-1.1.jar”. number of applications which can only
be installed a 100 times), Enterprise
License (2990,-€ valid for any number
An Example Application
of applications). An additional
For this introduction we use a simple application as an “Developer Seat” license needs to be
example. The application just shows a simple menu which obtained for every developer (99,- € ).
is typical for many J2ME applications (listing 1). This is Operating Systems: Windows, Linux,
the sample application which is included into the Mac OS X
J2ME Polish distribution. Prerequisites: Java Wireless Toolkit,
Ant
2)*3)45%6,%#/47#)8(/39:;.; Build-Process: preprocessing, device-
!"#$%&0&$'((0A.)(A,*1.90)*+),-(0A:B1.90C optimization, resource assembling,
localization, device-database,
=,890-.)(D#&..)6
compiling, preverifying, obfuscating,
!"#$%&0A.)(A,*1.9250C signing of MIDlets, creation of jar and
.("!)/256 jad files
0D<89.-3'(934&,)91)2E89"&9,)%0A.)(A,*1.9E56
GUI: Design via CSS, 100% compatible
.+0%(3-.)(D#&..)0F0,)10=,892EGHAI0J'1,8KEL0
=,893:AJ=:7:>56 to the MIDP standard, optional.
.+0%(3-.)(D#&..)3"44.)*2ED9"&90%"-.EL0,"$$56 Game-Engine: MIDP/2.0 game-API for
.+0%(3-.)(D#&..)3"44.)*2E='"*0%"-.EL0,"$$56
MIDP/1.0 devices.
.+0%(3-.)(D#&..)3"44.)*2EM.14EL0,"$$56
.+0%(3-.)(D#&..)3"44.)*2EN(,9EL0,"$$56 www.j2mepolish.org
.+0%(3-.)(D#&..)38.97'--")*=,89.).&2+0%(56
0D<89.-3'(934&,)91)2E,)9,"1,8"9,')0*').3E56
O
11
Introduction to J2ME Polish
12
Introduction to J2ME Polish
13
Introduction to J2ME Polish
.+0%(3-.)(D#&..)3"44.)*2E='"*0%"-.EL0,"$$56
0669(+:$).;'%,=2;;',-
.+0%(3-.)(D#&..)3"44.)*2EM.14EL0,"$$56
0669(+:$).;'%,=2;;',-
.+0%(3-.)(D#&..)3"44.)*2EN(,9EL0,"$$56
0669(+:$).;'%,=2;;',-
.+0%(3-.)(D#&..)38.97'--")*=,89.).&2+0%(56
0D<89.-3'(934&,)91)2E,)9,"1,8"9,')0*').3E56
O
Instead of using the “list” and the “listitem”-styles in the polish.css, you now need to use the styles
“mainCommand” and “mainScreen”. Since these are static styles, they need to start with a dot in the
polish.css file:
3-",)D#&..)0C
04"**,)%/0h604"**,)%+1.R9/0Yh604"**,)%+
0P333Q
O
3-",)7'--")*0C
0-"&%,)/0H60!"##$%&'()*(+",-&./0%#'
(<===>
;
With using the #style-preprocessing directive the code still remains 100% compatible to the MIDP
standard, so one use the native/standard GUI for very old devices while using the J2ME Polish GUI
for modern devices at the same time.
You can specify in the build.xml file what “resources” folder should
be used. This mechanism can be used to create different designs of
one application. Figure 2 shows the sample application with a
different design. This design is also included in the J2ME Polish
distribution and can be used when the “resDir”-Attribute is set to
“resources2” in the build.xml.
14
Introduction to J2ME Polish
?#1+0&(1%"+51@A3.01A(7B/CD/&E%F../.@A3.01A(G1.+/71@A2"571A(51G15@A1../.AH
0000UR,19.&04"99.&)FE#'-3#'-4")<34"#$"%.3mE01.W.1FE,)R'E0ZT
0000UR,19.&04"99.&)FE#'-3#'-4")<34"#$"%.3A<71"88E01.W.1FE*.!(%E0ZT
?I#1+0&H
The “enable”-attribute defines whether logging should be activated at all. The
“showLogOnError”-attribute can be used for showing the log automatically, whenever an error has
been logged. This only works when the GUI of J2ME Polish is used, though. An error can be logged
just by appending the error object to a System.out.println()-call:
9&<0C
00#"117'-41.?A.9K'*256
00ZZn*.!(%0,)R'
00D<89.-3'(934&,)91)20E#'-41.?0-.9K'*08(##..*.*3E056
O0#"9#K02A<I?#.49,')0.50C
00ZZn*.!(%0.&&'&
00D<89.-3'(934&,)91)20E#'-41.?0-.9K'*0R",1.*E0o0.0560ZZ0VK.)08K'V='%p)I&&'&0,809&(.
O0000000000000000000000000000000000000000000000000000ZZ09K,80V,1109&,%%.&09K.01'%
When the “verbose”-attribute is true, after each logging message the current time and the source-
code file as well line of the message will be added. This eases the location of errors especially when
obfuscation is used. The J2ME APIs of J2ME Polish will also specify details of errors whenever
they throw an exception, when the “verbose”-attribute is true. The “level“-attribute controls the
general logging-level which is used when no specific level has been assigned for a class. The
logging-levels are hierarchically ordered:
debug < info < warn < error < fatal < user-definiert
When a class has the logging-level “info” assigned, messages with a level of “warn”, “error” and so
on will also be logged, but no “debug” messages.
In the source code logging messages will be introduced with the #debug-preprocessing-directive,
which can specify the logging-level, e.g. “//#debug info”. When no level is specified the “debug”
level is assumed.
15
Introduction to J2ME Polish
One can differentiate between MIDP-versions with the “polish.midp1” and the “polish.midp2”
symbol:
ZZn,R04'1,8K3-,*4H
000ZZ09K,80*.W,#.08(44'&980A:BJZH3[089")*"&*
000P333Q
ZZn.18.
000ZZ09K,808(44'&90*'.808(44'&909K.0A:BJZY3[089")*"&*
000P333Q
ZZn.)*,R
To distinguish between the CLDC/1.0 and the CLDC/1.1 standard, the “polish.cldc1.0” and
“polish.cldc1.1” symbols can be used:
ZZn,R04'1,8K3#1*#Y3Y
000R1'"90R0F0Y3HR6
000P333Q
ZZn.)*,R
Variables can be defined as well and be used within the source code. An URL could be defined in
the build.xml like this:
UW"&,"!1.8T
000UW"&,"!1.0)"-.FE(4*"9.+(&1E0W"1(.FEK994/ZZVVV3.)'(%K3*.Z(4*"9.E0ZT
UZW"&,"!1.8T
The defined variable can be used in the source code with the “#=”-directive:
ZZn,R*.R0(4*"9.+(&1/*.R,).*
000ZZnF04(!1,#089"9,#0R,)"10D9&,)%0@JB;>Ir@^=0F0E]C0(4*"9.+(&10OE6
ZZn.18.
000ZZ0)'0W"&,"!1.0*.R,),9,')0V"80R'()*L0(8.0"0*.R"(19+W"1(./
0004(!1,#089"9,#0R,)"10D9&,)%0@JB;>Ir@^=0F0EK994/ZZ*.R"(193#'-Z(4*"9.E6
ZZn.)*,R
16
Introduction to J2ME Polish
current limitations are that no pixel-level collision-detections and no sprite-transformations for non-
Nokia devices are supported (for Nokia devices sprite transformations are supported).
The game-engine can be optimized for several usage scenarios, you can specify that the backbuffer-
optimization should be used for the TiledLayer implementation, for example.
17
Installation
Installation
Requirements
To use J2ME Polish, following components need to be installed:
! Java 2 Standard Edition SDK 1.4 or higher, K994/ZZS"W"38()3#'-ZSH8.ZY3b3HZ,)*.?3S84
! Java Wireless Toolkit, K994/ZZS"W"38()3#'-Z4&'*(#98ZSH-.V9''1$,9Z,)*.?3K9-1L0
or0K994/ZZ-4'V.&83).9Z-,*4+'8?Z0for Mac OS X
! Favorite IDE, for example Eclipse 3.0, K994/ZZVVV3.#1,48.3'&%0
! Ant 1.5 or higher, if not already integrated in the IDE, K994/ZZ")93"4"#K.3'&%
18
Installation
libraries are needed for the sample application, but when the others are included, future
enhancements are easier to accomplish.
Optionally you can change the build-settings by modifying the file "build.xml" (which is located in
the root of the sample project). For example you can change the deviceRequirements if you want to.
The example is optimized to Nokia Series 60 devices.
You can now create the JAR and JAD files by right-clicking the “build.xml” file, selecting "Run
Ant" and running Ant in the next dialog. You will find the JAR and JAD files then in the "dist"
folder of the project. If you want to access them from within Eclipse, you might need to refresh your
project: Right-click the project and select "Refresh".
If the “Run Ant...” command is not shown, select the “build.xml” file, then open the Menu “Run”
and select “External Tools” -> “Run as” -> “Ant Build”.
After you have integrated the sample application into Eclipse, you will find following structure in
your project (assuming that your project is called “sample” and your workspace “workspace”):
19
Installation
for building the actual applications: Right-click the “build.xml” file, select “Properties...” and de-
select the “Use Borland Java compiler” check box.
You can now build the sample application by right-clicking the “build.xml” file and selecting
“Make”. You will find the created J2ME application files in the “dist” folder of your project, after
you have switched to the “File Browser” view.
NetBeans 3.6
For integrating J2ME Polish with NetBeans 3.6 mount the installation directory of your J2ME
Polish installation, right-click the "sample/build.xml" file and choose "Execute".
! Create a New Project: Go to "Project" -> "Project Manager" and select "New..." and call the new
project "j2mepolish".
! Mounting the Filesystem: Select "File" -> "Mount Filesystem..." -> "Local Directory" and select
the folder into which you have installed J2ME Polish.
Note: Don't navigate into the directory. Just select the J2ME Polish directory and click "Finish".
! Executing J2ME Polish: Open the mounted file-system (switch to the file-system-window by
pressing "Control-2"), locate the file "sample/build.xml", right-click it and select "Execute".
After the execution you will find the created applications in the "dist" folder.
! Mounting the Libraries: Open the mounted file-system, open the "import" directory and right-
click the "enough-j2mepolish-client" jar and select "Mount JAR". Do the same with the libraries
"midp2", "mmapi", "nokia-ui" and "wmapi".
! Open the Sample Application: You can now change the sample application, if you want to. You
can find it in the "sample/src" directory (in the package "de.enough.polish.example").
NetBeans 4.x
For integrating J2ME Polish with NetBeans 4.0 create a new project and copy the sample project
from ${polish.home}/sample into your new project with a file-manager. Right-click the build.xml
and choose "Run Target" > "j2mepolish" for running the example.
! Create a new project: Go to "File" -> "New Project" and select "Mobile" -> "Mobile
Application" as your project type. Give the project any name and choose any folder as the
project's home. De-select the "Create Hello MIDlet"-option and select "Finish" to create the
project.
! Copy the sample project: Navigate to the "${polish.home}/sample" directory with your file-
manager (e.g. Windows Explorer on Windows or Finder on Mac OS X). Select the "resources",
"resources2" and "src" folders as well as the "build.xml" file and copy all into the folder of your
NetBeans project. Overwrite any existing files.
! Return to NetBeans, right-click your new project in the "Projects" view and select "Refresh
Folders". You can now view the sample application in the "de.enough.polish.example" package.
! Right-click your project again and select "Properties". Go to "Build" and select "Libraries and
Resources". Select "Add Jar/Zip" and add the "${polish.home}/import/enough-j2mepolish-
20
Installation
NetBeans 5.x
J2ME Polish provides NetBeans specific build scripts from J2ME Polish 1.3 Beta 3 onwards. You
can now just open any of the provided sample applications, delete the default build.xml script and
rename the build-netbeans.xml script to build.xml. You can from then on use the normal debugging,
build and compile facilities of NetBeans.
Integrating a sample application in NetBeans:
! Select File > Open Project... and select any sample application in ${polish.home}/samples. Just
select a folder like the menu folder and select Open.
! Now switch to the Files window by selecting Window > Files.
! In this window delete or rename the build.xml script which is in the base folder of the project.
! Now right-click the build-netbeans.xml script and rename it to build.xml. When the renaming
does not work, do it directly from the file system (e.g. Windows Explorer).
! From now on you can build, run, debug and compile with the normal NetBeans commands (e.g.
F5 for debugging). J2ME Polish is then used for building etc.
When you start a new project in NetBeans, just copy one of the sample build.xml scripts to your
project's folder. Then adjust the settings according to your needs.
You can change the PATH variable permanently in the System-Settings of Windows (Control Center
-> System -> Advanced -> Environment variables).
Now you need set the JAVA_HOME variable as well, e.g.:
DI>0G;q;rMpAIF7/XSH8*$Y3b3H
Under Unix/Linux/Mac OS X please use the “export” command instead of the “SET” command.
Now you should be able to issue following calls from the command-line (make sure that you are in
21
Installation
22
The Device Database
vendors.xml
The vendors of J2ME devices are defined in vendors.xml. An example definition is:
?G1%#/.7H
?G1%#/.H
?%":1HJ/-$"?I%":1H
?21"30.17H?I21"30.17H
?,"!"+$5$38(%":1@A,/5/.7=2/,07A(G"501@AKL))))MMA(IH
?IG1%#/.H
?G1%#/.H
?%":1HN$1:1%7?I%":1H
?IG1%#/.H
?IG1%#/.7H
In this code 2 vendors are defined – Nokia and Siemens. Vendors can possess features and
capabilities, which are inherited by all devices of that vendor. These abilities can be used during the
preprocessing (compare chapter “The world of preprocessing”, page 78). Features are just a comma
separated list, whereas capabilities always have a name and a value.
You can define your own vendors in the custom-vendors.xml file. This allows you to use your own
vendors without needing to merge the vendors.xml file with each update of J2ME Polish. The
custom-vendors.xml file is loaded from the current project folder and – if that file doesn't exist –
from the J2ME Polish installation folder.
groups.xml
The device groups are defined in the file groups.xml. A device can be a member in any number of
groups.
?&./0!7H
?&./0!H
?%":1HJ/-$"4OP?I%":1H
?21"30.17H?I21"30.17H
?,"!"+$5$38(%":1@A,5"7717=20557,.11%A(
G"501@A,/:=%/-$"=:$#=0$=Q0556"%G"7A(IH
?,"!"+$5$38(%":1@AR"G"S",-"&1A(G"501@A%/-$"40$A(IH
?I&./0!H
?&./0!H
?%":1HN1.$17TK?I%":1H
?!".1%3HJ/-$"4OP?I!".1%3H
?,"!"+$5$38(%":1@AR"G"S5"32/.:A(
G"501@AUPMSIV=KA(IH
?I&./0!H
?I&./0!7H
23
The Device Database
The group “Nokia-UI” is used for devices which support the UI API of Nokia. The group
“Series60” extends this group. Any capabilities or features defined in the groups can be overridden
or completed by the device definitions.
You can define your own groups in the custom-groups.xml file. This allows you to use your own
groups without needing to merge the groups.xml file with each update of J2ME Polish. The
custom-groups.xml file is loaded from the current project folder and – if that file doesn't exist –
from the J2ME Polish installation folder.
devices.xml
In devices.xml all J2ME devices are defined.
?#1G$,17H
?#1G$,1H
?$#1%3$2$1.HU/3/./5"I$WXK?I$#1%3$2$1.H
?071.4"&1%3HUEY$WXK?I071.4"&1%3H
?,"!"+$5$38(%":1@AN/23C".1S5"32/.:=R"G"S5"32/.:A
G"501@AUPMSIZ=KA(IH
?,"!"+$5$38(%":1@A[".#C".1S5"32/.:=N,.11%N$91A
G"501@AVXKLVXKA(IH
?,"!"+$5$38(%":1@A[".#C".1S5"32/.:=\$37S1.S$L15A
G"501@AVTA(IH
?,"!"+$5$38(%":1@A[".#C".1S5"32/.:=6":1."]17/503$/%A
G"501@AXKKLZKKA(IH
?,"!"+$5$38(%":1@AN/23C".1S5"32/.:=R"G"S./3/,/5A
G"501@AOMS^(Y6S^(NND^([YYS^([YYSN^(N1.$"5A(IH
?,"!"+$5$38(%":1@AN/23C".1S5"32/.:=R"G"S",-"&1A
G"501@AC:"!$^(::"!$^(:/3/./5"45C3^(5/,"3$/%4"!$A(IH
?,"!"+$5$38(%":1@AN/23C".1S5"32/.:=[1"!N$91A
G"501@AV=V)(U\A(IH
?,"!"+$5$38(%":1@AN/23C".1S5"32/.:=U"LR".N$91A
G"501@A)KK(-+A(IH
?I#1G$,1H
?#1G$,1H
?$#1%3$2$1.HJ/-$"ITTKK?I$#1%3$2$1.H
?071.4"&1%3HJ/-$"TTKK?I071.4"&1%3H
?&./0!7HN1.$17TK?I&./0!7H
?21"30.17HB"76":1."?I21"30.17H
?,"!"+$5$38(%":1@AN,.11%N$91A(G"501@AVWTLZK_AIH
?,"!"+$5$38(%":1@A\$37S1.S$L15A(G"501@AVTAIH
?,"!"+$5$38(%":1@AR"G"S",-"&1A(G"501@A::"!$^(+3"!$^(C:"!$A(IH
?,"!"+$5$38(%":1@AR"G"S5"32/.:A(G"501@AUPMSIZ=KA(IH
?I#1G$,1H
?I#1G$,17H
In the example the Motorola Ident 730 and the Nokia 6600 are defined. Capabilities can be grouped
into hardware- and software-capabilities. This grouping is optional and will not be distinguished in
the preprocessing step, thus one cannot use the same name for a SoftwarePlatform and a
HardwarePlatform capability.
The identifier consists of the vendor and device-name. The structure is “[vendor]/[device-name]”.
The <features>-element defines preprocessing symbols. These can be checked in the source code for
example with “//#ifdef [symbol-name]“. Several features need to be separated by comma:
?21"30.17HB"7S/$%31.FG1%37^(B"7S/$%31.FG1%37?I21"30.17H
Groups can be defined explicitly with the <groups>-element. All group-names to which the device
24
The Device Database
apis.xml
The file apis.xml defines some common libraries. You do not need to add every API you or your
device supports, but if a API is known under several names, it is advised to add that API to
apis.xml.
?"!$7H
?"!$H
?%":1HJ/-$"(O71.(P%31.2",1(aSP?I%":1H
?#17,.$!3$/%HYB1(J/-$"(O71.(P%31.2",1(aSP(!./G$#17
7/:1("#G"%,1#(#."C$%&(20%,3$/%"5$3$17=
?I#17,.$!3$/%H
?%":17H%/-$"40$^%/-$"0$^(%/-$"0$"!$?I%":17H
?2$517H%/-$"40$=b".^(%/-$"0$=9$!?I2$517H
?!"3BH$:!/.3I%/-$"40$=b".?I!"3BH
?I"!$H
?"!$H
?%":1H\5013//3B(aSP?I%":1(H
?#17,.$!3$/%HYB1(\5013//3B(aSP(!./G$#17
20%,3$/%"5$3$17(2/.(#"3"(1L,B"%&1(C$3B(/3B1.(+5013//3B(
#1G$,17=
?I#17,.$!3$/%H
?%":17H+3"!$^+34"!$^(+5013//3B^(+5013//3B4"!$?I%":17H
?2$517HbZ:14+3"!$=b".^(+5013//3B=9$!?I2$517H
?!"3BH$:!/.3IbZ:14+3"!$=b".?I!"3BH
?I"!$H
?I"!$7H
In the above example two libraries are defined. The <name> element describes the default name of a
library, whereas the <names> element defines other possible names of the library. The <files>
element defines the names of the library on the filesystem. The <path> element just defines the
default path. When that path is not found, J2ME Polish tries to find the API with the help of the
file-names defined in the <files> element.
You can define your own libraries in the custom-apis.xml file. This allows you to use your own
libraries without needing to merge the apis.xml file with each update of J2ME Polish. The custom-
apis.xml file is loaded from the current project folder and – if that file doesn't exist – from the J2ME
Polish installation folder.
25
The Device Database
Device Capabilities
The device database of J2ME Polish supports a number of capabilities, which are useful for
preprocessing and the assembling of resources.
You can use capabilities with any name, but following categories are predefined:
26
The Device Database
27
The Build Process
}
accomplished:
" Selection of the supported devices
" Assembling of the resources
" Preprocessing of the source code, optimizing for the device
" Compilation of the application for each selected
" Obfuscation and shrinking of the compiled code device
" Preverification
" Creation of the JAR and JAD files
Now you can use the 2ME Polish-Task under the name “j2mepolish”.
You need also define where to find the Wireless Toolkit by defining the Ant-property “wtk.home”:
?!./!1.38(%":1@AC3-=B/:1A(G"501@A6'cdYeZ=VA(IH
On a system without the Wireless Toolkit (like Mac OS X) you can still use J2ME Polish by
defining the preverify-attribute of the <build>-element instead of using the “wkt.home”-property.
Example
The following example shows a complete build.xml file:
?f44(YB$7(2$51(,/%3./57(3B1(+0$5#(!./,177=((((((((((((((((((((44H
?f44(YB1(:/73($:!/.3"%3(3".&13($7(3B1(bZ:1!/5$7B43".&13^((((((44H
?f44(CB$,B(,/%3./57(2/.(CB"3(#1G$,17(3B1("!!5$,"3$/%(7B/05#(((44H
?f44(+1(,.1"31#("%#(7/(/%=((((((((((((((((((((((((((((((((((((44H
?f44((((((((((((((((((((((((((((((((((((((((((((((((((((((((((44H
?f44(P:!/.3"%3'(CB1%(8/0(B"G1(%/(d$.15177(Y//5-$3($%73"551#(((44H
?f44(8/0(%11#(3/(#12$%1(3B1(A!.1G1.$28A4"33.$+031(((((((((((((44H
?f44(/2(3B1(?+0$5#H4151:1%3(/2(3B1(RZUF(S/5$7B(3"7-=((((((((((44H
?f44((((((((((((((((((((((((((((((((((((((((((((((((((((((((((44H
?f44(dB1%(8/0(,"55(a%3(2./:(3B1(,/::"%#45$%1^(8/0(,"%(((((((((44H
?f44(,"55(A"%3(3173(bZ:1!/5$7BA(3/(7-$!(3B1(/+207,"3$/%(((((((44H
28
The Build Process
?f44("%#(3/(+0$5#(3B1(1L":!51(2/.(21C1.(B"%#7137=(((((((((((((44H
?f44(YB1(#12"053(3".&13(+0$5#7("%#(/+207,"317(3B1(1L":!51=((((44H
?f44((((((((((((((((((((((((((((((((((((((((((((((((((((((((((44H
?f44(YB1(2055(#/,0:1%3"3$/%(,"%(+1(2/0%#("3(((((((((((((((((((44H
?f44(B33!'IICCC=bZ:1!/5$7B=/.&((((((((((((((((((((((((((((((((44H
?f44((((((((((((((((((((((((((((((((((((((((((((((((((((((((((44H
?f44(["G1(20%f((((((((((((((((((((((((((((((((((((((((((((((((44H
?!./b1,3(
%":1@A1%/0&B4bZ:1!/5$7B41L":!51A(
#12"053@AbZ:1!/5$7BAH
?f44(YB1(C3-=B/:1(!./!1.38(7B/05#(!/$%3(3/(3B1(#$.1,3/.8((((((44H
?f44(,/%3"$%$%&(3B1(d$.15177(Y//5-$3=(((((((((((((((((((((((((44H
?!./!1.38(%":1@AC3-=B/:1A(G"501@A6'cdYeZ=VA(IH
?f44(M12$%$3$/%(/2(3B1(RZUF(S/5$7B(3"7-'((((((((((((((((((((((44H
?3"7-#12(%":1@AbZ:1!/5$7BA(,5"77%":1@A#1=1%/0&B=!/5$7B="%3=S/5$7BY"7-A(
,5"77!"3B@A$:!/.3I1%/0&B4bZ:1!/5$7B4
+0$5#=b".'$:!/.3Ib#/:=b".'$:!/.3I!./&0".#=b".'$:!/.3I.13./&0".#=b".AIH
?f44(+0$5#(3".&137^(1",B(3".&13(,"%(+1(,"551#(G$"(A"%3(<%":1>A^(
(((((1=&=(A"%3(,51"%A^(A"%3(%/3173(bZ:1!/5$7BA(/.(b073(A"%3A(2/.(
(((((,"55$%&(3B1(#12"05343".&13(44H
?3".&13(%":1@A3173A(H
?!./!1.38(%":1@A3173A(G"501@A3.01A(IH
?I3".&13H
?3".&13(%":1@A$%$3AH
(( ?!./!1.38(%":1@A3173A(G"501@A2"571A(IH
?I3".&13H
(
?f44(P%(3B$7(3".&13(3B1(RZUF(S/5$7B(3"7-($7(071#=(((((((((((((44H
?f44(P3(B"7(X(71,3$/%7'(((((((((((((((((((((((((((((((((((((((44H
?f44((((V=(YB1($%2/471,3$/%(#12$%17(7/:1(&1%1."5($%2/.:"3$/%((44H
?f44((((Z=(YB1(#1G$,1]1g0$.1:1%37471,3$/%(,B//717(3B1(#1G$,17(44H
?f44(((((((2/.(CB$,B(3B1("!!5$,"3$/%($7(/!3$:$91#=((((((((((((44H
?f44((((X=(YB1(+0$5#471,3$/%(,/%3./57(3B1(",30"5(+0$5#((((((((44H
?f44(((((((!./,177=(((((((((((((((((((((((((((((((((((((((((((44H
?3".&13(%":1@AbZ:1!/5$7BA(
#1!1%#7@A$%$3A
#17,.$!3$/%@AYB$7($7(3B1(,/%3./551.(2/.(3B1(RZUF(+0$5#(!./,177=A(
H
?bZ:1!/5$7BH
((((?f44(&1%1."5(7133$%&7(44H
?$%2/
(5$,1%71@A`SDA
(%":1@ARZUF(S/5$7BA
(G1.7$/%@AV=X=hA
(#17,.$!3$/%@Aa(7":!51(!./b1,3A
(G1%#/.J":1@AF%/0&B(N/23C".1A
($%2/O.5@AB33!'IICCC=bZ:1!/5$7B=/.&A
($,/%@A$,/%=!%&A
(b".J":1@Aij!/5$7B=G1%#/.;4ij!/5$7B=%":1;41L":!51=b".A(
(b".O.5@Aij!/5$7B=b".J":1;A
(,/!8.$&B3@A6/!8.$&B3(ZKKh(F%/0&B(N/23C".1=(a55(.$&B37(.171.G1#=A
(#151316/%2$.:@AM/(8/0(.1"558(C"%3(3/(-$55(:1kA(
IH
?f44(7151,3$/%(/2(70!!/.31#(#1G$,17(44H
29
The Build Process
?f44(P%(3B1(3173(:/#1(3B1("!!5$,"3$/%($7(+0$5#(/%58(2/.(3B1((44H
?f44(J/-$"IXT)K("%#(3B1(TTKK(!B/%17^(/3B1.C$71((44H
?f44(3B1(71,/%#(#1G$,1]1g0$.1:1%37(C$55(+1(071#($%731"#=(44H
?#1G$,1]1g0$.1:1%37($2@A3173AH
?.1g0$.1:1%3(%":1@AP#1%3$2$1.A(G"501@AJ/-$"IXT)K^(J/-$"ITTKKA(
IH
?I#1G$,1]1g0$.1:1%37H
?#1G$,1]1g0$.1:1%37(0%5177@A3173AH
?.1g0$.1:1%3(%":1@AP#1%3$2$1.A(G"501@AJ/-$"IN1.$17TK^(
J/-$"IN1.$17TKU$#!Z^(`1%1.$,I:$#!Z^(`1%1.$,I:$#!VA(IH
?f44(/%(,/05#(071(/3B1.(#1G$,17(2/.(.1"5(+0$5#7^(1=&=('
?/.H
?"%#H
?.1g0$.1:1%3(%":1@AR"G"S",-"&1A(G"501@A%/-$"40$A(
IH
?.1g0$.1:1%3(%":1@A\$37S1.S$L15A(G"501@AVTlA(IH
?I"%#H
?I/.H
(44H
?I#1G$,1]1g0$.1:1%37H
((((?f44(+0$5#(7133$%&7(44H
?+0$5#
(78:+/57@AFL":!51N8:+/5^(a%/3B1.FL":!51A
($:"&1D/"#N3."31&8@A2/.1&./0%#A
(20557,.11%@A:1%0A
(071S/5$7B`0$@A3.01A
(.17M$.@A.17/0.,17A
(H
((?f44(:$#5137(#12$%$3$/%(44H
((?:$#513(,5"77@A#1=1%/0&B=!/5$7B=1L":!51=U1%0U$#513A(%":1@AFL":!51A(
IH
((?f44(!./b1,34C$#1(G".$"+517(4(071#(2/.(!.1!./,177$%&((44H
((?G".$"+517H
( ?G".$"+51(%":1@A0!#"3140.5A(
G"501@AB33!'IICCC=1%/0&B=#1I0!#"31A(IH
?G".$"+51(%":1@A3$351A(G"501@ARZUF(S/5$7BA(IH
((?IG".$"+517H
((?f44(/+207,"3/.'(#/%m3(/+207,"31(CB1%(3B1(31734!./!1.38($7(3.01(44
H
( ((?/+207,"3/.(0%5177@A3173A(%":1@AS./`0".#A(IH
((?f44(#1+0&(7133$%&7'(/%58($%,50#1(#1+0&(7133$%&(CB1%(3B1(31734
(!./!1.38($7(3.01(44H
((?#1+0&($2@A3173A(7B/CD/&E%F../.@A3.01A(G1.+/71@A3.01A(
51G15@A1../.AH
?2$531.(!"331.%@A#1=1%/0&B=!/5$7B=1L":!51=nA(51G15@A#1+0&A(IH
?2$531.(!"331.%@A#1=1%/0&B=!/5$7B=0$=nA(51G15@AC".%A(IH
((?I#1+0&H
((?f44(071.(#12$%1#(RaM("33.$+0317(,"%("57/(+1(071#'(44H
((?b"#H
?"33.$+031(%":1@AJ/-$"4UPM51346"31&/.8A(G"501@A`":1A(
$2@A!/5$7B=&./0!=N1.$17hKA(IH
((?Ib"#H
?I+0$5#H
?IbZ:1!/5$7BH
?I3".&13H
?3".&13(%":1@A,51"%A(
(( ((#17,.$!3$/%@A"55/C7("(,51"%(+0$5#=(o/0(7B/05#(,"55(<"%3(,51"%>(CB1%1G1.(
30
The Build Process
8/0(:"#1(,B"%&17(3/(#1G$,17=L:5^(G1%#/.7=L:5(/.(&./0!7=L:5AH
?#15131(#$.@A+0$5#A(IH
?#15131(#$.@A#$73A(IH
?I3".&13H
?I!./b1,3H
In the first section the J2ME Polish-task and the location of the wireless-toolkit are defined,
followed by the build-targets “test”, “init”, “j2mepolish” and “clean”. The targets “test” and “init”
are responsible for entering the test mode.
If you call Ant without any arguments, the Ant-property “test” will be set to false in the “init”
target. If you call Ant with the arguments “test j2mepolish”, the test-property will be set to true.
This allows controlling the build-script without changing it. In the example the obfuscation step is
skipped when the test-property is true. Also the debug messages are only included when test is true.
You can force a complete rebuild by calling “ant clean”. This can be necessary after you made
changes in the device database or in rare cases when there is a compile error in the J2ME Polish
packages.
The <info>-Section
In the <info>-section general information about the project is defined.
?$%2/
((((5$,1%71@A`SDA
((((%":1@AN$:!51U1%0A
((((G1.7$/%@AV=X=hA
((((#17,.$!3$/%@Aa(3173(!./b1,3A
((((G1%#/.J":1@AF%/0&B(N/23C".1A
(((($%2/O.5@AB33!'IICCC=1%/0&B=#1I#$,3$/%".8A
(((($,/%@A$,/%=!%&A
((((b".J":1@Aij!/5$7B=G1%#/.;4ij!/5$7B=%":1;4ij!/5$7B=5/,"51;41L":!51=b".A(
((((b".O.5@Aij!/5$7B=b".J":1;A
((((,/!8.$&B3@A6/!8.$&B3(ZKKh(F%/0&B(N/23C".1=(a55(.$&B37(.171.G1#=A
((((#151316/%2$.:@AM/(8/0(.1"558(C"%3(3/(-$55(:1kA(
((((IH
The information giving here is used for setting the JAD- and MANIFEST-attributes. If you need to
set attribute which are not supported by the <info>-section, you can always use the <jad>-element,
which is a subelement of the <build>-section. The <info> element supports following attributes:
31
The Build Process
Example: S"&\"-.Ft`"-.+]C4'1,8K3W.)*'&O+]C4'1,8K3)"-.O+
]C4'1,8K31'#"1.O3S"&t results into “Game-Nokia-6600-en.jar” for an
application which has been optimized for the Nokia/6600 and uses the
English locale.
jarUrl No The URL from which the jar file can be downloaded. This is either the
HTTP address, or just the name of the jar-file, when it is loaded locally.
When no jarUrl is defined, the jarName defined above is used. Apart
from the variables available for the jarName-attribute, you can use the
name of the jar-file as defined above:
S"&@&1FtK994/ZZVVV3.)'(%K3*.Z-,*1.98Z`"-.Z]C4'1,8K3W.)*'&
OZ]C4'1,8K3)"-.OZ]C4'1,8K3S"&\"-.Ot0
infoUrl No The URL containing more information about the application. The
variable “MIDlet-Info-URL” overrides this setting, this van be used to
localize the application.
copyright No Copyright notice.
deleteConfirm No The text which is presented to the user when he tries to delete the
application. The variable “MIDlet-Delete-Confirm” overrides this
setting, this van be used to localize the application.
installNotify No A HTTP-URL, which should be called after the successful installation
of the application.. This can be useful for tracking how many
32
The Build Process
The <deviceRequirements>-Section
The optional <deviceRequirements>-section is responsible for selecting the devices which are
supported by the application. When this section is omitted, the application will be optimized for all
known devices. Any device capabilities or features can be used for the device selection:
?#1G$,1]1g0$.1:1%37($2@A3173AH
?.1g0$.1:1%3(%":1@AP#1%3$2$1.A(G"501@AJ/-$"ITTKKA(IH
?I#1G$,1]1g0$.1:1%37H
?#1G$,1]1g0$.1:1%37(0%5177@A3173AH
?.1g0$.1:1%3(%":1@AR"G"S",-"&1A(G"501@A%/-$"40$A(IH
?.1g0$.1:1%3(%":1@A\$37S1.S$L15A(G"501@AhlA(IH
?I#1G$,1]1g0$.1:1%37H
In this example two alternative device-selections are defined – when the test-property is set to true
33
The Build Process
The <or>, <and>, <not> and <xor> elements can be nested in any manner:
?#1G$,1]1g0$.1:1%37H
?.1g0$.1:1%3(%":1@A\$37S1.S$L15A(G"501@AhlA(IH
?/.H
?.1g0$.1:1%3(%":1@AR"G"S",-"&1A(G"501@A%/-$"40$^(::"!$A(IH
34
The Build Process
?"%#H
?.1g0$.1:1%3(%":1@AR"G"S",-"&1A(G"501@A::"!$A(IH
?.1g0$.1:1%3(%":1@AR"G"S5"32/.:A(G"501@AUPMSIZ=KlA(IH
?I"%#H
?I/.H
?I#1G$,1]1g0$.1:1%37H
In this example each supported device must have a color depth of at least 4 bits per pixel.
Additionally the device needs to support either the Nokia-UI-API and the Mobile Media-API
(mmapi), or the Mobile Media-API and the MIDP/2.0 platform.
Instead of using such nested requirements, you can also use the "Term" requirement that allows you
to select devices with the same power like the #if preprocessing directive. The following example
includes the very same requirements like the above one – but only one "Term" requirement is used:
?#1G$,1]1g0$.1:1%37H
?.1g0$.1:1%3(%":1@AY1.:A(
G"501@Aq!/5$7B=\$37S1.S$L15(H@(hr("%#(qq!/5$7B="!$=%/-$"40$("%#(
!/5$7B="!$=::"!$r(/.(q!/5$7B="!$=::"!$("%#(!/5$7B=:$#!ZrrA(IH
?I#1G$,1]1g0$.1:1%37H
J2ME Polish provides several requirements that can be used "out of the box":
requirement-name Explanation
BitsPerPixel Needed color depth of the device: 1 is monochrome,
4 are 16 colors,
8 = 256 colors,
16 = 65.536 colors,
24 = 16.777.216 colors. Example:
“4+” for at least 4 bits per pixel or “16” for precisely 16 bits per pixel.
?.1g0$.1:1%3(%":1@A\$37S1.S$L15A(G"501@AhlA(IH
ScreenSize Required width and height of the display, e.g. “120+ x 100+” for a
resolution of at least 120 pixels horizontally and 100 pixels vertically.
?.1g0$.1:1%3(%":1@AN,.11%N$91A(G"501@AVZKl(L(VKKlA(IH
ScreenWidth The needed horizontal resolution of the display , e.g. “120+” for at least 120
pixels.
?.1g0$.1:1%3(%":1@AN,.11%d$#3BA(G"501@AVZKlA(IH
ScreenHeight The needed vertical resolution of the display, e.g. “100+” for at least 100
pixels.
?.1g0$.1:1%3(%":1@AN,.11%[1$&B3A(G"501@AVKKlA(IH
CanvasSize Required width and height of the MIDP-Canvas. Some devices do not allow
the usage of the complete screen.
?.1g0$.1:1%3(%":1@A6"%G"7N$91A(G"501@AVZKl(L(VKKlA(IH
JavaPlatform The needed platform, e.g. “MIDP/1.0” or “MIDP/2.0+”.
?.1g0$.1:1%3(%":1@AR"G"S5"32/.:A(G"501@AUPMSIZ=KlA(IH
JavaConfiguration The needed configuration, e.g. “CLDC/1.1+”.
?.1g0$.1:1%3(%":1@AR"G"6/%2$&0."3$/%@A(G"501@A6DM6IV=VlA(IH
JavaPackage Needed APIs, e.g. “nokia-ui, mmapi”:
?.1g0$.1:1%3(%":1@AR"G"S",-"&1A(G"501@A%/-$"40$^(::"!$A(IH
35
The Build Process
requirement-name Explanation
JavaProtocol Needed data exchange protocols, e.g. “serial, socket”:
?.1g0$.1:1%3(%":1@AR"G"S./3/,/5A(G"501@A71.$"5^7/,-13A(IH
HeapSize The needed heap size of the device, e.g. “200+ kb” or “1.1+ MB”
?.1g0$.1:1%3(%":1@A[1"!N$91A(G"501@AZKKl-+A(IH
Vendor The vendor of the device, e.g. “Nokia” or “Siemens”.
?.1g0$.1:1%3(%":1@As1%#/.A(G"501@AJ/-$"^(N/%8F.$,77/%A(IH
Identifier The identifier of the device, e.g. “Nokia/6600”.
?.1g0$.1:1%3(%":1@AP#1%3$2$1.A(G"501@AJ/-$"ITTKK^(
N/%8F.$,77/%IStKKA(IH
Feature A feature which needs to be supported by the device.
?.1g0$.1:1%3(%":1@AQ1"30.1A(G"501@AB"7S/$%31.FG1%37A(IH
Term A preprocessing term that needs to be fulfilled by the device. You can use
this flexible requirement just like the //#if-preprocessing directive in your
source code.
?.1g0$.1:1%3(%":1@AY1.:A(
G"501@A!/5$7B=::"!$(uu(f!/5$7B=$7s$.30"5(uu(q!/5$7B=s1%#/.(f@(
J/-$"rA(IH
The <build>-Section
With the <build>-section the actual build process is controlled:
?+0$5#
78:+/57@A7B/CN!5"7B^(a%/3B1.FL":!51N8:+/5A
20557,.11%@A:1%0A
071S/5$7B`0$@A3.01A
H
?f44(:$#5137(#12$%$3$/%(44H
?:$#513(,5"77@AU1%0U$#513A(%":1@AFL":!51A(IH
?f44(!./b1,34C$#1(G".$"+517(4(071#(2/.(!.1!./,177$%&((44H
?G".$"+517H
?G".$"+51(%":1@A0!#"3140.5A(
((((G"501@AB33!'IICCC=1%/0&B=#1I0!#"31A(IH
?IG".$"+517H
?f44(/+207,"3/.(7133$%&7'(#/(%/3(/+207,"31(CB1%(3173($7(3.01(44H
?/+207,"3/.(%":1@AS./`0".#A(071M12"053S",-"&1@A3.01A(0%5177@A3173A(IH
?f44(#1+0&(7133$%&7'(/%58(#1+0&(CB1%(3173($7(3.01(44H
?#1+0&($2@A3173A(
(G$70"5@A2"571A(G1.+/71@A3.01A(51G15@A1../.AH
?2$531.(!"331.%@A#1=1%/0&B=!/5$7B=#$,3=nA(51G15@A#1+0&A(IH
?2$531.(!"331.%@A#1=1%/0&B=!/5$7B=0$=nA(51G15@AC".%A(IH
?I#1+0&H
?I+0$5#H
36
The Build Process
37
The Build Process
38
The Build Process
<sources>
The <sources>-element can be used for a finer grained control of the source-directories. This can be
useful to include test classes, for example:
?7/0.,17H
?7/0.,1(#$.@A7/0.,1I7.,A(IH
?7/0.,1(#$.@A7/0.,1I3173A($2@A3173A(IH
?I7/0.,17H
39
The Build Process
<iappli>
The <iappli> or <doja> element defines the IApplication class of your DoJa release. This is only
applicable when you are targeting this platform (see page 178).
iappli- Require
Explanation
Attribute d
40
The Build Process
class Yes The complete package and class-name of the main IApplication.
The Ant-property or preprocessing directive that needs to be/result "true"
if No
for this iappli to be used.
The Ant-property or preprocessing directive that needs to be/result
unless No
"false" for this iappli to be used.
<resources>
?.17/0.,17
#$.@A.17/0.,17A
1L,50#17@An=3L3A
H
?2$51713(
#$.@A.17/0.,17I:053$:1#$"A(
$%,50#17@An=:!XA(
$2@A!/5$7B="0#$/=:!XA(
IH
?2$51713(
#$.@A.17/0.,17I:053$:1#$"A(
$%,50#17@An=:$#A(
$2@A!/5$7B="0#$/=:$#$("%#(%/3(!/5$7B="0#$/=:!XA(
IH
?2$51713(
#$.@A.17/0.,17I:053$:1#$"I$:"&17Iij!/5$7B=5"%&0"&1;A(
$%,50#17@An=!%&A(
IH
?5/,"5$9"3$/%(5/,"517@A#1^(1%A(0%5177@A3173A(IH
?5/,"5$9"3$/%(5/,"517@A1%A($2@A3173A(IH
?I.17/0.,17H
The <resources>-element can be used to fine tune the resources assembling as well as the
localization of the application. When it is used, the “resDir”-attribute of the <build>-section should
not be used. The <resources>-element supports following attributes:
41
The Build Process
The <resources> elements accepts the nested elements <filter>, <fileset>, <localization> and
<copier>:
Sometimes it is easier to exclude resources for specific devices rather than to include it for the other
devices. You can use any number of <filter> elements for this purpose. The following element
removes all *.mid files when the target device supports both MIDI as well as AMR files:
<filter excludes="*.mid" if="polish.audio.midi and polish.audio.amr" />
The <fileset> behaves like any Ant fileset, but it offers the additional “if” and “unless”-attributes for
allowing a fine grained control. The most important attributes are:
fileset-Attribute Required Explanation
dir Yes The base directory of this fileset. This directory needs to exist
unless you use variables in it like ]C4'1,8K3W.)*'&O,
]C4'1,8K3)"-.O, ]C4'1,8K31")%("%.O, ]C4'1,8K3#'()9&<O0
42
The Build Process
More information about localization can be found in the localization chapter on page 70.
Use the <copier>-element to transform the resources before they are packaged in the final JAR file.
You can chain several copiers together just by defining several <copier> elements.
copier-Attribute Required Explanation
name Yes, The name of the resource copier, e.g. “antcall”, “renamer” or
unless “svgconverter”. You can register your own resource copier in
43
The Build Process
?0).',+&'$$.@)(2"/&).=2!%)/
The “antcall” resource copier executes another target in your build.xml script for copying the
resources. You can use all (lowercase) J2ME Polish variables and properties of the current target
device as well as following specific properties:
! ${polish.resources.target}: contains the target directory, to which the resources need to be
copied
! ${polish.resources.files}: includes a comma separated list of the files that should be copied
! ${polish.resources.filePaths}: includes a semicolon (Windows) or colon (Unix) separated list of
the files that should be copied.
You can also specify your own properties by using nested <parameter> elements.
U#'4,.&0)"-.FE")9#"11E09"&%.9FE#'4<&.8'(&#.8ET
U4"&"-.9.&0)"-.FEA<D.99,)%8E0W"1(.FE]C4'1,8K3)"-.O38.99,)%8E0ZT
UZ#'4,.&T
?0)./),';)/.@)(2"/&).=2!%)/
Use the “renamer” resource copier for modifying the file-names of the resources before they are
packaged in the final JAR. The following renamer removes all characters that are surrounded by
curly braces. You can use this for giving your resources meaningful names while using short names
in the JAR file. The file i0{ start game icon }.png will be renamed to i0.png, for example. This saves
some precious space.
U#'4,.&0)"-.FE&.)"-.&ET
Uv++0(8.0"0&.%(1"&0.?4&.88,')0R'&0*.R,),)%
00000000000)"-.04"&9809K"908K'(1*0!.0#K")%.*/0
++T
U4"&"-.9.&0)"-.FE8."&#KJ"99.&)E0W"1(.FEXC3mXOE0ZT
Uv++0*.R,).09K.0&.41"#.-.)90R'&09K.08."&#KJ"99.&)0K.&./0++T
U4"&"-.9.&0)"-.FE&.41"#.-.)9E0W"1(.FEE0ZT
UZ#'4,.&T
44
The Build Process
?0).(37&2,3)/+)/.@)(2"/&).=2!%)/
Use the “svgconverter” for modifying SVG images of the resources before they are packaged in the
final JAR. The svgconverter allows you to provide only one icon or background image for a variety
of phones. It scales the SVG image to the appropriate size of the current target device and converts
it into a PNG image. For an background image you have to start naming your image
“bg”(“bg”+whatever+”.svg”), for an icon start with “icon”. The svgconverter then uses the defined
D#&..)D,i. and :#')D,i. of the target device for scaling such images. When the target device
does not specify these sizes the default size for icons is 15x15 and for backgrounds 128x160 pixels.
U#'4,.&0)"-.FE8W%#')W.&9.&E0ZT
<compiler>
The optional <compiler>-element can be used for specifying any compiler-arguments. J2ME Polish
normally calls the Java compiler normally with the appropriate classpath as well as bootclasspath
for the current target device. In some cases you might want to adjust the compiler settings, however,
so you can use the nested <compiler>-element. Along to all attributes of the standard <javac>-task,
the <compiler>-element also supports the "if" and "unless" attributes for selecting to appropriate
compiler setting:
45
The Build Process
46
The Build Process
You can specify additional command line arguments for the compiler with nested <compilerarg>
47
The Build Process
elements. These elements are specified like Command-line Arguments but have an additional
attribute that can be used to enable arguments only if a given compiler implementation will be used.
<obfuscator>
The optional <obfuscator>-element controls the obfuscating of the application bundle, which
decreases the jar-size and makes it difficult to reverse engineer the application.
?/+207,"3/.(%":1@AS./`0".#A(071M12"053S",-"&1@A3.01A(0%5177@A3173A(IH
48
The Build Process
Any number of <obfuscator>-elements can be used in a project. All active obfuscators are
combined by J2ME Polish.
The <obfuscator> supports the subelements <keep> and <parameter>.
The <keep> element is used to define classes which are loaded dynamically (e.g. with
Class.forName(...) ) and should not be obfuscated:
?/+207,"3/.(0%5177@A3173A(1%"+51@A3.01A(%":1@AS./`0".#A(H
?-11!(,5"77@A,/:=,/:!"%8=#8%":$,=N/:1M8%":$,65"77A(IH
?-11!(,5"77@A,/:=,/:!"%8=#8%":$,=a%/3B1.M8%":$,65"77A(IH
?I/+207,"3/.H
The used MIDlet classes do not need to be set with the <keep> element, since they are saved from
obfuscation automatically.
The <parameter>-element is used to specify parameters for the obfuscator. This can be useful for
integrating third party obfuscators which require additional settings (see page 157):
?/+207,"3/.(0%5177@A3173A(1%"+51@A3.01A(%":1@AS./`0".#A(H
?-11!(,5"77@A,/:=,/:!"%8=#8%":$,=N/:1M8%":$,65"77A(IH
?-11!(,5"77@A,/:=,/:!"%8=#8%":$,=a%/3B1.M8%":$,65"77A(IH
?!".":131.(%":1@A7,.$!3Q$51A(G"501@A==I7,.$!37I/+207,"31=7,.$!3A(IH
?I/+207,"3/.H
49
The Build Process
Several obfuscators can be combined just by specifying several <obfuscator> elements. When the
<keep> subelement is used, it only needs to be specified on of the <obfuscator> elements.
J2ME Polish will then use the obfuscated output of one obfuscator as input for the following
obfuscator.
A/2B"'/-
ProGuard is an excellent obfuscator, shrinker and optimizer by Eric Lafortune. It is freely availabe
under the GNU General Public License and can be downloaded from
K994/ZZ4&'%("&*38'(&#.R'&%.3).9.
If you want to use ProGuard as an obfuscator, please make sure that the proguard.jar-file is listed in
the classpath of the J2ME Polish task-definition (build.xml):
?3"7-#12(%":1@AbZ:1!/5$7BA(
,5"77%":1@A#1=1%/0&B=!/5$7B="%3=S/5$7BY"7-A(
,5"77!"3B@Aij!/5$7B=B/:1;I$:!/.3I1%/0&B4bZ:1!/5$7B4
+0$5#=b".'ij!/5$7B=B/:1;I$:!/.3Ib#/:=b".'!"#$%&'()($*+,-&*#$./-#.$012.3)42.AIH
You can use ProGuard by setting the name-attribute of the <obfuscator>-element to “ProGuard”.
ProGuard 3.x offers an additional optimization of the bytecode, which is disabled by default. The
optimization can be enabled by setting the “optimize”-parameter to “true”:
?/+207,"3/.(0%5177@A3173A(1%"+51@A3.01A(%":1@AS./`0".#A(H
?!".":131.(%":1@A/!3$:$91A(G"501@A3.01A(IH
?I/+207,"3/.H
:B"'/-
The yGuard obfuscator by the yWorks GmbH is another interesting obfuscator and code-shrinker.
J2ME Polish includes the library-classes, which are licensed under the GNU Lesser General Public
License. The full obfuscator is freely available from K994/ZZVVV3<V'&$83*..
If you want to use yGuard as an obfuscator, please make sure that either the yguard-lib.jar or the
original yguard.jar is listed in the classpath of the J2ME Polish task-definition (build.xml):
?3"7-#12(%":1@AbZ:1!/5$7BA(
,5"77%":1@A#1=1%/0&B=!/5$7B="%3=S/5$7BY"7-A(
,5"77!"3B@Aij!/5$7B=B/:1;I$:!/.3I1%/0&B4bZ:1!/5$7B4
+0$5#=b".'ij!/5$7B=B/:1;I$:!/.3Ib#/:=b".'!"#$%&'()($*+,-&*#$./-5012.36%&7)42.AIH
The yGuard obfuscator can be used by setting the name-attribute of the <obfuscator>-element to
“YGuard”:
?/+207,"3/.(0%5177@A3173A(1%"+51@A3.01A(%":1@Ao`0".#A(IH
50
The Build Process
@)+/2B"'/-
RetroGuard is the basis of both yGuard and ProGuard and was developed by Retrologic
Systems/Mark Welsh. It is licensed under the GNU Lesser General Public License and is included
in J2ME Polish by default. It can be downloaded from K994/ZZVVV3&.9&'1'%,#3#'-.
You can use RetroGuard just by setting the “name”-attribute to “RetroGuard”:
?/+207,"3/.(0%5177@A3173A(1%"+51@A3.01A(%":1@A]13./`0".#A(IH
C)$%*.D$'((E'(+)/
KlassMaster is a commercial obfuscator available from Zelix Pty Ltd. A free evaluation version can
be requested at K994/ZZVVV3i.1,?3#'-.
The KlassMaster integration is based on the WTK-mechanism for calling obfuscators, therefore
both the wxA3S"& as well as the $.)W3i,4 needs to be on the classpath:
?3"7-#12(%":1@AbZ:1!/5$7BA(
,5"77%":1@A#1=1%/0&B=!/5$7B="%3=S/5$7BY"7-A(
,5"77!"3B@Aij!/5$7B=B/:1;I$:!/.3I1%/0&B4bZ:1!/5$7B4
+0$5#=b".'ij!/5$7B=B/:1;I$:!/.3Ib#/:=b".'!"#$%&'()($*+,-&*#$./-89:)42.;!"</=)($*
+,-</=%&7-=+>?)@&#AIH
" p!R(8#"9.g1'V=.W.1: The obfuscation-flow level can also be set directly, e.g. “none” or
“aggressive”. This parameter takes precedent above the .)"!1.g1'Vp!R(8#"9,')-parameter.
" D#&,49g,1.: The file containing the full script can also be set. In that case please note that the
source-jar-file is always the “build/source.jar” and the target-file is the “build/dest.jar”.
The following example shows a possible invocation of KlassMaster:
?/+207,"3/.(0%5177@A3173A(1%"+51@A3.01A(%":1@Ae5"77U"731.A(H
?!".":131.(%":1@AE+207,"31Q5/CD1G15A(G"501@A%/%1A(IH
?I/+207,"3/.H
F'(0G.A/2
DashO Pro is a commercial obfuscator by Preemptive Solutions. A free evaluation version can be
requested at K994/ZZVVV34&..-49,W.3#'-.
When the DashO Pro obfuscator is used, either the Ant property “dasho.home” or the parameter
“DashoHome” needs to be given. The classpath does not need to be modified.
The DashO Pro obfuscator supports following parameters:
" B"8K'M'-.: needs to point to the installation directory of the DashO Pro obfuscator.
" q.&8,'): needs to correspond to the used version of DashO. The current default version is “3.1”.
" .)"!1.g1'Vp!R(8#"9,'): when “true” is given, DashO will obfuscate the application flow as
well. This is deactivated by default.
51
The Build Process
" .)"!1.D9&,)%I)#&,49,'): when “true” is given, Strings will be obfuscated by DashO as well.
Since this decreases the performance, it is deactivated by default.
" .)"!1.^.)"-,)%: when “true” is given, all possible classes will be renamed. This is activated by
default.
" .)"!1.p49,-,i"9,'): when “true” is given, the byte-code will be optimized by DashO. This
feature is activated by default.
" 7')89")9J''1>"%: a tag which will be added to all processed classes. This is only visible when a
decompiler is used.
" D#&,49g,1.: The file containing the full script can also be set. In that case please note that the
source-jar-file is always the “build/source.jar” and the target-file is the “build/dest.jar”.
A report about the renamed clases as well as methods will be written to
!(,1*ZPW.)*'&QZP*.W,#.QZP1'#"1.QZ'!R(8#"9,')+-"439?9. This file is useful for resolving
stacktraces in the obfuscated application.
This example shows the integration of DashO Pro:
?/+207,"3/.(0%5177@A3173A(1%"+51@A3.01A(%":1@AM"7B/A(H
?!".":131.(%":1@AM"7B/[/:1A(G"501@AIB/:1I071.IM"7BES./vX=VA(IH
?!".":131.(%":1@As1.7$/%A(G"501@AX=VA(IH
?I/+207,"3/.H
HGFI
JODE is quite a powerful optimizer, shrinker and obfuscator by Jochen Hoenicke. It is licensed
under the GNU General Public License and is available at K994/ZZS'*.38'(&#.R'&%.3).9 free of
charge.
If you want to use JODE, please make sure that the jode-jar-file is on the classpath:
?3"7-#12(%":1@AbZ:1!/5$7BA(
,5"77%":1@A#1=1%/0&B=!/5$7B="%3=S/5$7BY"7-A(
,5"77!"3B@Aij!/5$7B=B/:1;I$:!/.3I1%/0&B4bZ:1!/5$7B4
+0$5#=b".'ij!/5$7B=B/:1;I$:!/.3Ib#/:=b".'!"#$%&'()($*+,-&*#$./-A$3+6B)B)C6
#.+B)42.AIH
JODE supports the “ScriptFile”-parameter which can be used to specify the obfuscator-script.
Please note that the source-jar-file is always the “build/source.jar” and the target-file is the
“build/dest.jar”:
?/+207,"3/.(0%5177@A3173A(1%"+51@A3.01A(%":1@AR/#1A(H
?!".":131.(%":1@AN,.$!3Q$51A(G"501@A/+207,"31=b/7A(IH
?I/+207,"3/.H
When no script-file-parameter is present, J2ME Polish will create a default script. Depending on the
application and environment, several problems ranging from preverification/linking-errors to
NullPointerExceptions in the JODE-API can occur. Maybe someone with more experience with
JODE can provide help here – please get in touch with j2mepolish@enough.de.
52
The Build Process
preprocessing. This mechanism can be used for example to define configuration values:
?G".$"+517($%,50#1a%3S./!1.3$17@A3.01AH
?G".$"+51(%":1@A0!#"3140.5A(G"501@AB33!'IICCC=1%/0&B=#1I0!#"31A(IH
?G".$"+51(%":1@A!/5$7B=Y$51#D"81.=7!5$3P:"&1A
((((G"501@A3.01A(
(((($2@A!/5$7B=s1%#/.(@@(J/-$"A(IH
?IG".$"+517H
Variables which have been defined in this way can be included into the source code with the “ZZnF”
preprocessing directive and can be checked with the “PW"&,"!1.+)"-.Q/*.R,).*” symbol:
IIw$2#12(0!#"3140.5'#12$%1#
IIw@(N3.$%&(0.5(@(Aij(0!#"3140.5(;A*
IIw1571
N3.$%&(0.5(@(AB33!'IICCC=#12"053=,/:I0!#"31A*
IIw1%#$2
Variables can also be compared, please refer to the description of the n,R-directive on page 79 for
more information.
53
The Build Process
<debug>
The optional <debug>-element controls the inclusion of debugging messages for specific classes or
packages. The debugging messages will be activated or deactivated in the source code, so the
performance will not be decreased, when the debugging is deactivated.
?#1+0&(7B/CD/&E%F../.@A3.01A(G1.+/71@A2"571A(51G15@A1../.A($2@A3173A(H
?2$531.(!"331.%@A,/:=,/:!"%8=!",-"&1=nA(51G15@A$%2/A(IH
?2$531.(!"331.%@A,/:=,/:!"%8=!",-"&1=U865"77A(51G15@A#1+0&A(IH
?I#1+0&H
In the chapter “The world of preprocessing” on page 82 you will find more about the debugging
possibilities.
54
The Build Process
For a finer control of the debugging process, the <debug>-element allows the sub-element <filter>,
which defines the debug-level for specific classes or packages.
<jad>
With the <jad>-element user-defined attributes can be added to the JAD1-file as well as the
MANIFEST-file which is contained in the created JAR-file. The <jad> element contains a number
of <attribute>-sub-elements which define the actual attributes:
?b"#H
(?"33.$+031(
%":1@AJ/-$"4UPM51346"31&/.8A(
G"501@A`":1A(
$2@A!/5$7B=&./0!=N1.$17hKA(
IH
(?"33.$+031(
%":1@AUPM5134S07B4VA(
G"501@A7/,-13'II'Wt^(,/:=70%=1L":!51=N":!516B"3^(nA(
$2@A!/5$7B=:$#!ZA(
IH
?Ib"#H
55
The Build Process
Attributes which are defined in this way can be loaded in the application with the
MIDlet.getAppProperty( String name ) method, which needs the name of the attribute as an
argument and returns the value of that argument. Often it is advisable to use the variable-
mechanism of J2ME Polish instead, since such values are actually hard-coded into the application
and are, therefore, much faster than the getAppProperty(...)-mechanism.
The JAD-attributes can filtered and sorted using the <jadFilter> subelement:
?b"#H
(?"33.$+031(
%":1@AJ/-$"4UPM51346"31&/.8A(
G"501@A`":1A(
$2@A!/5$7B=&./0!=N1.$17hKA(
IH
(?b"#Q$531.H
UPM5134J":1^(UPM5134s1.7$/%^(
UPM5134s1%#/.^(UPM5134R".4O]D^(UPM5134R".4N$91^(
UPM5134M17,.$!3$/%k^(UPM5134P,/%k^(UPM5134P%2/4O]Dk^
UPM5134M"3"4N$91k^(UPM5134n^(n
(?Ib"#Q$531.H
?Ib"#H
The <jadfilter> element contains all allowed attribute names in the desired order and separated by
commas. You can use different filters by using the "if" or "unless" attributes:
56
The Build Process
Inside of the <jadfilter> element you can specify all allowed JAD-attributes in the desired order and
separated by commas. Following syntax is used:
<manifestFilter>
The manifest filter element can be used to sort and filter manifest attributes. Please note that the
first included attribute should always be the “Manifest-Version”-attribute. Otherwise the application
will most likely not work:
?:"%$2173Q$531.H
U"%$21734s1.7$/%^(UPM5134J":1^(UPM5134s1.7$/%^(UPM5134s1%#/.^
UPM5134V^(UPM5134Zk^(UPM5134Xk^(UPM5134hk^(UPM5134)k^(
U$,./F#$3$/%4S./2$51^(U$,./F#$3$/%46/%2$&0."3$/%^
UPM5134M17,.$!3$/%k^(UPM5134P,/%k^(UPM5134P%2/4O]Dk^
UPM5134M"3"4N$91k
?I:"%$2173Q$531.H
The <manifestFilter> element contains all allowed attribute names in the desired order and
separated by commas. You can use different filters by using the "if" or "unless" attributes:
57
The Build Process
Inside of the <manifestFilter > element you can specify all allowed MANIFEST-attributes in the
desired order and separated by commas. Following syntax is used:
ManifestFilter- Example Explanation
Text
name UPM5134J":1 The complete name of a required attribute.
name followed by UPM5134Zk The complete name of an optional attribute.
a questionmark
beginning of a UPM5134n All remaining attributes which names start with the given
name followed by sequence will be included at this position.
a star
star n All remaining attributes will be included at this position. A
star can only positioned at the end of a filter.
<preprocessor>
The <preprocessor> element can be used to integrate own or third party preprocessors. This can be
used for allowing new preprocessing directives for example (compare page 159).
?!.1!./,177/.
,5"77@A,/:=,/:!"%8=!.1!./,177=U8S.1!./,177/.A(
,5"77S"3B@A$:!/.3I!.1!./,177$%&=b".A(
H
(?!".":131.(
%":1@A7,.$!3Q$51A(
G"501@A==I7,.$!37I!.1!./,177=7,.$!3A(
IH
?I!.1!./,177/.H
58
The Build Process
The preprocessor can be configured using a number <parameter> subelements. Each <parameter>
subelement needs to define the attributes “name” and “value”.
<java>
The <java>-element can be used to extend J2ME Polish with any Java utility. It accepts all attributes
and nested elements like the Ant-<java>-element (compare
http://ant.apache.org/manual/CoreTasks/java.html) as well as the additional attribute “if”, “unless”
and “message”. J2ME Polish variables can be used in the nested <arg>-elements, so that the call can
be adjusted for the current device.
Each defined <java>-element is called after the successful creation of an application-bundle. A
possible use of the <java>-element is the signing of MIDlets, which is described in the signing-
how-to on page 186.
The following example calls the JadUtil.jar of the Wireless Toolkit for signing a JAD file:
US"W"0S"&FE]CV9$3K'-.OZ!,)ZG"*>''13S"&E0
000000 R'&$FE9&(.E0
000000 R",1').&&'&FE9&(.E0
0000 ,RFE4'1,8K3-,*4HE0
()1.88FE9.89E
-.88"%.FE;**,)%08,%)"9(&.0R'&0*.W,#.0]C4'1,8K3,*.)9,R,.&OE
T
U"&%01,).FE+"**S"&8,%EZT
U"&%01,).FE+$.<4"880]C4"88V'&*OEZT
U"&%01,).FE+"1,"80D,%)A:B1.9EZT
U"&%01,).FE+$.<89'&.0-,*1.983$8EZT
U"&%01,).FE+,)4(9S"*0*,89Z]C4'1,8K3S"*\"-.OEZT
U"&%01,).FE+'(94(9S"*0*,89Z]C4'1,8K3S"*\"-.OEZT
U"&%01,).FE+S"&R,1.0*,89Z]C4'1,8K3S"&\"-.OEZT
UZS"W"T
variable Explanation
polish.vendor The vendor of the current device, e.g. “Siemens” or “Nokia”.
polish.name The name of the current device, e.g. “N-Gage”.
polish.identifier The identifier of the current device, e.g. “Siemens/SX1”.
polish.version The version of the application as defined in the info-section.
polish.jarName The name of the jar-file as defined in the info-section.
polish.jadName The name of the jad-file as defined in the info-section.
59
The Build Process
<packager>
Usually the efficient internal J2ME Polish packager is used for creating the final application
bundles. For using a different packaging-program, the <packager>-element can be used:
?!",-"&1.
1L1,03"+51@Ab".A
".&0:1%37@A,G2U**ij!/5$7B=b".S"3B;**46**ij!/5$7B=!",-"&1M$.;**=A
IH
A possible alternative might be the Open Source tool “7-Zip”, which can create smaller files
60
The Build Process
compared to the standard ZIP mechanism. This might result in problems on the actual device,
though, so use with care. The 7-Zip tool can be obtained free of charge at http://www.7-zip.org/.
The <packager>-element supports following attributes:
The <emulator>-Section
The <emulator>-element is responsible for launching any emulators after the application has been
build.
?1:05"3/.
C"$3@A3.01A
3.",1@A,5"77A
!.121.1%,17@A:81:05"3/.=!./!1.3$17A
71,0.$38M/:"$%@A3.0731#A
1%"+51S./2$51.@A3.01A
1%"+51U1:/.8U/%$3/.@A3.01A
1%"+51J13C/.-U/%$3/.@A3.01A
$2@A3173A
H
?!".":131.(%":1@A4xb":A(
G"501@A3."%7$1%3@B33!'II5/,"5B/73'_K_KIij!/5$7B=b"#J":1;A(IH
61
The Build Process
?I1:05"3/.H
In the above example the emulator is only started, when the “test”-property is “true”.
62
The Build Process
WTK Emulators
For emulators which are integrated in the Wireless Toolkit the “I-(1"9'&3D$,)”-capability is used
for determining the correct emulator. This is the name which can be found in the
63
The Build Process
You can also set several skins, when several versions of an emulator do exist, for example.
J2ME Polish will then choose the the first emulator it finds. Additional skins are defined by the
capabilities “I-(1"9'&3D$,)3H”, “I-(1"9'&3D$,)3a” and so forth.
Nokia Emulators
For launching Siemens-emulators it might be necessary to define the “)'$,"3K'-.”-property in the
!(,1*3?-1. This property needs to point to the installation directory of the Nokia emulators and
defaults to “C:\Nokia” on Windows machines and to “${user.home}/Nokia” on Unix machines. For
many emulators it is sufficient to set the “I-(1"9'&371"88” and “I-(1"9'&3D$,)”-capabilities of
the device in the “${polish.home}/devices.xml” file. The “I-(1"9'&371"88”-capability then needs
to be “NokiaEmulator” and the “I-(1"9'&3D$,)”-capability needs to correspond with the name of
the emulator which can be found in the “${nokia.home}/Devices”-directory.
Some non-standard-emulators make it necessary the use the “GenericEmulator”-class instead. The
invocation of such emulators is explained below.
Siemens Emulators
For launching Siemens-emulators it might be necessary to define the “8,.-.)83K'-.”-property in
the !(,1*3?-1. This property needs to point to the installation directory of the “Siemens Mobile
Toolkit” (SMTK) and defaults to “C:\siemens”. When a Siemens-emulator should be used, the
corresponding device-definition in the “${polish.home}/devices.xml” file needs to set the
“I-(1"9'&371"88”-capability to “SiemensEmulator” (this is the default for all Siemens-phones).
The “Emulator.Skin”-capability needs to specify the name of the emulator, which can be found in
the “${siemens.home}/SMTK/emulators”-directory.
Motorola Emulators
For launching Motorola-emulators it is necessary to define the “-'9'&'1"3K'-.”-property in the
!(,1*3?-1. This property needs to point to the installation directory of the Motorola SDK, e.g.
“C:\program files\Motorola\SDK v.4.3 for J2ME”. Since Motorola-emulators do not support the
“Unified Emulator Interface”, the emulators are started by the “GenericEmulator”. See below for
more details.
64
The Build Process
You need also to define the command-line arguments for the emulator with the
“I-(1"9'&3;&%(-.)98”-capability. Command-line arguments are separated by two semicolons in a
row, e.g. “-Xdescriptor;;${polish.jadPath};;-classpath;;${polish.jarPath}”. As you can see in the
example, any J2ME Polish-variables as well as Ant-properties can be used within the emulator-
arguments. Often used is the “polish.jadPath”-variable, which contains the absolute path to the
JAD-file and the “polish.jarPath”-variable, which does the same for the JAR-file. Also useful is the
4'1,8K3#1"88.83-,*1.9+Y variable that contains the name of the first MIDlet class.
You should try to minimize the dependency on a specific system setup by using properties like
“motorola.home” or “nokia.home” in your settings. These properties can then be defined within the
corresponding !(,1*3?-1 file.
Please inform the J2ME Polish community about any emulators you have integrated, so that other
users can also benefit from your settings. Just send an email to SH-.4'1,8Ks.)'(%K3*.. Thanks!
In the first line the actual directive is given and in the following lines the binary equivalent
compiled java code is listed. The second number from the left is the number which is given in the
original error message (e.g. 4"#$"%.3#1"883-.9K'*2oYyc5).
When the “showDecompiledStackTrace”-attribute of the <emulator>-element is set to “true” or
“yes”, a decompiled code fragment will be given out for each stack-trace, even when the source-
code position could be located.
Please note that the source-code position can only be located, when the debugging-mode is
activated. This is done by setting the “enable”-attribute of the <debug>-element to “true”. In the
default-setup this is done when the “test”-target of the build.xml is called first:
65
The Build Process
“")909.890SH-.4'1,8K”.
66
Resource Assembling
Resource Assembling
Concepts
During the build process resources like images, sound files etc. are assembled automatically for
each device.
Resources for all devices will be placed into the “resources” folder (when no other directory has
been specified in the <resources>-element or with the “resDir”-attribute of the <build>-element in
the “build.xml” file).
Resources for devices of specific vendors can be placed into the “resources/[vendor-name]” folder,
e.g. the “resources/Nokia” folder for Nokia devices. Resources for a specific device can be placed
into the “resources/[vendor-name]/[device-name]” folder, e.g. the folder “resources/Nokia/3650” for
Nokia/3650 devices.
For more general resources the groups can be used to which a device belongs to. High-color images
can be be put into the “resources/BitsPerPixel.16+” folder, for example. The groups can be used
very efficiently to include only those resources which are actually relevant for a specific device. A
device can belong to many different groups, which are defined either implicitly by the capabilities
of that device (compare the section “Device Capabilities” on page 26) or explicitly by setting the
<groups>-element of a device in the device-database.
All resources will be copied to the root of the application and more specific resources will overwrite
the common resources: If you have a picture named “hello.png” in the “resources” folder as well as
in the “resources/Nokia” and in the “resources/Nokia/6600” folder, the version in the “resources”
folder will be used for all non-Nokia devices, the version contained in the “resources/Nokia” folder
will be used for all Nokia devices, but the image “resources/Nokia/6600/hello.png” will be used for
the application which is build for the Nokia/6600 phone. In the application code you can load this
image from the root: :-"%.3#&."9.:-"%.20EZK.11'34)%E05, no matter from where the resource
was copied from.
No subfolders can be used within an application, so it is not possible to load resources from a
subfolder within the application. Subfolders do add overhead to an application, this is why the usage
of subfolders is not allowed.
Instead of
ZZ09K,80,80)'90"11'V.*/
:)4(9D9&."-0,80F0%.971"88253%.9^.8'(&#.;8D9&."-2EZ1.W.18Z1.W.13-"4E560
Subfolders are merely used to differentiate between different devices and device groups.
67
Resource Assembling
68
Resource Assembling
The situation is different in the resource assembling step, though. Obviously you can put all MP3-
files into the “resources/mp3” folder and all MIDI-files into the “resources/midi”-folder, so that
these resources are available when they are needed. But for devices which support both MP3 as well
as MIDI sound, the application will contain the MIDI files as well, even though only the MP3 files
69
Resource Assembling
In the above example MIDI files are only included when two conditions are met:
1) The device supports MIDI sound
2) The device does not support MP3 sound.
The <resources>-element is a subelement of the <build>-section, look at page 41 for detailed
information about the supported attributes as well as the nested elements. An often used attribute is
the “exclude”-attribute which specifies any files which should not be included into the application
bundle. You can have readme-files for example with background information for designers. In the
above example all files starting with “readme” are excluded from the final application JAR file.
The <resources>-element is also responsible for the localization of the application, which is
discussed in the following chapter.
On a final note please remember not to use the “resDir”-attribute of the <build>-element when you
use the <resources>-element, since this will yield unpredictable results.
Localization
Concepts
Often applications should not only be marketed in one country or region, but in several ones. The
process of adjusting an application to a specific region is called localization.
J2ME Polish offers a very powerful framework for not only managing the obvious needed
translations, but also for adjusting any kind of resources like images or sounds to specific regions.
Even enhanced features like locale-aware date-formatting is no problem with J2ME Polish.
Traditionally localization involved loading the localized messages from a file during runtime and
retrieving these messages with Hashtable-keys. This significantly slows down a localized
application and also enlarges the application size. A unique feature of J2ME Polish is that the
translations are actually directly embedded into the source-code, so in most cases a localized
application has absolutely no overhead at all compared to a non-localized application – both in size
70
Localization
as well as in performance.
You can also enable dynamic translations that can be changed during the runtime of the application.
In that case any String-keys are converted into simple integer-keys during the preprocessing phase
so that translations can be retrieved as fast as possible.
The localization framework extends the concepts of the resource assembling, so that you can for
example provide one Nokia specific resource for each supported locale. The localization is
controlled by the <localization>-element, which is a subelement of the <resources>-element
(compare pages 67 and 41).
The <localization>-element is responsible for defining which locales should be supported. In the
above example the locales “de” (German) and “en” (English) are used, unless the test-mode is
active, in which case the application is only build for the English locale.
Locales are defined using the ISO standard of two lowercase letters for the language2 (“en” for
English, “de” for German, “fr” for French and so on) and two optional uppercase letters for the
country3 (“US” for USA, “DE” for Germany, “FR” for France and so on). Possible combinations
separate the language and the region with an underline. You can localize your application for French
speaking Canadians by supporting the locale “fr_CA” for example.
In each used resources-folder you can create a subfolder for a specific locale, e.g. “resources/en” for
general English resources and “resources/fr_CA” for resources for the French speaking Canadians.
The usual specification rules also apply here, so a more specific resource in “resources/Nokia/en”
will override a resource with the same name in “resources/Nokia” when the English locale is used.
Managing Translations
! 89"9,#0D9&,)%0%.920D9&,)%0)"-.L0D9&,)%04"&"-.9.&05, and
! 89"9,#0D9&,)%0%.920D9&,)%0)"-.L0D9&,)%PQ04"&"-.9.&805.
71
Localization
P333Q
ZZ0%.99,)%0"08,-41.09&")81"9,')/
9K,83-.)(D#&..)3"44.)*20='#"1.3%.920E-.)(3D9"&9`"-.E5L0)(1156
ZZ0%.99,)%0"09&")81"9,')0V,9K0').04"&"-.9.&/
9K,83-.)(D#&..)38.9>,91.20='#"1.3%.920E9,91.3A",)EL0(8.&\"-.05L0)(1156
ZZ0%.99,)%0"09&")81"9,')0V,9K08.W.&"104"&"-.9.&8/
D9&,)%PQ04"&"-.9.&80F0).V0D9&,)%PHQ6
4"&"-.9.&8P[Q0F0(8.&\"-.6
4"&"-.9.&8PYQ0F0.).-<\"-.6
9K,839.?9g,.1*38.9D9&,)%20='#"1.3%.92E-.88"%.83:)9&'*(#9,')EL04"&"-.9.&805056
As you can see in the above example you can use parameters in the translations, the first parameter
is C[O, the second CYO and so on. You can also use any Java specific characters, e.g. “X9” for a tab
or “XE” for using a quotation mark.
The translations are embedded in the actual code during the preprocessing phase, if you have a look
at the preprocessed code, you will find following code:
,-4'&90*.3.)'(%K34'1,8K3(9,13='#"1.6
P333Q
ZZ0%.99,)%0"08,-41.09&")81"9,')/
9K,83-.)(D#&..)3"44.)*20ED9"&90>,#$1.0g,%K9EL0)(1156
ZZ0%.99,)%0"09&")81"9,')0V,9K0').04"&"-.9.&/
9K,83-.)(D#&..)38.9>,91.20Ez.1#'-.0E0o0(8.&\"-.0o0EvEL0)(1156
ZZ0%.99,)%0"09&")81"9,')0V,9K08.W.&"104"&"-.9.&8/
D9&,)%PQ04"&"-.9.&80F0).V0D9&,)%PHQ6
4"&"-.9.&8P[Q0F0(8.&\"-.6
4"&"-.9.&8PYQ0F0.).-<\"-.6
9K,839.?9g,.1*38.9D9&,)%20='#"1.3%.92[L04"&"-.9.&805056
The translations for the first two Locale-methods are directly embedded into the source-code, so
there is no performance or size impact compared to a non-localized application at all for these kinds
of translations. Only for the third method a call to the Locale class is actually made, but in that call
the former String key “messages.Introduction” is transformed to a simple integer, thus saving
valuable bytes as well as ensuring a fast retrieval of the resource in question.
Dynamic Translations
You can also use dynamic translations that can be changed during the runtime of your application.
You have to activate dynamic translations by setting the "dynamic"-attribute of the <localization>-
72
Localization
element to "true":
?.17/0.,17
#$.@A.17/0.,17A
1L,50#17@An=3L3A
H
?5/,"5$9"3$/%(
#8%":$,@A3.01A
#12"053@A1%A
5/,"517@A#1^(1%^(2.v6aA(
IH
?I.17/0.,17H
You can now use the Locale class normally, the only difference to using static translations is that the
translations are not embedded into your source-code but rather retrieved dynamically from the
Locale class. For allowing a fast performance J2ME Polish converts all String-based keys into
simple integer-values, so that only a minimal overhead is present.
You can change the translations by calling ='#"1.31'"*>&")81"9,')820D9&,)%0(&105. For each
supported locale J2ME Polish generates a P1'#"1.+)"-.Q31'# file, e.g. "de.loc", "en.loc" or
"fr_CA.loc". You can switch to the German translation by calling ='#"1.31'"*>&")81"9,')820
EZ*.31'#E05, for example. Don't forget the slash character '/' at the start of the URL.
Defining Translations
All translations are by default defined in the -.88"%.839?9 file. All default messages are defined in
“&.8'(&#.8Z-.88"%.839?9”, all German messages in “&.8'(&#.8Z*.Z-.88"%.839?9” and all
French Canadian resources in “&.8'(&#.8ZR&r7;Z-.88"%.839?9”. You can also use the files
“&.8'(&#.8Z-.88"%.839?9”, “&.8'(&#.8Z-.88"%.8r*.39?9” and
“&.8'(&#.8Z-.88"%.8rR&r7;39?9” if you prefer to have all translations in one folder. The name of
the messages-files can be adjusted with the “messages”-attribute of the <localization>-element by
the way.
The translations can be adjusted by the usual hierarchy of the resource assembling, so if you have
Nokia-specific translations, these can be defined in the “&.8'(&#.8Z\'$,"Z-.88"%.839?9” etc.
When an application is localized for the Nokia/6600 phone and the German (“de”) language, J2ME
Polish tries to find a translation in following places:
1. resources/Nokia/6600/de/messages.txt
2. resources/Nokia/6600/messages_de.txt
3. resources/[group-name]/de/messages.txt, e.g. resources/Series60/de/messages.txt
4. resources/[group-name]/messages_de.txt, , e.g. resources/Series60/messages_de.txt
5. resources/Nokia/de/messages.txt
6. resources/Nokia/messages_de.txt
7. resources/de/messages.txt
8. resources/messages_de.txt
When the translation is still not found the same hierarchy is searched again, but this time the default
73
Localization
messages.txt file is used. If the translation cannot be found, J2ME Polish will report the error and
stop the build. When also a region is specified (e.g. “fr_CA” for French Canadian), J2ME Polish
will first try to get a specific “fr_CA” message, e.g. from
“&.8'(&#.8Z\'$,"Zdd[[ZR&r7;Z-.88"%.839?9”, secondly the translation will be searched for the
language, e.g. “&.8'(&#.8Z\'$,"Zdd[[ZR&Z-.88"%.839?9”, before the translation is retrieved
from the default messages-file.
In the actual translation files you can insert comments by starting the line with a hash-mark (#).
Like in normal Java internationalization you can use parameters within the translations, which are
denoted by {0}, {1}, {2} and so on:
-.)(3D9"&9`"-.FD9"&90>,#$1.0g,%K9
n09K.09,91.0'R09K.0-",)+8#&..)0V,9K09K.0(8.&+)"-.0"809K.0')1<04"&"-.9.&/
9,91.3A",)Fz.1#'-.0C[Ov
n09K.0,)9&'0R'&0"0).V0%"-.0{0V,9K0R'11'V,)%04"&"-.9.&8/
n0C[O/09K.0)"-.0'R09K.041"<.&
n0CYO/09K.0)"-.0'R09K.0&.-'9.0'&0#'-4(9.&041"<.&
-.88"%.83:)9&'*(#9,')FCYO09K&."9.)809'09,#$1.0<'(vX)C[O0"%",)890CYO0,801'"*,)%333
Such variables can also be used within the translations (of course normal variables can also be
used):
n0>K.041"<.&0K"80V')08'-.0)(%%.98L0C[O084.#,R,.809K.0)(-!.&0'R0V')0)(%%.98/
-.88"%.83|'(M"W.z')F7')%&"98v0|'(0K"W.0V')0C[O0]C4'1,8K3q.)*'&O+]Cq,&9("17(&&.)#<Ov
Naturally the variables can be used during the usual preprocessing in the Java source code as well:
ZZnF0D9&,)%0W,&9("17(&&.)#<0F0E]Cq,&9("17(&&.)#<OE6
Please compare the documentation of the <info>-section on page 31 for learning the names of the
MIDlet-attributes.
74
Localization
! 89"9,#0D9&,)%07p@\>^| is a field holding the ISO country code. This is null when no country
is used in the current locale.
! 89"9,#0D9&,)%0B:DJ=;|r=;\`@;`I is a field holding the localized language name, e.g.
“Deutsch” for German.
! 89"9,#0D9&,)%0B:DJ=;|r7p@\>^| is a field holding the localized country name, e.g.
“Deutschland” for Germany. This is null when no country is used in the current locale.
! 89"9,#0D9&,)%07@^^I\7|rD|Aep= is a field holding the symbol of the used currency, e.g. “$”
or “€”. This is null when no country is used in the current locale.
! 89"9,#0D9&,)%07@^^I\7|r7pBI is a field holding the three-letter code of the used currency,
e.g. “USD” or “EUR”. This is null when no country is used in the current locale.
Common Traps
75
Localization
ZZ09K,80,80S(890R,)./
9K,83-.)(D#&..)3"44.)*20='#"1.3%.920E-.)(3D9"&9`"-.E05L0)(1156
When you have several parameters, the parameters need to be given in a variable, otherwise J2ME
Polish is again unable to process the call correctly:
ZZ0).W.&0*'09K,8/
9K,83-.)(D#&..)3"44.)*20='#"1.3%.920E%"-.3D9"&9A.88"%.E05L0).V0D9&,)%PQC0(8.&\"-.L0
.).-<)"-.0O056
The following example shows the definition of some of these variables within a -.88"%.839?9 file:
W"&/4'1,8K3#'--")*3#")#.1F;!!&(#K
76
Localization
W"&/4'1,8K3#'--")*3*.1.9.F=}8#K.)
G".'!/5$7B=3$351=$%!03@F$%&"+1
This example shows the definition of some of these variables within the !(,1*3?-1 file. This
approach is useful when no complete localization/internationalization should be done:
UW"&,"!1.0)"-.FE4'1,8K3#'--")*3#")#.1E0W"1(.FE;!!&(#KE0ZT
UW"&,"!1.0)"-.FE4'1,8K3#'--")*3*.1.9.E0W"1(.FE=}8#K.)E0ZT
UW"&,"!1.0)"-.FE!/5$7B=3$351=$%!03E0W"1(.FEF$%&"+1E0ZT
77
The World of Preprocessing
Checking a Single Symbol with #ifdef, #ifndef, #else, #elifdef, #elifndef and #endif
Single symbols can be checked easily with the #ifdef directive:
IIw$2#12(!/5$7B=$:"&17=#$.1,3D/"#
P:"&1($:"&1(@(P:"&1=,.1"31P:"&1q(%":1(r*
IIw(.130.%($:"&1*
IIw1571
7,B1#051P:"&1q(%":1(r*
.130.%(%055*
IIw1%#$2
When the symbol “polish.images.directLoad” is defined, the code will be transformed to the
following:
IIw$2#12(!/5$7B=$:"&17=#$.1,3D/"#
P:"&1($:"&1(@(P:"&1=,.1"31P:"&1q(%":1(r*
.130.%($:"&1*
IIw1571
IIw(7,B1#051P:"&1q(%":1(r*
IIw(.130.%(%055*
IIw1%#$2
If, however, the symbol “polish.images.directLoad” is not defined, the transformation will be:
IIw$2#12(!/5$7B=$:"&17=#$.1,3D/"#
IIw(P:"&1($:"&1(@(P:"&1=,.1"31P:"&1q(%":1(r*
IIw(.130.%($:"&1*
IIw1571
7,B1#051P:"&1q(%":1(r*
.130.%(%055*
IIw1%#$2
Each #ifdef and #ifndef directive needs to be closed by the #endif directive.
78
The World of Preprocessing
The #ifdef directives can be nested, of course. Other preprocessing directives can be included into
the sub-sections as well:
IIw$2#12(:8N8:+/5
IIw$2%#12(:8E3B1.N8:+/5
IIw#1+0&
N8731:=/03=!.$%35%qA/%58(:8N8:+/5($7(#12$%1#=Ar*
#/N/:13B$%&qr*
IIw1571
IIw#1+0&
N8731:=/03=!.$%35%qA:8N8:+/5("%#(:8E3B1.N8:+/5(".1(#12$%1#=Ar*
#/N/:13B$%&F571qr*
IIw1%#$2
IIw1%#$2
The #ifdef directive and its related directives are faster to process than the more complex #if
directives.
Checking Several Symbols and Variables with #if, #else, #elif and #endif
With each #ifdef directive only a single symbol can be checked. With the #if and #elif directives,
however, complex terms containing several symbols and variables can be evaluated:
IIw$2(071F%B"%,1#P%!03(uu(q!/5$7B=B"7S/$%31.FG1%37(yy(!/5$7B=:/071N0!!/.31#r
79
The World of Preprocessing
#/N/:13B$%&qr*
IIw1%#$2
#if directives can also be nested and contain other preprocessing directives like the #ifdef directives.
#if and #ifdef directives can also be mixed:
IIw$2(f+"7$,P%!03(uu(q!/5$7B=B"7S/$%31.FG1%37(yy(!/5$7B=:/071N0!!/.31#r
#/N/:13B$%&qr*
IIw$2(!/5$7B=\$37S1.S$L15(H@(_
#/N/:13B$%&6/5/.205qr*
IIw1571
#/N/:13B$%&M055qr*
IIw1%#$2
IIw15$2#12(#/d$5#N3022
#/d$5#N3022qr*
IIw1%#$2
In the terms the boolean operators &&, ||, ^ and ! can be used. Complex terms can be separated
using normal parenthesizes “(“ and “)”. The term arguments for boolean operators are symbols,
which are true when they are defined and false otherwise.
Variables can be checked with the comparator FF, >, <, <= and >=. Arguments for the comparators
are variables or constants.
A term can include comparators and boolean operators, when the sections are separated by
parenthesizes.
80
The World of Preprocessing
In the above example the heapsize is compared using the !<9.8-function. When a function should
be used, a dollar-sign and curly parenthesizes needs to embrace the call. The !<9.8-function will
81
The World of Preprocessing
return -1 when the given memory-value is “dynamic”, so it might be necessary to test for both
values:
IIw$2(q(ij(+8317q(!/5$7B=[1"!N$91(r(;(H(VKZhKK(r(/.(q!/5$7B=[1"!N$91(@@(#8%":$,r
You will find more information about using functions at the “Using Variables” section on page 85.
Hiding Code
Code sections can be temporarily commented out, to avoid problems in the IDE. A typical problem
are several return statements:
IIw$2#12(!/5$7B=$:"&17=#$.1,3D/"#
P:"&1($:"&1(@(P:"&1=,.1"31P:"&1q(%":1(r*
IIw(.130.%($:"&1*
IIw1571
7,B1#051P:"&1q(%":1(r*
.130.%(%055*
IIw1%#$2
In this example the first return statement is hidden with a “//# “ directive. When the first #ifdef
directive is true, the corresponding code will be made visible again. The space after the # sign is
important for the correct handling of such comments.
You can define what debugging level is used by adding the debugging-level to the #debug directive.
When no level is specified the “debug” level is assumed.
IIw#1+0&($%2/
N8731:=/03=!.$%35%qA3B1($%2/(#1+0&&$%&(51G15($7(1%"+51#(2/.(3B$7(,5"77=Ar*
The #mdebug (multi-line debug) directive can be used to use multiple lines of debugging
information. It must be finished with the #enddebug directive:
IIw:#1+0&(1../.
1=!.$%3N3",-Y.",1qr*
N8731:=/03=!.$%35%qA0%"+51(3/(5/"#(7/:13B$%&'(A(l(1(r*
IIw1%##1+0&
82
The World of Preprocessing
IIw#1+0&(1../.
N8731:=/03=!.$%35%qA0%"+51(3/(5/"#(7/:13B$%&'(A(l(1(r*
Directive Explanation
//#debug [level] The next line is only compiled when the debugging setting for the class in
which the debugging information is enabled for the specified level. When
no level is specified, the “debug” level is assumed.
//#mdebug [level] The next lines up to the #enddebug directive will be compiled only when
the debugging setting for the class in which the debugging information is
enabled for the specified level. When no level is specified, the “debug”
level is assumed. Instead the preprocessing symbols “polish.debug.debug”,
“polish.debug.info”, “polish.debug.warn” etc can be used with the #ifdef
directive.
//#enddebug Marks the end of the #mdebug section.
//#ifdef, //#if The preprocessing symbols “polish.debug.debug”, “polish.debug.info”,
“polish.debug.warn” etc can be used instead of the #mdebug directive:
ZZn,R04'1,8K3*.!(%3,)R'
00,R02"&%(-.)90FF0)(1150C
00000D<89.-3'(934&,)91)2u"&%(-.)90,80)(11vt56
00O
ZZn.)*,R
Debug Levels
Following debug levels are predefined:
“debug”, “info”, “warn”, “error” and “fatal”. The specific level for a class can be defined with the
<debug> element of the J2ME Polish-task:
?#1+0&(7B/CD/&E%F../.@A3.01A(G1.+/71@A2"571A(51G15@A1../.A($2@A3173A(H
?2$531.(!"331.%@A,/:=,/:!"%8=!",-"&1=nA(51G15@A$%2/A(IH
?2$531.(!"331.%@A,/:=,/:!"%8=!",-"&1=U865"77A(51G15@A#1+0&A(IH
?I#1+0&H
Please see the section <debug> in the chapter “The Build Process” for further information. The
levels are weighted, meaning that the debug level is lower than the info level, which is in turn lower
than the error level and so forth:
debug < info < warn < error < fatal < user-defined
Thus when the info level is activated for a class, all debugging information with the level “warn”,
“error”, “fatal” and with a user-defined level will also be compiled.
User specific debugging levels can be useful for accomplishing specific tasks. For example a level
“benchmark” could be defined to allow the measurement of the performance:
IIw#1+0&(+1%,B:".-
5/%&(73".3Y$:1(@(N8731:=,0..1%3Y$:1U$5$7qr*
,"556/:!51LU13B/#qr*
IIw#1+0&(+1%,B:".-
83
The World of Preprocessing
N8731:=/03=!.$%35%qA,/:!51L(:13B/#(3//-(<A(l(qN8731:=,0..1%3Y$:1U$5$7qr(4(
73".3Y$:1r(l(A>(:7=Ar*
You can make the debug information available in your MIDlet class with the following code:
&*#$./(#1=1%/0&B=!/5$7B=03$5=M1+0&*
#17%&DED%2''E:5:FG%+/E+H/+>3'E:FG%+/E"
IIw$2#12(!/5$7B=#1+0&F%"+51#
#.&?2/+(6/::"%#(5/&6:#(@(>+<(6/::"%#q(A7B/C(5/&A^(6/::"%#=N6]FFJ^(VK(r*
IIw1%#$2
#.&?2/+(N,.11%(:"$%N,.11%*
#.&?2/+(N,.11%(#$7!5"8*
<===>
#17%&D(U8UPM513qr(j
<===>
IIw$2#12(!/5$7B=#1+0&F%"+51#
/(&'=:"$%N,.11%="##6/::"%#q(/(&'=5/&6:#(r*
IIw1%#$2
;
#17%&D(?$&3(,/::"%#a,3$/%q6/::"%#(,:#^(M$7!5"8"+51(7,.11%(r(j
<===>
IIw$2#12(!/5$7B=#1+0&F%"+51#
&I(q,:#(@@(/(&'=5/&6:#r(j
M1+0&=7B/CD/&q(/(&'=#$7!5"8(r*
;
IIw1%#$2
;
In the above example the MIDlet “MyMIDlet” adds a command to its main screen when the
debugging mode is enabled. When this is the case, the preprocessing symbol
“polish.debugEnabled” will be defined. The user can then select the “show log” command to see
view all logging messages. When the user selects the “return” command from the log-screen, he
will return to the screen which has been shown before.
Please make sure, that you have added the “import/enough-j2mepolish-client.jar” to the classpath of
your project, when using the Debug-class.
Debug-Method Explanation
Debug.showLog( Display display ) Shows the log containing all messages. When another
message is added while the log is shown, the log will be
updated.
84
The World of Preprocessing
IIw@(!.$G"31(N3.$%&(0.5(@(Aij(73".340.5(;A*
When the variable is not defined, the above example would throw an exception during the
preprocessing step of the build process. You can use the “[variable]:defined” symbol, which is set
for every known variable:
IIw$2#12(73".340.5'#12$%1#
IIw@(!.$G"31(N3.$%&(0.5(@(Aij(73".340.5(;A*
IIw1571
#.&?2/+EN3.$%&(0.5(@(AB33!'IIVtZ=VT_=VKV=VKVA*
IIw1%#$2
This is especially useful for setting configuration values, which can change easily, like Web-URLs
and so on.
The name of the variable needs to be surrounded by a Dollar-Sign followed by curly parenthesizes
(]CW"&,"!1.+)"-.O), just like referring to Ant-properties in the build.xml.
Variables can be defined in the <variables>-element in the build.xml. Other variables are defined in
the devices.xml, vendors.xml and groups.xml by the capabilities of the devices, vendors and groups.
These files are located in the installation directory of J2ME Polish.
Variable-Functions
You can use functions like “uppercase” to change the values. A function is used within the curly
parenthesizes and surrounds the variable-name by normal parenthesizes:
IIw$2#12(73".340.5'#12$%1#
IIw@(!.$G"31(N3.$%&(0.5(@(Aij(5/C1.,"71q73".340.5r(;A*
IIw1571
#.&?2/+EN3.$%&(0.5(@(AB33!'IIVtZ=VT_=VKV=VKVA*
IIw1%#$2
When using function you do not necessarily need a variable – you can also use a direct value. This
can be handy when handling with memory values for example:
IIw$2(ij(+8317q(!/5$7B=[1"!N$91(r(;(H(ij(+8317qVKK(-+r(;
Function Explanation
uppercase Translates the given value into uppercase. “abc” becomes “ABC” for example.
lowercase Translates the given value into lowercase. “ABC” becomes “abc” for example.
bytes Calculates the number of bytes of the given memory value. “1 kb” becomes 1024
for example. The memory-value “dynamic” results in -1.
kilobytes Calculates the (double) number of kilobytes of the given memory value. The value
will contain a point and decimal places. “512 bytes” becomes “0.5” for example,
“1024 bytes” becomes “1” and so on.
megabytes Calculates the (double) number of megabytes of the given memory value.
gigabytes Calculates the (double) number of gigabytes of the given memory value.
85
The World of Preprocessing
In the above example one of the styles “cool”, “frosty” or “default” is used for the new item. The
style “frosty” is only used when the style “cool” is not defined. The style “default” is only used,
when neither the style “cool” nor the style “frosty” is defined. The style “default” is special, since it
is always defined, even when the designer does not define it explicitly. The #style directive needs at
least one style name as argument. The style is deemed optional when the style ends with a question
mark. In that case it will only be used when it is defined:
IIw73851(,//5k
N3.$%&P31:(0.5(@(%1C(N3.$%&P31:q(%055^(AB33!'IIVtZ=VT_=VKV=VKVA(r*
The styles mentioned here can be defined in the “resources/polish.css” file. In that file the names of
custom styles need to start with a dot. In the above example you can define the styles “.cool”,
“.frosty” or “default”. The “default” style is a predefined style and its name must not, therefore, start
with a dot.
Styles are only used, when the J2ME Polish GUI is used. This can be triggered with the
“usePolishGui” attribute of the <build> element in the build.xml.
Using #style directive improves the performance of the application, since dynamic styles need some
processing time. Dynamic styles design items by their position in screens, see section “Dynamic
Styles” on page 107.
Styles can be set for all items-constructors and for many methods:
86
The World of Preprocessing
When in the above example the J2ME Polish GUI is not used (and thus the symbol
polish.usePolishGui is not defined), the file will not be included into the application bundle for the
current device. Conditions can use the same operators and comparators like the #if directive.
87
The World of Preprocessing
IIw$2(f+"7$,P%!03(uu(q!/5$7B=B"7S/$%31.FG1%37(yy(!/5$7B=:/071N0!!/.31#r
IIw#12$%1(3:!=,/:!51LP%!03
IIw1%#$2
You can later just check the temporary defined symbol:
IIw$2#12(3:!=,/:!51LP%!03
#/N/:13B$%&6/:!51Lqr*
IIw1%#$2
Directive Explanation
//#define [symbol] Defines the specified symbol. You can never define the symbol “false”.
//#undefine [symbol] Removes the specified symbol from the pool of defined symbols. You can
never undefine the symbol “true”.
Please note that you should rely on a defined or undefined symbol only in the same source-file
where you defined or undefined that symbol. It is advised that you start the names of defined
symbols with “tmp.”, so that you always know that this is a temporary symbol.
You can temporarily define and undefine variables with the #define as well. When the expression
after the #define directive contains the equals-sign, the left part will be taken as the variable name,
and the right part as the variable value:
IIw$2(f:177"&1'#12$%1#
IIw#12$%1(:177"&1(@([155/(C/.5#
IIw1%#$2
You can later just use the defined variable normally:
IIw@(N3.$%&(:177"&1(@(zij(:177"&1(;p*
Directive Explanation
//#define Defines the specified variable with the given value.
[name]=[value]
//#undefine [name] Removes the specified variable.
Within the file-name you can use all defined variables. A useful variable is especially
“polish.source”, which points the base directory of the file, which is currently preprocessed. I you
use only relative names, please bear in mind, that the base directory is the root of your project (or to
be more precise: the directory which contains the build.xml file).
88
The World of Preprocessing
Within each message any variables can be used. If a variable is not defined, the variable-definition
will be included in the message.
IIw:177"&1(07$%&(3B1(0!#"3140.5(ij0!#"3140.5;=
The above example results in the message “MESSAGE: using the update-url
http://update.company.com.” being given out, when the variable “update-url” has the value
“http://update.company.com”. When this variable is not defined, the message “MESSAGE: using
the update-url ${update-url}.” will be printed out instead.
The #todo directive works very similar like the #message directive, but it adds the name of the
source-code and the line in which the #todo-directive is embedded before the actual message (e.g.
“TODO: MyMidlet line 12: Implement pauseApp()”).
You can use any number and any kind of code and preprocessing directives within the #foreach-loop
itself. So you can even use nested #foreach loops, for example. The code-fragment within the
#foreach-loop will be copied into the preprocessed source-code as many time as there are values. In
the above example it would be copied three times, since in the example three formats are supported.
This copying process has two implications:
1. Any variables should be defined outside of the loop (but they can be set and used within the
loop, of course), and
89
The World of Preprocessing
2. When the application is debugged or compiled, breakpoints or errors can point to the wrong
source-code lines.
If you keep these implications in mind you have another powerful directive at your hand.
Useful Symbols
When the device supports the MIDP/2.0 platform, the symbol “4'1,8K3-,*4H” is defined,
otherwise the symbol “4'1,8K3-,*4Y”.
When a device supports the CLDC/1.0 standard, the symbol “4'1,8K3#1*#Y3[” is defined. When
the CLDC/1.0 standard is supported, the symbol “4'1,8K3#1*#Y3Y” is defined instead.
Useful Variables
Please refer to the section “Capabilities” on page 26 for standard preprocessing variables.
Other variables include:
! 4'1,8K3"),-"9,'):)9.&W"1 defines the interval in milliseconds for animations. This defaults
to 100 ms, but you can change this value within the <variables> element of the <build>-section.
! 4'1,8K3#1"88.83R(118#&..) defines the name of the fullscreen-class, when the device
supports such a class. For devices which support the Nokia UI API this variable contains
“com.nokia.mid.ui.FullCanvas”. Following example illustrates the usage:
#17%&D(27'/.2D/(D%2''(U86"%G"7(
IIw$2(!/5$7B=071Q055N,.11%(uu(!/5$7B=,5"7717=20557,.11%'#12$%1#
90
The World of Preprocessing
IIw#12$%1(3:!=2055N,.11%
IIw@(1L31%#7(ij!/5$7B=,5"7717=20557,.11%;
IIw1571
+H/+>3'(6"%G"7
IIw1%#$2
! 4'1,8K3q.)*'& defines the vendor of the current device, e.g. “Siemens” or “Nokia”:
IIw$2(!/5$7B=s1%#/.(@@(J/-$"
File Operations
The variable 4'1,8K38'(&#. points the current source directory. This is useful for //#include
directives.
91
The J2ME Polish GUI
92
The J2ME Polish GUI
!(,1*3?-1 file. J2ME Polish will then weave the necessary code automatically into the application.
The attribute accepts the values “yes”/”true”, “no”/”false” and “always”. When “true” or “yes” is
given, the GUI will be used, unless a target-device has not the recommended capabilities (i.e. a
maximum JAR size above 100kb and at least a color-depth of 8 bits per color). For such devices the
normal MIDP-GUI is then used. When the attribute is set to “always”, the GUI will be used for all
target-devices, even when they do not have the recommended capabilities.
The following example activates the GUI for most devices:
?+0$5#
071S/5$7B`0$@A3.01A
<===>
Alternatively you can enable the J2ME Polish GUI by defining the preprocessing variable
“polish.usePolishGui”. This is useful if the GUI should be activated for selected devices only. The
following example activated the GUI only for Nokia/Series 60 devices:
?+0$5#
78:+/57@A7B/CN!5"7B^(a%/3B1.FL":!51N8:+/5A
20557,.11%@A:1%0A
071S/5$7B`0$@A2"571A
H
?f44(",3$G"31(3B1(`OP(2/.(J/-$"IN1.$17(#1G$,17((44H
?G".$"+517H
?G".$"+51( %":1@A!/5$7B=071S/5$7B`0$A(
(((( G"501@A3.01A(
$2@A!/5$7B=&./0!=N1.$17TKA(IH
?IG".$"+517H
<===>
?I+0$5#H
93
The J2ME Polish GUI
Fig. 1: The "menu" and the normal fullscreen-mode on the Siemens CX65
Some MIDP/2.0 devices do not support the “menu” mode, since they do not forward key-events
when a soft-key is pressed. J2ME Polish determines whether a device supports the “menu” mode by
evaluating the device database. When the “K"87'--")*x.<IW.)98”-feature is set, the device
supports the pure MIDP/2.0 “menu” mode. Additionally the capabilities “$.<3=.R9D'R9x.<” and
“$.<3^,%K9D'R9x.<” can be set to define the key-codes for the soft-keys (these are the values,
which are reported to the “$.<J&.88.*”-method of a 7")W"8). When no keys are defined, the value
“-6” is assumed for the left soft key, and the value “-7” for the right soft key.
U*.W,#.
008(44'&98J'1,8K`(,FE9&(.ET
00U,*.)9,R,.&TD,.-.)8Z7ldhUZ,*.)9,R,.&T
004J)'+"/)(80'(=2;;',-D):I3),+(46J)'+"/)(8
00U#"4"!,1,9<0)"-.FED#&..)D,i.E0W"1(.FEYaH?YydEZT
00U#"4"!,1,9<0)"-.FE$.<3=.R9D'R9x.<E0W"1(.FE+YE0ZT
00U#"4"!,1,9<0)"-.FE$.<3^,%K9D'R9x.<E0W"1(.FE+bE0ZT
UZ*.W,#.T
94
The J2ME Polish GUI
95
The J2ME Polish GUI
96
The J2ME Polish GUI
the MIDP-standard, neither import-statements nor the actual code needs to be changed.
Setting Styles
You should use the n89<1.-preprocessing-directive for applying the desired design-styles. This
directive can be used in front of any Item-constructor and before some other methods:
Insertion Point Example Explanation
Item constructors IIw73851(,//5^(2./738^(#12"053 The #style directive can be
N3.$%&P31:(0.5(@(%1C(N3.$%&P31:q(
%055^(AB33!'IIVtZ=VT_=VKV=VKVA(r*
placed before any item
IIw73851(,//5 constructor.
P:"&1P31:($:&(@(%1C(P:"&1P31:q(
%055^($,/%P:"&1^(
P:"&1P31:=DaoEOYvMFQaODY^(%055(r*
Item. IIw73851(/!1%D$%- The #style directive can be
0.5=713a!!1"."%,1U/#1q(
setAppearanceMode P31:=[oSF]DPJe(r* placed before calling the
() setAppearanceMode-method of
an Item. Please note, that this
method is only available in
J2ME Polish.
List.append() IIw73851(,B/$,1 The #style directive can be
5$73="!!1%#q(AN3".3A^(%055((r*
placed before adding a list
element.
List.insert() IIw73851(,B/$,1 The #style directive can be
5$73=$%71.3q(Z^(AN3".3A^(%055((r*
placed before inserting a list
element.
List.set() IIw73851(,B/$,1 The #style directive can be
5$73=713q(Z^(AN3".3A^(%055((r*
placed before setting a list
element.
ChoiceGroup.appen IIw73851(,B/$,1 The #style directive can be
&./0!="!!1%#q(A6B/$,1(VA^(%055((r*
d() placed before adding an
element to a ChoiceGroup.
ChoiceGroup.insert( IIw73851(,B/$,1 The #style directive can be
&./0!=$%71.3q(Z^(A6B/$,1(XA^(%055(
) r*
placed before inserting an
element to a ChoiceGroup.
ChoiceGroup.set() IIw73851(,B/$,1 The #style directive can be
&./0!=713q(Z^(A6B/$,1(XA^(%055((r*
placed before setting an element
of a ChoiceGroup.
Form constructor IIw73851(:"$%N,.11% Use the #style directive before
Q/.:(2/.:(@(%1C(Q/.:q(AU1%0A(r*
a Form-constructor or before
II($%(70+,5"7717(/2(Q/.:' calling super() in subclass-
IIw73851(:"$%N,.11% constructors.
70!1.q(AU1%0A(r*
97
The J2ME Polish GUI
The following example uses the “.mainMenu”-style for the design of the form:
,-4'&90S"W"?3-,#&'.*,9,')31#*(,3g'&-6
4(!1,#0#1"880A",)A.)(0.?9.)*80g'&-0C
4(!1,#0A",)A.)(20D9&,)%09,91.050C
ZZn89<1.0-",)A.)(
8(4.&209,91.056
333
O
O
You can also use several style-names in a n89<1.-directive. In this case the first found directive is
used:
,-4'&90S"W"?3-,#&'.*,9,')31#*(,3g'&-6
4(!1,#0#1"880A",)A.)(0.?9.)*80g'&-0C
4(!1,#0A",)A.)(20D9&,)%09,91.050C
ZZn89<1.0-",)A.)(L08#&..)
8(4.&209,91.056
333
O
O
When none of the provided style-definitions is found, the build will report this error and abort the
processing.
98
The J2ME Polish GUI
predefined styles.
Please have a look at the chapter “Using Custom Items” on page 161 for more information on
custom items.
99
The J2ME Polish GUI
4"#$"%.0*.3.)'(%K34'1,8K3*.-'6
,-4'&90S"W"?3-,#&'.*,9,')31#*(,37K',#.6
,-4'&90S"W"?3-,#&'.*,9,')31#*(,37K',#.`&'(46
,-4'&90S"W"?3-,#&'.*,9,')31#*(,37'--")*6
,-4'&90S"W"?3-,#&'.*,9,')31#*(,3B"9.g,.1*6
,-4'&90S"W"?3-,#&'.*,9,')31#*(,3B,841"<6
,-4'&90S"W"?3-,#&'.*,9,')31#*(,3D9&,)%:9.-6
,-4'&90S"W"?3-,#&'.*,9,')31#*(,3>.?9g,.1*6
,-4'&90S"W"?3-,#&'.*,9,')31#*(,3:9.-6
,-4'&90S"W"?3-,#&'.*,9,')31#*(,3:9.-D9"9.=,89.).&6
,-4'&90*.3.)'(%K34'1,8K3(,3>"!!.*g'&-6
4(!1,#0#1"880>"!!.*g'&-B.-'0,-41.-.)980:9.-D9"9.=,89.).&0C
4&,W"9.0>.?9g,.1*0)"-.g,.1*6
4(!1,#0>"!!.*g'&-B.-'200B.-'A,*1.90-,*1.9L0B,841"<0*,841"<L07'--")*0
&.9(&)7-*050C
D9&,)%PQ09"!\"-.80F0).V0D9&,)%PQC0E:)4(9EL0E7K',#.EL0E7')).#9,')EL0
E>.89EL0ED.99,)%8EL0E:)9.&).9E0O6
ZZn89<1.09"!!.*D#&..)
>"!!.*g'&-0R'&-0F0).V0>"!!.*g'&-2E>"!!.*B.-'EL09"!\"-.8L0)(11056
ZZn89<1.01"!.1
D9&,)%:9.-01"!.10F0).V0D9&,)%:9.-20)(11L0E)"-./E056
R'&-3"44.)*20[L01"!.1056
ZZn89<1.0,)4(9
9K,83)"-.g,.1*0F0).V0>.?9g,.1*20)(11L0E^'!.&9EL0a[L0>.?9g,.1*3;\|0j0
>.?9g,.1*3:\:>:;=r7;JDrzp^B056
R'&-3"44.)*2[L09K,83)"-.g,.1*56
ZZn89<1.01"!.1
1"!.10F0).V0D9&,)%:9.-20)(11L0E!,&9K*"</E056
R'&-3"44.)*20[L01"!.1056
ZZn89<1.0,)4(9
B"9.g,.1*0!,&9K*"9.0F0).V0B"9.g,.1*20)(11L0B"9.g,.1*3B;>I056
R'&-3"44.)*20[L0!,&9K*"9.056
ZZn89<1.01"!.1
1"!.10F0).V0D9&,)%:9.-2)(11L0EzK"90$,)*0'R0"),-"180*'0<'(01,$./E56
R'&-3"44.)*20YL01"!.1056
ZZn89<1.0-(19,41.7K',#.
7K',#.`&'(40#K',#.0F0).V07K',#.`&'(420)(11L07K',#.3A@=>:J=I056
ZZn89<1.0#K',#.:9.-
#K',#.3"44.)*2E*'%8EL0)(1156
100
The J2ME Polish GUI
ZZn89<1.0#K',#.:9.-
#K',#.3"44.)*2E#"98EL0)(1156
ZZn89<1.0#K',#.:9.-
#K',#.3"44.)*2E!,&*8EL0)(1156
R'&-3"44.)*2YL0#K',#.56
ZZn89<1.01"!.1
1"!.10F0).V0D9&,)%:9.-2)(11L0E7')).#9,')/E56
R'&-3"44.)*20HL01"!.1056
ZZn89<1.0-(19,41.7K',#.
#K',#.0F0).V07K',#.`&'(420)(11L07K',#.3A@=>:J=I056
ZZn89<1.0#K',#.:9.-
#K',#.3"44.)*2E:DB\EL0)(1156
ZZn89<1.0#K',#.:9.-
#K',#.3"44.)*2EBD=EL0)(1156
ZZn89<1.0#K',#.:9.-
#K',#.3"44.)*2E7"!1.EL0)(1156
R'&-3"44.)*2HL0#K',#.56
R'&-3"**7'--")*2&.9(&)7-*56
R'&-38.97'--")*=,89.).&2-,*1.956
R'&-38.9:9.-D9"9.=,89.).&209K,8056
*,841"<38.97(&&.)9:9.-20#K',#.056
O
4(!1,#0W',*0,9.-D9"9.7K")%.*2:9.-0,9.-50C
,R02,9.-0,)89")#.'R0>.?9g,.1*50C
>.?9g,.1*0R,.1*0F02>.?9g,.1*50,9.-6
D<89.-3'(934&,)91)2E:9.-0D9"9.07K")%.*/0E0o0
R,.1*3%.9D9&,)%25056
O0.18.0C
D<89.-3'(934&,)91)2E:9.-0D9"9.07K")%.*/0E0o0,9.-056
O
O
O
101
The J2ME Polish GUI
A Quick Glance
All design settings and files are stored in the “resources” directory of the project, unless another
directory has been specified.7 The most important file is 4'1,8K3#88 in that directory. All design
definitions can be found here. The design definitions are grouped in “styles”. A style can be
assigned to any GUI item like a title, a paragraph or an input field. Within a style several attributes
and its values are defined:
3-<D9<1.0C
R')9+#'1'&/0VK,9.6
R')9+89<1./0!'1*6
R')9+8,i./01"&%.6
R')9+R"#./04&'4'&9,')"16
!"#$%&'()*+#'1'&/0!1"#$6
O
In this example the style called “myStyle” defines some font values and the color of the background.
Any style contains a selector as well as a number of attributes and its values:
03-<D9<1.00 0C0R')9+#'1'&/00VK,9.6 O
Each attribute-value pair needs to be finished with a semicolon. The style declaration needs to be
finished by a closing curved parenthesis. The selector or name of style is case-insensitive, so
“.MySTYle” is the same as “.myStyle”.
Apart from the 4'1,8K3#88 file, you can put images and other contents into the resources-folder.
Sub-folders are used for styles and content for specific devices and groups. You can put all resources
for Nokia devices into the “Nokia” folder and resources for Samsung's E700 into the
“Samsung/E700” folder. This is described in more detail in the “Designing Specific Devices and
Device-Groups” section.
You can specify styles directly for GUI items with the #style preprocessing directive in the source
code. Alternatively you can use the dynamic names of the GUI items, e.g. “p” for text-items, “a” for
hyperlinks or “form p” for all text-items which are embedded in a form. The possible combinations
as well as the predefined style-names are discussed in the section “Dynamic, Static and Predefined
102
The J2ME Polish GUI
Styles”.
Styles can extend other styles with the extends-keyword, e.g. “.myStyle extends baseStyle {}”. This
process is described in the section “Extending Styles”.
J2ME Polish supports the CSS box model with margins, paddings and content. Other common
design settings include the background, the border and font-settings. These common settings are
described in the section “Common Design Attributes”. Attributes for specific GUI items as well as
the details of the different background and border types are discussed in the section “Specific
Design Attributes”.
103
The J2ME Polish GUI
Groups
Every device can have explicit and implicit groups. Explicit groups are stated by the <groups>
element of the device in the file devices.xml8. Implicit groups are defined by the capabilities of the
device: Each supported API results in an implicit group and the BitsPerPixel capability results in
several groups.
BitsPerPixel-Groups
Every device display has a specific color depth which is specified by the BitsPerPixel-capability of
that device in the devices.xml file. Depending on how many bits per pixel are supported, the device
8 devices.xml can either be found in the root folder of the project or in the import/enough-j2mepolish-build.jar file.
104
The J2ME Polish GUI
So you can put images for phones with at least 16 colors into the “resources/BitsPerPixel.4+” folder.
And you can specify settings for true color devices in the file
“resources/BitsPerPixel.24/polish.css”.
105
The J2ME Polish GUI
! Dynamic styles are used for items according to their position on the screen.
Static Styles
The easiest styles are the static ones. The programmer just needs to tell the designer the style names
and what they are used for (that is for what kind of items or screens) and the designer defines them
in the appropriate polish.css file. Static styles always start with a dot, e.g. “.myStyle”.
Static styles are faster than dynamic styles. It is therefore recommended to use static styles whenever
possible.
Predefined Styles
Predefined styles are static styles which are used by the J2ME Polish GUI. In contrast to the normal
“user-defined” static styles their names do not start with a dot, e.g. “title” instead of “.title”.
Following predefined styles are used:
Style Description
title The style of screen-titles. For MIDP/2.0 devices the native
implementation is used by default, unless the preprocessing variable
“polish.usePolishTitle” is defined with “true”:
UW"&,"!1.0)"-.FE4'1,8K3(8.J'1,8K>,91.E0W"1(.FE9&(.E0
()1.88FE4'1,8K3q.)*'&0FF0\'$,"E0ZT
You can also use custom styles for specific Screens or ChoiceGroups by
using the “title-style”-attribute (compare page 131).
focused The style of a currently focused item. This style is used in Lists, Forms
and for Containers like the ChoiceGroup. You can also use custom
styles for specific Screens or ChoiceGroups by using the “focused-
style”-attribute (compare page 131).
menu This style is used for designing the menu bar in the full screen mode.
The full screen mode can be triggered by the “fullScreenMode” attribute
of the <build> element in the build.xml (with
fullScreenMode=”menu”). In the menu style you can also define which
style is used for the currently focused command with the “focused-
style”-attribute, e.g. “focused-style: menuFocused;”. In this case you
need to define the static style “.menuFocused” as well.
menuItem The style used for the menu items (the commands) of a screen. When
menuItem is not defined, the “menu” style is used instead.
label This style is used for the menu the label of any item. One can specify
another label-style by defining the CSS-attribute “label-style” in the
appropriate style, which refers to another style.
info The style that is used for displaying additional information in a screen.
Currently this is only used for showing the current input mode when the
“direct input mode” of a TextField or a TextBox is enabled. Compare
106
The J2ME Polish GUI
Style Description
page 142 for more information.
default The style which is used by the J2ME Polish GUI when the desired
predefined style is not defined. The default style is always defined, even
when it is not explicitly defined in the polish.css file.
tabbar This style designs the tab-bar of a TabbedForm.
activetab Designs the currently active tab of a TabbedForm.
Inactivetab Designs all tabs but the currently selected one of a TabbedForm.
The names of predefined styles must not be used for static styles, so you must not use a static style
with the name “.title” etc.
Dynamic Styles
Dynamic styles can be used to apply styles to items without using #style directives in the source
code. With dynamic styles the designer can work completely independent of the programmer and
try out new designs for GUI items which have not yet an associated static style. You can also check
out the power and possibilities of the J2ME Polish API without changing the source code of an
existing application at all.
Obviously, dynamic styles need a bit more memory and processing time than static styles. It is
recommended, therefore, to use static styles instead for finished applications.
Dynamic styles do not start with a dot and use the selectors of the items they want to design:
Texts use either “p”, “a”, “button” or “icon”. Screens use the name of the screen, e.g. “form”, “list”
or “textbox”.
40C
R')9+#'1'&/0!1"#$6
R')9+8,i./0-.*,(-6
!"#$%&'()*/0)').6
O
R'&-0C
-"&%,)/0h6
!"#$%&'()*+#'1'&/0%&"<6
!'&*.&/0)').6
R')9+8,i./0-.*,(-6
O
You can also design only items which are contained in other items or screens:
The style “form p” designs all text-items (of the class StringItem) which are contained in a form:
R'&-040C
R')9+#'1'&/0VK,9.6
R')9+8,i./0-.*,(-6
O
Static styles and dynamic styles can be used together, you can design all hyperlinks9 in the screen
9 StringItems which have the appearance mode Item.HYPERLINK
107
The J2ME Polish GUI
with the style “.startScreen” for example with the following style declaration:
389"&9D#&..)0"0C
R')9+#'1'&/0!1(.6
R')9+8,i./0-.*,(-6
R')9+89<1./0,9"1,#6
O
108
The J2ME Polish GUI
Extending Styles
A style can extend another style. It inherits all the attributes of the extended style. With this
mechanism a lot of writing work can be saved:
3-",)D#&..)0C
-"&%,)/0Y[6
R')9+#'1'&/0!1"#$6
R')9+8,i./0-.*,(-6
R')9+89<1./0,9"1,#6
!"#$%&'()*+#'1'&/0%&"<6
O
3K,%K8#'&.D#&..)0.?9.)*80-",)D#&..)0C
R')9+#'1'&/0VK,9.6
!"#$%&'()*+#'1'&/0!1"#$6
O
In the above example the style “highscoreScreen” inherits all attributes of the “mainScreen” style,
but “font-color” and “background-color” are specified differently.
Circle inheritance is not allowed, so the following example results in a build error:
3!"8.D#&..)0.?9.)*80K,%K8#'&.D#&..)0C00Zm09K,80.?9.)*80,80,)W"1,*v0mZ
-"&%,)/0h6
R')9+#'1'&/0VK,9.6
O
3-",)D#&..)0.?9.)*80!"8.D#&..)0C
-"&%,)/0Y[6
R')9+#'1'&/0!1"#$6
R')9+8,i./0-.*,(-6
R')9+89<1./0,9"1,#6
!"#$%&'()*+#'1'&/0%&"<6
O
3K,%K8#'&.D#&..)0.?9.)*80-",)D#&..)0C
R')9+#'1'&/0VK,9.6
!"#$%&'()*+#'1'&/0!1"#$6
O
The above example would be valid, when the style “baseScreen” would not extend the
“highscoreScreen”-style.
CSS Syntax
Following rules do apply for CSS styles:
03-<D9<1.00 0C0R')9+#'1'&/00VK,9.6 O
Every style starts with the selector followed by an opening curved parenthesis, a number of
attribute-value pairs and a closing curved parenthesis.
The selector can consist of several item-names and contain an “extends” clause.
109
The J2ME Polish GUI
Naming
Styles can use any names, as long as they consist of alphanumeric and underline (_) characters only.
Names are not case-sensitive. Static styles need to start with a dot. Static styles must not use the
names of dynamic or predefined styles. All Java keywords like “class”, “int” or “boolean” etcetera
are not allowed as style names.
Grouping of Attributes
Attributes can be grouped for easier handling:
3-",)D#&..)0C
R')9+#'1'&/0!1"#$6
R')9+8,i./0-.*,(-6
R')9+89<1./0,9"1,#6
R')9+R"#./08<89.-6
O
The above code is equivalent with the following:
3-",)D#&..)0C
R')90C
#'1'&/0!1"#$6
8,i./0-.*,(-6
89<1./0,9"1,#6
R"#./08<89.-6
O
O
Comments
Comments can be inserted at any place and start with “/*” and stop with “*/”. Everything between
these boundaries is ignored:
Zm09K,8089<1.0*.8,%)809K.0-",)08#&..)/0mZ
3-",)D#&..)0C
Zm0*.R,),)%09K.0#'1'&0'R0"0R')9/0mZ
R')9+#'1'&/0!1"#$6
Zm08,i.80"&.08-"11L0-.*,(-0")*01"&%./0mZ
R')9+8,i./0-.*,(-6
Zm089<1.80"&.041",)L0!'1*L0,9"1,#0'&0()*.&1,).*/0mZ
R')9+89<1./0,9"1,#6
Zm09K.0R"#.0#")0.,9K.&0!.08<89.-L04&'4'&9,')"10'&0-')'84"#./0mZ
R')9+R"#./08<89.-6
O
110
The J2ME Polish GUI
Structure of polish.css
The polish.css file can contain different sections:
" colors: The colors-section contains the definition of colors.
" fonts: The fonts-section contains font definitions.
" backgrounds: The backgrounds-section contains background definitions.
" borders: The borders-section contains definition of borders.
" rest: The rest of polish.css contains the actual style definitions.
The defined colors, fonts, backgrounds and borders can be referenced in the actual style definitions.
This makes changes very easy, since you need to change the value only in one position.
111
The J2ME Polish GUI
Zm0!.R'&./0"**0")0,-"%./0mZ
!.R'&./0(&120"&&'V34)%056
Zm0"R9.&/0"**0")'9K.&0,-"%./0mZ
"R9.&/0(&1201.R9;&&'V34)%056
Zm0)'084.#,R,#0"99&,!(9.80"&.0(8.*0,)09K,80.?"-41.mZ
O
margin-top
border
padding-top
padding-right
padding-left
margin-right
margin-left
content
padding-bottom
The margin describes the gap to other GUI items. The padding describes the gap between the border
of the item and the actual content of that item. So far no different border-widths (for left, right, top
and bottom) can be set with J2ME Polish. Since this is a more bizarre and seldom used feature, not
much harm is done.
The margin- and padding-attributes define the default gaps for the left, right, top and bottom
elements. Any margin has the default value of 0 pixels, whereas any padding defaults to 1 pixel.
Next to the left, right, top and bottom padding, J2ME Polish also knows the vertical and the
horizontal paddings. These define the gaps between different content sections. The gap between the
label of an item and the actual content is defined by the horizontal padding. Another example is the
icon, which consists of an image and a text. Depending on the align of the image, either the vertical
or the horizontal padding fills the space between the icon-image and the icon-text.
In the following example, the top, right and bottom margin is 5 pixels, whereas the left margin is
10 pixels:
3-<D9<1.0C
-"&%,)/0h6
-"&%,)+1.R9/0Y[6
R')9+#'1'&/0!1"#$6
O
Percentage values can also be used. Percentage values for top, bottom and vertical attributes relate
to the height of the display. Percentage values for left, right and horizontal attributes relate to the
width of the display:
112
The J2ME Polish GUI
3-<D9<1.0C
4"**,)%+1.R9/0Hk6
4"**,)%+&,%K9/0Hk6
4"**,)%+W.&9,#"1/0Yk6
R')9+#'1'&/0!1"#$6
O
When the device has a width of 176 pixels, a padding of 2% results into 3.52 pixels, meaning
effectively a padding of 3 pixels. At a display height of 208 pixels a vertical padding of 1% results
into a padding of 2.08 pixels or effectively 2 pixels. Please note that the capability “ScreenSize” of
the device needs to be defined when you use percentage values.
113
The J2ME Polish GUI
Layout values can also be combined, using either the “||”, “|”, “or“ or “and“ operators. All operators
result in the same combination. An item can be centered and using the whole available width with
following example:
3-<D9<1.0C
1"<'(9/0#.)9.&0j0.?4")*6
O
This is equivalent with:
3-<D9<1.0C
1"<'(9/0#.)9.&0jj0.?4")*6
O
And equivalent with:
3-<D9<1.0C
1"<'(9/0#.)9.&0")*0.?4")*6
O
And equivalent with:
3-<D9<1.0C
1"<'(9/0#.)9.&0'&0.?4")*6
O
And equivalent with:
3-<D9<1.0C
1"<'(9/0K#.)9.&0j0K.?4")*6
O
And equivalent with:
3-<D9<1.0C
1"<'(9/0K'&,i')9"1+#.)9.&0j0K'&,i')9"1+.?4")*6
O
Colors
Colors can be defined in the colors section and in each attribute which ends on “-color”, e.g. “font-
color”, “border-color” etc.
Predefined Colors
114
The J2ME Polish GUI
Another predefined color is “transparent”, which results in an transparent area. “transparent” is only
supported by some GUI elements like the menu-bar of a full-screen menu.
The colors section of the polish.css file can contain colors, which can be referenced in the styles,
fonts, border and background sections. You can even overwrite the predefined colors to confuse
other designers!
#'1'&80C
!%7'1'&/0nh[7y7y6
!%7'1'&=,%K9/0nh[BcBc6
%&"</0nygygyg6
O
Color names refer to one of the predefined colors or a color which has been defined in the colors-
section:
#'1'&/0!1"#$6 or #'1'&/0*"&$e"#$%&'()*7'1'&6
The hex-value defines a color with two hexadecimal digits for each color (RRGGBB). Additionally
the alpha blending-component can be added (AARRGGBB).
#'1'&/0ngg[[[6 defines red. color: nyggg[[[[6 defines a half transparent red.
The shortened hex-value defines a color by a RGB-value in hexadecimal. Every digit will be
doubled to retrieve the full hex-value:
#'1'&/0ng[[6 is equivalent with #'1'&/0ngg[[[[6
#'1'&/0n[BH6 is equivalent with #'1'&/0n[[BBHH6 and so on.
115
The J2ME Polish GUI
A rgb-value starts with “rgb(“ and then lists the decimal value of each color from 0 up to 255:
#'1'&/0&%!20HhhL0[L0[056 defines red. #'1'&/0&!%20[L0[L0Hhh56 defines blue and so on.
Alpha Blending
Colors with alpha blending can be defined with hexadecimal or argb-definitions (see above). An
alpha value of 0 results in fully transparent pixels, whereas the value FF (or 255 or 100%) results in
fully opaque pixels. Some devices support values between 0 and FF, which results in transparent
colors. Colors with a specified alpha channel can only be used by specific GUI items. Please refer to
the documentation of the specific design attributes.
Fonts
Many GUI-Items have text elements, which can be designed with the font-attributes:
116
The J2ME Polish GUI
Bitmap-Fonts
Bitmap-Fonts can be used instead of the usual predefined fonts for any text elements like titles,
StringItems, etc.
Creating Bitmap-Fonts
Bitmap-Fonts can be created out of any True Type Fonts (*.ttf) using the
]C4'1,8K3K'-.OZ!,)ZR')9.*,9'& executable. In some cases it might be beneficial to optimize the
created PNG image manually for decreasing the size of the image and making manual adjustments.
The created bitmap-fonts-files (*.bmf) can also be fine-tuned using the binary data editor
]C4'1,8K3K'-.OZ!,)Z!,)"&<*"9".*,9'&. Just select the File -> “open in binary
editor”-command.
The created bitmap-font needs to be copied into the “resources” folder of the project.
The created bitmap-fonts can be used for any text-based items in the J2ME Polish GUI. They can be
integrated using the “font-bitmap”-attribute. The “.bmf” extension does not need to be given. In the
following example the “china.bmf” font is used for the currently focused item:
R'#(8.*0C
R')9+!,9-"4/0#K,)"6
!"#$%&'()*+#'1'&/0<.11'V6
117
The J2ME Polish GUI
1"<'(9/0#.)9.&0j0.?4")*6
O
The bitmap-fonts can also be used directly in the program-code with the help of the
*.3.)'(%K34'1,8K3(9,13e,9A"4g')9 class. Please compare the JavaDoc documentation for more
information.
This example uses a bitmap-font for displaying a text:
%;!2/+.-)K),2"70K!2$%(0K"+%$KLM
4(!1,#0#1"880A<D#&..)0.?9.)*807")W"80C
!/%3'+).N%+E'!O2,+.#%+E'!O2,+.P.N%+E'!O2,+K7)+Q,(+',&)R.S6&0%,'K#;JT.UM
!/%3'+).N%+E'!O2,+V%)1)/.+)*+V%)1)/M
4(!1,#0A<D#&..)2509K&'V80:pI?#.49,')0C
+0%(K+)*+V%)1)/.P.+0%(K#%+E'!O2,+K7)+V%)1)/R.SW)$$2.X2/$-YT.UM
333
O
333
4(!1,#0W',*04",)920`&"4K,#80%050C
,)90?0F0H[6
,)90<0F0h[6
+0%(K3%)1)/K!'%,+R.*Z.:Z.7.UM
O
O
Labels
All GUI-Items can have a label, which is designed using the pre-defined style “label”. One can
specify another-style by using the “label-style”-attribute:
3-<D9<1.0C
R')90C
#'1'&/0VK,9.6
89<1./0!'1*6
O
1"!.1+89<1./0-<="!.1D9<1.6
O
3-<="!.1D9<1.0C
R')9+89<1./0!'1*6
R')9+#'1'&/0%&..)6
!"#$%&'()*+#'1'&/0<.11'V6
O
It is often advisable to use separate items for labels and contents. In that way you can get a clean
design by using a table, in which all labels are placed on the left side and all input-fields etc on the
right side. Tables are defined by using the “#'1(-)8”-attribute of the corresponding screen,
compare the Screens-description on page 131.
When you want to have a line-break after each label, just add the “newline-after”-value to the
layout:
1"!.10C
R')9+89<1./0!'1*6
R')9+#'1'&/0%&..)6
!"#$%&'()*/0)').6
118
The J2ME Polish GUI
1"<'(9/01.R90j0).V1,).+"R9.&6
O
If more complex types should be used, the background- or border-type needs to be specified
explicitly. The following example illustrates this for an background, which colors change all the
time:
The available background- and border-types are explained in detail in the section “Specific Design
Attributes”.
119
The J2ME Polish GUI
"R9.&/0(&120K."&934)%056
!"#$%&'()*/0)').6
!'&*.&+9<4./0&'()*+&.#96
!'&*.&+"&#/0d6
!'&*.&+#'1'&/0<.11'V6
!'&*.&+V,*9K/0H6
1"<'(9/01.R90j0.?4")*6
R')9+#'1'&/0!1"#$6
O
Simple Background
The simple background just fills the background with one color. When no background type is
specified, the simple background is used by default, unless the “background-image” attribute is set.
In the later case the image background will be used.
The simple background supports the color attribute:
Round-Rect Background
The round-rect background paints a rectangular background with round edges. It supports following
attributes:
120
The J2ME Polish GUI
Image Background
The image background uses an image for painting the background. This background type is used by
default when no type is set and the “background-image” attribute is set. The background supports
following attributes:
121
The J2ME Polish GUI
Circle Background
The circle background paints a circular or elliptical background. It supports following attributes:
Attribute Required Explanation
type Yes The type needs to be “circle”.
color No The color of the background, either the name of the color or a direct
definition. Defaults to “white”.
diameter No With the “diameter” attribute it can be ensured that always a circle and
never an ellipse is painted. The diameter then defines the diameter of the
circle.
The following example uses a green circle background with a diameter of 20 pixels:
3-<D9<1.0C
!"#$%&'()*+9<4./0#,.6
!"#$%&'()*+#'1'&/0%&..)6
!"#$%&'()*+*,"-.9.&/0H[6
O
122
The J2ME Polish GUI
Pulsating Background
The pulsating background animates the color of the background. The color is changing from a start-
color to an end-color. It supports following attributes:
The following style starts with a white background and stops with a yellow background:
3-<D9<1.0C
!"#$%&'()*0C
9<4./04(18"9,)%6
89"&9+#'1'&/0VK,9.6
.)*+#'1'&/0<.11'V6
89.48/0Yh6
&.4."9/0R"18.6
!"#$+")*+R'&9K/0R"18.6
O
O
The pulsating circle background paints a circular or background which size constantly increases and
decreases. It supports following attributes:
Attribute Required Explanation
type Yes The type needs to be “pulsating-circle”.
color No The color of the background, either the name of the color or a direct
definition. Defaults to “white”.
min- Yes The minimum diameter of the circle.
diameter
max- Yes The maximum diameter of the circle.
diameter
123
The J2ME Polish GUI
The following example uses a green pulsating circle background with a minimum diameter of 20
pixels and a maximum diameter of 40 pixels:
3-<D9<1.0C
!"#$%&'()*+9<4./04(18"9,)%+#,.6
!"#$%&'()*+#'1'&/0%&..)6
!"#$%&'()*+-,)+*,"-.9.&/0H[6
!"#$%&'()*+-"?+*,"-.9.&/0b[6
O
The following example uses the pulsating circles background with a dark and with a bright color:
3-<D9<1.0C
+",-&./0%#(j
38!1'(!057"3$%&4,$.,517*
2$.734,/5/.'(+&6/5/.*
71,/%#4,/5/.'(+.$&B3\&6/5/.*
:$%4#$":131.'(K*
:"L4#$":131.'(XKK*
,$.,5174%0:+1.'(_*
731!'(Z=)*
;
O
Opening Background
The opening background paints an animated background which height starts small and then
increases whenever it changes the position. Its primary use is for the “focused”-style. It supports
following attributes:
124
The J2ME Polish GUI
Opening-Round-Rect Background
The opening round rectangle background paints an animated background which height starts small
and then increases whenever it changes the position. Its primary use is for the “focused”-style. It
supports following attributes:
125
The J2ME Polish GUI
Round-Tab Background
The round-tab background paints a rectangular background where the top edges are rounded. It
supports following attributes:
Attribute Required Explanation
type Yes The type needs to be “round-tab”
color No The color of the background, either the name of the color or a direct
definition. The default color is white.
arc No The diameter of the arc at the four corners. Defaults to 10 pixels, when
none is specified.
arc-width No The horizontal diameter of the arc at the four corners. Defaults to the arc-
value, when none is specified.
arc-height No The vertical diameter of the arc at the four corners. Defaults to the arc-
value, when none is specified.
Smooth-Color Background
The smooth-color background paints an gradient background. It supports following attributes:
126
The J2ME Polish GUI
The color of the background, either the name of the color or a direct
color Yes
definition.
gradient- The color for the gradient, either the name of the color or a direct
Yes
color definition.
stroke No The default value is 0.For effects set stroke 1.
This example creates a red background with an gradient to yellow:
3-<D9<1.0C
00000000!"#$%&'()*0C
00000000000000009<4./08-''9K+#'1'&6
0000000000000000#'1'&/0&.*6
0000000000000000%&"*,.)9+#'1'&/0<.11'V6
0000000000000000
00000000O
O
Tiger-Stripes Background
The tiger-stripes background paints an background with randomized numbers of Stripes. It supports
following attributes:
Ball-Games Background
The ball-games background paints an animated background with an number of sprites which
moving through the background. It supports following attributes:
127
The J2ME Polish GUI
0000000000000000
00000000O
O
Borders
There are many different border-types which make use of specific CSS attributes. When another
border than the default simple border should be used, the border-type attribute needs to be declared.
When no border at all should be used, the !'&*.&/0)').6 declaration can be used.
Simple Border
The simple border paints a rectangle border in one color. The type attribute does not need to be set
for the simple border, since this is the default border. The only supported attributes are the color and
the width of the border:
Attribute Required Explanation
color Yes The color of the border, either the name of the color or a direct
definition.
width No The width of the border in pixels. Defaults to 1.
128
The J2ME Polish GUI
Round-Rect Border
The round-rect border paints a rectangular border with round edges. It supports following attributes:
Attribute Required Explanation
type Yes The type needs to be “round-rect” or “roundrect”.
color Yes The color of the border, either the name of the color or a direct
definition.
width No The width of the border in pixels. Defaults to 1.
arc No The diameter of the arc at the four corners. Defaults to 10 pixels, when
none is specified.
arc-width No The horizontal diameter of the arc at the four corners. Defaults to the arc-
value, when none is specified.
arc-height No The vertical diameter of the arc at the four corners. Defaults to the arc-
value, when none is specified.
This example creates a 2 pixels wide purple border with an arc diameter of 6 pixels:
3-<D9<1.0C
!'&*.&0C
9<4./0&'()*+&.#96
#'1'&/04(&41.6
V,*9K/0H6
"&#/0d6
O
O
Shadow Border
The shadow border paints a shadowy border. Following attributes are supported:
129
The J2ME Polish GUI
Currently only a “bottom-right-shadow” is supported, so the border is painted below the item and
right of the item.
The following example uses a green shadow border:
3-<D9<1.0C
!'&*.&+9<4./08K"*'V6
!'&*.&+#'1'&/0%&..)6
!'&*.&+V,*9K/0H6
!'&*.&+'RR8.9/0H6
O
These border paints a simple border on one side the corresponding item. Following attributes are
supported:
Attribute Required Explanation
type Yes The type needs to be “top”, “bottom”, “left” or “right”.
color Yes The color of the border, either the name of the color or a direct
definition.
width No The width of the border in pixels. Defaults to 1.
The following example uses a green border on the bottom of the title:
9,91.0C
!'&*.&+9<4./0!'99'-6
!'&*.&+#'1'&/0%&..)6
!'&*.&+V,*9K/0H6
O
Circle Border
The circle border paints a round or elliptical border and supports following attributes:
130
The J2ME Polish GUI
The following example uses a green circle border with a two pixel wide dotted line:
3-<D9<1.0C
!'&*.&+9<4./0#,.6
!'&*.&+#'1'&/0%&..)6
!'&*.&+V,*9K/0H6
!'&*.&+89&'$.+89<1./0*'99.*6
O
All screens have a title and one or several embedded GUI items. In a Form or List one item is
usually focused. Screens can also have a designable menu, when the application uses a full-screen-
mode10. Some of the used styles can also use additional attributes.
Style-Name Add. Attributes Explanation
title - The title of a screen.
focused - The style of the currently focused item in the screen.
menu The style of the full-screen menu.
focused-style The name of the style for the currently focused menu item.
menubar-color The background color of the menu-bar. Either the name or
the definition of a color or “transparent”. Defaults to
“white”.
label-color, label- The font of the menu-commands (like “Select” or
face, label-size, “Cancel”). Default color is “black”, default font is the
label-style system font in a bold style and medium size.
menuItem - The style for the commands in the menu. When not
defined, the menu-style will be used.
Please refer to page 145 for more information about designing the menu bar.
10 The fullscreen-mode can be activated by setting the <build> attribute “fullscreen” to either “menu” or “yes” in the
build.xml file.
131
The J2ME Polish GUI
132
The J2ME Polish GUI
TextBoxes also support a direct input mode and all CSS-attributes of the
text-field, please compare the discussion on page 142 for more
information.
Fig. 5: Using columns instead
Dynamic Styles for Screens of a normal list.
Dynamic styles can be used when no styles are explicitly set in the application code (compare page
107).
[%(+
A list uses the dynamic selector “list” and always contains choice-items. The selector of these items
depends on the type of the list. An implicit list contains a “listitem”, a multiple list contains a
“checkbox” and an exclusive list contains a “radiobox”.
1,890C
!"#$%&'()*+#'1'&/04,)$6
O
defines the background color for screens of the type “List”.
1,89,9.-0C0Zm0<'(0#'(1*0"18'0(8.0u1,8901,89,9.-t0mZ
R')9+89<1./0!'1*6
O
defines the font style for the items in an implicit list.
O2/;
A form uses the dynamic selector “form” and can contain different GUI items.
R'&-0C
!"#$%&'()*+#'1'&/04,)$6
O
defines the background color for screens of the type “Form”.
R'&-040C
R')9+89<1./0!'1*6
O
defines the font style for normal text items in a “Form”.
?)*+N2*
A TextBox uses the dynamic selector “textbox” and contains a single “textfield” item.
Commands
A multiple List or ChoiceGroup adds the commands “Mark” and “Unmark” by default to the menu.
133
The J2ME Polish GUI
The names of the commands can be changed easily, compare page 76. If you want to suppress the
commands completely, the “polish.ChoiceGroup.suppressMarkCommands”-variable has to be set:
UW"&,"!1.0)"-.FE4'1,8K37K',#.`&'(438(44&.88A"&$7'--")*8E0W"1(.FE9&(.EZT
The same holds true for the “Select” command in implicit and popup Lists and ChoiceGroups:
UW"&,"!1.0)"-.FE4'1,8K37K',#.`&'(438(44&.88D.1.#97'--")*E0W"1(.FE9&(.EZT
A TextBox or TextField adds the “Clear”- and “Delete”-commands to the menu by default. The
names of these commands can be changed easily, compare page 76. If you want to suppress the
commands completely, the “polish.TextField.suppressCommands”-variable has to be set:
UW"&,"!1.0)"-.FE4'1,8K3>.?9g,.1*38(44&.887'--")*8E0W"1(.FE9&(.EZT
Example
The following example designs the main menu of an application, which is implemented using a List.
#'1'&80C
4,)$/00&%!2HbfLacLYfd56
*"&$4,)$/00&%!2YfhLHdLYaf56
O
-.)(0C
-"&%,)+1.R9/0H6
4"**,)%/0H6
!"#$%&'()*0C
9<4./0&'()*+&.#96
#'1'&/0VK,9.6
!'&*.&+V,*9K/0H6
!'&*.&+#'1'&/0<.11'V6
O
R'#(8.*+89<1./03-.)(g'#(8.*6
-.)(!"&+#'1'&/09&")84"&.)96
-.)(R')9+#'1'&/0VK,9.6
O
-.)(:9.-0C
-"&%,)+9'4/0H6
4"**,)%/0H6
4"**,)%+1.R9/0h6
R')90C
#'1'&/0!1"#$6
8,i./0-.*,(-6
89<1./0!'1*6
O
1"<'(9/01.R96
O
3-.)(g'#(8.*0.?9.)*803-.)(:9.-0C
!"#$%&'()*+#'1'&/0!1"#$6
R')9+#'1'&/0VK,9.6
1"<'(9/01.R90j0K'&,i')9"1+.?4")*6
"R9.&/0(&12K."&934)%56
O
9,91.0C
134
The J2ME Polish GUI
4"**,)%/0H6
-"&%,)+9'4/0[6
-"&%,)+!'99'-/0h6
-"&%,)+1.R9/0[6
-"&%,)+&,%K9/0[6
R')9+R"#./04&'4'&9,')"16
R')9+8,i./01"&%.6
R')9+89<1./0!'1*6
R')9+#'1'&/0VK,9.6
!"#$%&'()*0C
#'1'&/0*"&$4,)$6
O
!'&*.&/0)').6
1"<'(9/0K'&,i')9"1+#.)9.&0j0K'&,i')9"1+.?4")*6
O
R'#(8.*0C
4"**,)%/0H6
4"**,)%+W.&9,#"1/0a6
4"**,)%+1.R9/0a6
4"**,)%+&,%K9/0a6
4"**,)%+9'4/0Y[6
4"**,)%+!'99'-/0Y[6
!"#$%&'()*+9<4./0&'()*+&.#96
!"#$%&'()*+"&#/0f6
!"#$%&'()*+#'1'&/04,)$6
!'&*.&0C
9<4./0&'()*+&.#96
"&#/0f6
#'1'&/0<.11'V6
V,*9K/0H6
O
R')90C
89<1./0!'1*6
#'1'&/0!1"#$6
8,i./08-"116
O
1"<'(9/0.?4")*0j0#.)9.&6
O
1,890C
4"**,)%+1.R9/0h6
4"**,)%+&,%K9/0h6
4"**,)%+W.&9,#"1/0Y[6
4"**,)%+K'&,i')9"1/0Y[6
!"#$%&'()*0C
#'1'&/04,)$6
,-"%./0(&120K."&934)%056
O
#'1(-)8/0H6
#'1(-)8+V,*9K/0._("16
1"<'(9/0K'&,i')9"1+.?4")*0j0K'&,i')9"1+#.)9.&0j0W.&9,#"1+#.)9.&6
O
1,89,9.-0C
-"&%,)/0H60Zm0R'&09K.0!'&*.&0'R09K.0R'#(8.*089<1.0mZ
4"**,)%/0H6
4"**,)%+W.&9,#"1/0a6
4"**,)%+1.R9/0a6
135
The J2ME Polish GUI
4"**,)%+&,%K9/0a6
4"**,)%+9'4/0Y[6
4"**,)%+!'99'-/0Y[6
!"#$%&'()*/0)').6
R')9+#'1'&/0VK,9.6
R')9+89<1./0!'1*6
R')9+8,i./08-"116
1"<'(9/0#.)9.&6
,#')+,-"%./0(&120k:\BIlk,#')34)%056
,#')+,-"%.+"1,%)/09'46
O
View Types
View-types can be used for animating Forms, Lists, ChoiceGroups or even menus. There are several
view-types available, which are usually defined in a screen-style, e.g.:
3-",)D#&..)0C
4"**,)%+1.R9/0h6
4"**,)%+&,%K9/0h6
3%)1\+:!)].-/2!!%,7M
O
You can use either a (predefined) name of the view-type or the fully qualified class-name of that
type, which needs to extend the *.3.)'(%K34'1,8K3(,37')9",).&q,.V class.
Dropping View
The dropping view shows an animation of dropping and bouncing items. It is activated by
specifying the “dropping” view-type and supports following additional attributes:
3-",)D#&..)0C
4"**,)%+1.R9/0h6
4"**,)%+&,%K9/0h6
3%)1\+:!)].-/2!!%,7M
-/2!!%,73%)1\(!))-].^_M
-/2!!%,73%)1\-';!%,7]._M
-/2!!%,73%)1\;'*!)/%2-)].`M
O
136
The J2ME Polish GUI
Shuffle View
The shuffle view animates the items by moving them from the left and right side into their final
target-position. It is activated by specifying the “shuffle” view-type and supports following
additional attributes:
Attribute Required Explanation
shuffleview-speed No The speed in pixels per animation-step. The default speed is 10.
shuffleview-repeat- No Defines whether the animation should be repeated each time
animation the screen is shown. Possible values are “true” and “false”.
This defaults to “false”.
3-",)D#&..)0C
4"**,)%+1.R9/0h6
4"**,)%+&,%K9/0h6
3%)1\+:!)].(0"JJ$)M
(0"JJ$)3%)1\(!))-].^_M
O
MIDP/2.0 View
The MIDP/2.0 view arranges the items just like the MIDP/2.0 standard encourages it: the items are
all lined up into one row until there is not enough space anymore or until an item with a "newline-
after" or "newline-before" layout is inserted. It is activated by specifying the “midp2” view-type
and supports no additional attributes.
3-",)D#&..)0C
4"**,)%+1.R9/0h6
4"**,)%+&,%K9/0h6
3%)1\+:!)].;%-!`M
O
Depending on the appearance mode11 of the text, either the “p”, the “a” or the “button” selector is
used for dynamic styles:
11 The appearance mode can be set in the application code with Item.setAppearanceMode( int ).
137
The J2ME Polish GUI
See the general explanation of dynamic styles on page 107 for more details.
The IconItem
Icons can only be used directly. Icons support following additional attributes:
When the icon-item has a “right” image align and the layout is set to “horizontal-expand”, the image
will be drawn directly at the right border of the item (with a gap specified by the padding-right
attribute). Otherwise the image will be drawn right of the text with the specified horizontal padding.
The ChoiceItem
The ChoiceItem is used in lists and in choice groups. It supports following additional attributes:
Attribute Required Explanation
icon-image No The URL of the image, e.g. “,#')+,-"%./0(&12,#')34)%56”.
The keyword %INDEX% can be used for adding the position
of the item to the name, e.g.
“,#')+,-"%./0(&12,#')k:\BIlk34)%56”. The image used
for the first item will be “icon0.png”, the second item will use
the image “icon1.png” and so on.
icon-image-align No The position of the image relative to the text. Either “top”,
“bottom”, “left” or “right”. Defaults to “left”, meaning that the
138
The J2ME Polish GUI
Depending on the type of the corresponding list or choice group, different dynamic selectors are
used by a choice item:
Type of List or Selector
ChoiceGroup
implicit listitem
exclusive radiobox
multiple checkbox
popup popup
The ChoiceGroup
A choice group contains several choice items. It supports the “focused-style” attribute:
Attribute Required Explanation
focused-style No The name of the style for the currently focused item.
columns No The number of columns. This can be used to layout the items in
a table. Defaults to 1 column.
columns-width No Either “normal”, “equal” or the width for each column in a
comma separated list (e.g. “#'1(-)8+V,*9K/0d[Ld[LY[[6”).
Defaults to “normal”, meaning that each column uses as much
space as the widest item of that column needs.
The “equal” width leads to columns which have all the same
width.
139
The J2ME Polish GUI
An multiple ChoiceGroup adds the commands “Mark” and “Unmark” by default to the menu. The
names of the commands can be changed easily, compare page 76. If you want to suppress the
commands completely, the “polish.ChoiceGroup.suppressMarkCommands”-variable has to be set:
UW"&,"!1.0)"-.FE4'1,8K37K',#.`&'(438(44&.88A"&$7'--")*8E0W"1(.FE9&(.EZT
The Gauge
A Gauge shows a progress indicator. It supports following additional attributes:
140
The J2ME Polish GUI
When the Gauge item is used with an indefinite range, the gauge-gap-color will be used to indicate
the idle state. When the “continuous running” state is entered and an image has been specified, the
image will “fly” from the left to the right of the indicator.
The TextField
A TextField is used to get user input. You can choose whether the native input methods or a direct
input mode should be used. When the native mode is activated, a new input screen will pop up for
the user and special input modes like T9 or handwriting recognition can be used. When the direct
input mode is used instead, no extra screen will be shown and J2ME Polish accepts the entered
character directly. Please compare the following subsection “Direct Input Mode” for more
information.
The TextField supports following additional attributes:
141
The J2ME Polish GUI
TextField-Commands
A TextField adds the “Clear”- and “Delete”-commands to the menu by default. The names of these
commands can be changed easily, compare page 76. If you want to suppress the commands
completely, the “polish.TextField.suppressCommands”-variable has to be set:
UW"&,"!1.0)"-.FE4'1,8K3>.?9g,.1*38(44&.887'--")*8E0W"1(.FE9&(.EZT
Last but not least it is also possible to deactivate the "Delete" command singly:
UW"&,"!1.0)"-.FE4'1,8K3>.?9g,.1*38(44&.88B.1.9.7'--")*E0W"1(.FE9&(.EZT
The direct input mode can be activated for TextFields as well as for TextBoxes using the CSS-
attribute “textfield-direct-input” or by defining the preprocessing-variable
“polish.TextField.useDirectInput” in the !(,1*3?-1 file:
142
The J2ME Polish GUI
UW"&,"!1.0)"-.FE4'1,8K3>.?9g,.1*3(8.B,&.#9:)4(9E0W"1(.FE9&(.EZT
When the direct input mode is used, no extra screen will be used for editing the text and all
designing possibilities of J2ME Polish can be used. When the TextField is used within a Form, the
associated ItemStateListener will be notified after each change of the text.
On stylus-based devices, this mode should not be used since these devices often rely on native input
methods like handwriting recognition. This can be ensured by setting the preprocessing variable
only for devices which have no pointer-events:
UW"&,"!1.0)"-.FE4'1,8K3>.?9g,.1*3(8.B,&.#9:)4(9E0W"1(.FE9&(.E0
,RFEv4'1,8K3K"8J',)9.&IW.)98EZT
The direct input should not be used for editing longs texts (i.e. TextBoxes), since T9 and similar
input helpers cannot be used in this mode.
The user can change the input mode from lowercase (“abc”) to initial-letter uppercase (“Abc”) to
uppercase (“ABC”) and to numeric (“123”). The current input mode is shown below the title in an
extra StringItem. This item can be designed using the predefined CSS-style “info”:
,)R'0C
4"**,)%+&,%K9/0Y[6
!"#$%&'()*/0)').6
!'&*.&+#'1'&/0!1"#$6
R')9+89<1./041",)60
R')9+R"#./04&'4'&9,')"160
R')9+8,i./08-"1160
R')9+#'1'&/0R')97'1'&60Zm0"0#'1'&0*.R,).*0,)09K.0u#'1'&8t08.#9,')0mZ
1"<'(9/0&,%K96
O
143
The J2ME Polish GUI
The DateField
A DateField is used to enter date or time information. Currently the input is done with the use of the
native functions, so that special input modes can be used (like T9 or handwriting recognition). The
DateField supports following additional attributes:
144
The J2ME Polish GUI
The appearance of the datefield can also be adjusted using the preprocessing variable
“polish.DateFormat”, which can be defined in the <variables> section of the J2ME Polish task:
" UW"&,"!1.0)"-.FE4'1,8K3B"9.g'&-"9E0W"1(.FE(8E0ZT: The US standard of MM-DD-
YYYY is used, e.g. “12-24-2004”.
" UW"&,"!1.0)"-.FE4'1,8K3B"9.g'&-"9E0W"1(.FE*.E0ZT: The German standard of
DD.MM.YYYY is used, e.g. “24.12.2004”.
" UW"&,"!1.0)"-.FE4'1,8K3B"9.g'&-"9E0W"1(.FER&E0ZT: The French standard of
DD/MM/YYYY is used, e.g. “24/12/2004”.
" All other settings: The ISO 8601 standard of YYYY-MM-DD is used, e.g. “2004-12-24”.
The DateFormat also supports the generic values “dmy” (day-month-year), “mdy” (month-day-year)
or “ymd” (year-month-day). Along with the polish.DateFormatSeparator-variable and the
polish.DateFormatEmptyText-variable one can use any custom date format:
UW"&,"!1.0)"-.FE4'1,8K3B"9.g'&-"9E0W"1(.FE<-*EZT
UW"&,"!1.0)"-.FE4'1,8K3B"9.g'&-"9D.4"&"9'&E0W"1(.FEZEZT
UW"&,"!1.0)"-.FE4'1,8K3B"9.g'&-"9I-49<>.?9E0W"1(.FED.1.#90B"9.EZT
The Ticker
A Ticker scrolls a text over the current screen. In J2ME Polish the ticker is situated right above the
menu-bar on the bottom of a screen. Following attribute is supported:
Attribute Required Explanation
ticker-step No The number of pixels by which the ticker is shifted at each
update. Defaults to 2 pixels.
145
The J2ME Polish GUI
R')9+89<1./0!'1*60
R')9+R"#./04&'4'&9,')"160
R')9+8,i./08-"1160
R')9+#'1'&/0&.*6
!"#$%&#/,7,5#,-#.%�&+2415#41/8*5,2+'6##"!
-.)(!"&+#'1'&/0!1"#$6
O
3-<D#&..)D9<1.0C
!"#$%&'()*+,-"%./0(&120!%34)%056
!"#2(#.51+(915&+.#0&+2415#-,5#(/5&&+(#:).%#.%)(#(.;7&<
#########(,#.%1.#.%*=9+*#)01*&#)(#(%,:+#)+#.%�&+2415#1(#:&776#"!
-.)(!"&+#'1'&/09&")84"&.)96
O
When there is more than one item available in the menu, an “Options” menu will be shown
automatically, which opens the real menu when pressed (like shown in the following figures).
The items in the opened menu are designed using the predefined “-.)(,9.-” style. The background
and the border of the opened menu is designed using the “-.)(” style. You can change the names of
the “Options”, “Select” and “Cancel” commands by the way, this is explained in the localization
chapter on page 76.
The menu bar can be designed using the predefined styles "menubar", "leftcommand" and
"rightcommand":
Style Description
menubar This design of the menu-bar itself.
leftcommand Designs the left command ("Options", "Select" and user-defined
commands). Accepts all attributes of the IconItem.
rightcommand Designs the right command ("Cancel" and user-defined BACK or
146
The J2ME Polish GUI
Style Description
CANCEL commands). Accepts all attributes of the IconItem.
1.R9#'--")*0C
4"**,)%+K'&,i')9"1/0b6
4"**,)%+!'99'-/0[6
R')9+#'1'&/0R')97'1'&6
R')9+89<1./0!'1*6
!"#$%&'()*/0)').6
O
&,%K9#'--")*0C
4"**,)%+K'&,i')9"1/0b6
4"**,)%+!'99'-/0[6
R')9+#'1'&/0R')97'1'&6
R')9+89<1./0!'1*6
!"#$%&'()*/0)').6
;
147
The J2ME Polish GUI
The TabbedForm
The tabbed form can be designed like any Form and accepts the very same CSS-attributes.
Additionally the predefined styles "tabbar", "activetab" and "inactivetab" can be used to design the
additional elements of a tabbed form.
Style Description
tabbar This style designs the tab-bar of a TabbedForm.
activetab Designs the currently active tab of a TabbedForm.
inactivetab Designs all tabs but the currently selected one of a TabbedForm.
You can set the color of the scrolling indicator within the tabbar-style with the tabbar-scrolling-
indicator-color attribute:
9"!!"&0C
!"#$%&'()*+#'1'&/0VK,9.6
1"<'(9/0.?4")*6
4"**,)%+!'99'-/0[6
9"!!"&+8#&'11,)%+,)*,#"9'&+#'1'&/0!1"#$6
O
"#9,W.9"!0C
!"#$%&'()*+9<4./0&'()*+9"!6
!"#$%&'()*+#'1'&/08,1W.&6
!"#$%&'()*+"&#/0f6
R')9+#'1'&/0VK,9.6
4"**,)%+1.R9/0Y[6
4"**,)%+&,%K9/0f6
O
,)"#9,W.9"!0C
4"**,)%+1.R9/0d6
4"**,)%+&,%K9/0b6
-"&%,)+1.R9/0H6
-"&%,)+&,%K9/0H6
!"#$%&'()*+9<4./0&'()*+9"!6
!"#$%&'()*+#'1'&/0%&"<6
!"#$%&'()*+"&#/0f6
R')9+#'1'&/08,1W.&6
O
148
The MIDP/2.0-Compatible Game-Engine
With this game-engine it is possible to program a game with one source code for MIDP/2.0 as well
as MIDP/1.0 devices without changing anything within the source code!
How It Works
The J2ME Polish build-tool identifies the usage of the MIDP/2.0 game API and “weaves” the
necessary wrapper classes into the code. The obfuscation step then removes all unnecessary
functionality to ensure that only the needed parts are actually included into the application. The
J2ME Polish game-engine only needs about 5 to 6 kb extra space in the resulting JAR package,
when all classes are used.
Limitations
For technical reasons the collision detection works only with collision rectangles, which should be
set tightly for Sprites therefore. A pixel-level collision detection is not supported.
When a class extends the GameCanvas class, it should call the super-implementations, when one of
the methods keyPressed(int), keyReleased(int) or keyRepeated(int) is overridden.
The transformation of Sprites is currently only supported for Nokia devices, otherwise the
transformations will be ignored.
Optimizations
The TiledLayer and the GameCanvas implementations have several optional optimizations, which
can be triggered by defining specific variables in the “build.xml” file (compare the variables section
on page 52).
149
The MIDP/2.0-Compatible Game-Engine
Using a Fullscreen-GameCanvas
The GameCanvas normally uses the “fullscreen”-attribute of the <build>-element to determine
whether it should use a fullscreen-canvas (compare page 36). This behavior can be overridden with
defining the “polish.GameCanvas.useFullScreen” variable. Allowed value are “yes”, “no” and
“menu”. Please note that the “menu” mode (which should be used when commands are added to the
GameCanvas) is only supported when the J2ME Polish GUI is used. Another limitation of the
“menu” mode is that the paint()-method of the GameCanvas cannot be overridden.
Variable Explanation
polish.GameCanvas.useFullSc Defines whether the fullscreen mode is used, overrides the
reen “fullscreen”-attribute of the <build>-element. Possible values are
“yes”, “no” or “menu”.
The following example enables the fullscreen mode for the GameCanvas:
?G".$"+51(%":1@A!/5$7B=`":16"%G"7=071Q055N,.11%A(G"501@A817A(IH
This example shows how to override the paint()-method, even though the J2ME Polish GUI and the
“menu” fullscreen mode is used:
4(!1,#0#1"880A<`"-.7")W"80.?9.)*80`"-.7")W"80C
00333
ZZn,R04'1,8K3(8.J'1,8K`(,0~~04'1,8K3#1"88.83R(118#&..)/*.R,).*
ZZn04(!1,#0W',*04",)9D#&..)20`&"4K,#80%5
ZZn.18.
4(!1,#0W',*04",)920`&"4K,#80%5
ZZn.)*,R
C
000ZZ0,-41.-.)909K.04",)90-.9K'*
000333
O
O
Variable Explanation
polish.TiledLayer.useBackBuff Defines whether the backbuffer optimization should be used,
er needs to be ”true” to enable the optimization.
polish.TiledLayer.Transparent The color which is used for tiles which should transparent. This
150
The MIDP/2.0-Compatible Game-Engine
Variable Explanation
TileColor defaults to black.
Variable Explanation
polish.TiledLayer.splitImage Defines whether the base image of a TiledLayer should be split
into single tiles. Needs to be “true” to enable this optimization.
The following example uses a short-grid, which allows the usage of 32767 different tiles instead of
128 different tiles:
?G".$"+51(%":1@A!/5$7B=Y$51#D"81.=`.$#Y8!1A(G"501@A7B/.3A(IH
151
The MIDP/2.0-Compatible Game-Engine
Variable Explanation
polish.usePolishGameApi Defines whether the J2ME Polish game-engine should be used on
MIDP/2.0 devices as well. Possible values are “true” or “false”.
The following example uses the game-engine for Nokia MIDP/2.0 devices as well:
?G".$"+51(%":1@A!/5$7B=071S/5$7B`":1a!$A(G"501@A3.01A($2@A!/5$7B=G1%#/.(@@(
J/-$"A(IH
152
The MIDP/2.0-Compatible Game-Engine
virtual device representing a typical Series 60 phone with MIDP/2.0 support. Such is phone
supports additionally the Mobile Media API (mmapi) and the Wireless Messaging API (wmapi).
The device selection is very flexible and can select all MIDP/2.0 devices which support the Mobile
Media API as well, for example. For keeping this example easy to manage, we use only the selection
by the device's identifier:
?#1G$,1]1g0$.1:1%37H
((?.1g0$.1:1%3(%":1@AP#1%3$2$1.A(G"501@AJ/-$"IN1.$17TKU$#!ZA(IH
?I#1G$,1]1g0$.1:1%37H
The <build>-section controls the actual build process. For keeping this example easy, we choose not
to use the GUI of J2ME Polish and set the “(8.J'1,8K`(,” attribute to “R"18.”. We also need to
adjust the <midlet>-subelement and enter the full name of our game-class:
?+0$5#
((071S/5$7B`0$@A2"571A
((.17M$.@A.17/0.,17A
((C/.-M$.@Aij#$.=C/.-;A
H
((?f44(:$#5137(#12$%$3$/%(44H
((?:$#513(,5"77@A#1=1%/0&B=!/5$7B=1L":!51=U1%0U$#513A(%":1@AFL":!51A(IH
?I+0$5#H
The U!(,1*T-section has many subelements and can automate many tasks from the inclusion of the
debugging framework to the signing of the application. These settings are outside of the scope or
this article, though.
153
The MIDP/2.0-Compatible Game-Engine
Sprite Transformations
Another limitation of J2ME Polish is that sprite-transformations are only supported for Nokia
devices so far. This means that for other devices transformed sprite-images are needed. These can be
easily included by putting them in the “&.8'(&#.8Z\'D4&,9.>&")8R'&-"9,')8” folder. We can
adjust the handling of sprite-transformations by using the preprocessing of J2ME Polish:
ZZn,R0v24'1,8K3-,*4H0jj04'1,8K38(44'&9D4&,9.>&")8R'&-"9,')5
154
The MIDP/2.0-Compatible Game-Engine
4&,W"9.0R,)"1089"9,#0,)90A:^^p^rDIN@I\7I0F0).V0,)9PQCaLbLyLhO6
ZZn.)*,R
P333Q
ZZn,R04'1,8K3-,*4H0jj04'1,8K38(44'&9D4&,9.>&")8R'&-"9,')
9K,8384&,9.38.9>&")8R'&-20D4&,9.3>^;\DrA:^^p^056
ZZn.18.
9K,8384&,9.38.9g&"-.D._(.)#.20A:^^p^rDIN@I\7I056
ZZn.)*,R
In the above example we use call the transform(int)-method of the sprite only when the device either
uses the MIDP/2.0 platform or supports sprite transformation. Otherwise the frame-sequence
MIRROR_SEQUENCE will be used instead.
A similar adjustment can be needed during the instantiation of the sprite, when the transformed
image has different frame-dimensions:
ZZn,R04'1,8K3-,*4H0jj04'1,8K38(44'&9D4&,9.>&")8R'&-"9,')
,)90R&"-.z,*9K0F0Y[6
,)90R&"-.M.,%K90F0f6
ZZn.18.
ZZn0,)90R&"-.z,*9K0F0d6
ZZn0,)90R&"-.M.,%K90F0f6
ZZn.)*,R
9K,8384&,9.0F0).V0D4&,9.2084&,9.:-"%.L0R&"-.z,*9KL0R&"-.M.,%K9056
For an even more flexible approach you can use preprocessing variables. These variables can be
defined in the UW"&,"!1.8T-subelement of the !(,1*3?-10file:
?G".$"+517H
((?G".$"+51(
%":1@A!5"81.=2.":1M$:1%7$/%7A(
G"501@AVK^(_A(
$2@A!/5$7B=70!!/.3N!.$31Y."%72/.:"3$/%(yy(!/5$7B=:$#!ZA((
((IH
((?G".$"+51(
%":1@A!5"81.=2.":1M$:1%7$/%7A(
G"501@AT^(_A(
0%5177@A!/5$7B=70!!/.3N!.$31Y."%72/.:"3$/%(yy(!/5$7B=:$#!ZA((
((IH
((?G".$"+51(
%":1@A!5"81.=2.":1M$:1%7$/%7A(
G"501@AT^(TA(
$2@A!/5$7B=$#1%3$2$1.(@@(J/-$"IWZVKA((
((IH
?IG".$"+517H
In the above example the frame-dimensions are set to 10x8 for devices which support either the
MIDP/2.0 or the sprite transformation. The dimension 6x8 are used for all other devices. For the
Nokia/7210 phone the special value of 6x6 is used.
In the source-code a default-value should always be used for cases in which the variables are not set:
ZZn,R041"<.&3R&"-.B,-.)8,')8/*.R,).*
ZZnF09K,8384&,9.0F0).V0D4&,9.2084&,9.:-"%.L0]C41"<.&3R&"-.B,-.)8,')8O056
ZZn.18.
9K,8384&,9.0F0).V0D4&,9.2084&,9.:-"%.L0Y[L0f056
ZZn.)*,R
By using this approach the resources can later be changed without needing to change the source-
155
The MIDP/2.0-Compatible Game-Engine
code.
You can use a multitude of preprocessing symbols and variables. Which of these are available
depends on the device and the current setup. Please compare J2ME Polish's device-database and the
preprocessing documentation on page 78 for further information.
156
Extending J2ME Polish
Preparations
Create a new project in your IDE and set the classpath so that it includes the “enough-j2mepolish-
build.jar”, which can be found in the “import” folder of the installation directory. Also include the
“ant.jar” file from your Ant-installation into the classpath.
157
Extending J2ME Polish
The “class”-attribute needs to be set to the new class. The classPath-attribute can be used for
pointing out the location of the obfuscator. This is only needed when the obfuscator is not on the
Ant-classpath.
For the using the above parameter, the obfuscator needs to implement either the public method
8.9D#&,49g,1.20g,1.0R,1.05 or the public method 8.9D#&,49g,1.20D9&,)%0W"1(.05. When a
method with a File-parameter is used, relative file paths are resolved relative to the location of the
build.xml file (or to be more precise relative to the project.getBaseDir() location). The file given as
158
Extending J2ME Polish
Preparations
Create a new project in your IDE and set the classpath so that it includes the “enough-j2mepolish-
build.jar”, which can be found in the “import” folder of the installation directory. Also include the
“ant.jar” file from your Ant-installation into the classpath.
When for example the directive “date” is registered, the public method 4&'#.88B"9.20D9&,)%0
1,).L0*.3.)'(%K34'1,8K3(9,13D9&,)%=,8901,).8L0D9&,)%0#1"88\"-.050needs to be
implemented.
You can make use of following protected variables:
" de.enough.polish.preprocess.Preprocessor preprocessor: the main preprocessor
" de.enough.polish.preprocess.BooleanEvaluator booleanEvaluator : an evaluator for complex
terms which can be used in the #if-directive.
If you need further configuration settings, you can add them with the <parameter> construct, which
is discussed below.
In the processing method the line in which the preprocessing directive was found is usually
159
Extending J2ME Polish
changed. When the line is changed, please make sure that the preprocessing-directive is be removed
from the changed line, so that the following preprocessing can continue without errors.
When there is an exception, abort the build by throwing a org.apache.tools.ant.BuildException
explaining the details why the preprocessing was aborted.
This example should illustrate the usage of the registerDirective()-method:
4"#$"%.0#'-3#'-4")<34&.4&'#.886
,-4'&90'&%3"4"#K.39''183")93e(,1*I?#.49,')6
,-4'&90*.3.)'(%K34'1,8K34&.4&'#.8837(89'-J&.4&'#.88'&6
,-4'&90*.3.)'(%K34'1,8K3(9,13D9&,)%=,896
,-4'&90S"W"3(9,13B"9.6
4(!1,#0#1"880A<J&.4&'#.88'&0.?9.)*807(89'-J&.4&'#.88'&0C
04(!1,#0A<J&.4&'#.88'&250C
8(4.&256
&.%,89.&B,&.#9,W.2E*"9.E56
0O
04(!1,#0W',*04&'#.88B"9.20D9&,)%01,).L0D9&,)%=,8901,).8L0D9&,)%0#1"88\"-.050C
0 ,)90*,&.#9,W.D9"&90F01,).3,)*.?pR20EZZn*"9.E56
D9&,)%0"&%(-.)90F01,).38(!89&,)%20*,&.#9,W.D9"&90o0EZZn*"9.E31.)%9K250539&,-256
,)90&.41"#.J'80F0"&%(-.)93,)*.?pR2E]C*"9.OE56
,R02&.41"#.J'80FF0+Y50C
009K&'V0).V0e(,1*I?#.49,')2#1"88\"-.0o0E0"901,).0E0
o021,).83%.97(&&.)9:)*.?250o0Y50
o0E/0@)"!1.09'04&'#.880n*"9.+*,&.#9,W./0R'()*0)'0]C*"9.O08._(.)#.0,)01,).0PE0
o01,).0o0E3E056
O
D9&,)%0&.8(190F0"&%(-.)938(!89&,)%2[L0&.41"#.J'805
o020).V0B"9.2539'D9&,)%25050
o0"&%(-.)938(!89&,)%20&.41"#.J'80o0E]C*"9.OE31.)%9K25056
1,).838.97(&&.)92&.8(1956
0O
O
160
Extending J2ME Polish
,5"77@A,/:=,/:!"%8=!.1!./,177=U8S.1!./,177/.A
,5"77S"3B@A==I!.1!./,177/.4!./b1,3I+$%I,5"7717A
H
?!".":131.(%":1@A7,.$!3Q$51A(G"501@A==I7,.$!37I!.1!./,177=7,.$!3A(IH
?I!.1!./,177/.(H
The “class”-attribute needs to be set to the new class. The classPath-attribute can be used for
pointing out the location of the preprocessor. This is only needed when the preprocessor is not on
the Ant-classpath.
For the using the above parameter, the preprocessor needs to implement either the public method
8.9D#&,49g,1.20g,1.0R,1.05 or the public method 8.9D#&,49g,1.20D9&,)%0W"1(.05. When a
method with a File-parameter is used, relative file paths are resolved relative to the location of the
build.xml file (or to be more precise relative to the project.getBaseDir() location). The file given as
a parameter in the set-method uses an absolute path in that case.
Initialisation
J2ME Polish calls the getPrefContentWidth()-method first with an open height (-1). Then the
getPrefContentHeight()-method is called with the actual granted width. When the width had to be
adjusted, the custom item will be notified again with the setSize(width. height)-method.
Please note that the Display.getColor( int ) and Font.getFont( int ) are only available on MIDP/2.0
devices. Such calls should be surrounded by #ifdef-directives:
ZZn,R*.R04'1,8K3-,*4H
g')90R')90F0g')93%.9g')920g')93gp\>rD>;>:7r>Il>056
ZZn.18.
ZZn0g')90R')90F0g')93%.9B.R"(19g')9256
ZZn.)*,R
Interaction Modes
The J2ME Polish implementation supports the interaction modes KEY_PRESS,
TRAVERSE_HORIZONTAL and TRAVERSE_VERTICAL.
Traversal
When the custom item gains the focus for the first time, the traverse-method will be called with the
CustomItem.NONE direction. Subsequent calls will include the direction (either Canvas.UP,
161
Extending J2ME Polish
The second variant is the most flexible one and is encouraged, therefore. When the item MyItem is
now used within the code, the appropriate style can specified with the #style directive:
ZZn89<1.0#''1D9<1.
A<:9.-0#''1:9.-0F0).V0A<:9.-201"!.1056
For reading the specific style settings, the method setStyle( Style ) needs to be overridden:
ZZn,R*.R04'1,8K3(8.J'1,8K`(,
004(!1,#0W',*08.9D9<1.20D9<1.089<1.050C
ZZn,R09&(.
ZZ09K.08(4.&+#"110)..*809'0!.0K,**.)/
ZZn08(4.&38.9D9<1.2089<1.056
ZZn.)*,R
9K,83R')90F089<1.3R')96
9K,83R')97'1'&0F089<1.3R')97'1'&6
ZZ0)'V0&."*084.#,R,#0"99&,!(9.8/
ZZn,R*.R04'1,8K3#883-<,9.-+#'1'&
:)9.%.&0#'1'&:)90F089<1.3%.9:)9J&'4.&9<20E-<,9.-+#'1'&E056
,R02#'1'&:)90vF0)(1150C
162
Extending J2ME Polish
9K,83#'1'&0F0#'1'&:)93,)9q"1(.256
O0.18.0C
9K,83#'1'&0F0[?gg[[[[6
O
ZZn.18.
9K,83#'1'&0F0[?gg[[[[6
ZZn.)*,R
00O
ZZn.)*,R
The setStyle()-method will be called before the preferred content width and height is requested,
when the CustomItem has a style associated with it.
Please note that the variable needs to be called “style” or needs to end with “style”, so that J2ME
Polish can process all styles correctly. This is required, since instead of String-based attribute-names
numerical short-values will be used in the actual code. This approach significantly reduces the
runtime-performance and minimizes the heap-usage.
There are 3 different ways to retrieve a property from a style:
! 89<1.3%.9J&'4.&9<20D9&,)%0)"-.05 returns either a String representing that value or null
when the property is not defined.
! 89<1.3%.9:)9J&'4.&9<20D9&,)%0)"-.05 returns either an Integer representing that value or
null when the property is not defined. You can use this method only when you have registered
the corresponding attribute in the file #(89'-+#88+"99&,!(9.83?-1. The attribute-type needs to
be either “,)9.%.&” or “#'1'&”.
! 89<1.3%.9e''1.")J&'4.&9<20D9&,)%0)"-.05 returns either a Boolean representing that value
or null when the property is not defined. You can use this method only when you have registered
the corresponding attribute in the file #(89'-+#88+"99&,!(9.83?-1. The attribute-type needs to
be “!''1.")”.
You will find the custom-css-attributes.xml file in the installation directory of J2ME Polish. This
file can be used to register CSS attributes which are used in your CustomItems.
The registration of these attributes is only required when either the 89<1.3%.9:)9J&'4.&9<20
D9&,)%0)"-.05+0or the 89<1.3%.9:)9J&'4.&9<20D9&,)%0)"-.05-method is used in the
8.9D9<1.20D9<1.05-method of the CustomItem. The registration is encouraged nevertheless, since
future-versions of J2ME Polish might use this information for an embedded CSS editor.
Each attribute is represented by an <attribute>-element with following attributes:
163
Extending J2ME Polish
164
Extending J2ME Polish
4"#$"%.0#'-3#'-4")<3!"#$%&'()*86
,-4'&90S"W"?3-,#&'.*,9,')31#*(,3`&"4K,#86
,-4'&90*.3.)'(%K34'1,8K3(,3e"#$%&'()*6
4(!1,#0#1"880J(18"9,)%7,.e"#$%&'()*0.?9.)*80e"#$%&'()*0C
4&,W"9.0R,)"10,)90#'1'&6
4(!1,#0J(18"9,)%7,.e"#$%&'()*20,)90#'1'&050C
8(4.&256
9K,83#'1'&0F0#'1'&6
O
4(!1,#0W',*04",)92,)90?L0,)90<L0,)90V,*9KL0,)90K.,%K9L0`&"4K,#80%50C
%38.97'1'&209K,83#'1'&056
%3R,11;?L0<L0V,*9KL0K.,%K9L0[L0ad[056
O
The paint method is used to render the background and needs to be implemented by all subclasses
of Background. The #condition-directive at the top ensures that the PulsatingCircleBackground is
included only when the GUI of J2ME Polish is actually used.
This background is useful, but a bit boring, so we add an animation to it: the background-diameter
should grow and shrink constantly. For doing this we need to override the animate()-method, which
is used to implement animations. When this method returns “true”, a repaint will be triggered
resulting in a call of the paint()-method. With returning false the background indicates that no
repaint is necessary.
4(!1,#0#1"880J(18"9,)%7,.e"#$%&'()*0.?9.)*80e"#$%&'()*0C
4&,W"9.0R,)"10,)90#'1'&6
4&,W"9.0R,)"10,)90-"?B,"-.9.&6
4&,W"9.0R,)"10,)90-,)B,"-.9.&6
4&,W"9.0,)90#(&&.)9B,"-.9.&6
4&,W"9.0!''1.")0,8`&'V,)%0F09&(.6
4(!1,#0J(18"9,)%7,.e"#$%&'()*20,)90#'1'&L0,)90-,)B,"-.9.&L0,)90-"?B,"-.9.&050C
8(4.&256
9K,83#'1'&0F0#'1'&6
9K,83-,)B,"-.9.&0F0-,)B,"-.9.&6
9K,83-"?B,"-.9.&0F0-"?B,"-.9.&6
9K,83#(&&.)9B,"-.9.&0F0-,)B,"-.9.&6
O
4(!1,#0W',*04",)92,)90?L0,)90<L0,)90V,*9KL0,)90K.,%K9L0`&"4K,#80%50C
%38.97'1'&209K,83#'1'&056
,)90#.)9.&l0F0?0o0V,*9K0Z0H6
,)90#.)9.&|0F0<0o0K.,%K90Z0H6
,)90'RR8.90F09K,83#(&&.)9B,"-.9.&0Z0H6
?0F0#.)9.&l0+0'RR8.96
<0F0#.)9.&|0+0'RR8.96
%3R,11;?L0<L09K,83#(&&.)9B,"-.9.&L09K,83#(&&.)9B,"-.9.&L0[L0ad[056
O
4(!1,#0!''1.")0"),-"9.250C
165
Extending J2ME Polish
,R029K,83,8`&'V,)%50C
9K,83#(&&.)9B,"-.9.&oo6
,R029K,83#(&&.)9B,"-.9.&0FF09K,83-"?B,"-.9.&50C
9K,83,8`&'V,)%0F0R"18.6
O
O0.18.0C
9K,83#(&&.)9B,"-.9.&++6
,R029K,83#(&&.)9B,"-.9.&0FF09K,83-,)B,"-.9.&50C
9K,83,8`&'V,)%0F09&(.6
O
O
&.9(&)09&(.6
O
O
The implementation uses the field “currentDiameter”, which is either decreased or increased in each
run of the animate()-method. The constructor now has two additional parameters: the minimum
diameter and the maximum diameter for the circle.
4"#$"%.0#'-3#'-4")<3!"#$%&'()*86
,-4'&90S"W"3(9,13M"8KA"46
,-4'&90'&%3"4"#K.39''183")93e(,1*I?#.49,')6
,-4'&90*.3.)'(%K34'1,8K34&.4&'#.883e"#$%&'()*7')W.&9.&6
,-4'&90*.3.)'(%K34'1,8K34&.4&'#.883D9<1.6
,-4'&90*.3.)'(%K34'1,8K34&.4&'#.883D9<1.DK..96
4(!1,#0#1"880J(18"9,)%7,.e"#$%&'()*7')W.&9.&0.?9.)*80e"#$%&'()*7')W.&9.&0C
4(!1,#0J(18"9,)%7,.e"#$%&'()*7')W.&9.&250C
8(4.&256
O
4&'9.#9.*0D9&,)%0#&."9.\.VD9"9.-.)92
M"8KA"40!"#$%&'()*L0
D9<1.089<1.L
D9<1.DK..9089<1.DK..9050
9K&'V80e(,1*I?#.49,')0C
D9&,)%0-,)B,"-.9.&D9&0F02D9&,)%50!"#$%&'()*3%.920E-,)+*,"-.9.&E56
,R02-,)B,"-.9.&D9&0FF0)(1150C
9K&'V0).V0e(,1*I?#.49,')2E:)W"1,*07DD/09K.04(18"9,)%+#,.0
!"#$%&'()*0)..*809K.0"99&,!(9.0P-,)+*,"-.9.&Q3E56
O
D9&,)%0-"?B,"-.9.&D9&00F02D9&,)%50!"#$%&'()*3%.920E-"?+*,"-.9.&E56
,R02-"?B,"-.9.&D9&0FF0)(1150C
9K&'V0).V0e(,1*I?#.49,')2E:)W"1,*07DD/09K.04(18"9,)%+#,.0
!"#$%&'()*0)..*809K.0"99&,!(9.0P-"?+*,"-.9.&Q3E56
O
ZZ0)'V0#K.#$0,R09K.8.0*,"-.9.&80K"W.0W"1,*0W"1(.8/
,)90-,)B,"-.9.&0F04"&8.:)92E-,)+*,"-.9.&EL0-,)B,"-.9.&D9&56
,)90-"?B,"-.9.&0F04"&8.:)92E-"?+*,"-.9.&EL0-"?B,"-.9.&D9&56
,R02-"?B,"-.9.&0UF0-,)B,"-.9.&050C
166
Extending J2ME Polish
9K&'V0).V0e(,1*I?#.49,')2E:)W"1,*07DD/09K.0P-,)+*,"-.9.&Q0"99&,!(9.0
'R09K.04(18"9,)%+#,.0!"#$%&'()*0)..*809'0!.08-"11.&09K")09K.0P-"?+*,"-.9.&Q3E56
O
,R02-,)B,"-.9.&0U0[050C
9K&'V0).V0e(,1*I?#.49,')2E:)W"1,*07DD/09K.0P-,)+*,"-.9.&Q0"99&,!(9.0
'R09K.04(18"9,)%+#,.0!"#$%&'()*0)..*809'0!.0%&."9.&0'&0._("180[3E56
O
ZZ0'$"<L09K.0-,)+0")*0-"?+*,"-.9.&04"&"-.9.&80"&.0'$"</
&.9(&)0E).V0#'-3#'-4")<3!"#$%&'()*83J(18"9,)%7,.e"#$%&'()*20E
o09K,83#'1'&0o0EL0E0o0-,)B,"-.9.&D9&0o0EL0E0o0-"?B,"-.9.&D9&0o0E5E6
O
In the method “createNewStatement” we read the provided values from the HashMap. To parse
these values we can the helper-method 4"&8.:)920D9&,)%0"99&,!(9.\"-.L0D9&,)%0
"99&,!(9.q"1(.05L04"&8.g1'"920D9&,)%0"99&,!(9.\"-.L0D9&,)%0"99&,!(9.q"1(.05L0
4"&8.7'1'&20D9&,)%0#'1'&q"1(.050and %.9@&120D9&,)%0(&105.
In our example we want to use the attribute “color”, “min-diameter” and “max-diameter”. The color
value is parsed by the super-class already and can be accessed with “9K,83#'1'&”. In case no color
has been defined, the background color defaults to white. When a required value is missing or a
value is set wrong, we throw a BuildException explaining the details of what went wrong. When
everything is okay, we return a String in which a new instance of our background is created.
We included the #condition “false”, so that this file is never included in the J2ME application. This
is useful when the same source folder is used for the client-background-class as well as the server-
background-class.
167
Extending J2ME Polish
?I+0$5#H
?IbZ:1!/5$7BH
Thirdly and lastly we need to use the new background in the “resources/polish.css” file of our
application. As the type we need to define the SERVER-side converting class:
R'#(8.*0C
4"**,)%/0h6
!"#$%&'()*0C
9<4./0#'-3#'-4")<3!"#$%&'()*83J(18"9,)%7,.e"#$%&'()*7')W.&9.&6
#'1'&/0VK,9.6
-,)+*,"-.9.&/0H[6
-"?+*,"-.9.&/0y[6
O
R')90C
89<1./0!'1*6
#'1'&/0R')97'1'&6
8,i./08-"116
O
1"<'(9/0.?4")*0j0#.)9.&6
O
Now we can build the application by
calling Ant to check the result:
4"#$"%.0#'-3#'-4")<3!'&*.&86
168
Extending J2ME Polish
,-4'&90S"W"?3-,#&'.*,9,')31#*(,3`&"4K,#86
,-4'&90*.3.)'(%K34'1,8K3(,3e'&*.&6
4(!1,#0#1"8807,.e'&*.&0.?9.)*80e'&*.&0C
4&,W"9.0R,)"10,)9089&'$.D9<1.6
4&,W"9.0R,)"10,)90#'1'&6
4&,W"9.0R,)"10,)90!'&*.&z,*9K6
4(!1,#07,.e'&*.&20,)90#'1'&L0,)90V,*9KL0,)9089&'$.D9<1.050C
8(4.&256
9K,83#'1'&0F0#'1'&6
9K,83!'&*.&z,*9K0F0V,*9K6
9K,8389&'$.D9<1.0F089&'$.D9<1.6
O
4(!1,#0W',*04",)92,)90?L0,)90<L0,)90V,*9KL0,)90K.,%K9L0`&"4K,#80%50C
%38.97'1'&209K,83#'1'&056
!''1.")08.9D9&'$.D9<1.0F029K,8389&'$.D9<1.0vF0`&"4K,#83Dp=:B056
,R028.9D9&'$.D9<1.50C
%38.9D9&'$.D9<1.209K,8389&'$.D9<1.056
O
%3*&"V;?L0<L0V,*9KL0K.,%K9L0[L0ad[056
,R029K,83!'&*.&z,*9K0T0Y50C
,)90!V0F09K,83!'&*.&z,*9K6
VK,1.02!V0T0[50C
%3*&"V;?0o0!VL0<0o0!VL0V,*9K0+0Hm!VL0K.,%K90+0Hm!VL0[L0ad[0
56
!V++6
O
O
,R028.9D9&'$.D9<1.50C
%38.9D9&'$.D9<1.20`&"4K,#83Dp=:B056
O
O
The #condition-directive ensures that this class is only used when the GUI of J2ME Polish is
actually used. In the paint()-method the border is rendered to the screen. When a different stroke-
style than Graphics.SOLID is used, we set that style and reset the style in the end of the paint()-
method. This is a J2ME Polish specific convention, since the Graphics.DOTTED stroke style is
hardly ever used.
4"#$"%.0#'-3#'-4")<3!'&*.&86
,-4'&90S"W"3(9,13M"8KA"46
,-4'&90'&%3"4"#K.39''183")93e(,1*I?#.49,')6
,-4'&90*.3.)'(%K34'1,8K34&.4&'#.883e'&*.&7')W.&9.&6
,-4'&90*.3.)'(%K34'1,8K34&.4&'#.883D9<1.6
,-4'&90*.3.)'(%K34'1,8K34&.4&'#.883D9<1.DK..96
169
Extending J2ME Polish
4(!1,#0#1"8807,.e'&*.&7')W.&9.&0.?9.)*80e'&*.&7')W.&9.&0C
4(!1,#07,.e'&*.&7')W.&9.&250C
8(4.&256
O
4&'9.#9.*0D9&,)%0#&."9.\.VD9"9.-.)92
M"8KA"40!'&*.&L0
D9<1.089<1.L
D9<1.DK..9089<1.DK..9050
9K&'V80e(,1*I?#.49,')0
C
D9&,)%089&'$.D9<1.0F02D9&,)%50!'&*.&3%.92E89&'$.+89<1.E56
D9&,)%089&'$.D9<1.7'*.6
,R0289&'$.D9<1.0vF0)(1150C
,R02E*'99.*E3._("18289&'$.D9<1.550C
89&'$.D9<1.7'*.0F0ES"W"?3-,#&'.*,9,')31#*(,3`&"4K,#83Bp>>IBE6
O0.18.0C
89&'$.D9<1.7'*.0F0ES"W"?3-,#&'.*,9,')31#*(,3`&"4K,#83Dp=:BE6
O
O0.18.0C
89&'$.D9<1.7'*.0F0ES"W"?3-,#&'.*,9,')31#*(,3`&"4K,#83Dp=:BE6
O
&.9(&)0E).V0*.3.)'(%K34'1,8K3.?9.)8,')837,.e'&*.&20E0
o09K,83#'1'&0o0EL0E0o09K,83V,*9K0o0EL0E0o089&'$.D9<1.7'*.0o0E5E6
O
The BorderConverter already parses the color and width of the border. The color defaults to black
and the width defaults to 1. So we only need to parse the desired stroke-style. Unless “dotted” is
defined, we assume that the Graphics.SOLID stroke-style should be used.
There are some helper methods for parsing the CSS-attributes: 4"&8.:)920D9&,)%0
"99&,!(9.\"-.L0D9&,)%0"99&,!(9.q"1(.05L04"&8.g1'"920D9&,)%0"99&,!(9.\"-.L0D9&,)%0
"99&,!(9.q"1(.05L04"&8.7'1'&20D9&,)%0#'1'&q"1(.050and %.9@&120D9&,)%0(&105.
We included the #condition “false”, so that this file is never included in the J2ME application. This
is useful when the same source folder is used for the client-background-class as well as the server-
background-class.
170
Extending J2ME Polish
?bZ:1!/5$7BH
((((<===>
?+0$5#
78:+/57@AFL":!51N8:+/5^(a%/3B1.FL":!51A
$:"&1D/"#N3."31&8@A+",-&./0%#A
20557,.11%@A:1%0A
071S/5$7B`0$@A3.01A
7.,M$.@A7/0.,1I7.,'==I+/.#1.4!./b1,3I7/0.,1I7.,A
H
((((<===>
?I+0$5#H
?IbZ:1!/5$7BH
Thirdly and lastly we need to use the new background in the “resources/polish.css” file of our
application. As the type we need to define the SERVER-side converting class:
R'#(8.*0C
4"**,)%/0h6
!"#$%&'()*/0)').60
!'&*.&0C
9<4./0
#'-3#'-4")<3!'&*.&837,.e"#$%&'()*7')W.&9.&6
V,*9K/0H6
#'1'&/0R')97'1'&6
89&'$.+89<1./0*'99.*6
O
R')90C
89<1./0!'1*6
#'1'&/0R')97'1'&6
8,i./08-"116
O
1"<'(9/0.?4")*0j0#.)9.&6
O
Now we can build the application by calling Ant to check the result:
171
Standalone Tools
Standalone Tools
J2ME Polish includes standalone tools for
specialized tasks in the
]C4'1,8K3K'-.OZ!,) folder.
172
Standalone Tools
“playerX”, “playerY” and so on. You can also define the type of each data-entry. There are
predefined types available, but you can also combine your own types out of the basic types using
“Edit -> Add Custom Type”.
Each data entry also has a “count” value, which determines how often the entry is repeated. You can
insert “static” numbers here, but you can also be a bit more flexible by using a calculation. In the
calculation you can use any entry which is listed before the affected entry. So far you can only use
simple terms using one operation on a number of entries. In this way you can for example define
first a number of columns and a number of rows and then use “columns * rows” for calculating the
number of cells of a table structure. Just click into the respective “count” field to start the editor for
changing the count-value of the entry.
The BinaryEditor can also generate the J2ME code for loading data files with the current definition
– just select “Code -> Generate Code”.
173
Standalone Tools
Since the font-editor does no yet optimize the generated font-images, you might want to optimize
the images outside of the editor: Just select “File -> Save PNG-Image As...” and edit the image in
your favorite image editing program, e.g. The Gimp. You might also want to use PNG-image
optimizer like PNG-Crush (http://pmt.sourceforge.net/pngcrush/) or PNG-Out
(http://advsys.net/ken/utils.htm#pngout). When you're done, just reload the PNG-image by selecting
“File -> Open PNG-Image”.
You can also fine-tune every aspect of the bitmap-font by opening it in the BinaryEditor: select
“File -> Open in Binary Editor” to do so.
174
Non-MIDP Platforms
Non-MIDP Platforms
J2ME Polish can be adjusted to support several platforms that support more than the normal MIDP
profile. The key for this support is the ${polish.home}/platforms.xml file, inclusion of platform
specific (boot) classpaths, and the automatic invocation of preprocessors, postcompilers, finalizers
and so on.
BlackBerry and Palm platforms are supported out of the box.
Preparations
For transforming and signing the JAR files to the BlackBerry proprietary COD format, the
BlackBerry Java Development Environment (JDE) needs to be installed. The JDE can be
downloaded from http://www.blackberry.com/developers. On Unix systems it can be installed using
Wine.
In your build.xml script you then need to define the !1"#$!.&&<3K'-. property which points to the
installation folder of the JDE:
U4&'4.&9<0
)"-.FE!1"#$!.&&<3K'-.E0
1'#"9,')FE7/ZJ&'%&"-0g,1.8Z^.8."&#K0:)0A'9,')Ze1"#$e.&&<0GBI0b3[3HE0
ZT
In case the sigtool.csk and sigtool.db files are not included in the same location like the certificates,
you also need to define the “blackberry.sigtool.dir” property:
U4&'4.&9<0)"-.FE!1"#$!.&&<38,%9''13*,&E01'#"9,')FE&.8'(&#.8Z8,%9''1EZT
175
Non-MIDP Platforms
When you specify the password as well, J2ME Polish uses this for requesting the signatures without
manual intervention. For such cases the password needs to contain only ASCII characters, otherwise
J2ME Polish can't include the password automatically.
U4&'4.&9<0)"-.FE!1"#$!.&&<3#.&9,R,#"9.34"88V'&*E0W"1(.FE8.#&.9EZT
Troubleshooting
Deactivate Obfuscation
You should deactivate obfuscation for BlackBerry devices, since the rapc compiler already removes
any unneeded fields, classes etc. Also you can get verification errors on the BlackBerry devices
when you enable the obfuscation. You can skip the obfuscation for test builds as well as for
BlackBerry devices with this definition:
U'!R(8#"9'&0)"-.FEJ&'`("&*E0()1.88FE9.890jj04'1,8K3!1"#$!.&&<E0ZT
Library
J2ME Polish includes the ${polish.home}/import/blackberry-4.0.jar library which contains the most
important packages that are additionally available on BlackBerry devices. If you use BlackBerry
specific classes in your application you might encounter compiler problems, because currently not
all available classes are included in the default library. In such cases you can copy the JAR provided
by the JDE from ${blackberry.home}/lib/net_rim_api.jar to ${polish.home}/import/blackberry-
4.0.jar. Since this file contains unresolved class dependencies you need to use a JDK 1.4.x and must
not use a 1.5 JDK.
176
Non-MIDP Platforms
Preparations
The Palm converter and simulator can be downloaded from http://www.palmos.com/dev/tech/java.
When you extract the WEME tools you will find additional libraries in the Tools/lib folder. You
need to adjust the CLASSPATH environment variable of your system to include those libraries or
you need to copy them to ${java.home}/lib.
In your build.xml script you then need to define the 4"1-3V.-.3K'-. property that points to the
folder into which you have extracted the WEME tools:
U4&'4.&9<0
)"-.FE4"1-3V.-.3K'-.E0
1'#"9,')FE7/ZJ&'%&"-0g,1.8ZJ"1-ZzIAIhyE0
ZT
The following example adds a splash image to the application and defines a vendor ID:
UW"&,"!1.0)"-.FE4"1-31"&%.:#')E0W"1(.FE&.8'(&#.8Z)"9,W.Z841"8K3S4%E0ZT
UW"&,"!1.0)"-.FE4"1-3W.)*'&:*E0W"1(.FEI\DzE0ZT
177
Non-MIDP Platforms
When you target only a generic device like the Generic/multi one, you can invoke the converter by
adding the jar2prc finalizer to the U!(,1*T section of your build.xml script:
UR,)"1,i.&0)"-.FES"&H4&#E0ZT
Preparations
You can download DoJa emulators from the DoJa Developer Network at http://www.doja-
developer.net. There are currently two versions of DoJa for the international market: 1.5 and 2.5.
J2ME Polish already includes libraries for both versions. In Japan DoJa 4.0 is the current standard.
In your IDE you need to include either ${polish.home}/import/doja-1.5.jar or
${polish.home}/import/doja-2.5.jar to the classpath of your project.
Last but not least you need to specify your :;441,#"9,') class with the U,"441,T element inside
of the U!(,1*T element:
U!(,1*T
U,"441,0#1"88FE9.9&,83>.9&,8E0ZT
U'!R(8#"9'&0)"-.FEJ&'`("&*E0ZT
Uv++03330++T
UZ!(,1*T
You can now build your application and launch the emulator, e.g. by calling ")90.-(1"9'& from the
command line. J2ME Polish creates the JAR file without a Manifest and a JAM instead of a JAD
descriptor.
178
Non-MIDP Platforms
179
Non-MIDP Platforms
wine then automatically for executing the emulator under Unix systems. Remember to specify the
*'S"3K'-. Ant property in your build.xml script.
Of course you can also use these symbols in n,R directives to branch within an utility class for
example:
ZZn,R04'1,8K3-,*4
000ZZ089'&.09K.0*"9"0,)0"0&.#'&*089'&./
000^.#'&*D9'&.089'&.0F0^.#'&*D9'&.3'4.)^.#'&*D9'&.20E)"-.EL09&(.056
000ZZ0333
ZZn.1,R04'1,8K3*'S"
000ZZ089'&.0*"9"0,)09K.08#&"9#K04"*/
0007')).#9,')0#')0F07')).#9'&3'4.)2E8#&"9#K4"*/ZZZ[604'8F[EL07')).#9'&3z^:>I056
000ZZ0333
ZZn.)*,R
Remember that you need to do this for your ,-4'&9 statements as well.
180
Cooking Tips and How-Tos
In the above example the “source/src” folder of the current project and the “source/src” folder of the
“extensions” project are included. The notation is OS-independent by the way. So you can separate
different source-paths with either a colon ':' or a semicolon ';' and you can separate folders with a
slash '/' or a backslash '\'.
You can also use the nested <sources>-element for including source-directories based on conditions.
In this example the directory “source/test” is only included when the Ant-property “test” is true:
?+0$5#
20557,.11%@A:1%0A
071S/5$7B`0$@A3.01A
H
?7/0.,17H
?7/0.,1(#$.@A7/0.,1I7.,A(IH
?7/0.,1(#$.@A7/0.,1I3173A($2@A3173A(IH
?I7/0.,17H
===
181
Cooking Tips and How-Tos
7/0.,1M$.@A7/0.,1I7.,'7/0.,1I3B$.#!".38A
H
The notation is OS-independent by the way. So you can separate different source-paths with either a
colon ':' or a semicolon ';' and you can separate folders with a slash '/' or a backslash '\'.
The notation is OS-independent by the way. So you can separate different source-paths with either a
colon ':' or a semicolon ';' and you can separate folders with a slash '/' or a backslash '\'.
182
Cooking Tips and How-Tos
The above example also uses the "polish.debugVerbose" symbol for determining if a meaningful
exception should be thrown. By giving verbose information only in cases when it is requested, some
memory can be saved, too. You can set and unset the "polish.debugVerbose" symbol by modifying
the “verbose” attribute of the <debug>-element. This is described in more detail on page 54.
183
Cooking Tips and How-Tos
section of the “resources/polish.css” file. In that case you can just refer to the instances:
!"#$%&'()*80C
-<e"#$%&'()*0C
9<4./0&'()*+&.#96
#'1'&/0%&"<6
"&#/0Yh6
!'&*.&+#'1'&/0!1"#$6
!'&*.&+V,*9K/0H6
O
O
9,91.0C
!"#$%&'()*/0-<e"#$%&'()*6
Zmm08$,44,)%0'9K.&0"99&,!(9.80mmZ
O
R'#(8.*0C
!"#$%&'()*/0-<e"#$%&'()*6
Zmm08$,44,)%0'9K.&0"99&,!(9.80mmZ
O
Use Preprocessing
With preprocessing you can make amazing adjustments to specific devices without wasting memory
and without losing the portability of an application.
Consider for example this “SplashScreen” solution, which shows a startup logo. This screen should
be derived from Nokia's FullScreenCanvas when this class is available. In a classic solution you
would need to test if Nokia's API is available and to load a Nokia-specific version of the
SplashScreen class:
4(!1,#0#1"880A<A,*1.90.?9.)*80A:B1.90C
P333Q
4(!1,#0W',*08K'VD41"8KD#&..)250C
B,841"<"!1.0841"8KD#&..)6
184
Cooking Tips and How-Tos
9&<0C
ZZ0#K.#$0,R09K,80,80"0\'$,"+*.W,#./
841"8KD#&..)0F071"883R'&\"-.2uA<\'$,"D41"8KD#&..)t53).V:)89")#.256
O0#"9#K02I?#.49,')0.50C
ZZ0)'0\'$,"0;J:0,80"W",1"!1.L01'"*09K.0#1"88,#0841"8K08#&..)/
841"8KD#&..)0F0).V0A<D41"8KD#&..)256
O
9K,83*,841"<38.9208#&..)056
O
O
4(!1,#0#1"880A<D41"8KD#&..)0.?9.)*807")W"80C
4(!1,#0W',*04",)920`&"4K,#80%50C
P333Q
O
O
4(!1,#0#1"880A<\'$,"D41"8KD#&..)0.?9.)*80#'-3)'$,"3-,*3(,3g(117")W"80C
4(!1,#0W',*04",)920`&"4K,#80%50C
P333Q
O
O
With the preprocessing capabilities and the integrated device database of J2ME Polish there is an
easier and much more memory efficient solution available:
4(!1,#0#1"880A<D41"8KD#&..)0
ZZn,R04'1,8K3"4,3)'$,"+(,
.?9.)*80#'-3)'$,"3-,*3(,3g(117")W"8
ZZn.18.
ZZn0.?9.)*807")W"8
ZZn.)*,R
C
4(!1,#0W',*04",)920`&"4K,#80%50C
P333Q
O
O
Another example is the playback of sound. In a classical environment you would need to check the
supported formats at runtime and then decide which one should be used. Using preprocessing and
the device database this is much easier and no checks during the runtime are necessary:
4(!1,#0W',*041"<A(8,#250C
J1"<.&041"<.&6
ZZn,R04'1,8K3"(*,'3-4.%
41"<.&0F0A")"%.&3#&."9.J1"<.&2071"883%.9^.8'(&#.;8D9&."-2u9,91.3-4at5L0
u"(*,'Z-4.%t056
41"<.&389"&9256
ZZn.1,R04'1,8K3"(*,'3"-&
41"<.&0F0A")"%.&3#&."9.J1"<.&2071"883%.9^.8'(&#.;8D9&."-2u9,91.3"-&t5L0
u"(*,'Z"-&t056
41"<.&389"&9256
ZZn.1,R04'1,8K3"(*,'3V"W
41"<.&0F0A")"%.&3#&."9.J1"<.&2071"883%.9^.8'(&#.;8D9&."-2u9,91.3V"Wt5L0
u"(*,'ZV"Wt056
41"<.&389"&9256
ZZn.1,R04'1,8K3"(*,'3-,*,
41"<.&0F0A")"%.&3#&."9.J1"<.&2071"883%.9^.8'(&#.;8D9&."-2u9,91.3-,*,t5L0
u"(*,'Z-,*,t056
41"<.&389"&9256
ZZn.18.
ZZn0&.9(&)6
185
Cooking Tips and How-Tos
ZZn.)*,R
O
With the help of preprocessing you can shift the runtime checks to the compile phase.
For testing purposes no certificate needs to be purchased and imported. Such MIDlets cannot be
installed on real devices, however.
When an appropriate certificate was purchased and imported into the keystore named “midlets.ks”
with the key “SignMIDlet”, the following two <java>-elements need to be added to the <build>-
element:
US"W"0S"&FE]CV9$3K'-.OZ!,)ZG"*>''13S"&E0
000000 R'&$FE9&(.E0
000000 R",1').&&'&FE9&(.E0
0000 ,RFE4'1,8K3-,*4HE0
()1.88FE9.89E
-.88"%.FE;**,)%08,%)"9(&.0R'&0*.W,#.0]C4'1,8K3,*.)9,R,.&OE
T
U"&%01,).FE+"**S"&8,%EZT
U"&%01,).FE+$.<4"880]C4"88V'&*OEZT
U"&%01,).FE+"1,"80D,%)A:B1.9EZT
U"&%01,).FE+$.<89'&.0-,*1.983$8EZT
U"&%01,).FE+,)4(9S"*0*,89Z]C4'1,8K3S"*\"-.OEZT
U"&%01,).FE+'(94(9S"*0*,89Z]C4'1,8K3S"*\"-.OEZT
U"&%01,).FE+S"&R,1.0*,89Z]C4'1,8K3S"&\"-.OEZT
UZS"W"T
US"W"0S"&FE]CV9$3K'-.OZ!,)ZG"*>''13S"&E0
R'&$FE9&(.E0
R",1').&&'&FE9&(.E0
186
Cooking Tips and How-Tos
,RFE4'1,8K3-,*4HE0
()1.88FE9.89E
-.88"%.FE;**,)%0#.&9,R,#"9.0R'&0*.W,#.0]C4'1,8K3,*.)9,R,.&OE
T
U"&%01,).FE+"**#.&9EZT
U"&%01,).FE+"1,"80D,%)A:B1.9EZT
U"&%01,).FE+$.<89'&.0-,*1.983$8EZT
U"&%01,).FE+,)4(9S"*0*,89Z]C4'1,8K3S"*\"-.OEZT
U"&%01,).FE+'(94(9S"*0*,89Z]C4'1,8K3S"*\"-.OEZT
?Ib"G"H
In the above example the signing is skipped when the test-mode is active or when the current device
does not support the MIDP/2.0 standard. It is assumed that the “midlets.ks” keystore is situated in
the same directory as the “build.xml” file.
Please note that the password needs to be specified as a property. This can be done within the
“build.xml” file or alternatively (for the more security conscious folks) on the command-line with
the -Dpassword=[value] option:
T0")90+B4"88V'&*F8.#&.9
In Mac OS X Wireless Toolkit the “JadTool.jar” is not available. It can be installed together with
J2ME Polish. In that case the path to the JadTool needs to be changed to
“${polish.home}/bin/JadTool.jar” in the above example.
GUI How-Tos
In the above example the dynamic style “form” is used for designing all Form screens. Form
elements will be added from left to right and from top to bottom of the table. The left column will
be 40 pixels wide, whereas the right column will use 100 pixels.
Find more information in the chapter “Specific Design Attributes” on page 120.
ZZn89<1.0-",)D#&..):9.-
-",)D#&..)3"44.)*20ED9"&90`"-.EL0)(11056
187
Cooking Tips and How-Tos
You then need to use static styles in the “polish.css” file. Static styles can have almost any
alphanumerical name and need to start with a dot:
3-",)D#&..)0C
4"**,)%/0h6
!"#$%&'()*+#'1'&/0<.11'V6
#'1(-)8/0H6
#'1(-)8+V,*9K/0b[L0Y[[6
O
In the last step you should refine your designs by adjusting them for different handsets. If you want
to make adjustments for the Sony-Ericsson P900 for example, you need to create the file
“resources/Sony-Ericsson/P900/polish.css”. In this file you can change any settings which you have
done in the basic “resources/polish.css” file. Remember that you only need to specify attributes
which are different, this makes subsequent changes easier.
Find more information on designing for specific devices on page 103.
188
Cooking Tips and How-Tos
U&.8'(&#.8
0 *,&FE&.8'(&#.8Z!'<E
ZT
P333Q0
UW"&,"!1.0)"-.FE41"<.&+V,*9KE0W"1(.FEYHE0T
UW"&,"!1.0)"-.FE41"<.&+K.,%K9E0W"1(.FEYHE0T
UZ!(,1*T
UZSH-.4'1,8KT
?I3".&13H
You can even define or alter <variables> to make further adjustments with the help of
preprocessing. You could define sprite-dimensions for example each or some of the <j2mepolish>-
tasks:
UW"&,"!1.0)"-.FE41"<.&+V,*9KE0W"1(.FEYHE0T
UW"&,"!1.0)"-.FE41"<.&+K.,%K9E0W"1(.FEYHE0T
These variables then can be used within the application with the use of preprocessing:
ZZn,R*.R041"<.&+V,*9K/*.R,).*
ZZnF0,)90V,*9K0F0]C41"<.&+V,*9KO6
ZZn.18.
,)90V,*9K0F0Y[6
ZZn.)*,R
ZZn,R*.R041"<.&+K.,%K9/*.R,).*
ZZnF0,)90K.,%K90F0]C41"<.&+K.,%K9O6
ZZn.18.
,)90K.,%K90F0Y[6
ZZn.)*,R
D4&,9.041"<.&0F0).V0D4&,9.2041"<.&:-"%.L0V,*9KL0K.,%K9056
Find more information on the <build> element on page 36. For more information about
preprocessing, please refer to page 78.
This example changes the “Cancel” command to “Abbruch” (German for cancel):
?G".$"+517H
?G".$"+51(%":1@A!/5$7B=,/::"%#=,"%,15A(G"501@Aa++.0,BAIH
?IG".$"+517H
How to Enable or Disable the Usage of the GUI for a Specific Device
J2ME Polish's GUI is deactivated by default for some older devices like the first version of Nokia
Series 40 models.
You can override this behavior by setting the “8(44'&98J'1,8K`(,”-attribute of the device in
question in the “*.W,#.83?-1” file, which is located in installation folder of J2ME Polish. When
the file is missing, re-run the installation and choose to install the “external device database” as
189
Cooking Tips and How-Tos
well.
Open *.W,#.83?-10and search the device in question. Now set the “8(44'&98J'1,8K`(,”-attribute
: It needs to be true, when the device should support J2ME Polish's GUI.
?#1G$,1
70!!/.37S/5$7B`0$@A2"571A(H
?$#1%3$2$1.HJ/-$"IN1.$17hK?I$#1%3$2$1.H
?f44("%#(7/(/%(44H
?I#1G$,1H
You can also override the settings in the device-database by setting the “(8.J'1,8K`(,”-attribute of
the <build>-element in the !(,1*3?-1 file to “always”. In that case the GUI will be used for all
devices, regardless of the settings in the device database.
Trouble Shooting
Compile Error
If you have a compile error within the J2ME Polish package or a compile error which seems to be
erroneous, please try a clean build: remove the “build” folder or call the “ant clean” before building
again.
Preverify Error
If you have a preverify error, please try a clean build: remove the “build” folder or call the “ant
clean” before building again.
190
Appendix
Appendix
Introduction to Ant
“Apache Ant is a Java-based build tool. In theory, it is kind of like Make, but without Make's
wrinkles.”
J2ME Polish uses Ant as its foundation for the build-process, therefore it is useful to get to know
Ant a little bit to make the most out of J2ME Polish.
The file “build.xml” is an XML based document which controls and configures Ant. The basic
syntax consists of the the <project>-root-element and several <target>-elements. Each <target>-
element is normally used to accomplish one or several specific tasks:
?!./b1,3(%":1@A1%/0&B4!/5$7B41L":!51A(H
?3".&13(%":1@A,51"%AH
?#15131(#$.@A+0$5#A(IH
?#15131(#$.@A#$73A(IH
?I3".&13H
?I!./b1,3H
In the above example we have one target called “clean” defined which uses two <delete>-tasks for –
who would have thought that – deleting two folders.
Assuming that Ant has been set up correctly (compare page 21) and that you are in the directory
containing the “build.xml” file, you can call each of the defined targets by calling “ant [target-
name]” on the command line. In the above example only one target is available, so you can only call
“ant clean”.
Usually there are several targets defined in the “build.xml” file. In that case it us useful to define a
default-target, which is executed whenever no target has been specified:
?!./b1,3(%":1@A1%/0&B4!/5$7B41L":!51A(
(((#12"053@AB155/A
H
?3".&13(%":1@AB155/AH
?1,B/(:177"&1@A[155/(d/.5#fA(IH
?I3".&13H
?3".&13(%":1@A,51"%AH
?#15131(#$.@A+0$5#A(IH
?#15131(#$.@A#$73A(IH
?I3".&13H
?I!./b1,3H
Now the “hello” target will be executed, when just “ant” is called from the command line.
Another powerful feature of Ant are properties, which are like variables with the difference that they
can only set once: after a property is set, it can not be changed anymore. This can be combined with
dependencies of targets to create complex behavior:
191
Appendix
?!./b1,3(%":1@A1%/0&B4!/5$7B41L":!51A(
(((#12"053@AB155/A
H
?3".&13(%":1@A#1!5/8AH
?!./!1.38(%":1@A#1!5/840.5A(
G"501@AB33!'IICCC=,/:!"%8=,/:I#/C%5/"#AIH
?I3".&13H
?3".&13(%":1@A$%$3AH
?!./!1.38(%":1@A#1!5/840.5A(G"501@AB33!'II5/,"5B/73AIH
?I3".&13H
?3".&13(%":1@AB155/A(#1!1%#7@A$%$3AH
?1,B/(:177"&1@AYB1(#1!5/840.5($7(ij#1!5/840.5;A(IH
?I3".&13H
?3".&13(%":1@A,51"%AH
?#15131(#$.@A+0$5#A(IH
?#15131(#$.@A#$73A(IH
?I3".&13H
?I!./b1,3H
In the above example the property “deploy-url” is defined in two targets – either in “init” or in
“deploy”. When we call “ant hello” or just “ant” the property will be “http://localhost”, because the
“hello” target depends on the execution of the “init”-target:
T0")9
e(,1*R,1./0!(,1*3?-1
,),9/
K.11'/
00000P.#K'Q0>K.0*.41'<+(&10,80K994/ZZ1'#"1K'89
e@:=B0D@77IDDg@=
>'9"109,-./0Y08.#')*
But when we call “ant deploy hello” the property will contain the value
“http://www.company.com/download” instead, since the “deploy”-target will be called first, then the
“init”-target (since the “hello”-target depends on the “init”-target) and last but not least the
“hello”-target:
T0")90*.41'<0K.11'
e(,1*R,1./0!(,1*3?-1
*.41'</
,),9/
K.11'/
00000P.#K'Q0>K.0*.41'<+(&10,80K994/ZZVVV3#'-4")<3#'-Z*'V)1'"*
e@:=B0D@77IDDg@=
>'9"109,-./0Y08.#')*
192
Appendix
Such properties can be use like any other properties within the “build.xml” script.
This closes the short introduction to Ant. We recommend either one of the many good books about
Ant or to consult the official Ant manual at K994/ZZ")93"4"#K.3'&%Z-")("1Z0for further
information.
193
Appendix
Licenses
J2ME Polish is licensed under the GNU General Public License (GPL) as well as several
commercial licenses.
GNU GPL
You can use the GPL license for projects, which are licensed under the GNU General Public License
without limitations.
More information about the GPL is available at these sites:
" http://www.gnu.org/licenses/gpl.html
" http://www.gnu.org/licenses/gpl-faq.html
Commercial Licenses
If the source code of your mobile applications should not be published under the GNU GPL license,
you can use one of the following commercial licenses:
! Single License
The single license can be used for the creation and distribution of one mobile application.
! Runtime License
The runtime license can be used for the creation of any number of mobile applications. The
drawback is that all applications together can be installed/sold only a 100 hundred times.
! Enterprise License
The enterprise license allows to create and sell any number of applications.
The pricing and license terms can be obtained at K994/ZZVVV3SH-.4'1,8K3'&%Z1,#.)8.83K9-1.
194
Contact
Contact
!"#$%&'(#)*+,-!
!"#$%&'()%*+,
("%'-$.'/&$)0&"%'123
13145'6%$.$0
7$%.809
:$;$<="0$ >?@'A'B4C?12'A'@3'3@'252
D8E >?@'A'B4C?12'A'@3'3@'251
F"#);$ >?@'A'B4C2G4'A'HH'33'145
IJF8); K1.$<";),=L$0"+M=N-$'
O$# PPPN$0"+M=N-$
195