зеркало из https://github.com/mozilla/gecko-dev.git
Preference dialog shows up and even saves the info back.
This commit is contained in:
Родитель
2d011004df
Коммит
f5fb036888
|
@ -195,9 +195,13 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
c.addPropertyChangeListener(ca);
|
||||
|
||||
c = fPanel.getCtrlByName(kHostListKey);
|
||||
((JList) c).setModel(fHostListModel);
|
||||
c.addPropertyChangeListener(new ListListener());
|
||||
((JList)c).setModel(fHostListModel);
|
||||
((JList)c).addListSelectionListener(new ListListener());
|
||||
|
||||
c = fPanel.getCtrlByName(kEditKey);
|
||||
c.setEnabled(false);
|
||||
c = fPanel.getCtrlByName(kDeleteKey);
|
||||
c.setEnabled(false);
|
||||
}
|
||||
|
||||
public String getAsText() {
|
||||
|
@ -267,11 +271,14 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
fListeners.removePropertyChangeListener(l);
|
||||
}
|
||||
|
||||
class ListListener implements PropertyChangeListener {
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
class ListListener
|
||||
implements ListSelectionListener {
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
System.out.println("foo");
|
||||
JComponent c;
|
||||
c = (JComponent)e.getSource();
|
||||
boolean enabled = (((JList)c).getSelectedValue() != null);
|
||||
boolean enabled = !(((JList)c).isSelectionEmpty());
|
||||
System.out.println(((JList)c).getSelectedValue());
|
||||
|
||||
c = fPanel.getCtrlByName(kDeleteKey);
|
||||
c.setEnabled(enabled);
|
||||
|
@ -324,20 +331,15 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
|
||||
public void add(URLName aURLName) {
|
||||
fEditableStores.addElement(aURLName);
|
||||
|
||||
fireIntervalAdded(this, fEditableStores.size() - 1,
|
||||
fEditableStores.size() - 1);
|
||||
|
||||
//fScrollPane.validate();
|
||||
}
|
||||
|
||||
public void remove(URLName aURLName) {
|
||||
int idx = fEditableStores.indexOf(aURLName);
|
||||
if (idx != -1) {
|
||||
fEditableStores.removeElementAt(idx);
|
||||
|
||||
fireIntervalRemoved(this, idx, idx);
|
||||
//fScrollPane.validate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,12 +361,4 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
event(aEvent);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
javax.swing.JFrame frame = new javax.swing.JFrame("Foo bar");
|
||||
MailServerPrefsEditor ui = new MailServerPrefsEditor();
|
||||
frame.getContentPane().add(ui.fPanel);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,6 @@ public class Prefs {
|
|||
|
||||
public UserPrefs getUserPrefs() {
|
||||
UserPrefs res = new UserPrefs();
|
||||
|
||||
res.setUserName(fPrefs.getString(kUserName, "John Doe"));
|
||||
res.setUserEmailAddress(fPrefs.getString(kEmailAddress, "john@doe.com"));
|
||||
res.setUserOrganization(fPrefs.getString(kOrganization, ""));
|
||||
|
@ -151,4 +150,14 @@ public class Prefs {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void set(Object obj) {
|
||||
if (obj instanceof UserPrefs) {
|
||||
setUserPrefs((UserPrefs)obj);
|
||||
} else if (obj instanceof UIPrefs) {
|
||||
setUIPrefs((UIPrefs)obj);
|
||||
} else if (obj instanceof MailServerPrefs) {
|
||||
setMailServerPrefs((MailServerPrefs)obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,8 +110,28 @@ public class UIPrefsEditor extends JPanel
|
|||
public Object getValue() {
|
||||
fPanel.saveAll();
|
||||
|
||||
// AbstractCtrl c = fPanel.getCtrlByName(kLAFKey);
|
||||
// fPrefs.setLAF((LookAndFeel) c.getValue());
|
||||
JList l = (JList)fPanel.getCtrlByName(kLAFKey);
|
||||
String str = (String)l.getSelectedValue();
|
||||
|
||||
// sigh. we now search for the LAF
|
||||
UIManager.LookAndFeelInfo[] info =
|
||||
UIManager.getInstalledLookAndFeels();
|
||||
LookAndFeel lf = null;
|
||||
|
||||
for (int i = 0; i < info.length; i++) {
|
||||
try {
|
||||
String cn = info[i].getClassName();
|
||||
Class c = Class.forName(cn);
|
||||
LookAndFeel current = (LookAndFeel)c.newInstance();
|
||||
if (current.getDescription().equals(str)) {
|
||||
lf = current;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (lf != null) { // fPrefs.setLAF((LookAndFeel) c.getValue());
|
||||
fPrefs.setLAF(lf);
|
||||
}
|
||||
|
||||
return fPrefs;
|
||||
}
|
||||
|
@ -131,8 +151,8 @@ public class UIPrefsEditor extends JPanel
|
|||
UIPrefs oldPrefs = fPrefs;
|
||||
fPrefs = (UIPrefs) aValue;
|
||||
|
||||
// AbstractCtrl c = fPanel.getCtrlByName(kLAFKey);
|
||||
// c.setValue(fPrefs.getLAF());
|
||||
JList l = (JList)fPanel.getCtrlByName(kLAFKey);
|
||||
l.setSelectedValue(fPrefs.getLAF().getDescription(), true);
|
||||
|
||||
fListeners.firePropertyChange(null, oldPrefs, fPrefs);
|
||||
}
|
||||
|
@ -157,7 +177,6 @@ public class UIPrefsEditor extends JPanel
|
|||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent aEvent) {
|
||||
System.out.println("propertyChange" + aEvent);
|
||||
event(aEvent);
|
||||
}
|
||||
}
|
||||
|
@ -166,14 +185,17 @@ public class UIPrefsEditor extends JPanel
|
|||
LookAndFeel fLAFs[] = null;
|
||||
|
||||
LAFListModel() {
|
||||
/* Hack until this works
|
||||
fLAFs = UIManager.getAuxiliaryLookAndFeels();
|
||||
*/
|
||||
fLAFs = new LookAndFeel[] {
|
||||
new javax.swing.plaf.metal.MetalLookAndFeel(),
|
||||
// new javax.swing.plaf.motif.MotifLookAndFeel(),
|
||||
// new javax.swing.windows.WindowsLookAndFeel()
|
||||
};
|
||||
UIManager.LookAndFeelInfo[] info =
|
||||
UIManager.getInstalledLookAndFeels();
|
||||
fLAFs = new LookAndFeel[info.length];
|
||||
for (int i = 0; i < info.length; i++) {
|
||||
try {
|
||||
String name = info[i].getClassName();
|
||||
Class c = Class.forName(name);
|
||||
fLAFs[i] = (LookAndFeel)c.newInstance();
|
||||
} catch (Exception e){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
|
@ -185,7 +207,9 @@ public class UIPrefsEditor extends JPanel
|
|||
|
||||
public Object getElementAt(int index) {
|
||||
if (fLAFs != null && index < fLAFs.length) {
|
||||
return fLAFs[index];
|
||||
// this is a hack. the toString() returns a string which is
|
||||
// best described as "unwieldly"
|
||||
return fLAFs[index].getDescription();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ class PreferencesAction extends UIAction {
|
|||
public void run() {
|
||||
synchronized(fThis) {
|
||||
setEnabled(false);
|
||||
PrefsDialog.EditPrefs(fFrame);
|
||||
new PrefsDialog(fFrame);
|
||||
setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@ public class EditHostDialog extends GeneralDialog {
|
|||
JOptionPane.OK_CANCEL_OPTION);
|
||||
actionPanel.addPropertyChangeListener(new OptionListener());
|
||||
getContentPane().add(actionPanel);
|
||||
fPanel.initAll();
|
||||
|
||||
// XXX This is a stupid hack because PageUI doesn't to a resource lookup
|
||||
// on it's title. Bleh.
|
||||
|
|
|
@ -42,94 +42,88 @@ import javax.swing.JPanel;
|
|||
import calypso.util.Preferences;
|
||||
import calypso.util.PreferencesFactory;
|
||||
|
||||
//import netscape.orion.propeditor.PropertyEditorDlg;
|
||||
|
||||
import grendel.prefs.Prefs;
|
||||
|
||||
public class PrefsDialog {
|
||||
// XXX do we really need these here? they sort of break abstraction
|
||||
static String sPrefNames[] = {"mail.email_address",
|
||||
"mail.host",
|
||||
"mail.user",
|
||||
"mail.directory",
|
||||
"smtp.host"};
|
||||
/**
|
||||
* This class handles preference dialog box handling for Grendel. Why
|
||||
* was all this stuff static?
|
||||
*/
|
||||
public class PrefsDialog
|
||||
extends JDialog {
|
||||
public static String OK = "Okay";
|
||||
public static String CANCEL = "Cancel";
|
||||
JTabbedPane pane;
|
||||
PropertyEditor[] editors;
|
||||
|
||||
public static void CheckPrefs(JFrame aParent) {
|
||||
if (!ValidPrefs()) {
|
||||
EditPrefs(aParent);
|
||||
new PrefsDialog(aParent);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EditPrefs(JFrame aParent) {
|
||||
public PrefsDialog(JFrame aParent) {
|
||||
Object objs[] = {new Prefs()};
|
||||
// PropertyEditorDlg.Edit(aParent, objs, false, true, "",
|
||||
// PropertyEditorDlg.UI_TREE);
|
||||
// JOptionPane.showMessageDialog(aParent, "This part of the UI is\nstill being worked on.", "Under Construction", JOptionPane.INFORMATION_MESSAGE);
|
||||
propertyEditorDialog(aParent, new Prefs(), false);
|
||||
propertyEditorDialog(aParent, new Prefs());
|
||||
}
|
||||
|
||||
public static boolean ValidPrefs() {
|
||||
Preferences prefs = PreferencesFactory.Get();
|
||||
|
||||
boolean res = true;
|
||||
/*
|
||||
for (int i = 0; i < sPrefNames.length; i++) {
|
||||
res &= !prefs.getString(sPrefNames[i], "").equals("");
|
||||
}
|
||||
*/
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private static void propertyEditorDialog(JFrame parent, Object obj,
|
||||
boolean modal) {
|
||||
private void propertyEditorDialog(JFrame parent, Object obj) {
|
||||
Class reference = obj.getClass();
|
||||
String name = reference.getName();
|
||||
Class beanie = null;
|
||||
SimpleBeanInfo info;
|
||||
Object o;
|
||||
JDialog dialog = new JDialog(parent, modal);
|
||||
JTabbedPane pane = new JTabbedPane();
|
||||
Container content = dialog.getContentPane();
|
||||
String[] labels = {"Okay", "Cancel"};
|
||||
Container content = getContentPane();
|
||||
String[] labels = {OK, CANCEL};
|
||||
pane = new JTabbedPane();
|
||||
|
||||
// gui handling
|
||||
content.setLayout(new BorderLayout());
|
||||
content.add(pane, BorderLayout.CENTER);
|
||||
content.add(buttonPanel(labels,
|
||||
new DialogListener(dialog)),
|
||||
new PrefsDialogListener()),
|
||||
BorderLayout.SOUTH);
|
||||
|
||||
try {
|
||||
// get the beaninfo
|
||||
beanie = Class.forName(name + "BeanInfo");
|
||||
Object o;
|
||||
SimpleBeanInfo info;
|
||||
Class beanie = Class.forName(name + "BeanInfo");
|
||||
PropertyDescriptor[] desc;
|
||||
o = beanie.newInstance();
|
||||
if (!(o instanceof SimpleBeanInfo)) return; // bummer
|
||||
|
||||
// process the descriptors
|
||||
PropertyDescriptor[] desc;
|
||||
info = (SimpleBeanInfo)o;
|
||||
desc = info.getPropertyDescriptors();
|
||||
editors = new PropertyEditor[desc.length];
|
||||
|
||||
for (int i = 0; i < desc.length; i++) {
|
||||
o = desc[i].getPropertyEditorClass().newInstance();
|
||||
if (!(o instanceof PropertyEditor)) continue;
|
||||
PropertyEditor editor = (PropertyEditor)o;
|
||||
pane.add(desc[i].getDisplayName(), editor.getCustomEditor());
|
||||
editors[i] = (PropertyEditor)o;
|
||||
pane.add(desc[i].getDisplayName(), editors[i].getCustomEditor());
|
||||
}
|
||||
dialog.pack();
|
||||
dialog.setVisible(true);
|
||||
pack();
|
||||
setVisible(true);
|
||||
} catch (Exception e) {
|
||||
System.out.println("welp, that sucked. beans is broke. And stuff");
|
||||
}
|
||||
}
|
||||
|
||||
public static JPanel buttonPanel(String[] labels,
|
||||
ActionListener listener) {
|
||||
private JPanel buttonPanel(String[] labels,
|
||||
ActionListener listener) {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new FlowLayout());
|
||||
|
||||
if (labels != null) {
|
||||
for (int i = 0; i < labels.length; i++) {
|
||||
JButton button = new JButton(labels[i]);
|
||||
button.setActionCommand(labels[i]);
|
||||
if (listener != null) button.addActionListener(listener);
|
||||
panel.add(button);
|
||||
}
|
||||
|
@ -137,17 +131,24 @@ public class PrefsDialog {
|
|||
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
|
||||
class DialogListener
|
||||
implements ActionListener {
|
||||
JDialog dialog;
|
||||
|
||||
public DialogListener(JDialog dialog) {
|
||||
this.dialog = dialog;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
dialog.setVisible(false);
|
||||
class PrefsDialogListener
|
||||
implements ActionListener {
|
||||
JDialog dialog;
|
||||
|
||||
public PrefsDialogListener() {
|
||||
dialog = PrefsDialog.this;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String command = event.getActionCommand();
|
||||
Prefs prefs = new Prefs();
|
||||
if (command.equals(PrefsDialog.OK)) {
|
||||
for (int i = 0; i < editors.length; i++) {
|
||||
prefs.set(editors[i].getValue());
|
||||
}
|
||||
}
|
||||
dialog.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче