7
7
import java .net .URI ;
8
8
import java .net .URL ;
9
9
import java .rmi .RemoteException ;
10
+ import java .text .SimpleDateFormat ;
10
11
import java .util .ArrayList ;
11
12
import java .util .Calendar ;
12
13
import java .util .List ;
26
27
import com .github .mob41 .osumer .method .MethodResult ;
27
28
import com .github .mob41 .osumer .queue .QueueStatus ;
28
29
import com .github .mob41 .osumer .rmi .IDaemon ;
30
+ import com .github .mob41 .osumer .updater .Announcement ;
31
+ import com .github .mob41 .osumer .updater .AnnouncementChecker ;
29
32
import com .github .mob41 .osumer .updater .UpdateInfo ;
30
33
import com .github .mob41 .osumer .updater .Updater ;
31
34
import com .github .mob41 .osums .Osums ;
32
35
import com .github .mob41 .osums .beatmap .OsuBeatmap ;
33
36
import com .github .mob41 .osums .beatmap .OsuSong ;
34
37
38
+ import javafx .animation .KeyFrame ;
39
+ import javafx .animation .Timeline ;
35
40
import javafx .application .Platform ;
36
41
import javafx .event .ActionEvent ;
37
42
import javafx .event .EventHandler ;
60
65
import javafx .stage .Modality ;
61
66
import javafx .stage .Stage ;
62
67
import javafx .stage .StageStyle ;
68
+ import javafx .util .Duration ;
63
69
import jfxtras .styles .jmetro8 .JMetro ;
64
70
65
71
public class MainController implements Initializable {
@@ -127,6 +133,9 @@ public class MainController implements Initializable {
127
133
@ FXML
128
134
private MenuItem aboutMenuItem ;
129
135
136
+ @ FXML
137
+ private MenuItem exitMenuItem ;
138
+
130
139
private Configuration config ;
131
140
132
141
private IDaemon d ;
@@ -136,8 +145,18 @@ public class MainController implements Initializable {
136
145
private QueueStatus [] queues ;
137
146
138
147
private Updater updater ;
148
+
149
+ private AnnouncementChecker annChecker ;
139
150
140
151
private boolean checkingUpdate ;
152
+
153
+ private boolean checkingAnnouncements ;
154
+
155
+ private Announcement [] ann ;
156
+
157
+ private int currAnnIndex ;
158
+
159
+ private Timeline updateAnnUiTimeline ;
141
160
142
161
@ Override
143
162
public void initialize (URL location , ResourceBundle resources ) {
@@ -192,6 +211,7 @@ public void handle(ActionEvent event) {
192
211
@ Override
193
212
public void handle (ActionEvent event ) {
194
213
checkUpdate ();
214
+ checkAnnouncements ();
195
215
}
196
216
});
197
217
@@ -235,6 +255,22 @@ public void handle(ActionEvent event) {
235
255
}
236
256
});
237
257
258
+ exitMenuItem .setOnAction (new EventHandler <ActionEvent >() {
259
+
260
+ @ Override
261
+ public void handle (ActionEvent event ) {
262
+ try {
263
+ d .shutdown ();
264
+ d = null ;
265
+ } catch (RemoteException e ) {
266
+ //e.printStackTrace();
267
+ //Alert alert = new Alert(AlertType.ERROR, "Could not shutdown daemon. Please do this manually in task manager by terminating Java VM.", ButtonType.OK);
268
+ //alert.showAndWait();
269
+ }
270
+ Platform .exit ();
271
+ }
272
+ });
273
+
238
274
docsMenuItem .setOnAction (new EventHandler <ActionEvent >() {
239
275
240
276
@ Override
@@ -355,8 +391,13 @@ protected void setConfiguration(Configuration config) {
355
391
updater = new Updater (config );
356
392
checkingUpdate = false ;
357
393
394
+ annChecker = new AnnouncementChecker ();
395
+ checkingAnnouncements = false ;
396
+ ann = null ;
397
+
358
398
//TODO do freq check
359
399
checkUpdate ();
400
+ checkAnnouncements ();
360
401
}
361
402
362
403
protected void setDaemon (IDaemon d ) {
@@ -696,6 +737,78 @@ private UpdateInfo getUpdateInfoByConfig() throws WithDumpException {
696
737
return updater .getLatestVersion ();
697
738
}
698
739
}
740
+
741
+ public void checkAnnouncements () {
742
+ if (checkingAnnouncements ) {
743
+ return ;
744
+ }
745
+
746
+ checkingAnnouncements = true ;
747
+ Thread thread = new Thread () {
748
+ public void run () {
749
+ Platform .runLater (new Runnable () {
750
+ @ Override
751
+ public void run () {
752
+ announcementLabel .setText ("Loading announcements..." );
753
+ }
754
+ });
755
+
756
+ if (updateAnnUiTimeline != null ) {
757
+ updateAnnUiTimeline .stop ();
758
+ }
759
+
760
+ currAnnIndex = -1 ;
761
+ ann = null ;
762
+ try {
763
+ ann = annChecker .getAnnouncements ();
764
+ } catch (WithDumpException e ) {
765
+ Platform .runLater (new Runnable () {
766
+ @ Override
767
+ public void run () {
768
+ announcementLabel .setText ("Error checking announcements. See dump for more details." );
769
+ }
770
+ });
771
+ checkingAnnouncements = false ;
772
+ return ;
773
+ }
774
+
775
+ nextAnnouncement ();
776
+ updateAnnUiTimeline = new Timeline (new KeyFrame (Duration .seconds (15 ), new EventHandler <ActionEvent >() {
777
+
778
+ @ Override
779
+ public void handle (ActionEvent event ) {
780
+ if (ann == null ) {
781
+ updateAnnUiTimeline .stop ();
782
+ return ;
783
+ }
784
+ nextAnnouncement ();
785
+ }
786
+
787
+ }));
788
+ updateAnnUiTimeline .setCycleCount (Timeline .INDEFINITE );
789
+ updateAnnUiTimeline .play ();
790
+
791
+ checkingAnnouncements = false ;
792
+ }
793
+ };
794
+ thread .start ();
795
+ }
796
+
797
+ private void nextAnnouncement () {
798
+ currAnnIndex = (currAnnIndex + 1 ) % ann .length ;
799
+
800
+ Announcement a = ann [currAnnIndex ];
801
+ SimpleDateFormat f = new SimpleDateFormat ("yyyy-MM-dd" );
802
+ String text = "[" + f .format (a .getTime ().getTime ()) + "] " + a .getText ();
803
+ Platform .runLater (new Runnable () {
804
+
805
+ @ Override
806
+ public void run () {
807
+ announcementLabel .setText (text );
808
+ }
809
+
810
+ });
811
+ }
699
812
700
813
public void checkUpdate () {
701
814
if (checkingUpdate ) {
0 commit comments