-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextCursor.java
More file actions
50 lines (40 loc) · 1000 Bytes
/
TextCursor.java
File metadata and controls
50 lines (40 loc) · 1000 Bytes
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.scene.shape.Rectangle;
import java.util.Timer;
import java.util.TimerTask;
/**
* Created by jasmine on 2/24/16.
*/
public class TextCursor extends Rectangle {
private Timer t;
private final int TIME = 500;
public TextCursor() {
super(5, 0, 1, 10);
startFlash();
}
private class CursorTimerTask extends TimerTask {
TextCursor tc;
int opacity;
public CursorTimerTask(TextCursor tc) {
this.tc = tc;
opacity = 1;
}
@Override
public void run() {
tc.setOpacity(opacity);
opacity = 1 - opacity;
}
}
public void halt() {
if (t != null) {
t.cancel();
}
}
private void startFlash() {
t = new Timer();
t.schedule(new CursorTimerTask(this), 0, TIME);
}
public String toString() {
return "TextCursor[x=" + this.getX() + ",y=" + this.getY() + "]";
}
}