I've seen this code that builds, my attention is to fix the resizing of those shape, and when I move them how can I block the shape to not move out of the window ?
I tried to fix resizing to not exceed when x is between 100 and 300, it works but when I try to decrease the shape size it does not move any more
static void enableDrag(Circle node, boolean canDragX, boolean canDragY, DragHandler dragHandler) {
final Delta dragDelta = new Delta();
node.setOnMousePressed(mouseEvent -> {
// record a delta distance for the drag and drop operation.
dragDelta.x = node.getCenterX() - mouseEvent.getX();
dragDelta.y = node.getCenterY() - mouseEvent.getY();
node.getScene().setCursor(Cursor.MOVE);
});
node.setOnMouseReleased(mouseEvent -> {
node.getScene().setCursor(Cursor.HAND);
});
node.setOnMouseDragged(mouseEvent -> {
double oldX = node.getCenterX();
double oldY = node.getCenterY();
System.out.println(node.getCenterX());
if(node.getCenterX()<=300 && node.getCenterX()>100){
System.out.println();
double newX = mouseEvent.getX() + dragDelta.x;
if (canDragX && newX > 0 && newX < node.getScene().getWidth()) {
node.setCenterX(newX);
}
double newY = mouseEvent.getY() + dragDelta.y;
if (canDragY && newY > 0 && newY < node.getScene().getHeight()) {
node.setCenterY(newY);
}
newX = node.getCenterX();
newY = node.getCenterY();
if (dragHandler != null && (newX != oldX || newY != oldY)) {
dragHandler.handle(oldX, oldY, newX, newY);
}
}
});
node.setOnMouseEntered(mouseEvent -> {
if (!mouseEvent.isPrimaryButtonDown()) {
node.getScene().setCursor(Cursor.HAND);
}
});
node.setOnMouseExited(mouseEvent -> {
if (!mouseEvent.isPrimaryButtonDown()) {
node.getScene().setCursor(Cursor.DEFAULT);
}
});
}