1 /*
2 * jcurl java curling software framework https://JCurl.mro.name
3 * Copyright (C) 2005-2009 M. Rohrmoser
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 * Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 package org.jcurl.demo.util;
20
21 import java.awt.event.KeyEvent;
22 import java.awt.event.KeyListener;
23
24 import org.jcurl.core.api.TrajectorySet;
25
26 /**
27 * A first, simple keyboard input class. Uses a
28 * {@link org.jcurl.demo.util.RealTimePlayer}to play.
29 *
30 * @author <a href="mailto:JCurl@mro.name">M. Rohrmoser </a>
31 * @version $Id:SimpleKeys.java 378 2007-01-24 01:18:35Z mrohrmoser $
32 */
33 public class SimpleKeys implements KeyListener {
34
35 private final RealTimePlayer player;
36
37 private Thread worker = null;
38
39 public SimpleKeys(final TrajectorySet src) {
40 final double t0 = 0;
41 player = new RealTimePlayer(t0, 1.0, src);
42 }
43
44 public void keyPressed(final KeyEvent e) {
45 switch (e.getKeyCode()) {
46 case KeyEvent.VK_SPACE:
47 if (worker == null || !worker.isAlive()) {
48 worker = new Thread(player, player.getClass().getName());
49 worker.start();
50 } else {
51 worker.interrupt();
52 worker = null;
53 }
54 break;
55 case KeyEvent.VK_LEFT:
56 player.setTimeScale(-1);
57 break;
58 case KeyEvent.VK_RIGHT:
59 player.setTimeScale(1);
60 break;
61 }
62 }
63
64 public void keyReleased(final KeyEvent e) {
65 ; // nop
66 }
67
68 public void keyTyped(final KeyEvent e) {
69 ; // nop
70 }
71 }