KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dom4j > samples > swing > JTableTool


1 /*
2  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
3  *
4  * This software is open source.
5  * See the bottom of this file for the licence.
6  *
7  * $Id: JTableTool.java,v 1.4 2005/01/29 14:53:14 maartenc Exp $
8  */

9
10 package org.dom4j.samples.swing;
11
12 import javax.swing.JFrame JavaDoc;
13 import javax.swing.JScrollPane JavaDoc;
14 import javax.swing.JTable JavaDoc;
15
16 import org.dom4j.Document;
17 import org.dom4j.io.SAXReader;
18 import org.dom4j.swing.XMLTableModel;
19
20 /**
21  * Displays an XML document in a JTable JTable GUI from a dom4j Document. The
22  * definition of the table is given using an XML descriptor document such as in
23  * xml/swing/.
24  *
25  * @author <a HREF="mailto:jstrachan@apache.org">James Strachan </a>
26  * @version $Revision: 1.4 $
27  */

28 public class JTableTool {
29
30     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
31         JTableTool sample = new JTableTool();
32         sample.run(args);
33     }
34
35     public void run(String JavaDoc[] args) throws Exception JavaDoc {
36         if (args.length <= 1) {
37             System.out.println("Usage: <tableXMLDescription> <xmlFileName>");
38             System.out.println();
39             System.out
40                     .println("This program displays a document in a Swing JTable given a table description");
41             System.out.println();
42             System.out
43                     .println("For example running this program as follows will display the servlets of a web.xml");
44             System.out
45                     .println(" java swing.JTableTool xml/swing/tableForWeb.xml xml/web.xml");
46             System.out
47                     .println("This example will display the periodic table in a JTable");
48             System.out
49                     .println(" java swing.JTableTool xml/swing/tableForAtoms.xml xml/periodic_table.xml");
50             return;
51         }
52
53         // parse document
54
SAXReader reader = new SAXReader();
55         Document definition = reader.read(args[0]);
56         Document document = reader.read(args[1]);
57
58         // build table model
59
XMLTableModel model = new XMLTableModel(definition, document);
60
61         // make the widgets
62
JTable JavaDoc table = new JTable JavaDoc(model);
63
64         JFrame JavaDoc frame = new JFrame JavaDoc("JTableTool: " + document.getName());
65         frame.setSize(300, 300);
66         frame.setLocation(100, 100);
67         frame.getContentPane().add(new JScrollPane JavaDoc(table));
68         frame.validate();
69         frame.setVisible(true);
70     }
71
72 }
73
74 /*
75  * Redistribution and use of this software and associated documentation
76  * ("Software"), with or without modification, are permitted provided that the
77  * following conditions are met:
78  *
79  * 1. Redistributions of source code must retain copyright statements and
80  * notices. Redistributions must also contain a copy of this document.
81  *
82  * 2. Redistributions in binary form must reproduce the above copyright notice,
83  * this list of conditions and the following disclaimer in the documentation
84  * and/or other materials provided with the distribution.
85  *
86  * 3. The name "DOM4J" must not be used to endorse or promote products derived
87  * from this Software without prior written permission of MetaStuff, Ltd. For
88  * written permission, please contact dom4j-info@metastuff.com.
89  *
90  * 4. Products derived from this Software may not be called "DOM4J" nor may
91  * "DOM4J" appear in their names without prior written permission of MetaStuff,
92  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
93  *
94  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
95  *
96  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
97  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
98  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
99  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
100  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
101  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
102  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
103  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
104  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
105  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
106  * POSSIBILITY OF SUCH DAMAGE.
107  *
108  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
109  *
110  * $Id: JTableTool.java,v 1.4 2005/01/29 14:53:14 maartenc Exp $
111  */

112
Popular Tags