1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2007 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 |
|
27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
|
30 |
import java.io.File; |
31 |
|
32 |
import javax.swing.BorderFactory; |
33 |
import javax.swing.Box; |
34 |
import javax.swing.BoxLayout; |
35 |
import javax.swing.JButton; |
36 |
import javax.swing.JFileChooser; |
37 |
import javax.swing.JLabel; |
38 |
import javax.swing.JPanel; |
39 |
import javax.swing.JSpinner; |
40 |
import javax.swing.JTextField; |
41 |
import javax.swing.SpinnerNumberModel; |
42 |
|
43 |
import org.jsampler.CC; |
44 |
import org.jsampler.JSPrefs; |
45 |
|
46 |
import static org.jsampler.view.std.StdI18n.i18n; |
47 |
import static org.jsampler.view.std.StdPrefs.*; |
48 |
|
49 |
|
50 |
/** |
51 |
* |
52 |
* @author Grigor Iliev |
53 |
*/ |
54 |
public class JSGeneralProps { |
55 |
|
56 |
/** Creates a new instance of <code>JSGeneralProps</code> */ |
57 |
private JSGeneralProps() { } |
58 |
|
59 |
private static JSPrefs |
60 |
preferences() { return CC.getViewConfig().preferences(); } |
61 |
|
62 |
|
63 |
public static class JSamplerHomePane extends JPanel { |
64 |
private final JTextField tfJSamplerHome = new JTextField(); |
65 |
private final JButton btnChange = |
66 |
new JButton(i18n.getButtonLabel("JSGeneralProps.btnChange")); |
67 |
|
68 |
public |
69 |
JSamplerHomePane() { |
70 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
71 |
|
72 |
JPanel p = new JPanel(); |
73 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
74 |
|
75 |
if(CC.getJSamplerHome() != null) { |
76 |
tfJSamplerHome.setText(CC.getJSamplerHome()); |
77 |
} |
78 |
|
79 |
Dimension d; |
80 |
d = new Dimension(Short.MAX_VALUE, tfJSamplerHome.getPreferredSize().height); |
81 |
tfJSamplerHome.setMaximumSize(d); |
82 |
p.add(tfJSamplerHome); |
83 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
84 |
p.add(btnChange); |
85 |
p.setBorder(BorderFactory.createEmptyBorder(2, 6, 6, 6)); |
86 |
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
87 |
add(p); |
88 |
|
89 |
String s = i18n.getLabel("JSGeneralProps.jSamplerHome"); |
90 |
setBorder(BorderFactory.createTitledBorder(s)); |
91 |
setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); |
92 |
setAlignmentX(JPanel.LEFT_ALIGNMENT); |
93 |
|
94 |
btnChange.addActionListener(new ActionListener() { |
95 |
public void |
96 |
actionPerformed(ActionEvent e) { onChange(); } |
97 |
}); |
98 |
} |
99 |
|
100 |
private void |
101 |
onChange() { |
102 |
JFileChooser fc = new JFileChooser(); |
103 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
104 |
int result = fc.showOpenDialog(this); |
105 |
if(result != JFileChooser.APPROVE_OPTION) return; |
106 |
|
107 |
String s = CC.getJSamplerHome(); |
108 |
String suf = File.separator + ".jsampler"; |
109 |
if(s != null) suf = File.separator + new File(s).getName(); |
110 |
|
111 |
tfJSamplerHome.setText(fc.getSelectedFile().getPath() + suf); |
112 |
} |
113 |
|
114 |
/** |
115 |
* Gets the selected JSampler's home directory. |
116 |
*/ |
117 |
public String |
118 |
getJSamplerHome() { return tfJSamplerHome.getText(); } |
119 |
} |
120 |
|
121 |
|
122 |
public static class RecentScriptsPane extends JPanel { |
123 |
private final JLabel lRecentScriptsSize = |
124 |
new JLabel(i18n.getLabel("JSGeneralProps.lRecentScriptsSize")); |
125 |
|
126 |
private final JSpinner spRecentScriptsSize; |
127 |
|
128 |
private final JButton btnClearRecentScriptList = |
129 |
new JButton(i18n.getButtonLabel("JSGeneralProps.btnClearRecentScriptList")); |
130 |
|
131 |
public |
132 |
RecentScriptsPane() { |
133 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
134 |
|
135 |
int i = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE); |
136 |
spRecentScriptsSize = new JSpinner(new SpinnerNumberModel(i, 0, 100, 1)); |
137 |
spRecentScriptsSize.setMaximumSize(spRecentScriptsSize.getPreferredSize()); |
138 |
|
139 |
JPanel p = new JPanel(); |
140 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
141 |
p.add(lRecentScriptsSize); |
142 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
143 |
p.add(spRecentScriptsSize); |
144 |
|
145 |
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
146 |
add(p); |
147 |
|
148 |
add(Box.createRigidArea(new Dimension(0, 6))); |
149 |
|
150 |
btnClearRecentScriptList.addActionListener(new ActionListener() { |
151 |
public void |
152 |
actionPerformed(ActionEvent e) { |
153 |
preferences().setStringProperty(RECENT_LSCP_SCRIPTS, null); |
154 |
clearRecentScripts(); |
155 |
} |
156 |
}); |
157 |
|
158 |
btnClearRecentScriptList.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
159 |
add(btnClearRecentScriptList); |
160 |
add(Box.createRigidArea(new Dimension(0, 6))); |
161 |
|
162 |
setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); |
163 |
setAlignmentX(JPanel.LEFT_ALIGNMENT); |
164 |
String s = i18n.getLabel("JSGeneralProps.recentScripts"); |
165 |
setBorder(BorderFactory.createTitledBorder(s)); |
166 |
} |
167 |
|
168 |
/** |
169 |
* Override this method to clear the recent scripts. |
170 |
*/ |
171 |
protected void |
172 |
clearRecentScripts() { } |
173 |
|
174 |
public int |
175 |
getRecentScriptsSize() { |
176 |
return Integer.parseInt(spRecentScriptsSize.getValue().toString()); |
177 |
} |
178 |
} |
179 |
} |