-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseEventHandler.java
More file actions
50 lines (46 loc) · 1.86 KB
/
MouseEventHandler.java
File metadata and controls
50 lines (46 loc) · 1.86 KB
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
package editor;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.control.ScrollBar;
import javafx.scene.input.MouseEvent;
/**
* Created by jasmine on 2/28/16.
*/
public class MouseEventHandler implements EventHandler<MouseEvent> {
private TextLinkedList text;
private TextCursor tc;
private ScrollBar sb;
private Group root;
private int window_height;
public MouseEventHandler(TextLinkedList text, TextCursor tc, Group root, ScrollBar sb) {
this.text = text;
this.tc = tc;
this.sb = sb;
this.root = root;
window_height = 500;
}
@Override
public void handle(MouseEvent mouseEvent) {
if (mouseEvent.getEventType() == MouseEvent.MOUSE_CLICKED) {
double height = text.getLast().i.getY() + text.getLast().prev.i.getLayoutBounds().getHeight();
if (mouseEvent.getY() > height) {
text.changeLine((int) mouseEvent.getX(), (int) text.getLast().i.getY());
} else if (mouseEvent.getY() < 0) {
text.changeLine((int) mouseEvent.getX(), 0);
}
else {
text.changeLine((int) mouseEvent.getX(), text.roundY((int) (mouseEvent.getY() - root.getLayoutY())));
}
if (tc.getY() + root.getLayoutY() < 0) {
root.setLayoutY( - tc.getY());
sb.setValue( - (int) root.getLayoutY() * (double) window_height / (height - window_height));
} else if (tc.getY() + tc.getHeight() + root.getLayoutY() > window_height) {
root.setLayoutY( - (tc.getY() + tc.getHeight() - window_height));
sb.setValue( - (int) root.getLayoutY() * (double) window_height / (height - window_height));
}
}
}
public void updateWindowHeight(int window_height) {
this.window_height = window_height;
}
}