Java Code Examples for javax.swing.JEditorPane#registerEditorKitForContentType()

The following examples show how to use javax.swing.JEditorPane#registerEditorKitForContentType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PartialReparseTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void setUp() throws Exception {
    super.setUp();
    SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
    // ensure JavaKit is present, so that NbEditorDocument is eventually created.
    // it handles PositionRefs differently than PlainDocument/PlainEditorKit.
    MockMimeLookup.setInstances(MimePath.get("text/x-java"),
            new Reindenter.Factory(), new JavaKit());
    SharedClassObject loader = JavaDataLoader.findObject(JavaDataLoader.class, true);

    SourceUtilsTestUtil.prepareTest(
            new String[] {
                "org/netbeans/modules/java/project/ui/layer.xml",
                "org/netbeans/modules/project/ui/resources/layer.xml"
            },
            new Object[] {loader/*, new VanillaPartialReparser()*/ /*, cpp*/}
    );

    JEditorPane.registerEditorKitForContentType("text/x-java", "org.netbeans.modules.editor.java.JavaKit");
    TestUtil.setupEditorMockServices();
}
 
Example 2
Source File: TreeRewriteTestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();

    // ensure JavaKit is present, so that NbEditorDocument is eventually created.
    // it handles PositionRefs differently than PlainDocument/PlainEditorKit.
    MockMimeLookup.setInstances(MimePath.get("text/x-java"),
            new Reindenter.Factory(), new JavaKit());

    SourceUtilsTestUtil.prepareTest(
            new String[]{
                "org/netbeans/modules/java/project/ui/layer.xml",
                "org/netbeans/modules/project/ui/resources/layer.xml"
            },
            new Object[]{}
    );

    JEditorPane.registerEditorKitForContentType("text/x-java", "org.netbeans.modules.editor.java.JavaKit");
    File cacheFolder = new File(getWorkDir(), "var/cache/index");
    cacheFolder.mkdirs();
    IndexUtil.setCacheFolder(cacheFolder);

    TestUtil.setupEditorMockServices();
    Main.initializeURLFactory();

}
 
Example 3
Source File: GeneratorTestMDRCompat.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    ClassPathProvider cpp = new ClassPathProvider() {
        public ClassPath findClassPath(FileObject file, String type) {
            if (type == ClassPath.SOURCE)
                return ClassPathSupport.createClassPath(getSourcePath());
                if (type == ClassPath.COMPILE)
                    return ClassPathSupport.createClassPath(new FileObject[0]);
                if (type == ClassPath.BOOT)
                    return BootClassPathUtil.getBootClassPath();
                return null;
        }
    };
    SharedClassObject loader = JavaDataLoader.findObject(JavaDataLoader.class, true);
    SourceLevelQueryImplementation slq = new SourceLevelQueryImplementation() {
        @Override public String getSourceLevel(FileObject javaFile) {
            return GeneratorTestMDRCompat.this.getSourceLevel();
        }
    };
    SourceUtilsTestUtil.prepareTest(new String[] {"org/netbeans/modules/java/source/resources/layer.xml"}, new Object[] {loader, cpp});
    MockMimeLookup.setInstances(MimePath.get("text/x-java"), new Reindenter.Factory());
    
    TestUtil.setupEditorMockServices();
    JEditorPane.registerEditorKitForContentType("text/x-java", "org.netbeans.modules.editor.java.JavaKit");
    File cacheFolder = new File(getWorkDir(), "var/cache/index");
    cacheFolder.mkdirs();
    IndexUtil.setCacheFolder(cacheFolder);
}
 
Example 4
Source File: GeneratorUtilitiesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    SharedClassObject loader = JavaDataLoader.findObject(JavaDataLoader.class, true);
    SourceUtilsTestUtil.prepareTest(new String[]{"org/netbeans/modules/java/source/resources/layer.xml", "META-INF/generated-layer.xml"}, new Object[]{loader/*, cpp*/});
    JEditorPane.registerEditorKitForContentType("text/x-java", "org.netbeans.modules.editor.java.JavaKit");
    Main.initializeURLFactory();
}
 
Example 5
Source File: TestJEditor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testJEditorPane() {

        try {

            JEditorPane.registerEditorKitForContentType("text/html", UserEditorKit.class.getName());
            EditorKit editorKit = JEditorPane.createEditorKitForContentType("text/html");

            if (!(editorKit instanceof UserEditorKit)) {
                throw new RuntimeException("Editor kit is not UserEditorKit!");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
Example 6
Source File: GeneratorTestBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void setUp() throws Exception {
    super.setUp();
    SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
    // ensure JavaKit is present, so that NbEditorDocument is eventually created.
    // it handles PositionRefs differently than PlainDocument/PlainEditorKit.
    MockMimeLookup.setInstances(MimePath.get("text/x-java"), 
            new Reindenter.Factory(), new JavaKit());
    dataDir = SourceUtilsTestUtil.makeScratchDir(this);
    FileObject dataTargetPackage = FileUtil.createFolder(dataDir, getSourcePckg());
    assertNotNull(dataTargetPackage);
    FileObject dataSourceFolder = FileUtil.toFileObject(getDataDir()).getFileObject(getSourcePckg());
    assertNotNull(dataSourceFolder);
    deepCopy(dataSourceFolder, dataTargetPackage);
    ClassPathProvider cpp = new ClassPathProvider() {
        public ClassPath findClassPath(FileObject file, String type) {
            if (type == ClassPath.SOURCE)
                return ClassPathSupport.createClassPath(new FileObject[] {dataDir});
                if (type == ClassPath.COMPILE)
                    return ClassPathSupport.createClassPath(new FileObject[0]);
                if (type == ClassPath.BOOT)
                    return BootClassPathUtil.getBootClassPath();
                return null;
        }
    };
    SharedClassObject loader = JavaDataLoader.findObject(JavaDataLoader.class, true);
    
    SourceUtilsTestUtil.prepareTest(
            new String[] {
                "org/netbeans/modules/java/project/ui/layer.xml", 
                "org/netbeans/modules/project/ui/resources/layer.xml",
                "META-INF/generated-layer.xml"
            },
            new Object[] {loader, cpp}
    );
    
    JEditorPane.registerEditorKitForContentType("text/x-java", "org.netbeans.modules.editor.java.JavaKit");
    File cacheFolder = new File(getWorkDir(), "var/cache/index");
    cacheFolder.mkdirs();
    IndexUtil.setCacheFolder(cacheFolder);
    ensureRootValid(dataDir.getURL());
    TestUtil.setupEditorMockServices();
    Main.initializeURLFactory();
}
 
Example 7
Source File: DefaultSyntaxKit.java    From visualvm with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Register the given content type to use the given class name as its kit
 * When this is called, an entry is added into the private HashMap of the
 * registered editors kits.  This is needed so that the SyntaxPane library
 * has it's own registration of all the EditorKits
 * @param type
 * @param classname
 */
public static void registerContentType(String type, String classname) {
    JEditorPane.registerEditorKitForContentType(type, classname);
    CONTENTS.add(type);
}