JSyntax Color


Contact : http://www.japisoft.com/contact.html


JSyntaxColor is a library  for coloring in real time user text input. It works with a set of file descriptor defining a relation between expression and user view (a color, underline, border...). Java, Javascript, SQL and Formula samples are provided.

Main features :
JSyntaxColor is a shareware, it is free to try for 30 days, else you must register for a low price the full version at : http://www.japisoft.com/buy.html. By registring you have a royalty free license and you can include JSyntaxColor with all your product.

I. Usage

Here a straightforward way for supporting coloring in a JEditorPane.

JEditorPane ed = new JEditorPane();
ScEditorKit ek = new ScEditorKit();
ed.setEditorKit( ek );
ek.readSyntaxColorDescriptor( "sql.prop" );
ed.setText( ... )

ScEditorKit reads a property file describing a format file (syntax and color).  This propery file is available by two ways :
Some property file samples are available in the lib directory : sql.prop, java.prop and formula.prop.

Note : We don't recommend to use setPage from the JEditorPage due to a mapping to custom EditorKits depending on the content-type of the loaded document. For XML usage, We advise you to use JXMLPad at http://www.japisoft.com/xmlpad.

II. Property file

Here a sample of property file for coloring formula


This file is composed of a set of line containing key=value element. The key part can start with
token_, color_, underline_ and border_ and end by an ID. In the previous sample, we have 3 ID
(op, number1 or cst). So, the first key part is reserved word and the last one is user choice (the ID).

Define a list of keywords and link it to ID
Define a color for ID
Decide to underline or not ID with the color of ID or the default one
Decide to draw a rectangle around ID with the color of ID or the default one
Set of characters before a token for validiting it
Set of characters after a token for validating it
ignoreTokenMatch_ID We ignore the characters before or after the tokens from token_ID
Target of the current property file. This is mainly useful for the GUI usage.

The value part have different meaning depending on the key type.

- token_ID :

value have 5 formats:

- color_ID :

value have 2 formats:

- underline_ID or border_ID :

value is a boolean : true or false

If you wish not to take into account the upper or lower case for the token value a property 'ignoreCase' is available.

- tokenMatchIni :

value is a set of characters like : "\ \t([{" meaning a token from the token_ID list is valid only if it is preceding by the blank caracter (\ ) or the tab character (\t) or the caracters '[', '(' or '{'.

This value is useful for avoiding conflicts with token detection like if you use a variable name in your language source that matches a key word.

- tokenMatchtEnd :

This is similar to tokenMatchIni, except that this is only for characters after a detected token.

This value is useful for avoiding conflicts with token detection. As sample if you have a key word 'AND' and you wish to use a variable
name 'AND1', then with a non empty tokenMatchEnd it will detect that AND from the AND1 is not a key word.

- ignoreTokenMatch_ID :

Sometimes the preceding rules for bad tokens detection should be ignored. This is often the case for operators and delimiters.

Here a complete SQL sample :

tokenMatchIni=\ \t([
tokenMatchEnd=\ \t)];=

Remarks : All provided sample may be complete depending on your context (SQL version...) and wishes (color, UI properties...).

Special tokens

In some cases, we would prefer to insert a ':' or '\n' (carriage return) caracters. But there's a little scope problem between the property file and the wished elements. That's why, JSyntaxColor includes special tokens avoiding conflicts with the descriptor format.

_RC_ : Carriage return, equals to '\n'
_DD_ : Double dot, equals to ':'

As sample here the Java '//' comment description :


III. Language modeling

JSyntaxColor is provided with a complete GUI "modeler" for building/updating property file syntax descriptor.


The modeler lists and edits available language descriptors from the lib directory.
The first top part helps you to choose a language or to manage it with the following buttons :

- New : Create a new language descriptor. You have to choose a name like 'bsh'.
- Delete : Delete the current one, if you want to delete a new one, you have to reload the application
- Save : Save the current one
- Info : Update the language descriptor

You must know that you loose your language descriptor changes if you don't save it and if
you select a new language from the top list.

You have two ways for editing your language descriptor :

1. The Descriptor tab

You have to select, create or remove a list of token like the keyword2 from the previous SQL property file sample. This list
is shown inside the central list. You can remove, add a new element for this list with the add Token and remove Token buttons. Each time you select an element from the list a textfield is updated below. If you want to change the current token element, you just have to press enter in the textfield.
GUI features are available in the bottom of the UI, just select a color by pressing the color button or select the underline or border checkbox.
Match ini delimiters and Match end delimiters are list of characters for avoiding token bad detection. It means that a token is valid only if if begins with one character of the Match ini delimiters and if it terminates with one character of the Match end delimiters.

2. The Property file tab


This property file is editable, you can validate it by changing of tab.

The last Test tab is a simple editor including your language descriptor and you can write sequence of characters for evaluating your descriptor choice.

(c) 2003 - 2004 JAPISoft