JavaFX SyntaxHighlighter

Posted: under JavaFX Technology.
Tags: , , , , ,

In a modern IDE(Integrated Development Environment), such as NetBeans or Eclipse, syntax elements of a programming language are usually shown in different colors and styles. On a web page, there are tools for highlighting the keywords. They are either client side or server side tools. The SyntaxHighlighter is a client side(javascript) tool to display keywords of a programming language in a particular style(bold, different color etc). It supports quite a few languages such as Java, C, C#, VB, Ruby, javascript. While I was recently writing articles on JavaFX, I found it necessary to come up with a syntax highlighter for JavaFX.


I did some search and found the reserved keywords, then modified the shBrushJava.js to be shBrushJavaFX.js. Now my articles can have highlighted JavaFX syntax. For example:

package pacman;
import java.lang.Math;
import pacman.MazeData;
import pacman.PacMan;

/**
 * @author Henry Zhang  http://www.javafxgame.com
 */

public class MoveDecision {

  // x and y of an intended move
  public var x: Number;
  public var y: Number;

  // evaluate if the move is valid and its score if it's valid
  public function evaluate(pacMan:PacMan, isHollow:Boolean): Void {
    if ( x < 1 or y < 1 or y >= MazeData.GRID_SIZE
         or x >= MazeData.GRID_SIZE){
      score = -1;
      return ;
    }
  }
 . . .
}


If you are interested in using this JavaFX highlighter, you can download the brush file: shBrushJavaFX.js and the CSS file: SyntaxHighlighter.css. Information about the original SyntaxHighlighter 1.5.1 can be found here: SyntaxHighlighter .


For those who are intersted in the reserved words (keywords) of JavaFX, you can find it here. For your convience, I list them below:

abstract after and as assert at attribute before bind bound break
catch class continue def delete else exclusive extends false finally
first for from function if import indexof in init insert instanceof
into inverse last lazy mixin mod new not null on or override
package postinit private protected public-init public public-read
replace return reverse sizeof static step super then this throw
trigger true try tween typeof var where while with



Comments (0) May 02 2009