1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2006 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.JFileChooser; |
36 |
import javax.swing.JOptionPane; |
37 |
import javax.swing.JPanel; |
38 |
import javax.swing.JTextField; |
39 |
|
40 |
import net.sf.juife.OkCancelDialog; |
41 |
|
42 |
import org.jsampler.CC; |
43 |
|
44 |
import static org.jsampler.view.std.StdI18n.i18n; |
45 |
|
46 |
/** |
47 |
* |
48 |
* @author Grigor Iliev |
49 |
*/ |
50 |
public class JSamplerHomeChooser extends OkCancelDialog { |
51 |
private final static JTextField tfHome = new JTextField(); |
52 |
|
53 |
private final JButton btnBrowse = new JButton(i18n.getButtonLabel("browse")); |
54 |
|
55 |
|
56 |
/** Creates a new instance of JSamplerHomeChooser */ |
57 |
public JSamplerHomeChooser(Frame owner) { |
58 |
super(owner, i18n.getLabel("JSamplerHomeChooser.title")); |
59 |
|
60 |
JPanel p = new JPanel(); |
61 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
62 |
Dimension d = new Dimension(Short.MAX_VALUE, tfHome.getPreferredSize().height); |
63 |
tfHome.setMaximumSize(d); |
64 |
p.add(tfHome); |
65 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
66 |
p.add(btnBrowse); |
67 |
|
68 |
p.setPreferredSize(new Dimension(350, p.getPreferredSize().height)); |
69 |
|
70 |
setMainPane(p); |
71 |
|
72 |
if(CC.getJSamplerHome() != null) tfHome.setText(CC.getJSamplerHome()); |
73 |
else tfHome.setText(System.getProperty("user.home") + File.separator + ".jsampler"); |
74 |
|
75 |
btnBrowse.addActionListener(new ActionListener() { |
76 |
public void |
77 |
actionPerformed(ActionEvent e) { onBrowse(); } |
78 |
}); |
79 |
|
80 |
btnBrowse.requestFocusInWindow(); |
81 |
this.setResizable(true); |
82 |
} |
83 |
|
84 |
private void |
85 |
onBrowse() { |
86 |
JFileChooser fc = new JFileChooser(); |
87 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
88 |
int result = fc.showOpenDialog(this); |
89 |
if(result != JFileChooser.APPROVE_OPTION) return; |
90 |
|
91 |
tfHome.setText(fc.getSelectedFile().getPath() + File.separator + ".jsampler"); |
92 |
btnOk.requestFocusInWindow(); |
93 |
|
94 |
} |
95 |
|
96 |
protected void |
97 |
onOk() { |
98 |
if(tfHome.getText().length() == 0) { |
99 |
JOptionPane.showMessageDialog ( |
100 |
this, i18n.getLabel("JSamplerHomeChooser.selectFile"), |
101 |
"", |
102 |
JOptionPane.INFORMATION_MESSAGE |
103 |
); |
104 |
|
105 |
return; |
106 |
} |
107 |
|
108 |
setVisible(false); |
109 |
} |
110 |
|
111 |
protected void |
112 |
onCancel() { setVisible(false); } |
113 |
|
114 |
/** |
115 |
* Gets the specified JSampler's home location. |
116 |
* @return The specified JSampler's home location. |
117 |
*/ |
118 |
public String |
119 |
getJSamplerHome() { return tfHome.getText(); } |
120 |
} |