views:

271

answers:

1

I'm trying to figure out which property of BoxComponentEvent will tell me if the generated OnMouseWheel event was a scroll-up or scroll-down event. I have output the values of all the properties BoxComponentEvent exposes; and all of them (with the exception of the coordinates at which the event took place) stay the same regardless. Google and the Ext-GWT docs have been pretty useless for providing a concrete example.

public class MyPanel extends ContentPanel {
    // ...
    public MyPanel() {
     addListener(Events.OnMouseWheel, new Listener<BoxComponentEvent>() {
      public void handleEvent(BoxComponentEvent be) {
       // What happens here to distinguish scroll-up and scroll-down?
      }
     });
    }

    protected void afterRender() {
     super.afterRender();
     el().addEventsSunk(Events.OnMouseWheel.getEventCode());
    }
    // ...
}
A: 

Hi Kevin, I tested this and it works:

private int vpos = 0;
public MyPanel() {
     ContentPanel contents = new ContentPanel();
     contents.setHeight(500);

     add(new Label("This is MyPanel"));
     add(contents);
     setHeight(300);
     setScrollMode(Scroll.ALWAYS);
     vpos = getVScrollPosition();

     addListener(Events.Scroll, new Listener<BaseEvent>(){

      @Override
      public void handleEvent(BaseEvent be) {

       int newVpos = getVScrollPosition();
       if(newVpos<vpos){
        Info.display("DEBUG", "UP!");
       } else if(newVpos>vpos){
        Info.display("DEBUG", "DOWN!");
       }
       vpos = newVpos;

      }});
    }
Dave Paroulek
That will only tell me if there was a wheel event, not the direction of the wheel event which is what I need to know how to retrieve.
Kevin Loney
Updated my answer to include a solution that works in my environment. Hope that helps you.
Dave Paroulek
This solution will not work if none of the child components exceed the size of the parent container (Which is the case with what I'm working on) and it requires that the scroll bars always be visible (not really a problem but not really that aesthetically pleasing either).
Kevin Loney