source: trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/eventcore/JFCEventId.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:executable set to *
File size: 3.5 KB
Line 
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
15package de.ugoe.cs.autoquest.plugin.jfc.eventcore;
16
17import java.awt.event.FocusEvent;
18import java.awt.event.KeyEvent;
19import java.awt.event.MouseEvent;
20
21/**
22 * <p>
23 * Enumeration to deal with JFC event ids.
24 * </p>
25 *
26 * @version 1.0
27 * @author Patrick Harms
28 */
29public enum JFCEventId {
30
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     */
43    private int mNumber;
44
45    /**
46     * <p>
47     * Constructor. Creates a new JFCEventId.
48     * </p>
49     *
50     * @param number
51     *            numerical representation of the event type.
52     */
53    JFCEventId(int number) {
54        mNumber = number;
55    }
56
57    /**
58     * <p>
59     * Returns the numerical representation of the event type.
60     * </p>
61     *
62     * @return the numerical representation
63     */
64    public int getNumber() {
65        return mNumber;
66    }
67
68    /**
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
78     */
79    public static JFCEventId parseEventId(String numberString) throws IllegalArgumentException {
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    /**
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
99     */
100    public static JFCEventId valueOf(int number) throws IllegalArgumentException {
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}
Note: See TracBrowser for help on using the repository browser.