forked from rhyzue/KettleLog
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNotifContainer.java
More file actions
200 lines (166 loc) · 5.87 KB
/
NotifContainer.java
File metadata and controls
200 lines (166 loc) · 5.87 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import Item.*;
import Notif.*;
import java.text.*;
import java.util.*;
import javafx.util.*;
import javafx.stage.*;
import javafx.event.*;
import javafx.geometry.*;
import javafx.scene.Scene;
import javafx.scene.text.*;
import javafx.scene.image.*;
import javafx.scene.paint.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.scene.control.ScrollPane.*;
import javafx.collections.transformation.*;
public class NotifContainer{
//Components
private Button readBtn = new Button();
private Image read = new Image("./Misc/Read.png");
private Image unread = new Image("./Misc/Unread.png");
private ImageView readImg = new ImageView();
private Tooltip readTP = new Tooltip("Mark read");
private Label message = new Label("Message");
private Button linkBtn = new Button();
private Image linkBtnImg = new Image("./Misc/link.png");
private ImageView linkImg = new ImageView();
private Tooltip linkTP = new Tooltip("View");
private Button delBtn = new Button();
private Image delBtnImg = new Image("./Misc/delete2.png");
private ImageView delImg = new ImageView();
private Tooltip delTP = new Tooltip("Delete");
//controls
private HBox hb;
private Notif notif = new Notif();
private static Kettlelog kettle = new Kettlelog();
public NotifContainer(){
hb = notifBox("N/A", "N/A", 0, "N/A", "N/A");
}
public NotifContainer(Notif notif){
this.notif = notif;
hb = notifBox(notif.getMessage(), notif.getItemId(), notif.getReadStatus(), notif.getNotifId(), notif.getDateGenerated());
}
public HBox notifBox(String messageStr, String linkId, int readStatus, String notifId, String dateGenerated){
hb = new HBox(10);
NotifHandler notifHandler = new NotifHandler();
readBtn.setStyle("-fx-background-color: transparent;");
readImg.setImage(read);
readImg.setFitWidth(20);
readImg.setPreserveRatio(true);
readImg.setSmooth(true);
readImg.setCache(true);
readBtn.setGraphic(readImg);
readTP.setShowDelay(new javafx.util.Duration(100.0));
readBtn.setTooltip(readTP);
readBtn.setId("readBtn");
readBtn.setOnAction(notifHandler);
message.setPrefWidth(285.0);
message.setPrefHeight(30.0);
linkBtn.setStyle("-fx-background-color: transparent;");
linkImg.setImage(linkBtnImg);
linkImg.setFitWidth(20);
linkImg.setPreserveRatio(true);
linkImg.setSmooth(true);
linkImg.setCache(true);
linkBtn.setGraphic(linkImg);
linkTP.setShowDelay(new javafx.util.Duration(100.0));
linkBtn.setTooltip(linkTP);
linkBtn.setId("linkBtn");
linkBtn.setOnAction(notifHandler);
if(linkId.equals("N/A")){
linkBtn.setDisable(true);
}
else{
linkBtn.setDisable(false);
}
delBtn.setStyle("-fx-background-color: transparent;");
delImg.setImage(delBtnImg);
delImg.setFitWidth(20);
delImg.setPreserveRatio(true);
delImg.setSmooth(true);
delImg.setCache(true);
delBtn.setGraphic(delImg);
delTP.setShowDelay(new javafx.util.Duration(100.0));
delBtn.setTooltip(delTP);
delBtn.setOnAction(notifHandler);
delBtn.setId("delBtn");
hb.setStyle("-fx-background-color: #ffbe5c;");
hb.setPadding(new Insets(10, 10, 10, 10));
hb.getChildren().addAll(readBtn, message, linkBtn, delBtn);
return hb;
}
public void setNotifVisible(boolean value){
hb.setVisible(value);
}
public boolean getNotifVisible(){
return hb.isVisible();
}
public void setMessage(String text){
message.setText(text);
}
public void setNotifReadStatus(int rd){
notif.setReadStatus(rd);
}
public void updateNotifContainer(Notif notif){
this.notif = notif;
message.setText(notif.getMessage());
if(notif.getItemId().equals("N/A")){
linkBtn.setDisable(true);
}
else{
linkBtn.setDisable(false);
}
if(kettle.getItemById(notif.getItemId())==null){
linkBtn.setDisable(true);
}
if(notif.getReadStatus()==1){//read
hb.setOpacity(0.5);
readImg.setImage(unread);
readTP.setText("Mark unread");
}
else if(notif.getReadStatus()==0){//unread
hb.setOpacity(1);
readImg.setImage(read);
readTP.setText("Mark read");
}
}
public Notif getNotif(){
return notif;
}
public HBox getNotifBox(){
return hb;
}
public class NotifHandler implements EventHandler<ActionEvent>{
@Override
public void handle(ActionEvent e) {
String itemClicked = ((Control)e.getSource()).getId();
switch(itemClicked){
case "readBtn":
if(notif.getReadStatus()==0){ //if unread, mark as read
notif.setReadStatus(1);
hb.setOpacity(0.5);
readImg.setImage(unread);
readTP.setText("Mark unread");
}
else if (notif.getReadStatus()==1){
notif.setReadStatus(0);
hb.setOpacity(1);
readImg.setImage(read);
readTP.setText("Mark read");
}
break;
case "delBtn":
hb.setVisible(false);
notif.setReadStatus(-1);
break;
case "linkBtn":
Item it = kettle.getItemById(notif.getItemId());
kettle.showInfoStage(it);
break;
default:
System.out.println("other");
}
}
}
}