1 33 34 package edu.rice.cs.util.swing; 35 36 import edu.rice.cs.drjava.DrJavaTestCase; 37 import edu.rice.cs.drjava.ui.ReverseHighlighter; 38 39 import javax.swing.*; 40 import javax.swing.text.Highlighter ; 41 import javax.swing.text.JTextComponent ; 42 import java.awt.*; 43 44 49 public class HighlightManagerTest extends DrJavaTestCase { 50 51 57 58 JTextComponent jtc; 59 Highlighter.HighlightPainter p, p1, p2; 60 HighlightManager hm; 61 62 public void setUp() throws Exception { 63 super.setUp(); 64 65 jtc = new JTextField(); 66 jtc.setHighlighter(new ReverseHighlighter()); 67 68 p = new ReverseHighlighter.DefaultHighlightPainter(Color.BLACK); 69 p1 = new ReverseHighlighter.DefaultFrameHighlightPainter(Color.RED, 2); 70 p2 = new ReverseHighlighter.DefaultHighlightPainter(Color.BLACK); 71 72 hm = new HighlightManager(jtc); 73 74 hm.addHighlight(0,0,p); 75 hm.addHighlight(0,1,p); 76 } 77 78 public void testAddRemove() { 79 hm.addHighlight(0,0,p); 80 hm.addHighlight(0,1,p); 81 assertEquals("HighlightManager add Test", 2, hm.size()); 82 hm.removeHighlight(0,0,p); 83 assertEquals("HighlightManager remove Test 1", 1, hm.size()); 84 hm.removeHighlight(0,1,p); 85 assertEquals("HighlightManager remove Test 1", 0, hm.size()); 86 } 87 88 public void testHighlightInfoEquals() { 89 HighlightManager.HighlightInfo hi1, hi2, hi3, hi4, hi5; 90 hi1 = hm.new HighlightInfo(0,0,p); 91 hi2 = hm.new HighlightInfo(0,0,p); 92 hi3 = hm.new HighlightInfo(0,1,p); 93 hi4 = hm.new HighlightInfo(0,0,p1); 94 hi5 = hm.new HighlightInfo(0,0,p2); 95 assertEquals("HighlightInfo equals test 1", hi1, hi2); 96 assertFalse("HighlightInfo equals test 2", hi1.equals(hi3)); 97 assertFalse("HighlightInfo equals test 3", hi1.equals(hi4)); 98 } 99 } 100 | Popular Tags |