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

Diff of /jsampler/trunk/src/org/jsampler/view/fantasia/ChannelsBar.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1539 by iliev, Sat Sep 22 17:27:06 2007 UTC revision 1540 by iliev, Mon Dec 3 23:22:02 2007 UTC
# Line 26  import java.awt.Dimension; Line 26  import java.awt.Dimension;
26  import java.awt.Insets;  import java.awt.Insets;
27  import java.awt.Point;  import java.awt.Point;
28    
29    import java.awt.event.ActionEvent;
30    import java.awt.event.ActionListener;
31  import java.awt.event.MouseAdapter;  import java.awt.event.MouseAdapter;
32  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
33    
34  import java.beans.PropertyChangeEvent;  import java.beans.PropertyChangeEvent;
35  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
36    
37    import java.text.NumberFormat;
38    
39    import javax.swing.BorderFactory;
40  import javax.swing.Box;  import javax.swing.Box;
41  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
42    import javax.swing.JButton;
43  import javax.swing.JLabel;  import javax.swing.JLabel;
44    import javax.swing.JPanel;
45  import javax.swing.JSlider;  import javax.swing.JSlider;
46  import javax.swing.JToolTip;  import javax.swing.JToolTip;
 import javax.swing.Popup;  
 import javax.swing.PopupFactory;  
