Skip to content

Commit df9d273

Browse files
committed
Fix cursor type when hovering and dragging.
1 parent 5dacfc2 commit df9d273

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/main/java/com/brunomnsilva/smartgraph/graphview/SmartGraphVertexNode.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class SmartGraphVertexNode<T> extends Group implements SmartGraphVertex<T
5959

6060
private boolean isDragging;
6161

62+
private boolean allowMove;
63+
6264
/* Critical for performance, so we don't rely on the efficiency of the Graph.areAdjacent method */
6365
private final Set<SmartGraphVertexNode<T>> adjacentVertices;
6466

@@ -119,6 +121,7 @@ public SmartGraphVertexNode(Vertex<T> v, double x, double y, double radius, Stri
119121
styleProxy = new SmartStyleProxy(this.shapeProxy.getShape());
120122
styleProxy.addStyleClass("vertex");
121123

124+
this.allowMove = allowMove;
122125
/* Enable dragging */
123126
if (allowMove) {
124127
enableDrag();
@@ -453,42 +456,50 @@ private void enableDrag() {
453456
// record a delta distance for the drag and drop operation.
454457
dragDelta.x = getCenterX() - mouseEvent.getX();
455458
dragDelta.y = getCenterY() - mouseEvent.getY();
456-
getScene().setCursor(Cursor.MOVE);
459+
457460
isDragging = true;
458461

459462
mouseEvent.consume();
460463
}
461464
});
462465

463466
setOnMouseReleased((MouseEvent mouseEvent) -> {
464-
getScene().setCursor(Cursor.HAND);
467+
if(allowMove) { // necessary after a possible drag operation
468+
setCursor(Cursor.HAND);
469+
}
470+
465471
isDragging = false;
466472

467473
mouseEvent.consume();
468474
});
469475

470476
setOnMouseDragged((MouseEvent mouseEvent) -> {
471477
if (mouseEvent.isPrimaryButtonDown()) {
478+
if(allowMove && getCursor() != Cursor.MOVE) {
479+
setCursor(Cursor.MOVE);
480+
}
481+
472482
double newX = mouseEvent.getX() + dragDelta.x;
473483
double x = boundVertexNodeXPositioning(newX, 0, getParent().getLayoutBounds().getWidth());
474484
setCenterX(x);
475485

476486
double newY = mouseEvent.getY() + dragDelta.y;
477487
double y = boundVertexNodeYPositioning(newY, 0, getParent().getLayoutBounds().getHeight());
478488
setCenterY(y);
489+
479490
mouseEvent.consume();
480491
}
481492
});
482493

483494
setOnMouseEntered((MouseEvent mouseEvent) -> {
484-
if (!mouseEvent.isPrimaryButtonDown()) {
485-
getScene().setCursor(Cursor.HAND);
495+
if (allowMove && !mouseEvent.isPrimaryButtonDown()) {
496+
setCursor(Cursor.HAND);
486497
}
487498
});
488499

489500
setOnMouseExited((MouseEvent mouseEvent) -> {
490-
if (!mouseEvent.isPrimaryButtonDown()) {
491-
getScene().setCursor(Cursor.DEFAULT);
501+
if (allowMove && !mouseEvent.isPrimaryButtonDown()) {
502+
setCursor(Cursor.DEFAULT);
492503
}
493504
});
494505
}

0 commit comments

Comments
 (0)