mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
First attempt at the preference dialog.
This commit is contained in:
parent
2cfe3510f6
commit
9b050c64eb
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user