5050import javafx .scene .control .Alert .AlertType ;
5151import javafx .scene .control .Label ;
5252import javafx .scene .control .TextArea ;
53+ import javafx .scene .input .KeyCode ;
54+ import javafx .scene .input .KeyCodeCombination ;
55+ import javafx .scene .input .KeyCombination ;
56+ import javafx .scene .input .KeyEvent ;
5357import javafx .scene .layout .GridPane ;
5458import javafx .scene .layout .Pane ;
5559import javafx .scene .layout .Priority ;
@@ -239,6 +243,8 @@ private void initialiseUI(final Stage primaryStage) throws IOException {
239243 // Show the scene containing the root layout.
240244 final Scene mainScene = new Scene (mainPane , Color .TRANSPARENT );
241245
246+ registerMinimizeEventlistener (mainScene , primaryStage );
247+ registerMaximizeEventlistener (mainScene , primaryStage );
242248 // Image(Resources.getResource(RESOURCE.ICON_MAIN).toString())); // TODO use an app icon
243249
244250 primaryStage .setTitle ("KeepTime" );
@@ -260,6 +266,28 @@ public void handle(final WindowEvent event) {
260266
261267 }
262268
269+ private void registerMinimizeEventlistener (final Scene mainScene , final Stage primaryStage ) {
270+ final KeyCombination keyComb = new KeyCodeCombination (KeyCode .DOWN , KeyCombination .META_DOWN );
271+ mainScene .addEventFilter (KeyEvent .KEY_RELEASED , keyEvent -> {
272+ if (keyComb .match (keyEvent )) {
273+ LOG .info ("KeyCombination '{}' was pressed: Minimizing window." , keyComb );
274+ primaryStage .setIconified (true );
275+ keyEvent .consume ();
276+ }
277+ });
278+ }
279+
280+ private void registerMaximizeEventlistener (final Scene mainScene , final Stage primaryStage ) {
281+ final KeyCombination keyComb = new KeyCodeCombination (KeyCode .UP , KeyCombination .META_DOWN );
282+ mainScene .addEventFilter (KeyEvent .KEY_RELEASED , keyEvent -> {
283+ if (keyComb .match (keyEvent )) {
284+ LOG .info ("KeyCombination '{}' was pressed: Maximizing window." , keyComb );
285+ primaryStage .setIconified (false );
286+ keyEvent .consume ();
287+ }
288+ });
289+ }
290+
263291 @ Override
264292 public void stop () throws Exception {
265293 springContext .stop ();
0 commit comments