blob: 3b2d52f521ea41928c3c9a7644384975d5cfb5cf [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
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000020import java.awt.*;
21import java.awt.event.*;
22import java.io.*;
23
24class ButtonPanel extends Panel implements ActionListener {
25
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000026 protected RfbPlayer player;
27 protected Button playButton;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000028 protected TextField posText;
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000029 protected TextField timeScaleText;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000030
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000031 protected int lastPosSeconds = -1;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000032
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000033 ButtonPanel(RfbPlayer player) {
34 this.player = player;
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000035
36 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000037
38 playButton = new Button("Play");
39 playButton.setEnabled(false);
40 add(playButton);
41 playButton.addActionListener(this);
42
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000043 add(new Label(" Position:"));
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000044 posText = new TextField(5);
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000045 add(posText);
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000046 posText.addActionListener(this);
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000047
48 add(new Label(" Speed:"));
49 timeScaleText = new TextField(5);
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +000050 timeScaleText.setText(String.valueOf(player.getSpeed()));
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000051 add(timeScaleText);
52 timeScaleText.addActionListener(this);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000053 }
54
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000055 public void setPaused(boolean paused)
56 {
57 if (paused) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000058 playButton.setLabel("Play");
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000059 posText.setEditable(true);
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000060 } else {
61 playButton.setLabel("Pause");
62 posText.setEditable(false);
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000063 }
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000064 playButton.setEnabled(true);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000065 }
66
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000067 public void setPos(long pos) {
68 int seconds = (int)(pos / 1000);
69 if (seconds != lastPosSeconds) {
70 lastPosSeconds = seconds;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000071 char[] zeroes = {'0', '0', '0', '0'};
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000072 String text = String.valueOf(seconds);
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000073 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 Kaplinsky1215b992008-04-18 09:51:44 +000081 //
82 // Event processing.
83 //
84
85 public void actionPerformed(ActionEvent evt) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000086 if (evt.getSource() == playButton) {
Constantin Kaplinsky972c2572002-05-30 14:19:02 +000087 player.setPaused(playButton.getLabel().equals("Pause"));
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000088 } else if (evt.getSource() == posText) {
Constantin Kaplinskyc833e012002-05-30 17:59:22 +000089 player.setPos(Long.parseLong(posText.getText()) * 1000);
Constantin Kaplinskyce39d3b2002-05-30 15:54:56 +000090 } else if (evt.getSource() == timeScaleText) {
Constantin Kaplinsky3044ecb2002-06-04 18:29:05 +000091 double speed = Double.valueOf(timeScaleText.getText()).doubleValue();
Constantin Kaplinsky7957ca12002-05-30 16:19:11 +000092 if (speed <= 0.0)
93 speed = 1.0;
94 timeScaleText.setText(String.valueOf(speed));
95 player.setSpeed(speed);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000096 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000097 }
98}
99