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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1284 by iliev, Mon Apr 2 21:18:31 2007 UTC revision 1285 by iliev, Fri Aug 10 19:55:03 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 25  package org.jsampler.view.classic; Line 25  package org.jsampler.view.classic;
25  import java.awt.BorderLayout;  import java.awt.BorderLayout;
26  import java.awt.Color;  import java.awt.Color;
27  import java.awt.Container;  import java.awt.Container;
 import java.awt.Cursor;  
 import java.awt.Dialog;  
28  import java.awt.Dimension;  import java.awt.Dimension;
29  import java.awt.GraphicsEnvironment;  import java.awt.GraphicsEnvironment;
30  import java.awt.Font;  import java.awt.Font;
# Line 39  import java.awt.event.ActionEvent; Line 37  import java.awt.event.ActionEvent;
37  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
38  import java.awt.event.ItemEvent;  import java.awt.event.ItemEvent;
39  import java.awt.event.ItemListener;  import java.awt.event.ItemListener;
 import java.awt.event.MouseAdapter;  
 import java.awt.event.MouseEvent;  
   
 import java.io.File;  
40    
41  import java.util.Locale;  import java.util.Locale;
 import java.util.Vector;  
42    
43  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
44  import javax.swing.Box;  import javax.swing.Box;
# Line 53  import javax.swing.BoxLayout; Line 46  import javax.swing.BoxLayout;
46  import javax.swing.DefaultButtonModel;  import javax.swing.DefaultButtonModel;
47  import javax.swing.JButton;  import javax.swing.JButton;
48  import javax.swing.JCheckBox;  import javax.swing.JCheckBox;
 import javax.swing.JColorChooser;  
49  import javax.swing.JComboBox;  import javax.swing.JComboBox;
 import javax.swing.JFileChooser;  
50  import javax.swing.JLabel;  import javax.swing.JLabel;
51  import javax.swing.JOptionPane;  import javax.swing.JOptionPane;
52  import javax.swing.JPanel;  import javax.swing.JPanel;
 import javax.swing.JPasswordField;  
 import javax.swing.JSpinner;  
53  import javax.swing.JTabbedPane;  import javax.swing.JTabbedPane;
54  import javax.swing.JTextField;  import javax.swing.JTextField;
 import javax.swing.SpinnerNumberModel;  
   
 import javax.swing.event.ChangeEvent;  
 import javax.swing.event.ChangeListener;  
55    
56  import net.sf.juife.EnhancedDialog;  import net.sf.juife.EnhancedDialog;
57  import net.sf.juife.JuifeUtils;  import net.sf.juife.JuifeUtils;
58  import net.sf.juife.LinkButton;  import net.sf.juife.LinkButton;
 import net.sf.juife.OkCancelDialog;  
