// // CollaborativePointDrag.java // // changes from PointDrag.java marked by #### 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; // #### name change public class CollaborativePointDrag { // #### add /** RemoteServerImpl for server this CollaborativePointDrag is a server if server_server != null */ RemoteServerImpl server_server; // #### add /** RemoteServer for client this CollaborativePointDrag is a client if client_server != null */ RemoteServer client_server; /** type 'java CollaborativePointDrag' to run as server or stand-alone type 'java CollaborativePointDrag server.ip.name' to run as client */ public static void main(String args[]) throws VisADException, RemoteException { // construct CollaborativePointDrag application // #### name change CollaborativePointDrag etch = new CollaborativePointDrag(args); // construct arrays to hold display and data DisplayImpl[] displays = new DisplayImpl[1]; DataReference[] refs = new DataReference[1]; // #### was just: // etch.setupServer(displays, refs); if (etch.client_server != null) { // set up data and display for client etch.setupClient(displays, refs); } else if (etch.server_server != null) { // set up data and display for server etch.setupServer(displays, refs); } else { // set up data and display for stand-alone // (neither client nor server) etch.setupServer(displays, refs); } // set up user interface setupUI(displays, refs); } public CollaborativePointDrag(String args[]) throws VisADException, RemoteException { // #### was empty constructor String serviceName = getClass().getName(); // i.e. "CollaborativePointDrag" if (args.length > 0) { // this is a client // try to connect to RemoteServer if (args[0].equals("null")) args[0] = ""; client_server = ClientServer.connectToServer(args[0], serviceName); } else { // args.length == 0 // this is a server // try to set up a RemoteServer server_server = ClientServer.startServer(serviceName); } } /** set up data and display for server or 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; // #### add // make display and DataReference to UnionSet accessible to clients if (server_server != null) { server_server.addDisplay(new RemoteDisplayImpl(display)); server_server.addDataReference(new RemoteDataReferenceImpl(ref)); } } // #### add /** set up data and display for client */ void setupClient(DisplayImpl[] displays, DataReference[] refs) throws VisADException, RemoteException { // get display and DataReference to UnionSet from server // the display will be fully collaborative with server display displays[0] = (DisplayImpl) ClientServer.getClientDisplay(client_server, 0); refs[0] = (DataReference) client_server.getDataReference(0); } /** 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 // #### name change JFrame frame = new JFrame("CollaborativePointDrag"); 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); } }