Skip to content

Method: lambda$onKeyReleased$0()

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.audio.renderer.impl.javafx;
28:
29: import javax.annotation.Nonnull;
30: import javax.inject.Inject;
31: import java.util.HashMap;
32: import java.util.Map;
33: import javafx.fxml.FXML;
34: import javafx.scene.control.Button;
35: import javafx.scene.control.Label;
36: import javafx.scene.control.ProgressBar;
37: import javafx.scene.input.KeyCodeCombination;
38: import javafx.scene.input.KeyCombination;
39: import javafx.scene.input.KeyEvent;
40: import it.tidalwave.role.ui.UserAction;
41: import it.tidalwave.role.ui.javafx.JavaFXBinder;
42: import it.tidalwave.bluemarine2.ui.audio.explorer.AudioExplorerPresentation;
43: import it.tidalwave.bluemarine2.ui.audio.renderer.AudioRendererPresentation;
44: import lombok.extern.slf4j.Slf4j;
45: import static javafx.scene.input.KeyCode.*;
46:
47: /***********************************************************************************************************************
48: *
49: * The JavaFX Delegate for {@link AudioExplorerPresentation}.
50: *
51: * @stereotype JavaFXDelegate
52: *
53: * @author Fabrizio Giudici
54: *
55: **********************************************************************************************************************/
56: @Slf4j
57: public class JavaFxAudioRendererPresentationDelegate implements AudioRendererPresentation
58: {
59: @FXML
60: private Button btPrev;
61:
62: @FXML
63: private Button btRewind;
64:
65: @FXML
66: private Button btStop;
67:
68: @FXML
69: private Button btPause;
70:
71: @FXML
72: private Button btPlay;
73:
74: @FXML
75: private Button btFastForward;
76:
77: @FXML
78: private Button btNext;
79:
80: @FXML
81: private ProgressBar pbPlayProgress;
82:
83: @FXML
84: private Label lbTitle;
85:
86: @FXML
87: private Label lbFolderName;
88:
89: @FXML
90: private Label lbArtist;
91:
92: @FXML
93: private Label lbComposer;
94:
95: @FXML
96: private Label lbDuration;
97:
98: @FXML
99: private Label lbPlayTime;
100:
101: @FXML
102: private Label lbNextTrack;
103:
104: @Inject
105: private JavaFXBinder binder;
106:
107: private final Map<KeyCombination, Runnable> accelerators = new HashMap<>();
108:
109: @FXML
110: private void initialize()
111: {
112: // final ObservableMap<KeyCombination, Runnable> accelerators = btPlay.getScene().getAccelerators();
113: accelerators.put(new KeyCodeCombination(PLAY), btPlay::fire);
114: accelerators.put(new KeyCodeCombination(STOP), btStop::fire);
115: accelerators.put(new KeyCodeCombination(PAUSE), btPause::fire);
116: accelerators.put(new KeyCodeCombination(REWIND), btRewind::fire);
117: accelerators.put(new KeyCodeCombination(FAST_FWD), btFastForward::fire);
118: }
119:
120: @FXML // TODO: should be useless, but getScene().getAccelerators() doesn't work
121: public void onKeyReleased (@Nonnull final KeyEvent event)
122: {
123: accelerators.getOrDefault(new KeyCodeCombination(event.getCode()), () -> {}).run();
124: }
125:
126: @Override
127: public void bind (@Nonnull final Properties properties,
128: @Nonnull final UserAction prevAction,
129: @Nonnull final UserAction rewindAction,
130: @Nonnull final UserAction stopAction,
131: @Nonnull final UserAction pauseAction,
132: @Nonnull final UserAction playAction,
133: @Nonnull final UserAction fastForwardAction,
134: @Nonnull final UserAction nextAction)
135: {
136: binder.bind(btPrev, prevAction);
137: binder.bind(btRewind, rewindAction);
138: binder.bind(btStop, stopAction);
139: binder.bind(btPause, pauseAction);
140: binder.bind(btPlay, playAction);
141: binder.bind(btFastForward, fastForwardAction);
142: binder.bind(btNext, nextAction);
143:
144: lbTitle.textProperty().bind(properties.titleProperty());
145: lbFolderName.textProperty().bind(properties.folderNameProperty());
146: lbArtist.textProperty().bind(properties.artistProperty());
147: lbComposer.textProperty().bind(properties.composerProperty());
148: lbDuration.textProperty().bind(properties.durationProperty());
149: lbPlayTime.textProperty().bind(properties.playTimeProperty());
150: lbNextTrack.textProperty().bind(properties.nextTrackProperty());
151: pbPlayProgress.progressProperty().bind(properties.progressProperty());
152: }
153:
154: @Override
155: public void showUp (@Nonnull final Object control)
156: {
157: }
158:
159: @Override
160: public void focusOnPlayButton()
161: {
162: btPlay.requestFocus();
163: }
164:
165: @Override
166: public void focusOnStopButton()
167: {
168: btStop.requestFocus();
169: }
170: }