blob: 1a9db17f63a4aa96d6b0e57fe8c1a1adaabfb4b0 [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;
28 protected Button pauseButton;
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000029 protected TextField posText;
30
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
43 pauseButton = new Button("Pause");
44 pauseButton.setEnabled(false);
45 add(pauseButton);
46 pauseButton.addActionListener(this);
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000047
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000048 posText = new TextField(5);
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000049 add(posText);
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000050 posText.addActionListener(this);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000051 }
52
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000053 public void setMode(int mode) {
54 switch(mode) {
55 case RfbPlayer.MODE_PLAYBACK:
56 playButton.setLabel("Stop");
57 playButton.setEnabled(true);
58 pauseButton.setLabel("Pause");
59 pauseButton.setEnabled(true);
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000060 posText.setEditable(false);
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000061 break;
62 case RfbPlayer.MODE_PAUSED:
63 playButton.setLabel("Stop");
64 playButton.setEnabled(true);
65 pauseButton.setLabel("Resume");
66 pauseButton.setEnabled(true);
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000067 posText.setEditable(true);
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000068 break;
69 default:
70 // case RfbPlayer.MODE_STOPPED:
71 playButton.setLabel("Play");
72 playButton.setEnabled(true);
73 pauseButton.setLabel("Pause");
74 pauseButton.setEnabled(false);
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +000075 posText.setEditable(true);
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000076 break;
77 }
78 player.setMode(mode);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000079 }
80
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000081 public void setPos(int pos) {
82 if (pos != lastPos) {
83 lastPos = pos;
84 char[] zeroes = {'0', '0', '0', '0'};
85 String text = String.valueOf(pos);
86 if (text.length() < 4) {
87 text = new String(zeroes, 0, 4 - text.length()) + text;
88 }
89 posText.setText(text);
90 posText.setCaretPosition(text.length());
91 }
92 }
93
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000094 //
95 // Event processing.
96 //
97
98 public void actionPerformed(ActionEvent evt) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000099 if (evt.getSource() == playButton) {
100 setMode((player.getMode() == RfbPlayer.MODE_STOPPED) ?
101 RfbPlayer.MODE_PLAYBACK : RfbPlayer.MODE_STOPPED);
102 } else if (evt.getSource() == pauseButton) {
103 setMode((player.getMode() == RfbPlayer.MODE_PAUSED) ?
104 RfbPlayer.MODE_PLAYBACK : RfbPlayer.MODE_PAUSED);
Constantin Kaplinsky30f786a2002-05-29 10:59:52 +0000105 } else if (evt.getSource() == posText) {
106 player.setPos(Integer.parseInt(posText.getText()));
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000107 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000108 }
109}
110