1 7 8 package org.jdesktop.swing.decorator; 9 10 import java.awt.Color ; 11 12 import junit.framework.TestCase; 13 14 import org.jdesktop.swing.JXTable; 15 16 public class HighlighterTest extends TestCase { 17 18 private Highlighter[] highlighters; 19 20 protected void setUp() { 21 highlighters = new Highlighter[] { 22 new AlternateRowHighlighter(Color.white, new Color (0xF0, 0xF0, 0xE0), null), 23 new PatternHighlighter(null, Color.red, "s.*", 0, 0) 24 }; 25 } 26 27 protected void tearDown() { 28 for (int i = 0; i < highlighters.length; i++) { 29 highlighters[i] = null; 30 } 31 highlighters = null; 32 } 33 34 38 public void testJavaDocExample() { 39 Highlighter[] highlighters = new Highlighter[] { 40 new AlternateRowHighlighter(Color.white, new Color (0xF0, 0xF0, 0xE0), null), 41 new PatternHighlighter(null, Color.red, "s.*", 0, 0) 42 }; 43 44 HighlighterPipeline highlighterPipeline = new HighlighterPipeline(highlighters); 45 JXTable table = new JXTable(); 46 table.setHighlighters(highlighterPipeline); 47 } 48 49 51 public void testAddRemoveHighlighter() { 52 HighlighterPipeline pipeline = new HighlighterPipeline(highlighters); 53 54 Highlighter hl = new PatternHighlighter(Color.blue, Color.red, "mark", 0, 0); 55 Highlighter hl2 = new PatternHighlighter(Color.white, Color.black, "amy", 0, 0); 56 57 pipeline.addHighlighter(hl); 59 60 Highlighter[] hls = pipeline.getHighlighters(); 61 62 assertTrue(hls.length == 3); 63 assertTrue(hls[2] == hl); 64 65 pipeline.addHighlighter(hl2, true); 67 68 hls = pipeline.getHighlighters(); 69 70 assertTrue(hls.length == 4); 71 assertTrue(hls[0] == hl2); 72 73 pipeline.removeHighlighter(hl); 75 76 hls = pipeline.getHighlighters(); 77 assertTrue(hls.length == 3); 78 for (int i = 0; i < hls.length; i++) { 79 assertTrue(hls[i] != hl); 80 } 81 82 pipeline.removeHighlighter(hl2); 84 85 hls = pipeline.getHighlighters(); 86 assertTrue(hls.length == 2); 87 for (int i = 0; i < hls.length; i++) { 88 assertTrue(hls[i] != hl2); 89 } 90 } 91 } 92 | Popular Tags |