-
Notifications
You must be signed in to change notification settings - Fork 0
/
DraggableNodePaneMaker.java
52 lines (35 loc) · 1.29 KB
/
DraggableNodePaneMaker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package edu.bsu.cs222;
import javafx.scene.*;
import javafx.scene.layout.*;
public class DraggableNodePaneMaker {
public BorderPane borderPane = new BorderPane();
public Pane createPane(int x, int y, Node[] content){
Pane pane = new Pane(content);
pane.setPrefSize(x, y);
return pane;
}
public Parent createDraggableApp(Node[] nodeArray) {
for(int i = 0; i<nodeArray.length; i++){
if(nodeArray[i] != null) {
nodeArray[i].setTranslateX(i * 75);
nodeArray[i].setTranslateY(50);
}
}
var root = createPane(800, 600, nodeArray);
root.getChildren().forEach(this::makeDraggable);
return root;
}
private double startPointX;
private double startPointY;
private void makeDraggable(Node node){
node.setOnMousePressed(obj -> {
startPointX = obj.getSceneX() - node.getTranslateX();
startPointY = obj.getSceneY() - node.getTranslateY();
node.setCursor(Cursor.CLOSED_HAND);
});
node.setOnMouseDragged(obj -> {
node.setTranslateX(obj.getSceneX() - startPointX);
node.setTranslateY(obj.getSceneY() - startPointY);
});
}
}