// // PointDrag.java // import visad.*; import visad.util.*; import visad.java3d.*; import visad.bom.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.rmi.*; import java.net.MalformedURLException; public class PointDrag { /** type 'java PointDrag' to run */ public static void main(String args[]) throws VisADException, RemoteException { // construct PointDrag application PointDrag etch = new PointDrag(args); // construct arrays to hold display and data:w DisplayImpl[] displays = new DisplayImpl[1]; DataReference[] refs = new DataReference[1]; // set up data and display for stand-alone etch.setupServer(displays, refs); // set up user interface setupUI(displays, refs); } // constructor does nothing: // all the work is done in setupServer and setupUI public PointDrag(String args[]) throws VisADException, RemoteException { } /** set up data and display for stand-alone */ void setupServer(DisplayImpl[] displays, DataReference[] refs) throws VisADException, RemoteException { // create RealTypes for the X and Y axes of the drawing space RealType x = new RealType("x"); RealType y = new RealType("y"); // create the RealTupleType for the drawing space RealTupleType xy = new RealTupleType(x, y); // construct Java3D display and mappings DisplayImpl display = new DisplayImplJ3D("display1", new TwoDDisplayRendererJ3D()); // map the data drawing space to the display X and Y axes ScalarMap xmap = new ScalarMap(x, Display.XAxis); ScalarMap ymap = new ScalarMap(y, Display.YAxis); display.addMap(xmap); display.addMap(ymap); // set the details of the linear mappings from data to display axes xmap.setRange(-1.0, 1.0); ymap.setRange(-1.0, 1.0); // make point large enough to see easily GraphicsModeControl mode = display.getGraphicsModeControl(); mode.setPointSize(5.0f); // turn off bounding box display.getDisplayRenderer().setBoxOn(false); // construct starter point as RealTuple RealTuple point = new RealTuple(xy, new double[] {0.0, 0.0}); // link starter point to display // // note DirectManipulationRendererJ3D provides // the point-drag behavior DataReferenceImpl ref = new DataReferenceImpl("point"); ref.setData(point); DirectManipulationRendererJ3D dmrenderer = new DirectManipulationRendererJ3D(); display.addReferences(dmrenderer, ref); // plug data and display in arrays displays[0] = display; refs[0] = ref; } /** set up the user interface */ static void setupUI(DisplayImpl[] displays, DataReference[] refs) throws VisADException, RemoteException { // create JFrame (i.e., a window) for display and slider JFrame frame = new JFrame("PointDrag"); 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(displays[0].getComponent()); // set size of JFrame and make it visible frame.setSize(500, 500); frame.setVisible(true); } }