Making a simple VisAD application collaborative

This is a walkthrough of the process of making a simple VisAD application collaborative.
We'll start with an application which reads a GIF file from the Web and displays it using a DisplayImplJ2D:
Next
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import java.io.IOException;
import java.rmi.RemoteException;

import visad.*;
import visad.data.DefaultFamily;
import visad.java2d.DisplayImplJ2D;
import visad.util.ClientServer;

public class DisplayGIF
{
  // location of GIF file to be displayed
  private static final String fileURL = "http://www.ssec.wisc.edu/~billh/billh.gif";

  public static void main(String[] args)
    throws IOException, RemoteException, VisADException
  {
    // create a display
    DisplayImpl dpy = new DisplayImplJ2D("display");

    // get the GIF file
    FlatField image = (FlatField )new DefaultFamily("dflt").open(fileURL);

    // compute ScalarMaps from type components
    FunctionType ftype = (FunctionType )image.getType();
    RealTupleType dtype = ftype.getDomain();
    RealTupleType rtype9 = (RealTupleType )ftype.getRange();
    dpy.addMap(new ScalarMap((RealType )dtype.getComponent(0),
                             Display.XAxis));
    dpy.addMap(new ScalarMap((RealType )dtype.getComponent(1),
                             Display.YAxis));
    dpy.addMap(new ScalarMap((RealType )rtype9.getComponent(0),
                             Display.Red));
    dpy.addMap(new ScalarMap((RealType )rtype9.getComponent(1),
                             Display.Green));
    dpy.addMap(new ScalarMap((RealType )rtype9.getComponent(2),
                             Display.Blue));

    // add the GIF data to the display
    DataReferenceImpl ref_image = new DataReferenceImpl("ref_image");
    ref_image.setData(image);
    dpy.addReference(ref_image, null);

    // create a frame
    JFrame jframe = new JFrame("GIF");
    jframe.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) { System.exit(0); }
      });

    // add display to frame
    jframe.setContentPane((Container )dpy.getComponent());

    // make frame visible
    jframe.pack();
    jframe.setVisible(true);
  }
}
    

Next
Last modified: Wed Jul 12 10:59:58 CDT 2000