source: trunk/gcc/libjava/javax/swing/KeyStroke.java

Last change on this file was 1389, checked in by bird, 21 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.0 KB
Line 
1/* KeyStroke.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package javax.swing;
39
40// Imports
41import java.awt.event.*;
42import java.io.*;
43
44/**
45 * KeyStroke
46 * @author Andrew Selkirk
47 * @version 1.0
48 */
49public class KeyStroke implements Serializable {
50
51 //-------------------------------------------------------------
52 // Variables --------------------------------------------------
53 //-------------------------------------------------------------
54
55 /**
56 * keyChar
57 */
58 private char keyChar = 0;
59
60 /**
61 * keyCode
62 */
63 private int keyCode = 0;
64
65 /**
66 * modifiers
67 */
68 private int modifiers = 0;
69
70 /**
71 * onKeyRelease
72 */
73 private boolean onKeyRelease = false;
74
75
76 //-------------------------------------------------------------
77 // Initialization ---------------------------------------------
78 //-------------------------------------------------------------
79
80 /**
81 * Constructor KeyStroke
82 */
83 private KeyStroke() {
84 } // KeyStroke()
85
86
87 //-------------------------------------------------------------
88 // Methods ----------------------------------------------------
89 //-------------------------------------------------------------
90
91 /**
92 * hashCode
93 * @returns int
94 */
95 public int hashCode() {
96 return 0; // TODO
97 } // hashCode()
98
99 /**
100 * equals
101 * @param object TODO
102 * @returns boolean
103 */
104 public boolean equals(Object object) {
105
106 // Variables
107 KeyStroke key;
108
109 if (object instanceof KeyStroke) {
110 key = (KeyStroke) object;
111 if (key.keyChar == keyChar &&
112 key.keyCode == keyCode &&
113 key.modifiers == modifiers &&
114 key.onKeyRelease == onKeyRelease) {
115 return true;
116 } // if
117 } // if
118 return false;
119
120 } // equals()
121
122 /**
123 * toString
124 * @returns String
125 */
126 public String toString() {
127 return null; // TODO
128 } // toString()
129
130 /**
131 * getKeyStroke
132 * @param keyChar TODO
133 * @returns KeyStroke
134 */
135 public static KeyStroke getKeyStroke(char keyChar) {
136
137 // Variables
138 KeyStroke key;
139
140 key = new KeyStroke();
141 key.keyChar = keyChar;
142 return key;
143
144 } // getKeyStroke()
145
146 /**
147 * getKeyStroke - deprecated
148 * @param keyChar TODO
149 * @param onKeyRelease TODO
150 * @returns KeyStroke
151 */
152 public static KeyStroke getKeyStroke(char keyChar, boolean onKeyRelease) {
153 KeyStroke key = getKeyStroke(keyChar);
154 key.onKeyRelease = onKeyRelease;
155 return key;
156 } // getKeyStroke()
157
158 /**
159 * getKeyStroke
160 * @param keyChar TODO
161 * @param modifiers TODO
162 * @returns KeyStroke
163 */
164 public static KeyStroke getKeyStroke(Character keyChar, int modifiers) {
165 KeyStroke key = getKeyStroke(keyChar.charValue());
166 key.modifiers = modifiers;
167 return key;
168 } // getKeyStroke()
169
170 /**
171 * getKeyStroke
172 * @param keyCode TODO
173 * @param modifiers TODO
174 * @param onKeyRelease TODO
175 * @returns KeyStroke
176 */
177 public static KeyStroke getKeyStroke(int keyCode, int modifiers,
178 boolean onKeyRelease) {
179
180 // Variables
181 KeyStroke key;
182
183 key = new KeyStroke();
184 key.keyCode = keyCode;
185 key.modifiers = modifiers;
186 key.onKeyRelease = onKeyRelease;
187 return key;
188
189 } // getKeyStroke()
190
191 /**
192 * getKeyStroke
193 * @param keyCode TODO
194 * @param modifiers TODO
195 * @returns KeyStroke
196 */
197 public static KeyStroke getKeyStroke(int keyCode, int modifiers) {
198 return getKeyStroke(keyCode, modifiers, false);
199 } // getKeyStroke()
200
201 /**
202 * getKeyStroke
203 * @param string TODO
204 * @returns KeyStroke
205 */
206 public static KeyStroke getKeyStroke(String string) {
207 return null; // TODO
208 } // getKeyStroke()
209
210 /**
211 * getKeyStrokeForEvent
212 * @param event TODO
213 * @returns KeyStroke
214 */
215 public static KeyStroke getKeyStrokeForEvent(KeyEvent event) {
216
217 // Variables
218 int eventID;
219 int eventMod;
220
221 // Get Event ID
222 eventID = event.getID();
223 eventMod = event.getModifiers();
224
225 // Check for KEY_TYPED event
226 if (eventID == KeyEvent.KEY_TYPED) {
227 return getKeyStroke(event.getKeyChar(), eventMod);
228
229 // KEY_PRESSED or KEY_RELEASED event
230 } else {
231 return getKeyStroke(event.getKeyCode(), eventMod);
232 } // if
233
234 } // getKeyStrokeForEvent()
235
236 /**
237 * getKeyChar
238 * @returns char
239 */
240 public char getKeyChar() {
241 return keyChar;
242 } // getKeyChar()
243
244 /**
245 * getKeyCode
246 * @returns int
247 */
248 public int getKeyCode() {
249 return keyCode;
250 } // getKeyCode()
251
252 /**
253 * getModifiers
254 * @returns int
255 */
256 public int getModifiers() {
257 return modifiers; // TODO
258 } // getModifiers()
259
260 /**
261 * isOnKeyRelease
262 * @returns boolean
263 */
264 public boolean isOnKeyRelease() {
265 return onKeyRelease;
266 } // isOnKeyRelease()
267
268
269} // KeyStroke
Note: See TracBrowser for help on using the repository browser.