So I add this behavior to my scene graph, and I think I'm doing everything right, and the processStimulus just doesn't get called.
I think I have all the pitfalls covered:
scheduling bounds set;
added to the graph;
wakeup condition created;
wakeupon called in both initialize() and processStimulus()...
Can anyone look at my code and tell me what I'm missing?
I add the object:
KeyBehavior keyBehavior = new KeyBehavior(locatableCallback);
keyBehavior.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0),
100));
objRoot.addChild(keyBehavior);
this is the behavior code:
public class KeyBehavior extends Behavior {
private static int deleteKey;
private WakeupOnAWTEvent condition;
private HashMap<Integer, KeyListener> map = new HashMap<Integer, KeyListener>();
private InstrumentManager manager;
public KeyBehavior(KnowsSelected knows) {
super();
manager= InstrumentManager.getInstance();
if (Util.isMac()){
deleteKey = KeyEvent.VK_BACK_SPACE;
} else {
deleteKey = KeyEvent.VK_DELETE;
}
map.put(deleteKey, new DeleteListener(knows));
}
@Override
public void initialize() {
condition = new WakeupOnAWTEvent( KeyEvent.KEY_RELEASED );
wakeupOn(condition);
}
@Override
public void processStimulus(Enumeration criteria) {
System.out.println("got here 1");
if (manager.isEditMode()){
System.out.println("got here 2");
KeyEvent kevt = (KeyEvent) ((WakeupOnAWTEvent)criteria.nextElement()).getAWTEvent()[0];
int kevtcode = kevt.getKeyCode();
System.out.print("key event code "+ kevtcode + " == delete "+ deleteKey+"?");
if (map.containsKey(kevtcode)){
map.get(kevt).keyReleased(kevt);
}
}
wakeupOn(condition);
}
}