From: John Alhroos Date: Thu, 11 Aug 2011 12:36:02 +0000 (+0000) Subject: Adds mouse wheel scrolling to VFilterSelect #4518 X-Git-Tag: 6.7.0.beta1~102 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1f2ac63ff8976bb2de8e00605ab2e9ffa4eaf342;p=vaadin-framework.git Adds mouse wheel scrolling to VFilterSelect #4518 svn changeset:20301/svn branch:6.7 --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java index 68d5e40326..108a68f73f 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java @@ -32,6 +32,7 @@ import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; @@ -175,7 +176,7 @@ public class VFilterSelect extends Composite implements Paintable, Field, DOM.appendChild(root, down); DOM.appendChild(root, status); DOM.setElementProperty(status, "className", CLASSNAME + "-status"); - DOM.sinkEvents(root, Event.ONMOUSEDOWN); + DOM.sinkEvents(root, Event.ONMOUSEDOWN | Event.ONMOUSEWHEEL); addCloseHandler(this); } @@ -317,6 +318,38 @@ public class VFilterSelect extends Composite implements Paintable, Field, } } + /* + * Timer for scrolling pages up or down. + */ + private LazyPageScroller lazyPageScroller = new LazyPageScroller(); + private class LazyPageScroller extends Timer { + private int pagesToScroll = 0; + + @Override + public void run() { + if(pagesToScroll != 0){ + filterOptions(currentPage + pagesToScroll, lastFilter); + pagesToScroll = 0; + } + } + + public void scrollUp() { + if(currentPage - pagesToScroll >= 0){ + pagesToScroll--; + cancel(); + schedule(100); + } + } + + public void scrollDown() { + if(totalMatches > (currentPage + pagesToScroll +1)*pageLength){ + pagesToScroll++; + cancel(); + schedule(100); + } + } + } + /* * (non-Javadoc) * @@ -329,9 +362,16 @@ public class VFilterSelect extends Composite implements Paintable, Field, if (event.getTypeInt() == Event.ONCLICK) { final Element target = DOM.eventGetTarget(event); if (target == up || target == DOM.getChild(up, 0)) { - filterOptions(currentPage - 1, lastFilter); + lazyPageScroller.scrollUp(); } else if (target == down || target == DOM.getChild(down, 0)) { - filterOptions(currentPage + 1, lastFilter); + lazyPageScroller.scrollDown(); + } + } else if (event.getTypeInt() == Event.ONMOUSEWHEEL) { + int velocity = event.getMouseWheelVelocityY(); + if (velocity > 0) { + lazyPageScroller.scrollDown(); + } else { + lazyPageScroller.scrollUp(); } }