Statistics Plugin Template
From Gephi:Wiki
Custom NetBeans templates helps to create plug-ins in a few clicks. This tutorial shows how to generate a Statistics plug-in easily, and start coding directly the algorithm.
Contents |
Prerequisites
To follow this tutorial, you must previously have:
- The Gephi source code. See how to checkout the code.
- NetBeans installed. See how to configure it.
Step 1: Get the template
- Download the NBM file org-gephi-statistics-template.nbm
- Launch NetBeans
- Go to Netbeans Tools > Plugins > Downloaded and click on Add plugins...
- Select the NBM file and follow the instructions. If a timeout problem occurs, restart NetBeans and the plugin will be installed anyway.
Congrats! You're now ready to generate your first Statistics Plugin.
Step 2: Create a Statistics Plugin
- Choose File > New Project. The New Project wizard opens and displays the new module sample.
- In Projects with Existing Sources select MyMetric and click Next. The wizard panel appears. I will continue to call this module "MyMetric" in this tutorial.
- Type another name in the project name field. Select the location of an existing Gephi project. Click Finish. The Projects window opens and displays the newly created module sample.
- Expand the Gephi 0.7 beta project. Right-click on Modules, and select Add Existing.... Select MyMetric, Open Project, then validate.
- Right-click on the Gephi 0.7 beta project, then Clean and Build All to take the new module into account.
Here we are! Verify if everything goes: run Gephi, open a graph file, and open the Statistics Panel. You should see a new metric called "MyMetric" in Network Overview. You can even run it... :)
Step 3: Refactor
You are almost there! Let's customize the module:
- Expand the source tree of MyMetric. Right-click on the package
org.gephi.statistics.templatethen Refactor > Rename. Change it to something like "org.yourname.yourmetric" then click on Refactor. If the name is not refreshed in the NetBeans interface, restart it. - Expand this source package. You can see 4 files: MyMetrics.java, MyMetricsBuilder.java, MyMetricsPanel.java and MyMetricsUI.java
- For each one, right-click on it, then Refactor > Rename and change the string "MyMetric" to the real name of your module.
- Open MyMetricsBuilder.java and edit the return string of the
getName()method. - Open MyMetricsUI.java and edit the return string of the
getDisplayName()method. - If you plan to use an option panel, open MyMetricsPanel.java in Design view, click on the title and edit it.
Now, let the magic happens...
Step 4: Start to code!
Open MyMetric.java (which should have a different name now). Start to code inside the execute() method, then fill in getReport() to display the results. Remove isDirected() and setDirected() if your algorithm doesn't care about edge direction.
Voila!

