Friday, October 30, 2009

Chinese characters in resource bundles

I had a difficult time to implement Chinese characters for my SWT application. I was using resource bundle for internationalizing the application. While creating resource bundles for Chinese characters I noticed that resource bundles will accept only ASCII and Java is not able to read UTF-8 resource bundles.I was using eclipse as my development IDE.

The following work around helped me to overcome the situation.

Open an existing MessageBundle.properties file outside eclipse using notepad. Enter Chinese characters for the translation you want and save the file in UTF-8 format. You can use google translation for getting the chinese characters.

Use the tool 'native2ascii' to convert the chinese charcters to unicode characters.

The syntax is like this:

C:\temp>native2ascii -encoding utf-8 MessagesBundle.properties Chinese.properties

The Chinese.properties file will contain Unicode characters for your Chinese letters in MessageBundle.properties. Then copy the content in Chinese.properties file and copy it to any MessageBundle.properties file created in eclipse.

The program will work fine displaying Chinese characters without any modification to source code.

http://forums.sun.com/thread.jspa?threadID=306155
http://forums.sun.com/thread.jspa?threadID=212238&tstart=121351
http://java.sun.com/developer/technicalArticles/Intl/IntlIntro/
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/native2ascii.html

Tuesday, October 27, 2009

ini file which helps you to preserve comments while updating

I have faced a difficult situation where one of the scenario require to write and preserve comments in configuration file. I tried using properties file and ini file concept using java. But when we write back to the file for storing configuration information, the entire comments in the proprieties or ini file get lost.

At last after a frantic search, I got the following free library which will help you to store configuration in an ini file where you can read and write and it will preserve any comments wrtitten at the top of the file.

http://ini4j.sourceforge.net/tutorial/IniTutorial.java.html

Format date in Lotus script

Below post helped me to format date in Lotus script

http://www.joelitton.net/A559B2/home.nsf/d6plinks/JLIN-5UU4B2

I made changes to the code and below code will format the date value in a field of document.

Dim session As New NotesSession
Dim dateTime As NotesDateTime
Set dateTime = session.CreateDateTime ( deliveredDate )
print " : " & Cstr(dateTime.LocalTime ) & " GMT Time :" & Cstr(dateTime.GMTTime)

Dim dtGMT As NotesDateTime
Dim strRSSDate As String

Set dtGMT = New NotesDateTime( Left$(dateTime.LocalTime , 22) )
strRSSDate = Format$(dtGMT.LSLocalTime, "dd-mmm-yyyy hh:mm:ss AM/PM")

ReplaceAll function in lotus script


Code snippet to stimulate replaceAll function in lotus script

Function StringReplaceAll(Byval strArg As String, Byval strSrc As String,Byval strDst As String) As String



Dim iPos As Integer
iPos = Instr(strArg, strSrc)

While iPos > 0
strArg = Left$(strArg, iPos - 1) + strDst + Mid$(strArg, iPos + Len(strSrc))
iPos = Instr(iPos + Len(strDst), strArg, strSrc)
Wend

StringReplaceAll= strArg

End Function


The function call
StringReplaceAll("hello","l", "g") will give the result as 'heggo'

Dynamically moving scroll bar when dragging an object over an SWT Tree.

Dynamically moving scroll bar when dragging an object over an SWT Tree.

In the dragOver() event write the following statements:

event.feedback |= DND.FEEDBACK_SCROLL;

For expanding a tree, when mouse hover over it during dragging an object:

event.feedback |= DND.FEEDBACK_EXPAND;

The more details can be found at the below link

http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html

Wednesday, September 9, 2009

Disabling close button in SWT shell window

Below snippet of code can be used in a SWT dialog box to disable the close button on window.

//disabling the close button
dialogShell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
e.doit = false;
}
});

Center a SWT Shell on the screen

Below snippet of code can be used to center a SWT shell on the screen

//center the dialog screen to the monitor
Monitor primary = display.getPrimaryMonitor ();
Rectangle bounds = primary.getBounds ();
Rectangle rect = shell.getBounds ();
int x = bounds.x + (bounds.width - rect.width) / 2;
int y = bounds.y + (bounds.height - rect.height) / 2;
shell.setLocation (x, y);

shell.open();
shell.layout();

Below link will provide a brief idea about creating a splash screen using SWT

http://www.eclipsezone.com/eclipse/forums/t53291.html