KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > JNTreeTableUnitTest


1 /*
2  * $Id: JNTreeTableUnitTest.java,v 1.4 2005/01/11 13:32:35 kleopatra 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.jdnc;
9
10 import java.awt.Color JavaDoc;
11 import java.awt.Dimension JavaDoc;
12 import java.awt.Point JavaDoc;
13 import javax.swing.JComponent JavaDoc;
14 import javax.swing.JFrame JavaDoc;
15 import javax.swing.ImageIcon JavaDoc;
16
17 import org.jdesktop.swing.JXSearchPanel;
18
19 import org.jdesktop.swing.decorator.AlternateRowHighlighter;
20 import org.jdesktop.swing.decorator.HierarchicalColumnHighlighter;
21 import org.jdesktop.swing.decorator.Highlighter;
22 import org.jdesktop.swing.decorator.HighlighterPipeline;
23 import org.jdesktop.swing.decorator.PatternHighlighter;
24 import org.jdesktop.swing.decorator.PatternFilter;
25 import org.jdesktop.swing.decorator.FilterPipeline;
26 import org.jdesktop.swing.decorator.Filter;
27 import org.jdesktop.swing.treetable.FileSystemModel;
28 import org.jdesktop.swing.treetable.TreeTableModel;
29
30 import org.jdesktop.jdnc.actions.CollapseAction;
31 import org.jdesktop.jdnc.actions.ExpandAction;
32
33 /**
34  * JNTreeTableUnitTest
35  *
36  * @author Ramesh Gupta
37  */

