Child pages
  • How to write a JAS3 Plugin
Skip to end of metadata
Go to start of metadata

Overview

JAS3 is based on the Freehep Application Framework, which provides a basic application framework into which extension modules, or "plugins" can be loaded. The application framework provides general purpose functionality, such as top level GUI (windows, menus etc.), help system, storing and retrieving user preferences etc. All of the data analysis specific functionality of JAS3 is provided by a set of extension modules. The functionality of JAS3 can be customized by adding, removing or replacing modules. In order to make this possible, direct interaction between modules is avoided as far as possible, instead modules communicate with each other via service interfaces and notification events. JAS3 comes with a standard set of service interfaces and notification events, but new modules can also define their own interfaces and events.

Writing a JAS3 Plugin

This document shows how to develop an extension (or "Plugin") for JAS3. In the tutorial we develop the extension in several phases, each phases shows a new feature of JAS3. The extension we develop does not do anything useful, it just aims to illustrate how to interface to the various capabilities of the JAS3 framework.

Developing an extension for JAS3 will require an understanding of Java itself and Swing (the Java GUI). You should also be familiar with running the java compiler, and building jar files using the jar tool. You can either do this using the line-mode tools which come with the Java SDK, or by using a suitable IDE. (The JAS team recommends the Netbeans IDE, but there is no requirement that you use this.) If you are not already familiar with these tools we suggest looking at Sun's Java tutorial, and developing at least a simple "Hello World" application in Swing before attempting to develop a JAS3 extension.

References:

Extensions vs Plugins

The JAS3 application is based on the FreeHEP application framework. If you were to run JAS3 with no extensions installed at all you would see a hollow application shell, looking something like this:

All of the useful functionality of JAS3 is provided by extensions. These are broken into two types:

  • Plugins: These are simple extensions that are always included with JAS3.
  • Extensions: These are typically more complex extensions, which can be optionally included with the JAS3 software.

Technically Plugins and Extensions are developed in exactly the same way, the only difference is that Plugins are normally packaged into the jas3.jar file, while extensions are distributed in their own separate jar file(s).

Write a simple Plugin

In this initial part of the tutorial we will develop a very simple extension which simply adds a "Hello World" item to the help menu. When this item is activated a dialog will appear. In this tutorial you will learn how to build and package extensions.

The source code for the first version of the HelloWorld extension is shown below.

As you can see this first version is very simple. There is a single class which extends Plugin.
All extensions must extend this class. For our purposes the class has one important method, Plugin.init(), which is overridden to install our menu item. In this method we create the new JMenuItem, and install it into the Help menu using the Plugin.addMenu(javax.swing.JMenuItem, long) method.

HelloWorldPlugin.java

To use this class as an extension you will also need to create a plugins.xml file which describes your extension to JAS3. Here is an example plugins.xml file for the HelloWorld extension. This file must be saved in a directory called PLUGIN-inf (please create it).

Finally you need to compile your java file, and package it into a jar file. The easiest way to do this is using ant, a make-like system commonly used by Java projects. Here is an ant build.xml file which will package up your extension into a HelloWorld.jar file, and then install the extension into JAS3.

Finally you should be able run JAS and see the new item in the Help menu. You should also be able to fire up the Plugin Manager (from the JAS3 View menu) to see that JAS3 has loaded your plugin.

Manipulating Windows

In this phase we will add a second way of displaying Hello World, this time we will open a window in the main JAS GUI, and display "Hello World!" there. Admittedly not a huge leap forward, but you will learn how to create JAS3 windows.

HelloWorldPlugin.java

Using the Console Service

In this next phase of the tutorial we will add extra code to log a message to the console each time a window is opened or closed. To do that we will make use of an indirect lookup of the console service, which is implemented by a different extension. The purpose of using the lookup is to isolate our extension from direct dependence on the console service, if the console service is not present our extension will still run, albeit with reduced functionality. In addition if in future an new improved console service is introduced our extension will continue to run correctly.

HelloWorldPlugin.java

Registering your own Services

HelloWorldPlugin.java
  • No labels