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 org.jetbrains.annotations.Nullable;
00026
00031 public class KeyBindingState {
00032
00036 @Nullable
00037 private final KeyBindings keyBindings;
00038
00042 @Nullable
00043 private final KeyBindings keyBindings2;
00044
00048 @Nullable
00049 private final CommandList commands;
00050
00055 private int state = 0;
00056
00061 private int type = -1;
00062
00066 private int keyCode = 0;
00067
00071 private int modifiers = 0;
00072
00081 public KeyBindingState(@Nullable final KeyBindings keyBindings, @Nullable final KeyBindings keyBindings2, @Nullable final CommandList commands) {
00082 this.keyBindings = keyBindings;
00083 this.keyBindings2 = keyBindings2;
00084 this.commands = commands;
00085 }
00086
00092 public void keyPressed(final int keyCode, final int modifiers) {
00093 state = 1;
00094 type = 0;
00095 this.keyCode = keyCode;
00096 this.modifiers = modifiers;
00097 }
00098
00104 public boolean keyReleased() {
00105 if (state == 0) {
00106 return false;
00107 }
00108
00109 assert type != -1;
00110 if (commands != null) {
00111 if (keyBindings != null) {
00112 keyBindings.addKeyBindingAsKeyCode(keyCode, modifiers, commands, false);
00113 }
00114 } else {
00115 if (keyBindings != null) {
00116 keyBindings.deleteKeyBindingAsKeyCode(keyCode, modifiers);
00117 }
00118
00119 if (keyBindings2 != null) {
00120 keyBindings2.deleteKeyBindingAsKeyCode(keyCode, modifiers);
00121 }
00122 }
00123
00124 return true;
00125 }
00126
00127 }