KickJava   Java API By Example, From Geeks To Geeks.

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


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: JTableDemo.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.XMLTableDefinition;
19 import org.dom4j.swing.XMLTableModel;
20
21 /**
22  * A sample program to build a JTable GUI from a dom4j Document
23  *
24  * @author <a HREF="mailto:jstrachan@apache.org">James Strachan </a>
25  * @version $Revision: 1.4 $
26  */

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

107
Popular Tags