
// import needed classes
import visad.*;
import visad.java3d.DisplayImplJ3D;
import visad.java2d.DisplayImplJ2D;
import visad.util.VisADSlider;
import visad.data.netcdf.Plain;
import java.rmi.RemoteException;
import java.io.IOException;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Junk {

  // type 'java Junk' to run this application
  public static void main(String args[])
         throws VisADException, RemoteException, IOException {

    RealTupleType earth =
      new RealTupleType(RealType.Longitude, RealType.Latitude);

    Linear2DSet region = new Linear2DSet(earth, -180.0, 180.0, 2,
-90.0, 90.0, 2);
    RealType range = RealType.Altitude;
    FunctionType ftype = new FunctionType(earth, range);
    FlatField field = new FlatField(ftype, region);
    field.setSamples(new float[][] {{0.0f, 0.5f, 0.5f, 0.0f}});

    // create a DataReference for region
    final DataReference region_ref = new DataReferenceImpl("region");
    // region_ref.setData(region);
    region_ref.setData(field);

    // create a Display using Java3D
    // DisplayImpl display = new DisplayImplJ3D("image display");
    // create a Display using Java2D
    DisplayImpl display = new DisplayImplJ3D("image display");

    // map earth coordinates to display coordinates
    display.addMap(new ScalarMap(RealType.Longitude, Display.XAxis));
    display.addMap(new ScalarMap(RealType.Latitude, Display.YAxis));
    display.addMap(new ScalarMap(range, Display.ZAxis));

    GraphicsModeControl mode = display.getGraphicsModeControl();
    mode.setScaleEnable(true);

    // link the Display to region_ref
    display.addReference(region_ref);

    // create JFrame (i.e., a window) for display and slider
    JFrame frame = new JFrame("Junk VisAD Application");
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {System.exit(0);}
    });

    // create JPanel in JFrame
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setAlignmentY(JPanel.TOP_ALIGNMENT);
    panel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
    frame.getContentPane().add(panel);

    // add display to JPanel
    panel.add(display.getComponent());

    // set size of JFrame and make it visible
    frame.setSize(500, 500);
    frame.setVisible(true);
  }
}

