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.classic; |
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.classic.ClassicI18n.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 = |
54 |
new JButton(i18n.getLabel("JSamplerHomeChooser.btnBrowse")); |
55 |
|
56 |
|
57 |
/** Creates a new instance of JSamplerHomeChooser */ |
58 |
public JSamplerHomeChooser(Frame owner) { |
59 |
super(owner, i18n.getLabel("JSamplerHomeChooser.title")); |
60 |
|
61 |
JPanel p = new JPanel(); |
62 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
63 |
Dimension d = new Dimension(Short.MAX_VALUE, tfHome.getPreferredSize().height); |
64 |
tfHome.setMaximumSize(d); |
65 |
p.add(tfHome); |
66 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
67 |
p.add(btnBrowse); |
68 |
|
69 |
p.setPreferredSize(new Dimension(350, p.getPreferredSize().height)); |
70 |
|
71 |
setMainPane(p); |
72 |
|
73 |
if(CC.getJSamplerHome() != null) tfHome.setText(CC.getJSamplerHome()); |
74 |
else tfHome.setText(System.getProperty("user.home") + File.separator + ".jsampler"); |
75 |
|
76 |
btnBrowse.addActionListener(new ActionListener() { |
77 |
public void |
78 |
actionPerformed(ActionEvent e) { onBrowse(); } |
79 |
}); |
80 |
|
81 |
btnBrowse.requestFocusInWindow(); |
82 |
this.setResizable(true); |
83 |
} |
84 |
|
85 |
private void |
86 |
onBrowse() { |
87 |
JFileChooser fc = new JFileChooser(); |
88 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
89 |
int result = fc.showOpenDialog(this); |
90 |
if(result != JFileChooser.APPROVE_OPTION) return; |
91 |
|
92 |
tfHome.setText(fc.getSelectedFile().getPath() + File.separator + ".jsampler"); |
93 |
btnOk.requestFocusInWindow(); |
94 |
|
95 |
} |
96 |
|
97 |
protected void |
98 |
onOk() { |
99 |
if(tfHome.getText().length() == 0) { |
100 |
JOptionPane.showMessageDialog ( |
101 |
this, i18n.getLabel("JSamplerHomeChooser.selectFile"), |
102 |
"", |
103 |
JOptionPane.INFORMATION_MESSAGE |
104 |
); |
105 |
|
106 |
return; |
107 |
} |
108 |
|
109 |
setVisible(false); |
110 |
} |
111 |
|
112 |
protected void |
113 |
onCancel() { setVisible(false); } |
114 |
|
115 |
/** |
116 |
* Gets the specified JSampler's home location. |
117 |
* @return The specified JSampler's home location. |
118 |
*/ |
119 |
public String |
120 |
getJSamplerHome() { return tfHome.getText(); } |
121 |
} |