59    
60  import org.jsampler.CC;  import org.jsampler.CC;
61  import org.jsampler.HF;  import org.jsampler.HF;
# Line 80  import org.jsampler.JSampler; Line 64  import org.jsampler.JSampler;
64  import org.jsampler.LSConsoleModel;  import org.jsampler.LSConsoleModel;
65  import org.jsampler.Prefs;  import org.jsampler.Prefs;
66    
67  import org.jsampler.task.SetServerAddress;  import org.jsampler.view.std.JSColorButton;
68    import org.jsampler.view.std.JSConnectionPropsPane;
69    import org.jsampler.view.std.JSGeneralProps;
70    import org.jsampler.view.std.JSLSConsolePropsPane;
71    
72  import static org.jsampler.view.classic.ClassicI18n.i18n;  import static org.jsampler.view.classic.ClassicI18n.i18n;
73    import static org.jsampler.view.classic.ClassicPrefs.preferences;
74    import static org.jsampler.view.std.StdPrefs.*;
75    
76    
77  /**  /**
# Line 93  public class PrefsDlg extends EnhancedDi Line 82  public class PrefsDlg extends EnhancedDi
82          private final GeneralPane genPane = new GeneralPane();          private final GeneralPane genPane = new GeneralPane();
83          private final ViewPane viewPane = new ViewPane();          private final ViewPane viewPane = new ViewPane();
84          private final ConsolePane consolePane = new ConsolePane();          private final ConsolePane consolePane = new ConsolePane();
85          private final ConnectionPane conPane = new ConnectionPane();          private final JSConnectionPropsPane connectionPane = new JSConnectionPropsPane();
86                    
87          private final JButton btnApply = new JButton(i18n.getButtonLabel("apply"));          private final JButton btnApply = new JButton(i18n.getButtonLabel("apply"));
88          private final JButton btnClose = new JButton(i18n.getButtonLabel("close"));          private final JButton btnClose = new JButton(i18n.getButtonLabel("close"));
# Line 104  public class PrefsDlg extends EnhancedDi Line 93  public class PrefsDlg extends EnhancedDi
93                  super(frm, i18n.getLabel("PrefsDlg"), true);                  super(frm, i18n.getLabel("PrefsDlg"), true);
94                                    
95                  initPrefsDlg();                  initPrefsDlg();
96                  handleEvents();                  installListeners();
                 initPrefs();  
97                                    
98                  setLocation(JuifeUtils.centerLocation(this, frm));                  setLocation(JuifeUtils.centerLocation(this, frm));
99                    
100                    connectionPane.setLSAddress(Prefs.getLSAddress());
101                    connectionPane.setLSPort(String.valueOf(Prefs.getLSPort()));
102          }          }
103                    
104          private void          private void
# Line 116  public class PrefsDlg extends EnhancedDi Line 107  public class PrefsDlg extends EnhancedDi
107                  tp.addTab(i18n.getLabel("PrefsDlg.tabGeneral"), genPane);                  tp.addTab(i18n.getLabel("PrefsDlg.tabGeneral"), genPane);
108                  tp.addTab(i18n.getLabel("PrefsDlg.tabView"), viewPane);                  tp.addTab(i18n.getLabel("PrefsDlg.tabView"), viewPane);
109                  tp.addTab(i18n.getLabel("PrefsDlg.tabConsole"), consolePane);                  tp.addTab(i18n.getLabel("PrefsDlg.tabConsole"), consolePane);
110                  tp.addTab(i18n.getLabel("PrefsDlg.tabConnection"), conPane);                  
111                    JPanel p = new JPanel();
112                    p.setLayout(new BorderLayout());
113                    p.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
114                    p.add(connectionPane, BorderLayout.NORTH);
115                    tp.addTab(i18n.getLabel("PrefsDlg.tabConnection"), p);
116                    
117                  tp.setAlignmentX(RIGHT_ALIGNMENT);                  tp.setAlignmentX(RIGHT_ALIGNMENT);
118                                    
119                  // Set preferred size for Apply & Exit buttons                  // Set preferred size for Apply & Exit buttons
# Line 145  public class PrefsDlg extends EnhancedDi Line 142  public class PrefsDlg extends EnhancedDi
142          }          }
143                    
144          private void          private void
145          handleEvents() {          installListeners() {
146                  btnApply.addActionListener(new ActionListener() {                  btnApply.addActionListener(new ActionListener() {
147                          public void                          public void
148                          actionPerformed(ActionEvent e) { onApply(); }                          actionPerformed(ActionEvent e) { onApply(); }
# Line 162  public class PrefsDlg extends EnhancedDi Line 159  public class PrefsDlg extends EnhancedDi
159                    
160          protected void          protected void
161          onCancel() { onExit(); }          onCancel() { onExit(); }
                   
         private void  
         initPrefs() {  
                 setLSAddress(Prefs.getLSAddress());  
                 setLSPort(Prefs.getLSPort());  
         }  
162                    
163          private void          private void
164          onApply() {          onApply() {
165                  genPane.apply();                  genPane.apply();
166                  viewPane.apply();                  viewPane.apply();
167                  consolePane.apply();                  consolePane.apply();
168                                    connectionPane.apply();
                 // CONNECTION  
                 Prefs.setLSAddress(getLSAddress());  
                   
                 boolean b = true;  
                 String s = getLSPort();  
                 try {  
                         if(s.length() > 0) {  
                                 int port = Integer.parseInt(s);  
                                 if(port > 0 && port < 0xffff)  
                                         Prefs.setLSPort(port);  
                                 else b = false;  
                         } else Prefs.setLSPort(-1);     // -1 resets to default value  
                 } catch(NumberFormatException x) {  
                         b = false;  
                 }  
                   
                 if(!b) {  
                         JOptionPane.showMessageDialog (  
                                 this,  
                                 i18n.getError("PrefsDlg.invalidPort", s),  
                                 i18n.getError("error"),  
                                 JOptionPane.ERROR_MESSAGE  
                         );  
                           
                         return;  
                 }  
                   
                 CC.getTaskQueue().add (  
                         new SetServerAddress(Prefs.getLSAddress(), Prefs.getLSPort())  
                 );  
169                                    
170                  setVisible(false);                  setVisible(false);
171          }          }
172                    
173          private void          private void
174          onExit() { setVisible(false); }          onExit() { setVisible(false); }
           
         private String  
         getLSAddress() { return conPane.getLSAddress().trim(); }  
           
         private void  
         setLSAddress(String s) { conPane.setLSAddress(s); }  
           
         private String  
         getLSPort() { return conPane.getLSPort().trim(); }  
           
         private void  
         setLSPort(int port) { conPane.setLSPort(String.valueOf(port)); }  
           
         protected static class ColorButton extends JPanel {  
                 private Color color;  
                 private final Vector<ActionListener> listeners = new Vector<ActionListener>();  
                   
                 ColorButton() { this(Color.WHITE); }  
                   
                 ColorButton(Color c) {  
                         color = c;  
                           
                         //setBorderPainted(false);  
                         setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));  
                         setPreferredSize(new Dimension(42, 16));  
                         setMaximumSize(new Dimension(42, 16));  
                         setBorder(BorderFactory.createLineBorder(Color.BLACK));  
                           
                         addMouseListener(new MouseAdapter() {  
                                 public void  
                                 mouseClicked(MouseEvent e) {  
                                         if(!isEnabled()) return;  
                                         if(e.getButton() == e.BUTTON1) showColorChooser();  
                                 }  
                         });  
                 }  
                   
                 /**  
                  * Registers the specified listener to be  
                  * notified when the current color is changed.  
                  * @param l The <code>ActionListener</code> to register.  
                  */  
                 public void  
                 addActionListener(ActionListener l) { listeners.add(l); }  
           
                 /**  
                  * Removes the specified listener.  
                  * @param l The <code>ActionListener</code> to remove.  
                  */  
                 public void  
                 removeActionListener(ActionListener l) { listeners.remove(l); }  
                   
                 /** Notifies listeners that the current color is changed. */  
                 private void  
                 fireActionPerformed() {  
                         ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null);  
                         for(ActionListener l : listeners) l.actionPerformed(e);  
                 }  
           
                 public void  
                 setEnabled(boolean b) {  
                         setOpaque(b);  
                         if(b) setBorder(BorderFactory.createLineBorder(Color.BLACK));  
                         else setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));  
                         //setBorderPainted(!b);  
                         super.setEnabled(b);  
                 }  
                   
                 private void  
                 showColorChooser() {  
                         ColorDlg dlg = new ColorDlg (  
                                 (Dialog)JuifeUtils.getWindow(this), getColor()  
                         );  
                           
                         dlg.setVisible(true);  
                         if(!dlg.isCancelled()) {  
                                 setColor(dlg.getColor());  
                                 fireActionPerformed();  
                         }  
                 }  
                   
                 public Color  
                 getColor() { return color; }  
                   
                 public void  
                 setColor(Color c) {  
                         color = c;  
                         setBackground(color);  
                 }  
         }  
           
         protected static class ColorDlg extends OkCancelDialog {  
                 private final JColorChooser colorChooser = new JColorChooser();  
                   
                 ColorDlg(Dialog owner) { this(owner, Color.WHITE); }  
                   
                 ColorDlg(Dialog owner, Color c) {  
                         super(owner);  
                           
                         colorChooser.setPreviewPanel(new JPanel());  
                         colorChooser.setColor(c);  
                           
                         JPanel mainPane = new JPanel();  
                         mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));  
                         mainPane.add(colorChooser);  
                           
                         mainPane.add(Box.createRigidArea(new Dimension(0, 6)));  
                           
                         final JPanel p = new JPanel();  
                         p.setBackground(c);  
                         p.setBorder(BorderFactory.createLineBorder(Color.BLACK));  
                         mainPane.add(p);  
                           
                         p.setPreferredSize(new Dimension(48, 8));  
                         p.setMaximumSize(new Dimension(Short.MAX_VALUE, 8));  
                           
                         setMainPane(mainPane);  
                           
                         colorChooser.getSelectionModel().addChangeListener(new ChangeListener() {  
                                 public void  
                                 stateChanged(ChangeEvent e) { p.setBackground(getColor()); }  
                         });  
                 }  
                   
                 protected void  
                 onOk() { setVisible(false); }  
                   
                 protected void  
                 onCancel() { setVisible(false); }  
                   
                 public Color  
                 getColor() { return colorChooser.getColor(); }  
         }  
