1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005 Grigor Kirilov Iliev |
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.BorderLayout; |
26 |
import java.awt.Color; |
27 |
import java.awt.Container; |
28 |
import java.awt.Cursor; |
29 |
import java.awt.Dialog; |
30 |
import java.awt.Dimension; |
31 |
import java.awt.GraphicsEnvironment; |
32 |
import java.awt.Font; |
33 |
import java.awt.Frame; |
34 |
import java.awt.GridBagConstraints; |
35 |
import java.awt.GridBagLayout; |
36 |
import java.awt.Insets; |
37 |
|
38 |
import java.awt.event.ActionEvent; |
39 |
import java.awt.event.ActionListener; |
40 |
import java.awt.event.ItemEvent; |
41 |
import java.awt.event.ItemListener; |
42 |
import java.awt.event.MouseAdapter; |
43 |
import java.awt.event.MouseEvent; |
44 |
|
45 |
import java.util.Locale; |
46 |
import java.util.Vector; |
47 |
|
48 |
import javax.swing.BorderFactory; |
49 |
import javax.swing.Box; |
50 |
import javax.swing.BoxLayout; |
51 |
import javax.swing.DefaultButtonModel; |
52 |
import javax.swing.JButton; |
53 |
import javax.swing.JCheckBox; |
54 |
import javax.swing.JColorChooser; |
55 |
import javax.swing.JComboBox; |
56 |
import javax.swing.JLabel; |
57 |
import javax.swing.JOptionPane; |
58 |
import javax.swing.JPanel; |
59 |
import javax.swing.JPasswordField; |
60 |
import javax.swing.JSpinner; |
61 |
import javax.swing.JTabbedPane; |
62 |
import javax.swing.JTextField; |
63 |
import javax.swing.SpinnerNumberModel; |
64 |
|
65 |
import javax.swing.event.ChangeEvent; |
66 |
import javax.swing.event.ChangeListener; |
67 |
|
68 |
import net.sf.juife.EnhancedDialog; |
69 |
import net.sf.juife.JuifeUtils; |
70 |
import net.sf.juife.LinkButton; |
71 |
import net.sf.juife.OkCancelDialog; |
72 |
|
73 |
import org.jsampler.CC; |
74 |
import org.jsampler.HF; |
75 |
import org.jsampler.JSI18n; |
76 |
import org.jsampler.JSampler; |
77 |
import org.jsampler.LSConsoleModel; |
78 |
import org.jsampler.Prefs; |
79 |
|
80 |
import org.jsampler.task.SetServerAddress; |
81 |
|
82 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
83 |
|
84 |
|
85 |
/** |
86 |
* |
87 |
* @author Grigor Iliev |
88 |
*/ |
89 |
public class PrefsDlg extends EnhancedDialog { |
90 |
private final GeneralPane genPane = new GeneralPane(); |
91 |
private final ViewPane viewPane = new ViewPane(); |
92 |
private final ConsolePane consolePane = new ConsolePane(); |
93 |
private final ConnectionPane conPane = new ConnectionPane(); |
94 |
|
95 |
private final JButton btnApply = new JButton(i18n.getButtonLabel("apply")); |
96 |
private final JButton btnClose = new JButton(i18n.getButtonLabel("close")); |
97 |
|
98 |
|
99 |
public |
100 |
PrefsDlg(Frame frm) { |
101 |
super(frm, i18n.getLabel("PrefsDlg"), true); |
102 |
|
103 |
initPrefsDlg(); |
104 |
handleEvents(); |
105 |
initPrefs(); |
106 |
|
107 |
setLocation(JuifeUtils.centerLocation(this, frm)); |
108 |
} |
109 |
|
110 |
private void |
111 |
initPrefsDlg() { |
112 |
JTabbedPane tp = new JTabbedPane(); |
113 |
tp.addTab(i18n.getLabel("PrefsDlg.tabGeneral"), genPane); |
114 |
tp.addTab(i18n.getLabel("PrefsDlg.tabView"), viewPane); |
115 |
tp.addTab(i18n.getLabel("PrefsDlg.tabConsole"), consolePane); |
116 |
tp.addTab(i18n.getLabel("PrefsDlg.tabConnection"), conPane); |
117 |
tp.setAlignmentX(RIGHT_ALIGNMENT); |
118 |
|
119 |
// Set preferred size for Apply & Exit buttons |
120 |
Dimension d = JuifeUtils.getUnionSize(btnApply, btnClose); |
121 |
btnApply.setPreferredSize(d); |
122 |
btnClose.setPreferredSize(d); |
123 |
|
124 |
JPanel btnPane = new JPanel(); |
125 |
btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.X_AXIS)); |
126 |
btnPane.add(btnApply); |
127 |
btnPane.add(Box.createRigidArea(new Dimension(5, 0))); |
128 |
btnPane.add(btnClose); |
129 |
btnPane.setAlignmentX(RIGHT_ALIGNMENT); |
130 |
|
131 |
JPanel mainPane = new JPanel(); |
132 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
133 |
mainPane.add(tp); |
134 |
mainPane.add(Box.createRigidArea(new Dimension(0, 12))); |
135 |
mainPane.add(btnPane); |
136 |
mainPane.setBorder(BorderFactory.createEmptyBorder(11, 12, 12, 12)); |
137 |
|
138 |
getContentPane().add(mainPane); |
139 |
|
140 |
pack(); |
141 |
setResizable(false); |
142 |
} |
143 |
|
144 |
private void |
145 |
handleEvents() { |
146 |
btnApply.addActionListener(new ActionListener() { |
147 |
public void |
148 |
actionPerformed(ActionEvent e) { onApply(); } |
149 |
}); |
150 |
|
151 |
btnClose.addActionListener(new ActionListener() { |
152 |
public void |
153 |
actionPerformed(ActionEvent e) { onExit(); } |
154 |
}); |
155 |
} |
156 |
|
157 |
protected void |
158 |
onOk() { onApply(); } |
159 |
|
160 |
protected void |
161 |
onCancel() { onExit(); } |
162 |
|
163 |
private void |
164 |
initPrefs() { |
165 |
setLSAddress(Prefs.getLSAddress()); |
166 |
setLSPort(Prefs.getLSPort()); |
167 |
} |
168 |
|
169 |
private void |
170 |
onApply() { |
171 |
genPane.apply(); |
172 |
viewPane.apply(); |
173 |
consolePane.apply(); |
174 |
|
175 |
// CONNECTION |
176 |
Prefs.setLSAddress(getLSAddress()); |
177 |
|
178 |
boolean b = true; |
179 |
String s = getLSPort(); |
180 |
try { |
181 |
if(s.length() > 0) { |
182 |
int port = Integer.parseInt(s); |
183 |
if(port > 0 && port < 0xffff) |
184 |
Prefs.setLSPort(port); |
185 |
else b = false; |
186 |
} else Prefs.setLSPort(-1); // -1 resets to default value |
187 |
} catch(NumberFormatException x) { |
188 |
b = false; |
189 |
} |
190 |
|
191 |
if(!b) { |
192 |
JOptionPane.showMessageDialog ( |
193 |
this, |
194 |
i18n.getError("PrefsDlg.invalidPort", s), |
195 |
i18n.getError("error"), |
196 |
JOptionPane.ERROR_MESSAGE |
197 |
); |
198 |
|
199 |
return; |
200 |
} |
201 |
|
202 |
CC.getTaskQueue().add ( |
203 |
new SetServerAddress(Prefs.getLSAddress(), Prefs.getLSPort()) |
204 |
); |
205 |
|
206 |
setVisible(false); |
207 |
} |
208 |
|
209 |
private void |
210 |
onExit() { setVisible(false); } |
211 |
|
212 |
private String |
213 |
getLSAddress() { return conPane.getLSAddress().trim(); } |
214 |
|
215 |
private void |
216 |
setLSAddress(String s) { conPane.setLSAddress(s); } |
217 |
|
218 |
private String |
219 |
getLSPort() { return conPane.getLSPort().trim(); } |
220 |
|
221 |
private void |
222 |
setLSPort(int port) { conPane.setLSPort(String.valueOf(port)); } |
223 |
|
224 |
protected static class ColorButton extends JPanel { |
225 |
private Color color; |
226 |
private final Vector<ActionListener> listeners = new Vector<ActionListener>(); |
227 |
|
228 |
ColorButton() { this(Color.WHITE); } |
229 |
|
230 |
ColorButton(Color c) { |
231 |
color = c; |
232 |
|
233 |
//setBorderPainted(false); |
234 |
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
235 |
setPreferredSize(new Dimension(42, 16)); |
236 |
setMaximumSize(new Dimension(42, 16)); |
237 |
setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
238 |
|
239 |
addMouseListener(new MouseAdapter() { |
240 |
public void |
241 |
mouseClicked(MouseEvent e) { |
242 |
if(!isEnabled()) return; |
243 |
if(e.getButton() == e.BUTTON1) showColorChooser(); |
244 |
} |
245 |
}); |
246 |
} |
247 |
|
248 |
/** |
249 |
* Registers the specified listener to be |
250 |
* notified when the current color is changed. |
251 |
* @param l The <code>ActionListener</code> to register. |
252 |
*/ |
253 |
public void |
254 |
addActionListener(ActionListener l) { listeners.add(l); } |
255 |
|
256 |
/** |
257 |
* Removes the specified listener. |
258 |
* @param l The <code>ActionListener</code> to remove. |
259 |
*/ |
260 |
public void |
261 |
removeActionListener(ActionListener l) { listeners.remove(l); } |
262 |
|
263 |
/** Notifies listeners that the current color is changed. */ |
264 |
private void |
265 |
fireActionPerformed() { |
266 |
ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null); |
267 |
for(ActionListener l : listeners) l.actionPerformed(e); |
268 |
} |
269 |
|
270 |
public void |
271 |
setEnabled(boolean b) { |
272 |
setOpaque(b); |
273 |
if(b) setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
274 |
else setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY)); |
275 |
//setBorderPainted(!b); |
276 |
super.setEnabled(b); |
277 |
} |
278 |
|
279 |
private void |
280 |
showColorChooser() { |
281 |
ColorDlg dlg = new ColorDlg ( |
282 |
(Dialog)JuifeUtils.getWindow(this), getColor() |
283 |
); |
284 |
|
285 |
dlg.setVisible(true); |
286 |
if(!dlg.isCancelled()) { |
287 |
setColor(dlg.getColor()); |
288 |
fireActionPerformed(); |
289 |
} |
290 |
} |
291 |
|
292 |
public Color |
293 |
getColor() { return color; } |
294 |
|
295 |
public void |
296 |
setColor(Color c) { |
297 |
color = c; |
298 |
setBackground(color); |
299 |
} |
300 |
} |
301 |
|
302 |
protected static class ColorDlg extends OkCancelDialog { |
303 |
private final JColorChooser colorChooser = new JColorChooser(); |
304 |
|
305 |
ColorDlg(Dialog owner) { this(owner, Color.WHITE); } |
306 |
|
307 |
ColorDlg(Dialog owner, Color c) { |
308 |
super(owner); |
309 |
|
310 |
colorChooser.setPreviewPanel(new JPanel()); |
311 |
colorChooser.setColor(c); |
312 |
|
313 |
JPanel mainPane = new JPanel(); |
314 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
315 |
mainPane.add(colorChooser); |
316 |
|
317 |
mainPane.add(Box.createRigidArea(new Dimension(0, 6))); |
318 |
|
319 |
final JPanel p = new JPanel(); |
320 |
p.setBackground(c); |
321 |
p.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
322 |
mainPane.add(p); |
323 |
|
324 |
p.setPreferredSize(new Dimension(48, 8)); |
325 |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, 8)); |
326 |
|
327 |
setMainPane(mainPane); |
328 |
|
329 |
colorChooser.getSelectionModel().addChangeListener(new ChangeListener() { |
330 |
public void |
331 |
stateChanged(ChangeEvent e) { p.setBackground(getColor()); } |
332 |
}); |
333 |
} |
334 |
|
335 |
protected void |
336 |
onOk() { setVisible(false); } |
337 |
|
338 |
protected void |
339 |
onCancel() { setVisible(false); } |
340 |
|
341 |
public Color |
342 |
getColor() { return colorChooser.getColor(); } |
343 |
} |
344 |
} |
345 |
|
346 |
class GeneralPane extends JPanel { |
347 |
private final JCheckBox checkWindowSizeAndLocation = |
348 |
new JCheckBox(i18n.getLabel("GeneralPane.checkWindowSizeAndLocation")); |
349 |
|
350 |
private final JCheckBox checkLeftPaneState = |
351 |
new JCheckBox(i18n.getLabel("GeneralPane.checkLeftPaneState")); |
352 |
|
353 |
private final JCheckBox checkShowLSConsoleWhenRunScript = |
354 |
new JCheckBox(i18n.getLabel("GeneralPane.checkShowLSConsoleWhenRunScript")); |
355 |
|
356 |
private final JLabel lRecentScriptsSize = |
357 |
new JLabel(i18n.getLabel("GeneralPane.lRecentScriptsSize")); |
358 |
private final JSpinner spRecentScriptsSize; |
359 |
private final JButton btnClearRecentScriptList = |
360 |
new JButton(i18n.getButtonLabel("GeneralPane.btnClearRecentScriptList")); |
361 |
|
362 |
|
363 |
public |
364 |
GeneralPane() { |
365 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
366 |
|
367 |
checkWindowSizeAndLocation.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
368 |
|
369 |
checkWindowSizeAndLocation.setSelected(ClassicPrefs.getSaveWindowProperties()); |
370 |
checkWindowSizeAndLocation.addItemListener(new ItemListener() { |
371 |
public void |
372 |
itemStateChanged(ItemEvent e) { |
373 |
boolean b = e.getStateChange() == e.SELECTED; |
374 |
//checkWindowSizeAndLocation.setEnabled(b); |
375 |
} |
376 |
}); |
377 |
|
378 |
add(checkWindowSizeAndLocation); |
379 |
|
380 |
checkLeftPaneState.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
381 |
checkLeftPaneState.setSelected(ClassicPrefs.getSaveLeftPaneState()); |
382 |
add(checkLeftPaneState); |
383 |
|
384 |
checkShowLSConsoleWhenRunScript.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
385 |
|
386 |
boolean b = ClassicPrefs.getShowLSConsoleWhenRunScript(); |
387 |
checkShowLSConsoleWhenRunScript.setSelected(b); |
388 |
|
389 |
add(checkShowLSConsoleWhenRunScript); |
390 |
|
391 |
add(Box.createRigidArea(new Dimension(0, 6))); |
392 |
|
393 |
JPanel rsp = new JPanel(); |
394 |
rsp.setLayout(new BoxLayout(rsp, BoxLayout.Y_AXIS)); |
395 |
|
396 |
int i = ClassicPrefs.getRecentScriptsSize(); |
397 |
spRecentScriptsSize = new JSpinner(new SpinnerNumberModel(i, 0, 100, 1)); |
398 |
spRecentScriptsSize.setMaximumSize(spRecentScriptsSize.getPreferredSize()); |
399 |
|
400 |
JPanel p = new JPanel(); |
401 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
402 |
p.add(lRecentScriptsSize); |
403 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
404 |
p.add(spRecentScriptsSize); |
405 |
|
406 |
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
407 |
rsp.add(p); |
408 |
|
409 |
rsp.add(Box.createRigidArea(new Dimension(0, 6))); |
410 |
|
411 |
btnClearRecentScriptList.addActionListener(new ActionListener() { |
412 |
public void |
413 |
actionPerformed(ActionEvent e) { |
414 |
ClassicPrefs.setRecentScripts(null); |
415 |
((MainFrame)CC.getMainFrame()).clearRecentScripts(); |
416 |
} |
417 |
}); |
418 |
|
419 |
btnClearRecentScriptList.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
420 |
rsp.add(btnClearRecentScriptList); |
421 |
rsp.add(Box.createRigidArea(new Dimension(0, 6))); |
422 |
|
423 |
rsp.setMaximumSize(new Dimension(Short.MAX_VALUE, rsp.getPreferredSize().height)); |
424 |
rsp.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
425 |
rsp.setBorder ( |
426 |
BorderFactory.createTitledBorder(i18n.getLabel("GeneralPane.recentScripts")) |
427 |
); |
428 |
|
429 |
add(rsp); |
430 |
add(Box.createGlue()); |
431 |
|
432 |
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
433 |
} |
434 |
|
435 |
protected void |
436 |
apply() { |
437 |
ClassicPrefs.setSaveWindowProperties(checkWindowSizeAndLocation.isSelected()); |
438 |
ClassicPrefs.setSaveLeftPaneState(checkLeftPaneState.isSelected()); |
439 |
|
440 |
boolean b = checkShowLSConsoleWhenRunScript.isSelected(); |
441 |
ClassicPrefs.setShowLSConsoleWhenRunScript(b); |
442 |
|
443 |
int size = Integer.parseInt(spRecentScriptsSize.getValue().toString()); |
444 |
ClassicPrefs.setRecentScriptstSize(size); |
445 |
((MainFrame)CC.getMainFrame()).updateRecentScriptsMenu(); |
446 |
} |
447 |
} |
448 |
|
449 |
class ViewPane extends JPanel { |
450 |
private final JLabel lIfaceLanguage = |
451 |
new JLabel(i18n.getLabel("ViewPane.lIfaceLanguage")); |
452 |
private final JComboBox cbIfaceLanguage = new JComboBox(); |
453 |
|
454 |
private final JLabel lIfaceFont = |
455 |
new JLabel(i18n.getLabel("ViewPane.lIfaceFont")); |
456 |
private final JComboBox cbIfaceFont = new JComboBox(); |
457 |
|
458 |
private final JCheckBox checkBorderColor = |
459 |
new JCheckBox(i18n.getLabel("ViewPane.channelBorderColor")); |
460 |
private final PrefsDlg.ColorButton btnBorderColor = |
461 |
new PrefsDlg.ColorButton(Color.WHITE); |
462 |
|
463 |
public |
464 |
ViewPane() { initViewPane(); } |
465 |
|
466 |
private void |
467 |
initViewPane() { |
468 |
cbIfaceLanguage.setMaximumSize ( |
469 |
new Dimension(Short.MAX_VALUE, cbIfaceLanguage.getPreferredSize().height) |
470 |
); |
471 |
|
472 |
for(Locale l : JSI18n.getAvailableLocales()) { |
473 |
LocaleBox box = new LocaleBox(l); |
474 |
cbIfaceLanguage.addItem(box); |
475 |
if ( l.getLanguage().equals(Prefs.getInterfaceLanguage()) && |
476 |
l.getCountry().equals(Prefs.getInterfaceCountry()) |
477 |
) cbIfaceLanguage.setSelectedItem(box); |
478 |
} |
479 |
|
480 |
cbIfaceFont.setMaximumSize ( |
481 |
new Dimension(Short.MAX_VALUE, cbIfaceFont.getPreferredSize().height) |
482 |
); |
483 |
|
484 |
cbIfaceFont.addItem("[Default]"); |
485 |
|
486 |
String[] fontS = |
487 |
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); |
488 |
|
489 |
for(String f : fontS) cbIfaceFont.addItem(f); |
490 |
|
491 |
if(Prefs.getInterfaceFont() == null) cbIfaceFont.setSelectedItem("[Default]"); |
492 |
else cbIfaceFont.setSelectedItem(Prefs.getInterfaceFont()); |
493 |
|
494 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
495 |
|
496 |
JPanel ifacePane = new JPanel(); |
497 |
ifacePane.setLayout(new BoxLayout(ifacePane, BoxLayout.X_AXIS)); |
498 |
ifacePane.add(lIfaceLanguage); |
499 |
ifacePane.add(Box.createRigidArea(new Dimension(5, 0))); |
500 |
ifacePane.add(cbIfaceLanguage); |
501 |
|
502 |
add(ifacePane); |
503 |
|
504 |
add(Box.createRigidArea(new Dimension(0, 6))); |
505 |
|
506 |
JPanel fontPane = new JPanel(); |
507 |
fontPane.setLayout(new BoxLayout(fontPane, BoxLayout.X_AXIS)); |
508 |
fontPane.add(lIfaceFont); |
509 |
fontPane.add(Box.createRigidArea(new Dimension(5, 0))); |
510 |
fontPane.add(cbIfaceFont); |
511 |
|
512 |
add(fontPane); |
513 |
add(Box.createRigidArea(new Dimension(0, 6))); |
514 |
add(createCustomColorsPane()); |
515 |
|
516 |
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
517 |
} |
518 |
|
519 |
private JPanel |
520 |
createCustomColorsPane() { |
521 |
JPanel ccp = new JPanel(); |
522 |
ccp.setAlignmentX(CENTER_ALIGNMENT); |
523 |
ccp.setLayout(new BoxLayout(ccp, BoxLayout.Y_AXIS)); |
524 |
|
525 |
JPanel p = new JPanel(); |
526 |
p.setAlignmentX(LEFT_ALIGNMENT); |
527 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
528 |
p.add(checkBorderColor); |
529 |
|
530 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
531 |
|
532 |
btnBorderColor.setColor(ClassicPrefs.getChannelBorderColor()); |
533 |
btnBorderColor.setEnabled(ClassicPrefs.getCustomChannelBorderColor()); |
534 |
p.add(btnBorderColor); |
535 |
|
536 |
checkBorderColor.setSelected(ClassicPrefs.getCustomChannelBorderColor()); |
537 |
|
538 |
checkBorderColor.addItemListener(new ItemListener() { |
539 |
public void |
540 |
itemStateChanged(ItemEvent e) { |
541 |
boolean b = e.getStateChange() == e.SELECTED; |
542 |
btnBorderColor.setEnabled(b); |
543 |
} |
544 |
}); |
545 |
|
546 |
ccp.add(p); |
547 |
|
548 |
JButton btnDefaults = new JButton("Reset to defaults"); |
549 |
btnDefaults.addActionListener(new ActionListener() { |
550 |
public void |
551 |
actionPerformed(ActionEvent e) { |
552 |
ClassicPrefs.setChannelBorderColor(null); |
553 |
btnBorderColor.setColor(ClassicPrefs.getChannelBorderColor()); |
554 |
} |
555 |
}); |
556 |
|
557 |
p = new JPanel(); |
558 |
p.setAlignmentX(LEFT_ALIGNMENT); |
559 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
560 |
p.setBorder(BorderFactory.createEmptyBorder(6, 0, 6, 6)); |
561 |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); |
562 |
|
563 |
p.add(Box.createGlue()); |
564 |
p.add(btnDefaults); |
565 |
p.add(Box.createGlue()); |
566 |
|
567 |
ccp.add(p); |
568 |
|
569 |
ccp.setBorder ( |
570 |
BorderFactory.createTitledBorder(i18n.getLabel("ViewPane.CustomColorsPane")) |
571 |
); |
572 |
|
573 |
ccp.setMaximumSize(new Dimension(Short.MAX_VALUE, ccp.getPreferredSize().height)); |
574 |
|
575 |
return ccp; |
576 |
} |
577 |
|
578 |
private String |
579 |
getInterfaceLanguage() { |
580 |
LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem(); |
581 |
if(box == null) return null; |
582 |
return box.getLocale().getLanguage(); |
583 |
} |
584 |
|
585 |
private String |
586 |
getInterfaceCountry() { |
587 |
LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem(); |
588 |
if(box == null) return null; |
589 |
return box.getLocale().getCountry(); |
590 |
} |
591 |
|
592 |
private String |
593 |
getInterfaceFontName() { return cbIfaceFont.getSelectedItem().toString(); } |
594 |
|
595 |
protected void |
596 |
apply() { |
597 |
boolean b = Prefs.setInterfaceLanguage(getInterfaceLanguage()); |
598 |
boolean b2 = Prefs.setInterfaceCountry(getInterfaceCountry()); |
599 |
if (b || b2) JOptionPane.showMessageDialog ( |
600 |
this, |
601 |
i18n.getMessage("PrefsDlg.ifaceChangeInfo", "JS Classic"), |
602 |
null, |
603 |
JOptionPane.INFORMATION_MESSAGE |
604 |
); |
605 |
|
606 |
b = false; |
607 |
String fontName = getInterfaceFontName(); |
608 |
if(fontName.equals("[Default]")) { |
609 |
b = Prefs.setInterfaceFont(null); |
610 |
} else if(Prefs.setInterfaceFont(fontName)) { |
611 |
HF.setUIDefaultFont(fontName); |
612 |
b = true; |
613 |
} |
614 |
|
615 |
if(b) JOptionPane.showMessageDialog ( |
616 |
this, |
617 |
i18n.getMessage("PrefsDlg.ifaceFontChangeInfo", "JS Classic"), |
618 |
null, |
619 |
JOptionPane.INFORMATION_MESSAGE |
620 |
); |
621 |
|
622 |
///***/// |
623 |
|
624 |
b = checkBorderColor.isSelected(); |
625 |
ClassicPrefs.setCustomChannelBorderColor(b); |
626 |
if(b) ClassicPrefs.setChannelBorderColor(btnBorderColor.getColor()); |
627 |
|
628 |
Color c; |
629 |
if(b) c = ClassicPrefs.getChannelBorderColor(); |
630 |
else c = ClassicPrefs.getDefaultChannelBorderColor(); |
631 |
Channel.setBorderColor(c); |
632 |
} |
633 |
|
634 |
class LocaleBox { |
635 |
private Locale locale; |
636 |
|
637 |
LocaleBox(Locale locale) { this.locale = locale; } |
638 |
|
639 |
public Locale |
640 |
getLocale() { return locale; } |
641 |
|
642 |
public String |
643 |
toString() { return locale.getDisplayLanguage(JSI18n.i18n.getCurrentLocale()); } |
644 |
} |
645 |
} |
646 |
|
647 |
class ConsolePane extends JPanel { |
648 |
private final JLabel lCmdHistorySize = |
649 |
new JLabel(i18n.getLabel("ConsolePane.lCmdHistorySize")); |
650 |
private final JSpinner spCmdHistorySize; |
651 |
private final JLabel lLines = new JLabel(i18n.getLabel("ConsolePane.lLines")); |
652 |
private final JButton btnClearCmdHistory = |
653 |
new JButton(i18n.getButtonLabel("ConsolePane.btnClearCmdHistory")); |
654 |
|
655 |
private final JLabel lTextColor = new JLabel(i18n.getLabel("ConsolePane.lTextColor")); |
656 |
private final PrefsDlg.ColorButton btnTextColor = new PrefsDlg.ColorButton(); |
657 |
|
658 |
private final JLabel lBGColor = new JLabel(i18n.getLabel("ConsolePane.lBGColor")); |
659 |
private final PrefsDlg.ColorButton btnBGColor = new PrefsDlg.ColorButton(); |
660 |
|
661 |
private final JLabel lNotifyColor = new JLabel(i18n.getLabel("ConsolePane.lNotifyColor")); |
662 |
private final PrefsDlg.ColorButton btnNotifyColor = new PrefsDlg.ColorButton(); |
663 |
|
664 |
private final JLabel lWarningColor = new JLabel(i18n.getLabel("ConsolePane.lWarningColor")); |
665 |
private final PrefsDlg.ColorButton btnWarningColor = new PrefsDlg.ColorButton(); |
666 |
|
667 |
private final JLabel lErrorColor = new JLabel(i18n.getLabel("ConsolePane.lErrorColor")); |
668 |
private final PrefsDlg.ColorButton btnErrorColor = new PrefsDlg.ColorButton(); |
669 |
|
670 |
|
671 |
public |
672 |
ConsolePane() { |
673 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
674 |
|
675 |
int i = ClassicPrefs.getLSConsoleHistSize(); |
676 |
spCmdHistorySize = new JSpinner(new SpinnerNumberModel(i, 0, 20000, 1)); |
677 |
spCmdHistorySize.setMaximumSize(spCmdHistorySize.getPreferredSize()); |
678 |
|
679 |
JPanel p = new JPanel(); |
680 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
681 |
p.add(lCmdHistorySize); |
682 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
683 |
p.add(spCmdHistorySize); |
684 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
685 |
p.add(lLines); |
686 |
|
687 |
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
688 |
add(p); |
689 |
|
690 |
add(Box.createRigidArea(new Dimension(0, 6))); |
691 |
|
692 |
btnClearCmdHistory.addActionListener(new ActionListener() { |
693 |
public void |
694 |
actionPerformed(ActionEvent e) { |
695 |
ClassicPrefs.setLSConsoleHistory(null); |
696 |
MainFrame mainFrame = (MainFrame)CC.getMainFrame(); |
697 |
mainFrame.getLSConsoleModel().clearCommandHistory(); |
698 |
} |
699 |
}); |
700 |
|
701 |
btnClearCmdHistory.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
702 |
add(btnClearCmdHistory); |
703 |
|
704 |
add(Box.createRigidArea(new Dimension(0, 6))); |
705 |
|
706 |
p = createConsoleColorsPane(); |
707 |
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
708 |
add(p); |
709 |
|
710 |
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
711 |
} |
712 |
|
713 |
private JPanel |
714 |
createConsoleColorsPane() { |
715 |
JPanel ccp = new JPanel(); |
716 |
ccp.setAlignmentX(CENTER_ALIGNMENT); |
717 |
|
718 |
GridBagLayout gridbag = new GridBagLayout(); |
719 |
GridBagConstraints c = new GridBagConstraints(); |
720 |
|
721 |
ccp.setLayout(gridbag); |
722 |
|
723 |
c.fill = GridBagConstraints.NONE; |
724 |
|
725 |
c.gridx = 0; |
726 |
c.gridy = 0; |
727 |
c.anchor = GridBagConstraints.EAST; |
728 |
c.insets = new Insets(3, 3, 3, 3); |
729 |
gridbag.setConstraints(lTextColor, c); |
730 |
ccp.add(lTextColor); |
731 |
|
732 |
c.gridx = 0; |
733 |
c.gridy = 1; |
734 |
gridbag.setConstraints(lBGColor, c); |
735 |
ccp.add(lBGColor); |
736 |
|
737 |
c.gridx = 0; |
738 |
c.gridy = 2; |
739 |
gridbag.setConstraints(lNotifyColor, c); |
740 |
ccp.add(lNotifyColor); |
741 |
|
742 |
c.gridx = 0; |
743 |
c.gridy = 3; |
744 |
gridbag.setConstraints(lWarningColor, c); |
745 |
ccp.add(lWarningColor); |
746 |
|
747 |
c.gridx = 0; |
748 |
c.gridy = 4; |
749 |
gridbag.setConstraints(lErrorColor, c); |
750 |
ccp.add(lErrorColor); |
751 |
|
752 |
c.fill = GridBagConstraints.HORIZONTAL; |
753 |
c.gridx = 1; |
754 |
c.gridy = 0; |
755 |
//c.weightx = 1.0; |
756 |
c.anchor = GridBagConstraints.WEST; |
757 |
gridbag.setConstraints(btnTextColor, c); |
758 |
ccp.add(btnTextColor); |
759 |
|
760 |
c.gridx = 1; |
761 |
c.gridy = 1; |
762 |
gridbag.setConstraints(btnBGColor, c); |
763 |
ccp.add(btnBGColor); |
764 |
|
765 |
c.gridx = 1; |
766 |
c.gridy = 2; |
767 |
gridbag.setConstraints(btnNotifyColor, c); |
768 |
ccp.add(btnNotifyColor); |
769 |
|
770 |
c.gridx = 1; |
771 |
c.gridy = 3; |
772 |
gridbag.setConstraints(btnWarningColor, c); |
773 |
ccp.add(btnWarningColor); |
774 |
|
775 |
c.gridx = 1; |
776 |
c.gridy = 4; |
777 |
gridbag.setConstraints(btnErrorColor, c); |
778 |
ccp.add(btnErrorColor); |
779 |
|
780 |
btnTextColor.setColor(ClassicPrefs.getLSConsoleTextColor()); |
781 |
btnBGColor.setColor(ClassicPrefs.getLSConsoleBackgroundColor()); |
782 |
btnNotifyColor.setColor(ClassicPrefs.getLSConsoleNotifyColor()); |
783 |
btnWarningColor.setColor(ClassicPrefs.getLSConsoleWarningColor()); |
784 |
btnErrorColor.setColor(ClassicPrefs.getLSConsoleErrorColor()); |
785 |
|
786 |
JButton btnDefaults = new JButton("Reset to defaults"); |
787 |
|
788 |
btnDefaults.addActionListener(new ActionListener() { |
789 |
public void |
790 |
actionPerformed(ActionEvent e) { |
791 |
ClassicPrefs.setLSConsoleTextColor(null); |
792 |
btnTextColor.setColor(ClassicPrefs.getLSConsoleTextColor()); |
793 |
|
794 |
ClassicPrefs.setLSConsoleBackgroundColor(null); |
795 |
btnBGColor.setColor(ClassicPrefs.getLSConsoleBackgroundColor()); |
796 |
|
797 |
ClassicPrefs.setLSConsoleNotifyColor(null); |
798 |
btnNotifyColor.setColor(ClassicPrefs.getLSConsoleNotifyColor()); |
799 |
|
800 |
ClassicPrefs.setLSConsoleWarningColor(null); |
801 |
btnWarningColor.setColor(ClassicPrefs.getLSConsoleWarningColor()); |
802 |
|
803 |
ClassicPrefs.setLSConsoleErrorColor(null); |
804 |
btnErrorColor.setColor(ClassicPrefs.getLSConsoleErrorColor()); |
805 |
} |
806 |
}); |
807 |
|
808 |
JPanel p = new JPanel(); |
809 |
p.setAlignmentX(LEFT_ALIGNMENT); |
810 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
811 |
p.setBorder(BorderFactory.createEmptyBorder(6, 0, 6, 6)); |
812 |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); |
813 |
|
814 |
p.add(Box.createGlue()); |
815 |
p.add(btnDefaults); |
816 |
p.add(Box.createGlue()); |
817 |
|
818 |
c.gridx = 0; |
819 |
c.gridy = 5; |
820 |
c.gridwidth = 2; |
821 |
gridbag.setConstraints(p, c); |
822 |
ccp.add(p); |
823 |
|
824 |
ccp.setBorder ( |
825 |
BorderFactory.createTitledBorder(i18n.getLabel("ConsolePane.consoleColors")) |
826 |
); |
827 |
|
828 |
ccp.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); |
829 |
|
830 |
return ccp; |
831 |
} |
832 |
|
833 |
protected void |
834 |
apply() { |
835 |
int size = Integer.parseInt(spCmdHistorySize.getValue().toString()); |
836 |
ClassicPrefs.setLSConsoleHistSize(size); |
837 |
LSConsoleModel model = ((MainFrame)CC.getMainFrame()).getLSConsoleModel(); |
838 |
model.setCommandHistorySize(size); |
839 |
|
840 |
///***/// |
841 |
|
842 |
MainFrame mainFrame = (MainFrame)CC.getMainFrame(); |
843 |
|
844 |
ClassicPrefs.setLSConsoleTextColor(btnTextColor.getColor()); |
845 |
mainFrame.setLSConsoleTextColor(btnTextColor.getColor()); |
846 |
|
847 |
ClassicPrefs.setLSConsoleBackgroundColor(btnBGColor.getColor()); |
848 |
mainFrame.setLSConsoleBackgroundColor(btnBGColor.getColor()); |
849 |
|
850 |
ClassicPrefs.setLSConsoleNotifyColor(btnNotifyColor.getColor()); |
851 |
mainFrame.setLSConsoleNotifyColor(btnNotifyColor.getColor()); |
852 |
|
853 |
ClassicPrefs.setLSConsoleWarningColor(btnWarningColor.getColor()); |
854 |
mainFrame.setLSConsoleWarningColor(btnWarningColor.getColor()); |
855 |
|
856 |
ClassicPrefs.setLSConsoleErrorColor(btnErrorColor.getColor()); |
857 |
mainFrame.setLSConsoleErrorColor(btnErrorColor.getColor()); |
858 |
} |
859 |
|
860 |
|
861 |
} |
862 |
|
863 |
class ConnectionPane extends JPanel { |
864 |
final LSPrefsPane lsPrefsPane = new LSPrefsPane(); |
865 |
|
866 |
public |
867 |
ConnectionPane() { initConnectionPane(); } |
868 |
|
869 |
private void |
870 |
initConnectionPane() { |
871 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
872 |
|
873 |
add(lsPrefsPane); |
874 |
add(Box.createGlue()); |
875 |
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
876 |
} |
877 |
|
878 |
public String |
879 |
getLSAddress() { return lsPrefsPane.getLSAddress(); } |
880 |
|
881 |
public void |
882 |
setLSAddress(String address) { lsPrefsPane.setLSAddress(address); } |
883 |
|
884 |
public String |
885 |
getLSPort() { return lsPrefsPane.getLSPort(); } |
886 |
|
887 |
public void |
888 |
setLSPort(String port) { lsPrefsPane.setLSPort(port); } |
889 |
} |
890 |
|
891 |
class LSPrefsPane extends JPanel { |
892 |
private final JLabel lAddress = new JLabel(i18n.getLabel("LSPrefsPane.Address")); |
893 |
private final JLabel lPort = new JLabel(i18n.getLabel("LSPrefsPane.Port")); |
894 |
private final JTextField tfAddress = new JTextField(); |
895 |
private final JTextField tfPort = new JTextField(); |
896 |
|
897 |
|
898 |
public |
899 |
LSPrefsPane() { initLSPrefsPane(); } |
900 |
|
901 |
private void |
902 |
initLSPrefsPane() { |
903 |
GridBagLayout gridbag = new GridBagLayout(); |
904 |
GridBagConstraints c = new GridBagConstraints(); |
905 |
|
906 |
setLayout(gridbag); |
907 |
|
908 |
// Set preferred size for username & password fields |
909 |
int w1 = (int) tfAddress.getMinimumSize().getWidth(); |
910 |
int h1 = (int) tfAddress.getMinimumSize().getHeight(); |
911 |
Dimension d = new Dimension(w1 > 150 ? w1 : 150, h1); |
912 |
tfAddress.setMinimumSize(d); |
913 |
tfAddress.setPreferredSize(d); |
914 |
|
915 |
w1 = (int) tfPort.getMinimumSize().getWidth(); |
916 |
h1 = (int) tfPort.getMinimumSize().getHeight(); |
917 |
d = new Dimension(w1 > 150 ? w1 : 150, h1); |
918 |
tfPort.setMinimumSize(d); |
919 |
tfPort.setPreferredSize(d); |
920 |
|
921 |
c.fill = GridBagConstraints.NONE; |
922 |
|
923 |
c.gridx = 0; |
924 |
c.gridy = 0; |
925 |
c.anchor = GridBagConstraints.EAST; |
926 |
c.insets = new Insets(3, 3, 3, 3); |
927 |
gridbag.setConstraints(lAddress, c); |
928 |
add(lAddress); |
929 |
|
930 |
c.gridx = 0; |
931 |
c.gridy = 1; |
932 |
gridbag.setConstraints(lPort, c); |
933 |
add(lPort); |
934 |
|
935 |
c.fill = GridBagConstraints.HORIZONTAL; |
936 |
c.gridx = 1; |
937 |
c.gridy = 0; |
938 |
c.weightx = 1.0; |
939 |
c.anchor = GridBagConstraints.WEST; |
940 |
gridbag.setConstraints(tfAddress, c); |
941 |
add(tfAddress); |
942 |
|
943 |
c.gridx = 1; |
944 |
c.gridy = 1; |
945 |
gridbag.setConstraints(tfPort, c); |
946 |
add(tfPort); |
947 |
|
948 |
setBorder(BorderFactory.createTitledBorder(i18n.getLabel("LSPrefsPane"))); |
949 |
setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); |
950 |
} |
951 |
|
952 |
public String |
953 |
getLSAddress() { return tfAddress.getText(); } |
954 |
|
955 |
public void |
956 |
setLSAddress(String address) { tfAddress.setText(address); } |
957 |
|
958 |
public String |
959 |
getLSPort() { return tfPort.getText(); } |
960 |
|
961 |
public void |
962 |
setLSPort(String port) { tfPort.setText(port); } |
963 |
} |