Simple HTML Spell Checker for NetBeans
By Geertjan on Sep 15, 2006
My first experiment with Jazzy just reused the code found here within the context of a JEditorPane in a simple Java application, rather than a file on disk (which is what that source code provides for). Here's the result. One types in something in the JEditorPane...
...one then clicks "Spell" and then one can see the mistakenly spelled words (which, apparently, includes "Norway"):
Next I created a module, again using Sandip's framework for adding actions for working with editors. Here's the result:
It is still pretty simple—works on one line instead of on the whole document, doesn't allow for the exclusion of HTML tags, doesn't let you update the dictionary, and doesn't provide functionality for replacing the mispelled words. But the start is clearly there! If someone would like my sources, to extend them and make a fully fledged spell checker for HTML files, let me know and I'll pass the sources on to you.
PS: Two further enhancements would be (1) to color every wrongly spelled word in red (or underline them), (2) to add annotation support, so that each line with wrong words gets a little annotation in the left sidebar, so that lines containing wrong words can be identified more easily.
And here's an alternative approach, using Jazzy's DocumentWordTokenizer (instead of StringWordTokenizer, which didn't let me get the whole content of the document), and hyperlinks in the JEditorPane:
Now I need to work out how to get the item under the cursor. Not sure how to do that. When the 'hand' cursor clicks a hyperlink, something specific should happen for that hyperlink. However, I'm using a StringBuilder, so while each item in the list is a separate hyperlink, it is in one long string, obtained from the StringBuilder. That's where I'm stuck—not knowing how to parse the current location of the cursor (I guess I'd parse up to the linebreak, but how do I even get started parsing in the first place). I guess the best solution is to use the Output Window and its API instead...