blob: cbfffc9cc5161c4152cd3c2c28a135f47c74535c [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
31 protected int lastPos = -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);
50 timeScaleText.setText("1.0");
51 timeScaleText.setEnabled(false);
52 timeScaleText.setEditable(false);
53 add(timeScaleText);
54 timeScaleText.addActionListener(this);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000055 }
56
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000057 public void setPaused(boolean paused)
58 {
59 if (paused) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000060 playButton.setLabel("Play");
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000061 posText.setEditable(true);
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000062 } else {
63 playButton.setLabel("Pause");
64 posText.setEditable(false);
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000065 }
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000066 playButton.setEnabled(true);
67 player.setPaused(paused);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000068 }
69
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000070 public void setPos(int pos) {
71 if (pos != lastPos) {
72 lastPos = pos;
73 char[] zeroes = {'0', '0', '0', '0'};
74 String text = String.valueOf(pos);
75 if (text.length() < 4) {
76 text = new String(zeroes, 0, 4 - text.length()) + text;
77 }
78 posText.setText(text);
79 posText.setCaretPosition(text.length());
80 }
81 }
82
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000083 //
84 // Event processing.
85 //
86
87 public void actionPerformed(ActionEvent evt) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000088 if (evt.getSource() == playButton) {
Constantin Kaplinskyac6420d2002-05-29 17:05:39 +000089 setPaused(playButton.getLabel().equals("Pause"));
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000090 } else if (evt.getSource() == posText) {
91 player.setPos(Integer.parseInt(posText.getText()));
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000092 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000093 }
94}
95