Friday, November 14, 2008

JSyntaxPane on dzone

Greetjan Wielenga posted a very cool entry on dzone here.
It is very cool with nice screenshots and a mini how-to.
Many Thanks Greetjan.

I haven't blogged for a while. I'll try and keep up with writing a bit more than Java Code.

Thursday, July 17, 2008

Back to Bahrain! and a JSyntaxPane fix

Well, this is my last day in Jeddah, and tomorrow I'm on my way to Bahrain, inshallah.

I had some time at the hotel, and since they have very good high speed in-room internet, and I got my laptop, I fired up Ubuntu, got the latest NetBeans loaded and upgraded, and fixed an outstanding issue with JSyntaxPane. So now, it is bug free :-)

Monday, July 07, 2008

Darken web pages for easy reading

Personally, I prefer reading light text on dark background. Most web-pages use black text on white background, including this blog. I'll probably change the theme on this blog later, but I'm actually lazy because of this amazing tool. All you need to do is drag it on your bookmarks toolbar, and voila! One click, and all the text in the page will be grey on black, and links blue on black.

This only works on Firefox. Internet Explorer users; now you have another reason to switch ;-)

Here is the article and the bookmarklet.

Wednesday, July 02, 2008

Great Leaders

Joel Spolsky has a great article about Bill Gates, and being a great leader. It's not that long and definitely worth reading.
The main point is, to be a good and successful leader, you have to know what your company / department / ministry / whatever is doing. You must have passion about what you are doing. How many times have we seen unfit managers who have no clue what their sub-ordinates are doing?
Enough said...

Sunday, June 29, 2008

JSyntaxPane with more Languages

Some more free time and I had time to fix Java and Groovy Lexers to have better String handling. The older versions did not process String Escape Characters properly.

I also added Property file and SQL lexers and did some refactoring by moving the lexers in their own package.

The Build file was modified to also build the Java lexers from the flex files (you need the JFlex.jar file in your ant/lib folder for this to work).

This may be the last version for a while. I may not have time in the next few weeks to manage this.

The source is now available in the Source Tab and only the binary distribution is available as a download. You can still load and execute the Jar file. It will start the tester.

Have fun!

Monday, June 23, 2008

JSyntaxPane new version - now with auto indentation and undo/redo

I had some more free time to work on JSyntaxPane. I did some refactoring, that should not change the way to use it though.
Refactoring was done by creating a new SyntaxDocument to store the Tokens, instead of having the SyntaxView store them. The former way was actually very stupid!
The Document should know about its own tokens, and the View gets the tokens from the Document. That is how it is done now. And this way you can also retrieve data about the SyntaxDocument by knowing its EditorPane control. And no need for listeners!
The new SyntaxDocument also has built in undo and redo.
A new class SyntaxActions was also created with several useful TextActions thrown in. These include Smart and Java Indentation, and mapping the TAB / Shift-TAB to indent / unindent the selected lines. Also mapped the default undo / redo keys to behave properly.
I also modified the Test application, and now it will display the token details under the cursor. This is very helpful for debugging the lexers.

Also changed is the way Fonts are used. Now the font of the Component is used, and you can only change the style (bold/italic) and color. Which means that the entire EditorPane will have one single font face and size. This actually suites my taste, unlike Notepad++ which by default uses different fonts and sizes for comments.

Again, all you need to do is one line to set the EditorKit. All the above is done for you automatically.

Have a look at the Test Application using Java WebStart here. Java 1.5+ is needed.

Project home is on Google Code here.

Hmm.. what next? Scripting? Nah.. I'm probably done, for now. I needed a simple control to edit scripts in my Java Swing applications, and thats probably it. unless...



Wednesday, June 18, 2008

JSyntaxPane is born

Based on demand (can't say popular, yet), I just created a Google Project for JSyntaxPane. The NetBeans project is located as the main download.

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.

Just Google it!