woensdag 6 april 2011

Asynchronous interface... the good, the bad and the ugly

Figuring out how to make my GUI run smooth even when CPU intensive or I/O blocking operations (HTTP requests...) are running was what I did this week.

As I already knew, Swing isn't inherently multithreaded, so I have to coordinate all efforts with "SwingWorkerTask"s. Doing so isn't hard (although ugly at times... I'll probably wrap the ChangeListener that's used for updating the GUI based on current progress of the task in something decent that doesn't require string comparisons to know what happened).

I did this for the most notorious of all blocking operations in Scarlet Nebula: listing machine images. This can often take 10-15 seconds, possibly more. Although the technical side of this isn't difficult, from a UI perspective it is.

Things I tried this week:

  • A small modal dialog window, possibly without controls containing only a progress bar. The way VLC does it for rebuilding font buffers.
    • The Good: easy to implement, cancellable
    • The Bad: Causes an extra level of nesting
    • The Ugly: looks like crap, obscures part of the UI
  • Change the cursor to a busy cursor and disable the table
    • The Good: users are familiar with the busy cursor and know something is happening
    • The Bad: the whole cursor thing in Swing sucks. The cursor only changes after the user moves his mouse; it's tricky to find all the different ways of leaving that screen, if one is forgetten the user will spend eternity with a busy cursor
    • The Ugly: /
  • Insert a progress-bar or some other status indication device into the GUI itself.
    • The Good: easily recognizable, in my opinion the prettiest of all 3 options
    • The Bad: Doesn't look perfect, not cancellable (although that's not strictly necessary, the user can type in a new search term)
    • The Ugly: /
After trying all three I decided to go with the third option, only with a "throbber" and some text instead of a progress bar. The end result:
The throbber is obviously animated and the whole white bar appears and disappears when needed. If I ever have some time to spend, I can even animate the appearance and disappearance of the white bar...

Geen opmerkingen:

Een reactie plaatsen