source: trunk/src_apollo/org/apollo/gui/PlaybackControlPopup.java@ 315

Last change on this file since 315 was 315, checked in by bjn8, 16 years ago

Apollo spin-off added

File size: 7.8 KB
Line 
1package org.apollo.gui;
2
3import java.awt.Dimension;
4import java.awt.GridBagConstraints;
5import java.awt.GridBagLayout;
6import java.awt.Insets;
7import java.awt.event.ActionEvent;
8import java.awt.event.ActionListener;
9
10import javax.swing.Icon;
11import javax.swing.JButton;
12import javax.swing.JSlider;
13import javax.swing.JToggleButton;
14import javax.swing.event.ChangeEvent;
15import javax.swing.event.ChangeListener;
16
17import org.apollo.io.IconRepository;
18import org.expeditee.gui.Popup;
19
20/**
21 * A pure GUI for playback and mixing popup used for tracks and linked tracks.
22 * Does not implement beahviour - just the gui.
23 *
24 * @author Brook Novak
25 *
26 */
27public abstract class PlaybackControlPopup extends Popup implements ActionListener {
28
29 public JButton playPauseButton;
30 public JButton stopButton;
31 public JButton rewindButton;
32 public JToggleButton muteButton;
33 public JToggleButton soloButton;
34 public JButton miscButton;
35 public JSlider volumeSlider;
36
37 private boolean isUpdatingGUI = false;
38
39 private static final int BUTTON_SIZE = 40;
40
41 protected PlaybackControlPopup() {
42 super(new GridBagLayout());
43
44 playPauseButton = new JButton();
45 playPauseButton.setActionCommand("playpause");
46 playPauseButton.addActionListener(this);
47 playPauseButton.setIcon(IconRepository.getIcon("play.png"));
48 playPauseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
49 playPauseButton.setToolTipText("Play selection / Pause");
50
51 stopButton = new JButton();
52 stopButton.setEnabled(false);
53 stopButton.addActionListener(this);
54 stopButton.setActionCommand("stop");
55 stopButton.setIcon(IconRepository.getIcon("stop.png"));
56 stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
57 stopButton.setToolTipText("Stop playback");
58
59 rewindButton = new JButton();
60 rewindButton.addActionListener(this);
61 rewindButton.setActionCommand("rewind");
62 rewindButton.setIcon(IconRepository.getIcon("rewind.png"));
63 rewindButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
64 rewindButton.setToolTipText("Rewind to start");
65
66 // Icon changes
67 muteButton = new JToggleButton();
68 muteButton.setSelectedIcon(IconRepository.getIcon("volmute.png"));
69 muteButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
70 muteButton.setToolTipText("Toggle mute");
71 muteButton.addChangeListener(new ChangeListener() {
72 public void stateChanged(ChangeEvent e) {
73 if (!PlaybackControlPopup.this.isUpdatingGUI) {
74 muteChanged();
75 }
76 }
77 });
78
79 soloButton = new JToggleButton();
80 soloButton.setIcon(IconRepository.getIcon("solo.png"));
81 soloButton.setSelectedIcon(IconRepository.getIcon("soloon.png"));
82 soloButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
83 soloButton.setToolTipText("Toggle solo");
84 soloButton.addChangeListener(new ChangeListener() {
85 public void stateChanged(ChangeEvent e) {
86 if (!PlaybackControlPopup.this.isUpdatingGUI) {
87 soloChanged();
88 }
89 }
90 });
91
92 miscButton = new JButton();
93 miscButton.addActionListener(this);
94 miscButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
95
96 final int VOLUME_SPACING = 6;
97 volumeSlider = new JSlider(JSlider.HORIZONTAL);
98 volumeSlider.setPreferredSize(new Dimension(2 * (BUTTON_SIZE - VOLUME_SPACING), BUTTON_SIZE));
99 volumeSlider.setMinimum(0);
100 volumeSlider.setMaximum(100);
101 volumeSlider.addChangeListener(new ChangeListener() {
102 public void stateChanged(ChangeEvent e) {
103 if (!PlaybackControlPopup.this.isUpdatingGUI) {
104 volumeChanged();
105 }
106 // Update the icons
107 updateButtonGUI();
108 }
109 });
110
111
112 // Create the toolbar
113 GridBagConstraints c = new GridBagConstraints();
114 c.gridx = 0;
115 c.gridy = 0;
116 c.fill = GridBagConstraints.BOTH;
117 add(playPauseButton, c);
118
119 c = new GridBagConstraints();
120 c.gridx = 1;
121 c.gridy = 0;
122 c.fill = GridBagConstraints.BOTH;
123 add(stopButton, c);
124
125 c = new GridBagConstraints();
126 c.gridx = 2;
127 c.gridy = 0;
128 c.fill = GridBagConstraints.BOTH;
129 add(rewindButton, c);
130
131 c = new GridBagConstraints();
132 c.gridx = 3;
133 c.gridy = 0;
134 c.fill = GridBagConstraints.BOTH;
135 add(soloButton, c);
136
137 c = new GridBagConstraints();
138 c.gridx = 4;
139 c.gridy = 0;
140 c.fill = GridBagConstraints.BOTH;
141 add(muteButton, c);
142
143 c = new GridBagConstraints();
144 c.gridx = 5;
145 c.gridy = 0;
146 c.fill = GridBagConstraints.BOTH;
147 c.insets = new Insets(0,VOLUME_SPACING,0,VOLUME_SPACING);
148 add(volumeSlider, c);
149
150 c = new GridBagConstraints();
151 c.gridx = 7;
152 c.gridy = 0;
153 c.fill = GridBagConstraints.BOTH;
154 add(miscButton, c);
155
156//
157// GridBagConstraints c = new GridBagConstraints();
158// c.gridx = 0;
159// c.gridy = 0;
160// c.fill = GridBagConstraints.BOTH;
161// this.add(soloButton, c);
162//
163// c = new GridBagConstraints();
164// c.gridx = 1;
165// c.gridy = 0;
166// c.fill = GridBagConstraints.BOTH;
167// this.add(muteButton, c);
168//
169// c = new GridBagConstraints();
170// c.gridx = 2;
171// c.gridy = 0;
172// c.gridwidth = 2;
173// c.insets = new Insets(0,VOLUME_SPACING,0,VOLUME_SPACING);
174// c.fill = GridBagConstraints.BOTH;
175// this.add(volumeSlider, c);
176//
177// c = new GridBagConstraints();
178// c.gridx = 0;
179// c.gridy = 1;
180// c.fill = GridBagConstraints.BOTH;
181// this.add(playPauseButton, c);
182//
183// c = new GridBagConstraints();
184// c.gridx = 1;
185// c.gridy = 1;
186// c.fill = GridBagConstraints.BOTH;
187// this.add(stopButton, c);
188//
189// c = new GridBagConstraints();
190// c.gridx = 2;
191// c.gridy = 1;
192// c.fill = GridBagConstraints.BOTH;
193// this.add(rewindButton, c);
194//
195// c = new GridBagConstraints();
196// c.gridx = 3;
197// c.gridy = 1;
198// c.fill = GridBagConstraints.BOTH;
199// this.add(miscButton, c);
200//
201// this.setSize(BUTTON_SIZE * 4, BUTTON_SIZE * 2);
202
203 this.setSize(BUTTON_SIZE * 8, BUTTON_SIZE);
204
205 this.doLayout();
206
207 }
208
209 /**
210 * Sets the mute icon to represent the current volume value in the slider.
211 * Note: this is not the icon if mute is on.
212 */
213 private void updateButtonGUI() {
214
215 Icon newIcon = null;
216 if (volumeSlider.getValue() <= 25)
217 newIcon = IconRepository.getIcon("vol25.png");
218 else if (volumeSlider.getValue() <= 50)
219 newIcon = IconRepository.getIcon("vol50.png");
220 else if (volumeSlider.getValue() <= 75)
221 newIcon = IconRepository.getIcon("vol75.png");
222 else // maxing
223 newIcon = IconRepository.getIcon("vol100.png");
224
225 muteButton.setIcon(newIcon);
226 }
227
228
229 public abstract void actionPerformed(ActionEvent e);
230
231 /**
232 * Invoke when the slider changes via the user (i.e. not from a model-changed to event)
233 */
234 protected abstract void volumeChanged();
235
236 /**
237 * Invoke when mute button toggles via the user (i.e. not from a model-changed to event)
238 */
239 protected abstract void muteChanged();
240
241 /**
242 * Invoke when solo button toggles via the user (i.e. not from a model-changed to event)
243 */
244 protected abstract void soloChanged();
245
246
247 /**
248 * Updates the volume GUI.
249 * {@link #volumeChanged()} is not raised as a result of this call.
250 *
251 * @param vol
252 * The volume ranging from 0 - 100. Clamped.
253 */
254 public void updateVolume(int vol) {
255
256 if (volumeSlider.getValue() == vol) return;
257
258 // Clamp
259 if(vol < 0) vol = 0;
260 else if (vol > 100) vol = 100;
261
262 isUpdatingGUI = true;
263
264 volumeSlider.setValue(vol);
265
266 isUpdatingGUI = false;
267 }
268
269
270 /**
271 * Updates the mute button GUI.
272 * {@link #muteChanged()} is not raised as a result of this call.
273 *
274 * @param isMuted
275 * True if set gui to muted.
276 */
277 public void updateMute(boolean isMuted) {
278
279 if (muteButton.isSelected() == isMuted) return;
280
281 isUpdatingGUI = true;
282
283 muteButton.setSelected(isMuted);
284
285 isUpdatingGUI = false;
286 }
287
288
289 /**
290 * Updates the solo button GUI.
291 * {@link #muteChanged()} is not raised as a result of this call.
292 *
293 * @param isSolo
294 * True if set gui to solo on.
295 */
296 public void updateSolo(boolean isSolo) {
297
298 if (soloButton.isSelected() == isSolo) return;
299
300 isUpdatingGUI = true;
301
302 soloButton.setSelected(isSolo);
303
304 isUpdatingGUI = false;
305 }
306
307
308}
Note: See TracBrowser for help on using the repository browser.