зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
aac3211600
Коммит
c9841350bc
|
@ -41,11 +41,12 @@ import javax.mail.Store;
|
|||
import javax.mail.URLName;
|
||||
|
||||
import javax.swing.AbstractListModel;
|
||||
import javax.swing.FileType;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
//import java.awt.FileDialog;
|
||||
//import java.io.File;
|
||||
//import java.io.FilenameFilter;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ListModel;
|
||||
|
@ -68,6 +69,8 @@ import javax.swing.table.AbstractTableModel;
|
|||
|
||||
import grendel.ui.EditHostDialog;
|
||||
import grendel.ui.Util;
|
||||
import grendel.ui.PageModel;
|
||||
import grendel.ui.PageUI;
|
||||
|
||||
public class MailServerPrefsEditor implements PropertyEditor
|
||||
{
|
||||
|
@ -99,27 +102,12 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
fValues.put(kMailDirectoryKey, "");
|
||||
fValues.put(kLeaveOnServerKey, Boolean.TRUE);
|
||||
fValues.put(kSMTPHostKey, "");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
setStore(fValues);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
String action = aEvent.getActionCommand();
|
||||
System.out.println(action);
|
||||
if (action.equals(kNewKey)) {
|
||||
EditHostDialog hostDialog =
|
||||
new EditHostDialog(Util.GetParentFrame(fPanel), null);
|
||||
|
@ -130,10 +118,10 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
fListeners.firePropertyChange(null, null, fPrefs);
|
||||
}
|
||||
} else if (action.equals(kEditKey)) {
|
||||
AbstractCtrl c;
|
||||
c = fPanel.getCtrlByName(kHostListKey);
|
||||
JList c;
|
||||
c = (JList)fPanel.getCtrlByName(kHostListKey);
|
||||
|
||||
URLName value = (URLName) c.getValue();
|
||||
URLName value = (URLName)c.getSelectedValue();
|
||||
if (value != null) {
|
||||
EditHostDialog hostDialog =
|
||||
new EditHostDialog(Util.GetParentFrame(fPanel), value);
|
||||
|
@ -145,10 +133,10 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
}
|
||||
}
|
||||
} else if (action.equals(kDeleteKey)) {
|
||||
AbstractCtrl c;
|
||||
c = fPanel.getCtrlByName(kHostListKey);
|
||||
JList c;
|
||||
c = (JList)fPanel.getCtrlByName(kHostListKey);
|
||||
|
||||
URLName value = (URLName) c.getValue();
|
||||
URLName value = (URLName) c.getSelectedValue();
|
||||
if (value != null) {
|
||||
fHostListModel.remove(value);
|
||||
fPrefs.setStores(fHostListModel.getStores());
|
||||
|
@ -156,8 +144,9 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
}
|
||||
} else if (action.equals(kChooseKey)) {
|
||||
JFileChooser chooser = new JFileChooser(fPrefs.getMailDirectory());
|
||||
chooser.setChoosableFileTypes(new FileType[] {FileType.SharedFolder});
|
||||
chooser.showDialog(fPanel);
|
||||
// chooser.addChoosableFileFilter(new FileFilter[]
|
||||
// {FileFilter.SharedFolder});
|
||||
chooser.showDialog(fPanel, "Okay");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -166,15 +155,11 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
fModel = new ServerPrefsModel();
|
||||
fHostListModel = new HostListModel();
|
||||
|
||||
XMLNode root = null;
|
||||
URL url = getClass().getResource("PrefDialogs.xml");
|
||||
try {
|
||||
root = xml.tree.TreeBuilder.build(url, getClass());
|
||||
XMLNode editHost = root.getChild("dialog", "id", "serverPrefs");
|
||||
fPanel = new PageUI(url, "id", "serverPrefs", fModel, getClass());
|
||||
|
||||
fPanel = new PageUI(url, editHost, fModel);
|
||||
|
||||
AbstractCtrl c;
|
||||
JComponent c;
|
||||
ChangeAction ca = new ChangeAction();
|
||||
|
||||
c = fPanel.getCtrlByName(kSMTPHostKey);
|
||||
|
@ -184,8 +169,8 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
c.addPropertyChangeListener(ca);
|
||||
|
||||
c = fPanel.getCtrlByName(kHostListKey);
|
||||
if (c instanceof JLISTeditor) {
|
||||
((JLISTeditor) c).setModel(fHostListModel);
|
||||
if (c instanceof JList) {
|
||||
((JList) c).setModel(fHostListModel);
|
||||
}
|
||||
c.addPropertyChangeListener(new ListListener());
|
||||
|
||||
|
@ -263,9 +248,9 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
|
||||
class ListListener implements PropertyChangeListener {
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
AbstractCtrl c;
|
||||
c = (AbstractCtrl) e.getSource();
|
||||
boolean enabled = c.getValue() != null;
|
||||
JComponent c;
|
||||
c = (JComponent)e.getSource();
|
||||
boolean enabled = (((JList)c).getSelectedValue() != null);
|
||||
|
||||
c = fPanel.getCtrlByName(kDeleteKey);
|
||||
c.setEnabled(enabled);
|
||||
|
@ -275,7 +260,6 @@ public class MailServerPrefsEditor implements PropertyEditor
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
class HostListModel extends AbstractListModel {
|
||||
URLName fStores[];
|
||||
Vector fEditableStores = new Vector();
|
||||
|
@ -355,4 +339,12 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<xml>
|
||||
<head>
|
||||
<link rel="stringprops" href="Labels.properties"/>
|
||||
<link role="stringprops" href="PrefLabels.properties"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
@ -62,7 +62,7 @@
|
|||
insets="[5,5,0,5]"/>
|
||||
|
||||
<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]"/>
|
||||
|
||||
<input type="button" ID="chooseButton" command="chooseButton"
|
||||
|
|
|
@ -37,20 +37,19 @@ import java.util.Hashtable;
|
|||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.AbstractListModel;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
//import netscape.orion.dialogs.AbstractCtrl;
|
||||
//import netscape.orion.dialogs.AttrNotFoundException;
|
||||
//import netscape.orion.dialogs.JLISTeditor;
|
||||
//import netscape.orion.dialogs.PageModel;
|
||||
//import netscape.orion.dialogs.PageUI;
|
||||
import grendel.ui.XMLPageBuilder;
|
||||
import grendel.ui.PageModel;
|
||||
import grendel.ui.PageUI;
|
||||
|
||||
//import xml.tree.XMLNode;
|
||||
//import xml.tree.TreeBuilder;
|
||||
|
||||
public class UIPrefsEditor implements PropertyEditor {
|
||||
public class UIPrefsEditor extends JPanel
|
||||
implements PropertyEditor {
|
||||
UIPrefs fPrefs = new UIPrefs();
|
||||
PropertyChangeSupport fListeners = new PropertyChangeSupport(this);
|
||||
|
||||
|
@ -68,23 +67,7 @@ public class UIPrefsEditor implements PropertyEditor {
|
|||
class UIPrefsModel extends PageModel {
|
||||
public UIPrefsModel() {
|
||||
fValues = new Hashtable();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
setStore(fValues);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
|
@ -94,25 +77,17 @@ public class UIPrefsEditor implements PropertyEditor {
|
|||
public UIPrefsEditor() {
|
||||
fModel = new UIPrefsModel();
|
||||
|
||||
XMLNode root = null;
|
||||
// XMLNode root = null;
|
||||
URL url = getClass().getResource("PrefDialogs.xml");
|
||||
try {
|
||||
root = xml.tree.TreeBuilder.build(url, getClass());
|
||||
XMLNode editHost = root.getChild("dialog", "id", "UIPrefs");
|
||||
fPanel = new PageUI(url, "id", "UIPrefs", fModel, getClass());
|
||||
|
||||
fPanel = new PageUI(url, editHost, fModel);
|
||||
JComponent c;
|
||||
ChangeAction ca = new ChangeAction();
|
||||
|
||||
AbstractCtrl c;
|
||||
ChangeAction ca = new ChangeAction();
|
||||
|
||||
c = fPanel.getCtrlByName(kLAFKey);
|
||||
c.addPropertyChangeListener(ca);
|
||||
if (c instanceof JLISTeditor) {
|
||||
((JLISTeditor) c).setModel(new LAFListModel());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
c = fPanel.getCtrlByName(kLAFKey);
|
||||
c.addPropertyChangeListener(ca);
|
||||
if (c instanceof JList) {
|
||||
((JList) c).setModel(new LAFListModel());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,8 +110,8 @@ public class UIPrefsEditor implements PropertyEditor {
|
|||
public Object getValue() {
|
||||
fPanel.saveAll();
|
||||
|
||||
AbstractCtrl c = fPanel.getCtrlByName(kLAFKey);
|
||||
fPrefs.setLAF((LookAndFeel) c.getValue());
|
||||
// AbstractCtrl c = fPanel.getCtrlByName(kLAFKey);
|
||||
// fPrefs.setLAF((LookAndFeel) c.getValue());
|
||||
|
||||
return fPrefs;
|
||||
}
|
||||
|
@ -156,8 +131,8 @@ public class UIPrefsEditor implements PropertyEditor {
|
|||
UIPrefs oldPrefs = fPrefs;
|
||||
fPrefs = (UIPrefs) aValue;
|
||||
|
||||
AbstractCtrl c = fPanel.getCtrlByName(kLAFKey);
|
||||
c.setValue(fPrefs.getLAF());
|
||||
// AbstractCtrl c = fPanel.getCtrlByName(kLAFKey);
|
||||
// c.setValue(fPrefs.getLAF());
|
||||
|
||||
fListeners.firePropertyChange(null, oldPrefs, fPrefs);
|
||||
}
|
||||
|
@ -195,9 +170,9 @@ public class UIPrefsEditor implements PropertyEditor {
|
|||
fLAFs = UIManager.getAuxiliaryLookAndFeels();
|
||||
*/
|
||||
fLAFs = new LookAndFeel[] {
|
||||
new javax.swing.jlf.JLFLookAndFeel(),
|
||||
new javax.swing.motif.MotifLookAndFeel(),
|
||||
new javax.swing.windows.WindowsLookAndFeel()
|
||||
new javax.swing.plaf.metal.MetalLookAndFeel(),
|
||||
// new javax.swing.plaf.motif.MotifLookAndFeel(),
|
||||
// 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.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 {
|
||||
UserPrefs fPrefs = new UserPrefs();
|
||||
PropertyChangeSupport fListeners = new PropertyChangeSupport(this);
|
||||
|
@ -67,23 +74,7 @@ public class UserPrefsEditor implements PropertyEditor {
|
|||
fValues.put(kNameKey, "");
|
||||
fValues.put(kOrganizationKey, "");
|
||||
fValues.put(kEmailAddressKey, "");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
setStore(fValues);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
|
@ -92,25 +83,29 @@ public class UserPrefsEditor implements PropertyEditor {
|
|||
|
||||
public UserPrefsEditor() {
|
||||
fModel = new UserPrefsModel();
|
||||
XMLNode root = null;
|
||||
// XMLNode root = null;
|
||||
URL url = getClass().getResource("PrefDialogs.xml");
|
||||
try {
|
||||
root = xml.tree.TreeBuilder.build(url, getClass());
|
||||
XMLNode editHost = root.getChild("dialog", "id", "userPrefs");
|
||||
// root = xml.tree.TreeBuilder.build(url, getClass());
|
||||
// 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();
|
||||
Component c;
|
||||
|
||||
c = fPanel.getCtrlByName(kNameKey);
|
||||
c.addPropertyChangeListener(ca);
|
||||
((JComponent)c).addPropertyChangeListener(ca);
|
||||
|
||||
c = fPanel.getCtrlByName(kOrganizationKey);
|
||||
c.addPropertyChangeListener(ca);
|
||||
((JComponent)c).addPropertyChangeListener(ca);
|
||||
|
||||
c = fPanel.getCtrlByName(kEmailAddressKey);
|
||||
c.addPropertyChangeListener(ca);
|
||||
((JComponent)c).addPropertyChangeListener(ca);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -133,7 +128,7 @@ public class UserPrefsEditor implements PropertyEditor {
|
|||
}
|
||||
|
||||
public Object getValue() {
|
||||
fPanel.saveAll();
|
||||
// fPanel.saveAll();
|
||||
|
||||
String name = (String) fValues.get(kNameKey);
|
||||
String org = (String) fValues.get(kOrganizationKey);
|
||||
|
@ -193,4 +188,12 @@ public class UserPrefsEditor implements PropertyEditor {
|
|||
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;
|
||||
|
||||
JPanel fPanel;
|
||||
PageUI fPanel;
|
||||
|
||||
EditHostModel model;
|
||||
|
||||
|
@ -99,28 +99,9 @@ public class EditHostDialog extends GeneralDialog {
|
|||
setModal(true);
|
||||
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");
|
||||
|
||||
/*
|
||||
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);
|
||||
}
|
||||
fPanel = new PageUI(url, "id", "editHost", model);
|
||||
|
||||
JOptionPane actionPanel = new JOptionPane(fPanel,
|
||||
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
|
||||
// on it's title. Bleh.
|
||||
String title = pb.getTitle();
|
||||
String title = fPanel.getTitle();
|
||||
if (title.charAt(0) == '$') {
|
||||
title = (String) model.getAttribute(title.substring(1));
|
||||
}
|
||||
|
@ -157,7 +138,7 @@ public class EditHostDialog extends GeneralDialog {
|
|||
|
||||
if (value == JOptionPane.OK_OPTION) {
|
||||
// Grab all the values
|
||||
// fPanel.saveAll();
|
||||
fPanel.saveAll();
|
||||
|
||||
String proto;
|
||||
Boolean imap = (Boolean) model.getAttribute(kIMAPRadioKey);
|
||||
|
|
Загрузка…
Ссылка в новой задаче