Thursday, September 25, 2008

Using Styles, Themes, and Painters with LWUIT

Biswajit Sarkar wrote an interesting article for about themeing and styling LWUIT. The article features helpful diagrams and illustrations to explain some of the UI concepts behind LWUIT themeing.
The article leverages the resource editor which is a very good thing since the resource editor is indeed somewhat under documented.

Tuesday, September 23, 2008

Exciting Changes To LWUIT

A super geek like myself is excited about game development as much as he is excited about accounting software (I know I wrote both), in my case the new testing and recording framework I just committed to LWUIT are remarkably exciting and I don't think you need to be a hardcore geek like myself to get excited (am I delusional?).
I will try to write additional posts explaining what is going on and how you can use this in your applications but since this is all under heavy development and WILL CHANGE... SIGNIFICANTLY! I don't want to go into too many details.
Generally what you see here is the LWUIT demo mostly unchanged, you can adapt any application to support this and when you remove those lines of code the application doesn't have a trace of that functionality. Currently long clicks on the numbers 1,2,3 & 4 are assigned to the testing framework:
1: starts recording every operation I perform.
2: opens the assert screen where I can assert various states of the UI such as the label of the focused component or whether an exception was thrown.
3: Stops recording and names a script.
4: Opens the script manager where I can rename, delete & play my scripts (hopefully edit too in the future).

Scripts are stored using a model of their own so they can be stored anywhere the user wants to e.g. RMS, filesystem or even the network (in this example in RMS). Scripts can theoretically run on every device or simulator unchanged but this has some issues such as applications behaving differently in different resolutions might not be a bug...

I will blog more about this in the coming weeks as the code and logic finalizes and becomes more concrete.

Sunday, September 21, 2008

How Fast Is LWUIT? Check For Yourself

Performance is one of the main points of focus when working on small devices, speed and memory size are remarkably important and often contradictory requirements. Its very hard to deal with customer complaints of performance since this sort of behavior is very subjective to perception and hard to quantify, often devices would slow down during networking operations (since they grant the native network thread higher priority and ignore Java's thread priorities). On many occasions we would get complaints relating to a specific device performance and it would be very hard for us to see what specifically is taking time to perform on the given device.

To this extent we chose to develop LWUITSpeed which tries to stress a device VM as much as possible and produce a summary for performance on a given device. This summary can be reviewed and particular points of low performance for the device can be optimized, this tool is great both for optimizing LWUIT and has been used to optimize our native VM graphics libraries as well.

We hope you too can make use of this tool both to evaluate LWUITs performance and align your expectations for the performance of a specific device, this tool is now open source in the LWUIT source control repository.

Thursday, September 18, 2008

Cooking With LWUIT: The Movie

As I discussed the other day, Kirill inspired me to adapt the cookbook UI for LWUIT and mobile devices. The fact that it took me so little time and effort to accomplish a great UI mockup is a pretty decent testament to the power and flexibility of LWUIT.
Frankly there is so little work to do here it doesn't really justify too many separate posts... I started off with building a cookbook theme and adding some cut up images into it (pictured on the left) the rest was just creating the appropriate renderers and placing the content into LWUIT. As icing over the top I added some transitions to make everything work as one would expect.

The code is trivial.

Most of the lesson learned is in adapting photoshop design from the web and application world to the world of mobile devices. This mostly consists of removing UI elements and splitting the screen into smaller portions of importance within the application. The initial design didn't have any menus making the adaption even simpler in some cases.

The first video shows the cookbook running on the simulator while the second video here shows this running on a series 40 Nokia device with 2mb of ram.

Tuesday, September 16, 2008

Cooking With LWUIT Preview

Inspiration is powerful stuff, Kirill's blog often inspires and educates me (highly recommended even for non-Swing developers his blog is very informative on all things GUI). This past week he featured an excellent series covering the subject of creating a UI from a photoshop mockup, this is a remarkably common task with very little coverage especially when considering the amount of times we get asked to perform this task.

Rather than just pick up any application Kirill focused on an application that never really existed and has an imaginative mockup photoshop UI, he did an impressive job in showing off the power of his excellent (and gorgeous) Swing Substance Look And Feel. Can something like this be done in LWUIT???


Sort of... Maybe. But not quite.

The UI is remarkable in its use of textures which have rather elaborate underlying special effects not really feasible on a phone what we can do is "cheat", we can use pre-rendered textures to reach a very similar effect. We also need to adapt the UI which just won't fit on even the largest phones available...

Unlike Kirill's series which deals with replicating 1 to 1 the photoshop design, this series is geared towards adapting an existing design used in applications or websites in order to move it to the cellular environment. I will write more about this in the next post and explain some of what I did but for now enjoy the teasers, a screenshot of the cookbook UI in LWUIT and the original cookbook image.

BTW any artifact you may see in the LWUIT image is purely my bad skills at gimp/photoshop shining through... I needed to do some cleaning up of the images and without a graphics department for this blog the quality leaves something to be desired ;-)

Sunday, September 14, 2008

Porting LWUIT Part I: Basics Of The Porting Layer

This series is intends for hackers who wish to port LWUIT itself, not for developers wishing to port applications written in LWUIT. LWUIT is portable on two fronts, the first allows us to run applications developed in LWUIT in many platforms. The second allows us to adapt LWUIT to additional platforms such as CDC, Android etc...

