4 Replies Latest reply: Nov 21, 2012 5:56 AM by dscarminiabielefeld RSS

    setOnScroll - scrolling up or down?


      i've a radar, and a rangeslider, so you basically can zoom in and zoom out the map.
      everything works pretty well, and now i simply want to add a scrollevent. So lets say my rangeslider goes from 0 - 1000.
      When i start the Program the default value of the slider is 500. when i know scroll up, i want to zoom in, so i basically set the current value of the rangeslider - 100. The other way around it goes +100. Works pretty good so for. But the way i solved it is pretty bad i guess, lol. i wondered if there is a more explicit event ike scene.setOnScrollUp or scene.setOnScrollDown. So when i tried to solve it, im checked the deltaY value of my event and saw, if you scroll down it gets the value -40. if you scroll up it's 40. so right now i did it like this:
              Animation.getInstance().radarScene.setOnScroll(new EventHandler<ScrollEvent>() 
                  public void handle(ScrollEvent me) 
                      if(me.getDeltaY() == 40)
                          Controller.getInstance().getRangeSlider().setValue(Controller.getInstance().getRangeSlider().getValue() - 100);
                      if(me.getDeltaY() == -40)
                         Controller.getInstance().getRangeSlider().setValue(Controller.getInstance().getRangeSlider().getValue() + 100); 
      yeah, it works but i find it very unsexy. any one got a better way? Didn't find something like setOnScrollDown, like i said, but maybe i just don't see it. Thanks in advance.

      Edited by: dscarminiabielefeld on 20-Nov-2012 03:11
        • 1. Re: setOnScroll - scrolling up or down?
          That looks somewhat non-robust... are you sure the scroll event always gives +/-40 for the delta? What if the user has a trackpad to scroll with? One thing you can be certain of is that the sign of the delta represents the direction of the scroll. So why not do something like
          private static final double SCROLL_ZOOM_SCALE = 2.5 ;
          public void handle(ScrollEvent me) {
            Slider rangeSlider = Controller.getInstance().getRangeSlider();
            double zoomDelta = me.getDeltaY() * SCROLL_ZOOM_SCALE ;
            double oldValue = rangeSlider.getValue();
            double targetValue = oldValue - zoomDelta ;
            double newValue = Math.max(rangeSlider.getMinValue(), Math.min(targetValue, rangeSlider.getMaxValue()));
          • 2. Re: setOnScroll - scrolling up or down?

            no i'm not sure it gives always -40. I don't really understand why it gives -40 to be honest. it's absolutely non-robust and no good style, but like i said, didn't found something else.
            And that's why i dont really want to use me.getDeltaY at all. You think there is something else?


            Edited by: dscarminiabielefeld on 21-Nov-2012 02:48
            • 3. Re: setOnScroll - scrolling up or down?
              The javadocs describe the deltaX and deltaY as "This value should be interpreted as the number of pixels to scroll." If you're using a mouse wheel, +/-40 is probably what is reported for a single "click" on the mouse wheel.

              I don't think there is any additional API; but I don't think you need any. Just take the deltaY value and use it generically, as for example in the code I put in the previous post.
              • 4. Re: setOnScroll - scrolling up or down?
                Ah, Okay. Think that helps, thank you james. ;-)
                have a nice day