Making SWT look more native on Mac OS

July 11, 2008 – 3:59 pm

Back in april, someone asked me if I had some thoughts about how to make an SWT app look and feel more like a real Mac OS application. Having only a couple days to think about it and the excellent Coda as a visual reference, I decided to create a silly file manager type application that would incorporate a unified toolbar, instead of the traditional ToolBar or CoolBar. The result was this rather silly looking contraption:

At that point, I could create a unified toolbar, populate it with the right contents, and even configure it using the default configuration mechanism. As I wasn’t sure where I was going when I started and with only three days to do something, I figured this would be a great opportunity to learn JNA, rather than start modifying the JNI layer of SWT. As is visible on the left side of the toolbar, I quickly found out how difficult it was to support segmented views the HIToolbar. I guess part of my problem was also that I have not written Apple code since the days of my Apple II.

After I gave the example to who had asked me, I started wondering about eclipse itself and the amount of work involved in transferring this little test to SWT, then to the Workspace. Within a couple days JNA was gone, and the same exact app was running on a modified 3.4M4 Carbon version. It was actually a lot easier than I had anticipated, a lot more than to try to convince the SWT team that this type of effort for the Mac and other platforms was actually worthwhile considering the leaps and bounds Swing made since they had started SWT. SWT is at close to (if not actually older) 10 years old… which in technology years makes it a dinosaur.

Once the code transfered to SWT, it was only a few more hours till I could do the same inside Eclipse.

As fate would have it, a couple days later I stumbled into a post on the SWT newsgroup made by someone asking the SWT team about their intentions in regards to supporting the Mac OS unified toolbar. I joined-in and asked their thoughts about moving parts of the classic Eclipse coolbar to the unified toolbar. The idea didn’t fly very far, and I was basically offered a lecture on the Apple ui guidelines, and how unfitting it basically was. Heaving read the document myself, I thought that the perspective switcher was actually a great candidate for relocation to the unified toolbar, while the rest would remain in a traditional toolbar (not unlike the division of labor in iWorks 08).

Up until then I was more preoccupied with how to wedge things in, rather than how to really make them fit meaningfully or properly. Having found out that it would not be too difficult to get something done, it was time to do the right thing (or at least something closer to it).

As a next step, I looked into wrapping this code inside an installable presentation that would also allow Mac users to move the switcher up the unified toolbar. Even though they offer a powerful way to configure Eclipse, custom presentation are not as flexible as one would expect. Some of the most fundamental characteristics of the Eclipse look are carved deeply in stone. In bug 229840 I started to track some changes to loosen things up via some enhancements to the current presentation definition.

Basically this is what some of the current workbench code looks like:

	private static int TILE_SPACING = 2;
	private static int LINE_SPACING = 2;
...
	totalMinor += (lines.size() + 1) * LINE_SPACING;

Not really a model of flexibility…

This is how I left things. SWT has two extra widgets MToolbar and MToolbarItem. These hide the details of supporting a the Mac OS unified toolbar in an SWT application. I also managed to get the segmented view code working and was able to display the traditional previous|next capsule style buttons. Buttons can have text and images, and the images can be custom org.eclipse.swt.Image instances or any of the OS provided default ones (via some constants I defined is OS.class). In order to get to the next, I’ll have to create a new toolbar and a new status control that will provide better control over its looks on all platforms. I have a name for it: Flatbar.

Enter this code

You must be logged in to post a comment.