Home
Categories
Dictionnary
Download
Project Details
Changes Log
FAQ
License

XUL document



The XULDocument is the class which represents one XUL file. It is returned by one of the following methods on the ScriptManager:

Swing widgets tree

The XUL document XULDocument.getRootComponent() return the XULSwingPanel component which is the root of the XUL document associated Swing widget tree. It can be used in any Swing widgets hierarchy.

Swing root widget


The root of the XUL document is a XULSwingPanel component which is a subclass of JPanel. You can put it in any Swing structure you want.

Additionnally, this class has the XULSwingPanel.addActionListener(XULActionListener) method to deal with events on widgets.

For example, suppose the following XUL file:

      <window title="Example" width="200" height ="200"
      xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">   
         <button id="myButton" value="Push Me!"/>
      </window>      

And the following java code which add this XUL file to the ScriptManager:

      ScriptManager manager = new DefaultScriptManager();
      XULDocument document = manager.addXULScript(<the XUL file>);

You can perform on the Swing root associated with the document:

      XULSwingPanel panel = document.getRootComponent();
      panel.addActionListener(new XULActionListener() {
        public void actionPerformed(XULActionEvent event) {
         System.out.println(event.getWidgetID() + " clicked");
        }
      });

Getting the current document

On Javascript scripts, the current docupenjt is always accessible by the document property, such as:

      var widget = document.getElementById("open");

On other script type, you can get it through the ScriptHelper:

      XULDocument doc = helper.getCurrentDocument();

Getting a widget in the tree

You can get any widget in the tree (providing it has an ID attribute) with the following method: On Javascript scripts, you can also use the document property, such as:

      var widget = document.getElementById("open");

You can get the current widget which is the source of the last user event by one of the following methods: You can get the current window which is the root of the widget which is at the origin of the last user event by: For example in Javascript:

      var widget = document.getcurrentWindow();

See also


Categories: api

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