01: /*
02: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/KeyControls.java,v 1.1 2005/04/20 21:04:21 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;
19:
20: import java.awt.event.KeyEvent;
21: import java.awt.BorderLayout;
22:
23: /**
24: * Monitors user key strokes in the canvas3D checking for sequences
25: * that control the app. This does not perform any java3D user motion
26: *
27: * @author Paul Byrne
28: * @version $Revision: 1.1 $
29: */
30: public class KeyControls implements java.awt.event.KeyListener {
31:
32: private J3dFly j3dfly;
33: private ControlFrame controlFrame;
34:
35: private static final int showControlsKey = KeyEvent.VK_C; // Show/Hide controls
36: private static final int helpKey = KeyEvent.VK_H; // Show help
37: private static final int quitKey = KeyEvent.VK_Q; // Quit the app
38:
39: /** Creates new KeyControls */
40: public KeyControls(J3dFly j3dfly, ControlFrame controlFrame) {
41: this .j3dfly = j3dfly;
42: this .controlFrame = controlFrame;
43: }
44:
45: public void keyReleased(final java.awt.event.KeyEvent p1) {
46: }
47:
48: public void keyPressed(final java.awt.event.KeyEvent evt) {
49: switch (evt.getKeyCode()) {
50: case showControlsKey:
51: if (controlFrame.isVisible()) {
52: controlFrame.setVisible(false);
53: } else {
54: controlFrame.setVisible(true);
55: controlFrame.toFront();
56: }
57: break;
58: case helpKey:
59: showHelpDialog();
60: break;
61: case KeyEvent.VK_HELP:
62: showHelpDialog();
63: break;
64: case quitKey:
65: j3dfly.exit();
66: break;
67: }
68: }
69:
70: public void keyTyped(final java.awt.event.KeyEvent evt) {
71: }
72:
73: public void showHelpDialog() {
74: javax.swing.JOptionPane
75: .showMessageDialog(
76: j3dfly.getContainer(),
77: "c - Show/Hide Control Panel \n h - Display this Help Message \n q - Quit the application",
78: "J3dFly Help",
79: javax.swing.JOptionPane.INFORMATION_MESSAGE);
80: }
81: }
|