MCPcopy Create free account
hub / github.com/TheCyaniteProject/exit_code_java / DraggableNode

Class DraggableNode

src/main/java/exitcode/DraggableNode.java:21–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19// Internal dependancies: Desktop
20
21class DraggableNode extends BorderPane {
22 public static boolean tile_windows_on_edge=true;//feel free to change this variable name, the only use is in tileWindowIfOnEdge funtion
23 // node position
24 private double x = 0;
25 private double y = 0;
26 // mouse position
27 private double mousex = 0;
28 private double mousey = 0;
29 private Node view;
30 private boolean dragging = false;
31 private boolean moveToFront = true;
32 private boolean onEdge= false;
33 private double nonMaxSizeHeight;
34 private double nonMaxSizeWidth;
35 private double layoutXnoMax;
36 private double layoutYnoMax;
37
38 public DraggableNode() {
39 init();
40 }
41
42 public DraggableNode(Node view) {
43 this.view = view;
44 getChildren().add(view);
45 init();
46 }
47
48 private void init() {
49 layoutXnoMax= getLayoutX();
50 layoutYnoMax= getLayoutY();
51 onMousePressedProperty().set(new EventHandler<MouseEvent>() {
52 @Override
53 public void handle(MouseEvent event) {
54
55 // record the current mouse X and Y position on Node
56 mousex = event.getSceneX();
57 mousey = event.getSceneY();
58
59 x = getLayoutX();
60 y = getLayoutY();
61
62 if (isMoveToFront()) {
63 toFront();
64 }
65 }
66 });
67
68 //Event Listener for MouseDragged
69 onMouseDraggedProperty().set(new EventHandler<MouseEvent>() {
70 @Override
71 public void handle(MouseEvent event) {
72
73 // Get the exact moved X and Y
74 double offsetX = event.getSceneX() - mousex;
75 double offsetY = event.getSceneY() - mousey;
76
77 x += offsetX;
78 y += offsetY;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected