/[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 841 by iliev, Mon Oct 10 16:03:12 2005 UTC revision 842 by iliev, Thu Mar 16 18:08:34 2006 UTC
# Line 22  Line 22 
22    
23  package org.jsampler.view.classic;  package org.jsampler.view.classic;
24    
25    import java.awt.BorderLayout;
26    import java.awt.Color;
27  import java.awt.Container;  import java.awt.Container;
28    import java.awt.Cursor;
29    import java.awt.Dialog;
30  import java.awt.Dimension;  import java.awt.Dimension;
31  import java.awt.GraphicsEnvironment;  import java.awt.GraphicsEnvironment;
32  import java.awt.Font;  import java.awt.Font;
# Line 33  import java.awt.Insets; Line 37  import java.awt.Insets;
37    
38  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
39  import java.awt.event.ActionListener;  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;  import java.util.Locale;
46    import java.util.Vector;
47    
48  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
49  import javax.swing.Box;  import javax.swing.Box;
50  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
51    import javax.swing.DefaultButtonModel;
52  import javax.swing.JButton;  import javax.swing.JButton;
53    import javax.swing.JCheckBox;
54    import javax.swing.JColorChooser;
55  import javax.swing.JComboBox;  import javax.swing.JComboBox;
56  import javax.swing.JLabel;  import javax.swing.JLabel;
57  import javax.swing.JOptionPane;  import javax.swing.JOptionPane;
# Line 48  import javax.swing.JPasswordField; Line 60  import javax.swing.JPasswordField;
60  import javax.swing.JTabbedPane;  import javax.swing.JTabbedPane;
61  import javax.swing.JTextField;  import javax.swing.JTextField;
62    
63    import javax.swing.event.ChangeEvent;
64    import javax.swing.event.ChangeListener;
65    
66  import net.sf.juife.EnhancedDialog;  import net.sf.juife.EnhancedDialog;
67  import net.sf.juife.JuifeUtils;  import net.sf.juife.JuifeUtils;
68    import net.sf.juife.LinkButton;
69    import net.sf.juife.OkCancelDialog;
70    
71    import org.jsampler.CC;
72  import org.jsampler.HF;  import org.jsampler.HF;
73  import org.jsampler.JSI18n;  import org.jsampler.JSI18n;
74  import org.jsampler.JSampler;  import org.jsampler.JSampler;
75  import org.jsampler.Prefs;  import org.jsampler.Prefs;
76    
77    import org.jsampler.task.SetServerAddress;
78    
79  import static org.jsampler.view.classic.ClassicI18n.i18n;  import static org.jsampler.view.classic.ClassicI18n.i18n;
80    
81    
# Line 143  public class PrefsDlg extends EnhancedDi Line 163  public class PrefsDlg extends EnhancedDi
163                    
164          private void          private void
165          onApply() {          onApply() {
166                  // GENERAL                  genPane.apply();
167                  boolean b = Prefs.setInterfaceLanguage(viewPane.getInterfaceLanguage());                  viewPane.apply();
                 boolean b2 = Prefs.setInterfaceCountry(viewPane.getInterfaceCountry());  
                 if (b || b2) JOptionPane.showMessageDialog (  
                         this,  
                         i18n.getMessage("PrefsDlg.ifaceChangeInfo", JSampler.NAME),  
                         null,  
                         JOptionPane.INFORMATION_MESSAGE  
                 );  
                   
                 String fontName = viewPane.getInterfaceFontName();  
                 if(fontName.equals("[Default]")) {  
                         if(Prefs.setInterfaceFont(null)) JOptionPane.showMessageDialog (  
                                 this,  
                                 i18n.getMessage("PrefsDlg.ifaceFontChangeInfo", JSampler.NAME),  
                                 null,  
                                 JOptionPane.INFORMATION_MESSAGE  
                         );  
                 } else if(Prefs.setInterfaceFont(fontName)) {  
                         HF.setUIDefaultFont(fontName);  
                 }  
168                                    
169                  // CONNECTION                  // CONNECTION
170                  Prefs.setLSAddress(getLSAddress());                  Prefs.setLSAddress(getLSAddress());
171                                    
172                  b = true;                  boolean b = true;
173                  String s = getLSPort();                  String s = getLSPort();
174                  try {                  try {
175                          if(s.length() > 0) {                          if(s.length() > 0) {
176                                  int port = Integer.parseInt(s);                                  int port = Integer.parseInt(s);
177                                  if(port > 0 && port < 0xffff)                                  if(port > 0 && port < 0xffff)
178                                          Prefs.setAuthSrvPort(port);                                          Prefs.setLSPort(port);
179                                  else b = false;                                  else b = false;
180                          } else Prefs.setAuthSrvPort(-1);        // -1 resets to default value                          } else Prefs.setLSPort(-1);     // -1 resets to default value
181                  } catch(NumberFormatException x) {                  } catch(NumberFormatException x) {
182                          b = false;                          b = false;
183                  }                  }
# Line 192  public class PrefsDlg extends EnhancedDi Line 193  public class PrefsDlg extends EnhancedDi
193                          return;                          return;
194                  }                  }
195                                    
196                    //CC.getClient().setServerAddress(Prefs.getLSAddress());
197                    //CC.getClient().setServerPort(Prefs.getLSPort());
198                    CC.getTaskQueue().add (
199                            new SetServerAddress(Prefs.getLSAddress(), Prefs.getLSPort())
200                    );
201                    
202                  setVisible(false);                  setVisible(false);
203          }          }
204                    
# Line 212  public class PrefsDlg extends EnhancedDi Line 219  public class PrefsDlg extends EnhancedDi
219  }  }
220    
221  class GeneralPane extends JPanel {  class GeneralPane extends JPanel {
222            private final JCheckBox checkWindowSizeAndLocation =
223                    new JCheckBox(i18n.getLabel("GeneralPane.checkWindowSizeAndLocation"));
224            
225          public          public
226          GeneralPane() { initGeneralPane(); }          GeneralPane() { initGeneralPane(); }
227                    
228          private void          private void
229          initGeneralPane() {          initGeneralPane() {
230                    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
231                    add(checkWindowSizeAndLocation);
232                    
233                    checkWindowSizeAndLocation.setSelected(Prefs.getSaveWindowProperties());
234                                    
235                    checkWindowSizeAndLocation.addItemListener(new ItemListener() {
236                            public void
237                            itemStateChanged(ItemEvent e) {
238                                    boolean b = e.getStateChange() == e.SELECTED;
239                                    checkWindowSizeAndLocation.setEnabled(b);
240                            }
241                    });
242                    
243                    
244            }
245            
246            protected void
247            apply() {
248                    Prefs.setSaveWindowProperties(checkWindowSizeAndLocation.isSelected());
249          }          }
250  }  }
251    
# Line 230  class ViewPane extends JPanel { Line 258  class ViewPane extends JPanel {
258                  new JLabel(i18n.getLabel("ViewPane.lIfaceFont"));                  new JLabel(i18n.getLabel("ViewPane.lIfaceFont"));
259          private final JComboBox cbIfaceFont = new JComboBox();          private final JComboBox cbIfaceFont = new JComboBox();
260                    
261            private final JCheckBox checkBorderColor =
262                    new JCheckBox(i18n.getLabel("ViewPane.channelBorderColor"));
263            private final ColorButton btnBorderColor = new ColorButton(Color.WHITE);
264            
265          public          public
266          ViewPane() { initViewPane(); }          ViewPane() { initViewPane(); }
267                    
# Line 280  class ViewPane extends JPanel { Line 312  class ViewPane extends JPanel {
312                  fontPane.add(cbIfaceFont);                  fontPane.add(cbIfaceFont);
313                                    
314                  add(fontPane);                  add(fontPane);
315                    add(Box.createRigidArea(new Dimension(0, 6)));
316                    add(createCustomColorsPane());
317                    
318                  setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));                  setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
319          }          }
320                    
321          protected String          private JPanel
322            createCustomColorsPane() {
323                    JPanel ccp = new JPanel();
324                    ccp.setAlignmentX(CENTER_ALIGNMENT);
325                    ccp.setLayout(new BoxLayout(ccp, BoxLayout.Y_AXIS));
326                    
327                    JPanel p = new JPanel();
328                    p.setAlignmentX(LEFT_ALIGNMENT);
329                    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
330                    p.add(checkBorderColor);
331                    
332                    p.add(Box.createRigidArea(new Dimension(6, 0)));
333                    
334                    btnBorderColor.setColor(ClassicPrefs.getChannelBorderColor());
335                    btnBorderColor.setEnabled(ClassicPrefs.getCustomChannelBorderColor());
336                    p.add(btnBorderColor);
337                    
338                    checkBorderColor.setSelected(ClassicPrefs.getCustomChannelBorderColor());
339                    
340                    checkBorderColor.addItemListener(new ItemListener() {
341                            public void
342                            itemStateChanged(ItemEvent e) {
343                                    boolean b = e.getStateChange() == e.SELECTED;
344                                    btnBorderColor.setEnabled(b);
345                            }
346                    });
347                    
348                    /*btnBorderColor.addActionListener(new ActionListener() {
349                            public void
350                            actionPerformed(ActionEvent e) {
351                                    ClassicPrefs.setChannelBorderColor(btnBorderColor.getColor());
352                            }
353                    });*/
354                    
355                    ccp.add(p);
356                    
357                    JButton btnDefaults = new JButton("Reset to defaults");
358                    btnDefaults.addActionListener(new ActionListener() {
359                            public void
360                            actionPerformed(ActionEvent e) {
361                                    ClassicPrefs.setChannelBorderColor(null);
362                                    btnBorderColor.setColor(ClassicPrefs.getChannelBorderColor());
363                            }
364                    });
365                    
366                    p = new JPanel();
367                    p.setAlignmentX(LEFT_ALIGNMENT);
368                    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
369                    p.setBorder(BorderFactory.createEmptyBorder(6, 0, 6, 6));
370                    p.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
371                    
372                    p.add(Box.createGlue());
373                    p.add(btnDefaults);
374                    p.add(Box.createGlue());
375                    
376                    ccp.add(p);
377                    
378                    ccp.setBorder (
379                            BorderFactory.createTitledBorder(i18n.getLabel("ViewPane.CustomColorsPane"))
380                    );
381                    
382                    ccp.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
383                    
384                    return ccp;
385            }
386            
387            private String
388          getInterfaceLanguage() {          getInterfaceLanguage() {
389                  LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem();                  LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem();
390                  if(box == null) return null;                  if(box == null) return null;
391                  return box.getLocale().getLanguage();                  return box.getLocale().getLanguage();
392          }          }
393                    
394          protected String          private String
395          getInterfaceCountry() {          getInterfaceCountry() {
396                  LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem();                  LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem();
397                  if(box == null) return null;                  if(box == null) return null;
398                  return box.getLocale().getCountry();                  return box.getLocale().getCountry();
399          }          }
400                    
401          protected String          private String
402          getInterfaceFontName() { return cbIfaceFont.getSelectedItem().toString(); }          getInterfaceFontName() { return cbIfaceFont.getSelectedItem().toString(); }
403                    
404            protected void
405            apply() {
406                    boolean b = Prefs.setInterfaceLanguage(getInterfaceLanguage());
407                    boolean b2 = Prefs.setInterfaceCountry(getInterfaceCountry());
408                    if (b || b2) JOptionPane.showMessageDialog (
409                            this,
410                            i18n.getMessage("PrefsDlg.ifaceChangeInfo", "JS Classic"),
411                            null,
412                            JOptionPane.INFORMATION_MESSAGE
413                    );
414                    
415                    b = false;
416                    String fontName = getInterfaceFontName();
417                    if(fontName.equals("[Default]")) {
418                            b = Prefs.setInterfaceFont(null);
419                    } else if(Prefs.setInterfaceFont(fontName)) {
420                            HF.setUIDefaultFont(fontName);
421                            b = true;
422                    }
423                    
424                    if(b) JOptionPane.showMessageDialog (
425                            this,
426                            i18n.getMessage("PrefsDlg.ifaceFontChangeInfo", "JS Classic"),
427                            null,
428                            JOptionPane.INFORMATION_MESSAGE
429                    );
430                    
431                    ///***///
432                    
433                    b = checkBorderColor.isSelected();
434                    ClassicPrefs.setCustomChannelBorderColor(b);
435                    if(b) ClassicPrefs.setChannelBorderColor(btnBorderColor.getColor());
436                    
437                    Color c;
438                    if(b) c = ClassicPrefs.getChannelBorderColor();
439                    else c = ClassicPrefs.getDefaultChannelBorderColor();
440                    Channel.setBorderColor(c);
441            }
442            
443          class LocaleBox {          class LocaleBox {
444                  private Locale locale;                  private Locale locale;
445                                    
# Line 311  class ViewPane extends JPanel { Line 451  class ViewPane extends JPanel {
451                  public String                  public String
452                  toString() { return locale.getDisplayLanguage(JSI18n.i18n.getCurrentLocale()); }                  toString() { return locale.getDisplayLanguage(JSI18n.i18n.getCurrentLocale()); }
453          }          }
454            
455            private class ColorButton extends JPanel {
456                    private Color color;
457                    private final Vector<ActionListener> listeners = new Vector<ActionListener>();
458                    
459                    ColorButton(Color c) {
460                            color = c;
461                            
462                            //setBorderPainted(false);
463                            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
464                            setPreferredSize(new Dimension(42, 16));
465                            setMaximumSize(new Dimension(42, 16));
466                            setBorder(BorderFactory.createLineBorder(Color.BLACK));
467                            
468                            addMouseListener(new MouseAdapter() {
469                                    public void
470                                    mouseClicked(MouseEvent e) {
471                                            if(!isEnabled()) return;
472                                            if(e.getButton() == e.BUTTON1) showColorChooser();
473                                    }
474                            });
475                    }
476                    
477                    /**
478                     * Registers the specified listener to be
479                     * notified when the current color is changed.
480                     * @param l The <code>ActionListener</code> to register.
481                     */
482                    public void
483                    addActionListener(ActionListener l) { listeners.add(l); }
484            
485                    /**
486                     * Removes the specified listener.
487                     * @param l The <code>ActionListener</code> to remove.
488                     */
489                    public void
490                    removeActionListener(ActionListener l) { listeners.remove(l); }
491                    
492                    /** Notifies listeners that the current color is changed. */
493                    private void
494                    fireActionPerformed() {
495                            ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null);
496                            for(ActionListener l : listeners) l.actionPerformed(e);
497                    }
498            
499                    public void
500                    setEnabled(boolean b) {
501                            setOpaque(b);
502                            if(b) setBorder(BorderFactory.createLineBorder(Color.BLACK));
503                            else setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
504                            //setBorderPainted(!b);
505                            super.setEnabled(b);
506                    }
507                    
508                    private void
509                    showColorChooser() {
510                            ColorDlg dlg = new ColorDlg(getColor());
511                            dlg.setVisible(true);
512                            if(!dlg.isCancelled()) {
513                                    setColor(dlg.getColor());
514                                    fireActionPerformed();
515                            }
516                    }
517                    
518                    public Color
519                    getColor() { return color; }
520                    
521                    public void
522                    setColor(Color c) {
523                            color = c;
524                            setBackground(color);
525                    }
526            }
527            
528            private class ColorDlg extends OkCancelDialog {
529                    private final JColorChooser colorChooser = new JColorChooser();
530                    
531                    ColorDlg() { this(Color.WHITE); }
532                    
533                    ColorDlg(Color c) {
534                            super((Dialog)JuifeUtils.getWindow(ViewPane.this));
535                            
536                            colorChooser.setPreviewPanel(new JPanel());
537                            colorChooser.setColor(c);
538                            
539                            JPanel mainPane = new JPanel();
540                            mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
541                            mainPane.add(colorChooser);
542                            
543                            mainPane.add(Box.createRigidArea(new Dimension(0, 6)));
544                            
545                            final JPanel p = new JPanel();
546                            p.setBackground(c);
547                            p.setBorder(BorderFactory.createLineBorder(Color.BLACK));
548                            mainPane.add(p);
549                            
550                            p.setPreferredSize(new Dimension(48, 8));
551                            p.setMaximumSize(new Dimension(Short.MAX_VALUE, 8));
552                            
553                            setMainPane(mainPane);
554                            
555                            colorChooser.getSelectionModel().addChangeListener(new ChangeListener() {
556                                    public void
557                                    stateChanged(ChangeEvent e) { p.setBackground(getColor()); }
558                            });
559                    }
560                    
561                    protected void
562                    onOk() { setVisible(false); }
563                    
564                    protected void
565                    onCancel() { setVisible(false); }
566                    
567                    public Color
568                    getColor() { return colorChooser.getColor(); }
569            }
570  }  }
571    
572  class ConnectionPane extends JPanel {  class ConnectionPane extends JPanel {
# Line 399  class LSPrefsPane extends JPanel { Line 655  class LSPrefsPane extends JPanel {
655                  add(tfPort);                  add(tfPort);
656                                    
657                  setBorder(BorderFactory.createTitledBorder(i18n.getLabel("LSPrefsPane")));                  setBorder(BorderFactory.createTitledBorder(i18n.getLabel("LSPrefsPane")));
658                    setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height));
659          }          }
660                    
661          public String          public String

Legend:
Removed from v.841  
changed lines
  Added in v.842

  ViewVC Help
Powered by ViewVC