/[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 2288 - (hide annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 5 months ago) by iliev
File size: 4294 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

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

  ViewVC Help
Powered by ViewVC