1999-02-19 09:02:35 +00:00
|
|
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-02 01:51:54 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
1999-02-19 09:02:35 +00:00
|
|
|
*
|
1999-11-02 01:51:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-02-19 09:02:35 +00:00
|
|
|
*
|
|
|
|
* The Original Code is the Grendel mail/news client.
|
|
|
|
*
|
1999-03-07 19:58:40 +00:00
|
|
|
* The Initial Developer of the Original Code is Giao Nguyen
|
1999-11-02 01:51:54 +00:00
|
|
|
* <grail@cafebabe.org>. Portions created by Giao Nguyen are
|
|
|
|
* Copyright (C) 1999 Giao Nguyen. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-02-19 09:02:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package grendel.ui;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.Hashtable;
|
|
|
|
import java.util.Enumeration;
|
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.StringTokenizer;
|
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
|
|
|
|
import java.awt.Container;
|
|
|
|
import java.awt.Component;
|
|
|
|
import java.awt.GridBagLayout;
|
|
|
|
import java.awt.GridBagConstraints;
|
|
|
|
import java.awt.Insets;
|
|
|
|
|
|
|
|
import javax.swing.JComponent;
|
|
|
|
import javax.swing.JList;
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JDialog;
|
|
|
|
import javax.swing.ButtonGroup;
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.RootPaneContainer;
|
|
|
|
import javax.swing.JRadioButton;
|
|
|
|
import javax.swing.JTextField;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
import javax.swing.SwingConstants;
|
1999-02-20 22:53:02 +00:00
|
|
|
import javax.swing.JToggleButton;
|
1999-02-22 07:54:14 +00:00
|
|
|
import javax.swing.JScrollPane;
|
1999-11-29 00:44:34 +00:00
|
|
|
import javax.swing.JComboBox;
|
|
|
|
import javax.swing.ComboBoxModel;
|
1999-02-20 22:53:02 +00:00
|
|
|
import javax.swing.text.JTextComponent;
|
1999-02-19 09:02:35 +00:00
|
|
|
|
|
|
|
import org.w3c.dom.Element;
|
|
|
|
import org.w3c.dom.Node;
|
|
|
|
|
|
|
|
import com.sun.xml.parser.Resolver;
|
|
|
|
import com.sun.xml.parser.Parser;
|
|
|
|
import com.sun.xml.tree.XmlDocument;
|
|
|
|
import com.sun.xml.tree.XmlDocumentBuilder;
|
|
|
|
import com.sun.xml.tree.TreeWalker;
|
|
|
|
import org.xml.sax.InputSource;
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
import org.xml.sax.SAXParseException;
|
|
|
|
|
|
|
|
public class PageUI extends JPanel {
|
|
|
|
Hashtable table = new Hashtable();
|
1999-02-20 22:53:02 +00:00
|
|
|
PageModel model;
|
1999-02-19 09:02:35 +00:00
|
|
|
String title;
|
|
|
|
|
|
|
|
public PageUI() {
|
|
|
|
}
|
|
|
|
|
1999-02-20 22:53:02 +00:00
|
|
|
private void build(XMLPageBuilder pb, URL url, PageModel model) {
|
|
|
|
setModel(model);
|
1999-02-19 09:02:35 +00:00
|
|
|
try {
|
|
|
|
pb.buildFrom(url.openStream());
|
|
|
|
title = pb.getTitle();
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
1999-02-20 22:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the model for the page.
|
|
|
|
*
|
|
|
|
* @return the model
|
|
|
|
*/
|
|
|
|
public PageModel getModel() {
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the model for the page.
|
|
|
|
*
|
|
|
|
* @param model the model as the backing for the page
|
|
|
|
*/
|
|
|
|
public void setModel(PageModel model) {
|
|
|
|
this.model = model;
|
1999-02-19 09:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addCtrl(String name, JComponent component) {
|
1999-11-29 00:44:34 +00:00
|
|
|
System.out.println("addCtrl2: "+name);
|
1999-02-19 09:02:35 +00:00
|
|
|
if (name != null) table.put(name, component);
|
1999-02-22 07:54:14 +00:00
|
|
|
if (component instanceof JList) {
|
|
|
|
component = new JScrollPane(component);
|
|
|
|
}
|
1999-02-19 09:02:35 +00:00
|
|
|
add(component);
|
1999-02-20 22:53:02 +00:00
|
|
|
}
|
1999-02-19 09:02:35 +00:00
|
|
|
|
|
|
|
public void addCtrl(String name, JComponent component,
|
1999-06-21 09:28:04 +00:00
|
|
|
Object constraints) {
|
1999-11-29 00:44:34 +00:00
|
|
|
System.out.println("addCtrl: "+name);
|
1999-02-19 09:02:35 +00:00
|
|
|
if (name != null) table.put(name, component);
|
1999-02-22 07:54:14 +00:00
|
|
|
if (component instanceof JList) {
|
|
|
|
component = new JScrollPane(component);
|
|
|
|
}
|
1999-02-19 09:02:35 +00:00
|
|
|
add(component, constraints);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a component by its name.
|
|
|
|
*
|
|
|
|
* @param key the name of the component to retrieve
|
|
|
|
* @param return the component identiified by the key
|
|
|
|
*/
|
|
|
|
public JComponent getCtrlByName(String key) {
|
|
|
|
return (JComponent)table.get(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the title of this page.
|
|
|
|
*
|
|
|
|
* @return the title for this page
|
|
|
|
*/
|
|
|
|
public String getTitle() {
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store the values set in the input fields of the page.
|
|
|
|
*/
|
|
|
|
public void saveAll() {
|
1999-02-20 22:53:02 +00:00
|
|
|
Enumeration e = table.keys();
|
|
|
|
|
|
|
|
while(e.hasMoreElements()) {
|
|
|
|
String k = (String)e.nextElement();
|
|
|
|
Object obj = table.get(k);
|
|
|
|
Object val = null;
|
|
|
|
|
|
|
|
if (obj instanceof JTextComponent) {
|
|
|
|
JTextComponent tc = (JTextComponent)obj;
|
|
|
|
String str = tc.getText();
|
|
|
|
val = str;
|
|
|
|
} else if (obj instanceof JToggleButton) {
|
|
|
|
JToggleButton button = (JToggleButton)obj;
|
|
|
|
Boolean b = new Boolean(button.isSelected());
|
|
|
|
val = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val != null) {
|
|
|
|
model.setAttribute(k, val);
|
|
|
|
}
|
|
|
|
}
|
1999-02-19 09:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize input fields to known values.
|
|
|
|
*/
|
|
|
|
public void initAll() {
|
1999-02-20 22:53:02 +00:00
|
|
|
Enumeration e = table.keys();
|
|
|
|
|
|
|
|
while (e.hasMoreElements()) {
|
|
|
|
String s = (String)e.nextElement();
|
1999-11-29 00:44:34 +00:00
|
|
|
System.out.println(s);
|
1999-02-20 22:53:02 +00:00
|
|
|
Object obj = table.get(s);
|
|
|
|
Object val = model.getAttribute(s);
|
|
|
|
|
|
|
|
if (obj instanceof JTextComponent) {
|
|
|
|
JTextComponent tf = (JTextComponent)obj;
|
|
|
|
tf.setText((String)val);
|
|
|
|
} else if (obj instanceof JToggleButton) {
|
|
|
|
JToggleButton button = (JToggleButton)obj;
|
|
|
|
Boolean b = (Boolean)model.getAttribute(s);
|
|
|
|
button.setSelected(((Boolean)val).booleanValue());
|
1999-11-29 00:44:34 +00:00
|
|
|
} else if (obj instanceof JComboBox) {
|
|
|
|
System.out.println("combo!");
|
|
|
|
JComboBox combo = (JComboBox)obj;
|
|
|
|
ComboBoxModel cbmodel = (ComboBoxModel)model.getAttribute(s);
|
|
|
|
combo.setModel(cbmodel);
|
1999-02-20 22:53:02 +00:00
|
|
|
}
|
|
|
|
}
|
1999-02-19 09:02:35 +00:00
|
|
|
}
|
|
|
|
}
|