Hello Helen, Hello VisAD World,
here (s. bellow) is the solution to keeping the rubberband on screen.
To track down my changes look for "// UT". I've changed some code near
the Cell stuff, in main().
Cheers,
Ugo
// UT
private static final int N = 16;
/** test RubberBandBoxRendererJ3D */
public static void main(String args[])
throws VisADException, RemoteException {
RealType x = new RealType("x");
RealType y = new RealType("y");
RealTupleType xy = new RealTupleType(x, y);
RealType c = new RealType("c");
FunctionType ft = new FunctionType(xy, c);
// construct Java3D display and mappings
DisplayImpl display = new DisplayImplJ3D("display1");
if (args.length == 0 || args[0].equals("z")) {
display.addMap(new ScalarMap(x, Display.XAxis));
display.addMap(new ScalarMap(y, Display.YAxis));
}
else if (args[0].equals("x")) {
display.addMap(new ScalarMap(x, Display.YAxis));
display.addMap(new ScalarMap(y, Display.ZAxis));
}
else if (args[0].equals("y")) {
display.addMap(new ScalarMap(x, Display.XAxis));
display.addMap(new ScalarMap(y, Display.ZAxis));
}
else if (args[0].equals("radius")) {
display.addMap(new ScalarMap(x, Display.Longitude));
display.addMap(new ScalarMap(y, Display.Latitude));
}
else if (args[0].equals("lat")) {
display.addMap(new ScalarMap(x, Display.Longitude));
display.addMap(new ScalarMap(y, Display.Radius));
}
else if (args[0].equals("lon")) {
display.addMap(new ScalarMap(x, Display.Latitude));
display.addMap(new ScalarMap(y, Display.Radius));
}
else {
display.addMap(new ScalarMap(x, Display.Longitude));
display.addMap(new ScalarMap(y, Display.Latitude));
}
display.addMap(new ScalarMap(c, Display.RGB));
Integer2DSet fset = new Integer2DSet(xy, N, N);
FlatField field = new FlatField(ft, fset);
float[][] values = new float[1][N * N];
int k = 0;
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
values[0][k++] = (i - N / 2) * (j - N / 2);
}
}
field.setSamples(values);
DataReferenceImpl field_ref = new DataReferenceImpl("field");
field_ref.setData(field);
display.addReference(field_ref);
Gridded2DSet dummy_set = new Gridded2DSet(xy, null, 1);
final DataReferenceImpl ref = new DataReferenceImpl("set");
ref.setData(dummy_set);
int m = (args.length > 1) ? InputEvent.CTRL_MASK : 0;
display.addReferences(new RubberBandBoxRendererJ3D(x, y, m, m),
ref);
// UT
final DataReferenceImpl ref2 = new DataReferenceImpl("set2");
ref2.setData(dummy_set);
ConstantMap[] yellowCMap = { new ConstantMap( 1.0f, Display.Red ),
new ConstantMap( 1.0f, Display.Green
),
new ConstantMap( 0.0f, Display.Blue ),
new ConstantMap( 2.50f,
Display.LineWidth ) };
display.addReference(ref2, yellowCMap);
CellImpl cell = new CellImpl() {
public void doAction() throws VisADException, RemoteException {
Set set = (Set) ref.getData();
float[][] samples = set.getSamples();
if (samples != null) {
System.out.println("box test: (" + samples[0][0] + ", " +
samples[1][0] +
") to (" + samples[0][1] + ", " +
samples[1][1] + ")");
}
// UT dump data
visad.jmet.DumpType.dumpDataType(set,System.out);
// HI; UT -> changed indices
float[][] points1 = new float[2][5];
points1[0][0]= samples[0][0];
points1[1][0]= samples[1][0];
points1[0][1]= samples[0][0];
points1[1][1]= samples[1][1];
points1[0][2]= samples[0][1];
points1[1][2]= samples[1][1];
points1[0][3]= samples[0][1];
points1[1][3]= samples[1][0];
points1[0][4]= samples[0][0];
points1[1][4]= samples[1][0];
// UT
RealType x2 = RealType.getRealType("x");
RealType y2 = RealType.getRealType("y");
RealTupleType xy2 = new RealTupleType(x2, y2);
// UT
ref2.setData( new Gridded2DSet(xy2, points1, 5));
}
};
cell.addReference(ref);
// create JFrame (i.e., a window) for display and slider
JFrame frame = new JFrame("test RubberBandBoxRendererJ3D");
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);
}