11package com .github .reugn .devtools .controllers ;
22
33import com .github .reugn .devtools .services .EpochService ;
4+ import com .github .reugn .devtools .utils .Elements ;
45import com .github .reugn .devtools .utils .Logger ;
56import javafx .event .ActionEvent ;
67import javafx .fxml .FXML ;
78import javafx .fxml .Initializable ;
89import javafx .geometry .Insets ;
9- import javafx .scene .control .Button ;
10- import javafx .scene .control .Label ;
11- import javafx .scene .control .TextArea ;
12- import javafx .scene .control .TextField ;
13- import javafx .scene .layout .*;
14- import javafx .scene .paint .Color ;
10+ import javafx .scene .control .*;
11+ import javafx .scene .input .KeyEvent ;
12+ import javafx .scene .layout .Border ;
13+ import javafx .scene .layout .GridPane ;
14+ import javafx .scene .layout .HBox ;
1515
1616import java .net .URL ;
1717import java .time .LocalDateTime ;
1818import java .util .ResourceBundle ;
19+ import java .util .TimeZone ;
1920
2021public class EpochController implements Initializable , Logger {
2122
22- public Label currentEpochLabel ;
23-
24- public TextField currentEpoch ;
25-
26- public Button currentEpochRefreshButton ;
27-
28- public TextField tsToHumanField ;
29-
30- public Button tsToHumanButton ;
31-
32- public TextArea tsToHumanResult ;
33-
34- public Button humanToTsButton ;
35-
36- public TextArea humanToTsResult ;
37-
38- public TextField epochYear ;
39- public TextField epochMonth ;
40- public TextField epochDay ;
41- public TextField epochHour ;
42- public TextField epochMinute ;
43- public TextField epochSecond ;
23+ @ FXML
24+ private Label currentEpochLabel ;
25+ @ FXML
26+ private TextField currentEpoch ;
27+ @ FXML
28+ private Button currentEpochRefreshButton ;
29+ @ FXML
30+ private TextField tsToHumanField ;
31+ @ FXML
32+ private Button tsToHumanButton ;
33+ @ FXML
34+ private TextArea tsToHumanResult ;
35+ @ FXML
36+ private Button humanToTsButton ;
37+ @ FXML
38+ private TextArea humanToTsResult ;
39+ @ FXML
40+ private TextField epochYear ;
41+ @ FXML
42+ private TextField epochMonth ;
43+ @ FXML
44+ private TextField epochDay ;
45+ @ FXML
46+ private TextField epochHour ;
47+ @ FXML
48+ private TextField epochMinute ;
49+ @ FXML
50+ private TextField epochSecond ;
51+ @ FXML
52+ private ComboBox <String > timeZoneComboBox ;
53+ private int timeZoneComboBoxIndex ;
4454
4555 @ FXML
4656 private void handleRefreshEpoch (final ActionEvent event ) {
@@ -55,8 +65,7 @@ private void handleTsToHumanEpoch(final ActionEvent event) {
5565 String result = EpochService .toHumanEpoch (dt );
5666 tsToHumanResult .setText (result );
5767 } catch (Exception e ) {
58- tsToHumanField .setBorder (new Border (new BorderStroke (Color .RED ,
59- BorderStrokeStyle .SOLID , new CornerRadii (3 ), BorderWidths .DEFAULT )));
68+ tsToHumanField .setBorder (Elements .alertBorder );
6069 tsToHumanResult .setText ("" );
6170 }
6271 }
@@ -71,13 +80,30 @@ private void handleHumanToTsEpoch(final ActionEvent event) {
7180 int hour = EpochService .validate (epochHour , 0 , 24 );
7281 int minute = EpochService .validate (epochMinute , 0 , 59 );
7382 int second = EpochService .validate (epochSecond , 0 , 59 );
74- String result = EpochService .toTsEpoch (year , month , day , hour , minute , second );
83+ String timeZone = timeZoneComboBox .getSelectionModel ().getSelectedItem ();
84+ String result = EpochService .toTsEpoch (year , month , day , hour , minute , second , timeZone );
7585 humanToTsResult .setText (result );
7686 } catch (Exception e ) {
7787 humanToTsResult .setText ("" );
7888 }
7989 }
8090
91+ @ FXML
92+ private void handleTimeZoneSearch (KeyEvent keyEvent ) {
93+ String key = keyEvent .getText ();
94+ if (key .length () == 0 ) return ;
95+ int i = 0 ;
96+ for (String item : timeZoneComboBox .getItems ()) {
97+ if (item .toLowerCase ().startsWith (key ) && i > timeZoneComboBoxIndex ) {
98+ timeZoneComboBox .setValue (item );
99+ timeZoneComboBoxIndex = i ;
100+ return ;
101+ }
102+ i ++;
103+ }
104+ timeZoneComboBoxIndex = 0 ;
105+ }
106+
81107 private void resetBorders () {
82108 epochYear .setBorder (Border .EMPTY );
83109 epochMonth .setBorder (Border .EMPTY );
@@ -89,11 +115,11 @@ private void resetBorders() {
89115
90116 @ Override
91117 public void initialize (URL location , ResourceBundle resources ) {
92- HBox .setMargin (currentEpochLabel , new Insets (20 , 5 , 15 , 0 ));
93- HBox .setMargin (currentEpoch , new Insets (15 , 5 , 15 , 0 ));
94- HBox .setMargin (currentEpochRefreshButton , new Insets (15 , 5 , 15 , 0 ));
95- HBox .setMargin (tsToHumanField , new Insets (15 , 5 , 15 , 0 ));
96- HBox .setMargin (tsToHumanButton , new Insets (15 , 5 , 15 , 0 ));
118+ HBox .setMargin (currentEpochLabel , new Insets (15 , 5 , 10 , 0 ));
119+ HBox .setMargin (currentEpoch , new Insets (10 , 5 , 10 , 0 ));
120+ HBox .setMargin (currentEpochRefreshButton , new Insets (10 , 5 , 10 , 0 ));
121+ HBox .setMargin (tsToHumanField , new Insets (10 , 5 , 10 , 0 ));
122+ HBox .setMargin (tsToHumanButton , new Insets (10 , 5 , 10 , 0 ));
97123
98124 GridPane .setMargin (epochYear , new Insets (10 , 5 , 0 , 0 ));
99125 GridPane .setMargin (epochMonth , new Insets (10 , 5 , 0 , 0 ));
@@ -102,6 +128,7 @@ public void initialize(URL location, ResourceBundle resources) {
102128 GridPane .setMargin (epochMinute , new Insets (10 , 5 , 0 , 0 ));
103129 GridPane .setMargin (epochSecond , new Insets (10 , 5 , 0 , 0 ));
104130 GridPane .setMargin (humanToTsButton , new Insets (10 , 5 , 0 , 0 ));
131+ GridPane .setMargin (timeZoneComboBox , new Insets (10 , 5 , 0 , 0 ));
105132
106133 long now = System .currentTimeMillis ();
107134 currentEpoch .setText (Long .toString (now ));
@@ -114,5 +141,9 @@ public void initialize(URL location, ResourceBundle resources) {
114141 epochHour .setText (String .valueOf (date .getHour ()));
115142 epochMinute .setText (String .valueOf (date .getMinute ()));
116143 epochSecond .setText (String .valueOf (date .getSecond ()));
144+
145+ timeZoneComboBox .getItems ().setAll (TimeZone .getAvailableIDs ());
146+ timeZoneComboBox .setValue ("UTC" );
147+ timeZoneComboBoxIndex = 0 ;
117148 }
118149}
0 commit comments