//
// Rain.java
//

package visad.rabin;

// import needed classes
import visad.*;
import visad.java2d.DisplayImplJ2D;
import visad.java2d.DirectManipulationRendererJ2D;
import visad.java3d.DisplayImplJ3D;
import visad.java3d.TwoDDisplayRendererJ3D;
import visad.java3d.DirectManipulationRendererJ3D;
import visad.util.VisADSlider;
import visad.util.LabeledColorWidget;
import visad.util.Delay;
import visad.data.Form;
import visad.data.vis5d.Vis5DForm;
import visad.data.netcdf.Plain;
import visad.formula.*;
import java.rmi.RemoteException;
import java.rmi.NotBoundException;
import java.rmi.AccessException;
import java.rmi.Naming;
import java.net.MalformedURLException;
import java.io.IOException;
import java.util.Vector;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class Rain implements ActionListener, ControlListener {

  /** RemoteServerImpl for server
      this Rain is a server if server_server != null
      this Rain is stand-alone if server_server == null
        and client_server == null */
  RemoteServerImpl server_server = null;

  /** RemoteServer for client
      this Rain is a client if client_server != null */
  RemoteServer client_server = null;

  /** whether to use Java2D or Java3D */
  boolean twod = false;

  static final int N_COLUMNS = 3;
  static final int N_ROWS = 4;
  final JPanel[] column_panels =
    new JPanel[N_COLUMNS];
  final JPanel[][] cell_panels =
    new JPanel[N_ROWS][N_COLUMNS];
  final DataReference[][] cell_refs =
    new DataReferenceImpl[N_ROWS][N_COLUMNS];
  final CellImpl[][] cells =
    new CellImpl[N_ROWS][N_COLUMNS];
  final DisplayImpl[][] displays =
    new DisplayImpl[N_ROWS][N_COLUMNS];
  final RemoteDisplayImpl[][] remote_displays =
    new RemoteDisplayImpl[N_ROWS][N_COLUMNS];
  final CellImpl[][] formula_update =
    new CellImpl[N_ROWS][N_COLUMNS];
  final boolean[][] display_done =
    new boolean[N_ROWS][N_COLUMNS];

  static final String[][] cell_names =
    {{"A1", "B1", "C1"}, {"A2", "B2", "C2"},
     {"A3", "B3", "C3"}, {"A4", "B4", "C4"}};

  static final String[][] cell_formulas =
    {{"", "A1[0]",
      "(10^(extract(B1, 0)/10)/num300) ^ (1/num1_4)"},
     {"(10^(extract(B1, 1)/10)/num300) ^ (1/num1_4)",
      "(10^(extract(B1, 2)/10)/num300) ^ (1/num1_4)",
      "(10^(extract(B1, 3)/10)/num300) ^ (1/num1_4)"},
     {"(10^(extract(B1, 4)/10)/num300) ^ (1/num1_4)",
      "(10^(extract(B1, 5)/10)/num300) ^ (1/num1_4)",
      "(10*C1 + 10*A2 + 10*B2 + 10*C2 + 10*A3 + 3*B3)/53"},
     {"extract(B1, 6)", "extract(B1, 7)", "extract(B1, 8)"}};

  JLabel[][] cell_fields = new JLabel[N_ROWS][N_COLUMNS];

  /** width and height of the UI frame */
  static final int WIDTH = 1100;
  static final int HEIGHT = 900;

  static final double MIN = 0.0;
  static final double MAX = 300.0;
  static final double MAXH2 = 10.0;

  /** remoted DataReferences */
  DataReference ref300 = null;
  DataReference ref1_4 = null;
  DataReference refMAX = null;
  DataReference ref_cursor = null;
  DataReference ref_vis5d = null;
  DataReference ref_projection = null;
  DataReference ref_colorH1 = null;
  DataReference ref_colorH2 = null;
  DataReference[][] cell_text = new DataReference[N_ROWS][N_COLUMNS];

  /** widgets and controls */
  VisADSlider slider300;
  LabeledColorWidget color_widgetH1 = null;
  LabeledColorWidget color_widgetH2 = null;
  ColorControl color_controlH1 = null;
  ColorControl color_controlH2 = null;
  ColorControl[][] color_controls = new ColorControl[N_ROWS][N_COLUMNS];
  ProjectionControl[][] projection_controls =
    new ProjectionControl[N_ROWS][N_COLUMNS];
  ScalarMap[][] color_maps = new ScalarMap[N_ROWS][N_COLUMNS];
  ScalarMap color_mapH1 = null;
  ScalarMap color_mapH2 = null;

  /** seventh band, used for point mode detection during band changes */
  RealType band7 = null;

  /** cursor */
  RealTupleType cursor_type = null;

  /** formula-related objects */
  FormulaManager f_manager = null;
  JTextField[][] jtfield = new JTextField[N_ROWS][N_COLUMNS];

  // type 'java Rain' to run this application
  public static void main(String args[])
         throws VisADException, RemoteException, IOException {
    if (args == null || args.length < 1) {
      System.out.println("run 'java visad.rabin.Rain file.v5d'\n or");
      System.out.println("    'java visad.rabin.Rain file.nc'\n or");
      System.out.println("    'java visad.rabin.Rain server.ip.name'");
      System.exit(1);
    }
    Rain rain = new Rain(args);

    rain.makeRain();
  }

  private Rain(String args[])
          throws VisADException, RemoteException {
    if (args[0].endsWith(".v5d") || args[0].endsWith(".nc")) {
      // this is server
      // try to set up a RemoteServer
      server_server = new RemoteServerImpl();
      try {
        Naming.rebind("///Rain", server_server);
      }
      catch (MalformedURLException e) {
        System.out.println("Cannot set up server - running as stand-alone");
        server_server = null;
      }
      catch (AccessException e) {
        System.out.println("Cannot set up server - running as stand-alone");
        server_server = null;
      }
      catch (RemoteException e) {
        System.out.println("Cannot set up server - running as stand-alone");
        server_server = null;
      }

      Form form = null;
      if (args[0].endsWith(".v5d")) {
        try {
          form = new Vis5DForm();
        } catch (UnsatisfiedLinkError e) {
          System.out.println("Cannot find vis5d library: " + e.getMessage());
          System.exit(1);
        }
      }
      else {
        form = new Plain();
      }
      FieldImpl vis5d = null;
      try {
        vis5d = (FieldImpl) form.open(args[0]);
      }
      catch (Exception e) {
        System.out.println(e.getMessage());
        System.exit(0);
      }
      if (vis5d == null) {
        System.out.println("bad Vis5D file read");
        System.exit(0);
      }

      ref300 = new DataReferenceImpl("num300");
      ref1_4 = new DataReferenceImpl("num1_4");
      refMAX = new DataReferenceImpl("colorMAX");
      ref_cursor = new DataReferenceImpl("cursor");
      ref_vis5d = new DataReferenceImpl("vis5d");
      ref_projection = new DataReferenceImpl("projection");
      ref_colorH1 = new DataReferenceImpl("colorH1");
      ref_colorH2 = new DataReferenceImpl("colorH2");
      for (int i=0; i

Ads help maintain this website.