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

Contents of /jsampler/trunk/src/org/jsampler/view/std/JSamplerHomeChooser.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1871 - (show annotations) (download)
Sun Mar 22 18:11:39 2009 UTC (15 years, 1 month ago) by iliev
File size: 3147 byte(s)
* Mac OS integration, work in progress:
* Added option to use native file choosers
  (choose Edit/Preferences, then click the `View' tab)

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler.view.std;
24
25 import java.awt.Dimension;
26 import java.awt.Frame;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29
30 import java.io.File;
31
32 import javax.swing.Box;
33 import javax.swing.BoxLayout;
34 import javax.swing.JButton;
35 import javax.swing.JOptionPane;
36 import javax.swing.JPanel;
37 import javax.swing.JTextField;
38
39 import net.sf.juife.OkCancelDialog;
40
41 import org.jsampler.CC;
42
43 import static org.jsampler.view.std.StdI18n.i18n;
44
45 /**
46 *
47 * @author Grigor Iliev
48 */
49 public class JSamplerHomeChooser extends OkCancelDialog {
50 private final static JTextField tfHome = new JTextField();
51
52 private final JButton btnBrowse = new JButton(i18n.getButtonLabel("browse"));
53
54
55 /** Creates a new instance of JSamplerHomeChooser */
56 public JSamplerHomeChooser(Frame owner) {
57 super(owner, i18n.getLabel("JSamplerHomeChooser.title"));
58
59 JPanel p = new JPanel();
60 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
61 Dimension d = new Dimension(Short.MAX_VALUE, tfHome.getPreferredSize().height);
62 tfHome.setMaximumSize(d);
63 p.add(tfHome);
64 p.add(Box.createRigidArea(new Dimension(6, 0)));
65 p.add(btnBrowse);
66
67 p.setPreferredSize(new Dimension(350, p.getPreferredSize().height));
68
69 setMainPane(p);
70
71 if(CC.getJSamplerHome() != null) tfHome.setText(CC.getJSamplerHome());
72 else tfHome.setText(System.getProperty("user.home") + File.separator + ".jsampler");
73
74 btnBrowse.addActionListener(new ActionListener() {
75 public void
76 actionPerformed(ActionEvent e) { onBrowse(); }
77 });
78
79 btnBrowse.requestFocusInWindow();
80 this.setResizable(true);
81 }
82
83 private void
84 onBrowse() {
85 File f = StdUtils.showOpenDirectoryChooser(this, null);
86 if(f == null) return;
87
88 tfHome.setText(f.getPath() + File.separator + ".jsampler");
89 btnOk.requestFocusInWindow();
90
91 }
92
93 @Override
94 protected void
95 onOk() {
96 if(tfHome.getText().length() == 0) {
97 JOptionPane.showMessageDialog (
98 this, i18n.getLabel("JSamplerHomeChooser.selectFile"),
99 "",
100 JOptionPane.INFORMATION_MESSAGE
101 );
102
103 return;
104 }
105
106 setVisible(false);
107 }
108
109 @Override
110 protected void
111 onCancel() { setVisible(false); }
112
113 /**
114 * Gets the specified JSampler's home location.
115 * @return The specified JSampler's home location.
116 */
117 public String
118 getJSamplerHome() { return tfHome.getText(); }
119 }

  ViewVC Help
Powered by ViewVC