weixin_39918128 2020-11-20 13:09
浏览 0

rangeslider high/low properties continuously changed when dragging and never report isChanging() == true

Original report by jonathan millman (Bitbucket: millmanorama, GitHub: millmanorama).

because RangeSliderSkin does not use a mouseReleasedHandler, it sets both isLow/HighChanging to false for every drag gesture, and there is no way to detect finalized input.

I have fixed this in my client code temporarily by overriding the mouse handlers:


#!java

   private void attachDragListener(RangeSliderSkin skin) {
        if (skin != null) {
            for (Node n : skin.getChildren()) {
                if (n.getStyleClass().contains("range-bar")) {
                    StackPane rangeBar = (StackPane) n;
                    rangeBar.setOnMousePressed((MouseEvent e) -> {
                        rangeBar.requestFocus();
                        preDragPos = e.getX();
                    });
                    rangeBar.setOnMouseReleased((MouseEvent event) -> {
                        rangeSlider.setLowValueChanging(false);
                        rangeSlider.setHighValueChanging(false);
                    });
                    rangeBar.setOnMouseDragged((MouseEvent event) -> {
                        final double min = rangeSlider.getMin();
                        final double max = rangeSlider.getMax();

                        ///!!!  compensate for range and width so that rangebar actualy stays with the slider
                        double delta = (event.getX() - preDragPos) * (max - min) / rangeSlider.
                                getWidth();
                        ////////////////////////////////////////////////////

                        final double lowValue = rangeSlider.getLowValue();
                        final double newLowValue = Math.min(Math.max(min, lowValue + delta),
                                                            max);
                        final double highValue = rangeSlider.getHighValue();
                        final double newHighValue = Math.min(Math.max(min, highValue + delta),
                                                             max);

                        if (newLowValue <= min || newHighValue >= max) {
                            return;
                        }

                        rangeSlider.setLowValueChanging(true);
                        rangeSlider.setHighValueChanging(true);
                        rangeSlider.setLowValue(newLowValue);
                        rangeSlider.setHighValue(newHighValue);
                    });
                }
            }
        }
    }


this should be easy to incorporate back into ControlsFX, but i don't know if I will have the time.

该提问来源于开源项目:controlsfx/controlsfx

  • 写回答

6条回答 默认 最新

  • weixin_39918128 2020-11-20 13:09
    关注

    Original comment by Jonathan Giles (Bitbucket: JonathanGiles, GitHub: JonathanGiles).

    Apparently fixed, but without a full test application I can not be sure.

    评论

报告相同问题?