forked from rhyzue/KettleLog
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNotifStage.java
More file actions
235 lines (193 loc) · 8.21 KB
/
NotifStage.java
File metadata and controls
235 lines (193 loc) · 8.21 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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.*;
/*
Notif stage contains rows of hboxes, each with:
1. Button: mark read/unread, will toggle
2. Label: Message
3. Button: Visit item (pulls out info stage)
Need db to save notifs: Contains message, item id, read status
*/
public class NotifStage extends Stage{
//components
private static Button clearBtn = new Button("Clear");
private static Button closeBtn = new Button("Close");
private static Button refreshBtn = new Button();
private static Label notifLabel = new Label("Notifications");
private static Font notifFont = new Font(20);
//panes
private static AnchorPane topAnchor = new AnchorPane();
private static AnchorPane bottomAnchor = new AnchorPane();
private static ScrollPane sp = new ScrollPane();
private static VBox notifVB = new VBox(5);
private static BorderPane notifBP = new BorderPane();
//controls
private static List<NotifContainer> notifBoxList = new ArrayList<NotifContainer>();
private static Scene notifScene;
private static Kettlelog kettle = new Kettlelog();
NotifStage(){
NotifStageHandler notifStageHandler = new NotifStageHandler();
//TOP (LABEL, CLEAR BTN)
clearBtn.setId("clearBtn");
clearBtn.setStyle("-fx-background-color: #ffe1bb;");
clearBtn.setSkin(new FadeButtonSkin(clearBtn));
clearBtn.setOnAction(notifStageHandler);
AnchorPane.setRightAnchor(clearBtn, 10.0);
AnchorPane.setTopAnchor(clearBtn, 20.0);
notifLabel.setFont(notifFont);
notifLabel.setStyle("-fx-text-fill: white");
AnchorPane.setLeftAnchor(notifLabel, 20.0);
AnchorPane.setTopAnchor(notifLabel, 20.0);
topAnchor.setStyle("-fx-background-color: #ff940c;");
topAnchor.setPrefHeight(60);
topAnchor.getChildren().addAll(notifLabel, clearBtn);
//BOTTOM (CLOSE BTN)
closeBtn.setId("closeBtn");
closeBtn.setStyle("-fx-background-color: #ffe1bb;");
closeBtn.setSkin(new FadeButtonSkin(closeBtn));
closeBtn.setOnAction(notifStageHandler);
Image refreshImg = new Image("./Misc/refreshBlack.png");
ImageView refreshImgView = new ImageView();
refreshBtn.setStyle("-fx-background-color: transparent;");
refreshImgView.setImage(refreshImg);
refreshImgView.setFitWidth(25);
refreshImgView.setPreserveRatio(true);
refreshImgView.setSmooth(true);
refreshImgView.setCache(true);
refreshBtn.setGraphic(refreshImgView);
Tooltip refreshTP = new Tooltip("Refresh");
refreshTP.setShowDelay(new javafx.util.Duration(100.0));
refreshBtn.setTooltip(refreshTP);
refreshBtn.setId("refreshBtn");
refreshBtn.setOnAction(notifStageHandler);
AnchorPane.setRightAnchor(closeBtn, 10.0);
AnchorPane.setBottomAnchor(closeBtn, 10.0);
AnchorPane.setLeftAnchor(refreshBtn, 10.0);
AnchorPane.setBottomAnchor(refreshBtn, 7.0);
bottomAnchor.setStyle("-fx-background-color: #ff940c;");
bottomAnchor.setPrefHeight(50);
bottomAnchor.getChildren().addAll(refreshBtn, closeBtn);
//VBOX CONTENTS (NOTIFS)
notifVB.setPadding(new Insets(10.0, 20.0, 10.0, 20.0));
notifVB.setStyle("-fx-background-color: #ffe1bb;");
for(int i = 0; i<20; i++){
String notifID = "NOTIF"+String.valueOf(i);
NotifContainer notifBox = new NotifContainer();
notifBoxList.add(notifBox);
notifVB.getChildren().add(notifBox.getNotifBox());
}
//SETTING CONTENT OF SCROLLPANE
sp.setContent(notifVB);
sp.setFitToWidth(true);
sp.setFitToHeight(true);
sp.setVbarPolicy(ScrollBarPolicy.NEVER);
//ADDING NODES TO MAIN BORDER PANE
notifBP.setTop(topAnchor);
notifBP.setBottom(bottomAnchor);
notifBP.setCenter(sp);
notifBP.setStyle("-fx-background-color: #ffe1bb;");
notifScene = new Scene(notifBP, 500, 500);
this.setResizable(false);
this.setScene(notifScene);
this.initOwner(kettle.getPrimaryStage());
this.initStyle(StageStyle.UNDECORATED);
this.initModality(Modality.WINDOW_MODAL);
}
public void updateNotifStage(List<Notif> kettleNotifs){
System.out.println("kettle notif size: "+kettleNotifs.size());
int sz = kettleNotifs.size();
int numToGen = 20;
for(int i = 0; i<numToGen; i++){
if(i<sz){
//SET ALL NOTIF DATA TO KETTLE NOTIF DATA
//if the item doesn't have status deleted, add it to stage's notifs
notifBoxList.get(i).updateNotifContainer(kettleNotifs.get(i));
notifBoxList.get(i).setNotifVisible(true);
}
//if less than 20 notifs exist
else{
notifBoxList.get(i).setNotifVisible(false);
}
}
}
public void onClose(){
List<Notif> notifsToUpdate = new ArrayList<Notif>();
for(int i = 0; i<20; i++){
Notif curNotif = notifBoxList.get(i).getNotif();
if(curNotif.getReadStatus()==-1){
//if this item has reorder date<=today && dategenerated==today, read status should be -3
Item it = kettle.getItemById(curNotif.getItemId());
//if the user already deleted the item, we do not need to worry about regenerating
//so treat like regular delete
if(it==null){
notifsToUpdate.add(curNotif);
continue;
}
//get value of ROD
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date today = new java.util.Date();
String todayString = dateFormat.format(today);
java.util.Date rod = new java.util.Date();
String rodString = it.getROD();
if(rodString.equals("OVERDUE")){
rodString = todayString;
}
try{
rod = dateFormat.parse(rodString);
}
catch(ParseException ex){
ex.printStackTrace();
}
//set read status to -3
if(todayString.equals(curNotif.getDateGenerated()) && (today.after(rod) || todayString.equals(rodString))){
curNotif.setReadStatus(-3);
}
notifsToUpdate.add(curNotif);
}
else if (curNotif.getReadStatus()==0 || curNotif.getReadStatus()==1){
notifsToUpdate.add(curNotif);
}
}
kettle.updateNotifs(notifsToUpdate);
}
public class NotifStageHandler implements EventHandler<ActionEvent>{
@Override
public void handle(ActionEvent e) {
String itemClicked = ((Control)e.getSource()).getId();
if(itemClicked.equals("closeBtn")){
kettle.hideNotifStage();
onClose();
kettle.primaryStage.updateNotifIcon();
}
else if(itemClicked.equals("clearBtn")){
//if notifs are visible, set them to not visible
//set read status to -1
for(int i =0; i<20; i++){
if(notifBoxList.get(i).getNotifVisible()){
notifBoxList.get(i).setNotifReadStatus(-1);
notifBoxList.get(i).setNotifVisible(false);
}
}
}
else if(itemClicked.equals("refreshBtn")){
kettle.hideNotifStage();
onClose();
kettle.primaryStage.updateNotifIcon();
kettle.showNotifStage();
}
}
}
}