Home
Categories
Dictionnary
Download
Project Details
Changes Log
FAQ
License

ScriptManager



The ScriptManager and its default implementation DefaultScriptManager is the main class which is responsible for managing XUL content.

Creating the ScriptManager

There is nothing special to do, you only have to use the constructor as:
      ScriptManager manager = new DefaultScriptManager();

Configuring the ScriptManager


The ScriptManager is usable as soon as it has been created, but several methods allow to configure how it will be used:
  • By default the parsing of XUL files will not check the validity of the files compared to the XUL grammar. it is possible to set the the files will be validated and also to popup a window if the validation is incorrect rather than show the errors on the command-line
  • By default errors encountered in the scripts (for example, a command which refer to a not existing script function) will be shown on the command-line. It is possible to set that they will be shown on an error window, with the associated Stack trace of the exception in the script
  • By default echo instructions (such as print in Javascript) encountered in the scripts will be shown on the command-line. it is possible to specify a logger to log the result of these instructions on a Swing component
  • By default scripts defined for a XUL file are local to this XUL file. However it is possible to specify that scripts are global to all XUL files
  • By default only Javascript scripts can be triggered by widget events. However it is possible to set that all scripts referenced in a XUL document can be triggered by widget events
  • We can set a custom ScriptContext to the manager
  • We can set a custom ScriptFactory to the manager to customize the interface the scripts will have to implement

Adding XUL files

Adding a XUL file can be performed through one of the following methods: By default the methods which do not use a name use the File or URL file name for the name of the script.

Each of these methods return the XULDocument which manage the UI tree for this XUL file.

Activating the ScriptManager

By default the ScriptManager is not active, which means that the XUL content is visible but the user events will not be wired to the scripts. To ensure that the events will be managed by the scripts, you just have to do:

      manager.setActive(true);

Note that the "onload" event will be sent for all windows element. This event will be sent for all XUL document windows when the ScriptManager is activated.

Example

      public class MyFrame extends JFrame {
      
        public MyFrame() {
          ScriptManager manager = new DefaultScriptManager();
          manager.addXULScript(<the XUL script file>);
          manager.install(this);
          manager.setActive(true);
        }
      
        public static void main(String args) {
          MyFrame frame = new MyFrame();
          frame.setVisible(true);      
        }      
      }

See also


Categories: api

Copyright 2008-2020 Herve Girod. All Rights Reserved. Documentation and source under the LGPL licence