1 7 8 package org.jdesktop.jdnc; 9 10 import java.awt.Color ; 11 import java.awt.Dimension ; 12 import java.awt.Point ; 13 import javax.swing.JComponent ; 14 import javax.swing.JFrame ; 15 import javax.swing.ImageIcon ; 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 38 public class JNTreeTableUnitTest extends junit.framework.TestCase { 39 40 public JNTreeTableUnitTest(String name) { 41 super(name); 42 } 43 44 47 public void testInstantiate() { 48 JNTreeTable tt = new JNTreeTable(); 49 } 50 51 52 55 public void testInstantiateWithFileSystemModel() { 56 TreeTableModel treeTableModel = new FileSystemModel(); 57 JNTreeTable tt = new JNTreeTable(treeTableModel); 58 } 59 60 63 public void testGetTreeTableModel() { 64 JNTreeTable tt = new JNTreeTable(); 65 assertNotNull(tt.getTreeTableModel()); 66 } 67 70 public void testSetTreeTableModel() { 71 JNTreeTable tt = new JNTreeTable(); 72 tt.setTreeTableModel(new FileSystemModel()); 73 } 74 75 76 79 public void testGetTreeTable() { 80 JNTreeTable ttable = new JNTreeTable(); 81 assertNotNull(ttable.getTreeTableModel()); 82 } 83 84 85 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 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 118 public void testSetCollapsedIcon() { 119 JNTreeTable tt = new JNTreeTable(); 120 tt.setCollapsedIcon(new ImageIcon ( 121 JNTreeTableUnitTest.class.getResource("resources/down.png"))); 122 } 123 124 128 public void testSetClosedIcon() { 129 JNTreeTable tt = new JNTreeTable(); 130 tt.setClosedIcon(new ImageIcon ( 131 JNTreeTableUnitTest.class.getResource("resources/down.png"))); 132 } 133 137 public void testSetExpandedIcon() { 138 JNTreeTable tt = new JNTreeTable(); 139 tt.setExpandedIcon(new ImageIcon ( 140 JNTreeTableUnitTest.class.getResource("resources/down.png"))); 141 } 142 146 public void testSetLeafIcon() { 147 JNTreeTable tt = new JNTreeTable(); 148 tt.setLeafIcon(new ImageIcon ( 149 JNTreeTableUnitTest.class.getResource("resources/down.png"))); 150 } 151 155 public void testSetOpenIcon() { 156 JNTreeTable tt = new JNTreeTable(); 157 tt.setOpenIcon(new ImageIcon ( 158 JNTreeTableUnitTest.class.getResource("resources/down.png"))); 159 } 160 161 162 163 164 165 public static void main(String [] args) { 166 try { 167 } 169 catch (Exception ex) { 170 171 } 172 173 final TestCase[] testCases = createTestCases(); 174 if (testCases.length > 0) { 175 testCases[testCases.length - 1].frame.setDefaultCloseOperation( 177 JFrame.EXIT_ON_CLOSE); 178 179 Point location = testCases[0].frame.getLocation(); 180 181 for (int i = testCases.length - 1; i >= 0; i--) { 182 location.translate(30,30); 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 194 private static TestCase[] createTestCases() { 195 196 final TreeTableModel treeTableModel = new FileSystemModel(); 198 final TestCase[] testCases = new TestCase[] { 199 new TestCase(treeTableModel) { 200 public JComponent define() { 201 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.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 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 define(); 246 247 public JFrame wrap(JComponent component) { 248 final JFrame frame = new JFrame (); 249 component.setPreferredSize(new Dimension (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 frame; 258 } 259 260 private JNTreeTableUnitTest() { 261 } 262 } 263 | Popular Tags |