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

public class Junk {

  // make sliderReference and field global for CellImpl access
  static DataReference sliderReference;
  static FlatField field;

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

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

    Linear2DSet region = new Linear2DSet(earth, -50.0, 50.0, 4, 0.0,
50.0, 4);
    RealType range = RealType.Longitude;
    FunctionType ftype = new FunctionType(earth, range);
    field = new FlatField(ftype, region);
    field.setSamples(new float[][] {{0.0f, 0.0f, 0.0f, 0.0f,
                                     0.0f, 0.0f, 0.0f, 0.0f,
                                     0.0f, 0.0f, 0.0f, 0.0f,
                                     0.0f, 0.0f, 0.0f, 0.0f}});

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

    // create slider
    Real slider = new Real(RealType.Longitude, 0);
    sliderReference = new DataReferenceImpl("slider");
    ConstantMap[] cMaps = new ConstantMap[6];
    cMaps[0] = new ConstantMap(-1.0, Display.YAxis);
    cMaps[1] = new ConstantMap(-1.0, Display.ZAxis);
    cMaps[2] = new ConstantMap(1.0, Display.Red);
    cMaps[3] = new ConstantMap(0.0, Display.Green);
    cMaps[4] = new ConstantMap(0.0, Display.Blue);
    cMaps[5] = new ConstantMap(5.0, Display.PointSize);
    sliderReference.setData(slider);
    CellImpl cell = new CellImpl() {
      public void doAction() throws VisADException,
java.rmi.RemoteException {
        double value = ((Real)sliderReference.getData()).getValue();
        double[][] values = new double[1][16];
        for (int i = 0 ; i < 16 ; i++) values[0][i] = value;
        field.setSamples(values);
      }
    };
    cell.addReference(sliderReference);

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

    // create Longitude-ScalarMap
    ScalarMap longScalarMap = new ScalarMap(RealType.Longitude,
Display.XAxis);
    longScalarMap.setRange(-180, 180);

    // map earth coordinates to display coordinates
    display.addMap(longScalarMap);
    display.addMap(new ScalarMap(RealType.Latitude, Display.YAxis));
    display.addMap(new ScalarMap(RealType.Altitude, Display.ZAxis));

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

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

    // link the Display to sliderReference with a
DirectManipulationRenderer
    display.addReferences(new DirectManipulationRendererJ3D(),
sliderReference, cMaps);

    // 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);
  }
}

