Dialogs that builds out of XML descriptions. Test code to verify that

they do work. Need integration into the main UI.
This commit is contained in:
grail%cafebabe.org 1999-02-19 09:05:00 +00:00
Родитель aac3211600
Коммит c9841350bc
5 изменённых файлов: 97 добавлений и 138 удалений

Просмотреть файл

@ -41,11 +41,12 @@ import javax.mail.Store;
import javax.mail.URLName; import javax.mail.URLName;
import javax.swing.AbstractListModel; import javax.swing.AbstractListModel;
import javax.swing.FileType;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
//import java.awt.FileDialog; //import java.awt.FileDialog;
//import java.io.File; //import java.io.File;
//import java.io.FilenameFilter; //import java.io.FilenameFilter;
import javax.swing.JComponent;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.ListModel; import javax.swing.ListModel;
@ -68,6 +69,8 @@ import javax.swing.table.AbstractTableModel;
import grendel.ui.EditHostDialog; import grendel.ui.EditHostDialog;
import grendel.ui.Util; import grendel.ui.Util;
import grendel.ui.PageModel;
import grendel.ui.PageUI;
public class MailServerPrefsEditor implements PropertyEditor public class MailServerPrefsEditor implements PropertyEditor
{ {
@ -99,27 +102,12 @@ public class MailServerPrefsEditor implements PropertyEditor
fValues.put(kMailDirectoryKey, ""); fValues.put(kMailDirectoryKey, "");
fValues.put(kLeaveOnServerKey, Boolean.TRUE); fValues.put(kLeaveOnServerKey, Boolean.TRUE);
fValues.put(kSMTPHostKey, ""); fValues.put(kSMTPHostKey, "");
} setStore(fValues);
public Object getAttribute(String aAttrib) throws AttrNotFoundException {
Object res = fValues.get(aAttrib);
if (res == null) {
res = fLabels.getString(aAttrib);
}
if (res == null) {
throw new AttrNotFoundException(aAttrib);
}
return res;
}
public void setAttribute(String aAttrib, Object aValue) {
if (fValues.containsKey(aAttrib)) {
fValues.put(aAttrib, aValue);
}
} }
public void actionPerformed(ActionEvent aEvent) { public void actionPerformed(ActionEvent aEvent) {
String action = aEvent.getActionCommand(); String action = aEvent.getActionCommand();
System.out.println(action);
if (action.equals(kNewKey)) { if (action.equals(kNewKey)) {
EditHostDialog hostDialog = EditHostDialog hostDialog =
new EditHostDialog(Util.GetParentFrame(fPanel), null); new EditHostDialog(Util.GetParentFrame(fPanel), null);
@ -130,10 +118,10 @@ public class MailServerPrefsEditor implements PropertyEditor
fListeners.firePropertyChange(null, null, fPrefs); fListeners.firePropertyChange(null, null, fPrefs);
} }
} else if (action.equals(kEditKey)) { } else if (action.equals(kEditKey)) {
AbstractCtrl c; JList c;
c = fPanel.getCtrlByName(kHostListKey); c = (JList)fPanel.getCtrlByName(kHostListKey);
URLName value = (URLName) c.getValue(); URLName value = (URLName)c.getSelectedValue();
if (value != null) { if (value != null) {
EditHostDialog hostDialog = EditHostDialog hostDialog =
new EditHostDialog(Util.GetParentFrame(fPanel), value); new EditHostDialog(Util.GetParentFrame(fPanel), value);
@ -145,10 +133,10 @@ public class MailServerPrefsEditor implements PropertyEditor
} }
} }
} else if (action.equals(kDeleteKey)) { } else if (action.equals(kDeleteKey)) {
AbstractCtrl c; JList c;
c = fPanel.getCtrlByName(kHostListKey); c = (JList)fPanel.getCtrlByName(kHostListKey);
URLName value = (URLName) c.getValue(); URLName value = (URLName) c.getSelectedValue();
if (value != null) { if (value != null) {
fHostListModel.remove(value); fHostListModel.remove(value);
fPrefs.setStores(fHostListModel.getStores()); fPrefs.setStores(fHostListModel.getStores());
@ -156,8 +144,9 @@ public class MailServerPrefsEditor implements PropertyEditor
} }
} else if (action.equals(kChooseKey)) { } else if (action.equals(kChooseKey)) {
JFileChooser chooser = new JFileChooser(fPrefs.getMailDirectory()); JFileChooser chooser = new JFileChooser(fPrefs.getMailDirectory());
chooser.setChoosableFileTypes(new FileType[] {FileType.SharedFolder}); // chooser.addChoosableFileFilter(new FileFilter[]
chooser.showDialog(fPanel); // {FileFilter.SharedFolder});
chooser.showDialog(fPanel, "Okay");
} }
} }
} }
@ -166,15 +155,11 @@ public class MailServerPrefsEditor implements PropertyEditor
fModel = new ServerPrefsModel(); fModel = new ServerPrefsModel();
fHostListModel = new HostListModel(); fHostListModel = new HostListModel();
XMLNode root = null;
URL url = getClass().getResource("PrefDialogs.xml"); URL url = getClass().getResource("PrefDialogs.xml");
try { try {
root = xml.tree.TreeBuilder.build(url, getClass()); fPanel = new PageUI(url, "id", "serverPrefs", fModel, getClass());
XMLNode editHost = root.getChild("dialog", "id", "serverPrefs");
fPanel = new PageUI(url, editHost, fModel); JComponent c;
AbstractCtrl c;
ChangeAction ca = new ChangeAction(); ChangeAction ca = new ChangeAction();
c = fPanel.getCtrlByName(kSMTPHostKey); c = fPanel.getCtrlByName(kSMTPHostKey);
@ -184,8 +169,8 @@ public class MailServerPrefsEditor implements PropertyEditor
c.addPropertyChangeListener(ca); c.addPropertyChangeListener(ca);
c = fPanel.getCtrlByName(kHostListKey); c = fPanel.getCtrlByName(kHostListKey);
if (c instanceof JLISTeditor) { if (c instanceof JList) {
((JLISTeditor) c).setModel(fHostListModel); ((JList) c).setModel(fHostListModel);
} }
c.addPropertyChangeListener(new ListListener()); c.addPropertyChangeListener(new ListListener());
@ -263,9 +248,9 @@ public class MailServerPrefsEditor implements PropertyEditor
class ListListener implements PropertyChangeListener { class ListListener implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
AbstractCtrl c; JComponent c;
c = (AbstractCtrl) e.getSource(); c = (JComponent)e.getSource();
boolean enabled = c.getValue() != null; boolean enabled = (((JList)c).getSelectedValue() != null);
c = fPanel.getCtrlByName(kDeleteKey); c = fPanel.getCtrlByName(kDeleteKey);
c.setEnabled(enabled); c.setEnabled(enabled);
@ -275,7 +260,6 @@ public class MailServerPrefsEditor implements PropertyEditor
} }
} }
class HostListModel extends AbstractListModel { class HostListModel extends AbstractListModel {
URLName fStores[]; URLName fStores[];
Vector fEditableStores = new Vector(); Vector fEditableStores = new Vector();
@ -355,4 +339,12 @@ public class MailServerPrefsEditor implements PropertyEditor
event(aEvent); 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);
}
} }

