blob: 167f7719b85062ce978c7a2b342d7912bd4f59c8 [file] [log] [blame]
Constantin Kaplinsky1215b992008-04-18 09:51:44 +00001//
Constantin Kaplinsky903009e2002-05-20 10:55:47 +00002// Copyright (C) 2002 HorizonLive.com, Inc. All Rights Reserved.
Constantin Kaplinsky1215b992008-04-18 09:51:44 +00003//
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.com8091a2f2007-11-19 19:05:01 +000020package com.wimba.RfbPlayer;
wimba.comc23aeb02004-09-16 00:00:00 +000021
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000022import java.awt.*;
23import java.awt.event.*;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000024
25class ButtonPanel extends Panel implements ActionListener {
26
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000027 protected RfbPlayer player;
28 protected Button playButton;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000029 protected TextField posText;
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000030 protected TextField timeScaleText;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000031
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000032 protected int lastPosSeconds = -1;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000033
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000034 ButtonPanel(RfbPlayer player) {
35 this.player = player;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000036
37 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000038
39 playButton = new Button("Play");
40 playButton.setEnabled(false);
41 add(playButton);
42 playButton.addActionListener(this);
43
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000044 add(new Label(" Position:"));
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000045 posText = new TextField(5);
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000046 add(posText);
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000047 posText.addActionListener(this);
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000048
49 add(new Label(" Speed:"));
50 timeScaleText = new TextField(5);
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +000051 timeScaleText.setText(String.valueOf(player.getSpeed()));
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000052 add(timeScaleText);
53 timeScaleText.addActionListener(this);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000054 }
55
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +000056 public void setPaused(boolean paused) {
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000057 if (paused) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000058 playButton.setLabel("Play");
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000059 } else {
60 playButton.setLabel("Pause");
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000061 }
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000062 playButton.setEnabled(true);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000063 }
64
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000065 public void setPos(long pos) {
66 int seconds = (int)(pos / 1000);
67 if (seconds != lastPosSeconds) {
68 lastPosSeconds = seconds;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000069 char[] zeroes = {'0', '0', '0', '0'};
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000070 String text = String.valueOf(seconds);
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000071 if (text.length() < 4) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +000072 text = new String(zeroes, 0, 4 - text.length()) + text;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000073 }
74 posText.setText(text);
75 posText.setCaretPosition(text.length());
76 }
77 }
78
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000079 //
80 // Event processing.
81 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000082 public void actionPerformed(ActionEvent evt) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000083 if (evt.getSource() == playButton) {
Constantin Kaplinsky972c2572002-05-30 14:19:02 +000084 player.setPaused(playButton.getLabel().equals("Pause"));
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000085 } else if (evt.getSource() == posText) {
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000086 player.setPos(Long.parseLong(posText.getText()) * 1000);
Constantin Kaplinskyce39d3b2002-05-30 15:54:56 +000087 } else if (evt.getSource() == timeScaleText) {
Constantin Kaplinsky3044ecb2002-06-04 18:29:05 +000088 double speed = Double.valueOf(timeScaleText.getText()).doubleValue();
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +000089 if (speed <= 0.0)
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +000090 speed = 1.0;
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +000091 timeScaleText.setText(String.valueOf(speed));
92 player.setSpeed(speed);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000093 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000094 }
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +000095
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000096}
97