Over a million developers have joined DZone.

Embedding a Visual HTML Editor in the NetBeans RCP

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

Getting the NetBeans RCP/DJ Native Swing integration to work with the FCKEditor or the CKEditor (the same lib, just renamed) is quite easy.

  1. After taking the steps described in the link above, to add CKEditor/FCKEditor support, you just download the CKEditor ZIP file or the FCKEditor ZIP file from http://ckeditor.com/download/

  2. Add the ZIP file to the classpath. I simply added the zip-file to the "DJSwing-Windows64" module, via Properties->Libraries->Wrapped Jars->Add Jar. That's it. Though, I would think that one might want to create a separate module for the  ZIP file if one wants to save some space. And one can also remove the samples from the ZIP file if one is so inclined.

  3. In your implementations of the "Browser" interface, change the "webBrowser" variable to an instance of "JHTMLEditor".

  4. Instantiate the "webBrowser" by means of the following:
  5. webBrowser = new 
    JHTMLEditor(
       JHTMLEditor.HTMLEditorImplementation.CKEditor, NSComponentOptions.destroyOnFinalization());
    It's possible to add options to the editor by just calling:
    JHTMLEditor.CKEditorOptions.setCustomJavascriptConfiguration("options...")
    So it would look something like this:
    webBrowser = new JHTMLEditor(
    JHTMLEditor.HTMLEditorImplementation.CKEditor,
    JHTMLEditor.CKEditorOptions.setCustomJavascriptConfiguration("yourCustomOptions..."),
    NSComponentOptions.destroyOnFinalization()
  6. To actually use the HTML editor, you would switch out the "browseTo(URL url)" in the Browser interface with two functions:
    public void setEditorContents(String htmlContent);
    public String getEditorContents();

    That way you would achieve loose coupling, instead of casting the Browser.getComponent() to a JHTMLEditor.

    Implementation:

        @Override
        public String getEditorContents() {
            return webBrowser.getHTMLContent();
        }
    
        @Override
        public void setEditorContents(String htmlContents) {
            webBrowser.setHTMLContent(htmlContents);
        } 
    

Result on Windows:

Result on Ubuntu:

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}