// Copyright 2012 Georg-August-Universität Göttingen, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package de.ugoe.cs.autoquest.plugin.html.eventcore; import de.ugoe.cs.autoquest.keyboardmaps.VirtualKey; /** *

* Map of virtual keys for HTML. *

* * @version 1.0 * @author Patrick Harms */ public enum HTMLVirtualKey { VK_BACKSPACE(0x08, VirtualKey.BACK_SPACE), VK_TAB(0x09, VirtualKey.TAB), VK_RETURN(0x0D, VirtualKey.ENTER); /** *

* Numerical representation of the virtual key. *

*/ private int mNumber; /** *

* {@link VirtualKey} represented by this HTMLVirtualKey *

*/ private VirtualKey mRepresentedKey; /** *

* Constructor. Creates a new HTMLVirtualKey. *

* * @param number * numerical representation of the virtual key * @param representedKey * virtual key that is represented */ HTMLVirtualKey(int number, VirtualKey representedKey) { mNumber = number; mRepresentedKey = representedKey; } /** *

* Returns the numerical representation of the virtual key. *

* * @return the numerical representation */ int getNumber() { return mNumber; } /** *

* Parses an {@link String} and returns the respective HTMLVirtualKey if possible. *

* * @param string * String representation of the event type * @return created HTMLVirtualKey * @throws IllegalArgumentException * thrown if there is no HTMLVirtualKey that correlates to string */ public static HTMLVirtualKey parseVirtualKey(String string) throws IllegalArgumentException { for (HTMLVirtualKey virtualKey : HTMLVirtualKey.values()) { if (virtualKey.mNumber == Integer.parseInt(string)) { return virtualKey; } } throw new IllegalArgumentException("there is no virtual key with id " + string); } /** *

* Returns the HTMLVirtualKey associated with an integer. *

* * @param number * integer to which the according HTMLVirtualKey is returned * @return the HTMLVirtualKey * @throws IllegalArgumentException * thrown if there is no HTMLVirtualKey that correlates to number */ public static HTMLVirtualKey valueOf(int number) throws IllegalArgumentException { for (HTMLVirtualKey virtualKey : HTMLVirtualKey.values()) { if (virtualKey.mNumber == number) { return virtualKey; } } throw new IllegalArgumentException("there is no virtual key with number " + number); } /** *

* Returns the {@link VirtualKey} associated with this HTMLVirtualKey. *

* * @return the virtual key */ public VirtualKey getKey() { return mRepresentedKey; } }