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 | |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame^] | 31 | protected int lastPosSeconds = -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 | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame^] | 67 | public void setPos(long pos) { |
| 68 | int seconds = (int)(pos / 1000); |
| 69 | if (seconds != lastPosSeconds) { |
| 70 | lastPosSeconds = seconds; |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 71 | char[] zeroes = {'0', '0', '0', '0'}; |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame^] | 72 | String text = String.valueOf(seconds); |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 73 | if (text.length() < 4) { |
| 74 | text = new String(zeroes, 0, 4 - text.length()) + text; |
| 75 | } |
| 76 | posText.setText(text); |
| 77 | posText.setCaretPosition(text.length()); |
| 78 | } |
| 79 | } |
| 80 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 81 | // |
| 82 | // Event processing. |
| 83 | // |
| 84 | |
| 85 | public void actionPerformed(ActionEvent evt) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 86 | if (evt.getSource() == playButton) { |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 87 | player.setPaused(playButton.getLabel().equals("Pause")); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 88 | } else if (evt.getSource() == posText) { |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame^] | 89 | player.setPos(Long.parseLong(posText.getText()) * 1000); |
Constantin Kaplinsky | ce39d3b | 2002-05-30 15:54:56 +0000 | [diff] [blame] | 90 | } else if (evt.getSource() == timeScaleText) { |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 91 | double speed = Double.parseDouble(timeScaleText.getText()); |
| 92 | if (speed <= 0.0) |
| 93 | speed = 1.0; |
| 94 | timeScaleText.setText(String.valueOf(speed)); |
| 95 | player.setSpeed(speed); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 96 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |