1 16 package com.buchuki.ensmer.input; 17 18 import com.buchuki.ensmer.*; 19 import com.buchuki.ensmer.input.event.*; 20 import com.buchuki.ensmer.input.command.*; 21 import java.awt.event.KeyEvent ; 22 23 32 public class InputManager implements InputProcessor { 33 34 39 public static CommandMap getCommandMap() { 40 return commandMap; 41 } 42 43 47 public InputManager() { 48 InputEventConverter ic = new InputEventConverter(this, EnsmerManager.instance().getInterfaceManager().getCanvas()); 49 Command escapeObjectMode = new Command() { 50 public boolean execute(EnsmerInputEvent event) { 51 if (mode == InputMode.OBJECT) { 52 systemMode(); 53 return true; 54 } 55 return false; 56 } 57 }; 58 commandMap.addCommand(this, escapeObjectMode, new KeyPressEvent( 59 KeyEvent.VK_ESCAPE)); 60 } 61 62 69 public void processInput(EnsmerInputEvent event) { 70 if (!commandMap.interpretEvent(this, event)) { 71 if (mode == InputMode.SYSTEM) { 72 systemManager.processInput(event); 73 } 74 else { 75 objectManager.processInput(event); 76 } 77 } 78 } 79 80 84 public void systemMode() { 85 mode = InputMode.SYSTEM; 86 objectManager.setFocusedObject(null); 87 EnsmerManager.instance().getInterfaceManager().setCursorVisible(false); 88 } 89 90 96 public void objectMode(Long objectID) { 97 mode = InputMode.OBJECT; 98 objectManager.setFocusedObject(objectID); 99 EnsmerManager.instance().getInterfaceManager().setCursorVisible(true); 100 } 101 102 106 public ObjectInputManager getObjectManager() { 107 return objectManager; 108 } 109 110 118 private static CommandMap commandMap = new CommandMap(); 119 120 123 private SystemInputManager systemManager = new SystemInputManager(); 124 125 128 private ObjectInputManager objectManager = new ObjectInputManager(); 129 130 133 private InputMode mode = InputMode.SYSTEM; 134 135 139 private enum InputMode {SYSTEM, OBJECT} 140 } 141 | Popular Tags |