Skip to content

Commit

Permalink
Prevent possible NPE while dragging the thumbs of the RangeSlider con…
Browse files Browse the repository at this point in the history
…trol (#1507)
  • Loading branch information
jperedadnr committed Jun 28, 2023
1 parent 0a8caa4 commit d141298
Showing 1 changed file with 7 additions and 1 deletion.
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2013, 2021, ControlsFX
* Copyright (c) 2013, 2023, ControlsFX
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -244,6 +244,9 @@ private void initFirstThumb() {

lowThumb.setOnMouseDragged(me -> {
Point2D cur = lowThumb.localToParent(me.getX(), me.getY());
if (preDragThumbPoint == null) {
preDragThumbPoint = cur;
}
double dragPos = (isHorizontal())?
cur.getX() - preDragThumbPoint.getX() : -(cur.getY() - preDragThumbPoint.getY());
lowThumbDragged(me, preDragPos + dragPos / trackLength);
Expand All @@ -269,6 +272,9 @@ private void initSecondThumb() {
double trackLength = orientation ? track.getWidth() : track.getHeight();

Point2D point2d = highThumb.localToParent(e.getX(), e.getY());
if (preDragThumbPoint == null) {
preDragThumbPoint = point2d;
}
double d = getSkinnable().getOrientation() != Orientation.HORIZONTAL ? -(point2d.getY() - preDragThumbPoint.getY()) : point2d.getX() - preDragThumbPoint.getX();
highThumbDragged(e, preDragPos + d / trackLength);
});
Expand Down

0 comments on commit d141298

Please sign in to comment.