1 7 8 package org.jdesktop.swing.data; 9 10 import javax.xml.parsers.DocumentBuilder ; 11 import javax.xml.parsers.DocumentBuilderFactory ; 12 13 import java.awt.Dimension ; 14 import java.awt.Point ; 15 import javax.swing.JComponent ; 16 import javax.swing.JFrame ; 17 import javax.swing.JScrollPane ; 18 19 import org.w3c.dom.Document ; 20 import org.jdesktop.swing.JXTreeTable; 21 22 import org.jdesktop.swing.treetable.TreeTableModel; 23 24 29 public class DOMAdapterUnitTest extends junit.framework.TestCase { 30 31 public DOMAdapterUnitTest() { 32 super("DOMAdapterUnitTest"); 33 } 34 35 public void testDummy() { 36 } 38 39 public static void main(String [] args) { 40 try { 41 } 43 catch (Exception ex) { 44 45 } 46 47 final TestCase[] testCases = createTestCases(); 48 if (testCases.length > 0) { 49 testCases[testCases.length - 1].frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 51 52 Point location = testCases[0].frame.getLocation(); 53 54 for (int i = testCases.length - 1; i >= 0; i--) { 55 location.translate(30, 30); 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 67 private static TestCase[] createTestCases() { 68 Document dom = null; 69 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 70 dbf.setNamespaceAware(true); 71 dbf.setIgnoringComments(true); 72 try { 73 DocumentBuilder db = dbf.newDocumentBuilder(); 74 dom = db.parse("test/XMLBugQuery4.xml"); 75 } 76 catch (Exception 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 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 define(); 102 103 public JFrame wrap(JComponent component) { 104 final JFrame frame = new JFrame (); 105 final JScrollPane scroller = new JScrollPane (component); 106 scroller.setPreferredSize(new Dimension (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 frame; 115 } 116 } 117 | Popular Tags |