175  }  }
176    
177  class GeneralPane extends JPanel {  class GeneralPane extends JPanel {
# Line 356  class GeneralPane extends JPanel { Line 184  class GeneralPane extends JPanel {
184          private final JCheckBox checkShowLSConsoleWhenRunScript =          private final JCheckBox checkShowLSConsoleWhenRunScript =
185                  new JCheckBox(i18n.getLabel("GeneralPane.checkShowLSConsoleWhenRunScript"));                  new JCheckBox(i18n.getLabel("GeneralPane.checkShowLSConsoleWhenRunScript"));
186                    
187          private final JTextField tfJSamplerHome = new JTextField();          private final JSGeneralProps.JSamplerHomePane jSamplerHomePane =
188          private final JButton btnChange = new JButton(i18n.getLabel("GeneralPane.btnChange"));                  new JSGeneralProps.JSamplerHomePane();
189                    
190          private final JLabel lRecentScriptsSize =          private final RecentScriptsPane recentScriptsPane = new RecentScriptsPane();
                 new JLabel(i18n.getLabel("GeneralPane.lRecentScriptsSize"));  
         private final JSpinner spRecentScriptsSize;  
         private final JButton btnClearRecentScriptList =  
                 new JButton(i18n.getButtonLabel("GeneralPane.btnClearRecentScriptList"));  
191                    
192                    
193          public          public
# Line 389  class GeneralPane extends JPanel { Line 213  class GeneralPane extends JPanel {
213                                    
214                  checkShowLSConsoleWhenRunScript.setAlignmentX(JPanel.LEFT_ALIGNMENT);                  checkShowLSConsoleWhenRunScript.setAlignmentX(JPanel.LEFT_ALIGNMENT);
215                                    
216                  boolean b = ClassicPrefs.getShowLSConsoleWhenRunScript();                  boolean b = preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT);
217                  checkShowLSConsoleWhenRunScript.setSelected(b);                  checkShowLSConsoleWhenRunScript.setSelected(b);
218                                    
219                  add(checkShowLSConsoleWhenRunScript);                  add(checkShowLSConsoleWhenRunScript);
220                                    
221                  add(Box.createRigidArea(new Dimension(0, 6)));                  add(Box.createRigidArea(new Dimension(0, 6)));
222                                    
223                  JPanel jhp = new JPanel();                  add(jSamplerHomePane);
                 jhp.setLayout(new BoxLayout(jhp, BoxLayout.Y_AXIS));  
                   
                 JPanel p = new JPanel();  
                 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));  
                 if(CC.getJSamplerHome() != null) tfJSamplerHome.setText(CC.getJSamplerHome());  
                 Dimension d;  
                 d = new Dimension(Short.MAX_VALUE, tfJSamplerHome.getPreferredSize().height);  
                 tfJSamplerHome.setMaximumSize(d);  
                 p.add(tfJSamplerHome);  
                 p.add(Box.createRigidArea(new Dimension(5, 0)));  
                 p.add(btnChange);  
                 p.setBorder(BorderFactory.createEmptyBorder(2, 6, 6, 6));  
                 p.setAlignmentX(JPanel.CENTER_ALIGNMENT);  
                 jhp.add(p);  
                   
                 String s = i18n.getLabel("GeneralPane.jSamplerHome");  
                 jhp.setBorder(BorderFactory.createTitledBorder(s));  
                 jhp.setMaximumSize(new Dimension(Short.MAX_VALUE, jhp.getPreferredSize().height));  
                 jhp.setAlignmentX(JPanel.LEFT_ALIGNMENT);  
                 add(jhp);  
