Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 1 | // |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 2 | // Copyright (C) 2002 HorizonLive.com, Inc. All Rights Reserved. |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 3 | // |
| 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 20 | import java.awt.*; |
| 21 | import java.awt.event.*; |
| 22 | import java.io.*; |
| 23 | |
| 24 | class ButtonPanel extends Panel implements ActionListener { |
| 25 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 26 | protected RfbPlayer player; |
| 27 | protected Button playButton; |
| 28 | protected Button pauseButton; |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame^] | 29 | protected TextField posText; |
| 30 | |
| 31 | protected int lastPos = -1; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 32 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 33 | ButtonPanel(RfbPlayer player) { |
| 34 | this.player = player; |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 35 | |
| 36 | setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 37 | |
| 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 Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame^] | 47 | |
| 48 | posText = new TextField(4); |
| 49 | posText.setEditable(false); |
| 50 | add(posText); |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 53 | 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Constantin Kaplinsky | fe07983 | 2002-05-29 00:52:32 +0000 | [diff] [blame^] | 78 | 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 91 | // |
| 92 | // Event processing. |
| 93 | // |
| 94 | |
| 95 | public void actionPerformed(ActionEvent evt) { |
Constantin Kaplinsky | 903009e | 2002-05-20 10:55:47 +0000 | [diff] [blame] | 96 | 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 Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 102 | } |
Constantin Kaplinsky | 1215b99 | 2008-04-18 09:51:44 +0000 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |