blob: 306c62ecbf689504a6db5b6451c8e0a0b3f49abc [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.comc23aeb02004-09-16 00:00:00 +000020package com.HorizonLive.RfbPlayer;
21
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000022import java.awt.*;
23import java.awt.event.*;
24import java.io.*;
25
26class ButtonPanel extends Panel implements ActionListener {
27
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000028 protected RfbPlayer player;
29 protected Button playButton;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000030 protected TextField posText;
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000031 protected TextField timeScaleText;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000032
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000033 protected int lastPosSeconds = -1;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000034
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000035 ButtonPanel(RfbPlayer player) {
36 this.player = player;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000037
38 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000039
40 playButton = new Button("Play");
41 playButton.setEnabled(false);
42 add(playButton);
43 playButton.addActionListener(this);
44
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000045 add(new Label(" Position:"));
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000046 posText = new TextField(5);
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000047 add(posText);
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000048 posText.addActionListener(this);
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000049
50 add(new Label(" Speed:"));
51 timeScaleText = new TextField(5);
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +000052 timeScaleText.setText(String.valueOf(player.getSpeed()));
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000053 add(timeScaleText);
54 timeScaleText.addActionListener(this);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000055 }
56
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +000057 public void setPaused(boolean paused) {
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000058 if (paused) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000059 playButton.setLabel("Play");
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000060 } else {
61 playButton.setLabel("Pause");
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000062 }
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000063 playButton.setEnabled(true);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000064 }
65
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000066 public void setPos(long pos) {
67 int seconds = (int)(pos / 1000);
68 if (seconds != lastPosSeconds) {
69 lastPosSeconds = seconds;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000070 char[] zeroes = {'0', '0', '0', '0'};
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000071 String text = String.valueOf(seconds);
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000072 if (text.length() < 4) {
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +000073 text = new String(zeroes, 0, 4 - text.length()) + text;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000074 }
75 posText.setText(text);
76 posText.setCaretPosition(text.length());
77 }
78 }
79
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000080 //
81 // Event processing.
82 //
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000083 public void actionPerformed(ActionEvent evt) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000084 if (evt.getSource() == playButton) {
Constantin Kaplinsky972c2572002-05-30 14:19:02 +000085 player.setPaused(playButton.getLabel().equals("Pause"));
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000086 } else if (evt.getSource() == posText) {
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000087 player.setPos(Long.parseLong(posText.getText()) * 1000);
Constantin Kaplinskyce39d3b2002-05-30 15:54:56 +000088 } else if (evt.getSource() == timeScaleText) {
Constantin Kaplinsky3044ecb2002-06-04 18:29:05 +000089 double speed = Double.valueOf(timeScaleText.getText()).doubleValue();
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +000090 if (speed <= 0.0)
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +000091 speed = 1.0;
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +000092 timeScaleText.setText(String.valueOf(speed));
93 player.setSpeed(speed);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000094 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000095 }
Constantin Kaplinsky72e47ef2008-04-18 17:48:16 +000096
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000097}
98