Skip to content

Method: getCode()

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.cec;
28:
29: import javax.annotation.Nonnull;
30: import javax.annotation.concurrent.Immutable;
31: import it.tidalwave.util.NotFoundException;
32: import lombok.EqualsAndHashCode;
33: import lombok.Getter;
34: import lombok.RequiredArgsConstructor;
35: import lombok.ToString;
36:
37: /***********************************************************************************************************************
38: *
39: * Represents a CEC event about a user control.
40: *
41: * @author Fabrizio Giudici
42: *
43: **********************************************************************************************************************/
44: @Immutable @Getter @EqualsAndHashCode(callSuper=true) @ToString
45: public class CecUserControlEvent extends CecEvent
46: {
47: /*******************************************************************************************************************
48: *
49: * Defines the key codes.
50: *
51: ******************************************************************************************************************/
52: @RequiredArgsConstructor @Getter
53: public enum UserControlCode
54: {
55: SELECT(0x00),
56: UP(0x01),
57: DOWN(0x02),
58: LEFT(0x03),
59: RIGHT(0x04),
60: EXIT(0x0d),
61: PLAY(0x44),
62: STOP(0x45),
63: PAUSE(0x46),
64: FAST_FORWARD(0x4b),
65: REWIND(0x4c);
66:
67: private final int code;
68:
69: @Nonnull
70: public static UserControlCode forCode (final int code)
71: throws NotFoundException
72: {
73: for (final UserControlCode userControlCode : values())
74: {
75: if (userControlCode.getCode() == code)
76: {
77: return userControlCode;
78: }
79: }
80:
81: throw new NotFoundException("CEC user control code: " + Integer.toHexString(code));
82: }
83: }
84:
85: @Nonnull
86: private final UserControlCode userControlCode;
87:
88: public CecUserControlEvent (@Nonnull final EventType eventType, @Nonnull final UserControlCode userControlCode)
89: {
90: super(eventType);
91: this.userControlCode = userControlCode;
92: }
93: }