Display Problem :
As we mentioned earlier we want a tuple when we right
click a mouse button. Now we are able to see only one
real tuple when we click the mouse button but, the
earlier ones are not seen. Suggest us in doing this.
Thanks a lot,
karan
======================================================
/*
* DrawGeometry2.java
*
* Created on July 14, 2001, 3:25 PM
*/
import visad.*;
import visad.java2d.DisplayImplJ2D;
import visad.java3d.*;
import java.rmi.RemoteException;
import javax.swing.*;
import visad.java2d.*;
import javax.media.j3d.*;
import java.util.*;
import java.awt.event.*;
import visad.bom.PointManipulationRendererJ3D;
public class DrawGeometry2 extends Object {
RealType row, column, index;
RealTupleType domain_tuple;
DisplayImpl display;
ScalarMap rowMap, colMap;
DataReferenceImpl data_ref;
DisplayRenderer dr;
String ag[];
DataReferenceImpl d_ref;
private static final int N = 64;
float dx, dy;
RealTuple rt;
Vector xvector, yvector;
/** Creates new DrawGeometry2 */
public DrawGeometry2() {
}
public void displayGrid() throws RemoteException,
VisADException {
row = new RealType("X", SI.meter, null);
column = new RealType("Y", SI.meter, null);
domain_tuple = new RealTupleType(row, column);
RealType index = new RealType("index");
FunctionType func_type = new
FunctionType(domain_tuple, index);
Integer2DSet integer_set = new
Integer2DSet(domain_tuple, N, N);
FlatField field = new FlatField(func_type,
integer_set);
display = new DisplayImplJ3D("display1");
dr = display.getDisplayRenderer();
dr.setBoxOn(false);
GraphicsModeControl dispGMC
(GraphicsModeControl)
display.getGraphicsModeControl();
rowMap = new ScalarMap( row, Display.XAxis );
colMap = new ScalarMap( column, Display.YAxis
);
display.addMap(colMap);
display.addMap(rowMap);
rowMap.setRange(0, 50);
colMap.setRange(0, 50);
RealTuple dummy_rt = new
RealTuple(domain_tuple, new double[] {Double.NaN,
Double.NaN});
final DataReferenceImpl ref = new
DataReferenceImpl("rt");
ref.setData(dummy_rt);
final ConstantMap[] pointsCol = { new
ConstantMap( 1.0f, Display.Red),
new ConstantMap( 1.0f, Display.Green),
new ConstantMap( 1.0f, Display.Blue),
new ConstantMap( 10.0f, Display.PointSize)};
int m = (ag.length > 1) ? InputEvent.CTRL_MASK
: 0;
display.addReferences(new
PointManipulationRendererJ3D(row, column, m, m), ref);
CellImpl cell = new CellImpl() {
public void doAction() throws
VisADException, RemoteException {
RealTuple rt = (RealTuple)
ref.getData();
dx = (float)((Real)
rt.getComponent(0)).getValue();
dy = (float)((Real)
rt.getComponent(1)).getValue();
if (dx == dx && dy == dy) {
// System.out.println("point (" +
dx + ", " + dy + ")");
}
}
};
cell.addReference(ref);
final DirectManipulationRendererJ3D dmr = new
DirectManipulationRendererJ3D();
final ConstantMap[] pointsCMap = { new
ConstantMap( 1.0f, Display.Red ),
new ConstantMap( 1.0f, Display.Green ),
new ConstantMap( 1.0f, Display.Blue ),
new ConstantMap( 3.50f, Display.PointSize ) };
d_ref = new DataReferenceImpl("d_ref");
display.addDisplayListener(new
DisplayListener() {
public void displayChanged(DisplayEvent e)
throws RemoteException, VisADException {
if(e.getId() =
DisplayEvent.MOUSE_RELEASED_RIGHT) {
Real r2[] = new Real[] { new
Real(row, dx), new Real(column, dy) };
RealTuple real_tuple = new
RealTuple(r2);
d_ref.setData(real_tuple);
}
}
});
display.addReference(d_ref);
JFrame jframe = new JFrame("2D Grid");
jframe.getContentPane().add(display.getComponent());
jframe.setSize(400, 400);
jframe.setVisible(true);
jframe.addWindowListener(new
java.awt.event.WindowAdapter() {
public void
windowClosing(java.awt.event.WindowEvent evt) {
System.exit(0);
}
}
);
}
public static void main(String args[]) {
DrawGeometry2 g = new DrawGeometry2();
g.ag = args;
try {
g.displayGrid();
} catch (Exception e) {
e.printStackTrace();
}
}
}
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/