KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > data > DOMAdapterUnitTest


1 /*
2  * $Id: DOMAdapterUnitTest.java,v 1.1 2004/08/05 01:29:18 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing.data;
9
10 import javax.xml.parsers.DocumentBuilder JavaDoc;
11 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
12
13 import java.awt.Dimension JavaDoc;
14 import java.awt.Point JavaDoc;
15 import javax.swing.JComponent JavaDoc;
16 import javax.swing.JFrame JavaDoc;
17 import javax.swing.JScrollPane JavaDoc;
18
19 import org.w3c.dom.Document JavaDoc;
20 import org.jdesktop.swing.JXTreeTable;
21
22 import org.jdesktop.swing.treetable.TreeTableModel;
23
24 /**
25  * DOMAdapterUnitTest
26  *
27  * @author Ramesh Gupta
28  */

29 public class DOMAdapterUnitTest extends junit.framework.TestCase {
30
31     public DOMAdapterUnitTest() {
32     super("DOMAdapterUnitTest");
33     }
34
35     public void testDummy() {
36     // XXX placeholder test. replace with a real unit test
37
}
38
39     public static void main(String JavaDoc[] args) {
40         try {
41         // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
42
}
43         catch (Exception JavaDoc ex) {
44
45         }
46
47         final TestCase[] testCases = createTestCases();
48         if (testCases.length > 0) {
49             // Automatically exit after last window is closed.
50
testCases[testCases.length - 1].frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
51
52             Point JavaDoc location = testCases[0].frame.getLocation();
53
54             for (int i = testCases.length - 1; i >= 0; i--) {
55                 location.translate(30, 30); // stagger frames
56
testCases[i].frame.setTitle("DOMAdapter Unit Test " + (i + 1));
57                 testCases[i].frame.setLocation(location);
58                 testCases[i].frame.setVisible(true);
59             }
60         }
61     }
62
63     /**
64      * For unit testing only
65      * @return
66      */

67     private static TestCase[] createTestCases() {
68         Document JavaDoc dom = null;
69         DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
70         dbf.setNamespaceAware(true);
71         dbf.setIgnoringComments(true);
72         try {
73             DocumentBuilder JavaDoc db = dbf.newDocumentBuilder();
74             dom = db.parse("test/XMLBugQuery4.xml");
75         }
76         catch (Exception JavaDoc ex) {
77             ex.printStackTrace();
78         }
79         final DOMAdapter treeTableModel = new DOMAdapter();
80         treeTableModel.bind(dom);
81
82         final TestCase[] testCases = new TestCase[] {
83             new TestCase(treeTableModel) {
84                 public JComponent JavaDoc define() {
85                     JXTreeTable treeTable = new JXTreeTable(model);
86                     treeTable.setShowGrid(true);
87                     return treeTable;
88                 }
89             },
90         };
91         return testCases;
92     }
93
94     private static abstract class TestCase {
95
96         public TestCase(TreeTableModel model) {
97             this.model = model;
98             this.frame = wrap(define());
99         }
100
101         public abstract JComponent JavaDoc define();
102
103         public JFrame JavaDoc wrap(JComponent JavaDoc component) {
104             final JFrame JavaDoc frame = new JFrame JavaDoc();
105             final JScrollPane JavaDoc scroller = new JScrollPane JavaDoc(component);
106             scroller.setPreferredSize(new Dimension JavaDoc(600, 304));
107             frame.getContentPane().add(scroller);
108             frame.pack();
109             frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
110             return frame;
111         }
112
113         public final TreeTableModel model;
114         public final JFrame JavaDoc frame;
115     }
116 }
117
Popular Tags