blob: 83cf19188e0e2191bb251a71fd8dcba19759c095 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001package tai_ofa;
2
3
4import javafx.collections.ObservableList;
5import javafx.event.EventHandler;
6import javafx.scene.Parent;
7import javafx.scene.input.MouseEvent;
8
9/**
10 *
11 * @author Raghav Kashyap raghavkashyap@paxterrasolutions.com
12
13 * TestON is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 2 of the License, or
16 * (at your option) any later version.
17
18 * TestON is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22
23 * You should have received a copy of the GNU General Public License
24 * along with TestON. If not, see <http://www.gnu.org/licenses/>.
25
26
27 */
28public class DraggableNode extends Parent{
29
30 //ATTRIBUTES
31 //X AND Y postion of Node
32 double x = 0;
33 double y = 0;
34 //X AND Y position of mouse
35 double mousex=0;
36 double mousey=0;
37
38 //To make this function accessible for other Class
39 @Override
40 public ObservableList getChildren(){
41 return super.getChildren();
42 }
43
44 public DraggableNode(){
45 super();
46
47 //EventListener for MousePressed
48 onMousePressedProperty().set(new EventHandler<MouseEvent>(){
49
50 @Override
51 public void handle(MouseEvent event) {
52 //record the current mouse X and Y position on Node
53 mousex = event.getSceneX();
54 mousey= event.getSceneY();
55 //get the x and y position measure from Left-Top
56 x = getLayoutX();
57 y = getLayoutY();
58 }
59
60 });
61
62 //Event Listener for MouseDragged
63 onMouseDraggedProperty().set(new EventHandler<MouseEvent>(){
64
65 @Override
66 public void handle(MouseEvent event) {
67 //Get the exact moved X and Y
68 x += event.getSceneX()-mousex ;
69 y += event.getSceneY()-mousey ;
70
71 //set the positon of Node after calculation
72 setLayoutX(x);
73 setLayoutY(y);
74
75 //again set current Mouse x AND y position
76 mousex = event.getSceneX();
77 mousey= event.getSceneY();
78
79 }
80 });
81 }
82}