Просмотреть файл

@ -1,6 +1,6 @@
<xml> <xml>
<head> <head>
<link rel="stringprops" href="Labels.properties"/> <link role="stringprops" href="PrefLabels.properties"/>
</head> </head>
<body> <body>
@ -62,7 +62,7 @@
insets="[5,5,0,5]"/> insets="[5,5,0,5]"/>
<input type="text" ID="mailDirectoryField" value="mailDirectoryField" <input type="text" ID="mailDirectoryField" value="mailDirectoryField"
weightx="1" fill="horizontal" gridwidth="relative" weightx="1" fill="horizontal" gridwidth="relative" columns="15"
insets="[0,5,5,5]"/> insets="[0,5,5,5]"/>
<input type="button" ID="chooseButton" command="chooseButton" <input type="button" ID="chooseButton" command="chooseButton"

Просмотреть файл

@ -37,20 +37,19 @@ import java.util.Hashtable;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javax.swing.JList;
import javax.swing.JComponent;
import javax.swing.AbstractListModel; import javax.swing.AbstractListModel;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.JPanel;
//import netscape.orion.dialogs.AbstractCtrl; import grendel.ui.XMLPageBuilder;
//import netscape.orion.dialogs.AttrNotFoundException; import grendel.ui.PageModel;
//import netscape.orion.dialogs.JLISTeditor; import grendel.ui.PageUI;
//import netscape.orion.dialogs.PageModel;
//import netscape.orion.dialogs.PageUI;
//import xml.tree.XMLNode; public class UIPrefsEditor extends JPanel
//import xml.tree.TreeBuilder; implements PropertyEditor {
public class UIPrefsEditor implements PropertyEditor {
UIPrefs fPrefs = new UIPrefs(); UIPrefs fPrefs = new UIPrefs();
PropertyChangeSupport fListeners = new PropertyChangeSupport(this); PropertyChangeSupport fListeners = new PropertyChangeSupport(this);
@ -68,23 +67,7 @@ public class UIPrefsEditor implements PropertyEditor {
class UIPrefsModel extends PageModel { class UIPrefsModel extends PageModel {
public UIPrefsModel() { public UIPrefsModel() {
fValues = new Hashtable(); fValues = new Hashtable();
} setStore(fValues);
public Object getAttribute(String aAttrib) throws AttrNotFoundException {
Object res = fValues.get(aAttrib);
if (res == null) {
res = fLabels.getString(aAttrib);
}
if (res == null) {
throw new AttrNotFoundException(aAttrib);
}
return res;
}
public void setAttribute(String aAttrib, Object aValue) {
if (fValues.containsKey(aAttrib)) {
fValues.put(aAttrib, aValue);
}
} }
public void actionPerformed(ActionEvent aEvent) { public void actionPerformed(ActionEvent aEvent) {
@ -94,25 +77,17 @@ public class UIPrefsEditor implements PropertyEditor {
public UIPrefsEditor() { public UIPrefsEditor() {
fModel = new UIPrefsModel(); fModel = new UIPrefsModel();
XMLNode root = null; // XMLNode root = null;
URL url = getClass().getResource("PrefDialogs.xml"); URL url = getClass().getResource("PrefDialogs.xml");
try { fPanel = new PageUI(url, "id", "UIPrefs", fModel, getClass());
root = xml.tree.TreeBuilder.build(url, getClass());
XMLNode editHost = root.getChild("dialog", "id", "UIPrefs");
fPanel = new PageUI(url, editHost, fModel); JComponent c;
ChangeAction ca = new ChangeAction();
AbstractCtrl c; c = fPanel.getCtrlByName(kLAFKey);
ChangeAction ca = new ChangeAction(); c.addPropertyChangeListener(ca);
if (c instanceof JList) {
c = fPanel.getCtrlByName(kLAFKey); ((JList) c).setModel(new LAFListModel());
c.addPropertyChangeListener(ca);
if (c instanceof JLISTeditor) {
((JLISTeditor) c).setModel(new LAFListModel());
}
} catch (Exception e) {
e.printStackTrace();
} }
} }
@ -135,8 +110,8 @@ public class UIPrefsEditor implements PropertyEditor {
public Object getValue() { public Object getValue() {
fPanel.saveAll(); fPanel.saveAll();
AbstractCtrl c = fPanel.getCtrlByName(kLAFKey); // AbstractCtrl c = fPanel.getCtrlByName(kLAFKey);
fPrefs.setLAF((LookAndFeel) c.getValue()); // fPrefs.setLAF((LookAndFeel) c.getValue());
return fPrefs; return fPrefs;
} }
@ -156,8 +131,8 @@ public class UIPrefsEditor implements PropertyEditor {
UIPrefs oldPrefs = fPrefs; UIPrefs oldPrefs = fPrefs;
fPrefs = (UIPrefs) aValue; fPrefs = (UIPrefs) aValue;
AbstractCtrl c = fPanel.getCtrlByName(kLAFKey); // AbstractCtrl c = fPanel.getCtrlByName(kLAFKey);
c.setValue(fPrefs.getLAF()); // c.setValue(fPrefs.getLAF());
fListeners.firePropertyChange(null, oldPrefs, fPrefs); fListeners.firePropertyChange(null, oldPrefs, fPrefs);
} }
@ -195,9 +170,9 @@ public class UIPrefsEditor implements PropertyEditor {
fLAFs = UIManager.getAuxiliaryLookAndFeels(); fLAFs = UIManager.getAuxiliaryLookAndFeels();
*/ */
fLAFs = new LookAndFeel[] { fLAFs = new LookAndFeel[] {
new javax.swing.jlf.JLFLookAndFeel(), new javax.swing.plaf.metal.MetalLookAndFeel(),
new javax.swing.motif.MotifLookAndFeel(), // new javax.swing.plaf.motif.MotifLookAndFeel(),
new javax.swing.windows.WindowsLookAndFeel() // new javax.swing.windows.WindowsLookAndFeel()
}; };
} }
@ -216,4 +191,12 @@ public class UIPrefsEditor implements PropertyEditor {
} }
} }
public static void main(String[] args) throws Exception {
javax.swing.JFrame frame = new javax.swing.JFrame("Foo bar");
UIPrefsEditor ui = new UIPrefsEditor();
frame.getContentPane().add(ui.fPanel);
frame.pack();
frame.setVisible(true);
}
} }

Просмотреть файл

@ -44,6 +44,13 @@ import java.util.ResourceBundle;
//import xml.tree.XMLNode; //import xml.tree.XMLNode;
//import xml.tree.TreeBuilder; //import xml.tree.TreeBuilder;
import javax.swing.JComponent;
import javax.swing.JPanel;
import grendel.ui.XMLPageBuilder;
import grendel.ui.PageModel;
import grendel.ui.PageUI;
public class UserPrefsEditor implements PropertyEditor { public class UserPrefsEditor implements PropertyEditor {
UserPrefs fPrefs = new UserPrefs(); UserPrefs fPrefs = new UserPrefs();
PropertyChangeSupport fListeners = new PropertyChangeSupport(this); PropertyChangeSupport fListeners = new PropertyChangeSupport(this);
@ -67,23 +74,7 @@ public class UserPrefsEditor implements PropertyEditor {
fValues.put(kNameKey, ""); fValues.put(kNameKey, "");
fValues.put(kOrganizationKey, ""); fValues.put(kOrganizationKey, "");
fValues.put(kEmailAddressKey, ""); fValues.put(kEmailAddressKey, "");
} setStore(fValues);
public Object getAttribute(String aAttrib) throws AttrNotFoundException {
Object res = fValues.get(aAttrib);
if (res == null) {
res = fLabels.getString(aAttrib);
}
if (res == null) {
throw new AttrNotFoundException(aAttrib);
}
return res;
}
public void setAttribute(String aAttrib, Object aValue) {
if (fValues.containsKey(aAttrib)) {
fValues.put(aAttrib, aValue);
}
} }
public void actionPerformed(ActionEvent aEvent) { public void actionPerformed(ActionEvent aEvent) {
@ -92,25 +83,29 @@ public class UserPrefsEditor implements PropertyEditor {
public UserPrefsEditor() { public UserPrefsEditor() {
fModel = new UserPrefsModel(); fModel = new UserPrefsModel();
XMLNode root = null; // XMLNode root = null;
URL url = getClass().getResource("PrefDialogs.xml"); URL url = getClass().getResource("PrefDialogs.xml");
try { try {
root = xml.tree.TreeBuilder.build(url, getClass()); // root = xml.tree.TreeBuilder.build(url, getClass());
XMLNode editHost = root.getChild("dialog", "id", "userPrefs"); // XMLNode editHost = root.getChild("dialog", "id", "userPrefs");
XMLPageBuilder pb = new XMLPageBuilder("id", "userPrefs", fModel);
pb.setReference(getClass());
pb.buildFrom(url.openStream());
fPanel = new PageUI(url, editHost, fModel); // fPanel = new PageUI(url, editHost, fModel);
fPanel = new PageUI(url, "id", "userPrefs", fModel, getClass());
AbstractCtrl c;
ChangeAction ca = new ChangeAction(); ChangeAction ca = new ChangeAction();
Component c;
c = fPanel.getCtrlByName(kNameKey); c = fPanel.getCtrlByName(kNameKey);
c.addPropertyChangeListener(ca); ((JComponent)c).addPropertyChangeListener(ca);
c = fPanel.getCtrlByName(kOrganizationKey); c = fPanel.getCtrlByName(kOrganizationKey);
c.addPropertyChangeListener(ca); ((JComponent)c).addPropertyChangeListener(ca);
c = fPanel.getCtrlByName(kEmailAddressKey); c = fPanel.getCtrlByName(kEmailAddressKey);
c.addPropertyChangeListener(ca); ((JComponent)c).addPropertyChangeListener(ca);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -133,7 +128,7 @@ public class UserPrefsEditor implements PropertyEditor {
} }
public Object getValue() { public Object getValue() {
fPanel.saveAll(); // fPanel.saveAll();
String name = (String) fValues.get(kNameKey); String name = (String) fValues.get(kNameKey);
String org = (String) fValues.get(kOrganizationKey); String org = (String) fValues.get(kOrganizationKey);
@ -193,4 +188,12 @@ public class UserPrefsEditor implements PropertyEditor {
event(aEvent); event(aEvent);
} }
} }
public static void main(String[] args) throws Exception {
javax.swing.JFrame frame = new javax.swing.JFrame("Foo bar");
UserPrefsEditor d = new UserPrefsEditor();
frame.getContentPane().add(d.fPanel);
frame.pack();
frame.setVisible(true);
}
} }

Просмотреть файл

@ -58,7 +58,7 @@ public class EditHostDialog extends GeneralDialog {
Hashtable fValues = null; Hashtable fValues = null;
JPanel fPanel; PageUI fPanel;
EditHostModel model; EditHostModel model;
@ -99,28 +99,9 @@ public class EditHostDialog extends GeneralDialog {
setModal(true); setModal(true);
model = new EditHostModel(aURL); model = new EditHostModel(aURL);
// use the XML parser to get the root XML node of the resource tree
// XMLNode root = null;
URL url = getClass().getResource("dialogs.xml"); URL url = getClass().getResource("dialogs.xml");
/* fPanel = new PageUI(url, "id", "editHost", model);
try {
root = xml.tree.TreeBuilder.build(url, getClass());
} catch (Exception e) {
e.printStackTrace();
}
XMLNode editHost = root.getChild("dialog", "id", "editHost");
fPanel = new PageUI(url, editHost, model);
*/
XMLPageBuilder pb = new XMLPageBuilder("id", "editHost", model);
try {
pb.buildFrom(url.openStream());
fPanel = pb.getComponent();
} catch (IOException io) {
System.out.println(io);
}
JOptionPane actionPanel = new JOptionPane(fPanel, JOptionPane actionPanel = new JOptionPane(fPanel,
JOptionPane.PLAIN_MESSAGE, JOptionPane.PLAIN_MESSAGE,
@ -130,7 +111,7 @@ public class EditHostDialog extends GeneralDialog {
// XXX This is a stupid hack because PageUI doesn't to a resource lookup // XXX This is a stupid hack because PageUI doesn't to a resource lookup
// on it's title. Bleh. // on it's title. Bleh.
String title = pb.getTitle(); String title = fPanel.getTitle();
if (title.charAt(0) == '$') { if (title.charAt(0) == '$') {
title = (String) model.getAttribute(title.substring(1)); title = (String) model.getAttribute(title.substring(1));
} }
@ -157,7 +138,7 @@ public class EditHostDialog extends GeneralDialog {
if (value == JOptionPane.OK_OPTION) { if (value == JOptionPane.OK_OPTION) {
// Grab all the values // Grab all the values
// fPanel.saveAll(); fPanel.saveAll();
String proto; String proto;
Boolean imap = (Boolean) model.getAttribute(kIMAPRadioKey); Boolean imap = (Boolean) model.getAttribute(kIMAPRadioKey);