Criticism on SWT

The Standard Widget Toolkit (SWT) is a graphical widget toolkit for the Java platform. It conceived as an alternative to the AWT or Swing toolkits provided by Sun Microsystems. It has the intent for better performance (to run faster and and to consume less memory), native look and feel and deep platform integration.

As there is already a lot of discussion about Swing and SWT on the web and I will not compare them again. I personally prefer SWT because I felt more productive with this toolkit. Nevertheless, I still did not yet feel productive enough to consider SWT valuable. Let me explain why.

Java and incorrect timezone on Windows XP

How reliable is Java date, time and timezone API? In this article I discuss a relevant issue that may compromise application correctness when relying not only on date/time calculations, but also on reporting date/time according to local timezone and locale.

Recently I was debugging an activity scheduling application that was reporting events to weird time. Even worse, the weird time varied according to the desktop PC the application was running on. First, we assured that all date/time calculations were done correctly. Then, we double checked if Java reads the correct date/time from the system. Also, date, time and timezone configurations were set properly on the underlying platform. The odd behavior appeared on Java Virtual Machines from Sun, both JRE 1.5 and JRE. What was happening? We compared Java API results to Joda Time API.

Create a front page for WordPress that does not show up twice

Note: I think this is not an issue anymore, since WordPress finally created the “menu” design feature. There is no need anymore to create front pages to show content as tabs at the top of the page. The “menu” feature works better than front pages.

Several people wonder how to configure WordPress to show ones own page when opening the blog (also called front page). There are instructions on wordpress support.

JFace table sorting

Nowadays, when the application displays as a table, the modern user expects to click on the the column header to change the ordering criteria. Unfortunately, SWT/JFace API have not yet implemented this feature transparently. The programmer is required to write a bunch of code to implement this feature on each table.
For this purpose, I have written a single class that listens to table columns and applies ordering to the table viewer.

When Java code becomes funny

Eventually, some fun happens while writing Java code.

Apache Commons: Error or Success?

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. (see Java API docs). Does it make sense to call such subclass “Error“?

Found at org.apache.commons.configuration.plist.PropertyListParser

Two way names

Particularly, the Eclipse naming convention resulted this interesting symmetric method declaration.

protected void initialize(ColumnViewer viewer, ViewerColumn column)

Printing java logger configuration

I have been wondering for some time how to print out a list with details how loggers were configured.
In order to work, one requires to create at least one logger instance of each logger that shall be listed.
I will provide further details in future.


public void print(PrintStream out) {
	out.println("Configuração de log: ");
	LogManager logManager = LogManager.getLogManager();
	Enumeration<String> loggerNames = logManager.getLoggerNames();
	Set<String> names = new TreeSet<String>();
	Set<Handler> handlerSet = new HashSet<Handler>();
	while (loggerNames.hasMoreElements()) {
		String name = loggerNames.nextElement();
		names.add(name);
	}
	for (String name : names) {
		Logger logger = logManager.getLogger(name);
		String nome = logger.getName();
		if (nome.length() == 0) nome = "<root>";
//		boolean inheritedLevel = false;
		Level level = logger.getLevel();
//		boolean inheritedHandler = false;
		Handler[] handlers = logger.getHandlers();

		Logger parentLevelLogger = null;
		if (level == null) {
			parentLevelLogger = logger.getParent();
			while (parentLevelLogger != null && level == null) {
				Level parentLevel = parentLevelLogger.getLevel();
				if (parentLevel != null) {
					level = parentLevel;
				} else {
					parentLevelLogger = parentLevelLogger.getParent();
				}
			}
		}
		Logger parentHandlerLogger = null;
		if (handlers == null) {
			parentHandlerLogger = logger.getParent();
			while (parentHandlerLogger != null && handlers == null) {
				Handler[] parentHandlers = parentHandlerLogger.getHandlers();
				if (parentHandlers != null) {
					handlers = parentHandlers;
				} else {
					parentHandlerLogger = parentHandlerLogger.getParent();
				}
			}
		}
		String nivel = "?";
		if (level != null) nivel = level.getName();
		if (parentLevelLogger != null) {
			if (parentLevelLogger.getName().length() == 0)
				nivel = "<root>:"+nivel;
			else
				nivel = parentLevelLogger.getName()+":"+nivel;
		}
		String lista = "?";
		if (handlers != null) {
			List<Handler> list = Arrays.asList(handlers);
			if (list.size() == 0) {
				lista = "";
			} else {
				lista = null;
				for (Handler handler : list) {
					if (lista == null) lista = handler.getClass().getName();
					else lista += ", " + handler.getClass().getSimpleName();
				}
			}
		}
		if (parentHandlerLogger != null) {
			if (parentHandlerLogger.getName().length() == 0)
				nivel = "<root>:"+lista;
			else
				nivel = parentHandlerLogger.getName()+":"+lista;
		}
		out.format(" - %s (%s): %s\n", nome, nivel, lista);
	}
	for (Handler handler : handlerSet) {
		String nome = handler.getClass().getSimpleName();
		String nivel = handler.getLevel().getName();
		out.format(" - %s (%s)\n", nome, nivel);
	}
}

Ubuntu 9.04: External and internal speaker issues

If you run Ubuntu 9.04 and your desktop or laptop is featured with both internal speaker and TRS jacks for external speakers, then you might face some issues that sound is played on both. I have written some articles where I propose some very simple solutions and you may try them and choose the one you like most.

Of course, I discarded any inappropriate solutions that were proposed in several forums: editing mysterious configuration files,recompiling the kernel and unplugging the internal speaker from the motherboard.

Ubuntu 9.04: External and internal speaker issues – part 2

If you run Ubuntu 9.04 and your desktop or laptop is featured with both internal speaker and TRS jacks for external speakers, then you might face some issues that sound is played on both. I have written some articles where I propose some very simple solutions and you may try them and choose the one you like most.

Issue 2: Connecting the headset does not turn off internal speaker.

Try to connect/remove a headset from the external jack and observe if your internal speaker becomes automatically muted. If not, then some more configuration is required.

Ubuntu 9.04: Microphone issues

Continuing the discussion of audio configuration issues on Ubuntu 9.04…

If you are using Skype, please also read my next article that discusses Skype on Ubuntu 9.04.

I suggest testing the microphone with the “Sound Recorder” that is found in the “Applications”->”Sound and Video” menu of the top bar on the Ubuntu desktop. Ensure that “voice, lossless (.wav)” (may vary according to your language) is selected. Click on “Record” and talk to the microphone. The “Level” bar should increase as you talk louder. Click on “Stop” and “Play” to hear if your voice was recorded sucessfully.

Ubuntu 9.04: Skype issues

This article addresses an issue similar to another that I have already adressed for Ubuntu 8.04: How to correctly configure Skype on Ubuntu 9.04.

First, I assume that Skype was installed from midibuntu.org repositories.

Issue 1: Speakers do not work.

The first required configuration change is setting Skype to use Pulse Audio Support instead of default (ALSA) sound drivers. Go to Skype->Options->Audio Devices. Select “pulse” for all audio devices.

I also recommend to disable an option like “Allow Skype to automatically adjust mixer levels” for this first moment. While this option was enabled, I have experienced Skype undoing the correct configuration and turning off my microphone volume before each call . After you manage to have Skype working fine, then you may enable this option again to see if Skype continues working fine 🙂