224                                    
225                  add(Box.createRigidArea(new Dimension(0, 6)));                  add(Box.createRigidArea(new Dimension(0, 6)));
226                                    
227                  JPanel rsp = new JPanel();                  add(recentScriptsPane);
                 rsp.setLayout(new BoxLayout(rsp, BoxLayout.Y_AXIS));  
                   
                 int i = ClassicPrefs.getRecentScriptsSize();  
                 spRecentScriptsSize = new JSpinner(new SpinnerNumberModel(i, 0, 100, 1));  
                 spRecentScriptsSize.setMaximumSize(spRecentScriptsSize.getPreferredSize());  
                   
                 p = new JPanel();  
                 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));  
                 p.add(lRecentScriptsSize);  
                 p.add(Box.createRigidArea(new Dimension(5, 0)));  
                 p.add(spRecentScriptsSize);  
                   
                 p.setAlignmentX(JPanel.CENTER_ALIGNMENT);  
                 rsp.add(p);  
                   
                 rsp.add(Box.createRigidArea(new Dimension(0, 6)));  
                   
                 btnClearRecentScriptList.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) {  
                                 ClassicPrefs.setRecentScripts(null);  
                                 ((MainFrame)CC.getMainFrame()).clearRecentScripts();  
                         }  
                 });  
                   
                 btnClearRecentScriptList.setAlignmentX(JPanel.CENTER_ALIGNMENT);  
                 rsp.add(btnClearRecentScriptList);  
                 rsp.add(Box.createRigidArea(new Dimension(0, 6)));  
                   
                 rsp.setMaximumSize(new Dimension(Short.MAX_VALUE, rsp.getPreferredSize().height));  
                 rsp.setAlignmentX(JPanel.LEFT_ALIGNMENT);  
                 s = i18n.getLabel("GeneralPane.recentScripts");  
                 rsp.setBorder(BorderFactory.createTitledBorder(s));  
                   
                 add(rsp);  
228                  add(Box.createGlue());                  add(Box.createGlue());
229                                    
230                  setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));                  setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
                   
                 btnChange.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) { onChange(); }  
                 });  
         }  
           
         private void  
         onChange() {  
                 JFileChooser fc = new JFileChooser();  
                 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);  
                 int result = fc.showOpenDialog(this);  
                 if(result != JFileChooser.APPROVE_OPTION) return;  
                   
                 String s = CC.getJSamplerHome();  
                 String suf = File.separator + ".jsampler";  
                 if(s != null) suf = File.separator + new File(s).getName();  
                   
                 tfJSamplerHome.setText(fc.getSelectedFile().getPath() + suf);  
