/[svn]/jsampler/trunk/src/org/jsampler/view/classic/PrefsDlg.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/classic/PrefsDlg.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 911 - (hide annotations) (download)
Mon Aug 7 18:25:58 2006 UTC (17 years, 8 months ago) by iliev
File size: 27348 byte(s)
updating to JSampler 0.3a

1 iliev 787 /*
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 iliev 842 import java.awt.BorderLayout;
26     import java.awt.Color;
27 iliev 787 import java.awt.Container;
28 iliev 842 import java.awt.Cursor;
29     import java.awt.Dialog;
30 iliev 787 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 iliev 842 import java.awt.event.ItemEvent;
41     import java.awt.event.ItemListener;
42     import java.awt.event.MouseAdapter;
43     import java.awt.event.MouseEvent;
44 iliev 787
45     import java.util.Locale;
46 iliev 842 import java.util.Vector;
47 iliev 787
48     import javax.swing.BorderFactory;
49     import javax.swing.Box;
50     import javax.swing.BoxLayout;
51 iliev 842 import javax.swing.DefaultButtonModel;
52 iliev 787 import javax.swing.JButton;
53 iliev 842 import javax.swing.JCheckBox;
54     import javax.swing.JColorChooser;
55 iliev 787 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 iliev 911 import javax.swing.JSpinner;
61 iliev 787 import javax.swing.JTabbedPane;
62     import javax.swing.JTextField;
63 iliev 911 import javax.swing.SpinnerNumberModel;
64 iliev 787
65 iliev 842 import javax.swing.event.ChangeEvent;
66     import javax.swing.event.ChangeListener;
67    
68 iliev 787 import net.sf.juife.EnhancedDialog;
69     import net.sf.juife.JuifeUtils;
70 iliev 842 import net.sf.juife.LinkButton;
71     import net.sf.juife.OkCancelDialog;
72 iliev 787
73 iliev 842 import org.jsampler.CC;
74 iliev 787 import org.jsampler.HF;
75     import org.jsampler.JSI18n;
76     import org.jsampler.JSampler;
77 iliev 911 import org.jsampler.LSConsoleModel;
78 iliev 787 import org.jsampler.Prefs;
79    
80 iliev 842 import org.jsampler.task.SetServerAddress;
81    
82 iliev 787 import static org.jsampler.view.classic.ClassicI18n.i18n;
83    
84    
85     /**
86     *
87     * @author Grigor Iliev
88     */
89     public class PrefsDlg extends EnhancedDialog {
90 iliev 911 private final GeneralPane genPane = new GeneralPane();
91 iliev 787 private final ViewPane viewPane = new ViewPane();
92 iliev 911 private final ConsolePane consolePane = new ConsolePane();
93 iliev 787 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 iliev 911 tp.addTab(i18n.getLabel("PrefsDlg.tabConsole"), consolePane);
116 iliev 787 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 iliev 842 genPane.apply();
172     viewPane.apply();
173 iliev 911 consolePane.apply();
174 iliev 787
175     // CONNECTION
176     Prefs.setLSAddress(getLSAddress());
177    
178 iliev 842 boolean b = true;
179 iliev 787 String s = getLSPort();
180     try {
181     if(s.length() > 0) {
182     int port = Integer.parseInt(s);
183     if(port > 0 && port < 0xffff)
184 iliev 842 Prefs.setLSPort(port);
185 iliev 787 else b = false;
186 iliev 842 } else Prefs.setLSPort(-1); // -1 resets to default value
187 iliev 787 } 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 iliev 842 CC.getTaskQueue().add (
203     new SetServerAddress(Prefs.getLSAddress(), Prefs.getLSPort())
204     );
205    
206 iliev 787 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 iliev 911
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 iliev 787 }
345    
346     class GeneralPane extends JPanel {
347 iliev 842 private final JCheckBox checkWindowSizeAndLocation =
348     new JCheckBox(i18n.getLabel("GeneralPane.checkWindowSizeAndLocation"));
349    
350 iliev 911 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 iliev 787 public
364 iliev 911 GeneralPane() {
365 iliev 842 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
366 iliev 787
367 iliev 911 checkWindowSizeAndLocation.setAlignmentX(JPanel.LEFT_ALIGNMENT);
368 iliev 842
369 iliev 911 checkWindowSizeAndLocation.setSelected(ClassicPrefs.getSaveWindowProperties());
370 iliev 842 checkWindowSizeAndLocation.addItemListener(new ItemListener() {
371     public void
372     itemStateChanged(ItemEvent e) {
373     boolean b = e.getStateChange() == e.SELECTED;
374 iliev 911 //checkWindowSizeAndLocation.setEnabled(b);
375 iliev 842 }
376     });
377    
378 iliev 911 add(checkWindowSizeAndLocation);
379 iliev 842
380 iliev 911 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 iliev 787 }
434 iliev 842
435     protected void
436     apply() {
437 iliev 911 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 iliev 842 }
447 iliev 787 }
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 iliev 842 private final JCheckBox checkBorderColor =
459     new JCheckBox(i18n.getLabel("ViewPane.channelBorderColor"));
460 iliev 911 private final PrefsDlg.ColorButton btnBorderColor =
461     new PrefsDlg.ColorButton(Color.WHITE);
462 iliev 842
463 iliev 787 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 iliev 842 add(Box.createRigidArea(new Dimension(0, 6)));
514     add(createCustomColorsPane());
515    
516 iliev 787 setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
517     }
518    
519 iliev 842 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 iliev 911 ccp.setMaximumSize(new Dimension(Short.MAX_VALUE, ccp.getPreferredSize().height));
574 iliev 842
575     return ccp;
576     }
577    
578     private String
579 iliev 787 getInterfaceLanguage() {
580     LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem();
581     if(box == null) return null;
582     return box.getLocale().getLanguage();
583     }
584    
585 iliev 842 private String
586 iliev 787 getInterfaceCountry() {
587     LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem();
588     if(box == null) return null;
589     return box.getLocale().getCountry();
590     }
591    
592 iliev 842 private String
593 iliev 787 getInterfaceFontName() { return cbIfaceFont.getSelectedItem().toString(); }
594    
595 iliev 842 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 iliev 787 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 iliev 911 }
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 iliev 842
655 iliev 911 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 iliev 842
675 iliev 911 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 iliev 842
701 iliev 911 btnClearCmdHistory.setAlignmentX(JPanel.CENTER_ALIGNMENT);
702     add(btnClearCmdHistory);
703 iliev 842
704 iliev 911 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 iliev 842
713 iliev 911 private JPanel
714     createConsoleColorsPane() {
715     JPanel ccp = new JPanel();
716     ccp.setAlignmentX(CENTER_ALIGNMENT);
717 iliev 842
718 iliev 911 GridBagLayout gridbag = new GridBagLayout();
719     GridBagConstraints c = new GridBagConstraints();
720 iliev 842
721 iliev 911 ccp.setLayout(gridbag);
722 iliev 842
723 iliev 911 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 iliev 842 }
806 iliev 911 });
807 iliev 842
808 iliev 911 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 iliev 842
814 iliev 911 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 iliev 842 }
832    
833 iliev 911 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 iliev 842
840 iliev 911 ///***///
841 iliev 842
842 iliev 911 MainFrame mainFrame = (MainFrame)CC.getMainFrame();
843 iliev 842
844 iliev 911 ClassicPrefs.setLSConsoleTextColor(btnTextColor.getColor());
845     mainFrame.setLSConsoleTextColor(btnTextColor.getColor());
846 iliev 842
847 iliev 911 ClassicPrefs.setLSConsoleBackgroundColor(btnBGColor.getColor());
848     mainFrame.setLSConsoleBackgroundColor(btnBGColor.getColor());
849 iliev 842
850 iliev 911 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 iliev 842 }
859 iliev 911
860    
861 iliev 787 }
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 iliev 842 setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height));
950 iliev 787 }
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     }

  ViewVC Help
Powered by ViewVC