NetBeans Tips

From Gephi:Wiki
Jump to: navigation, search

Get familiar with Netbeans Platform

Checkout this article that gather useful recent references.

How to attach source for Library Wrapper Modules

You may ask yourself how is linked a library JAR in a Library Wrapper Module and the Netbeans Library Manager (Tools > Libraries). To link sources/javadoc you define in the Library Manager and your project, you must add to the Library Manager's CLASSPATH tab the JAR from the Wrapped Library (which is in the \release\modules\ext directory of your wrapper module).

Help -> Help contents -> Netbeans Modules -> Getting started -> Module and Rich-Client Application Tasks: Quick Reference -> Attach source code to libraries for debugging

If you plan to debug into library code, follow the second link.

How to disable Netbeans logs when executing a NBP Application

Add this option to the command line: -J-Dorg.netbeans.level=SEVERE

How to programatically close a NBP Application

LifecycleManager.getDefault().exit();

How to attach a TopComponent to a TopComponentGroup

Where you defined the group file MyGroup.wsgrp, create for each TopComponent a file MyTopComponent.wstcgrp containing:

<!DOCTYPE tc-group PUBLIC
  "-//NetBeans//DTD Top Component in Group Properties 2.0//EN"
  "http://www.netbeans.org/dtds/tc-group2_0.dtd">
 
<tc-group version="2.0">
    <module name="org.gephi.visualization" spec="1.0"/>
    <tc-id id="GraphTopComponent" />
    <open-close-behavior open="true" close="true" />
</tc-group>

Be careful the module name points on the location of the module root (where the GraphTopComponentWstcref.xml file is), not the location of the GraphTopComponent, which could be in a sub-package.

How to customize Gephi look and feel

Edit the file gephi/nbproject/project.properties and add --laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel to run.args.extra.

How to increase Heap Size for JUnit test

Go to the project.properties file of your module and add the following line:

test.run.args=-Xms128m -Xmx1400m

How to force the Gephi interface language

Edit the file gephi/nbproject/private/platform-private.properties and add --locale en:US to run.args.extra, or add the line:

run.args.extra=--locale en:US

How to use other modules in Unit Test

It is often needed to initialize some modules to be able to properly test some code. Hopefully Netbeans allows to add libraries for JUnit tests and therefore services normally present in Lookup.

In the module you have your test, see the Unit Test Librairies folder. Right click on it and do Add Unit Test Dependency.

Some classical modules to include to init basic features:

  • Project API - to create workspace
  • Attributes API & Attributes Impl - to get attributes working
  • Graph API & DHNSGraph & Collection Utils - to get graph model working

And here is the code to init a current workspace, with a GraphModel and an AttributeModel.

ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
projectController.newProject();
AttributeController attributeController = Lookup.getDefault().lookup(AttributeController.class);
AttributeModel attributeModel = attributeController.getModel();
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getModel();

How to integrate NetBeans to Windows 7

Install the SevenBeans module.

How to execute Gephi from Java, as an external program

see related forum topic: How do I show graph view in my own java UI app?

import java.io.File;
import java.io.InputStream;
 
public class GephiGraphView {
   /**
    * Executes gephi from the command-line to display a given graph.  This assumes that gephi is installed in the java.install.path.
    * Unfortunately the execute is different between windows and linux/mac so a different command exec string is required.
    * 
    * @param graphFile Graph to be displayed
    */
   public static void viewGraph(File graphFile){
 
      String gephiDir = System.getProperty("java.install.path") + File.separator + "gephi" + File.separator + "bin";
      String os = System.getProperty("os.name");
      try {
         ProcessBuilder pb;
 
         if (os.startsWith("Window")){
            String cmd = "\"" + gephiDir + File.separator + "gephi07beta.exe\" \"" + graphFile.getAbsolutePath() + "\"";            
            pb = new ProcessBuilder(cmd);
         }
         else {
            String file = graphFile.getAbsolutePath().replaceAll("\\b\\s\\b", "\\\\ ");
            pb = new ProcessBuilder("bash", "-c", gephiDir + File.separator + "gephi07beta " + file);
         }
         pb.directory(new File(gephiDir));
         pb.redirectErrorStream(true); // use this to capture messages sent to stderr
         Process shell = pb.start();
         InputStream shellIn = shell.getInputStream(); // this captures the output from the command
         shell.waitFor();
         int c;
         while ((c = shellIn.read()) != -1) {System.out.write(c);}
         // close the stream
         shellIn.close();
 
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}