/[svn]/jsampler/trunk/src/org/jsampler/view/classic/ChannelsBar.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/classic/ChannelsBar.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1144 - (hide annotations) (download)
Mon Apr 2 21:39:15 2007 UTC (17 years, 1 month ago) by iliev
File size: 3820 byte(s)
- upgrading to version 0.4a

1 iliev 1144 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4     * Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>
5     *
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.classic;
24    
25     import java.awt.Dimension;
26    
27     import javax.swing.BorderFactory;
28     import javax.swing.BoxLayout;
29     import javax.swing.JButton;
30     import javax.swing.JLabel;
31     import javax.swing.JPanel;
32     import javax.swing.JSlider;
33     import javax.swing.JToolBar;
34    
35     import javax.swing.event.ChangeEvent;
36     import javax.swing.event.ChangeListener;
37    
38     import org.jsampler.CC;
39    
40     import org.jsampler.event.SamplerAdapter;
41     import org.jsampler.event.SamplerEvent;
42    
43     import static org.jsampler.view.classic.ClassicI18n.i18n;
44    
45    
46     /**
47     *
48     * @author Grigor Iliev
49     */
50     public class ChannelsBar extends JToolBar {
51     private final JButton btnNew = new ToolbarButton(A4n.newChannel);
52     private final JButton btnDuplicate = new ToolbarButton(A4n.duplicateChannels);
53     private final JButton btnUp = new ToolbarButton(A4n.moveChannelsUp);
54     private final JButton btnDown = new ToolbarButton(A4n.moveChannelsDown);
55     private final JButton btnRemove = new ToolbarButton(A4n.removeChannels);
56    
57     private final JButton btnNewTab = new ToolbarButton(A4n.newChannelsTab);
58     private final JButton btnRemoveTab = new ToolbarButton(A4n.closeChannelsTab);
59     private final JButton btnTabMoveLeft = new ToolbarButton(A4n.moveTab2Left);
60     private final JButton btnTabMoveRight = new ToolbarButton(A4n.moveTab2Right);
61    
62     private final JLabel lVolume = new JLabel(Res.iconVolume22);
63     private final JSlider slVolume = new JSlider(0, 100);
64    
65    
66     /**
67     * Creates a new instance of ChannelsBar
68     */
69     public ChannelsBar() {
70     super(i18n.getLabel("ChanelsBar.name"));
71     setFloatable(false);
72    
73     add(lVolume);
74    
75     Dimension d = new Dimension(200, slVolume.getPreferredSize().height);
76     slVolume.setPreferredSize(d);
77     slVolume.setMaximumSize(d);
78     slVolume.setOpaque(false);
79     add(slVolume);
80    
81     addSeparator();
82    
83     add(btnNew);
84     add(btnDuplicate);
85     add(btnRemove);
86     add(btnUp);
87     add(btnDown);
88    
89     addSeparator();
90    
91     add(btnNewTab);
92     add(btnRemoveTab);
93     add(btnTabMoveLeft);
94     add(btnTabMoveRight);
95    
96     slVolume.addChangeListener(new ChangeListener() {
97     public void
98     stateChanged(ChangeEvent e) { setVolume(); }
99     });
100    
101     CC.getSamplerModel().addSamplerListener(new SamplerAdapter() {
102     public void
103     volumeChanged(SamplerEvent e) { updateVolume(); }
104     });
105    
106     updateVolume();
107     }
108    
109     private void
110     setVolume() {
111     int volume = slVolume.getValue();
112     slVolume.setToolTipText(i18n.getLabel("ChannelsBar.volume", volume));
113     lVolume.setToolTipText(i18n.getLabel("ChannelsBar.volume", volume));
114    
115     if(slVolume.getValueIsAdjusting()) return;
116    
117     int vol = (int)(CC.getSamplerModel().getVolume() * 100);
118    
119     if(vol == slVolume.getValue()) return;
120    
121     /*
122     * If the model's volume is not equal to the slider
123     * value we assume that the change is due to user input.
124     * So we must update the volume at the backend too.
125     */
126     float v = slVolume.getValue();
127     v /= 100;
128     CC.getSamplerModel().setBackendVolume(v);
129     }
130    
131     private void
132     updateVolume() {
133     slVolume.setValue((int)(CC.getSamplerModel().getVolume() * 100));
134     }
135     }

  ViewVC Help
Powered by ViewVC