Determine if user has scrolled to bottom of panel?

I’m writing a log file viewer (using panels and labels). It uses ICEPush to update the labels every X seconds.

I want the following behavior:

  1. If user is in the middle of the panel it should not scroll on update.
  2. If the user is at the bottom of the panel, it should scroll to “new” bottom after update.
  3. If the user is at the bottom of the panel and scrolls up manually, it should freeze the scroll where he stops.

The first case works fine by default (that is how browsers do layers with scroll in them).

The second one is a problem. I can’t figure out IF the user is scrolled to the bottom.
Using javascript, I’d do:

if( obj.scrollTop == (obj.scrollHeight - obj.offsetHeight)) { }

But I don’t know how to embed javascript into Vaadin (and I’m hoping theres an easier way) or do something similar using the methods that are available to me in the panel.

The third will probably fix itself if #2 is fixed.

What I’ve discovered so far is that getScrollTop() gives the current vertical scrolling position, but there is no way to get the “real” height of the panel in pixels (as its rendered in the browser) that I can find.

Any ideas?