/[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 1870 by iliev, Sun Mar 15 14:33:48 2009 UTC revision 1871 by iliev, Sun Mar 22 18:11:39 2009 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 22  Line 22 
22  package org.jsampler.view.std;  package org.jsampler.view.std;
23    
24  import java.awt.Desktop;  import java.awt.Desktop;
25    import java.awt.Dialog;
26    import java.awt.FileDialog;
27    import java.awt.Frame;
28  import java.awt.Rectangle;  import java.awt.Rectangle;
29    import java.awt.Window;
30    
31  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
32  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
# Line 32  import java.awt.event.MouseEvent; Line 36  import java.awt.event.MouseEvent;
36  import java.beans.PropertyChangeEvent;  import java.beans.PropertyChangeEvent;
37  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
38    
39    import java.io.File;
40    import java.io.FilenameFilter;
41  import java.net.URI;  import java.net.URI;
42    
43  import java.text.NumberFormat;  import java.text.NumberFormat;
# Line 40  import java.util.Vector; Line 46  import java.util.Vector;
46  import java.util.logging.Level;  import java.util.logging.Level;
47    
48  import javax.swing.JComboBox;  import javax.swing.JComboBox;
49    import javax.swing.JFileChooser;
50  import javax.swing.JSlider;  import javax.swing.JSlider;
51  import javax.swing.JToolTip;  import javax.swing.JToolTip;
52  import javax.swing.Popup;  import javax.swing.Popup;
# Line 51  import org.jsampler.CC; Line 58  import org.jsampler.CC;
58  import org.jsampler.HF;  import org.jsampler.HF;
59  import org.jsampler.JSPrefs;  import org.jsampler.JSPrefs;
60    
61    import org.jsampler.view.JSFileFilter;
62    import org.jsampler.view.LscpFileFilter;
63  import static org.jsampler.view.std.StdI18n.i18n;  import static org.jsampler.view.std.StdI18n.i18n;
64  import static org.jsampler.view.std.StdPrefs.*;  import static org.jsampler.view.std.StdPrefs.*;
65    
# Line 67  public class StdUtils { Line 76  public class StdUtils {
76                    
77          private static JSPrefs          private static JSPrefs
78          preferences() { return CC.getViewConfig().preferences(); }          preferences() { return CC.getViewConfig().preferences(); }
79            
80          public static JComboBox          public static JComboBox
81          createPathComboBox() {          createEnhancedComboBox() {
82                  final JComboBox cb = new JComboBox();                  final JComboBox cb = new JComboBox();
                 cb.setEditable(true);  
83                  cb.addActionListener(new ActionListener() {                  cb.addActionListener(new ActionListener() {
84                          public void                          public void
85                          actionPerformed(ActionEvent e) {                          actionPerformed(ActionEvent e) {
# Line 84  public class StdUtils { Line 92  public class StdUtils {
92                                  else cb.setToolTipText(s);                                  else cb.setToolTipText(s);
93                          }                          }
94                  });                  });
95                    
96                    return cb;
97            }
98            
99            public static JComboBox
100            createPathComboBox() {
101                    JComboBox cb = createEnhancedComboBox();
102                    cb.setEditable(true);
103                  return cb;                  return cb;
104          }          }
105                    
# Line 185  public class StdUtils { Line 200  public class StdUtils {
200                  String s = windowName + ".windowSizeAndLocation";                  String s = windowName + ".windowSizeAndLocation";
201                  CC.preferences().setStringProperty(s, sb.toString());                  CC.preferences().setStringProperty(s, sb.toString());
202          }          }
203    
204            public static File
205            showOpenLscpFileChooser() {
206                    return showLscpFileChooser(true);
207            }
208    
209            public static File
210            showOpenLscpFileChooser(Window owner) {
211                    return showLscpFileChooser(true, owner);
212            }
213    
214            public static File
215            showSaveLscpFileChooser() {
216                    return showLscpFileChooser(false);
217            }
218    
219            public static File
220            showSaveLscpFileChooser(Window owner) {
221                    return showLscpFileChooser(false, owner);
222            }
223    
224            private static File
225            showLscpFileChooser(boolean openDialog) {
226                    return showLscpFileChooser(openDialog, CC.getMainFrame());
227            }
228    
229            private static File
230            showLscpFileChooser(boolean openDialog, Window owner) {
231                    return showFileChooser (
232                            openDialog, owner, false, new LscpFileFilter(), "lastScriptLocation"
233                    );
234            }
235    
236            public static File
237            showOpenInstrumentFileChooser(Window owner) {
238                    return showFileChooser(true, owner, false, null, "lastInstrumentLocation");
239            }
240    
241            public static File
242            showOpenDirectoryChooser(Window owner, String locationProperty) {
243                    return showFileChooser(true, owner, true, null, locationProperty);
244            }
245    
246            private static File
247            showFileChooser (
248                    boolean       openDialog,
249                    Window        owner,
250                    boolean       dirChooser,
251                    JSFileFilter  filter,
252                    String        locationProperty
253            ) {
254                    boolean nativeFileChooser = preferences().getBoolProperty("nativeFileChoosers");
255                    String oldPath = null;
256                    if(locationProperty != null) {
257                            oldPath = preferences().getStringProperty(locationProperty);
258                    }
259                    File f = null;
260                    if(nativeFileChooser && CC.isMacOS()) {
261                            if(dirChooser) {
262                                    System.setProperty("apple.awt.fileDialogForDirectories", "true");
263                            }
264                            FileDialog dlg;
265                            if(owner instanceof Frame) dlg = new FileDialog((Frame)owner);
266                            else if(owner instanceof Dialog) dlg = new FileDialog((Dialog)owner);
267                            else dlg = new FileDialog(CC.getMainFrame());
268                            dlg.setDirectory(oldPath);
269                            dlg.setMode(openDialog ? FileDialog.LOAD : FileDialog.SAVE);
270                            if(filter != null) dlg.setFilenameFilter(filter);
271                            dlg.setVisible(true);
272                            if(dirChooser) {
273                                    System.setProperty("apple.awt.fileDialogForDirectories", "false");
274                            }
275                            if(dlg.getFile() != null) {
276                                    f = new File(new File(dlg.getDirectory()), dlg.getFile());
277                            }
278                    } else {
279                            JFileChooser fc = new JFileChooser(oldPath);
280                            if(filter != null) fc.setFileFilter(filter);
281                            if(dirChooser) fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
282                            int result;
283                            if(openDialog) result = fc.showOpenDialog(owner);
284                            else result = fc.showSaveDialog(owner);
285                            if(result == JFileChooser.APPROVE_OPTION) f = fc.getSelectedFile();
286                    }
287    
288                    if(f == null) return null;
289                    String path = f.getParent();
290                    if(path != null && locationProperty != null) {
291                            preferences().setStringProperty(locationProperty, path);
292                    }
293                    return f;
294            }
295                    
296          public static JSlider          public static JSlider
297          createVolumeSlider() {          createVolumeSlider() {

Legend:
Removed from v.1870  
changed lines
  Added in v.1871

  ViewVC Help
Powered by ViewVC