Java example: Opening the VisIt GUI from Java

This program shows how to host to start the VisIt GUI from within your Java application. By altering the arguments passed to the OpenClient() method, you could launch other VisIt clients too. A VisIt client is a program that uses the ViewerProxy class to control the viewer. Examples of VisIt clients are: VisIt's GUI, VisIt's Python interface, any program that uses the VisIt Java interface.

Running the program

java -cp . OpenGUI -dv

Program source code

The important part of this code is the call to the OpenClient() method. The OpenClient method takes 3 arguments: clientName, clientProgram, clientArgs. The clientName is the internal name that will be used to identify the client inside of VisIt. You can pass any name that you want for this. The clientProgram argment is a string that identifies the executable for your program. The clientArgs argument lets you pass command line arguments to your program when it is started. When you call OpenClient(), the VisIt viewer will attempt to launch the specified VisIt client and then the client will be attached to VisIt and can control the VisIt viewer. Any number of VisIt clients can be connected to the VisIt viewer.

import llnl.visit.ViewerProxy;
import java.util.Vector;

// ****************************************************************************
// Class: OpenGUI
//
// Purpose:
//   This class implements an example program that shows how to use the 
//   ViewerProxy class and control VisIt's viewer from Java.
//
// Notes:      
//
// Programmer: Brad Whitlock
// Creation:   Mon Aug 17 13:40:40 PDT 2009
//
// Modifications:
//
// ****************************************************************************

public class OpenGUI extends RunViewer
{
    public OpenGUI()
    {
    }

    protected void work(String[] args)
    {
        // Do a plot of some data.
        String db = "globe.silo";
        if(viewer.GetViewerMethods().OpenDatabase(viewer.GetDataPath() + db))
        {
            viewer.GetViewerMethods().AddPlot("Pseudocolor", "u");
            viewer.GetViewerMethods().AddPlot("Mesh", "mesh1");
            viewer.GetViewerMethods().DrawPlots();
        }
        else
        {
            System.out.println("Could not open the database!");
        }

        // Open the VisIt GUI.
        String clientName = "GUI";
        String clientProgram = "visit";
        Vector clientArgs = new Vector();
        clientArgs.add("-gui");
        viewer.GetViewerMethods().OpenClient(clientName, clientProgram, clientArgs);
    }

    public static void main(String args[])
    {
        OpenGUI r = new OpenGUI();
        r.run(args);
    }
}