231          }          }
232                    
233          protected void          protected void
# Line 486  class GeneralPane extends JPanel { Line 236  class GeneralPane extends JPanel {
236                  ClassicPrefs.setSaveLeftPaneState(checkLeftPaneState.isSelected());                  ClassicPrefs.setSaveLeftPaneState(checkLeftPaneState.isSelected());
237                                    
238                  boolean b = checkShowLSConsoleWhenRunScript.isSelected();                  boolean b = checkShowLSConsoleWhenRunScript.isSelected();
239                  ClassicPrefs.setShowLSConsoleWhenRunScript(b);                  preferences().setBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT, b);
240                                    
241                  int size = Integer.parseInt(spRecentScriptsSize.getValue().toString());                  int size = recentScriptsPane.getRecentScriptsSize();
242                  ClassicPrefs.setRecentScriptstSize(size);                  preferences().setIntProperty(RECENT_LSCP_SCRIPTS_SIZE, size);
243                  ((MainFrame)CC.getMainFrame()).updateRecentScriptsMenu();                  ((MainFrame)CC.getMainFrame()).updateRecentScriptsMenu();
244                                    
245                  String s = tfJSamplerHome.getText();                  String s = jSamplerHomePane.getJSamplerHome();
246                  if(s.length() > 0 && !s.equals(CC.getJSamplerHome())) {                  if(s.length() > 0 && !s.equals(CC.getJSamplerHome())) {
247                          CC.changeJSamplerHome(s);                          CC.changeJSamplerHome(s);
248                  }                  }
249          }          }
250            
251            private class RecentScriptsPane extends JSGeneralProps.RecentScriptsPane {
252                    protected void
253                    clearRecentScripts() {
254                            ((MainFrame)CC.getMainFrame()).clearRecentScripts();
255                    }
256            }
257  }  }
258    
259  class ViewPane extends JPanel {  class ViewPane extends JPanel {
# Line 510  class ViewPane extends JPanel { Line 267  class ViewPane extends JPanel {
267                    
268          private final JCheckBox checkBorderColor =          private final JCheckBox checkBorderColor =
269                  new JCheckBox(i18n.getLabel("ViewPane.channelBorderColor"));                  new JCheckBox(i18n.getLabel("ViewPane.channelBorderColor"));
270          private final PrefsDlg.ColorButton btnBorderColor =          private final JSColorButton btnBorderColor = new JSColorButton(Color.WHITE);
                 new PrefsDlg.ColorButton(Color.WHITE);  
271                    
272          private final JCheckBox checkHlChnBorderColor =          private final JCheckBox checkHlChnBorderColor =
273                  new JCheckBox(i18n.getLabel("ViewPane.checkHlChnBorderColor"));                  new JCheckBox(i18n.getLabel("ViewPane.checkHlChnBorderColor"));
274          private final PrefsDlg.ColorButton btnHlChnBorderColor =          private final JSColorButton btnHlChnBorderColor = new JSColorButton(Color.WHITE);
                 new PrefsDlg.ColorButton(Color.WHITE);  
275                    
276          private final JCheckBox checkSelChnBgColor =          private final JCheckBox checkSelChnBgColor =
277                  new JCheckBox(i18n.getLabel("ViewPane.checkSelChnBgColor"));                  new JCheckBox(i18n.getLabel("ViewPane.checkSelChnBgColor"));
278          private final PrefsDlg.ColorButton btnSelChnBgColor =          private final JSColorButton btnSelChnBgColor = new JSColorButton(Color.WHITE);
                 new PrefsDlg.ColorButton(Color.WHITE);  
279                    
280          private final JCheckBox checkHlChnBgColor =          private final JCheckBox checkHlChnBgColor =
281                  new JCheckBox(i18n.getLabel("ViewPane.checkHlChnBgColor"));                  new JCheckBox(i18n.getLabel("ViewPane.checkHlChnBgColor"));
282          private final PrefsDlg.ColorButton btnHlChnBgColor =          private final JSColorButton btnHlChnBgColor = new JSColorButton(Color.WHITE);
                 new PrefsDlg.ColorButton(Color.WHITE);  
283                    
284          public          public
285          ViewPane() { initViewPane(); }          ViewPane() { initViewPane(); }
# Line 834  class ViewPane extends JPanel { Line 587  class ViewPane extends JPanel {
587          }          }
588  }  }
589    
590  class ConsolePane extends JPanel {  class ConsolePane extends JSLSConsolePropsPane {
591          private final JCheckBox checkSaveCmdHist =          protected void
592                  new JCheckBox(i18n.getLabel("ConsolePane.checkSaveCmdHist"));          clearConsoleHistory() {
593                            MainFrame mainFrame = (MainFrame)CC.getMainFrame();
594          private final JLabel lCmdHistorySize =                  mainFrame.getLSConsoleModel().clearCommandHistory();
                 new JLabel(i18n.getLabel("ConsolePane.lCmdHistorySize"));  
         private JSpinner spCmdHistorySize;  
         private final JLabel lLines = new JLabel(i18n.getLabel("ConsolePane.lLines"));  
         private final JButton btnClearCmdHistory =  
                 new JButton(i18n.getButtonLabel("ConsolePane.btnClearCmdHistory"));  
           
         private final JLabel lTextColor = new JLabel(i18n.getLabel("ConsolePane.lTextColor"));  
         private final PrefsDlg.ColorButton btnTextColor = new PrefsDlg.ColorButton();  
           
         private final JLabel lBGColor = new JLabel(i18n.getLabel("ConsolePane.lBGColor"));  
         private final PrefsDlg.ColorButton btnBGColor = new PrefsDlg.ColorButton();  
           
         private final JLabel lNotifyColor = new JLabel(i18n.getLabel("ConsolePane.lNotifyColor"));  
         private final PrefsDlg.ColorButton btnNotifyColor = new PrefsDlg.ColorButton();  
           
         private final JLabel lWarningColor = new JLabel(i18n.getLabel("ConsolePane.lWarningColor"));  
         private final PrefsDlg.ColorButton btnWarningColor = new PrefsDlg.ColorButton();  
           
         private final JLabel lErrorColor = new JLabel(i18n.getLabel("ConsolePane.lErrorColor"));  
         private final PrefsDlg.ColorButton btnErrorColor = new PrefsDlg.ColorButton();  
           
           
         public  
         ConsolePane() {  
                 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));  
                   
                 add(checkSaveCmdHist);  
                   
                 add(createCommandHistoryPane());  
                 add(Box.createRigidArea(new Dimension(0, 6)));  
                 add(createConsoleColorsPane());  
                   
                 setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));  
         }  
           
         private JPanel  
         createCommandHistoryPane() {  
                 JPanel chp = new JPanel();  
                 chp.setAlignmentX(CENTER_ALIGNMENT);  
                   
                 GridBagLayout gridbag = new GridBagLayout();  
                 GridBagConstraints c = new GridBagConstraints();  
           
                 chp.setLayout(gridbag);  
                   
                 int i = ClassicPrefs.getLSConsoleHistSize();  
                 spCmdHistorySize = new JSpinner(new SpinnerNumberModel(i, 0, 20000, 1));  
                 spCmdHistorySize.setMaximumSize(spCmdHistorySize.getPreferredSize());  
                   
                 btnClearCmdHistory.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) {  
                                 LSConsolePane.clearConsoleHistory();  
                                 MainFrame mainFrame = (MainFrame)CC.getMainFrame();  
                                 mainFrame.getLSConsoleModel().clearCommandHistory();  
                         }  
                 });  
                           
                 btnClearCmdHistory.setAlignmentX(JPanel.CENTER_ALIGNMENT);  
                 add(btnClearCmdHistory);  
                   
                 c.fill = GridBagConstraints.NONE;  
                   
                 c.gridx = 0;  
                 c.gridy = 0;  
                 c.anchor = GridBagConstraints.EAST;  
                 c.insets = new Insets(0, 6, 3, 0);  
                 gridbag.setConstraints(lCmdHistorySize, c);  
                 chp.add(lCmdHistorySize);  
   
                 c.gridx = 1;  
                 c.gridy = 0;  
                 gridbag.setConstraints(spCmdHistorySize, c);  
                 chp.add(spCmdHistorySize);  
   
                 c.gridx = 2;  
                 c.gridy = 0;  
                 gridbag.setConstraints(lLines, c);  
                 chp.add(lLines);  
   
                 c.gridx = 3;  
                 c.gridy = 0;  
                 c.insets = new Insets(0, 12, 3, 6);  
                 gridbag.setConstraints(btnClearCmdHistory, c);  
                 chp.add(btnClearCmdHistory);  
   
                 checkSaveCmdHist.setSelected(ClassicPrefs.getSaveConsoleHistory());  
                 checkSaveCmdHist.setAlignmentX(JPanel.CENTER_ALIGNMENT);  
                   
                 c.gridx = 0;  
                 c.gridy = 1;  
                 c.gridwidth = 4;  
                 c.insets = new Insets(3, 6, 3, 6);  
                 c.anchor = GridBagConstraints.CENTER;  
                 gridbag.setConstraints(checkSaveCmdHist, c);  
                 chp.add(checkSaveCmdHist);  
   
                 String s = i18n.getLabel("ConsolePane.commandHistory");  
                 chp.setBorder(BorderFactory.createTitledBorder(s));  
                   
                 chp.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));  
                   
                 return chp;  
         }  
           
         private JPanel  
         createConsoleColorsPane() {  
                 JPanel ccp = new JPanel();  
                 ccp.setAlignmentX(CENTER_ALIGNMENT);  
                   
                 GridBagLayout gridbag = new GridBagLayout();  
                 GridBagConstraints c = new GridBagConstraints();  
           
                 ccp.setLayout(gridbag);  
                   
                 c.fill = GridBagConstraints.NONE;  
           
                 c.gridx = 0;  
                 c.gridy = 0;  
                 c.anchor = GridBagConstraints.EAST;  
                 c.insets = new Insets(3, 3, 3, 3);  
                 gridbag.setConstraints(lTextColor, c);  
                 ccp.add(lTextColor);  
   
                 c.gridx = 0;  
                 c.gridy = 1;  
                 gridbag.setConstraints(lBGColor, c);  
                 ccp.add(lBGColor);  
           
                 c.gridx = 0;  
                 c.gridy = 2;  
                 gridbag.setConstraints(lNotifyColor, c);  
                 ccp.add(lNotifyColor);  
           
                 c.gridx = 0;  
                 c.gridy = 3;  
                 gridbag.setConstraints(lWarningColor, c);  
                 ccp.add(lWarningColor);  
           
                 c.gridx = 0;  
                 c.gridy = 4;  
                 gridbag.setConstraints(lErrorColor, c);  
                 ccp.add(lErrorColor);  
           
                 c.fill = GridBagConstraints.HORIZONTAL;  
                 c.gridx = 1;  
                 c.gridy = 0;  
                 //c.weightx = 1.0;  
                 c.anchor = GridBagConstraints.WEST;  
                 gridbag.setConstraints(btnTextColor, c);  
                 ccp.add(btnTextColor);  
                   
                 c.gridx = 1;  
                 c.gridy = 1;  
                 gridbag.setConstraints(btnBGColor, c);  
                 ccp.add(btnBGColor);  
                   
                 c.gridx = 1;  
                 c.gridy = 2;  
                 gridbag.setConstraints(btnNotifyColor, c);  
                 ccp.add(btnNotifyColor);  
                   
                 c.gridx = 1;  
                 c.gridy = 3;  
                 gridbag.setConstraints(btnWarningColor, c);  
                 ccp.add(btnWarningColor);  
                   
                 c.gridx = 1;  
                 c.gridy = 4;  
                 gridbag.setConstraints(btnErrorColor, c);  
                 ccp.add(btnErrorColor);  
                   
                 btnTextColor.setColor(ClassicPrefs.getLSConsoleTextColor());  
                 btnBGColor.setColor(ClassicPrefs.getLSConsoleBackgroundColor());  
                 btnNotifyColor.setColor(ClassicPrefs.getLSConsoleNotifyColor());  
                 btnWarningColor.setColor(ClassicPrefs.getLSConsoleWarningColor());  
                 btnErrorColor.setColor(ClassicPrefs.getLSConsoleErrorColor());  
                   
                 JButton btnDefaults = new JButton("Reset to defaults");  
                   
                 btnDefaults.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) {  
                                 ClassicPrefs.setLSConsoleTextColor(null);  
                                 btnTextColor.setColor(ClassicPrefs.getLSConsoleTextColor());  
                                   
                                 ClassicPrefs.setLSConsoleBackgroundColor(null);  
                                 btnBGColor.setColor(ClassicPrefs.getLSConsoleBackgroundColor());  
                                   
                                 ClassicPrefs.setLSConsoleNotifyColor(null);  
                                 btnNotifyColor.setColor(ClassicPrefs.getLSConsoleNotifyColor());  
                                   
                                 ClassicPrefs.setLSConsoleWarningColor(null);  
                                 btnWarningColor.setColor(ClassicPrefs.getLSConsoleWarningColor());  
                                   
                                 ClassicPrefs.setLSConsoleErrorColor(null);  
                                 btnErrorColor.setColor(ClassicPrefs.getLSConsoleErrorColor());  
                         }  
                 });  
                   
                 JPanel p = new JPanel();  
                 p.setAlignmentX(LEFT_ALIGNMENT);  
                 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));  
                 p.setBorder(BorderFactory.createEmptyBorder(6, 0, 6, 6));  
                 p.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));  
                   
                 p.add(Box.createGlue());  
                 p.add(btnDefaults);  
                 p.add(Box.createGlue());  
                   
                 c.gridx = 0;  
                 c.gridy = 5;  
                 c.gridwidth = 2;  
                 gridbag.setConstraints(p, c);  
                 ccp.add(p);  
                   
                 String s = i18n.getLabel("ConsolePane.consoleColors");  
                 ccp.setBorder(BorderFactory.createTitledBorder(s));  
                   
                 ccp.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));  
                   
                 return ccp;  
