You'll find the source under the src folder of the archive.
Here is a break down of what the classes do and how you can use the library in your own projects:
The SyntaxTester is a NetBeans created Main application you can use to see and test how syntax highlighting works. Or you can just start the Jar file in the dist folder.
SyntaxKit: you need to set your JEditorPane control's editorKit to a new instance of this. Just pass the required language as a String to the SyntaxKit constructor:
jEdtTest.setEditorKit(new SyntaxKit("java"));
SyntaxView does all the ugly work of maintaining the Tokens List for the Document and drawing the highlighted document.
SyntaxStyle is used to store various data about the style to use for each TokenType.
And finally SyntaxStyles is just a map of Styles. It has one method to set a Graphics object with the needed Font and Color for a Token.
All the Lexers were created using JFlex and the sources for them are in the JFlex folder of the archive.
Have fun! and please let me know if you find it useful or for any feature requests.
5 comments:
This is very useful. Which SyntaxKits do you support? Only Java or XML, JavaScript, Groovy as well?
It supports all of the above, plus a language called TAL for HP NSK / Tandem.
Creating your own should be easy. All that is needed is to create a new Lexer instance and add it to the setLanguage method of SyntaxView.
The available lexers were all created using JFlex, and the sources are also available in the distribution.
Quite cool. But if you are in XML mode and the document is empty and you start typing < the editor does not show the <. Only if you type another char. Now we are waiting for autoindent and highlighting of braces :) Thanks for you work. Chris
This is great! I was thinking of implementing a something similar, as I was unhappy with the way jEdit was implemented - namely, it didn't follow the Swing architecture by using EditorKits etc. I won't have to implement it now!
I'm impressed with how snappy this is.
-Ken
@Chris:
Thanks for the bug report. The error was due to the default color being white, so it did not appear on white background. A release will be out shortly.
Autoindent and brace highlighting are on my to do list :). Should be fun to implement.
@Ken:
Thanks :-). I did some not so scientific benchmarks on several highlighters, including jEdit Syntax Package, and the GroovyShell syntax highlighters, and in those performance suffers after a few hundred lines. My implementation is much faster.
Post a Comment