Crossfire JXClient, Trunk  R20561
KeyEvent2.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.keybindings;
23 
24 import java.awt.event.InputEvent;
25 import java.awt.event.KeyEvent;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28 
33 public class KeyEvent2 {
34 
38  public static final int NONE = 0;
39 
43  public static final int ALT = InputEvent.ALT_MASK;
44 
48  public static final int ALT_GRAPH = InputEvent.ALT_GRAPH_MASK;
49 
53  public static final int CTRL = InputEvent.CTRL_MASK;
54 
58  public static final int META = InputEvent.META_MASK;
59 
63  public static final int SHIFT = InputEvent.SHIFT_MASK;
64 
68  public static final int MASK = ALT|ALT_GRAPH|CTRL|META|SHIFT;
69 
73  private final int keyCode;
74 
78  private final char keyChar;
79 
84  private final int modifiers;
85 
92  public KeyEvent2(final int keyCode, final char keyChar, final int modifiers) {
93  this.keyCode = keyCode;
94  this.keyChar = keyChar;
95  this.modifiers = modifiers;
96  }
97 
102  public int getKeyCode() {
103  return keyCode;
104  }
105 
110  public char getKeyChar() {
111  return keyChar;
112  }
113 
119  public int getModifiers() {
120  return modifiers;
121  }
122 
129  public boolean equalsKeyCode(@NotNull final KeyEvent2 keyEvent) {
130  return keyCode == keyEvent.keyCode && modifiers == keyEvent.modifiers;
131  }
132 
136  @Override
137  public boolean equals(@Nullable final Object obj) {
138  if (obj == null || obj.getClass() != getClass()) {
139  return false;
140  }
141  final KeyEvent2 keyEvent = (KeyEvent2)obj;
142  return keyCode == keyEvent.keyCode && keyChar == keyEvent.keyChar && modifiers == keyEvent.modifiers;
143  }
144 
148  @Override
149  public int hashCode() {
150  return keyCode^keyChar^modifiers;
151  }
152 
156  @NotNull
157  @Override
158  public String toString() {
159  return "code="+keyCode+", char="+(keyChar == KeyEvent.CHAR_UNDEFINED ? "undefined" : keyChar)+", modifiers="+modifiers;
160  }
161 
162 }
boolean equalsKeyCode(@NotNull final KeyEvent2 keyEvent)
Returns whether this key event matches the same key code as another key event.
Definition: KeyEvent2.java:129
static final int ALT
The mask for "shift".
Definition: KeyEvent2.java:43
Represents a pressed or released key.
Definition: KeyEvent2.java:33
final char keyChar
The key as a char value.
Definition: KeyEvent2.java:78
static final int META
The mask for "meta".
Definition: KeyEvent2.java:58
KeyEvent2(final int keyCode, final char keyChar, final int modifiers)
Creates a new instance.
Definition: KeyEvent2.java:92
static final int CTRL
The mask for "ctrl".
Definition: KeyEvent2.java:53
static final int NONE
The mask for "no modifier".
Definition: KeyEvent2.java:38
static final int ALT_GRAPH
The mask for "alt_graph".
Definition: KeyEvent2.java:48
static final int MASK
The mask for all used modifiers.
Definition: KeyEvent2.java:68
static final int SHIFT
The mask for "shift".
Definition: KeyEvent2.java:63