source: trunk/autoquest-misc/src/main/java/de/ugoe/cs/autoquest/keyboardmaps/KeyStroke.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
File size: 5.7 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.keyboardmaps;
16
17/**
18 * <p>
19 * This class is used to define key strokes.
20 * </p>
21 *
22 * @version 1.0
23 * @author Patrick Harms
24 */
25public class KeyStroke {
26
27    /**
28     * <p>
29     * Name of the key stroke.
30     * </p>
31     */
32    private String keyStrokeName;
33
34    /**
35     * <p>
36     * {@link VirtualKey} associated with the key stroke.
37     * </p>
38     */
39    private VirtualKey virtualKey;
40
41    /**
42     * <p>
43     * Defines whether numlock is pressed during the stroke.
44     * </p>
45     */
46    private boolean numlock;
47
48    /**
49     * <p>
50     * Defines whether localstate is pressed during the stroke.
51     * </p>
52     */
53    private boolean localstate;
54
55    /**
56     * <p>
57     * Defines whether shift is pressed during the stroke.
58     * </p>
59     */
60    private boolean shift;
61
62    /**
63     * <p>
64     * Defines whether altgr is pressed during the stroke.
65     * </p>
66     */
67    private boolean altgr;
68
69    /**
70     * <p>
71     * Defines whether inhibit is pressed during the stroke.
72     * </p>
73     */
74    private boolean inhibit;
75
76    /**
77     * <p>
78     * Defines the character in which the key stroke results.
79     * </p>
80     */
81    private char character;
82
83    /**
84     * <p>
85     * Constructor. Creates a new key stroke
86     * </p>
87     *
88     * @param keyStrokeName
89     *            name of the key stroke
90     * @param virtualKey
91     *            virtual key associated with the key stroke
92     * @param numlock
93     *            defines whether numlock is pressed during the key stroke
94     * @param localstate
95     *            defines whether localstate is pressed during the key stroke
96     * @param shift
97     *            defines whether shift is pressed during the key stroke
98     * @param altgr
99     *            defines whether altgr is pressed during the key stroke
100     * @param inhibit
101     *            defines whether inhibit is pressed during the key stroke
102     * @param character
103     *            defines that character in which the key stroke results
104     */
105    public KeyStroke(String keyStrokeName,
106                     VirtualKey virtualKey,
107                     boolean numlock,
108                     boolean localstate,
109                     boolean shift,
110                     boolean altgr,
111                     boolean inhibit,
112                     char character)
113    {
114        this.keyStrokeName = keyStrokeName;
115        this.virtualKey = virtualKey;
116        this.numlock = numlock;
117        this.localstate = localstate;
118        this.shift = shift;
119        this.altgr = altgr;
120        this.inhibit = inhibit;
121        this.character = character;
122    }
123
124    /**
125     * <p>
126     * Returns the name of the key stroke.
127     * </p>
128     *
129     * @return the name
130     */
131    public String getKeyStrokeName() {
132        return keyStrokeName;
133    }
134
135    /**
136     * <p>
137     * Returns the virtual key associated with the key stroke.
138     * </p>
139     *
140     * @return the virtual key
141     */
142    public VirtualKey getVirtualKey() {
143        return virtualKey;
144    }
145
146    /**
147     * <p>
148     * Returns the character in which the key stroke results.
149     * </p>
150     *
151     * @return the character
152     */
153    public char getCharacter() {
154        return character;
155    }
156
157    /**
158     * <p>
159     * Returns whether inhibit is pressed.
160     * </p>
161     *
162     * @return true if pressed; false otherwise
163     */
164    public boolean getInhibit() {
165        return inhibit;
166    }
167
168    /**
169     * <p>
170     * Returns whether altgr is pressed.
171     * </p>
172     *
173     * @return true if pressed; false otherwise
174     */
175    public boolean getAltgr() {
176        return altgr;
177    }
178
179    /**
180     * <p>
181     * Returns whether shift is pressed.
182     * </p>
183     *
184     * @return true if pressed; false otherwise
185     */
186    public boolean getShift() {
187        return shift;
188    }
189
190    /**
191     * <p>
192     * Returns whether localstate is pressed.
193     * </p>
194     *
195     * @return true if pressed; false otherwise
196     */
197    public boolean getLocalstate() {
198        return localstate;
199    }
200
201    /**
202     * <p>
203     * Returns whether numlock is pressed.
204     * </p>
205     *
206     * @return true if pressed; false otherwise
207     */
208    public boolean getNumlock() {
209        return numlock;
210    }
211
212    /*
213     * (non-Javadoc)
214     *
215     * @see java.lang.Object#toString()
216     */
217    @Override
218    public String toString() {
219        StringBuffer toString = new StringBuffer();
220        toString.append("KeyStroke(");
221        toString.append(keyStrokeName);
222        toString.append(", ");
223        toString.append(virtualKey);
224
225        if (character != Character.UNASSIGNED) {
226            toString.append(", \'");
227            toString.append(character);
228            toString.append("\'");
229        }
230
231        if (shift) {
232            toString.append(", shift");
233        }
234
235        if (altgr) {
236            toString.append(", altgr");
237        }
238
239        if (numlock) {
240            toString.append(", numlock");
241        }
242
243        if (localstate) {
244            toString.append(", localstate");
245        }
246
247        if (inhibit) {
248            toString.append(", inhibit");
249        }
250
251        toString.append(")");
252
253        return toString.toString();
254    }
255
256}
Note: See TracBrowser for help on using the repository browser.