595          }          }
596                    
597          protected void          protected void
598          apply() {          apply() {
599                  ClassicPrefs.setSaveConsoleHistory(checkSaveCmdHist.isSelected());                  super.apply();
                   
                 int size = Integer.parseInt(spCmdHistorySize.getValue().toString());  
                 ClassicPrefs.setLSConsoleHistSize(size);  
                 LSConsoleModel model = ((MainFrame)CC.getMainFrame()).getLSConsoleModel();  
                 model.setCommandHistorySize(size);  
                   
                 ///***///  
600                                    
601                  MainFrame mainFrame = (MainFrame)CC.getMainFrame();                  MainFrame mainFrame = (MainFrame)CC.getMainFrame();
602                                    
603                  ClassicPrefs.setLSConsoleTextColor(btnTextColor.getColor());                  LSConsoleModel model = mainFrame.getLSConsoleModel();
604                  mainFrame.setLSConsoleTextColor(btnTextColor.getColor());                  model.setCommandHistorySize(preferences().getIntProperty(LS_CONSOLE_HISTSIZE));
605                                    
606                  ClassicPrefs.setLSConsoleBackgroundColor(btnBGColor.getColor());                  int c = preferences().getIntProperty(LS_CONSOLE_TEXT_COLOR);
607                  mainFrame.setLSConsoleBackgroundColor(btnBGColor.getColor());                  mainFrame.setLSConsoleTextColor(new Color(c));
608                                    
609                  ClassicPrefs.setLSConsoleNotifyColor(btnNotifyColor.getColor());                  c = preferences().getIntProperty(LS_CONSOLE_BACKGROUND_COLOR);
610                  mainFrame.setLSConsoleNotifyColor(btnNotifyColor.getColor());                  mainFrame.setLSConsoleBackgroundColor(new Color(c));
611                                    
612                  ClassicPrefs.setLSConsoleWarningColor(btnWarningColor.getColor());                  c = preferences().getIntProperty(LS_CONSOLE_NOTIFY_COLOR);
613                  mainFrame.setLSConsoleWarningColor(btnWarningColor.getColor());                  mainFrame.setLSConsoleNotifyColor(new Color(c));
614                                    
615                  ClassicPrefs.setLSConsoleErrorColor(btnErrorColor.getColor());                  c = preferences().getIntProperty(LS_CONSOLE_WARNING_COLOR);
616                  mainFrame.setLSConsoleErrorColor(btnErrorColor.getColor());                  mainFrame.setLSConsoleWarningColor(new Color(c));
         }  
           
           
 }  
   
 class ConnectionPane extends JPanel {  
         final LSPrefsPane lsPrefsPane = new LSPrefsPane();  
           
         public  
         ConnectionPane() { initConnectionPane(); }  
           
         private void  
         initConnectionPane() {  
                 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));  
