1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2011 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 |
import java.beans.PropertyChangeEvent; |
27 |
import java.beans.PropertyChangeListener; |
28 |
|
29 |
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 |
import org.jsampler.view.std.StdUtils; |
43 |
|
44 |
import static org.jsampler.view.classic.A4n.a4n; |
45 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
46 |
import static org.jsampler.view.classic.ClassicPrefs.preferences; |
47 |
import static org.jsampler.JSPrefs.*; |
48 |
|
49 |
|
50 |
/** |
51 |
* |
52 |
* @author Grigor Iliev |
53 |
*/ |
54 |
public class ChannelsBar extends JToolBar { |
55 |
private final JButton btnNew = new ToolbarButton(A4n.newChannel); |
56 |
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 |
|
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 |
private final JSlider slVolume = StdUtils.createVolumeSlider(); |
68 |
|
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 |
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 |
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 |
String s = i18n.getLabel("ChannelsBar.volume", volume); |
128 |
|
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 |
} |