[1824] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
| 15 | package de.ugoe.cs.autoquest.plugin.html.eventcore;
|
---|
| 16 |
|
---|
| 17 | import de.ugoe.cs.autoquest.keyboardmaps.VirtualKey;
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * <p>
|
---|
| 21 | * Map of virtual keys for HTML.
|
---|
| 22 | * </p>
|
---|
| 23 | *
|
---|
| 24 | * @version 1.0
|
---|
| 25 | * @author Patrick Harms
|
---|
| 26 | */
|
---|
| 27 | public enum HTMLVirtualKey {
|
---|
| 28 | VK_BACKSPACE(0x08, VirtualKey.BACK_SPACE),
|
---|
| 29 | VK_TAB(0x09, VirtualKey.TAB),
|
---|
| 30 | VK_RETURN(0x0D, VirtualKey.ENTER);
|
---|
| 31 |
|
---|
| 32 | /**
|
---|
| 33 | * <p>
|
---|
| 34 | * Numerical representation of the virtual key.
|
---|
| 35 | * </p>
|
---|
| 36 | */
|
---|
| 37 | private int mNumber;
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | * <p>
|
---|
| 41 | * {@link VirtualKey} represented by this HTMLVirtualKey
|
---|
| 42 | * </p>
|
---|
| 43 | */
|
---|
| 44 | private VirtualKey mRepresentedKey;
|
---|
| 45 |
|
---|
| 46 | /**
|
---|
| 47 | * <p>
|
---|
| 48 | * Constructor. Creates a new HTMLVirtualKey.
|
---|
| 49 | * </p>
|
---|
| 50 | *
|
---|
| 51 | * @param number
|
---|
| 52 | * numerical representation of the virtual key
|
---|
| 53 | * @param representedKey
|
---|
| 54 | * virtual key that is represented
|
---|
| 55 | */
|
---|
| 56 | HTMLVirtualKey(int number, VirtualKey representedKey) {
|
---|
| 57 | mNumber = number;
|
---|
| 58 | mRepresentedKey = representedKey;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /**
|
---|
| 62 | * <p>
|
---|
| 63 | * Returns the numerical representation of the virtual key.
|
---|
| 64 | * </p>
|
---|
| 65 | *
|
---|
| 66 | * @return the numerical representation
|
---|
| 67 | */
|
---|
| 68 | int getNumber() {
|
---|
| 69 | return mNumber;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /**
|
---|
| 73 | * <p>
|
---|
| 74 | * Parses an {@link String} and returns the respective HTMLVirtualKey if possible.
|
---|
| 75 | * </p>
|
---|
| 76 | *
|
---|
| 77 | * @param string
|
---|
| 78 | * String representation of the event type
|
---|
| 79 | * @return created HTMLVirtualKey
|
---|
| 80 | * @throws IllegalArgumentException
|
---|
| 81 | * thrown if there is no HTMLVirtualKey that correlates to string
|
---|
| 82 | */
|
---|
| 83 | public static HTMLVirtualKey parseVirtualKey(String string) throws IllegalArgumentException {
|
---|
| 84 | for (HTMLVirtualKey virtualKey : HTMLVirtualKey.values()) {
|
---|
| 85 | if (virtualKey.mNumber == Integer.parseInt(string)) {
|
---|
| 86 | return virtualKey;
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | throw new IllegalArgumentException("there is no virtual key with id " + string);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | /**
|
---|
| 94 | * <p>
|
---|
| 95 | * Returns the HTMLVirtualKey associated with an integer.
|
---|
| 96 | * </p>
|
---|
| 97 | *
|
---|
| 98 | * @param number
|
---|
| 99 | * integer to which the according HTMLVirtualKey is returned
|
---|
| 100 | * @return the HTMLVirtualKey
|
---|
| 101 | * @throws IllegalArgumentException
|
---|
| 102 | * thrown if there is no HTMLVirtualKey that correlates to number
|
---|
| 103 | */
|
---|
| 104 | public static HTMLVirtualKey valueOf(int number) throws IllegalArgumentException {
|
---|
| 105 | for (HTMLVirtualKey virtualKey : HTMLVirtualKey.values()) {
|
---|
| 106 | if (virtualKey.mNumber == number) {
|
---|
| 107 | return virtualKey;
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | throw new IllegalArgumentException("there is no virtual key with number " + number);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /**
|
---|
| 115 | * <p>
|
---|
| 116 | * Returns the {@link VirtualKey} associated with this HTMLVirtualKey.
|
---|
| 117 | * </p>
|
---|
| 118 | *
|
---|
| 119 | * @return the virtual key
|
---|
| 120 | */
|
---|
| 121 | public VirtualKey getKey() {
|
---|
| 122 | return mRepresentedKey;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | }
|
---|