- Timestamp:
- 08/17/12 08:52:45 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-misc/src/main/java/de/ugoe/cs/tasktree/keyboardmaps/VirtualKey.java
r447 r558 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Key.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 01.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.tasktree.keyboardmaps; 9 9 10 10 import java.awt.event.KeyEvent; 11 11 12 //-------------------------------------------------------------------------------------------------13 12 /** 14 13 * TODO comment 15 * 14 * 16 15 * @version $Revision: $ $Date: 01.04.2012$ 17 16 * @author 2012, last modified by $Author: patrick$ 18 17 */ 19 //------------------------------------------------------------------------------------------------- 20 public enum VirtualKey 21 { 18 public enum VirtualKey { 19 22 20 ENTER(KeyEvent.VK_ENTER), 23 21 BACK_SPACE(KeyEvent.VK_BACK_SPACE), … … 228 226 229 227 UNDEFINED(KeyEvent.VK_UNDEFINED); 230 231 /*BAR(KeyEvent.VK_UNDEFINED), 232 APOSTROPHE(KeyEvent.VK_UNDEFINED), 233 QUESTIONMARK(KeyEvent.VK_UNDEFINED), 234 DEGREE(KeyEvent.VK_UNDEFINED), 235 HENKAN_MODE(KeyEvent.VK_UNDEFINED), 236 MUHENKAN(KeyEvent.VK_UNDEFINED), 237 EISU_TOGGLE(KeyEvent.VK_UNDEFINED), 238 HANGUL(KeyEvent.VK_UNDEFINED), 239 HANGUL_HANJA(KeyEvent.VK_UNDEFINED), 240 EXECUTE(KeyEvent.VK_UNDEFINED);*/ 241 242 /** the virtual key code of the virtual key. */ 243 private int mVirtualKeyCode = -1; 244 245 /** the description of the virtual key */ 246 private String mDescription; 247 248 //----------------------------------------------------------------------------------------------- 249 /** 250 * 251 */ 252 //----------------------------------------------------------------------------------------------- 253 private VirtualKey(int virtualKeyCode) 254 { 255 mVirtualKeyCode = virtualKeyCode; 256 mDescription = KeyEvent.getKeyText(mVirtualKeyCode); 257 } 258 259 //----------------------------------------------------------------------------------------------- 260 /** 261 * @return Returns the description. 262 */ 263 //----------------------------------------------------------------------------------------------- 264 String getDescription() 265 { 266 return mDescription; 267 } 268 269 //----------------------------------------------------------------------------------------------- 270 /** 271 * 272 */ 273 //----------------------------------------------------------------------------------------------- 274 public boolean isCombinationKey() 275 { 276 switch (this) 277 { 278 case SHIFT: 279 case CONTROL: 280 case ALT: 281 case ALT_GRAPH: 282 case WINDOWS: 283 return true; 284 285 default: 286 return false; 287 } 288 } 289 290 //----------------------------------------------------------------------------------------------- 291 /** 292 * 293 */ 294 //----------------------------------------------------------------------------------------------- 295 public boolean isLockKey() 296 { 297 switch (this) 298 { 299 case CAPS_LOCK : 300 case NUM_LOCK: 301 case SCROLL_LOCK: 302 303 return true; 304 305 default: 306 return false; 307 } 308 } 309 310 //----------------------------------------------------------------------------------------------- 311 /** 312 * 313 */ 314 //----------------------------------------------------------------------------------------------- 315 public boolean isShiftKey() 316 { 317 switch (this) 318 { 319 case SHIFT: 320 return true; 321 322 default: 323 return false; 324 } 325 } 326 327 //----------------------------------------------------------------------------------------------- 328 /** 329 * 330 */ 331 //----------------------------------------------------------------------------------------------- 332 public boolean isAltKey() 333 { 334 switch (this) 335 { 336 case ALT: 337 case ALT_GRAPH: 338 return true; 339 340 default: 341 return false; 342 } 343 } 344 345 //----------------------------------------------------------------------------------------------- 346 /** 347 * 348 */ 349 //----------------------------------------------------------------------------------------------- 350 public boolean isControlKey() 351 { 352 switch (this) 353 { 354 case CONTROL: 355 return true; 356 357 default: 358 return false; 359 } 360 } 361 362 //----------------------------------------------------------------------------------------------- 363 /** 364 * 365 */ 366 //----------------------------------------------------------------------------------------------- 367 public boolean isWindowsKey() 368 { 369 switch (this) 370 { 371 case WINDOWS: 372 return true; 373 374 default: 375 return false; 376 } 377 } 378 379 //----------------------------------------------------------------------------------------------- 380 /** 381 * 382 */ 383 //----------------------------------------------------------------------------------------------- 384 public boolean isMetaKey() 385 { 386 switch (this) 387 { 388 case META: 389 return true; 390 391 default: 392 return false; 393 } 394 } 395 396 //----------------------------------------------------------------------------------------------- 397 /** 398 * 399 */ 400 //----------------------------------------------------------------------------------------------- 401 public boolean isLetter() 402 { 403 if (mVirtualKeyCode > -1) 404 { 405 return Character.isLetter((char) mVirtualKeyCode); 406 } 407 else 408 { 409 return false; 410 } 411 } 412 413 //----------------------------------------------------------------------------------------------- 414 /** 415 * 416 */ 417 //----------------------------------------------------------------------------------------------- 418 public boolean isDigit() 419 { 420 if (mVirtualKeyCode > -1) 421 { 422 return Character.isDigit(mVirtualKeyCode); 423 } 424 else 425 { 426 return false; 427 } 428 } 429 430 //----------------------------------------------------------------------------------------------- 431 /** 432 * TODO: comment 433 * 434 * @param parameter 435 * @return 436 */ 437 //----------------------------------------------------------------------------------------------- 438 public static VirtualKey parseVirtualKey(String string) 439 { 440 int virtualKeyCode = Integer.parseInt(string); 441 for (VirtualKey key1 : VirtualKey.values()) 442 { 443 if (key1.mVirtualKeyCode == virtualKeyCode) 444 { 445 return key1; 446 } 447 } 448 449 throw new IllegalArgumentException("there is no virtual key with id " + string); 450 } 451 452 //----------------------------------------------------------------------------------------------- 453 /** 454 * 455 */ 456 //----------------------------------------------------------------------------------------------- 457 public static VirtualKey valueOf(int number) 458 { 459 for (VirtualKey virtualKey : VirtualKey.values()) 460 { 461 if (virtualKey.mVirtualKeyCode == number) 462 { 463 return virtualKey; 464 } 465 } 466 467 throw new IllegalArgumentException("there is no virtual key with number " + number); 468 } 228 229 /* 230 * BAR(KeyEvent.VK_UNDEFINED), 231 * APOSTROPHE(KeyEvent.VK_UNDEFINED), 232 * QUESTIONMARK(KeyEvent.VK_UNDEFINED), 233 * DEGREE(KeyEvent.VK_UNDEFINED), 234 * HENKAN_MODE(KeyEvent.VK_UNDEFINED), 235 * MUHENKAN(KeyEvent.VK_UNDEFINED), 236 * EISU_TOGGLE(KeyEvent.VK_UNDEFINED), 237 * HANGUL(KeyEvent.VK_UNDEFINED), 238 * HANGUL_HANJA(KeyEvent.VK_UNDEFINED), 239 * EXECUTE(KeyEvent.VK_UNDEFINED); 240 */ 241 242 /** the virtual key code of the virtual key. */ 243 private int virtualKeyCode = -1; 244 245 /** the description of the virtual key */ 246 private String description; 247 248 /** 249 * 250 */ 251 private VirtualKey(int virtualKeyCode) { 252 this.virtualKeyCode = virtualKeyCode; 253 this.description = KeyEvent.getKeyText(this.virtualKeyCode); 254 } 255 256 /** 257 * @return Returns the description. 258 */ 259 String getDescription() { 260 return description; 261 } 262 263 /** 264 * 265 */ 266 public boolean isCombinationKey() { 267 switch (this) 268 { 269 case SHIFT: 270 case CONTROL: 271 case ALT: 272 case ALT_GRAPH: 273 case WINDOWS: 274 return true; 275 276 default: 277 return false; 278 } 279 } 280 281 /** 282 * 283 */ 284 public boolean isLockKey() { 285 switch (this) 286 { 287 case CAPS_LOCK: 288 case NUM_LOCK: 289 case SCROLL_LOCK: 290 return true; 291 292 default: 293 return false; 294 } 295 } 296 297 /** 298 * 299 */ 300 public boolean isShiftKey() { 301 switch (this) 302 { 303 case SHIFT: 304 return true; 305 306 default: 307 return false; 308 } 309 } 310 311 /** 312 * 313 */ 314 public boolean isAltKey() { 315 switch (this) 316 { 317 case ALT: 318 case ALT_GRAPH: 319 return true; 320 321 default: 322 return false; 323 } 324 } 325 326 /** 327 * 328 */ 329 public boolean isControlKey() { 330 switch (this) 331 { 332 case CONTROL: 333 return true; 334 335 default: 336 return false; 337 } 338 } 339 340 /** 341 * 342 */ 343 public boolean isWindowsKey() { 344 switch (this) 345 { 346 case WINDOWS: 347 return true; 348 349 default: 350 return false; 351 } 352 } 353 354 /** 355 * 356 */ 357 public boolean isMetaKey() { 358 switch (this) 359 { 360 case META: 361 return true; 362 363 default: 364 return false; 365 } 366 } 367 368 /** 369 * 370 */ 371 public boolean isLetter() { 372 if (virtualKeyCode > -1) { 373 return Character.isLetter((char) virtualKeyCode); 374 } 375 else { 376 return false; 377 } 378 } 379 380 /** 381 * 382 */ 383 public boolean isDigit() { 384 if (virtualKeyCode > -1) { 385 return Character.isDigit(virtualKeyCode); 386 } 387 else { 388 return false; 389 } 390 } 391 392 /** 393 * TODO: comment 394 * 395 * @param parameter 396 * @return 397 */ 398 public static VirtualKey parseVirtualKey(String string) { 399 int virtualKeyCode = Integer.parseInt(string); 400 for (VirtualKey key1 : VirtualKey.values()) { 401 if (key1.virtualKeyCode == virtualKeyCode) { 402 return key1; 403 } 404 } 405 406 throw new IllegalArgumentException("there is no virtual key with id " + string); 407 } 408 409 /** 410 * 411 */ 412 public static VirtualKey valueOf(int number) { 413 for (VirtualKey virtualKey : VirtualKey.values()) { 414 if (virtualKey.virtualKeyCode == number) { 415 return virtualKey; 416 } 417 } 418 419 throw new IllegalArgumentException("there is no virtual key with number " + number); 420 } 469 421 470 422 }
Note: See TracChangeset
for help on using the changeset viewer.