Archive for November, 2007

New developer on ShareMedia

November 20th, 2007

The Sharemedia project has a new commiter : James Williams, who is working on the Flickr plugin. The current development version of this plugin lets you browse Flickr libraries directly in ShareMedia (read only). He already commited his work on SVN.

Unicode : the reason you need ICU for Java

November 20th, 2007

I learned recently that there are several ways to code accented characters in Unicode. As instance, a word like “Rivière” can be stored as :

R i v i è r e (composed characters)
or
R i v i e ` r e (combining characters)

At first, it seems to be only technical details. Most Java developers use Strings without taking much care of how it is stored internaly. Convertion problems happen sometimes but can be easily fixed in most cases.

But things are more complicated here. Java Strings can use the two forms and both are valid : Eclipse debugger displays the same value for each one. However if you try to use Object#equals on two equivalent strings which are not using the same form, the result is false.

This means that equals cannot be used to compare Strings. Other comparators supporting Unicode forms are available in the Java API, but you can choose to use them only in your code. If the comparation is done by a third party library, you have no choice than to convert the String from one form to another.

This can be done using java.text.Normalizer, but this is a Java 6 API. If you have to ensure compatibility with Java 1.4 or 5, one way is to use IBM’s ICU4J, which is available in the default Eclipse distribution as a plugin.

com.ibm.icu.text.Normalizer.compose(String str, boolean compat)
and
com.ibm.icu.text.Normalizer.decompose(String str, boolean compat)

So when do you need to use theses method ? ALWAYS !!
You never know when a library will choose to return a String in one form or the other because it is often unspecified.

This is exactly what happens with SWT : depending of the OS and the method you call you can get two Strings that are equivalent but return false when using equals.

Here is an example on OSX
* Text#getText() returns the first form
* a FileTransfer Drag and Drop returns paths in the second form.
See Bug 141282

In my opinion, a library should only use a single form and returning string of the other form should be considered as a bug. Otherwise developers have to do too many convertions all over the code to ensure that strings can be correctly compared.

SWT/JFace quick start (1 min)

November 9th, 2007

I was asked in my previous blog entry how to add SWT to a project classpath in order to run a simple snippet.
This for me the quickest way to run a SWT snippet from scratch :

Start Eclipse
swt-quickstart-1.png

Create a new plugin project
swt-quickstart-2.png
swt-quickstart-3.png
swt-quickstart-4.png

Go through the plugin wizard
swt-quickstart-5.png
swt-quickstart-6.png

Do not use templates
swt-quickstart-7.png
swt-quickstart-8.png
swt-quickstart-9.png

Add SWT dependency
swt-quickstart-10.png
swt-quickstart-11.png
swt-quickstart-12.png
swt-quickstart-13.png

Create a new class

Note : If you want to run a SWT snippet you even don’t need these steps. Just copy the snippet content and paste it in the package view. This will create the java class in the right package, ready to be launched. Then jump to the “run snippet” step.

swt-quickstart-14.png
swt-quickstart-15.png
swt-quickstart-16.png

Paste the snippet
swt-quickstart-17.png

Organize imports
swt-quickstart-18.png
swt-quickstart-19.png

Run the snippet
swt-quickstart-21.png

And voila
swt-quickstart-22.png

Once you got this working, you can start working with JFace or RCP, by adding the corresponding dependency.

Reopening SWT bug 141282

November 8th, 2007

I spent several hours to locate a SWT problem with DND and special characters in path on OSX. The hard part was that strings were are correctly displayed by SWT and work with the file API. But if you try to compare or check equality of this string with another one, it always fails because a special char uses 2 chars instead of one. This is only an encoding problem, but not easy to find.

See Bug 141282 on Eclipse
and Bug 97 on ShareMedia bugtracker

Dismanteling a Compaq laptop

November 3rd, 2007

Compaq Presario 2100Today I dismantled a Compaq Presario 2150 in order to replace the power connector which had bad contact problems. This was a far more precise work than working on a desktop computer. Parts can only be removed in one specific order that you have to guess, and you have to pay attention not to torn ribbon cables of keyboard and case. (See this usefull forum thread in french)

After a some soldering work the connector was replaced, but it did not resolve completely the problem. It turned out that the laptop doesn’t have power until you apply a presure to a specific point of the case. The motherboard is simply dying.

Anyway this was interesting and my first dismanteling & soldering work on a laptop (already did it on several desktop computers and my Playstation 2 :-) ) .
The problem is still there, but at least it is now fully identified. I put everything back together and it works better than before :-) .