1 7 8 package org.jdesktop.swing; 9 10 import java.util.regex.Pattern ; 11 12 import java.awt.Color ; 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.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.JXTreeTable; 24 import org.jdesktop.swing.decorator.PatternHighlighter; 25 import org.jdesktop.swing.treetable.DefaultTreeTableModel; 26 import org.jdesktop.swing.treetable.FileSystemModel; 27 import org.jdesktop.swing.treetable.TreeTableModel; 28 29 31 public class JXTreeTableUnitTest extends InteractiveTestCase { 32 33 private TreeTableModel treeTableModel; 34 35 public JXTreeTableUnitTest() { 36 super("JXTreeTable Unit Test"); 37 } 38 39 43 public void testRendererProperties() { 44 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 45 boolean expandsSelected = !treeTable.getExpandsSelectedPaths(); 47 boolean scrollsOnExpand = !treeTable.getScrollsOnExpand(); 48 boolean showRootHandles = !treeTable.getShowsRootHandles(); 49 boolean rootVisible = !treeTable.isRootVisible(); 50 treeTable.setExpandsSelectedPaths(expandsSelected); 52 treeTable.setScrollsOnExpand(scrollsOnExpand); 53 treeTable.setShowsRootHandles(showRootHandles); 54 treeTable.setRootVisible(rootVisible); 55 assertEquals("expand selected", expandsSelected, treeTable 57 .getExpandsSelectedPaths()); 58 assertEquals("scrolls expand", scrollsOnExpand, treeTable 59 .getScrollsOnExpand()); 60 assertEquals("shows handles", showRootHandles, treeTable 61 .getShowsRootHandles()); 62 assertEquals("root visible", rootVisible, treeTable.isRootVisible()); 63 treeTable.setTreeTableModel(new DefaultTreeTableModel()); 65 assertEquals("expand selected", expandsSelected, treeTable 67 .getExpandsSelectedPaths()); 68 assertEquals("scrolls expand", scrollsOnExpand, treeTable 69 .getScrollsOnExpand()); 70 assertEquals("shows handles", showRootHandles, treeTable 71 .getShowsRootHandles()); 72 assertEquals("root visible", rootVisible, treeTable.isRootVisible()); 73 74 } 75 76 80 public void testLineStyle() { 81 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 82 String propertyName = "JTree.lineStyle"; 83 treeTable.putClientProperty(propertyName, "Horizontal"); 84 JXTree renderer = (JXTree) treeTable.getCellRenderer(0, 0); 85 assertEquals(propertyName + " set on renderer", "Horizontal", renderer 86 .getClientProperty(propertyName)); 87 } 88 89 93 public void testArbitraryClientProperty() { 94 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 95 String propertyName = "someproperty"; 96 treeTable.putClientProperty(propertyName, "Horizontal"); 97 JXTree renderer = (JXTree) treeTable.getCellRenderer(0, 0); 98 assertNull(propertyName + " not set on renderer", renderer 99 .getClientProperty(propertyName)); 100 101 } 102 103 105 public void interactiveTestFilterAndLineStyle() { 106 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 107 treeTable.putClientProperty("JTree.lineStyle", "Angled"); 111 treeTable.setRowHeight(22); 112 treeTable.setRowMargin(1); 113 treeTable.setHighlighters(new HighlighterPipeline(new Highlighter[] { 114 AlternateRowHighlighter.quickSilver, 115 new HierarchicalColumnHighlighter(), 116 new PatternHighlighter(null, Color.red, "s.*", 117 Pattern.CASE_INSENSITIVE, 0, -1), })); 118 JFrame frame = wrapWithScrollingInFrame(treeTable, 119 "QuickSilver-, Column-, PatternHighligher and LineStyle"); 120 frame.setVisible(true); 121 } 122 123 public void interactiveTestFiltersAndRowHeight() { 124 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 125 treeTable.setRowHeight(22); 126 treeTable.setRowMargin(1); 127 treeTable.setHighlighters(new HighlighterPipeline(new Highlighter[] { 128 AlternateRowHighlighter.linePrinter, 129 new HierarchicalColumnHighlighter(), })); 130 JFrame frame = wrapWithScrollingInFrame(treeTable, 131 "LinePrinter-, ColumnHighlighter and RowHeight"); 132 frame.setVisible(true); 133 } 134 135 public void interactiveTestAlternateRowHighlighter() { 136 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 137 treeTable 138 .setHighlighters(new HighlighterPipeline( 139 new Highlighter[] { AlternateRowHighlighter.classicLinePrinter, })); 140 treeTable.setRowHeight(22); 141 treeTable.setRowMargin(1); 142 JFrame frame = wrapWithScrollingInFrame(treeTable, 143 "ClassicLinePrinter and RowHeight"); 144 frame.setVisible(true); 145 } 146 147 public void interactiveTestBackgroundHighlighter() { 148 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 149 treeTable.setHighlighters(new HighlighterPipeline(new Highlighter[] { 150 AlternateRowHighlighter.notePadBackground, 151 new HierarchicalColumnHighlighter(), })); 152 treeTable.setBackground(new Color (0xFF, 0xFF, 0xCC)); treeTable.setGridColor(Color.cyan.darker()); 154 treeTable.setRowHeight(22); 155 treeTable.setRowMargin(1); 156 treeTable.setShowHorizontalLines(true); 157 JFrame frame = wrapWithScrollingInFrame(treeTable, 158 "NotePadBackground- HierarchicalColumnHighlighter and horiz lines"); 159 frame.setVisible(true); 160 } 161 162 public void interactiveTestLedgerBackground() { 163 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 164 treeTable.setBackground(new Color (0xF5, 0xFF, 0xF5)); treeTable.setGridColor(Color.cyan.darker()); 166 treeTable.setRowHeight(22); 167 treeTable.setRowMargin(1); 168 treeTable.setShowHorizontalLines(true); 169 JFrame frame = wrapWithScrollingInFrame(treeTable, "LedgerBackground"); 170 frame.setVisible(true); 171 } 172 173 public void interactiveTestHierarchicalColumn() { 174 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 175 treeTable.setHighlighters(new HighlighterPipeline( 176 new Highlighter[] { new HierarchicalColumnHighlighter(), })); 177 JFrame frame = wrapWithScrollingInFrame(treeTable, 178 "HierarchicalColumnHigh"); 179 frame.setVisible(true); 180 } 181 182 public void interactiveTestIntercellSpacing1() { 183 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 184 treeTable.setIntercellSpacing(new Dimension (1, 1)); 185 treeTable.setShowGrid(true); 186 JFrame frame = wrapWithScrollingInFrame(treeTable, "Intercellspacing 1"); 187 frame.setVisible(true); 188 } 189 190 public void interactiveTestIntercellSpacing2() { 191 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 192 treeTable.setIntercellSpacing(new Dimension (2, 2)); 193 treeTable.setShowGrid(true); 194 JFrame frame = wrapWithScrollingInFrame(treeTable, "Intercellspacing 2"); 195 frame.setVisible(true); 196 } 197 198 public void interactiveTestIntercellSpacing3() { 199 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 200 treeTable.setIntercellSpacing(new Dimension (3, 3)); 201 treeTable.setShowGrid(true); 202 JFrame frame = wrapWithScrollingInFrame(treeTable, "Intercellspacing 3"); 203 frame.setVisible(true); 204 } 205 206 public void interactiveTestHighlighterRowHeight() { 207 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 208 treeTable.setHighlighters(new HighlighterPipeline( 209 new Highlighter[] { new Highlighter(Color.orange, null), })); 210 treeTable.setIntercellSpacing(new Dimension (15, 15)); 211 treeTable.setRowHeight(48); 212 JFrame frame = wrapWithScrollingInFrame(treeTable, 213 "Orange, IntercellSpacing15, big rowheight"); 214 frame.setVisible(true); 215 } 216 217 public void interactiveTestHighLighters() { 218 JXTreeTable treeTable = new JXTreeTable(treeTableModel); 219 treeTable.setIntercellSpacing(new Dimension (15, 15)); 220 treeTable.setRowHeight(48); 221 treeTable.setShowGrid(true); 224 treeTable.setHighlighters(new HighlighterPipeline( 225 new Highlighter[] { 226 new Highlighter(Color.orange, null), 227 new HierarchicalColumnHighlighter(), 228 new PatternHighlighter(null, Color.red, 229 ".*TreeTable.*", 0, 0), })); 230 JFrame frame = wrapWithScrollingInFrame(treeTable, "Highlighters"); 231 frame.setVisible(true); 232 } 233 234 240 protected void setUp() throws Exception { 242 super.setUp(); 243 treeTableModel = new FileSystemModel(); 244 } 245 246 public static void main(String [] args) { 247 JXTreeTableUnitTest test = new JXTreeTableUnitTest(); 248 try { 249 test.runInteractiveTests("interactive.*HighLighters"); 251 } catch (Exception ex) { 252 253 } 254 256 } 272 273 278 } 454 | Popular Tags |