Update copyright.
[official-gcc.git] / libjava / javax / swing / KeyStroke.java
blobb2687cdc18cc5dff7c9dbdb40e086d816522c7c9
1 /* KeyStroke.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.swing;
40 // Imports
41 import java.awt.event.*;
42 import java.io.*;
44 /**
45 * KeyStroke
46 * @author Andrew Selkirk
47 * @version 1.0
49 public class KeyStroke implements Serializable {
51 //-------------------------------------------------------------
52 // Variables --------------------------------------------------
53 //-------------------------------------------------------------
55 /**
56 * keyChar
58 private char keyChar = 0;
60 /**
61 * keyCode
63 private int keyCode = 0;
65 /**
66 * modifiers
68 private int modifiers = 0;
70 /**
71 * onKeyRelease
73 private boolean onKeyRelease = false;
76 //-------------------------------------------------------------
77 // Initialization ---------------------------------------------
78 //-------------------------------------------------------------
80 /**
81 * Constructor KeyStroke
83 private KeyStroke() {
84 } // KeyStroke()
87 //-------------------------------------------------------------
88 // Methods ----------------------------------------------------
89 //-------------------------------------------------------------
91 /**
92 * hashCode
93 * @returns int
95 public int hashCode() {
96 return 0; // TODO
97 } // hashCode()
99 /**
100 * equals
101 * @param object TODO
102 * @returns boolean
104 public boolean equals(Object object) {
106 // Variables
107 KeyStroke key;
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;
120 } // equals()
123 * toString
124 * @returns String
126 public String toString() {
127 return null; // TODO
128 } // toString()
131 * getKeyStroke
132 * @param keyChar TODO
133 * @returns KeyStroke
135 public static KeyStroke getKeyStroke(char keyChar) {
137 // Variables
138 KeyStroke key;
140 key = new KeyStroke();
141 key.keyChar = keyChar;
142 return key;
144 } // getKeyStroke()
147 * getKeyStroke - deprecated
148 * @param keyChar TODO
149 * @param onKeyRelease TODO
150 * @returns KeyStroke
152 public static KeyStroke getKeyStroke(char keyChar, boolean onKeyRelease) {
153 KeyStroke key = getKeyStroke(keyChar);
154 key.onKeyRelease = onKeyRelease;
155 return key;
156 } // getKeyStroke()
159 * getKeyStroke
160 * @param keyChar TODO
161 * @param modifiers TODO
162 * @returns KeyStroke
164 public static KeyStroke getKeyStroke(Character keyChar, int modifiers) {
165 KeyStroke key = getKeyStroke(keyChar.charValue());
166 key.modifiers = modifiers;
167 return key;
168 } // getKeyStroke()
171 * getKeyStroke
172 * @param keyCode TODO
173 * @param modifiers TODO
174 * @param onKeyRelease TODO
175 * @returns KeyStroke
177 public static KeyStroke getKeyStroke(int keyCode, int modifiers,
178 boolean onKeyRelease) {
180 // Variables
181 KeyStroke key;
183 key = new KeyStroke();
184 key.keyCode = keyCode;
185 key.modifiers = modifiers;
186 key.onKeyRelease = onKeyRelease;
187 return key;
189 } // getKeyStroke()
192 * getKeyStroke
193 * @param keyCode TODO
194 * @param modifiers TODO
195 * @returns KeyStroke
197 public static KeyStroke getKeyStroke(int keyCode, int modifiers) {
198 return getKeyStroke(keyCode, modifiers, false);
199 } // getKeyStroke()
202 * getKeyStroke
203 * @param string TODO
204 * @returns KeyStroke
206 public static KeyStroke getKeyStroke(String string) {
207 return null; // TODO
208 } // getKeyStroke()
211 * getKeyStrokeForEvent
212 * @param event TODO
213 * @returns KeyStroke
215 public static KeyStroke getKeyStrokeForEvent(KeyEvent event) {
217 // Variables
218 int eventID;
219 int eventMod;
221 // Get Event ID
222 eventID = event.getID();
223 eventMod = event.getModifiers();
225 // Check for KEY_TYPED event
226 if (eventID == KeyEvent.KEY_TYPED) {
227 return getKeyStroke(event.getKeyChar(), eventMod);
229 // KEY_PRESSED or KEY_RELEASED event
230 } else {
231 return getKeyStroke(event.getKeyCode(), eventMod);
232 } // if
234 } // getKeyStrokeForEvent()
237 * getKeyChar
238 * @returns char
240 public char getKeyChar() {
241 return keyChar;
242 } // getKeyChar()
245 * getKeyCode
246 * @returns int
248 public int getKeyCode() {
249 return keyCode;
250 } // getKeyCode()
253 * getModifiers
254 * @returns int
256 public int getModifiers() {
257 return modifiers; // TODO
258 } // getModifiers()
261 * isOnKeyRelease
262 * @returns boolean
264 public boolean isOnKeyRelease() {
265 return onKeyRelease;
266 } // isOnKeyRelease()
269 } // KeyStroke