Tutorial of Hello World Plug-in

HelloWorld.java   MMM.jar

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 required classes:

import javax.swing.*;
import java.awt.event.*;
import cagt.bu.visant.plugin.AbstractVisANTPlugin;
  • Create a construct with no parameter. In the construct we create two menus (In reality only one menu is enough, we create two just to demonstrate the function of addToMenu

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");
   }
}
  • Finally, we overwrite the function about to introduce this plug-in (HTML tags can be used to make the information colorful):

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>&nbsp; </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.

Tutorials of Network Randomization Plug-in

RandomizationPlugin    rand.jar

Network randomization is used to determine the statistical significance of network patterns. We implemented randomization as a plug-in to test of our plug-in architecture. To distinguish the plug-in of this tutorial, we remove the package information and rename the menu My Randomization

Here is the step-step explanation of the plug-in:

  • Import required classes. Because we need to randomize the network, we need to get the data model of the network, and then change it. Therefore this plug-in uses many more VisANT classes than the HelloWorld plug-in:

import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import cagt.bu.visant.plugin.AbstractVisANTPlugin;
import cagt.bu.visant.plugin.PluginManager;
import cagt.bu.visant.graphics.VisMainPanel;
import cagt.bu.visant.graphics.NetNode;
import cagt.bu.visant.graphics.VEdge;
import cagt.bu.visant.model.Linkage;
import cagt.bu.visant.misi.VisCounter;
  • Create a construct with no parameter. Similarly, we create two menus corresponding to different methods used for randomization of directed and undirected network, both menus are added to a JMenu named My Randomization which is then added to Plugins menu in VisANT

public RandomizationPlugin() {
   JMenu randomization=new JMenu("My Randomization");
   JMenuItem dRan=new JMenuItem("Randomize Directed Network");
   dRan.setActionCommand("directed");
   dRan.addActionListener(this);
   dRan.setToolTipText("Number of Nodes and their indegree and outdegree remain the same.");
   JMenuItem udRan=new JMenuItem("Randomize Undirected Network");
   udRan.setActionCommand("undirected");
   udRan.addActionListener(this);
   udRan.setToolTipText("Number of Nodes and Edges remain the same.");
   randomization.add(udRan);randomization.add(dRan);
   addToMenu(randomization);
}
  • Because the plug-in needs listen to the ActionEvent, 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. Please see the source code of the plug-in for detailed method on the randomization method.

public void actionPerformed(ActionEvent ae){
    //first, get the object that controls the network
   //which will used to get the data model that need to be changed
   VisMainPanel graph=PluginManager.getNetworkGraph();
   if (ae.getActionCommand().equals("directed")){
      randomDirected(graph);
   }else {
      randomUndirected(graph);
   }
   //update the network
   graph.redrawAll();
}
  • Because we use this plug-in as part of core function of VisANT and the function of this plug-in has been clearly described from the name of the menu, we did not overwrite the about function.

Compiling: Download RandomizationPlugin, 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 RandomizationPlugin.java

Packaging the plug-in: if you do not have a sub-directory named "plugins" under current directory, create it. Then run following command to package (the name of the package is your choice, we use rand.jar here):

jar -cf plugins\rand.jar RandomizationPlugin.class

This command will create rand.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 -jar  VisAnt.jar

The RandomizationPlugin should be automatically loaded into VisANT and you will find the corresponding menu under Plugins menu in VisANT.

For questions/suggestions about this tutorials, please email VisANT@zlab.bu.edu.