Jaxe, your XML editor
Jaxe, your XML editor
Home pageSummaryPage for printing<-->

Creation of new Jaxe elements

Author: Damien Guillaume

A Jaxe element is a class derived from jaxe.JaxeElement, describing a display for a given XML element. Standard Jaxe elements are gathered in the jaxe.elements package. They correspond to display types in the configuration files (for instance, the type string corresponds to the Jaxe element jaxe.elements.JEString).

A new Jaxe element can be created by deriving a new class from jaxe.JaxeElement. It can then be used in a configuration file with the plugin type, with the class to be used:

<AFFICHAGE_ELEMENT element="aBooleanElement" type="plugin">
  <PARAMETRE nom="classe" valeur="JEBoolean"/>

Two methods must be defined in the Jaxe element: init and nouvelElement. Two other ones are only useful if starting and ending tags are used (as explained later): insPosition, and (if the element has attributes) majAffichage.

init is used for initialisation and to insert the Swing component in the text area. The parameters are the position where the element has to be inserted in the text, and the DOM node. Using these parameters, the component has to be inserted with the method JaxeElement.insertComponent(Position pos, JComponent comp).

It gets trickier if we want to use a component as a start tag and a component as an end tag, letting Jaxe handle recursively the descendants. The position in the text after the insertion of the start tag has to be obtained (it is returned by insertComponent), descendants have to be added with creerEnfants(Position), and the end tag has to be inserted with a new call to insertComponent (with the Position objects passed as a parameter to creerEnfants. The character style has then to be updated for the tags and the descendants, which means the start position had to be kept before the first insertComponent. Here is an example:

int startOffset = pos.getOffset();
Position newpos = insertComponent(pos, startTagComponent);
insertComponent(newpos, endTagComponent);
if (newpos.getOffset() - startOffset - 1 > 0) {
  SimpleAttributeSet style = attStyle(null);
  if (style != null)
    doc.setCharacterAttributes(startOffset, newpos.getOffset() - startOffset - 1, style, false);

The method nouvelElement is called when the user inserts a new element. It might have to ask for informations to the user (such as the attributes), and has to return the new DOM element. The dialog jaxe.DialogueAttributs can be used to ask for attribute values.

insPosition can be called to get the position where the cursor will be placed after the insertion of a new element. By default, the cursor is placed after the element, but it can be useful to place it between the start and end tags when they are used.

Finally, majAffichage is called to update the display when the attributes values have been changed in the attribute panel.


The following file is a Jaxe element for a boolean, using a checkbox as a display: JEBoolean.java. It can be compiled and put into a jar file to become a new plugin for Jaxe.

Previous pageNext page