Wednesday, June 24, 2009

LWUIT RTL support announced at Java Tech Day



Last Monday in the Sun Java Tech Day 2009 (A mini-JavaOne held in Israel) I announced together with the LWUIT team the new support for RTL (Right-to-Left) languages in LWUIT.

LWUIT is a UI toolkit from Sun for the JavaME platform. JavaME suffered for quite a while from lack of a reasonable UI framework. The basic components it provides are well... very basic... And also not very portable across devices, which made developers to adopt other solutions such as developing their own UI frameworks internally or use other frameworks such as J2ME Polish.

And then came LWUIT which was announced a year ago in the JavaOne conference. It offers an entirely different mobile coding experience, and gives developers complete control over the UI. In fact it is resembles Swing a lot and gives the mobile developer tools which he/she never dreamt of... (except nightmares...)

Moreover, it is open sourced, and unlike other JavaME UI solutions it is free to use for any purpose, including commercial. And let's not forget one more fact that seperates it from other solutions, it is not a 3rd party add-on, it comes from the "source" itself, the developer of the JavaME platform, Sun.

I have been engaged with LWUIT for the past year in my capacity as a consultant - helping companies figuring out if it's worth migrating to, building a UI architectures over LWUIT, designing it and even "getting my hands dirty" sometimes and coding... I have to say that my experience shows that this is a truly robust framework, and a real breakthrough for the JavaME world. Like everything else it has its issues and bugs, but overall it is definitely what we all needed a long time ago...

One of the things LWUIT was missing was proper support for right-to-left languages such as Hebrew and Arabic. This of course doesn't bother everyone, but here in our local market in Israel, it is certainly something the LWUIT team was asked about.

So, Telmap, a mobile mapping and navigation company, which is one of my clients picked up the glove, and sponsosred a full project for adding RTL support to LWUIT. The project was done by myself and after a few months of work - it is here, and will be contributed back to the LWUIT community later this year.

The support is full and thorough and includes the following:

* Components - All the basic components LWUIT offers (Label, Button, RadioButton, CheckBox, ComboBox, TextArea etc.) support the RTL mode and are rendered accodinglty (i.e. in checkbox the box would be to the right of the text).

* Padding/Margin/Alignement reversal - A main concept of the solution is enabling seamless and easy "porting" of an English/LTR application to a Hebrew/RTL one. So, when the RTL flag is turned on, LEFT becomes RIGHT and vice versa. Why? Because if you had an app with a list of bullets that had a left padding of 10 pixels, it would make sense that the hebrew version of this app will feature these bullets in the right side of the screen, and with a padding of 10 from the *right* side and not left padding. So instead of having to provide different values to your English and Hebrew version, everything is reversed and transparent to the developer.

* Layouts - All layouts support RTL and components added are added from right to left when applicable. For example in a horizontal BoxLayout everything will be aligned to the right, in a GridLayout of 3x3, the first component you add will be in the top right, the second one in the top-middle, third in the top-left and so on. This of course includes right-to-left focus traversal. BTW - In BorderLayout WEST becomes EAST and vice versa.

* Bitmap Fonts - One of the problems when using RTL languages, is what happens when it is mixed together with LTR text and/or numbers, the text direction of each segment can be different, which makes things difficult. When drawing such mixed text in system fonts, usually the handsets marketed in the relevant markets already support a bidirectional (BiDi) algorithm that fixes this, but for bitmap fonts, we have to do it on our own - so a BiDi algorithm was added and is applied when a special flag in LookAndFeel is activated.

* Text input - TextField also supports bidirectional text input, including placing the cursor where it should be (Not very easy in mixed LTR/RTL texts...).

* Horizontal List - Supports now RTL in all of its modes, all items are added from right to left.

* Misc - A lot of other behaviours were modified when the RTL flag is turned on, such as reversing the ticker direction in Labels, reversing the horizontal slide direction, the vertical scrollbar is always on the left side etc.

That's about it, I'll update here when the code is officially contributed back to the LWUIT source base and can be downloaded. For other LWUIT updates check Shai's LWUIT blog and to download it and start working you can go to LWUIT's homepage or simply download the new JavaME SDK 3.0 which includes LWUIT.

5 comments:

Zahid Ishaq said...

hi!
Currently i am working in a j2me project use some rtl launguages. i want to use bitmap or true type font.
how to use With LWUIT frame work .i want to show any example.
thanks in advance
zhaid

Ofir Leitner said...

Hi Zahid,

When the RTL contribution will be released (later this year), you will be able to use RTL languages without any problems - it will be completely transparent. Since the RTL support is not public yet, I can't give code examples, but in any case, even if it was public - you wouldn't see any difference, since it really is transparent.

The RTL support includes bitmap fonts as well.

Hope it helps.

genial said...

great full of infos.. thnx for sharing this :)

farhan said...

hi!.
Thank for de gr8 post

Anonymous said...

Hi, Did they add this contribution or not yet?