--- jsampler/trunk/src/org/jsampler/view/classic/PrefsDlg.java 2005/10/10 16:03:12 787 +++ jsampler/trunk/src/org/jsampler/view/classic/PrefsDlg.java 2006/03/16 18:08:34 842 @@ -22,7 +22,11 @@ package org.jsampler.view.classic; +import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Container; +import java.awt.Cursor; +import java.awt.Dialog; import java.awt.Dimension; import java.awt.GraphicsEnvironment; import java.awt.Font; @@ -33,13 +37,21 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.Locale; +import java.util.Vector; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.DefaultButtonModel; import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JColorChooser; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -48,14 +60,22 @@ import javax.swing.JTabbedPane; import javax.swing.JTextField; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + import net.sf.juife.EnhancedDialog; import net.sf.juife.JuifeUtils; +import net.sf.juife.LinkButton; +import net.sf.juife.OkCancelDialog; +import org.jsampler.CC; import org.jsampler.HF; import org.jsampler.JSI18n; import org.jsampler.JSampler; import org.jsampler.Prefs; +import org.jsampler.task.SetServerAddress; + import static org.jsampler.view.classic.ClassicI18n.i18n; @@ -143,40 +163,21 @@ private void onApply() { - // GENERAL - boolean b = Prefs.setInterfaceLanguage(viewPane.getInterfaceLanguage()); - 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); - } + genPane.apply(); + viewPane.apply(); // CONNECTION Prefs.setLSAddress(getLSAddress()); - b = true; + boolean b = true; String s = getLSPort(); try { if(s.length() > 0) { int port = Integer.parseInt(s); if(port > 0 && port < 0xffff) - Prefs.setAuthSrvPort(port); + Prefs.setLSPort(port); else b = false; - } else Prefs.setAuthSrvPort(-1); // -1 resets to default value + } else Prefs.setLSPort(-1); // -1 resets to default value } catch(NumberFormatException x) { b = false; } @@ -192,6 +193,12 @@ return; } + //CC.getClient().setServerAddress(Prefs.getLSAddress()); + //CC.getClient().setServerPort(Prefs.getLSPort()); + CC.getTaskQueue().add ( + new SetServerAddress(Prefs.getLSAddress(), Prefs.getLSPort()) + ); + setVisible(false); } @@ -212,12 +219,33 @@ } class GeneralPane extends JPanel { + private final JCheckBox checkWindowSizeAndLocation = + new JCheckBox(i18n.getLabel("GeneralPane.checkWindowSizeAndLocation")); + public GeneralPane() { initGeneralPane(); } private void initGeneralPane() { + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + add(checkWindowSizeAndLocation); + + checkWindowSizeAndLocation.setSelected(Prefs.getSaveWindowProperties()); + checkWindowSizeAndLocation.addItemListener(new ItemListener() { + public void + itemStateChanged(ItemEvent e) { + boolean b = e.getStateChange() == e.SELECTED; + checkWindowSizeAndLocation.setEnabled(b); + } + }); + + + } + + protected void + apply() { + Prefs.setSaveWindowProperties(checkWindowSizeAndLocation.isSelected()); } } @@ -230,6 +258,10 @@ new JLabel(i18n.getLabel("ViewPane.lIfaceFont")); private final JComboBox cbIfaceFont = new JComboBox(); + private final JCheckBox checkBorderColor = + new JCheckBox(i18n.getLabel("ViewPane.channelBorderColor")); + private final ColorButton btnBorderColor = new ColorButton(Color.WHITE); + public ViewPane() { initViewPane(); } @@ -280,26 +312,134 @@ fontPane.add(cbIfaceFont); add(fontPane); + add(Box.createRigidArea(new Dimension(0, 6))); + add(createCustomColorsPane()); + setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); } - protected String + private JPanel + createCustomColorsPane() { + JPanel ccp = new JPanel(); + ccp.setAlignmentX(CENTER_ALIGNMENT); + ccp.setLayout(new BoxLayout(ccp, BoxLayout.Y_AXIS)); + + JPanel p = new JPanel(); + p.setAlignmentX(LEFT_ALIGNMENT); + p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); + p.add(checkBorderColor); + + p.add(Box.createRigidArea(new Dimension(6, 0))); + + btnBorderColor.setColor(ClassicPrefs.getChannelBorderColor()); + btnBorderColor.setEnabled(ClassicPrefs.getCustomChannelBorderColor()); + p.add(btnBorderColor); + + checkBorderColor.setSelected(ClassicPrefs.getCustomChannelBorderColor()); + + checkBorderColor.addItemListener(new ItemListener() { + public void + itemStateChanged(ItemEvent e) { + boolean b = e.getStateChange() == e.SELECTED; + btnBorderColor.setEnabled(b); + } + }); + + /*btnBorderColor.addActionListener(new ActionListener() { + public void + actionPerformed(ActionEvent e) { + ClassicPrefs.setChannelBorderColor(btnBorderColor.getColor()); + } + });*/ + + ccp.add(p); + + JButton btnDefaults = new JButton("Reset to defaults"); + btnDefaults.addActionListener(new ActionListener() { + public void + actionPerformed(ActionEvent e) { + ClassicPrefs.setChannelBorderColor(null); + btnBorderColor.setColor(ClassicPrefs.getChannelBorderColor()); + } + }); + + 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()); + + ccp.add(p); + + ccp.setBorder ( + BorderFactory.createTitledBorder(i18n.getLabel("ViewPane.CustomColorsPane")) + ); + + ccp.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); + + return ccp; + } + + private String getInterfaceLanguage() { LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem(); if(box == null) return null; return box.getLocale().getLanguage(); } - protected String + private String getInterfaceCountry() { LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem(); if(box == null) return null; return box.getLocale().getCountry(); } - protected String + private String getInterfaceFontName() { return cbIfaceFont.getSelectedItem().toString(); } + protected void + apply() { + boolean b = Prefs.setInterfaceLanguage(getInterfaceLanguage()); + boolean b2 = Prefs.setInterfaceCountry(getInterfaceCountry()); + if (b || b2) JOptionPane.showMessageDialog ( + this, + i18n.getMessage("PrefsDlg.ifaceChangeInfo", "JS Classic"), + null, + JOptionPane.INFORMATION_MESSAGE + ); + + b = false; + String fontName = getInterfaceFontName(); + if(fontName.equals("[Default]")) { + b = Prefs.setInterfaceFont(null); + } else if(Prefs.setInterfaceFont(fontName)) { + HF.setUIDefaultFont(fontName); + b = true; + } + + if(b) JOptionPane.showMessageDialog ( + this, + i18n.getMessage("PrefsDlg.ifaceFontChangeInfo", "JS Classic"), + null, + JOptionPane.INFORMATION_MESSAGE + ); + + ///***/// + + b = checkBorderColor.isSelected(); + ClassicPrefs.setCustomChannelBorderColor(b); + if(b) ClassicPrefs.setChannelBorderColor(btnBorderColor.getColor()); + + Color c; + if(b) c = ClassicPrefs.getChannelBorderColor(); + else c = ClassicPrefs.getDefaultChannelBorderColor(); + Channel.setBorderColor(c); + } + class LocaleBox { private Locale locale; @@ -311,6 +451,122 @@ public String toString() { return locale.getDisplayLanguage(JSI18n.i18n.getCurrentLocale()); } } + + private class ColorButton extends JPanel { + private Color color; + private final Vector listeners = new Vector(); + + 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 ActionListener to register. + */ + public void + addActionListener(ActionListener l) { listeners.add(l); } + + /** + * Removes the specified listener. + * @param l The ActionListener 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(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); + } + } + + private class ColorDlg extends OkCancelDialog { + private final JColorChooser colorChooser = new JColorChooser(); + + ColorDlg() { this(Color.WHITE); } + + ColorDlg(Color c) { + super((Dialog)JuifeUtils.getWindow(ViewPane.this)); + + 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(); } + } } class ConnectionPane extends JPanel { @@ -399,6 +655,7 @@ add(tfPort); setBorder(BorderFactory.createTitledBorder(i18n.getLabel("LSPrefsPane"))); + setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); } public String