1999-02-09 08:06:09 +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-09 08:06:09 +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-09 08:06:09 +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.
|
1999-02-09 08:06:09 +00:00
|
|
|
*
|
1999-11-02 01:51:54 +00:00
|
|
|
* Contributor(s): Morgan Schweers <morgan@vixen.com>
|
1999-02-09 08:06:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package grendel.ui;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.net.URL;
|
1999-02-19 09:02:35 +00:00
|
|
|
import java.util.Hashtable;
|
1999-02-09 08:06:09 +00:00
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.StringTokenizer;
|
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
|
|
|
|
import java.awt.Container;
|
|
|
|
import java.awt.GridBagLayout;
|
|
|
|
import java.awt.GridBagConstraints;
|
|
|
|
import java.awt.Insets;
|
|
|
|
|
|
|
|
import javax.swing.JComponent;
|
1999-02-19 02:39:00 +00:00
|
|
|
import javax.swing.JList;
|
1999-02-09 08:06:09 +00:00
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JDialog;
|
|
|
|
import javax.swing.ButtonGroup;
|
1999-02-19 09:02:35 +00:00
|
|
|
import javax.swing.JCheckBox;
|
1999-02-09 08:06:09 +00:00
|
|
|
import javax.swing.JPanel;
|
1999-03-30 00:30:33 +00:00
|
|
|
import javax.swing.JPasswordField;
|
1999-02-09 08:06:09 +00:00
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.RootPaneContainer;
|
|
|
|
import javax.swing.JRadioButton;
|
|
|
|
import javax.swing.JTextField;
|
|
|
|
import javax.swing.JLabel;
|
1999-02-20 23:53:48 +00:00
|
|
|
import javax.swing.JScrollPane;
|
1999-02-09 08:06:09 +00:00
|
|
|
import javax.swing.SwingConstants;
|
1999-11-29 00:44:34 +00:00
|
|
|
import javax.swing.ImageIcon;
|
|
|
|
import javax.swing.JComboBox;
|
1999-02-09 08:06:09 +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.TreeWalker;
|
|
|
|
import org.xml.sax.InputSource;
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
import org.xml.sax.SAXParseException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build a panel from an XML data source.
|
|
|
|
*/
|
|
|
|
public class XMLPageBuilder extends XMLWidgetBuilder {
|
|
|
|
static final String id_attr = "id";
|
|
|
|
static final String label_attr = "label";
|
|
|
|
static final String separator_attr = "separator";
|
|
|
|
static final String radio_attr = "radio";
|
|
|
|
static final String group_attr = "group";
|
|
|
|
static final String accel_attr = "accel";
|
|
|
|
static final String type_attr = "type";
|
|
|
|
static final String dialog_tag = "dialog";
|
|
|
|
static final String panel_tag = "panel";
|
|
|
|
static final String input_tag = "input";
|
1999-06-21 09:28:04 +00:00
|
|
|
static final String label_tag = "label";
|
1999-11-29 00:44:34 +00:00
|
|
|
static final String image_tag = "image";
|
1999-02-09 08:06:09 +00:00
|
|
|
static final String layout_attr = "layout";
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-19 09:02:35 +00:00
|
|
|
PageUI component;
|
1999-02-09 08:06:09 +00:00
|
|
|
String title;
|
|
|
|
String id;
|
|
|
|
String attr;
|
1999-02-18 10:11:44 +00:00
|
|
|
PageModel model;
|
1999-02-19 09:02:35 +00:00
|
|
|
Hashtable group = new Hashtable();
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
/**
|
|
|
|
* Build a menu builder which operates on XML formatted data
|
|
|
|
*
|
|
|
|
* @param attr attribute
|
|
|
|
* @param id the value of the attribute to have a match
|
1999-02-18 10:11:44 +00:00
|
|
|
* @param model the page model for the page to be created
|
1999-02-09 08:06:09 +00:00
|
|
|
*/
|
1999-02-18 10:11:44 +00:00
|
|
|
public XMLPageBuilder(String attr, String id, PageModel model) {
|
1999-02-09 08:06:09 +00:00
|
|
|
this.attr = attr;
|
|
|
|
this.id = id;
|
1999-02-18 10:11:44 +00:00
|
|
|
this.model = model;
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
/**
|
|
|
|
* Read the input stream and build a menubar from it
|
|
|
|
*
|
|
|
|
* @param stream the stream containing the XML data
|
|
|
|
*/
|
1999-06-21 09:28:04 +00:00
|
|
|
public JComponent buildFrom(InputStream stream) {
|
1999-02-09 08:06:09 +00:00
|
|
|
XmlDocument doc;
|
|
|
|
TreeWalker tree;
|
|
|
|
Node node;
|
|
|
|
URL linkURL;
|
|
|
|
Element current;
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
try {
|
1999-03-01 00:09:16 +00:00
|
|
|
doc = XmlDocument.createXmlDocument(stream, false);
|
1999-02-09 08:06:09 +00:00
|
|
|
current = doc.getDocumentElement();
|
|
|
|
tree = new TreeWalker(current);
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-06-21 09:28:04 +00:00
|
|
|
// get the link tag for this file
|
|
|
|
// get into head and get the first element
|
1999-02-09 08:06:09 +00:00
|
|
|
node =
|
1999-06-21 09:28:04 +00:00
|
|
|
tree.getNextElement("head").getFirstChild().getNextSibling();
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
// set the configuration contained in this node
|
|
|
|
setConfiguration((Element)node);
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-06-21 09:28:04 +00:00
|
|
|
// skip to the body and find the element
|
|
|
|
current = findTargetElement(tree.getNextElement("body"));
|
|
|
|
|
|
|
|
if (current != null) {
|
|
|
|
component = (PageUI)buildFrom(current);
|
|
|
|
}
|
1999-02-09 08:06:09 +00:00
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
1999-06-21 09:28:04 +00:00
|
|
|
|
|
|
|
return component;
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
/**
|
1999-06-21 09:28:04 +00:00
|
|
|
* Locates the element targeted.
|
|
|
|
* @param element the element that contains all nodes to search
|
|
|
|
* @return the element matching the target description
|
1999-02-09 08:06:09 +00:00
|
|
|
*/
|
1999-06-21 09:28:04 +00:00
|
|
|
private Element findTargetElement(Element element) {
|
|
|
|
Node node = element.getFirstChild().getNextSibling();
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
while (node != null) {
|
1999-06-21 09:28:04 +00:00
|
|
|
// make sure we're looking at an ELEMENT_NODE
|
|
|
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
element = (Element)node;
|
|
|
|
|
|
|
|
// found it
|
|
|
|
if (element.getAttribute(attr).equals(id)) break;
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
1999-06-21 09:28:04 +00:00
|
|
|
|
|
|
|
// proceed to the next node in the tree
|
1999-02-09 08:06:09 +00:00
|
|
|
node = node.getNextSibling();
|
|
|
|
}
|
1999-06-21 09:28:04 +00:00
|
|
|
|
|
|
|
// we didn't find it otherwise we wouldn't be here.
|
|
|
|
return element;
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
1999-06-21 09:28:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Build a page from this element.
|
|
|
|
* @param element figure it out you twit
|
|
|
|
* @return the component built
|
|
|
|
*/
|
|
|
|
public JComponent buildFrom(Element element) {
|
|
|
|
Node node;
|
1999-11-29 00:44:34 +00:00
|
|
|
PageUI my_component = buildPanel((Element)element.getFirstChild().getNextSibling());
|
1999-06-21 09:28:04 +00:00
|
|
|
title = getReferencedLabel(element, "title");
|
|
|
|
|
|
|
|
return my_component;
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
1999-06-21 09:28:04 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
/**
|
1999-06-21 09:28:04 +00:00
|
|
|
* Build a panel.
|
|
|
|
* @param element the panel element
|
|
|
|
* @return the panel object as a PageUI type
|
1999-02-09 08:06:09 +00:00
|
|
|
*/
|
1999-06-21 09:28:04 +00:00
|
|
|
public PageUI buildPanel(Element element) {
|
1999-11-29 00:44:34 +00:00
|
|
|
Node node = element.getFirstChild().getNextSibling();
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-06-21 09:28:04 +00:00
|
|
|
PageUI my_component = new PageUI();
|
|
|
|
|
|
|
|
// every pageui in a dialog shares the same model. pageui just
|
|
|
|
// spec the layout.
|
|
|
|
my_component.setModel(model);
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-06-21 09:28:04 +00:00
|
|
|
// in the future, we'll determine what the layout manager is. for now,
|
|
|
|
// the only one we support is GridBagLayout
|
|
|
|
my_component.setLayout(new GridBagLayout());
|
|
|
|
|
|
|
|
while (node != null) {
|
|
|
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
element = (Element)node;
|
|
|
|
JComponent child = buildComponent(element);
|
|
|
|
GridBagConstraints cons = buildConstraints(element);
|
|
|
|
my_component.addCtrl(element.getAttribute("ID"), child, cons);
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-06-21 09:28:04 +00:00
|
|
|
node = node.getNextSibling();
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
1999-06-21 09:28:04 +00:00
|
|
|
|
|
|
|
return my_component;
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
|
|
|
private int parseGridConstant(String data) {
|
|
|
|
int result = 1;
|
|
|
|
|
|
|
|
try {
|
|
|
|
data = data.trim();
|
|
|
|
result = Integer.parseInt(data);
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
if (data.equals("remainder")) {
|
|
|
|
result = GridBagConstraints.REMAINDER;
|
|
|
|
} else if (data.equals("relative")) {
|
|
|
|
result = GridBagConstraints.RELATIVE;
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int parseFillConstant(String fill) {
|
|
|
|
int result = GridBagConstraints.NONE;
|
|
|
|
|
|
|
|
fill = fill.trim();
|
|
|
|
|
|
|
|
if (fill.equals("horizontal")) {
|
|
|
|
result = GridBagConstraints.HORIZONTAL;
|
|
|
|
} else if (fill.equals("vertical")) {
|
|
|
|
result = GridBagConstraints.VERTICAL;
|
|
|
|
} else if (fill.equals("both")) {
|
|
|
|
result = GridBagConstraints.BOTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1999-02-09 08:06:09 +00:00
|
|
|
|
1999-06-18 03:48:43 +00:00
|
|
|
private float parseWeightConstant(String weight) {
|
|
|
|
float result = 0.0f;
|
|
|
|
|
|
|
|
try {
|
|
|
|
result = Float.valueOf(weight).floatValue();
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
} finally {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
/**
|
|
|
|
* Build a constraint from the element's details.
|
|
|
|
*
|
|
|
|
* @param current the XML element containing constraint information.
|
|
|
|
* @return extracted constraints
|
|
|
|
*/
|
|
|
|
protected GridBagConstraints buildConstraints(Element current) {
|
|
|
|
GridBagConstraints constraints = new GridBagConstraints();
|
|
|
|
CustomInsets inset =
|
|
|
|
new CustomInsets(current.getAttribute("insets"));
|
|
|
|
|
1999-06-18 03:48:43 +00:00
|
|
|
constraints.weightx =
|
|
|
|
parseWeightConstant(current.getAttribute("weightx"));
|
|
|
|
|
1999-11-29 00:44:34 +00:00
|
|
|
constraints.weighty =
|
|
|
|
parseWeightConstant(current.getAttribute("weighty"));
|
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
// fill
|
1999-06-18 03:48:43 +00:00
|
|
|
constraints.fill = parseFillConstant(current.getAttribute("fill"));
|
|
|
|
|
|
|
|
constraints.gridwidth =
|
|
|
|
parseGridConstant(current.getAttribute("gridwidth"));
|
|
|
|
|
|
|
|
constraints.gridheight =
|
|
|
|
parseGridConstant(current.getAttribute("gridheight"));
|
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
constraints.insets = inset;
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
return constraints;
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
protected JComponent buildComponent(Element current) {
|
|
|
|
JComponent item = null;
|
|
|
|
String tag = current.getTagName();
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-06-21 09:28:04 +00:00
|
|
|
if (tag.equals(input_tag)) { // input tag
|
1999-02-09 08:06:09 +00:00
|
|
|
item = buildInput(current);
|
1999-06-21 09:28:04 +00:00
|
|
|
} else if (tag.equals(label_tag)) {
|
1999-02-09 08:06:09 +00:00
|
|
|
item = buildLabel(current);
|
1999-06-21 09:28:04 +00:00
|
|
|
} else if (tag.equals(panel_tag)) {
|
|
|
|
item = buildPanel(current);
|
1999-11-29 00:44:34 +00:00
|
|
|
} else if (tag.equals(image_tag)) {
|
|
|
|
item = buildImage(current);
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
return item;
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-03-30 00:30:33 +00:00
|
|
|
protected JPasswordField buildPasswordField(Element current) {
|
|
|
|
JPasswordField item = null;
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-03-30 00:30:33 +00:00
|
|
|
item = new JPasswordField();
|
|
|
|
textFieldAdjustments(item, current);
|
|
|
|
return item;
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-03-30 00:30:33 +00:00
|
|
|
private void textFieldAdjustments(JTextField item, Element current) {
|
1999-06-18 03:48:43 +00:00
|
|
|
String s = current.getAttribute("columns");
|
|
|
|
s = s.trim();
|
|
|
|
try {
|
|
|
|
int column = Integer.parseInt(s);
|
|
|
|
item.setColumns(column);
|
|
|
|
} catch (NumberFormatException nfe) {
|
1999-02-19 09:02:35 +00:00
|
|
|
}
|
1999-03-30 00:30:33 +00:00
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-03-30 00:30:33 +00:00
|
|
|
protected JTextField buildTextField(Element current) {
|
1999-06-21 09:28:04 +00:00
|
|
|
JTextField item = new JTextField();
|
1999-03-30 00:30:33 +00:00
|
|
|
textFieldAdjustments(item, current);
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
return item;
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
protected JRadioButton buildRadioButton(Element current) {
|
1999-06-21 09:28:04 +00:00
|
|
|
JRadioButton item = new JRadioButton();
|
1999-02-09 08:06:09 +00:00
|
|
|
String label = getReferencedLabel(current, "title");
|
1999-02-19 09:02:35 +00:00
|
|
|
String group_str = current.getAttribute("group");
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-06-21 09:28:04 +00:00
|
|
|
if (label.length() > 0) {
|
1999-02-09 08:06:09 +00:00
|
|
|
item.setText(label);
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-19 09:02:35 +00:00
|
|
|
// button group matters
|
1999-06-21 09:28:04 +00:00
|
|
|
if (group_str.length() > 0) {
|
|
|
|
ButtonGroup bg;
|
1999-02-19 09:02:35 +00:00
|
|
|
if (group.containsKey(group_str)) {
|
|
|
|
bg = (ButtonGroup)group.get(group_str);
|
|
|
|
} else {
|
|
|
|
bg = new ButtonGroup();
|
|
|
|
group.put(group_str, bg);
|
|
|
|
}
|
|
|
|
bg.add(item);
|
|
|
|
}
|
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
return item;
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-06-21 09:28:04 +00:00
|
|
|
private JComponent buildInput(Element current) {
|
1999-02-09 08:06:09 +00:00
|
|
|
JComponent item = null;
|
|
|
|
String type = current.getAttribute("type");
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
String ID = current.getAttribute("ID");
|
|
|
|
if (type.equals("radio")) { // radio type
|
|
|
|
item = buildRadioButton(current);
|
|
|
|
} else if (type.equals("text")) { // text type
|
|
|
|
item = buildTextField(current);
|
1999-03-30 00:30:33 +00:00
|
|
|
} else if (type.equals("password")) {
|
|
|
|
item = buildPasswordField(current);
|
1999-02-09 08:06:09 +00:00
|
|
|
} else if (type.equals("button")) { // buttons
|
1999-03-30 00:30:33 +00:00
|
|
|
item = buildButton(current);
|
1999-02-19 09:02:35 +00:00
|
|
|
} else if (type.equals("checkbox")) {
|
1999-03-30 00:30:33 +00:00
|
|
|
item = buildCheckBox(current);
|
1999-02-19 02:39:00 +00:00
|
|
|
} else if (type.equals("jlist")) {
|
|
|
|
item = buildList(current);
|
1999-11-29 00:44:34 +00:00
|
|
|
} else if (type.equals("combobox")) {
|
|
|
|
item = buildComboBox(current);
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-03-30 00:30:33 +00:00
|
|
|
protected JCheckBox buildCheckBox(Element current) {
|
|
|
|
return new JCheckBox(getReferencedLabel(current, "title"));
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-03-30 00:30:33 +00:00
|
|
|
protected JButton buildButton(Element current) {
|
|
|
|
JButton button = new JButton(getReferencedLabel(current, "title"));
|
|
|
|
button.addActionListener(model);
|
|
|
|
button.setActionCommand(getReferencedLabel(current, "command"));
|
|
|
|
return button;
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-19 02:39:00 +00:00
|
|
|
protected JList buildList(Element current) {
|
|
|
|
JList list = new JList();
|
|
|
|
return list;
|
|
|
|
}
|
1999-02-09 08:06:09 +00:00
|
|
|
|
1999-11-29 00:44:34 +00:00
|
|
|
protected JComboBox buildComboBox(Element current) {
|
|
|
|
JComboBox combobox = new JComboBox();
|
|
|
|
return combobox;
|
|
|
|
}
|
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
protected JLabel buildLabel(Element current) {
|
|
|
|
JLabel label = new JLabel(getReferencedLabel(current, "title"));
|
|
|
|
return label;
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-11-29 00:44:34 +00:00
|
|
|
protected JLabel buildImage(Element current) {
|
|
|
|
URL iconURL = ref.getResource(getReferencedLabel(current, "href"));
|
|
|
|
JLabel label = new JLabel(new ImageIcon(iconURL));
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
public JPanel getComponent() {
|
|
|
|
return component;
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
public String getTitle() {
|
|
|
|
return title;
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
1999-02-09 08:06:09 +00:00
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
javax.swing.JFrame frame = new javax.swing.JFrame("Foo bar");
|
1999-02-18 10:11:44 +00:00
|
|
|
PageModel model = new PageModel();
|
|
|
|
XMLPageBuilder builder = new XMLPageBuilder(args[0], args[1], model);
|
1999-02-09 08:06:09 +00:00
|
|
|
URL url = builder.getClass().getResource("dialogs.xml");
|
|
|
|
builder.buildFrom(url.openStream());
|
|
|
|
JPanel panel = builder.getComponent();
|
|
|
|
JDialog dialog = new JDialog();
|
1999-06-18 03:48:43 +00:00
|
|
|
|
|
|
|
dialog.getContentPane().setLayout(new java.awt.GridBagLayout());
|
|
|
|
dialog.getContentPane().add(panel, null);
|
1999-02-09 08:06:09 +00:00
|
|
|
dialog.setTitle(builder.getTitle());
|
|
|
|
dialog.pack();
|
|
|
|
dialog.setVisible(true);
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
|
|
|
|
}
|
1999-02-09 08:06:09 +00:00
|
|
|
|
1999-06-18 03:48:43 +00:00
|
|
|
class CustomInsets extends Insets {
|
|
|
|
CustomInsets(String inset) {
|
|
|
|
super(0, 0, 0, 0);
|
|
|
|
|
|
|
|
inset = inset.trim();
|
|
|
|
|
|
|
|
if (inset != null && inset.length() >= 9
|
|
|
|
&& (inset.charAt(0) == '['
|
1999-02-09 08:06:09 +00:00
|
|
|
|| inset.charAt(inset.length() - 1) == ']')) {
|
1999-06-18 03:48:43 +00:00
|
|
|
inset = inset.substring(1, inset.length() - 1);
|
|
|
|
int[] val = parseInset(inset); // guaranteed to be a length of 4
|
|
|
|
|
|
|
|
top = val[0];
|
1999-02-09 08:06:09 +00:00
|
|
|
left = val[1];
|
|
|
|
bottom = val[2];
|
|
|
|
right = val[3];
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private int[] parseInset(String inset) {
|
|
|
|
// if all else fails, it's 0
|
|
|
|
int[] val = { 0, 0, 0, 0 };
|
|
|
|
StringTokenizer tok = new StringTokenizer(inset, ",");
|
1999-02-09 08:06:09 +00:00
|
|
|
|
1999-06-18 03:48:43 +00:00
|
|
|
// assign the values into
|
|
|
|
for (int i = 0; i < val.length; i++) {
|
|
|
|
try {
|
|
|
|
String s = tok.nextToken();
|
|
|
|
val[i] = Integer.parseInt(s);
|
|
|
|
} catch (NoSuchElementException nse) {
|
|
|
|
// ignore. if it's fubared, we use 0 as the value
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
// ignore. if it's fubared, we use 0 as the value
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
|
|
|
}
|
1999-06-18 03:48:43 +00:00
|
|
|
return val;
|
1999-02-09 08:06:09 +00:00
|
|
|
}
|
|
|
|
}
|