Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 1 | // |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 2 | // Copyright (C) 2002 HorizonLive.com, Inc. All Rights Reserved. |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 3 | // |
| 4 | // This is free software; you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation; either version 2 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This software is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this software; if not, write to the Free Software |
| 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 17 | // USA. |
| 18 | // |
| 19 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 20 | import java.awt.*; |
| 21 | import java.awt.event.*; |
| 22 | import java.io.*; |
| 23 | |
| 24 | class ButtonPanel extends Panel implements ActionListener { |
| 25 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 26 | protected RfbPlayer player; |
| 27 | protected Button playButton; |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 28 | protected TextField posText; |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 29 | protected TextField timeScaleText; |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 30 | |
| 31 | protected int lastPos = -1; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 32 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 33 | ButtonPanel(RfbPlayer player) { |
| 34 | this.player = player; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 35 | |
| 36 | setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 37 | |
| 38 | playButton = new Button("Play"); |
| 39 | playButton.setEnabled(false); |
| 40 | add(playButton); |
| 41 | playButton.addActionListener(this); |
| 42 | |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 43 | add(new Label(" Position:")); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 44 | posText = new TextField(5); |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 45 | add(posText); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 46 | posText.addActionListener(this); |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 47 | |
| 48 | add(new Label(" Speed:")); |
| 49 | timeScaleText = new TextField(5); |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 50 | timeScaleText.setText(String.valueOf(player.getSpeed())); |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 51 | add(timeScaleText); |
| 52 | timeScaleText.addActionListener(this); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 55 | public void setPaused(boolean paused) |
| 56 | { |
| 57 | if (paused) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 58 | playButton.setLabel("Play"); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 59 | posText.setEditable(true); |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 60 | } else { |
| 61 | playButton.setLabel("Pause"); |
| 62 | posText.setEditable(false); |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 63 | } |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 64 | playButton.setEnabled(true); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 67 | public void setPos(int pos) { |
| 68 | if (pos != lastPos) { |
| 69 | lastPos = pos; |
| 70 | char[] zeroes = {'0', '0', '0', '0'}; |
| 71 | String text = String.valueOf(pos); |
| 72 | if (text.length() < 4) { |
| 73 | text = new String(zeroes, 0, 4 - text.length()) + text; |
| 74 | } |
| 75 | posText.setText(text); |
| 76 | posText.setCaretPosition(text.length()); |
| 77 | } |
| 78 | } |
| 79 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 80 | // |
| 81 | // Event processing. |
| 82 | // |
| 83 | |
| 84 | public void actionPerformed(ActionEvent evt) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 85 | if (evt.getSource() == playButton) { |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 86 | player.setPaused(playButton.getLabel().equals("Pause")); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 87 | } else if (evt.getSource() == posText) { |
| 88 | player.setPos(Integer.parseInt(posText.getText())); |
Constantin Kaplinsky | ce39d3b | 2002-05-30 15:54:56 +0000 | [diff] [blame] | 89 | } else if (evt.getSource() == timeScaleText) { |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 90 | double speed = Double.parseDouble(timeScaleText.getText()); |
| 91 | if (speed <= 0.0) |
| 92 | speed = 1.0; |
| 93 | timeScaleText.setText(String.valueOf(speed)); |
| 94 | player.setSpeed(speed); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 95 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |