24 |
|
|
25 |
import java.awt.Dimension; |
import java.awt.Dimension; |
26 |
import java.awt.Insets; |
import java.awt.Insets; |
27 |
|
import java.awt.Point; |
28 |
|
|
29 |
|
import java.awt.event.MouseAdapter; |
30 |
|
import java.awt.event.MouseEvent; |
31 |
|
|
32 |
|
import java.beans.PropertyChangeEvent; |
33 |
|
import java.beans.PropertyChangeListener; |
34 |
|
|
35 |
import javax.swing.Box; |
import javax.swing.Box; |
36 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
37 |
import javax.swing.JLabel; |
import javax.swing.JLabel; |
38 |
import javax.swing.JSlider; |
import javax.swing.JSlider; |
39 |
|
import javax.swing.JToolTip; |
40 |
|
import javax.swing.Popup; |
41 |
|
import javax.swing.PopupFactory; |
42 |
|
|
43 |
|
import javax.swing.event.ChangeEvent; |
44 |
|
import javax.swing.event.ChangeListener; |
45 |
|
|
46 |
|
import org.jsampler.CC; |
47 |
|
|
48 |
|
import org.jsampler.event.SamplerAdapter; |
49 |
|
import org.jsampler.event.SamplerEvent; |
50 |
|
|
51 |
|
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
52 |
|
import static org.jsampler.view.fantasia.FantasiaPrefs.preferences; |
53 |
|
import static org.jsampler.view.std.StdPrefs.*; |
54 |
|
|
55 |
/** |
/** |
56 |
* |
* |
58 |
*/ |
*/ |
59 |
public class ChannelsBar extends PixmapPane { |
public class ChannelsBar extends PixmapPane { |
60 |
private final JSlider slVolume = new JSlider(); |
private final JSlider slVolume = new JSlider(); |
61 |
|
private Popup popup = null; |
62 |
|
private final JToolTip tip = new JToolTip(); |
63 |
|
|
64 |
/** Creates a new instance of <code>ChannelsBar</code> */ |
/** Creates a new instance of <code>ChannelsBar</code> */ |
65 |
public |
public |
80 |
slVolume.setMaximumSize(d); |
slVolume.setMaximumSize(d); |
81 |
|
|
82 |
add(slVolume); |
add(slVolume); |
83 |
|
|
84 |
add(Box.createGlue()); |
add(Box.createGlue()); |
85 |
|
|
86 |
d = new Dimension(420, 29); |
d = new Dimension(420, 29); |
88 |
setPreferredSize(d); |
setPreferredSize(d); |
89 |
setMaximumSize(d); |
setMaximumSize(d); |
90 |
|
|
91 |
|
// Setting the tooltip size |
92 |
|
tip.setTipText(i18n.getLabel("ChannelsBar.volume", 1000)); |
93 |
|
tip.setMinimumSize(tip.getPreferredSize()); |
94 |
|
tip.setPreferredSize(tip.getPreferredSize()); // workaround for preserving that size |
95 |
|
tip.setComponent(slVolume); |
96 |
|
/////// |
97 |
|
|
98 |
|
int i = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME); |
99 |
|
slVolume.setMaximum(i); |
100 |
|
String s = MAXIMUM_MASTER_VOLUME; |
101 |
|
preferences().addPropertyChangeListener(s, new PropertyChangeListener() { |
102 |
|
public void |
103 |
|
propertyChange(PropertyChangeEvent e) { |
104 |
|
int j = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME); |
105 |
|
slVolume.setMaximum(j); |
106 |
|
} |
107 |
|
}); |
108 |
|
|
109 |
|
slVolume.addChangeListener(new ChangeListener() { |
110 |
|
public void |
111 |
|
stateChanged(ChangeEvent e) { setVolume(); } |
112 |
|
}); |
113 |
|
|
114 |
|
CC.getSamplerModel().addSamplerListener(new SamplerAdapter() { |
115 |
|
public void |
116 |
|
volumeChanged(SamplerEvent e) { updateVolume(); } |
117 |
|
}); |
118 |
|
|
119 |
|
updateVolume(); |
120 |
|
|
121 |
|
slVolume.addMouseListener(new MouseAdapter() { |
122 |
|
public void |
123 |
|
mousePressed(MouseEvent e) { |
124 |
|
if(popup != null) { |
125 |
|
popup.hide(); |
126 |
|
popup = null; |
127 |
|
} |
128 |
|
|
129 |
|
Point p = slVolume.getLocationOnScreen(); |
130 |
|
PopupFactory pf = PopupFactory.getSharedInstance(); |
131 |
|
popup = pf.getPopup(slVolume, tip, p.x, p.y - 22); |
132 |
|
popup.show(); |
133 |
|
} |
134 |
|
|
135 |
|
public void |
136 |
|
mouseReleased(MouseEvent e) { |
137 |
|
if(popup != null) { |
138 |
|
popup.hide(); |
139 |
|
popup = null; |
140 |
|
} |
141 |
|
} |
142 |
|
}); |
143 |
|
} |
144 |
|
|
145 |
|
private void |
146 |
|
setVolume() { |
147 |
|
int volume = slVolume.getValue(); |
148 |
|
String s = i18n.getLabel("ChannelsBar.volume", volume); |
149 |
|
slVolume.setToolTipText(s); |
150 |
|
tip.setTipText(s); |
151 |
|
tip.repaint(); |
152 |
|
|
153 |
|
if(slVolume.getValueIsAdjusting()) return; |
154 |
|
|
155 |
|
int vol = (int)(CC.getSamplerModel().getVolume() * 100); |
156 |
|
|
157 |
|
if(vol == slVolume.getValue()) return; |
158 |
|
|
159 |
|
/* |
160 |
|
* If the model's volume is not equal to the slider |
161 |
|
* value we assume that the change is due to user input. |
162 |
|
* So we must update the volume at the backend too. |
163 |
|
*/ |
164 |
|
float v = slVolume.getValue(); |
165 |
|
v /= 100; |
166 |
|
CC.getSamplerModel().setBackendVolume(v); |
167 |
|
} |
168 |
|
|
169 |
|
private void |
170 |
|
updateVolume() { |
171 |
|
slVolume.setValue((int)(CC.getSamplerModel().getVolume() * 100)); |
172 |
} |
} |
173 |
|
|
174 |
} |
} |