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); |
| 50 | timeScaleText.setText("1.0"); |
| 51 | timeScaleText.setEnabled(false); |
| 52 | timeScaleText.setEditable(false); |
| 53 | add(timeScaleText); |
| 54 | timeScaleText.addActionListener(this); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 57 | public void setPaused(boolean paused) |
| 58 | { |
| 59 | if (paused) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 60 | playButton.setLabel("Play"); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 61 | posText.setEditable(true); |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 62 | } else { |
| 63 | playButton.setLabel("Pause"); |
| 64 | posText.setEditable(false); |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 65 | } |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 66 | playButton.setEnabled(true); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 69 | public void setPos(int pos) { |
| 70 | if (pos != lastPos) { |
| 71 | lastPos = pos; |
| 72 | char[] zeroes = {'0', '0', '0', '0'}; |
| 73 | String text = String.valueOf(pos); |
| 74 | if (text.length() < 4) { |
| 75 | text = new String(zeroes, 0, 4 - text.length()) + text; |
| 76 | } |
| 77 | posText.setText(text); |
| 78 | posText.setCaretPosition(text.length()); |
| 79 | } |
| 80 | } |
| 81 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 82 | // |
| 83 | // Event processing. |
| 84 | // |
| 85 | |
| 86 | public void actionPerformed(ActionEvent evt) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 87 | if (evt.getSource() == playButton) { |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame^] | 88 | player.setPaused(playButton.getLabel().equals("Pause")); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 89 | } else if (evt.getSource() == posText) { |
| 90 | player.setPos(Integer.parseInt(posText.getText())); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 91 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |