Skip to content

Package: JavaFxCecNavigationAdapter

JavaFxCecNavigationAdapter

nameinstructionbranchcomplexitylinemethod
JavaFxCecNavigationAdapter()
M: 242 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 24 C: 0
0%
M: 1 C: 0
0%
afterPropertiesSet()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
destroy()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
keyPress(KeyCode)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
keyRelease(KeyCode)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
lambda$new$0()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$1()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$10()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$11()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$12()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$13()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$14()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$15()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$16()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$17()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$18()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$19()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$2()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$20()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$3()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$4()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$5()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$6()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$7()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$8()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$new$9()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$onCecUserControlEventReceived$21(CecUserControlEvent)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$onCecUserControlEventReceived$22(CecUserControlEvent)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
onCecUserControlEventReceived(CecUserControlEvent)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

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.cec.javafx.impl;
28:
29: import javax.annotation.Nonnull;
30: import javax.inject.Inject;
31: import java.util.HashMap;
32: import java.util.Map;
33: import javafx.scene.input.KeyCode;
34: import javafx.scene.robot.Robot;
35: import javafx.application.Platform;
36: import it.tidalwave.util.annotation.VisibleForTesting;
37: import it.tidalwave.messagebus.annotation.ListensTo;
38: import it.tidalwave.messagebus.annotation.SimpleMessageSubscriber;
39: import it.tidalwave.cec.CecEvent;
40: import it.tidalwave.cec.CecUserControlEvent;
41: import it.tidalwave.bluemarine2.ui.commons.flowcontroller.impl.javafx.JavaFxFlowController;
42: import lombok.extern.slf4j.Slf4j;
43: import static it.tidalwave.cec.CecEvent.EventType.*;
44: import static it.tidalwave.cec.CecUserControlEvent.UserControlCode.*;
45:
46: /***********************************************************************************************************************
47: *
48: * @author Fabrizio Giudici
49: *
50: **********************************************************************************************************************/
51: @SimpleMessageSubscriber @Slf4j
52: public class JavaFxCecNavigationAdapter
53: {
54: private final Map<CecEvent, Runnable> actionMap = new HashMap<>();
55:
56: public JavaFxCecNavigationAdapter()
57: {
58: actionMap.put(new CecUserControlEvent(USER_CONTROL_PRESSED, SELECT), () -> keyPress(KeyCode.SPACE) );
59: actionMap.put(new CecUserControlEvent(USER_CONTROL_RELEASED, SELECT), () -> keyRelease(KeyCode.SPACE) );
60: actionMap.put(new CecUserControlEvent(USER_CONTROL_PRESSED, LEFT), () -> keyPress(KeyCode.LEFT) );
61: actionMap.put(new CecUserControlEvent(USER_CONTROL_RELEASED, LEFT), () -> keyRelease(KeyCode.LEFT) );
62: actionMap.put(new CecUserControlEvent(USER_CONTROL_PRESSED, RIGHT), () -> keyPress(KeyCode.RIGHT) );
63: actionMap.put(new CecUserControlEvent(USER_CONTROL_RELEASED, RIGHT), () -> keyRelease(KeyCode.RIGHT) );
64: actionMap.put(new CecUserControlEvent(USER_CONTROL_PRESSED, UP), () -> keyPress(KeyCode.UP) );
65: actionMap.put(new CecUserControlEvent(USER_CONTROL_RELEASED, UP), () -> keyRelease(KeyCode.UP) );
66: actionMap.put(new CecUserControlEvent(USER_CONTROL_PRESSED, DOWN), () -> keyPress(KeyCode.DOWN) );
67: actionMap.put(new CecUserControlEvent(USER_CONTROL_RELEASED, DOWN), () -> keyRelease(KeyCode.DOWN) );
68: actionMap.put(new CecUserControlEvent(USER_CONTROL_PRESSED, PLAY), () -> keyPress(KeyCode.PLAY) );
69: actionMap.put(new CecUserControlEvent(USER_CONTROL_RELEASED, PLAY), () -> keyRelease(KeyCode.PLAY) );
70: actionMap.put(new CecUserControlEvent(USER_CONTROL_PRESSED, STOP), () -> keyPress(KeyCode.STOP) );
71: actionMap.put(new CecUserControlEvent(USER_CONTROL_RELEASED, STOP), () -> keyRelease(KeyCode.STOP) );
72: actionMap.put(new CecUserControlEvent(USER_CONTROL_PRESSED, PAUSE), () -> keyPress(KeyCode.PAUSE) );
73: actionMap.put(new CecUserControlEvent(USER_CONTROL_RELEASED, PAUSE), () -> keyRelease(KeyCode.PAUSE) );
74: actionMap.put(new CecUserControlEvent(USER_CONTROL_PRESSED, REWIND), () -> keyPress(KeyCode.REWIND) );
75: actionMap.put(new CecUserControlEvent(USER_CONTROL_RELEASED, REWIND), () -> keyRelease(KeyCode.REWIND) );
76: actionMap.put(new CecUserControlEvent(USER_CONTROL_PRESSED, FAST_FORWARD), () -> keyPress(KeyCode.FAST_FWD) );
77: actionMap.put(new CecUserControlEvent(USER_CONTROL_RELEASED, FAST_FORWARD), () -> keyRelease(KeyCode.FAST_FWD));
78:
79: actionMap.put(new CecUserControlEvent(USER_CONTROL_PRESSED, EXIT),
80: () -> flowController.tryToDismissCurrentPresentation());
81: }
82:
83: @Inject
84: private JavaFxFlowController flowController;
85:
86: @VisibleForTesting void onCecUserControlEventReceived (@Nonnull @ListensTo final CecUserControlEvent event)
87: {
88: log.debug("onCecUserControlEventReceived({})", event);
89: Platform.runLater(() -> actionMap.getOrDefault(event, () -> log.warn("unmapped event: {}", event)).run());
90: }
91:
92: private void keyPress (@Nonnull final KeyCode code)
93: {
94: log.debug("keyPress({})", code);
95: final Robot robot = new Robot();
96: robot.keyPress(code);
97: }
98:
99: private void keyRelease (@Nonnull final KeyCode code)
100: {
101: log.debug("keyRelease({})", code);
102: final Robot robot = new Robot();
103: robot.keyRelease(code);
104: }
105: }