blob: 62fa88b32ede8700e0a9551d3bc770aec627925c [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
48 posText = new TextField(4);
49 posText.setEditable(false);
50 add(posText);
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);
60 break;
61 case RfbPlayer.MODE_PAUSED:
62 playButton.setLabel("Stop");
63 playButton.setEnabled(true);
64 pauseButton.setLabel("Resume");
65 pauseButton.setEnabled(true);
66 break;
67 default:
68 // case RfbPlayer.MODE_STOPPED:
69 playButton.setLabel("Play");
70 playButton.setEnabled(true);
71 pauseButton.setLabel("Pause");
72 pauseButton.setEnabled(false);
73 break;
74 }
75 player.setMode(mode);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000076 }
77
Constantin Kaplinskyfe079832002-05-29 00:52:32 +000078 public void setPos(int pos) {
79 if (pos != lastPos) {
80 lastPos = pos;
81 char[] zeroes = {'0', '0', '0', '0'};
82 String text = String.valueOf(pos);
83 if (text.length() < 4) {
84 text = new String(zeroes, 0, 4 - text.length()) + text;
85 }
86 posText.setText(text);
87 posText.setCaretPosition(text.length());
88 }
89 }
90
Constantin Kaplinsky1215b992008-04-18 09:51:44 +000091 //
92 // Event processing.
93 //
94
95 public void actionPerformed(ActionEvent evt) {
Constantin Kaplinsky903009e2002-05-20 10:55:47 +000096 if (evt.getSource() == playButton) {
97 setMode((player.getMode() == RfbPlayer.MODE_STOPPED) ?
98 RfbPlayer.MODE_PLAYBACK : RfbPlayer.MODE_STOPPED);
99 } else if (evt.getSource() == pauseButton) {
100 setMode((player.getMode() == RfbPlayer.MODE_PAUSED) ?
101 RfbPlayer.MODE_PLAYBACK : RfbPlayer.MODE_PAUSED);
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000102 }
Constantin Kaplinsky1215b992008-04-18 09:51:44 +0000103 }
104}
105