1 16 17 package com.buchuki.ensmer.input; 18 19 import com.buchuki.ensmer.EnsmerManager; 20 import com.buchuki.ensmer.input.command.CommandMap; 21 import com.buchuki.ensmer.input.event.*; 22 import com.buchuki.ensmer.input.event.semantic.*; 23 import com.buchuki.ensmer.object.Backend; 24 import javax.swing.event.EventListenerList ; 25 26 33 public class ObjectInputManager implements InputProcessor { 34 35 42 public void processInput(EnsmerInputEvent event) { 43 if (focused == null) { 44 return; 45 } 46 CommandMap map = InputManager.getCommandMap(); 47 Backend backend = EnsmerManager.instance().getBackhoe().findBackend(focused); 48 if (backend != null) { 49 map.interpretEvent(backend, event); 50 } 51 } 52 53 61 public void setFocusedObject(Long id) { 62 if (id != null && id.equals(focused)) { 63 return; 64 } 65 Long oldFocused = focused; 66 focused = id; 67 if (oldFocused != null) { 68 fireFocusEvent(new FocusEvent(this, oldFocused, false)); 69 } 70 if (focused != null) { 71 fireFocusEvent(new FocusEvent(this, focused, true)); 72 } 73 } 74 75 82 public Long getFocusedObject() { 83 return focused; 84 } 85 86 92 public void addFocusListener(FocusListener listener) { 93 listenerList.add(FocusListener.class, listener); 94 } 95 96 102 public void removeFocusListener(FocusListener listener) { 103 listenerList.remove(FocusListener.class, listener); 104 } 105 106 111 protected void fireFocusEvent(FocusEvent event) { 112 Object [] listeners = listenerList.getListenerList(); 113 for (int i = listeners.length - 2; i >= 0; i -= 2) { 114 if (listeners[i] == FocusListener.class) { 115 ((FocusListener) listeners[i + 1]).focusChanged(event); 116 } 117 } 118 } 119 120 123 private Long focused; 124 125 128 private EventListenerList listenerList = new EventListenerList (); 129 } 130 | Popular Tags |