LWUIT's portability is achieved by abstracting the underlying platform in a porting layer which consists of 3 main classes and a few optional classes: Graphics, Implementation and SystemFont. All of these classes are very system specific and require the porting to additional platforms to take them into account, additionally a port might want to either remove or adapt the classes: MediaComponent, Transition3D, M3G and Log.

Since the other classes in LWUIT make use of these classes all we need to do in order to port LWUIT is create a build.xml file which copies the existing LWUIT code base and deletes these files. We then need to compile with our version of these files that makes use of the new API, e.g. when porting to CDC we no longer have GameCanvas of which the Implementation class derives, so we derive from java.awt.Component which is the closest counterpart.

The implementation class is completely hidden within LWUIT since it contains many hidden implementation details that are subject to change. However, several of its methods are used by LWUIT itself and this allows us to ease the porting work considerably. Since the class is hidden its API isn't "documented" and so it is likely that the task of porting will change in some ways in future versions of LWUIT (e.g. as we add functionality to LWUIT the implementation class would be modified/enhanced).

To understand this better the Implementation class in the Android port is based on the android.view.View class, while the LWUIT Graphics class delegates everything to the class. In the Java SE port, the implementation class is a JComponent while the Graphics class delegates to the java.awt.Graphics2D class.

Thursday, September 11, 2008

Yoav Demoing LWUIT For SDN (Sun Developer Network)

Yoav Barel the manager of the operator group and a major driving force behind LWUIT is interviewed here in the Sun Developer network videos. Without Yoav's vision and support we wouldn't have LWUIT it would never have reached the market and never would have become open source.
This discussion is a great summary introducing LWUIT.

Wednesday, September 10, 2008

Animated Focus Transition For Regular Components

Lists in LWUIT have a great animation by default to show the transition between elements in the list. Components placed in the form don't have that animation by default, but they can thanks to the ability to infinitely customize everything about LWUIT.
The animation is comprised of motion objects tracking the transition from one element to the next and painting an overlay before setting the actual focus element, the code is really very simple...
class FocusAnimation extends Form {
private Component futureFocus;
private Motion focusMotionX;
private Motion focusMotionY;
private Motion focusMotionWidth;
private Motion focusMotionHeight;
public FocusAnimation() {
super("Focus Animation");
for(int iter = 1 ; iter < 5 ; iter++) {
addComponent(new Button("Button " + iter));
addComponent(new TextArea("Multi-line text\nwith several\ndifferent lines", 3, 20));
addComponent(new List(new Object[] {"Entry 1", "Entry 2", "Entry 3"}));
addComponent(new ComboBox(new Object[] {"Entry 1", "Entry 2", "Entry 3"}));

public void setFocused(Component c) {
Component current = getFocused();
if(current != null && current != c) {
futureFocus = c;
focusMotionX = Motion.createSplineMotion(current.getAbsoluteX(), futureFocus.getAbsoluteX(), 300);
focusMotionY = Motion.createSplineMotion(current.getAbsoluteY(), futureFocus.getAbsoluteY(), 300);
focusMotionWidth = Motion.createSplineMotion(current.getWidth(), futureFocus.getWidth(), 300);
focusMotionHeight = Motion.createSplineMotion(current.getHeight(), futureFocus.getHeight(), 300);
} else {

public void paint(Graphics g) {
if(futureFocus != null) {
g.fillRect(focusMotionX.getValue(), focusMotionY.getValue(),
focusMotionWidth.getValue(), focusMotionHeight.getValue(),

public boolean animate() {
boolean val = super.animate();
if(futureFocus != null && focusMotionX.isFinished()) {
futureFocus = null;
focusMotionX = null;
focusMotionY = null;
focusMotionWidth = null;
focusMotionHeight = null;
return val || futureFocus != null;

Sunday, September 7, 2008

LWUIT Application Alert: PaderSyncFM & MyWidz

One of the cool surprises we get is when someone just releases a LWUIT application out of the blue. A couple of such applications came out recently that seem very cool and attractive, first is Pader Sync File Manager which has been around for quite some time. They decided to overhaul their UI using LWUIT and are prompting this as one of the main features of their new release.
It seems like a cool and useful application but I had trouble with it under Symbian where you can't really control permissions properly (manufacturer/operator restrictions are really limiting here).

The other application is MyWidz it offers a widget based experience for installing widgets on the cell phone, seems somewhat similar to the Hydrazine project from Sun.

Wednesday, September 3, 2008

Running On The Smasung F480

I just uploaded a video showing LWUIT on the Samsung F480. This is one of the most impressive devices running LWUIT so far since it is running a high quality VM with proper 3D support on a touch screen device. This allows us to show off practically every featue of LWUIT on a single device.

If you are demoing a LWUIT application this device is high performance and allows your application to really shine, I highly recommend it.

Monday, September 1, 2008

LWUIT Running On The HTC Touch

This video shows LWUIT running on the HTC touch device using the PhoneME open source VM from
PhoneME is very fast and provides a high performance user experience on this device. However, the open source version doesn't have 3D support so we can't really demo those features in this device either.

Chen chose to use the stylus for this device since the touch screen doesn't respond well to direct touch by fingers.