[927] | 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.
|
---|
[835] | 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.plugin.jfc.eventcore;
|
---|
[573] | 16 |
|
---|
| 17 | import java.awt.event.FocusEvent;
|
---|
| 18 | import java.awt.event.KeyEvent;
|
---|
| 19 | import java.awt.event.MouseEvent;
|
---|
| 20 |
|
---|
| 21 | /**
|
---|
[835] | 22 | * <p>
|
---|
| 23 | * Enumeration to deal with JFC event ids.
|
---|
| 24 | * </p>
|
---|
[573] | 25 | *
|
---|
[835] | 26 | * @version 1.0
|
---|
| 27 | * @author Patrick Harms
|
---|
[573] | 28 | */
|
---|
| 29 | public enum JFCEventId {
|
---|
| 30 |
|
---|
[835] | 31 | MOUSE_CLICKED(MouseEvent.MOUSE_CLICKED), MOUSE_PRESSED(MouseEvent.MOUSE_PRESSED),
|
---|
| 32 | MOUSE_RELEASED(MouseEvent.MOUSE_RELEASED), MOUSE_MOVED(MouseEvent.MOUSE_MOVED), MOUSE_ENTERED(
|
---|
| 33 | MouseEvent.MOUSE_ENTERED), MOUSE_EXITED(MouseEvent.MOUSE_EXITED), MOUSE_DRAGGED(
|
---|
| 34 | MouseEvent.MOUSE_DRAGGED), MOUSE_WHEEL(MouseEvent.MOUSE_WHEEL), FOCUS_GAINED(
|
---|
| 35 | FocusEvent.FOCUS_GAINED), FOCUS_LOST(FocusEvent.FOCUS_LOST), KEY_TYPED(KeyEvent.KEY_TYPED),
|
---|
| 36 | KEY_PRESSED(KeyEvent.KEY_PRESSED), KEY_RELEASED(KeyEvent.KEY_RELEASED);
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 | * <p>
|
---|
| 40 | * Numerical representation of the event type.
|
---|
| 41 | * </p>
|
---|
| 42 | */
|
---|
[573] | 43 | private int mNumber;
|
---|
| 44 |
|
---|
| 45 | /**
|
---|
[835] | 46 | * <p>
|
---|
| 47 | * Constructor. Creates a new JFCEventId.
|
---|
| 48 | * </p>
|
---|
| 49 | *
|
---|
[573] | 50 | * @param number
|
---|
[835] | 51 | * numerical representation of the event type.
|
---|
[573] | 52 | */
|
---|
| 53 | JFCEventId(int number) {
|
---|
| 54 | mNumber = number;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | /**
|
---|
[835] | 58 | * <p>
|
---|
| 59 | * Returns the numerical representation of the event type.
|
---|
| 60 | * </p>
|
---|
| 61 | *
|
---|
| 62 | * @return the numerical representation
|
---|
[573] | 63 | */
|
---|
| 64 | public int getNumber() {
|
---|
| 65 | return mNumber;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | /**
|
---|
[835] | 69 | * <p>
|
---|
| 70 | * Parses an {@link String} and returns the respective JFCEventId if possible.
|
---|
| 71 | * </p>
|
---|
| 72 | *
|
---|
| 73 | * @param numberString
|
---|
| 74 | * String representation of the event type
|
---|
| 75 | * @return created JFCEventId
|
---|
| 76 | * @throws IllegalArgumentException
|
---|
| 77 | * thrown if there is no JFCEventId that correlates to numberString
|
---|
[573] | 78 | */
|
---|
[835] | 79 | public static JFCEventId parseEventId(String numberString) throws IllegalArgumentException {
|
---|
[573] | 80 | try {
|
---|
| 81 | int number = Integer.parseInt(numberString);
|
---|
| 82 | return valueOf(number);
|
---|
| 83 | }
|
---|
| 84 | catch (NumberFormatException e) {
|
---|
| 85 | return JFCEventId.valueOf(JFCEventId.class, numberString);
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | /**
|
---|
[835] | 90 | * <p>
|
---|
| 91 | * Returns the JFCEventId associated with an integer.
|
---|
| 92 | * </p>
|
---|
| 93 | *
|
---|
| 94 | * @param number
|
---|
| 95 | * integer to which the according JFCEventId is returned
|
---|
| 96 | * @return the JFCEventId
|
---|
| 97 | * @throws IllegalArgumentException
|
---|
| 98 | * thrown if there is no JFCEventId that correlates to number
|
---|
[573] | 99 | */
|
---|
[835] | 100 | public static JFCEventId valueOf(int number) throws IllegalArgumentException {
|
---|
[573] | 101 | for (JFCEventId type : JFCEventId.values()) {
|
---|
| 102 | if (type.mNumber == number) {
|
---|
| 103 | return type;
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | throw new IllegalArgumentException("there is no event type with number " + number);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | }
|
---|