Wow! Java (Swing) doesn't have to look crappy!

I have a long love-hate (well, mostly hate-hate) relationship with Java.  I used to be a Swing hacker, in my callow youth, and the whole experience left me feeling pretty bad about Java GUI programming.

Over the years, I've watched as Java has gotten better and better native look and feel on Mac and Windows, but every time I've started a Java application on Linux, it's time to party like it's 1995; the default "Metal" look is reminiscent of a souped-up Motif, and clashes terribly with my desktop.

Totally by accident, I discovered this gem on stackoverflow...

This page explains how the work with Look&Feels: http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/plaf.html

You can do it commandline:

java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel MyApp
... and my jaw dropped.  Really?  It's that easy?  I tried it with my favorite Java GUI application, Tiled - and here it is, not looking like crap:



As with every native look and feel, it's not quite right.  The behavior of 'tab' is off in a few places, there are tons of things that should be keyboard-focusable but aren't... but it's a huge improvement.

I still have no idea why this isn't just the default behavior on Linux — although I'm sure I have a few fun inexplicable segfaults to look forward to — but I'm certainly going to enjoy using Java applications quite a bit more now.

Programming (And Markup) Languages I've Learned In Order

Catching up with some blog backlog, I saw this post from James Tauber and it looked memeish.  I think my list is interesting:
  • HyperTalk
  • SuperTalk
  • AppleScript
  • CSH
  • Bash
  • HTML
  • POVRay
  • C++
  • Emacs Lisp
  • VRML
  • Java
  • Perl
  • Scheme
  • C
  • x86 assembler
  • Python
  • Squeak Smalltalk
  • Common Lisp
  • Ruby
  • JavaScript
  • ActionScript 3
I would consider myself proficient in the boldface languages, and use them all frequently.

Languages I intend to learn in my copious spare time:
  • C#
  • Erlang
  • Haskell

After These Messages, We'll Be Right Back

Do you have an account on Blendix?  Did you know that you can find out all kinds of interesting stuff about me on my Blendix page?  Or that, if you sign up, you can get notified on your dashboard when I do something new?

I have no problem with self-promotion, but I tend to do it indirectly, in pursuit of making some point that I hope my audience will find interesting rather than just coming out and saying it.  But this weekend I discovered that not even my own sister knew we'd launched this thing — even though I mentioned it when it launched back in January!  I guess I'm not being clear enough!

So here's clear for you.  TRY BLENDIX! :-).

We have a bunch of new development happening on Blendix now, but it's been useful for a while already.  It's useful if your friends use it, since, like other services, your friends can update their list of feeds, and you'll be notified of new things.  On Blendix, though, if your friends don't have accounts, or are lazy, and don't update their pages, you can create your own version of them with more information that is useful to you.

Now, back to our regularly scheduled programming.

exarkun for president

Jean-Paul Calderone is an amazing hacker.

So, here's the setup.  We're working on this application that runs in the Adobe AIR runtime.  We implemented the AMP protocol for client-server communication.  Superficially, it worked great; limited tests gave us good results.

Then, we started throwing some real data at it.  And it choked.  The runtime would terminate its client socket silently: it would stop delivering data to application code, send a TCP FIN to the server, and not even deliver an event indicating that the socket had gone away.  Nothing.  Nowhere to set a breakpoint, nothing to debug.

The Python implementation of this protocol worked fine; everything got delivered.  The connection was not dropped unless we told it to drop.

I spent all night poring over protocol dumps, trying to figure out what was going wrong.  There were slight differences in where in the data stream it was dying - but for some reason, always cleanly, on a message boundary.

So, I come into the office and I fire up the program and show JP.  We get a tcpdump, and he looks at the output.  He squints at it for a few minutes and says:
"Huh.  It died on message 64.  That's interesting...
Oh wait, that's hex.  What's 64 in hex?  100.
... thoughtful pause ...
Maybe the garbage collector is buggy?"
He was right.  The bug was in the garbage collector.  AIR apparently doesn't think sockets (and apparently, other stuff, like animations) are "real" things that should keep strong references to the things they are feeding events to - so, sometimes they just crap out and get garbage collected, and silently stop delivering events.

The Ultimate Ubuntu / PulseAudio Guide

After writing about how great Hardy was, I suddenly started experiencing mysterious crashes of various applications on my desktop.  That'll teach me to say anything nice about an operating system!  Firefox, Pidgin, Deskbar, and even the Gnome Panel would periodically freeze up.  It seemed particularly exacerbated by running applications in the Flash and AIR runtimes — which was pretty bad news, since I am supposed to be writing some code in Flex!

Eventually, I caught one of these programs in the act, and traced the buggy behavior down to the PulseAudio daemon.

Apparently this is a common problem, with a bewildering array of elaborate and perplexing "solutions".  I spent hours trying to figure out some kind of combination of ALSA and Pulse tools that would get me out of the increasingly crashy situation on my desktop.  Oddly, nobody mentions the most obvious solution:

"Turn it off."

While I can appreciate the benefits that Pulse will (eventually) bring, it seems that it doesn't actually do anything for me today.  The main idea is that Pulse will allow me to play and record multiple sounds simultaneously.  However, the out-of-the-box Ubuntu ALSA experience allows me to do this with my current sound card.  I don't pretend to understand why — maybe my card supports multiple channels, maybe things are using dmix somehow — but there is no problem to solve.  Running the pulseaudio daemon actually has the opposite effect: sounds from multiple programs stop working.

I wanted to remove the pulseaudio package, but it turns out that would remove the ubuntu-desktop package as well, which means everything will probably be broken (certainly when I do my next major upgrade).  So, here's an alternate and non-obvious way to turn it off, without any fancy configuration:
  1. Go to the "System → Preferences → Sound" in your menu.
    http://www.twistedmatrix.com/users/glyph/images/content/blogowebs/sound-menu-item.png
  2. Make sure none of the devices say "Pulse Audio"; they should all say "Autodetect", "ALSA", or something more specific.
    http://www.twistedmatrix.com/users/glyph/images/content/blogowebs/nothing-says-pulse.png
  3. Click on the "Sounds" tab, and make sure that the "Enable software sound mixing (ESD)" checkbox is un-checked:
    http://www.twistedmatrix.com/users/glyph/images/content/blogowebs/quote-esd-unquote-disabled.png
  4. Log out, and let it trouble you no more.
I got a little chuckle out of discovering the "ESD" footnote, but it turns out that really means "PulseAudio" these days.

Better luck next time to the Ubuntu audio team!  I look forward to using all these cool pulseaudio gadgets next time.  I hope skype, flash, air, and the dozen other proprietary-and-wrong audio apps out there get fixed before Intrepid hits the shelves.