01: /*
02: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/vpbehaviors/KeyNavigatorBehavior.java,v 1.1 2005/04/20 21:05:13 paulby Exp $
03: *
04: * Sun Public License Notice
05: *
06: * The contents of this file are subject to the Sun Public License Version
07: * 1.0 (the "License"). You may not use this file except in compliance with
08: * the License. A copy of the License is available at http://www.sun.com/
09: *
10: * The Original Code is Java 3D(tm) Fly Through.
11: * The Initial Developer of the Original Code is Paul Byrne.
12: * Portions created by Paul Byrne are Copyright (C) 2002.
13: * All Rights Reserved.
14: *
15: * Contributor(s): Paul Byrne.
16: *
17: **/
18: package org.jdesktop.j3dfly.utils.vpbehaviors;
19:
20: import com.sun.j3d.utils.behaviors.vp.ViewPlatformAWTBehavior;
21: import com.sun.j3d.utils.behaviors.keyboard.KeyNavigator;
22: import com.sun.j3d.utils.universe.ViewingPlatform;
23: import java.awt.AWTEvent;
24: import java.awt.event.KeyEvent;
25: import java.util.Enumeration;
26:
27: /**
28: * This class is a simple behavior that invokes the KeyNavigator
29: * to modify the view platform transform.
30: */
31: public class KeyNavigatorBehavior extends ViewPlatformAWTBehavior {
32: private KeyNavigator keyNavigator;
33:
34: public KeyNavigatorBehavior() {
35: super (KEY_LISTENER | MOUSE_LISTENER);
36: }
37:
38: public void setViewingPlatform(ViewingPlatform vp) {
39: super .setViewingPlatform(vp);
40: if (vp != null)
41: keyNavigator = new KeyNavigator(targetTG);
42: else
43: keyNavigator = null;
44: }
45:
46: protected void integrateTransforms() {
47: keyNavigator.integrateTransformChanges();
48: }
49:
50: protected void processAWTEvents(final java.awt.AWTEvent[] events) {
51: motion = false;
52: for (int loop = 0; loop < events.length; loop++) {
53: if (events[loop] instanceof KeyEvent) {
54: KeyEvent eventKey = (KeyEvent) events[loop];
55: // change the transformation; for example to zoom
56: if (eventKey.getID() == KeyEvent.KEY_PRESSED
57: || eventKey.getID() == KeyEvent.KEY_RELEASED) {
58: keyNavigator.processKeyEvent(eventKey);
59: motion = true;
60: }
61: }
62: }
63: }
64:
65: }
|