/[svn]/jsampler/trunk/src/org/jsampler/view/std/StdUtils.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/view/std/StdUtils.java

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

revision 1539 by iliev, Mon Nov 19 22:22:22 2007 UTC revision 1540 by iliev, Mon Dec 3 23:22:02 2007 UTC
# Line 23  package org.jsampler.view.std; Line 23  package org.jsampler.view.std;
23    
24  import java.awt.Desktop;  import java.awt.Desktop;
25    
26    import java.awt.event.ActionEvent;
27    import java.awt.event.ActionListener;
28    import java.awt.event.MouseAdapter;
29    import java.awt.event.MouseEvent;
30    
31    import java.beans.PropertyChangeEvent;
32    import java.beans.PropertyChangeListener;
33    
34  import java.net.URI;  import java.net.URI;
35    
36    import java.text.NumberFormat;
37    
38  import java.util.Vector;  import java.util.Vector;
39    
40    import javax.swing.JComboBox;
41    import javax.swing.JSlider;
42    import javax.swing.JToolTip;
43    import javax.swing.Popup;
44    import javax.swing.PopupFactory;
45    
46    import javax.swing.event.ChangeEvent;
47    import javax.swing.event.ChangeListener;
48  import org.jsampler.CC;  import org.jsampler.CC;
49  import org.jsampler.HF;  import org.jsampler.HF;
50  import org.jsampler.JSPrefs;  import org.jsampler.JSPrefs;
51    
52  import static org.jsampler.view.std.StdI18n.i18n;  import static org.jsampler.view.std.StdI18n.i18n;
53    import static org.jsampler.view.std.StdPrefs.*;
54    
55    
56  /**  /**
# Line 47  public class StdUtils { Line 66  public class StdUtils {
66          private static JSPrefs          private static JSPrefs
67          preferences() { return CC.getViewConfig().preferences(); }          preferences() { return CC.getViewConfig().preferences(); }
68                    
69            public static JComboBox
70            createPathComboBox() {
71                    final JComboBox cb = new JComboBox();
72                    cb.setEditable(true);
73                    cb.addActionListener(new ActionListener() {
74                            public void
75                            actionPerformed(ActionEvent e) {
76                                    if(cb.getSelectedItem() == null) {
77                                            cb.setToolTipText(null);
78                                            return;
79                                    }
80                                    String s = cb.getSelectedItem().toString();
81                                    if(s.length() < 15) cb.setToolTipText(null);
82                                    else cb.setToolTipText(s);
83                            }
84                    });
85                    
86                    return cb;
87            }
88            
89          /**          /**
90           * Updates the specified string list property by adding the specified           * Updates the specified string list property by adding the specified
91           * element on the top. Also restricts the maximum number of elements to 12.           * element on the top. Also restricts the maximum number of elements to 12.
# Line 92  public class StdUtils { Line 131  public class StdUtils {
131                  try { Desktop.getDesktop().mail(new URI(uri)); }                  try { Desktop.getDesktop().mail(new URI(uri)); }
132                  catch(Exception x) { x.printStackTrace(); }                  catch(Exception x) { x.printStackTrace(); }
133          }          }
134            
135            public static JSlider
136            createVolumeSlider() {
137                    return new VolumeSlider();
138            }
139            
140            private static class VolumeSlider extends JSlider {
141                    private Popup popup = null;
142                    private final JToolTip tip = new JToolTip();
143                    private static NumberFormat numberFormat = NumberFormat.getInstance();
144                    
145                    VolumeSlider() {
146                            super(0, 100, 100);
147                            numberFormat.setMaximumFractionDigits(1);
148                            // Setting the tooltip size
149                            tip.setTipText(i18n.getLabel("StdUtils.volume", 10000));
150                            tip.setMinimumSize(tip.getPreferredSize());
151                            tip.setPreferredSize(tip.getPreferredSize()); // workaround for preserving that size
152                            tip.setComponent(this);
153                            tip.setTipText(i18n.getLabel("StdUtils.volume", 0));
154                            ///////
155                            
156                            updateVolumeInfo();
157                            
158                            addMouseListener(new MouseAdapter() {
159                                    public void
160                                    mousePressed(MouseEvent e) {
161                                            if(popup != null) {
162                                                    popup.hide();
163                                                    popup = null;
164                                            }
165                                            
166                                            if(!VolumeSlider.this.isEnabled()) return;
167                                            
168                                            java.awt.Point p = VolumeSlider.this.getLocationOnScreen();
169                                            PopupFactory pf = PopupFactory.getSharedInstance();
170                                            popup = pf.getPopup(VolumeSlider.this, tip, p.x, p.y - 22);
171                                            popup.show();
172                                    }
173                                    
174                                    public void
175                                    mouseReleased(MouseEvent e) {
176                                            if(popup != null) {
177                                                    popup.hide();
178                                                    popup = null;
179                                            }
180                                    }
181                            });
182                            
183                            addChangeListener(new ChangeListener() {
184                                    public void
185                                    stateChanged(ChangeEvent e) { updateVolumeInfo(); }
186                            });
187                            
188                            String s = VOL_MEASUREMENT_UNIT_DECIBEL;
189                            preferences().addPropertyChangeListener(s, new PropertyChangeListener() {
190                                    public void
191                                    propertyChange(PropertyChangeEvent e) {
192                                            updateVolumeInfo();
193                                    }
194                            });
195                    }
196                    
197                    private void
198                    updateVolumeInfo() {
199                            String s;
200                            if(CC.getViewConfig().isMeasurementUnitDecibel()) {
201                                    double d = HF.percentsToDecibels(getValue());
202                                    s = i18n.getLabel("StdUtils.volumeDecibels", numberFormat.format(d));
203                            } else {
204                                    s = i18n.getLabel("StdUtils.volume", getValue());
205                            }
206                            
207                            setToolTipText(s);
208                            tip.setTipText(s);
209                            tip.repaint();
210                    }
211            }
212  }  }

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

  ViewVC Help
Powered by ViewVC