BUG Community

Welcome! Log In

kschultz's Blog

SWT on the BUG

All BUG applications today use Java's original GUI library, the Abstract Window Toolkit (AWT). It runs really efficiently, but has limited featured compared to the modern widely used libraires. The primary alternatives are Swing, SWT, LWUIT and Java-GNOME. Swing and SWT are the most popular Java GUI toolkits today, and LWUIT and Java-GNOME are interesting but not as popular. Every Java devloper has a favorite in the Swing vs SWT debate, but for the BUG the choice is clearly SWT because it runs on phoneME Advanced while Swing doesn't. (With OpenJDK, both work just fine). SWT brings new  features to the table such as graphic support (see the scrolling telemetry app below) that were not easy with AWT before, with smoother animations. SWT's Linux theme is more modern as well.

 

A telemetry application on the BUG using SWT - not possible with AWT

It is relatively easy to begin using SWT on the BUG today. First you will need to put libSWT on your BUG. This provides the class files necessary to run SWT with phoneME on the BUG, along with the manifest file necessary for OSGi. Second, you need SWTDisplayProvider on the BUG. In SWT there is only one top level Display device. SWTDisplayProvider starts that device and provides and OSGi services so it can be used by multiple SWT applications on the BUG.

An SWT application needs to consume the ISWTDisplayProvider service, and import the SWT libraries.

Add SWTDisplayProvider and libSWT to the build path in Dragonfly. (Right click on the project, Build Path->Configure Build Path->Projects->Add)

Your MANIFEST.MF file should include these imports:

Manifest-Version: 1.0 Bundle-Name: BUGGraph Bundle-Activator: buggraph.Activator Bundle-SymbolicName: BUGGraph Bundle-Version: 1.0.0 Bug-Bundle-Type: Application Import-Package: com.buglabs.bug.module.lcd.pub, org.osgi.framework, org.osgi.util.tracker, com.buglabs.application, com.buglabs.util, com.buglabs.bug.module.lcd.swt.pub, org.eclipse.swt, org.eclipse.swt.accessibility, org.eclipse.swt.browser, org.eclipse.swt.custom, org.eclipse.swt.dnd, org.eclipse.swt.events, org.eclipse.swt.graphics, org.eclipse.swt.layout, org.eclipse.swt.opengl, org.eclipse.swt.printing, org.eclipse.swt.program, org.eclipse.swt.widgets

And your service tracker needs the following code,

In doStart():

ISWTDisplayProvider displayProvider = (ISWTDisplayProvider) getService(ISWTDisplayProvider.class); final Display display = displayProvider.getSWTDisplay();

In initServices():

getServices().add("com.buglabs.bug.module.lcd.swt.pub.ISWTDisplayProvider"); 

And if you want for a Hello World type application, add the following to the doStart() method:

final Shell shell = new Shell(display); shell.setText("HelloWorld"); shell.setSize(320, 240); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose();

Unfortunately, there is one hangup. While SWT will run just fine on the BUG, it will not work with this setup on the host machine. SWT relies on platform specific code which is not reflected in libSWT. We support various versions of Windows, Linux, and Mac OS X so it would be difficult to create every permutation of the SWT library as a BUG app to use.

The solution is relatively straightforward, you much create an SWT .jar file specific to your machine and include it for use with the Virtual BUG. Luckily, Eclipse relies on SWT so if you have the Dragonfly setup you already have an almost useable version of the .jar file.

I say almost usable because in most cases the Manifest file does not have the proper Export-Packages attribute to work properly for a BUG app. The solution is to unpack the .jar file, modify the Manifest file, repac the .jar file, and add it to the build path of your application.

The following commands can be used on a Ubuntu (GNU/Linux) system, I have not tried the equivalent on Windows. They can not be simply copied and pasted because versions differ so you will have to be familiar with the command line and have fastjar or other equivalent of jar to run these commands.

Locate your Eclispe directory

cp plugins/org.eclipse.swt.gtk.[arch/version specific].jar plugins/com.buglabs.dragonfly.bug.kernel_[version]/kernel/ cd plugins/com.buglabs.dragonfly.bug.kernel_[version]/kernel/ mkdir temp/ cp org.eclipse.swt.gtk.[version].jar temp/ cd temp/ jar xf org.eclipse.swt rm swt.jar

edit META-INF/MANIFEST.MF to read

Manifest-Version: 1.0 Bundle-Version: 3.4.2 Bundle-Name: swt Bundle-ManifestVersion: 2 Bundle-SymbolicName: swt Export-Package: org.eclipse.swt, org.eclipse.swt.accessibility, org.eclipse.swt.browser, org.eclipse.swt.custom, org.eclipse.swt.dnd, org.eclipse.swt.events, org.eclipse.swt.graphics, org.eclipse.swt.layout, org.eclipse.swt.opengl, org.eclipse.swt.printing, org.eclipse.swt.program, org.eclipse.swt.widgets 

(Note: the single space indentation of the packages matters)

rm (everything but MANIFEST.MF in META-INF) fastjar cf swt.jar org -m META-INF/MANIFEST.MF mv swt.jar ../ cd ../ rm -rf temp

Now open up Dragonfly. If you expand BUG Libraries in the Package Explorer view, you should see swt.jar along with the rest of the BUG libraries, and be able to use it in your SWT application.

Hopefully in the future I can streamline these instructions/come up with a more robust solution for the host platform, but rather than wait I wanted to put SWT in the wild. There will probably be some issues found as people try this on more systems, but don't hestitate to contact me by email, IRC, and of course the comments here.

 

Post Comments

Add Your Comment!

The essay writing services should be organized especially for university students, because they really need the outline essays created perfectly.
It's distinguished for customers to learn though, you need to buy term paper or buy research papers just because a school isn't the best at everything doesn't mean it can't be the matchless at certain things. Essays blogs can arrange more usefull for your function you can also buy essay. But first of all, my gratitude to this article, it has a first-class instigation.
My promise to you is that I will always strive to equip significance that provides tough value & benefit to you everytime you come to this page. Everytime you see here I want you to feel that it's time and money well spent. . I find it very beneficial especially when you need research paper services.

Really good knowledge just about this post. The students use the term paper writing service and buy essays or buy a research paper just about this good topic.

A lot of men are looking for facts referring to this post. So, that’s assertable to receive new information here freelance writers .

You have to be really fanciful guy to accomplish a kind perfect dissertation writing reffering to this post . I should buy a paper or thesis about it. Thank you very much!

You are making really very perfect research about this topic! Therefore, the dissertation writing services or some custom thesis writing services, could use as ground for the thesis write.

The buy thesis service could offer scholars with the thesis papers but the well done topic close to this good topic we could see on this page only.

I haven't spent much time in Java world, but couldn't you inject which SWT binaries you wanted at run time? Thus sticking to particular interfaces in your code... you could be multi-platform?

Really useful information, AWT is pretty clunky and SWT looks a lot nicer. I've only used Swing in the past but I could be converted to SWT. Can't wait for rev 1.3 and international shipping, Christmas may come early this year :-)

» All comments
» Comments RSS

Powered by Community Engine

Top
Login
Close
Bottom