Novocode Application Framework - Documentation
NAF consists of the following major components:
||GUI Widgets & Layout Managers
|Events and Models
||XML Resource Loader
|Eclipse Plugins: SWT & JFace
- Resource Management (package
ResourceManager can load resource files which contain descriptions of
ResourceLoader implementations can be
plugged in to support different description languages.
- XML Resource Loader (package
XMLResourceLoader can parse XML resource files. It is always available in newly
JSResourceLoader uses Mozilla Rhino to
- Color Management (package
Colors are represented in NAF by
PreciseColor objects which can contain 192-bit RGB and HSV colors.
These color objects can be modified with high precision by chains of
- Image Management (package
Images in NAF are represented by
IManagedImage objects from which SWT Images can be obtained
and released. Managed images are created by
- Custom SWT Controls and JFace Viewers and Providers (packages
These classes do not require any other parts of NAF and can be used independently as well.
- Events and Models (packages
There are separate model interfaces for reading and modifying different kinds of data (e.g. strings, numbers,
window positions) and matching default implementations. Applications can use these default implementations for
their view models or implement the model interfaces directly. Actions are sent by
IActionListeners which are usually implemented directly by applications. Some common
action listeners are provided as separate classes (e.g.
- GUI Widgets (package
All widgets inherit from
NGWidget (which in turn is a subclass of
Some widget classes can create a
WindowInstance object which represents a top-level widget (e.g.
an SWT Shell or TrayItem) which is managed by NAF.
- Layout Managers (package
NAF layout managers are subclasses of
NGLayout (a subclass of
are wrappers for SWT layout managers which allow layout and layout data properties to be set from NAF resource
files (just as
NGWidgets are wrappers for SWT widgets).
- Model Persistence (package
Persister classes implement the
IPersister interface. They are used to create XML representations
of models and restore model states from these XML representations.
Opening a window with NAF requires only a few lines of Java code (taken from
NAFApplication app = new NAFApplication(HelloExample.class);
app.runMainWindow(app.getResourceObject("hello.naf", IWindowInstanceWidget.class), null);
All NAF applications create one
NAFApplication object which manages the windows
and runs the SWT event queue. The
Class object which is passed to the
NAFApplication constructor is used as the base for resolving relative URLs.
A tree which describes a window is loaded with
app.getResourceObject() from the file
hello.naf which must be in the class path in the same package as
HelloExample.class. The second argument to
getResource() is the expected
type of the resource object, in this case
IWindowInstanceWidget (a GUI widget which
can be used to create a top-level window).
getResource() performs a type check, so you
get a proper error message (in a
NAFException) if the resource object is not what you
expect. The returned object is passed directly to
app.runMainWindow(). This is a
convenience method for simple applications which instantiates the window, opens it and runs the
event loop. The method returns when the last managed window has been disposed. Finally all
native resource associated with the application are disposed by calling
NAF resource files (
*.naf) are XML files which describe GUIs as a tree of Widget
elements. Here is the simple
hello.naf file used by
<?xml version="1.0" encoding="UTF-8"?>
<Shell title="HelloExample" resize="false" xmlns="http://www.novocode.com/namespaces/naf">
<Label text=" Hello, World ! " font="Arial Black, 0.5in" />
The first line is the usual header which is found in all XML files. The root element is named
Shell which translates to the class
elements in NAF resource files use the NAF namespace which is declared in the root element with
xmlns attribute (
The other attributes belong to the
NGShell widget. Quite obviously,
sets the window's title and
resize="false" makes the window non-resizable.
The window contains only one widget, a
com.novocode.naf.gui.NGLabel). The label's text is set with the
font attribute specifies the font for the label (in this case Arial
Black with a height of 0.5 inches). This attribute is available for all widgets but it may be
ignored in some cases (e.g. the font specified on a
Button will be used when the
button is used as a Control but not when it is used as a MenuItem).
Note that no layout has been specified for the Shell in this example, so the default
FillLayout will be used. This makes the Shell's client area the size of the Label.
The sample applications in the "examples" folder demonstrate most of the features of NAF. Here
is an overview of what you can expect from the individual applications:
Menus, Toolbars and Coolbars.
A simple web browser. Shows how to use the Browser control and how to connect its models
to a typical browser UI.
StringList, CLabelModel and FormLayout's invisibilityPolicy.
All system dialogs and system images.
Tree and Table controls, BackgroundTreeContentProvider.
MDI with the InternalShell and DesktopForm controls. This is a basic SWT application.
There are no NAF wrappers for InternalShell yet.
"hello.js.launch" to run it with JSRunner.
Using model persistence to store the state of a GUI.
A splash screen which is updated from a background thread.
Various controls and features. This is the testbed for most new controls.
Updating a typical progress dialog from a background thread; Using multiple image versions for a shell image.
An XPath explorer which allows you to evaluate XPath expressions on NAF widget trees, using a Tree control
and NAFNavigator. Also demonstrates the use of @ModelField and @ActionMethod annotations.
More documentation to follow...