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

Last change on this file since 835 was 835, checked in by sherbold, 12 years ago
  • code documentation and clean-up
  • Property svn:executable set to *
File size: 2.8 KB
Line 
1
2package de.ugoe.cs.quest.plugin.jfc.eventcore;
3
4import java.awt.event.FocusEvent;
5import java.awt.event.KeyEvent;
6import java.awt.event.MouseEvent;
7
8/**
9 * <p>
10 * Enumeration to deal with JFC event ids.
11 * </p>
12 *
13 * @version 1.0
14 * @author Patrick Harms
15 */
16public enum JFCEventId {
17
18    MOUSE_CLICKED(MouseEvent.MOUSE_CLICKED), MOUSE_PRESSED(MouseEvent.MOUSE_PRESSED),
19    MOUSE_RELEASED(MouseEvent.MOUSE_RELEASED), MOUSE_MOVED(MouseEvent.MOUSE_MOVED), MOUSE_ENTERED(
20        MouseEvent.MOUSE_ENTERED), MOUSE_EXITED(MouseEvent.MOUSE_EXITED), MOUSE_DRAGGED(
21        MouseEvent.MOUSE_DRAGGED), MOUSE_WHEEL(MouseEvent.MOUSE_WHEEL), FOCUS_GAINED(
22        FocusEvent.FOCUS_GAINED), FOCUS_LOST(FocusEvent.FOCUS_LOST), KEY_TYPED(KeyEvent.KEY_TYPED),
23    KEY_PRESSED(KeyEvent.KEY_PRESSED), KEY_RELEASED(KeyEvent.KEY_RELEASED);
24
25    /**
26     * <p>
27     * Numerical representation of the event type.
28     * </p>
29     */
30    private int mNumber;
31
32    /**
33     * <p>
34     * Constructor. Creates a new JFCEventId.
35     * </p>
36     *
37     * @param number
38     *            numerical representation of the event type.
39     */
40    JFCEventId(int number) {
41        mNumber = number;
42    }
43
44    /**
45     * <p>
46     * Returns the numerical representation of the event type.
47     * </p>
48     *
49     * @return the numerical representation
50     */
51    public int getNumber() {
52        return mNumber;
53    }
54
55    /**
56     * <p>
57     * Parses an {@link String} and returns the respective JFCEventId if possible.
58     * </p>
59     *
60     * @param numberString
61     *            String representation of the event type
62     * @return created JFCEventId
63     * @throws IllegalArgumentException
64     *             thrown if there is no JFCEventId that correlates to numberString
65     */
66    public static JFCEventId parseEventId(String numberString) throws IllegalArgumentException {
67        try {
68            int number = Integer.parseInt(numberString);
69            return valueOf(number);
70        }
71        catch (NumberFormatException e) {
72            return JFCEventId.valueOf(JFCEventId.class, numberString);
73        }
74    }
75
76    /**
77     * <p>
78     * Returns the JFCEventId associated with an integer.
79     * </p>
80     *
81     * @param number
82     *            integer to which the according JFCEventId is returned
83     * @return the JFCEventId
84     * @throws IllegalArgumentException
85     *             thrown if there is no JFCEventId that correlates to number
86     */
87    public static JFCEventId valueOf(int number) throws IllegalArgumentException {
88        for (JFCEventId type : JFCEventId.values()) {
89            if (type.mNumber == number) {
90                return type;
91            }
92        }
93
94        throw new IllegalArgumentException("there is no event type with number " + number);
95    }
96
97}
Note: See TracBrowser for help on using the repository browser.