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 | |
wimba.com | c23aeb0 | 2004-09-16 00:00:00 +0000 | [diff] [blame^] | 20 | package com.HorizonLive.RfbPlayer; |
| 21 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 22 | import java.awt.*; |
| 23 | import java.awt.event.*; |
| 24 | import java.io.*; |
| 25 | |
| 26 | class ButtonPanel extends Panel implements ActionListener { |
| 27 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 28 | protected RfbPlayer player; |
| 29 | protected Button playButton; |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 30 | protected TextField posText; |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 31 | protected TextField timeScaleText; |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 32 | |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame] | 33 | protected int lastPosSeconds = -1; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 34 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 35 | ButtonPanel(RfbPlayer player) { |
| 36 | this.player = player; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 37 | |
| 38 | setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 39 | |
| 40 | playButton = new Button("Play"); |
| 41 | playButton.setEnabled(false); |
| 42 | add(playButton); |
| 43 | playButton.addActionListener(this); |
| 44 | |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 45 | add(new Label(" Position:")); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 46 | posText = new TextField(5); |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 47 | add(posText); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 48 | posText.addActionListener(this); |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 49 | |
| 50 | add(new Label(" Speed:")); |
| 51 | timeScaleText = new TextField(5); |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 52 | timeScaleText.setText(String.valueOf(player.getSpeed())); |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 53 | add(timeScaleText); |
| 54 | timeScaleText.addActionListener(this); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 57 | public void setPaused(boolean paused) { |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 58 | if (paused) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 59 | playButton.setLabel("Play"); |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 60 | } else { |
| 61 | playButton.setLabel("Pause"); |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 62 | } |
Constantin Kaplinsky | ac6420d | 2002-05-29 17:05:39 +0000 | [diff] [blame] | 63 | playButton.setEnabled(true); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame] | 66 | public void setPos(long pos) { |
| 67 | int seconds = (int)(pos / 1000); |
| 68 | if (seconds != lastPosSeconds) { |
| 69 | lastPosSeconds = seconds; |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 70 | char[] zeroes = {'0', '0', '0', '0'}; |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame] | 71 | String text = String.valueOf(seconds); |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 72 | if (text.length() < 4) { |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 73 | text = new String(zeroes, 0, 4 - text.length()) + text; |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame] | 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 | // |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 83 | public void actionPerformed(ActionEvent evt) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 84 | if (evt.getSource() == playButton) { |
Constantin Kaplinsky | 972c257 | 2002-05-30 14:19:02 +0000 | [diff] [blame] | 85 | player.setPaused(playButton.getLabel().equals("Pause")); |
Constantin Kaplinsky | 30f786a | 2002-05-29 10:59:52 +0000 | [diff] [blame] | 86 | } else if (evt.getSource() == posText) { |
Constantin Kaplinsky | c833e01 | 2002-05-30 17:59:22 +0000 | [diff] [blame] | 87 | player.setPos(Long.parseLong(posText.getText()) * 1000); |
Constantin Kaplinsky | ce39d3b | 2002-05-30 15:54:56 +0000 | [diff] [blame] | 88 | } else if (evt.getSource() == timeScaleText) { |
Constantin Kaplinsky | 3044ecb | 2002-06-04 18:29:05 +0000 | [diff] [blame] | 89 | double speed = Double.valueOf(timeScaleText.getText()).doubleValue(); |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 90 | if (speed <= 0.0) |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 91 | speed = 1.0; |
Constantin Kaplinsky | 7957ca1 | 2002-05-30 16:19:11 +0000 | [diff] [blame] | 92 | timeScaleText.setText(String.valueOf(speed)); |
| 93 | player.setSpeed(speed); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 94 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 95 | } |
Constantin Kaplinsky | 72e47ef | 2008-04-18 17:48:16 +0000 | [diff] [blame] | 96 | |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 97 | } |
| 98 | |