00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.gui.keybindings;
00023
00024 import com.realtime.crossfire.jxclient.gui.commandlist.CommandList;
00025 import java.awt.event.KeyEvent;
00026 import org.jetbrains.annotations.NotNull;
00027 import org.jetbrains.annotations.Nullable;
00028
00033 public class KeyCodeKeyBinding extends KeyBinding {
00034
00038 private final int keyCode;
00039
00043 private final int modifiers;
00044
00053 public KeyCodeKeyBinding(final int keyCode, final int modifiers, @NotNull final CommandList commands, final boolean isDefault) {
00054 super(commands, isDefault);
00055 this.keyCode = keyCode;
00056 this.modifiers = modifiers;
00057 }
00058
00063 public int getKeyCode() {
00064 return keyCode;
00065 }
00066
00071 public int getModifiers() {
00072 return modifiers;
00073 }
00074
00078 @Override
00079 public boolean equals(@Nullable final Object obj) {
00080 if (obj == null || !(obj instanceof KeyCodeKeyBinding)) {
00081 return false;
00082 }
00083
00084 final KeyCodeKeyBinding keyBinding = (KeyCodeKeyBinding)obj;
00085 return keyBinding.getKeyCode() == keyCode && keyBinding.getModifiers() == modifiers;
00086 }
00087
00091 @Override
00092 public int hashCode() {
00093 return keyCode^(modifiers<<16);
00094 }
00095
00099 @Override
00100 public boolean matchesKeyCode(final int keyCode, final int modifiers) {
00101 return this.keyCode == keyCode && this.modifiers == modifiers;
00102 }
00103
00107 @Override
00108 public boolean matchesKeyChar(final char keyChar) {
00109 return false;
00110 }
00111
00115 @Override
00116 public String getBindingDescription() {
00117 final StringBuilder sb = new StringBuilder();
00118 if (modifiers != 0) {
00119 sb.append(KeyEvent.getKeyModifiersText(modifiers)).append("+");
00120 }
00121 sb.append(KeyEvent.getKeyText(keyCode));
00122 return sb.toString();
00123 }
00124 }