47    
48  import javax.swing.event.ChangeEvent;  import javax.swing.event.ChangeEvent;
49  import javax.swing.event.ChangeListener;  import javax.swing.event.ChangeListener;
50    
51  import org.jsampler.CC;  import org.jsampler.CC;
52    import org.jsampler.HF;
53    
54  import org.jsampler.event.SamplerAdapter;  import org.jsampler.event.SamplerAdapter;
55  import org.jsampler.event.SamplerEvent;  import org.jsampler.event.SamplerEvent;
56    
57    import org.jsampler.view.std.JSVolumeEditorPopup;
58    
59  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
60  import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;  import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
61    import static org.jsampler.view.fantasia.FantasiaUtils.*;
62    
63    import static org.jsampler.view.std.JSVolumeEditorPopup.VolumeType;
64  import static org.jsampler.view.std.StdPrefs.*;  import static org.jsampler.view.std.StdPrefs.*;
65    
66  /**  /**
# Line 58  import static org.jsampler.view.std.StdP Line 69  import static org.jsampler.view.std.StdP
69   */   */
70  public class ChannelsBar extends PixmapPane {  public class ChannelsBar extends PixmapPane {
71          private final JSlider slVolume = new JSlider();          private final JSlider slVolume = new JSlider();
72          private Popup popup = null;          JButton btnVolume = FantasiaUtils.createScreenButton("3 dB");
73          private final JToolTip tip = new JToolTip();          
74            private final JLabel lStreams = createScreenLabel(" --");
75            private final JLabel lVoices = createScreenLabel("-- ");
76            private JSVolumeEditorPopup popupVolume;
77            
78            private static NumberFormat numberFormat = NumberFormat.getInstance();
79                    
80          /** Creates a new instance of <code>ChannelsBar</code> */          /** Creates a new instance of <code>ChannelsBar</code> */
81          public          public
82          ChannelsBar() {          ChannelsBar() {
83                  super(Res.gfxCreateChannel);                  super(Res.gfxCreateChannel);
84                    
85                    numberFormat.setMaximumFractionDigits(1);
86                    popupVolume = new JSVolumeEditorPopup(btnVolume, VolumeType.MASTER);
87                    
88                  setPixmapInsets(new Insets(1, 1, 1, 1));                  setPixmapInsets(new Insets(1, 1, 1, 1));
89                                    
90                  setLayout(new BoxLayout(this, BoxLayout.X_AXIS));                  setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
# Line 80  public class ChannelsBar extends PixmapP Line 100  public class ChannelsBar extends PixmapP
100                  slVolume.setMaximumSize(d);                  slVolume.setMaximumSize(d);
101                                    
102                  add(slVolume);                  add(slVolume);
103                    add(Box.createRigidArea(new Dimension(5, 0)));
104                    
105                    PixmapPane p = new PixmapPane(Res.gfxTextField);
106                    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
107                    p.setPixmapInsets(new Insets(5, 5, 4, 5));
108                    p.setBorder(BorderFactory.createEmptyBorder(1, 8, 1, 5));
109                    
110                    lStreams.setFont(Res.fontScreenMono);
111                    lStreams.setHorizontalAlignment(JLabel.RIGHT);
112                    lStreams.setPreferredSize(lStreams.getPreferredSize());
113                    lStreams.setMaximumSize(lStreams.getPreferredSize());
114                    lStreams.setToolTipText(i18n.getLabel("ChannelsBar.streamVoiceCount"));
115                    p.add(lStreams);
116                    
117                    l = createScreenLabel("/");
118                    l.setFont(Res.fontScreenMono);
119                    l.setToolTipText(i18n.getLabel("ChannelsBar.streamVoiceCount"));
120                    p.add(l);
121                    
122                    lVoices.setFont(Res.fontScreenMono);
123                    lVoices.setPreferredSize(lVoices.getPreferredSize());
124                    lVoices.setMaximumSize(lVoices.getPreferredSize());
125                    lVoices.setToolTipText(i18n.getLabel("ChannelsBar.streamVoiceCount"));
126                    p.add(lVoices);
127                    
128                    add(Box.createRigidArea(new Dimension(5, 0)));
129                    
130                    btnVolume.setIcon(Res.iconVolume14);
131                    btnVolume.setIconTextGap(2);
132                    btnVolume.setHorizontalAlignment(btnVolume.LEFT);
133                    d = btnVolume.getPreferredSize();
134                    d.width = 55;
135                    btnVolume.setPreferredSize(d);
136                    btnVolume.setMaximumSize(d);
137                    p.add(btnVolume);
138                                    
139                    p.setMaximumSize(p.getPreferredSize());
140                    
141                    add(p);
142                  add(Box.createGlue());                  add(Box.createGlue());
143                                    
144                  d = new Dimension(420, 29);                  d = new Dimension(420, 29);
# Line 88  public class ChannelsBar extends PixmapP Line 146  public class ChannelsBar extends PixmapP
146                  setPreferredSize(d);                  setPreferredSize(d);
147                  setMaximumSize(d);                  setMaximumSize(d);
148                                    
                 // Setting the tooltip size  
                 tip.setTipText(i18n.getLabel("ChannelsBar.volume", 1000));  
                 tip.setMinimumSize(tip.getPreferredSize());  
                 tip.setPreferredSize(tip.getPreferredSize()); // workaround for preserving that size  
                 tip.setComponent(slVolume);  
                 ///////  
                   
149                  int i = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME);                  int i = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME);
150                  slVolume.setMaximum(i);                  slVolume.setMaximum(i);
151                  String s = MAXIMUM_MASTER_VOLUME;                  String s = MAXIMUM_MASTER_VOLUME;
# Line 118  public class ChannelsBar extends PixmapP Line 169  public class ChannelsBar extends PixmapP
169                                    
170                  updateVolume();                  updateVolume();
171                                    
172                  slVolume.addMouseListener(new MouseAdapter() {                  btnVolume.addActionListener(new ActionListener() {
173                          public void                          public void
174                          mousePressed(MouseEvent e) {                          actionPerformed(ActionEvent e) {
175                                  if(popup != null) {                                  if(popupVolume.isVisible()) {
176                                          popup.hide();                                          popupVolume.commit();
177                                          popup = null;                                          popupVolume.hide();
178                                    } else {
179                                            float vol = CC.getSamplerModel().getVolume();
180                                            popupVolume.setCurrentVolume(vol);
181                                            popupVolume.show();
182                                  }                                  }
                                   
                                 Point p = slVolume.getLocationOnScreen();  
                                 PopupFactory pf = PopupFactory.getSharedInstance();  
                                 popup = pf.getPopup(slVolume, tip, p.x, p.y - 22);  
                                 popup.show();  
183                          }                          }
184                                            });
185                    
186                    popupVolume.addActionListener(new ActionListener() {
187                          public void                          public void
188                          mouseReleased(MouseEvent e) {                          actionPerformed(ActionEvent e) {
189                                  if(popup != null) {                                  CC.getSamplerModel().setBackendVolume(popupVolume.getVolumeFactor());
190                                          popup.hide();                          }
191                                          popup = null;                  });
192                                  }                  
193                    s = VOL_MEASUREMENT_UNIT_DECIBEL;
194                    preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
195                            public void
196                            propertyChange(PropertyChangeEvent e) {
197                                    setVolume();
198                          }                          }
199                  });                  });
200          }          }
# Line 145  public class ChannelsBar extends PixmapP Line 202  public class ChannelsBar extends PixmapP
202          private void          private void
203          setVolume() {          setVolume() {
204                  int volume = slVolume.getValue();                  int volume = slVolume.getValue();
205                  String s = i18n.getLabel("ChannelsBar.volume", volume);                  
206                  slVolume.setToolTipText(s);                  if(CC.getViewConfig().isMeasurementUnitDecibel()) {
207                  tip.setTipText(s);                          double dB = HF.percentsToDecibels(volume);
208                  tip.repaint();                          btnVolume.setText(numberFormat.format(dB) + "dB");
209                    } else {
210                            btnVolume.setText(volume + "%");
211                    }
212                                    
213                  if(slVolume.getValueIsAdjusting()) return;                  if(slVolume.getValueIsAdjusting()) return;
214                                    

Legend:
Removed from v.1539  
changed lines
  Added in v.1540

  ViewVC Help
Powered by ViewVC