From bbf9e64a654004386f81db4105597254aa448e11 Mon Sep 17 00:00:00 2001 From: "grail%cafebabe.org" Date: Tue, 23 Feb 1999 03:44:34 +0000 Subject: [PATCH] First attempt at the preference dialog. git-svn-id: svn://10.0.0.236/trunk@21569 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/grendel/ui/PrefsDialog.java | 89 ++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/mozilla/grendel/ui/PrefsDialog.java b/mozilla/grendel/ui/PrefsDialog.java index 6a88231a103..2ac1d437083 100644 --- a/mozilla/grendel/ui/PrefsDialog.java +++ b/mozilla/grendel/ui/PrefsDialog.java @@ -21,8 +21,23 @@ package grendel.ui; +import java.beans.SimpleBeanInfo; +import java.beans.PropertyDescriptor; +import java.beans.PropertyEditor; + +import java.awt.Container; +import java.awt.BorderLayout; +import java.awt.FlowLayout; + +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; +import javax.swing.JDialog; +import javax.swing.JTabbedPane; +import javax.swing.JPanel; import calypso.util.Preferences; import calypso.util.PreferencesFactory; @@ -32,6 +47,7 @@ import calypso.util.PreferencesFactory; 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", @@ -48,7 +64,8 @@ public class PrefsDialog { 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); + // JOptionPane.showMessageDialog(aParent, "This part of the UI is\nstill being worked on.", "Under Construction", JOptionPane.INFORMATION_MESSAGE); + propertyEditorDialog(aParent, new Prefs(), false); } public static boolean ValidPrefs() { @@ -62,5 +79,75 @@ public class PrefsDialog { */ return res; } + + private static void propertyEditorDialog(JFrame parent, Object obj, + boolean modal) { + 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"}; + + content.setLayout(new BorderLayout()); + content.add(pane, BorderLayout.CENTER); + content.add(buttonPanel(labels, + new DialogListener(dialog)), + BorderLayout.SOUTH); + + try { + // get the beaninfo + beanie = Class.forName(name + "BeanInfo"); + o = beanie.newInstance(); + if (!(o instanceof SimpleBeanInfo)) return; // bummer + + // process the descriptors + PropertyDescriptor[] desc; + info = (SimpleBeanInfo)o; + desc = info.getPropertyDescriptors(); + + 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()); + } + dialog.pack(); + dialog.setVisible(true); + } catch (Exception e) { + System.out.println("welp, that sucked. beans is broke. And stuff"); + } + } + + public static 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]); + if (listener != null) button.addActionListener(listener); + panel.add(button); + } + } + + return panel; + } } +class DialogListener + implements ActionListener { + JDialog dialog; + + public DialogListener(JDialog dialog) { + this.dialog = dialog; + } + + public void actionPerformed(ActionEvent event) { + dialog.setVisible(false); + } +}