-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNotification.java
More file actions
64 lines (55 loc) · 1.72 KB
/
Notification.java
File metadata and controls
64 lines (55 loc) · 1.72 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import javafx.animation.Interpolator;
import javafx.animation.TranslateTransition;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.util.Duration;
public class Notification extends Group {
private TranslateTransition tt = new TranslateTransition();
private Text t = new Text();
private ImageView i = new ImageView();
private final Vector2 in = new Vector2(400, 200);
private final Vector2 out = new Vector2(150, 200);
private final Vector2 mid = new Vector2(295, 200);
public Notification() {
tt.setNode(this);
tt.setDuration(Duration.millis(2000));
tt.setInterpolator(Interpolator.EASE_BOTH);
t.setX(50);
t.setY(20);
t.setFill(Color.BLACK);
t.setStroke(Color.WHITE);
i.setImage(new Image("https://lh3.googleusercontent.com/3Ofcop0iBUBDcxHk_-fB3-Y9xaeIv9Tt6Mvvnv6W8085GbqUrJiLOZR35yLpaR3VqTR1ocG9YSwCVvt5MkeN3mA=s0"));
i.setPreserveRatio(true);
i.setFitWidth(40);
this.getChildren().addAll(i, t);
this.setTranslateX(in.x);
this.setTranslateY(in.y);
tt.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if(tt.getToX() == out.x) {
tt.setToX(mid.x);
tt.play();
}
}
});
}
public void onClick(EventHandler<MouseEvent> onClick) {
i.setOnMouseClicked(onClick);
}
public void showAlert(String text) {
t.setText(text);
tt.setToX(out.x);
tt.playFromStart();
}
public void hideAlert() {
tt.setToX(in.x);
tt.playFromStart();
}
}