/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/Channel.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/fantasia/Channel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1732 - (hide annotations) (download)
Sat May 3 01:40:06 2008 UTC (15 years, 11 months ago) by iliev
File size: 20864 byte(s)
* Fantasia: Implemented Small View for sampler channels
  (right-click on the sampler channel then choose Small View)
* Fantasia: Implemented option to choose default sampler channel view
  (choose Edit/Preferences, then click the `Defaults' tab)
* Fantasia: Added context menu to sampler channels

1 iliev 912 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1688 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 912 *
6     * This file is part of JSampler.
7     *
8     * JSampler is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * JSampler is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with JSampler; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.jsampler.view.fantasia;
24    
25 iliev 1467 import java.awt.Container;
26 iliev 1732 import java.awt.Dimension;
27 iliev 1467 import java.awt.Rectangle;
28 iliev 912
29     import java.awt.event.ActionEvent;
30     import java.awt.event.ActionListener;
31 iliev 1732 import java.awt.event.MouseAdapter;
32     import java.awt.event.MouseEvent;
33 iliev 912
34 iliev 1285 import java.beans.PropertyChangeEvent;
35     import java.beans.PropertyChangeListener;
36    
37 iliev 1732 import java.text.NumberFormat;
38    
39     import javax.swing.AbstractAction;
40     import javax.swing.Action;
41 iliev 912 import javax.swing.BoxLayout;
42 iliev 1732 import javax.swing.ButtonGroup;
43 iliev 912 import javax.swing.DefaultListCellRenderer;
44 iliev 1732 import javax.swing.ImageIcon;
45 iliev 912 import javax.swing.JButton;
46 iliev 1540 import javax.swing.JComponent;
47 iliev 1732 import javax.swing.JLabel;
48     import javax.swing.JMenuItem;
49 iliev 912 import javax.swing.JPanel;
50 iliev 1732 import javax.swing.JPopupMenu;
51     import javax.swing.JRadioButtonMenuItem;
52 iliev 1467 import javax.swing.JScrollPane;
53 iliev 912 import javax.swing.JToggleButton;
54 iliev 1732 import javax.swing.JToolBar;
55 iliev 912
56 iliev 1732 import net.sf.juife.InformationDialog;
57 iliev 912 import net.sf.juife.TitleBar;
58    
59 iliev 1285 import org.jdesktop.swingx.JXCollapsiblePane;
60    
61 iliev 912 import org.jsampler.CC;
62 iliev 1540 import org.jsampler.HF;
63 iliev 912 import org.jsampler.SamplerChannelModel;
64    
65     import org.jsampler.event.SamplerChannelEvent;
66 iliev 1285 import org.jsampler.event.SamplerChannelListEvent;
67     import org.jsampler.event.SamplerChannelListListener;
68 iliev 912 import org.jsampler.event.SamplerChannelListener;
69    
70 iliev 1732 import org.jsampler.view.std.JSChannelOutputRoutingDlg;
71     import org.jsampler.view.std.JSFxSendsPane;
72     import org.jsampler.view.std.JSInstrumentChooser;
73     import org.jsampler.view.std.JSVolumeEditorPopup;
74    
75     import org.linuxsampler.lscp.SamplerChannel;
76    
77     import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
78 iliev 1285 import static org.jsampler.view.fantasia.FantasiaPrefs.*;
79 iliev 1732 import static org.jsampler.view.fantasia.FantasiaUtils.*;
80     import static org.jsampler.view.std.JSVolumeEditorPopup.VolumeType;
81 iliev 912
82    
83     /**
84     *
85     * @author Grigor Iliev
86     */
87     public class Channel extends org.jsampler.view.JSChannel {
88 iliev 1285 private final JXCollapsiblePane mainPane;
89 iliev 1730 private ChannelView channelView;
90     private ChannelOptionsView channelOptionsView;
91     private final ChannelOptionsPane optionsPane = new ChannelOptionsPane();
92 iliev 912
93 iliev 1732 private InformationDialog fxSendsDlg = null;
94    
95     private final ContextMenu contextMenu = new ContextMenu();
96    
97 iliev 1730 private boolean selected = false;
98 iliev 912
99 iliev 1730 private AnimatedPorpetyListener animatedPorpetyListener = new AnimatedPorpetyListener();
100 iliev 912
101 iliev 1730 class AnimatedPorpetyListener implements PropertyChangeListener {
102     public void
103     propertyChange(PropertyChangeEvent e) {
104     mainPane.setAnimated(preferences().getBoolProperty(ANIMATED));
105     }
106     }
107 iliev 912
108     /**
109     * Creates a new instance of <code>Channel</code> using the specified
110     * non-<code>null</code> channel model.
111     * @param model The model to be used by this channel.
112     * @throws IllegalArgumentException If the model is <code>null</code>.
113     */
114     public
115     Channel(SamplerChannelModel model) {
116 iliev 1318 this(model, null);
117     }
118    
119     /**
120     * Creates a new instance of <code>Channel</code> using the specified
121     * non-<code>null</code> channel model.
122     * @param model The model to be used by this channel.
123     * @param listener A listener which is notified when the newly created
124     * channel is fully expanded on the screen.
125     * @throws IllegalArgumentException If the model is <code>null</code>.
126     */
127     public
128     Channel(SamplerChannelModel model, final ActionListener listener) {
129 iliev 912 super(model);
130    
131     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
132     optionsPane.setAlignmentX(JPanel.CENTER_ALIGNMENT);
133    
134 iliev 1285 mainPane = new JXCollapsiblePane();
135     mainPane.getContentPane().setLayout (
136     new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS)
137     );
138 iliev 912
139 iliev 1732 int viewIdx = preferences().getIntProperty(DEFAULT_CHANNEL_VIEW);
140     if(viewIdx == 0) {
141     contextMenu.rbmiSmallView.doClick(0);
142     } else if(viewIdx == 1) {
143     contextMenu.rbmiNormalView.doClick(0);
144     } else {
145     contextMenu.rbmiNormalView.doClick(0);
146     }
147 iliev 1730
148 iliev 1285 setOpaque(false);
149    
150 iliev 912 getModel().addSamplerChannelListener(getHandler());
151    
152     updateChannelInfo();
153 iliev 1285
154     add(mainPane);
155    
156 iliev 1318 if(listener != null) {
157     final String s = JXCollapsiblePane.ANIMATION_STATE_KEY;
158     mainPane.addPropertyChangeListener(s, new PropertyChangeListener() {
159     public void
160     propertyChange(PropertyChangeEvent e) {
161     if(e.getNewValue() == "expanded") {
162 iliev 1467 // TODO: this should be done regardles the listener != null?
163 iliev 1318 mainPane.removePropertyChangeListener(s, this);
164 iliev 1467 ///////
165 iliev 1318 listener.actionPerformed(null);
166 iliev 1467 ensureChannelIsVisible();
167     } else if(e.getNewValue() == "expanding/collapsing") {
168     ensureChannelIsVisible();
169 iliev 1318 }
170     }
171     });
172     }
173    
174 iliev 1285 mainPane.setAnimated(false);
175     mainPane.setCollapsed(true);
176     mainPane.setAnimated(preferences().getBoolProperty(ANIMATED));
177     mainPane.setCollapsed(false);
178    
179 iliev 1730 preferences().addPropertyChangeListener(ANIMATED, animatedPorpetyListener);
180 iliev 1318
181     if(listener != null) {
182     javax.swing.SwingUtilities.invokeLater(new Runnable() {
183     public void
184     run() { listener.actionPerformed(null); }
185     });
186     }
187 iliev 1341
188     CC.getSamplerModel().addSamplerChannelListListener(getHandler());
189 iliev 912 }
190    
191 iliev 1467 private void
192     ensureChannelIsVisible() {
193     Container p = getParent();
194     JScrollPane sp = null;
195     while(p != null) {
196     if(p instanceof JScrollPane) {
197     sp = (JScrollPane)p;
198     break;
199     }
200     p = p.getParent();
201     }
202     if(sp == null) return;
203     int h = sp.getViewport().getView().getHeight();
204     sp.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1));
205     }
206    
207 iliev 912 /**
208     * Determines whether the channel is selected.
209     * @return <code>true</code> if the channel is selected, <code>false</code> otherwise.
210     */
211     public boolean isSelected() { return selected; }
212    
213     /**
214     * Sets the selection state of this channel.
215     * This method is invoked when the selection state of the channel has changed.
216     * @param select Specifies the new selection state of this channel;
217     * <code>true</code> to select the channel, <code>false</code> otherwise.
218     */
219     public void
220     setSelected(boolean select) {
221    
222     selected = select;
223     }
224    
225     /** Shows the channel properties. */
226     public void
227 iliev 1285 expandChannel() { expandChannel(optionsPane.isAnimated()); }
228 iliev 912
229 iliev 1285 /** Shows the channel properties. */
230     public void
231     expandChannel(boolean animated) {
232     boolean b = optionsPane.isAnimated();
233     optionsPane.setAnimated(animated);
234 iliev 1730 channelView.expandChannel();
235 iliev 1285 optionsPane.setAnimated(b);
236     }
237 iliev 912
238     /**
239     * Updates the channel settings. This method is invoked when changes to the
240     * channel were made.
241     */
242     private void
243     updateChannelInfo() {
244 iliev 1730 channelView.updateChannelInfo();
245     channelOptionsView.updateChannelInfo();
246 iliev 912 }
247    
248 iliev 1732 public void
249     loadInstrument() {
250     JSInstrumentChooser dlg = FantasiaUtils.createInstrumentChooser(CC.getMainFrame());
251     dlg.setVisible(true);
252    
253     if(!dlg.isCancelled()) {
254     SamplerChannelModel m = getModel();
255     m.loadBackendInstrument(dlg.getInstrumentFile(), dlg.getInstrumentIndex());
256     }
257     }
258    
259 iliev 1341 protected void
260     onDestroy() {
261     CC.getSamplerModel().removeSamplerChannelListListener(getHandler());
262 iliev 1730 preferences().removePropertyChangeListener(ANIMATED, animatedPorpetyListener);
263 iliev 1341
264 iliev 1730 channelView.uninstallView();
265     channelOptionsView.uninstallView();
266 iliev 1341 }
267 iliev 1730
268     public void
269     remove() {
270     if(!mainPane.isAnimated()) {
271     CC.getSamplerModel().removeBackendChannel(getChannelId());
272     return;
273     }
274    
275     String s = JXCollapsiblePane.ANIMATION_STATE_KEY;
276     mainPane.addPropertyChangeListener(s, getHandler());
277     mainPane.setCollapsed(true);
278     }
279 iliev 1341
280 iliev 1730 public void
281     showOptionsPane(boolean show) { optionsPane.showOptionsPane(show); }
282    
283 iliev 1732 public void
284     showFxSendsDialog() {
285     if(fxSendsDlg != null && fxSendsDlg.isVisible()) {
286     fxSendsDlg.toFront();
287     return;
288     }
289     FxSendsPane p = new FxSendsPane(getModel());
290     int id = getModel().getChannelId();
291     fxSendsDlg = new InformationDialog(CC.getMainFrame(), p);
292     fxSendsDlg.setTitle(i18n.getLabel("FxSendsDlg.title", id));
293     fxSendsDlg.setModal(false);
294     fxSendsDlg.showCloseButton(false);
295     fxSendsDlg.setVisible(true);
296     }
297    
298 iliev 912 private final EventHandler eventHandler = new EventHandler();
299    
300     private EventHandler
301     getHandler() { return eventHandler; }
302    
303 iliev 1730 private class EventHandler implements SamplerChannelListener,
304     SamplerChannelListListener, PropertyChangeListener {
305 iliev 912 /**
306     * Invoked when changes are made to a sampler channel.
307     * @param e A <code>SamplerChannelEvent</code> instance
308     * containing event information.
309     */
310     public void
311     channelChanged(SamplerChannelEvent e) { updateChannelInfo(); }
312    
313     /**
314     * Invoked when the number of active disk streams has changed.
315     * @param e A <code>SamplerChannelEvent</code> instance
316     * containing event information.
317     */
318     public void
319     streamCountChanged(SamplerChannelEvent e) {
320 iliev 1730 channelView.updateStreamCount(getModel().getStreamCount());
321 iliev 912 }
322    
323     /**
324     * Invoked when the number of active voices has changed.
325     * @param e A <code>SamplerChannelEvent</code> instance
326     * containing event information.
327     */
328     public void
329     voiceCountChanged(SamplerChannelEvent e) {
330 iliev 1730 channelView.updateVoiceCount(getModel().getVoiceCount());
331 iliev 912 }
332 iliev 1341
333     /**
334     * Invoked when a new sampler channel is created.
335     * @param e A <code>SamplerChannelListEvent</code>
336     * instance providing the event information.
337     */
338     public void
339     channelAdded(SamplerChannelListEvent e) { }
340    
341     /**
342     * Invoked when a sampler channel is removed.
343     * @param e A <code>SamplerChannelListEvent</code>
344     * instance providing the event information.
345     */
346     public void
347     channelRemoved(SamplerChannelListEvent e) {
348     // Some cleanup when the channel is removed.
349     if(e.getChannelModel().getChannelId() == getChannelId()) {
350     onDestroy();
351     }
352     }
353 iliev 1285
354 iliev 912 public void
355 iliev 1285 propertyChange(PropertyChangeEvent e) {
356     if(e.getNewValue() == "collapsed") {
357     CC.getSamplerModel().removeBackendChannel(getChannelId());
358     }
359     }
360 iliev 912 }
361 iliev 1732
362     class EditInstrumentAction extends AbstractAction implements SamplerChannelListener {
363     EditInstrumentAction() {
364     super(i18n.getMenuLabel("channels.editInstrument"));
365     channelChanged(null);
366     getModel().addSamplerChannelListener(this);
367     }
368    
369     public void
370     actionPerformed(ActionEvent e) {
371     CC.getSamplerModel().editBackendInstrument(getChannelId());
372     }
373    
374     public void
375     channelChanged(SamplerChannelEvent e) {
376     boolean b = getChannelInfo().getInstrumentStatus() == 100;
377     setEnabled(b);
378     }
379    
380     public void
381     streamCountChanged(SamplerChannelEvent e) { }
382    
383     public void
384     voiceCountChanged(SamplerChannelEvent e) { }
385     }
386    
387     class FxSendsAction extends AbstractAction {
388     FxSendsAction() {
389     super(i18n.getMenuLabel("channels.fxSends"));
390     }
391    
392     public void
393     actionPerformed(ActionEvent e) {
394     showFxSendsDialog();
395     }
396     }
397    
398     class ChannelRoutingAction extends AbstractAction implements SamplerChannelListener {
399     ChannelRoutingAction() {
400     super(i18n.getMenuLabel("channels.channelRouting"));
401     channelChanged(null);
402     getModel().addSamplerChannelListener(this);
403     }
404    
405     public void
406     actionPerformed(ActionEvent e) {
407     SamplerChannel c = getChannelInfo();
408     new JSChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true);
409     }
410    
411     public void
412     channelChanged(SamplerChannelEvent e) {
413     boolean b = getChannelInfo().getAudioOutputDevice() != -1;
414     setEnabled(b);
415     }
416    
417     public void
418     streamCountChanged(SamplerChannelEvent e) { }
419    
420     public void
421     voiceCountChanged(SamplerChannelEvent e) { }
422     }
423    
424     class SetSmallViewAction extends AbstractAction {
425     SetSmallViewAction() {
426     super(i18n.getMenuLabel("channels.smallView"));
427     }
428    
429     public void
430     actionPerformed(ActionEvent e) {
431     if(channelView instanceof SmallChannelView) return;
432    
433     if(channelView != null) {
434     mainPane.remove(channelView.getComponent());
435     mainPane.remove(optionsPane);
436    
437     channelView.uninstallView();
438     channelOptionsView.uninstallView();
439     }
440    
441     channelView = new SmallChannelView(Channel.this);
442     channelOptionsView = channelView.getChannelOptionsView();
443    
444     optionsPane.setContentPane(channelOptionsView.getComponent());
445    
446     updateChannelInfo();
447    
448     mainPane.add(channelView.getComponent());
449     mainPane.add(optionsPane);
450     mainPane.validate();
451     }
452     }
453    
454     class SetNormalViewAction extends AbstractAction {
455     SetNormalViewAction() {
456     super(i18n.getMenuLabel("channels.normalView"));
457     }
458    
459     public void
460     actionPerformed(ActionEvent e) {
461     if(channelView instanceof NormalChannelView) return;
462    
463     if(channelView != null) {
464     mainPane.remove(channelView.getComponent());
465     mainPane.remove(optionsPane);
466    
467     channelView.uninstallView();
468     channelOptionsView.uninstallView();
469     }
470    
471     channelView = new NormalChannelView(Channel.this);
472     channelOptionsView = channelView.getChannelOptionsView();
473    
474     optionsPane.setContentPane(channelOptionsView.getComponent());
475    
476     updateChannelInfo();
477    
478     mainPane.add(channelView.getComponent());
479     mainPane.add(optionsPane);
480     mainPane.validate();
481     }
482     }
483    
484     public ContextMenu
485     getContextMenu() { return contextMenu; }
486    
487     class ContextMenu extends MouseAdapter {
488     private final JPopupMenu menu = new JPopupMenu();
489    
490     protected final JRadioButtonMenuItem rbmiSmallView;
491     protected final JRadioButtonMenuItem rbmiNormalView;
492    
493     ContextMenu() {
494     menu.add(new JMenuItem(new EditInstrumentAction()));
495     menu.addSeparator();
496    
497     rbmiSmallView = new JRadioButtonMenuItem(new SetSmallViewAction());
498     rbmiNormalView = new JRadioButtonMenuItem(new SetNormalViewAction());
499    
500     ButtonGroup group = new ButtonGroup();
501     group.add(rbmiSmallView);
502     group.add(rbmiNormalView);
503    
504     menu.add(rbmiSmallView);
505     menu.add(rbmiNormalView);
506    
507     menu.addSeparator();
508     menu.add(new JMenuItem(new FxSendsAction()));
509     menu.add(new JMenuItem(new ChannelRoutingAction()));
510     }
511    
512     public void
513     mousePressed(MouseEvent e) {
514     if(e.isPopupTrigger()) show(e);
515     }
516    
517     public void
518     mouseReleased(MouseEvent e) {
519     if(e.isPopupTrigger()) show(e);
520     }
521    
522     void
523     show(MouseEvent e) {
524     menu.show(e.getComponent(), e.getX(), e.getY());
525     }
526     }
527    
528     class FxSendsPane extends JSFxSendsPane {
529     FxSendsPane(SamplerChannelModel model) {
530     super(model);
531    
532     actionAddFxSend.putValue(Action.SMALL_ICON, Res.iconNew16);
533     actionRemoveFxSend.putValue(Action.SMALL_ICON, Res.iconDelete16);
534     }
535    
536     protected JToolBar
537     createToolBar() {
538     JToolBar tb = new JToolBar();
539     Dimension d = new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height);
540     tb.setMaximumSize(d);
541     tb.setFloatable(false);
542     tb.setAlignmentX(JPanel.RIGHT_ALIGNMENT);
543    
544     tb.add(new ToolbarButton(actionAddFxSend));
545     tb.add(new ToolbarButton(actionRemoveFxSend));
546    
547     return tb;
548     }
549     }
550    
551     public static class StreamVoiceCountPane extends JPanel {
552     private final Channel channel;
553    
554     private final JLabel lStreams = createScreenLabel(" --");
555     private final JLabel lSlash = createScreenLabel("/");
556     private final JLabel lVoices = createScreenLabel("-- ");
557    
558     public
559     StreamVoiceCountPane(Channel channel) {
560     this.channel = channel;
561    
562     setOpaque(false);
563     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
564     lStreams.setFont(Res.fontScreenMono);
565     lStreams.setHorizontalAlignment(JLabel.RIGHT);
566     lStreams.setToolTipText(i18n.getLabel("Channel.streamVoiceCount"));
567    
568     Dimension d = lStreams.getPreferredSize();
569     lStreams.setMinimumSize(d);
570     lStreams.setPreferredSize(d);
571     lStreams.setMaximumSize(d);
572     add(lStreams);
573    
574     lSlash.setFont(Res.fontScreenMono);
575     lSlash.setToolTipText(i18n.getLabel("Channel.streamVoiceCount"));
576     add(lSlash);
577    
578     lVoices.setFont(Res.fontScreenMono);
579     lVoices.setToolTipText(i18n.getLabel("Channel.streamVoiceCount"));
580    
581     d = lStreams.getPreferredSize();
582     lVoices.setMinimumSize(d);
583     lVoices.setPreferredSize(d);
584     lVoices.setMaximumSize(d);
585     add(lVoices);
586    
587     lStreams.addMouseListener(channel.getContextMenu());
588     lSlash.addMouseListener(channel.getContextMenu());
589     lVoices.addMouseListener(channel.getContextMenu());
590     }
591    
592     public void
593     updateStreamCount(int count) {
594     lStreams.setText(count == 0 ? " --" : String.valueOf(count));
595     }
596    
597     public void
598     updateVoiceCount(int count) {
599     lVoices.setText(count == 0 ? "-- " : String.valueOf(count));
600     }
601     }
602    
603     public static class VolumePane extends JPanel {
604     private final Channel channel;
605     private final JButton btnVolume = createScreenButton("");
606     private JSVolumeEditorPopup popupVolume;
607    
608     private static NumberFormat numberFormat = NumberFormat.getInstance();
609     static { numberFormat.setMaximumFractionDigits(1); }
610    
611     public
612     VolumePane(final Channel channel) {
613     this.channel = channel;
614     setOpaque(false);
615     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
616    
617     btnVolume.setIcon(Res.iconVolume14);
618     btnVolume.setIconTextGap(2);
619     btnVolume.setAlignmentX(RIGHT_ALIGNMENT);
620     btnVolume.setHorizontalAlignment(btnVolume.LEFT);
621     updateVolumeInfo(100);
622     Dimension d = btnVolume.getPreferredSize();
623     d.width = 57;
624     btnVolume.setPreferredSize(d);
625     btnVolume.setMinimumSize(d);
626    
627     add(btnVolume);
628    
629     btnVolume.addActionListener(new ActionListener() {
630     public void
631     actionPerformed(ActionEvent e) {
632     if(popupVolume.isVisible()) {
633     popupVolume.commit();
634     popupVolume.hide();
635     } else {
636     float vol = channel.getModel().getChannelInfo().getVolume();
637     popupVolume.setCurrentVolume(vol);
638     popupVolume.show();
639     }
640     }
641     });
642    
643     popupVolume = new JSVolumeEditorPopup(btnVolume, VolumeType.CHANNEL);
644    
645     popupVolume.addActionListener(new ActionListener() {
646     public void
647     actionPerformed(ActionEvent e) {
648     channel.getModel().setBackendVolume(popupVolume.getVolumeFactor());
649     }
650     });
651    
652     btnVolume.addMouseListener(channel.getContextMenu());
653     }
654    
655     public void
656     updateVolumeInfo(int volume) {
657     if(CC.getViewConfig().isMeasurementUnitDecibel()) {
658     String s = numberFormat.format(HF.percentsToDecibels(volume));
659     btnVolume.setText(s + "dB");
660     } else {
661     btnVolume.setText(String.valueOf(volume) + "%");
662     }
663     }
664     }
665    
666     public static class PowerButton extends PixmapToggleButton implements ActionListener {
667     private final Channel channel;
668    
669     PowerButton(Channel channel) {
670     this(channel, Res.gfxPowerOff, Res.gfxPowerOn);
671     }
672    
673     PowerButton(Channel channel, ImageIcon defaultIcon, ImageIcon selectedIcon) {
674     super(defaultIcon, selectedIcon);
675    
676     this.channel = channel;
677    
678     setSelected(true);
679     addActionListener(this);
680     setToolTipText(i18n.getButtonLabel("Channel.ttRemoveChannel"));
681     }
682    
683     public void
684     actionPerformed(ActionEvent e) {
685     boolean b = preferences().getBoolProperty(CONFIRM_CHANNEL_REMOVAL);
686     if(b) {
687     String s = i18n.getMessage("Channel.remove?", channel.getChannelId());
688     if(!HF.showYesNoDialog(channel, s)) {
689     setSelected(true);
690     return;
691     }
692     }
693     channel.remove();
694     }
695    
696     public boolean
697     contains(int x, int y) { return (x - 11)*(x - 11) + (y - 11)*(y - 11) < 71; }
698     }
699    
700     public static class OptionsButton extends PixmapToggleButton implements ActionListener {
701     private final Channel channel;
702    
703     OptionsButton(Channel channel) {
704     super(Res.gfxOptionsOff, Res.gfxOptionsOn);
705    
706     this.channel = channel;
707    
708     setRolloverIcon(Res.gfxOptionsOffRO);
709     this.setRolloverSelectedIcon(Res.gfxOptionsOnRO);
710     addActionListener(this);
711     setToolTipText(i18n.getButtonLabel("Channel.ttShowOptions"));
712     }
713    
714     public void
715     actionPerformed(ActionEvent e) {
716     channel.showOptionsPane(isSelected());
717    
718     String s;
719     if(isSelected()) s = i18n.getButtonLabel("Channel.ttHideOptions");
720     else s = i18n.getButtonLabel("Channel.ttShowOptions");
721    
722     setToolTipText(s);
723     }
724    
725     public boolean
726     contains(int x, int y) { return super.contains(x, y) & y < 13; }
727     }
728 iliev 912 }
729    
730 iliev 1730 class ChannelOptionsPane extends JXCollapsiblePane {
731     ChannelOptionsPane() {
732 iliev 1285 setAnimated(false);
733     setCollapsed(true);
734     setAnimated(preferences().getBoolProperty(ANIMATED));
735    
736     preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() {
737     public void
738     propertyChange(PropertyChangeEvent e) {
739     setAnimated(preferences().getBoolProperty(ANIMATED));
740     }
741     });
742 iliev 912 }
743    
744 iliev 1730 public void
745     showOptionsPane(boolean show) { setCollapsed(!show); }
746 iliev 912 }

  ViewVC Help
Powered by ViewVC