1 19 20 package general; 21 22 import javax.swing.JEditorPane ; 23 import javax.swing.SwingUtilities ; 24 import javax.swing.text.DefaultEditorKit ; 25 import javax.swing.text.EditorKit ; 26 import javax.swing.text.html.HTMLEditorKit ; 27 import javax.swing.text.rtf.RTFEditorKit ; 28 import org.netbeans.junit.NbTestCase; 29 import org.openide.text.CloneableEditorSupport; 30 31 35 public class EditorKitsRegistryTest extends NbTestCase { 36 37 38 public EditorKitsRegistryTest(String name) { 39 super(name); 40 } 41 42 public void testHTMLEditorKits() { 43 JEditorPane pane = new JEditorPane (); 44 setContentTypeInAwt(pane, "text/html"); 45 46 EditorKit kitFromJdk = pane.getEditorKit(); 48 assertNotNull("Can't find JDK kit for text/html", kitFromJdk); 49 assertTrue("Wrong JDK kit for text/html", kitFromJdk instanceof HTMLEditorKit ); 50 51 EditorKit kitFromNb = CloneableEditorSupport.getEditorKit("text/html"); 53 assertNotNull("Can't find Nb kit for text/html", kitFromNb); 54 assertEquals("Wrong Nb kit for text/html", 55 "org.netbeans.modules.editor.html.HTMLKit", kitFromNb.getClass().getName()); 56 } 57 58 public void testPlainEditorKits() { 59 JEditorPane pane = new JEditorPane (); 63 pane.setEditorKit(new DefaultEditorKit () { 64 public String getContentType() { 65 return "text/whatever"; 66 } 67 }); 68 setContentTypeInAwt(pane, "text/plain"); 69 70 EditorKit kitFromJdk = pane.getEditorKit(); 72 assertNotNull("Can't find JDK kit for text/plain", kitFromJdk); 73 assertEquals("The kit for text/plain should not be from JDK", 74 "org.netbeans.modules.editor.plain.PlainKit", kitFromJdk.getClass().getName()); 75 76 EditorKit kitFromNb = CloneableEditorSupport.getEditorKit("text/plain"); 78 assertNotNull("Can't find Nb kit for text/plain", kitFromNb); 79 assertEquals("Wrong Nb kit for text/plain", 80 "org.netbeans.modules.editor.plain.PlainKit", kitFromNb.getClass().getName()); 81 } 82 83 public void testTextRtfEditorKits() { 84 JEditorPane pane = new JEditorPane (); 85 setContentTypeInAwt(pane, "text/rtf"); 86 87 EditorKit kitFromJdk = pane.getEditorKit(); 89 assertNotNull("Can't find JDK kit for text/rtf", kitFromJdk); 90 assertTrue("Wrong JDK kit for application/rtf", kitFromJdk instanceof RTFEditorKit ); 91 } 92 93 public void testApplicationRtfEditorKits() { 94 JEditorPane pane = new JEditorPane (); 95 setContentTypeInAwt(pane, "application/rtf"); 96 97 EditorKit kitFromJdk = pane.getEditorKit(); 99 assertNotNull("Can't find JDK kit for application/rtf", kitFromJdk); 100 assertTrue("Wrong JDK kit for application/rtf", kitFromJdk instanceof RTFEditorKit ); 101 } 102 103 private void setContentTypeInAwt(final JEditorPane pane, final String mimeType) { 104 try { 105 SwingUtilities.invokeAndWait(new Runnable () { 106 public void run() { 107 pane.setContentType(mimeType); 108 } 109 }); 110 } catch (Exception e) { 111 e.printStackTrace(); 112 fail("Can't set content type in AWT: " + e.getMessage()); 113 } 114 } 115 } 116
| Popular Tags
|