Skip to content

Method: onKeyReleased(KeyEvent)

1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.ui.impl.javafx;
28:
29: import javax.annotation.Nonnull;
30: import java.util.Optional;
31: import javafx.beans.property.DoubleProperty;
32: import javafx.beans.property.SimpleDoubleProperty;
33: import javafx.collections.ObservableList;
34: import javafx.fxml.FXML;
35: import javafx.scene.input.KeyCode;
36: import javafx.scene.input.KeyEvent;
37: import javafx.scene.layout.ColumnConstraints;
38: import javafx.scene.layout.GridPane;
39: import javafx.scene.layout.RowConstraints;
40: import javafx.scene.layout.StackPane;
41: import it.tidalwave.bluemarine2.message.PowerOnNotification;
42: import it.tidalwave.bluemarine2.ui.commons.flowcontroller.FlowController;
43: import lombok.Getter;
44: import lombok.Setter;
45: import lombok.extern.slf4j.Slf4j;
46:
47: /***********************************************************************************************************************
48: *
49: * The JavaFX Delegate for the main application screen.
50: *
51: * @stereotype JavaFXDelegate
52: *
53: * @author Fabrizio Giudici
54: *
55: **********************************************************************************************************************/
56: @Slf4j
57: public class JavaFXApplicationPresentationDelegate
58: {
59: @FXML
60: private GridPane gpGridPane;
61:
62: @FXML @Getter
63: private StackPane spContent;
64:
65: @Getter @Setter
66: private Optional<Runnable> backspaceCallback = Optional.empty();
67:
68: private final DoubleProperty leftOverscan = new SimpleDoubleProperty(0);
69:
70: private final DoubleProperty rightOverscan = new SimpleDoubleProperty(0);
71:
72: private final DoubleProperty topOverscan = new SimpleDoubleProperty(0);
73:
74: private final DoubleProperty bottomOverscan = new SimpleDoubleProperty(0);
75:
76: /*******************************************************************************************************************
77: *
78: * When initialization is completed, binds the screen estate to the {@link FlowController} and fires a
79: * {@link PowerOnNotification}, so other actors can start working.
80: *
81: ******************************************************************************************************************/
82: @FXML
83: public void initialize()
84: {
85: log.info("initialize()");
86:
87: final ObservableList<ColumnConstraints> columns = gpGridPane.getColumnConstraints();
88: final ObservableList<RowConstraints> rows = gpGridPane.getRowConstraints();
89: columns.get(0).minWidthProperty().bind(leftOverscan);
90: columns.get(0).maxWidthProperty().bind(leftOverscan);
91: columns.get(2).minWidthProperty().bind(rightOverscan);
92: columns.get(2).maxWidthProperty().bind(rightOverscan);
93: rows.get(0).minHeightProperty().bind(topOverscan);
94: rows.get(0).maxHeightProperty().bind(topOverscan);
95: rows.get(2).minHeightProperty().bind(bottomOverscan);
96: rows.get(2).maxHeightProperty().bind(bottomOverscan);
97:
98: // FIXME: this is hardwired for my TV set - must be configurable by JavaFXApplicationWithSplash
99: // Or FlowController, repurposed as a UIController
100:
101: if ("arm".equals(System.getProperty("os.arch")))
102: {
103: leftOverscan.set(38);
104: rightOverscan.set(38);
105: topOverscan.set(22);
106: bottomOverscan.set(22);
107: }
108: // END FIXME
109: }
110:
111: /*******************************************************************************************************************
112: *
113: * Binds the BACK_SPACE key to backward navigation, which for the main UI means to quit the application.
114: *
115: * @param event the key event
116: *
117: ******************************************************************************************************************/
118: @FXML
119: public void onKeyReleased (@Nonnull final KeyEvent event)
120: {
121:• if (event.getCode().equals(KeyCode.BACK_SPACE))
122: {
123: log.debug("onKeyReleased({})", event);
124: backspaceCallback.ifPresent(Runnable::run);
125: }
126: }
127: }