Sunday, July 15, 2012

Java Swing UI Quirks

In the enterprise world I don't get to doing desktop development often. A year ago I took over the maintenance of BDSup2Sub, a tool to convert and tweak bitmap based subtitle streams. This program is written in Java and uses Swing for the user interface. The original author mainly developed and tested it on Windows and did not polish the UI for other platforms. These days Ubuntu Linux is my primary desktop operating system (followed by Mac OS X) so I did some polishing.

Both the JVM GTK+ Look and Feel and the Ambiance theme in Ubuntu 12.04 could use a little love. While one could argue here that the bugs should be fixed in those projects instead of introducing workarounds in the applications the process is slow or fixes will never be backported to the currently stable releases.


Major annoyances

  • unreadable menu bar
Unreadable menu bar

  • dropdown menus and popups are missing borders and dropdown-shadow
Dropdown menu without borders and shadow
Popup menu without borders and shadow


  • missing menu separator
Missing menu separator

Determining the actual Look And Feel and theme

I am going to describe workarounds for the GTK Look and Feel, and one of them is only applicable for the Ubuntu Ambiance theme. I wrote some convenience methods to determine the current Look And Feel and the theme name:


Unreadable menu bar

This one is a JVM bug exposed by the Ambiance theme in Ubuntu 12.04. According to the bug report it is fixed in Java 8, but not (and never will be) in 7 and 6.

The JVM picks up the wrong colors so we have to set them explicitly. We can create a class for the action menus and use that instead of JMenu:



Menubar with correct colors

Missing borders for dropdown menus and popups

This could be actually fixed in the theme file but remember, the application should work out-of-the-box, so let's fix it by tweaking the theme in Java. The method below changes the style for the popup menus and sets the xThickness and yThickness fields to a sensible non-zero value. We have to create a JPopupMenu instance for its style to get updated and then the original SynthStyleFactory can be restored.


You can see the result on the screenshots below. They were taken after applying the fix from the next section so besides the border they also show the dropdown shadow.
Dropdown menu with borders and dropdown shadow
Popup menu with borders and dropdown shadow

Missing dropdown shadow for dropdown menus and popups

A Swing popup can have different weight (light, medium, heavy). The heavyweight popup uses a window as backend and has dropdown shadow. Heavyweight popup is not the default so we have to force it.



The util class I created for getting/setting the popup type:



Missing menu separator

This one could also be fixed by changing the theme and doing it from Java is very similar to the solution for the missing borders. We just have to manipulate a different region and create a JPopupMenu.Separator instance for its style to get updated.



Horizontal menu separator

Credits

IntelliJ IDEA is the Java IDE I use on Ubuntu Linux and the community edition is open source. Hats off to the Jetbrains developers for finding or leading me to some of the workarounds I posted above.

Saturday, June 16, 2012

Shift+click on a launcher icon to open a new application instance

I just noticed that finally the Ubuntu Unity shift+click regression fix made it to the trunk:

  • Committer: Tarmac
  • Author(s): Thomi Richards, Miklos Juhasz
  • Date: 2012-06-05 04:49:29 UTC

I proposed my branch in April but unfortunately it did not make it into 12.04. It's not a crucial feature but I still like it and I am happy to have it back. A Unity package with this fix is in my ppa for 12.04.
Thank you, Thomi Richards, for writing the AutoPilot test!

Tuesday, April 17, 2012

Fix blue people on Flash videos without losing HW acceleration

Adobe announced that they abandon Flash on Linux and 11.2 will be the last release after which they will provide 5 years support limited to security issues only.

11.2 was released with a terrible bug: Flash Player sends U and V components in the wrong order which results in incorrect colors. They are not going to fix it - all reports are being closed as CannotReproduce or FeatureRemoved.

This bug affects only users with NVidia cards but still: I can hardly accept that such a bug slips through all the quality checks and that they refuse to fix it. Users have not much choice: earlier versions are full of security holes, the latest renders the videos unwatchable.

Since Flash Player is closed source and Adobe doesn't care, we can just workaround this problem, and libvdpau is one possible layer where we can do this. VDPAU is an open-source library which allows programs to offload portions of the video decoding process and video post-processing to the GPU video-hardware. This is the only open-source component I can think of in the chain so this will have to be abused. While this goes against all my software engineering principles here is the deal:

We modify the VDPAU trace library. It's meant for tracing VDPAU functionality and not for working around Adobe's incompetence but that's our best shot. In this library we can swap the U and V color components so they will be in the correct order. The patch is not mine, the credit goes to Pierre-Loup A. Griffais. The patch stubs out all the tracing routines and only does color swapping. If you need to trace the VDPAU functionality remember to use the unmodified version!

I applied the patch on the 10.04 (previous LTS version of Ubuntu), 11.10 (current stable version) and 12.04 (upcoming LTS release). All of them have been built on Launchpad and reside in my Personal Package Archive (PPA).

If you are reading this and eager to use the patched version you will know how to create your own PPA and copy my packages there. You can also add my PPA to your package manager (instructions on the PPA site) and upgrade the libvdpau1 package. Downloading the debs and installing manually is also an option. Be aware that my ppa has other packages which you may not want to upgrade so make sure you know what you are doing.

Having the patched VDPAU library is not enough: you have to activate it by enabling tracing. You can do so by using the VDPAU_TRACE=1 before starting your browser, e.g. you can modify the Exec line(s) in your firefox.desktop or google-chrome.desktop file to start with env VDPAU_TRACE=1

Not an easy ride. While it was possible to workaround this bug that's not always the case. Which proprietary, closed-source software comes next? Try to find the open alternatives, which, in case of flash, is using HTML5.

In the meantime, enjoy YouTube videos, on Linux, even with NVidia cards!

Update 1: I have backported the official fix for Precise (12.04) and it is in my ppa now. Other versions have been removed in order to reduce maintenance burden.

Update 2: The fixed version is in the official archive now - no need for 3rd party ppa's anymore.

Friday, February 24, 2012

BDSup2Sub 4.0.1

BDSup2Sub 4.0.1 has been released. This is a bugfix release.

Changes:
  • Fixed: Flashing subtitles - if the end time of the current subtitle picture is beyond the start time of the next one the subtitle was set to zero length.
  • Fixed: Resolution incorrectly read from the dvd ifo file in cases other than 720x576/720x480 16:9.
  • Fixed: Incorrect (too short) subtitle duration for dvd subtitle frames using subtitle effects


WDTV Live users: I have also updated the version that has the workaround for the WDTV Live vobsub subtitle handling bug.

BDSup2Sub v4.0.1-wdtv (for WDTV Live media player owners)