1 16 package com.buchuki.ensmer; 17 18 import java.awt.event.ItemListener ; 19 import javax.swing.event.EventListenerList ; 20 import javax.vecmath.*; 21 22 import com.buchuki.ensmer.input.*; 23 import com.buchuki.ensmer.input.event.*; 24 import com.buchuki.ensmer.input.event.semantic.UserMoveEvent; 25 import com.buchuki.ensmer.input.event.semantic.UserMoveListener; 26 27 34 public class UserManager { 35 36 42 public void addUserMoveListener(UserMoveListener listener) { 43 listenerList.add(UserMoveListener.class, listener); 44 } 45 46 52 public void removeItemListener(UserMoveListener listener) { 53 listenerList.remove(UserMoveListener.class, listener); 54 } 55 56 61 public InputManager getInputManager() { 62 return inputManager; 63 } 64 65 74 public void setUserPosition(Matrix4f relativePos) { 75 Matrix4f currentPos = EnsmerManager.instance().getInterfaceManager() 76 .getViewPosition(); 77 currentPos.mul(relativePos); 78 setAbsoluteUserPosition(currentPos); 79 fireUserMoveEvent(new UserMoveEvent(this, relativePos)); 80 } 81 82 92 public void setAbsoluteUserPosition(Matrix4f absolutePos) { 93 InterfaceManager intf = EnsmerManager.instance().getInterfaceManager(); 95 AreaManager area = EnsmerManager.instance().getAreaManager(); 96 Area current = area.getCurrentArea(); 97 intf.setViewPosition(absolutePos); 98 current.setUserPosition(absolutePos); 99 } 100 101 106 protected void fireUserMoveEvent(UserMoveEvent event) { 107 Object [] listeners = listenerList.getListenerList(); 108 for (int i = listeners.length - 2; i >= 0; i -= 2) { 109 if (listeners[i] == UserMoveListener.class) { 110 ((UserMoveListener) listeners[i + 1]).userMoved(event); 111 } 112 } 113 } 114 115 118 EventListenerList listenerList = new EventListenerList (); 119 120 123 private InputManager inputManager = new InputManager(); 124 } 125 126 | Popular Tags |