 |
FesiForm
An XML based GUI builder. |
This introduction assumes that you know Swing and
XML to some reasonable level!
Main program
A main program is required to call FesiForm. There is a default main program
in FesiForm.java, which parses and load the user interface specified
by the first file parameter. It is useful to test a user interfaces. You
must create an input source (see your SAX driver or the source code of
FesiForm for information), create a FesiForm object (which may create an
EcmaScript interpreter if needed) and then call process on it.
The user interface is created from the XML specification.
Unless some script in the xml source show it to the user, it will not be
visible. You must call getById on the returned GuiContext
to get the main elements of user interface, and present it when suitable
to the user (using pack, show, etc...).
XML description
The details of the XML syntax is in the file gui.dtd, which should
be consulted. The top level document is a <gui>, which will
contain script, top level frames and top level dialogs. Top level elements
must be identified by a unique id.
Containers
Containters are elements which contain other elements (see the list of
gui.dtd). The contained element must be lexically scoped in the
container definition. Many container have a layout attribute,
which can take one of the following values:
-
null (then Bounds must be specified on components)
-
BorderLayout() or BorderLayout(hgap,vgap)
-
FlowLayout() or FlowLayout(align,hgap,vgap)
-
GridLayout(), GridLayout(rows,cols) or GridLayout(rows,cols,hgap,vgap)
-
BoxLayout(X_AXIS) or BoxLayout(Y_AXIS)
Container not at top level may have an optional id. They may be created
by a "creationScript", which must return a container of the same
class or a subclass of the defined type.
They may have a script attribute. The script is executed after the
container has been created and after it had its elements added. The script
is executed with "this" being the container. Additional parameters
can be set via the script.
Components
Component elements are empty (they must be closed by the /> sequence
- a common error is to forget the slash). They may have a unique id for
reference by the main java code or by the script. They may be created
by a "creationScript", which must return a container of the same
class or a subclass of the defined type.
Usually component may have a layout attribute, which is the
string parameter of the add routine, dependent of the layout manager
of the container. It has usually the form "North", "Top", or other case
sensitive values. If there is no layout attribute, then a simple add(component)
routine is called.
They may have a script attribute. The script is executed after the
component has been created and after it had been added to its container.
The script is executed with "this" being the component. Additional
parameters can be set via the script.
Script usage
Script based creation
Almost all elements can be created by a script. If an attribute creationScript
exists, the corresponding script is executed and the returned value must
be a Component of the appropriate class. Therefore components
of a subclass of an existing class can be created. It is possible as well
to use any object of a subclass of JComponent (in that case the
creationScript is mandatory).
Global scripts
A <gui> can have the first and the last element being a script
(in between are JFrame or JDialog elements).
The first script (which must be the first element of the <gui>)
is executed before the creation of the various user interface. It should
contain all definitions used by <script> or <creationScript>.
Because it is inconvenient to create lengthy script as attribute values
(you must escape quotes), most script valued attributes consist in little
more than the call of a function or the definition of an event handler,
which must be defined in the first global script.
The second script (which must be the last element of the <gui>)
is executed when the JFrame and JDialog components have
been created in memory. It can make other global initialization (for example
populating the elements of a list). It can as well complement the initialization
in case of circular references (see below). And it can even show the user
interface.
Each identified element (and all top level JFrame and JDialog
are identified) can be retrieved from a script using the routine getById(id).
This works from the <script> attribute of the creating element, to all
scripts executed after (except the creationScript of the creating element).
The same routine getById can be used from Java, on the GuiContext
returned by the process routine.
Tips
-
Forgetting the "this" in EcmaScript is a common error, which can easily
be unnoticed. Check if you have a missing "this" if your event handler
seems not to work or if you your code seem to have no impact. Unlike Java,
"this" is not a default place to look for a property in EcmaScript.
-
Use EcmaScript to link the actions of the user interface to the functions
of your program. This will provide the end user with a lot of customization
capabilities. For example if a codelet links the Open button action to
the open action of your program, a user could change the action to use
a code management package (as PVCS or RCS) to access the source.
-
Do not abuse the script language. A function longer than about a page should
probably be rewritten in Java. So should mouse trackink events. But there
is no performance problem if you do simple things in response to user actions.
Back to home page.
Last update: 10 July 1998