38 public class JNTreeTableUnitTest extends junit.framework.TestCase {
39
40     public JNTreeTableUnitTest(String JavaDoc name) {
41         super(name);
42     }
43
44     /**
45      * Basic instantiation test. Make sure that no exceptions are thrown
46      */

47     public void testInstantiate() {
48         JNTreeTable tt = new JNTreeTable();
49     }
50
51
52     /**
53      * Basic instantiation test. Make sure that no exceptions are thrown
54      */

55     public void testInstantiateWithFileSystemModel() {
56         TreeTableModel treeTableModel = new FileSystemModel();
57         JNTreeTable tt = new JNTreeTable(treeTableModel);
58     }
59
60     /*
61      * Test getModel
62      */

63     public void testGetTreeTableModel() {
64         JNTreeTable tt = new JNTreeTable();
65         assertNotNull(tt.getTreeTableModel());
66     }
67     /*
68      * Test setModel
69      */

70     public void testSetTreeTableModel() {
71         JNTreeTable tt = new JNTreeTable();
72         tt.setTreeTableModel(new FileSystemModel());
73     }
74
75
76     /*
77      * Test getTreeTable
78      */

79     public void testGetTreeTable() {
80         JNTreeTable ttable = new JNTreeTable();
81         assertNotNull(ttable.getTreeTableModel());
82     }
83
84
85     /*
86      * Test Highlighter
87      */

88     public void testPatternHighlighter() {
89         JNTreeTable tt = new JNTreeTable();
90         PatternHighlighter patternHighlighter =
91                        new PatternHighlighter(null, Color.red, null, 0, 0);
92
93         tt.setHighlighters(new HighlighterPipeline(new Highlighter[] {
94                         AlternateRowHighlighter.quickSilver,
95                         new HierarchicalColumnHighlighter(),
96                         patternHighlighter,
97                     }));
98
99     }
100
101
102     /*
103      * Test Filter
104      */

105     public void testPatternFilter() {
106         JNTreeTable tt = new JNTreeTable();
107         PatternFilter patternFilter = new PatternFilter("", 0, 0);
108         tt.setFilters(new FilterPipeline(new Filter[] {
109                         patternFilter,
110                         }));
111
112     }
113    
114     /*
115      * Test setCollapsedIcon
116      *
117      */

118     public void testSetCollapsedIcon() {
119        JNTreeTable tt = new JNTreeTable();
120        tt.setCollapsedIcon(new ImageIcon JavaDoc(
121             JNTreeTableUnitTest.class.getResource("resources/down.png")));
122     }
123  
124     /*
125      * Test setClosedIcon
126      *
127      */

128     public void testSetClosedIcon() {
129        JNTreeTable tt = new JNTreeTable();
130        tt.setClosedIcon(new ImageIcon JavaDoc(
131             JNTreeTableUnitTest.class.getResource("resources/down.png")));
132     }
133     /*
134      * Test setExpandedIcon
135      *
136      */

137     public void testSetExpandedIcon() {
138        JNTreeTable tt = new JNTreeTable();
139        tt.setExpandedIcon(new ImageIcon JavaDoc(
140             JNTreeTableUnitTest.class.getResource("resources/down.png")));
141     }
142     /*
143      * Test setLeafIcon
144      *
145      */

146     public void testSetLeafIcon() {
147        JNTreeTable tt = new JNTreeTable();
148        tt.setLeafIcon(new ImageIcon JavaDoc(
149             JNTreeTableUnitTest.class.getResource("resources/down.png")));
150     }
151     /*
152      * Test setOpenIcon
153      *
154      */

155     public void testSetOpenIcon() {
156        JNTreeTable tt = new JNTreeTable();
157        tt.setOpenIcon(new ImageIcon JavaDoc(
158             JNTreeTableUnitTest.class.getResource("resources/down.png")));
159     }
160
161
162
163
164   
165     public static void main(String JavaDoc[] args) {
166         try {
167             // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
168
}
169         catch (Exception JavaDoc ex) {
170
171         }
172
173         final TestCase[] testCases = createTestCases();
174         if (testCases.length > 0) {
175             // Automatically exit after last window is closed.
176
testCases[testCases.length - 1].frame.setDefaultCloseOperation(
177                                                                            JFrame.EXIT_ON_CLOSE);
178
179             Point JavaDoc location = testCases[0].frame.getLocation();
180
181             for (int i = testCases.length - 1; i >= 0; i--) {
182                 location.translate(30,30); // stagger frames
183
testCases[i].frame.setTitle("JNTreeTable Unit Test " + (i+1));
184                 testCases[i].frame.setLocation(location);
185                 testCases[i].frame.setVisible(true);
186             }
187         }
188     }
189
190     /**
191      * For unit testing only
192      * @return
193      */

194     private static TestCase[] createTestCases() {
195
196         final TreeTableModel treeTableModel = new FileSystemModel(); // shared
197

198         final TestCase[] testCases = new TestCase[] {
199             new TestCase(treeTableModel) {
200                 public JComponent JavaDoc define() {
201                     //PatternFilter patternFilter = new PatternFilter(0, null, 0);
202
PatternHighlighter patternHighlighter =
203                         new PatternHighlighter(null, Color.red, null, 0, 0);
204
205                     JNTreeTable treeTable = new JNTreeTable(model);
206                     treeTable.putClientProperty("JTree.lineStyle", "None");
207                     JXSearchPanel searchPanel = new JXSearchPanel();
208                     //searchPanel.setPatternFilter(patternFilter);
209
searchPanel.setPatternHighlighter(patternHighlighter);
210                     searchPanel.setTargetComponent(treeTable);
211
212                     treeTable.setRowHeight(22);
213                     treeTable.setRowMargin(1);
214                     treeTable.setHighlighters(new HighlighterPipeline(new Highlighter[] {
215                         AlternateRowHighlighter.quickSilver,
216                         new HierarchicalColumnHighlighter(),
217                         patternHighlighter,
218                     }));
219
220                     //treeTable.setFilters(new FilterPipeline(new Filter[] {
221
// patternFilter,
222
// }));
223
ExpandAction expand = new ExpandAction();
224                     expand.putValue("delegate", treeTable);
225                     treeTable.addAction(expand);
226                     CollapseAction collapse = new CollapseAction();
227                     collapse.putValue("delegate", treeTable);
228                     treeTable.addAction(collapse);
229                     treeTable.addToolBarComponent(searchPanel);
230                     return treeTable;
231                 }
232             },
233
234         };
235         return testCases;
236     }
237
238     private static abstract class TestCase {
239
240         public TestCase(TreeTableModel model) {
241             this.model = model;
242             this.frame = wrap(define());
243         }
244
245         public abstract JComponent JavaDoc define();
246
247         public JFrame JavaDoc wrap(JComponent JavaDoc component) {
248             final JFrame JavaDoc frame = new JFrame JavaDoc();
249             component.setPreferredSize(new Dimension JavaDoc(600, 304));
250             frame.getContentPane().add(component);
251             frame.pack();
252             frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
253             return frame;
254         }
255
256         public final TreeTableModel model;
257         public final JFrame JavaDoc frame;
258     }
259
260     private JNTreeTableUnitTest() {
261     }
262 }
263
Popular Tags