* set up for different content types.
*/
public class ContentType implements Testlet {
public void test(TestHarness harness) {
JEditorPane pane = new JEditorPane();
harness.checkPoint ("Default EditorKits for content types");
harness.check
(pane.getEditorKitForContentType
("text/plain").getClass().getName(),
"javax.swing.JEditorPane$PlainEditorKit");
harness.check
(JEditorPane.getEditorKitClassNameForContentType("text/plain"),
"javax.swing.JEditorPane$PlainEditorKit");
harness.check
(pane.getEditorKitForContentType
("text/html").getClass(), HTMLEditorKit.class);
harness.check
(pane.getEditorKitForContentType
("text/rtf").getClass(), RTFEditorKit.class);
harness.check
(pane.getEditorKitForContentType
("application/rtf").getClass(), RTFEditorKit.class);
harness.checkPoint ("Registering an EditorKit for a content type");
harness.check
(pane.getEditorKitForContentType
("foobar").getClass().getName(),
"javax.swing.JEditorPane$PlainEditorKit");
harness.check (JEditorPane.getEditorKitClassNameForContentType("foobar") == null);
harness.check
(JEditorPane.createEditorKitForContentType("foobar") == null);
JEditorPane.registerEditorKitForContentType
("foobar", "javax.swing.text.html.HTMLEditorKit");
harness.check
(pane.getEditorKitForContentType("foobar").getClass(),
HTMLEditorKit.class);
harness.check
(JEditorPane.createEditorKitForContentType("foobar").getClass(),
HTMLEditorKit.class);
// Explicitly setting the EditorKit takes precedence over the
// registered type
pane.setEditorKitForContentType ("foobar", new RTFEditorKit());
harness.check
(pane.getEditorKitForContentType("foobar").getClass(),
RTFEditorKit.class);
// We can set the EditorKit for content types previously unintroduced
pane.setEditorKitForContentType ("tony", new RTFEditorKit());
harness.check
(pane.getEditorKitForContentType("tony").getClass(),
RTFEditorKit.class);
// But this only affects the instance of JEditorPane, not the class itself
harness.check (JEditorPane.createEditorKitForContentType("tony") == null);
}