Thursday, May 28, 2009

A Swing component to display last keystroke and keystroke history

A Swing component to display last keystroke. Also shows the keystroke history.

How it works

The KeyLabel component registers a global listener for KeyEvents using:
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
On receiving KEY_RELEASED event formats the KeyStroke as a string and displays it. The dropdown shows history of last 100 keystrokes. Clicking on the X (Clear KeyStroke History) button clears the keystroke history. The KeyEvent listening can be suspended by deseleting the checkbox.

JComponent keyLabel = KeyLabelFactory.createKeyLabel();
// Use keyLabel in your application's statusbar

Download (KeyLabel.jar)
> java -jar KeyLabel.jar
Screenshot of KeyLabel Demo

Source Code

Wednesday, May 27, 2009

Error launching Mozilla (only from inside Eclipse) using simple Runtime.exec() on Ubuntu.

I discovered that, on Ubuntu 9.04, I cannot launch mozilla browser using the simple invocation of Runtime.getRuntime().exec("/usr/bin/mozilla"). It turns out, I have to use the variant of exec() where I can pass in some environment variables explicitly.

Here is the program that I used to test it:

public class MB {

* @param args
public static void main(String[] args) {
try {
Process exec = Runtime.getRuntime().exec("/usr/bin/mozilla"
// Uncommenting out following line will launch mozilla browser on Ubuntu
//, new String[] {"DISPLAY=:0.0", "HOME="+System.getProperty("user.home")}
} catch (IOException e) {
} catch (InterruptedException e) {

Very interesting. May be that is why Eclipse has trouble launching help in default external browser on Ubuntu.

UPDATE: It turns out that this fails only if I run the above program from inside Eclipse. If I run it from a terminal window it works. It turns out that Eclipse sets an environment variable MOZILLA_FIVE_HOME to point to /usr/lib[64]/xulrunner-addon to make the SWT's embedded browser widget work correctly. However this environment variable is inherited by any process that is launched from within Eclipse. And apparently MOZILLA_FIVE_HOME inteferes with the Mozilla browser (/usr/bin/mozilla) launch.

Two issues have been filed in Eclipse Bugzilla:

Sunday, May 17, 2009

MultiPage Editor Tab Traverse Eclipse Plug-in

The MultiPage editors such as plug-in manifest editor do not support navigation of tabs (pages of the editor) using keyboard. This plug-in implements that functionality for any MultiPage editor that subclasses org.eclipse.ui.part.MultiPageEditorPart and uses org.eclipse.swt.custom.CTabFolder to implement the tab folder.


Starting with Overview tab:

Type CTRL+TAB to go to Dependencies tab:

Type CTRL+SHIFT+TAB instead to go to tab: