|
This plug-in is simply
for the demonstration purpose. It creates two menus in VisANT. When
the menus are selected, a window pops up with "Hello VisANT Plugin".
The following figure shows the impact of this plug-in on VisANT and
corresponding functions:

Here is the step-step
explanation of the plug-in:
import javax.swing.*;
import java.awt.event.*;
import cagt.bu.visant.plugin.AbstractVisANTPlugin;
public HelloWorld() {
JMenuItem helloMenu=new JMenuItem ("Hello VisANT Expression");
helloMenu.addActionListener(this);
helloMenu.setActionCommand("expression");
//be aware that VisANT do not have a menu named "Expression", therefore
//following line will create a new menu in VisANT menubar
addToMenu(helloMenu, "Expression");
JMenuItem vhelloMenu=new JMenuItem ("Hello VisANT Plugins");
vhelloMenu.addActionListener(this);
vhelloMenu.setActionCommand("plugins");
//by default, the menu will be added under menu "Plugins"
addToMenu(vhelloMenu);
}
-
Because the plug-in
listens to the ActionEvent of the menu, we need to
implement the function specified by the ActionListener, in which we
determine the menu based on the action command set above and show
the corresponding message:
public void actionPerformed(ActionEvent ae){
if (ae.getActionCommand().equals("expression")){
JOptionPane.showMessageDialog(null, "Hello VisANT Expression");
}else {
JOptionPane.showMessageDialog(null, "Hello VisANT Plugins");
}
}
public String about(){
StringBuffer sb=new StringBuffer();
sb.append("<HTML><font color=\"#800080\"><b>Hello VisANT</b></font> Plugin<BR>");
sb.append("<p align=\"center\" >Author: <font color=\"#0000FF\">Zhenjun Hu</font> (zjhu@bu.edu)</P><BR>");
sb.append("This plugin is used for the demonstration purpose.<BR>");
sb.append("Be aware that VisANT plugins belong to the plugin author and<BR>");
sb.append("Plugin authors can distribute VisANT with plugins freely for no-profit purpose.<BR><BR>");
sb.append("To report bugs of the plugins, please either send email to plugins authors<BR>");
sb.append("or make a new post in VisANT discussion board:<BR><BR>");
sb.append("<a href=\"http://visant.bu.edu/discussion/\">http://visant.bu.edu/discussion/</a> </P><BR>");
sb.append("Plguin authors are encourage to open a new post for corresponding plugins.<BR><BR>");
sb.append("<p align=\"center\" >\u00A9 Free :D<BR></p></HTML>");
return sb.toString();
}
The implementation of
about function will add an additional about menu for this plug-in,
as shown in the figure at the beginning of this tutorial.
Compiling: Download
HelloWorld.java, and put it in the
same directory as VisAnt.jar, open a
does/shell window and go to the directory where there is VisAnt.jar.
use following command to compile:
javac -classpath .;VisAnt.jar
HelloWorld.java
Packaging the plug-in:
if you do not have a sub-directory named "plugins" under your
current directory, create it. Then run the following command to
package (the name of the package is your choice, we use MMM.jar
here):
jar -cf plugins\MMM.jar
HelloWorld.class
this command will
create MMM.jar under plugins directory,
Running VisANT: VisANT
can be started by double-mouse-clicking. If that does not work, run
following command to start (always using following command to run
VisANT if you need to debug your plug-in) :
java -classpath
VisAnt.jar VisAntApplet
The HelloWorld plug-in
should be automatically loaded into VisANT and you will find the
corresponding menu as shown in the beginning of this tutorial.
For
questions/suggestions about this tutorials, please email
VisANT@zlab.bu.edu.
|