//
// 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 0.00001) {
identical = false;
break;
}
}
}
}
if (!identical) {
color_controlH1.setTable(table);
}
}
};
if (client_server != null) {
RemoteCellImpl remote_cell = new RemoteCellImpl(color_cellH1);
remote_cell.addReference(ref_colorH1);
}
else {
color_cellH1.addReference(ref_colorH1);
}
}
// set up hidden cell 2, for use with the second ColorControl (cell C4)
color_mapH2 = new ScalarMap(rangeH2, Display.RGB);
DisplayImpl displayH2 = newDisplay("display_hidden_2");
displayH2.addMap(color_mapH2);
color_widgetH2 = new LabeledColorWidget(color_mapH2);
Dimension dH2 = new Dimension(500, 170);
color_widgetH2.setMaximumSize(dH2);
color_mapH2.setRange(MIN, MAXH2);
color_controlH2 = (ColorControl) color_mapH2.getControl();
color_controlH2.addControlListener(this);
if (server_server != null) {
float[][] table = color_controlH2.getTable();
Integer1DSet set = new Integer1DSet(table[0].length);
FlatField color_fieldH2 =
new FlatField(FunctionType.REAL_1TO3_FUNCTION, set);
color_fieldH2.setSamples(table);
ref_colorH2.setData(color_fieldH2);
}
if (server_server != null || client_server != null) {
CellImpl color_cellH2 = new CellImpl() {
public void doAction() throws VisADException, RemoteException {
FlatField field = (FlatField) ref_colorH2.getData().local();
float[][] table = field.getFloats();
float[][] old_table = color_controlH2.getTable();
boolean identical = true;
for (int i=0; i<3; i++) {
if (identical) {
for (int j=0; j 0.00001) {
identical = false;
break;
}
}
}
}
if (!identical) {
color_controlH2.setTable(table);
}
}
};
if (client_server != null) {
RemoteCellImpl remote_cell = new RemoteCellImpl(color_cellH2);
remote_cell.addReference(ref_colorH2);
}
else {
color_cellH2.addReference(ref_colorH2);
}
}
left_panel.add(color_widgetH2);
left_panel.add(new JLabel(" "));
// set up cell A1
displays[0][0].addMap(new ScalarMap(range_types[0], Display.Red));
displays[0][0].addMap(new ScalarMap(range_types[1], Display.Green));
displays[0][0].addMap(new ScalarMap(range_types[2], Display.Blue));
displays[0][0].addMap(new ScalarMap(time, Display.Animation));
displays[0][0].addReference(cell_refs[0][0]);
display_done[0][0] = true;
if (server_server != null) {
double[] matrix = projection_controls[0][0].getMatrix();
if (matrix.length != 6) {
matrix = ProjectionControl.matrix3DTo2D(matrix);
}
Integer1DSet set = new Integer1DSet(6);
FlatField projection_field =
new FlatField(FunctionType.REAL_1TO1_FUNCTION, set);
projection_field.setSamples(new double[][] {matrix});
ref_projection.setData(projection_field);
}
if (server_server != null || client_server != null) {
CellImpl projection_cell = new CellImpl() {
public void doAction() throws VisADException, RemoteException {
FlatField field = (FlatField) ref_projection.getData().local();
double[] matrix = field.getValues()[0];
double[] old = projection_controls[0][0].getMatrix();
double[] old_matrix = null;
if (old.length == 6) {
old_matrix = old;
}
else {
old_matrix = ProjectionControl.matrix3DTo2D(old);
}
boolean identical = true;
for (int j=0; j 0.00001) {
identical = false;
break;
}
}
if (!identical) {
if (old.length == 6) {
projection_controls[0][0].setMatrix(matrix);
}
else {
double[] mat = ProjectionControl.matrix2DTo3D(matrix);
projection_controls[0][0].setMatrix(mat);
}
}
}
};
if (client_server != null) {
RemoteCellImpl remote_cell = new RemoteCellImpl(projection_cell);
remote_cell.addReference(ref_projection);
}
else {
projection_cell.addReference(ref_projection);
}
}
// cell B1
displays[0][1].addMap(new ScalarMap(range_types[0], Display.Red));
displays[0][1].addMap(new ScalarMap(range_types[1], Display.Green));
displays[0][1].addMap(new ScalarMap(range_types[2], Display.Blue));
displays[0][1].addReference(cell_refs[0][1]);
display_done[0][1] = true;
// cell C1
finishDisplay(client_server, (RealType) range.getComponent(0), 0, 2);
// cell A2
finishDisplay(client_server, (RealType) range.getComponent(1), 1, 0);
// cell B2
finishDisplay(client_server, (RealType) range.getComponent(2), 1, 1);
// cell C2
finishDisplay(client_server, (RealType) range.getComponent(3), 1, 2);
// cell A3
finishDisplay(client_server, (RealType) range.getComponent(4), 2, 0);
// cell B3
finishDisplay(client_server, (RealType) range.getComponent(5), 2, 1);
// cell C3
finishDisplay(client_server, rangeH1, 2, 2);
// cell A4
finishDisplay(client_server, (RealType) range.getComponent(6), 3, 0);
// cell B4
band7 = (RealType) range.getComponent(7);
finishDisplay(client_server, band7, 3, 1);
// enable point mode for cell B4
GraphicsModeControl mode = displays[3][1].getGraphicsModeControl();
mode.setTextureEnable(false);
mode.setPointMode(true);
mode.setPointSize(5.0f);
// cell C4
finishDisplay(client_server, (RealType) range.getComponent(8), 3, 2);
// cell for updating formula text fields when formulas change
CellImpl cell_formulas = new CellImpl() {
public void doAction() {
for (int i=0; i
Ads help maintain this website.