617                                    
618                  add(lsPrefsPane);                  c = preferences().getIntProperty(LS_CONSOLE_ERROR_COLOR);
619                  add(Box.createGlue());                  mainFrame.setLSConsoleErrorColor(new Color(c));
                 setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));  
620          }          }
           
         public String  
         getLSAddress() { return lsPrefsPane.getLSAddress(); }  
           
         public void  
         setLSAddress(String address) { lsPrefsPane.setLSAddress(address); }  
           
         public String  
         getLSPort() { return lsPrefsPane.getLSPort(); }  
           
         public void  
         setLSPort(String port) { lsPrefsPane.setLSPort(port); }  
 }  
   
 class LSPrefsPane extends JPanel {  
         private final JLabel lAddress = new JLabel(i18n.getLabel("LSPrefsPane.Address"));  
         private final JLabel lPort = new JLabel(i18n.getLabel("LSPrefsPane.Port"));  
         private final JTextField tfAddress = new JTextField();  
         private final JTextField tfPort = new JTextField();  
   
   
         public  
         LSPrefsPane() { initLSPrefsPane(); }  
   
         private void  
         initLSPrefsPane() {  
                 GridBagLayout gridbag = new GridBagLayout();  
                 GridBagConstraints c = new GridBagConstraints();  
           
                 setLayout(gridbag);  
                   
                 // Set preferred size for username & password fields  
                 int w1 = (int) tfAddress.getMinimumSize().getWidth();  
                 int h1 = (int) tfAddress.getMinimumSize().getHeight();  
                 Dimension d = new Dimension(w1 > 150 ? w1 : 150, h1);  
                 tfAddress.setMinimumSize(d);  
                 tfAddress.setPreferredSize(d);  
           
                 w1 = (int) tfPort.getMinimumSize().getWidth();  
                 h1 = (int) tfPort.getMinimumSize().getHeight();  
                 d = new Dimension(w1 > 150 ? w1 : 150, h1);  
                 tfPort.setMinimumSize(d);  
                 tfPort.setPreferredSize(d);  
           
                 c.fill = GridBagConstraints.NONE;  
           
                 c.gridx = 0;  
                 c.gridy = 0;  
                 c.anchor = GridBagConstraints.EAST;  
                 c.insets = new Insets(3, 3, 3, 3);  
                 gridbag.setConstraints(lAddress, c);  
                 add(lAddress);  
   
                 c.gridx = 0;  
                 c.gridy = 1;  
                 gridbag.setConstraints(lPort, c);  
                 add(lPort);  
           
                 c.fill = GridBagConstraints.HORIZONTAL;  
                 c.gridx = 1;  
                 c.gridy = 0;  
                 c.weightx = 1.0;  
                 c.anchor = GridBagConstraints.WEST;  
                 gridbag.setConstraints(tfAddress, c);  
                 add(tfAddress);  
                   
                 c.gridx = 1;  
                 c.gridy = 1;  
                 gridbag.setConstraints(tfPort, c);  
                 add(tfPort);  
                   
                 setBorder(BorderFactory.createTitledBorder(i18n.getLabel("LSPrefsPane")));  
                 setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height));  
         }  
           
         public String  
         getLSAddress() { return tfAddress.getText(); }  
           
         public void  
         setLSAddress(String address) { tfAddress.setText(address); }  
           
         public String  
         getLSPort() { return tfPort.getText(); }  
           
         public void  
         setLSPort(String port) { tfPort.setText(port); }  
621  }  }

Legend:
Removed from v.1284  
changed lines
  Added in v.1285

  ViewVC Help
Powered by ViewVC