Source code: org/fluidsynth/gui/ConfigChooserUtil.java
1 /*
2 * Copyright (C) 2003 Ken Ellinwood.
3 *
4 * This file is part of FluidGUI.
5 *
6 * FluidGUI is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 package org.fluidsynth.gui;
22
23 import org.fluidsynth.api.*;
24
25 import java.io.*;
26 import java.awt.*;
27 import javax.swing.*;
28 import javax.swing.filechooser.FileFilter;
29
30 /** Utility class for creating configuration file choosers. */
31 public class ConfigChooserUtil
32 {
33
34 /** Create a config file chooser. Try to open the file chooser in
35 * the directory containing the given config path, revert to
36 * user's home dir if anything goes wrong.
37 */
38 public static JFileChooser createChooser( Component parent,
39 String configPathname,
40 String approveButtonText,
41 String title)
42 {
43 return createChooser( parent, configPathname, approveButtonText, title, ConfigManager.getConfigFileFilter());
44 }
45
46 public static JFileChooser createChooser( Component parent,
47 String configPathname,
48 String approveButtonText,
49 String title,
50 FileFilter filter)
51 {
52 // Try to open the file chooser in the user's favorite folder.
53 File configDir = null;
54 if (FluidGuiPrefs.getFavoriteFolder() != null)
55 configDir = new File( FluidGuiPrefs.getFavoriteFolder());
56
57 JFileChooser chooser;
58 if (configDir == null) chooser = new JFileChooser();
59 else chooser = new JFileChooser( configDir);
60
61 chooser.setApproveButtonText(approveButtonText);
62 chooser.setDialogTitle( title);
63 chooser.setFileFilter( filter);
64 return chooser;
65 }
66 }
67