This is a brief outline of the main concepts in RSWT. These concepts are useful when trying to understand how to deploy and start RSWT applications.
The figure below illustrates the basic components of an RSWT application.
An RSWT server application uses the SWT API to create and manipulate SWT
GUI controls. The server-side RSWT implementation of the SWT API is
responsible for delegating SWT API calls from the server-side application
to a remote RSWT client. The RSWT implementation on the client is responsible for
translating calls from the server to calls on native SWT widgets.
All communication between the server application and client 'browser' is managed by two objects. Objects on the client are managed by an implemention of the net.sourceforge.rswt.RSWTToolkit interface. Objects on the server are managed by an implemention of the net.sourceforge.rswt.RSWTApplication interface. Both of these interfaces extend the java.rmi.Remote interface. The RSWT library contains RMI-based implementations of these interfaces.
The sequence diagram below illustrates the usual interaction between
a client-side RSWTToolkit and a server-side RSWTApplication.
An RSWT application is started when the 'browser' application obtains a reference to a remote instance of a net.sourceforge.rswt.RSWTApplication . This is shown in the first line of the above sequence diagram. There are many ways a client could obtain such a reference; from an RMI registry; from a web server; over a socket connection. RSWT does not dictate how remote applications are discovered. RSWT comes with a simple server application that will start an RSWT server connection and open a socket connection from which clients may obtain a Remote reference. See the net.sourceforge.rswt.server.ServerLauncher class.
After getting a reference to a remote RSWTApplication a client calls the RSWTApplication.start method and passes itself to the server appliction. The server application will use the given RSWTToolkit reference to make callbacks to the client. When the RSWTApplication.start method is called the server application starts the application. Usually this means creating an SWT Shell and populating the shell it with controls.
The RSWTApplication calls the RSWTToolkit.createPeer method to create client-side 'peers' for every SWT object that is created by the server application. widget that the server application After getting a reference to a remote RSWTApplication a client calls the RSWTApplication.start method and passes itself to the server appliction. The server application will use the given RSWTToolkit reference to make callbacks to the client. When the RSWTApplication.start method is called the server application starts the application. Usually this means creating an SWT Shell and populating the shell it with controls.
The design of RSWT does not dictate how server applications should be launched and discovered by client 'browsers'. There are many possible ways to launch RSWT applications.
RSWT comes with a simple launcher for launching server applications. This section contains details on using the net.sourceforge.rswt.server.ServerLauncher class to start an RSWT server application. ServerLauncher is a simple RSWT server application launcher that opens a socket connection from which client applications may obtain references to an RSWTApplication instance. Every time a client connects to the socket a new instance of the server application is instantiated and a stub that implements the RSWTApplication interface is written to socket. The client application reads the RSWTApplication reference from the socket and may then use it to start the application as described in the previous section.
java -cp <classpath> net.sourceforge.rswt.server.ServerLauncher -port <port-number> -class <application-class>
RSWT comes with a sample application that has simple demonstrations of all the standard SWT widgets. Use the following command from the directory in which you installed RSWT to launch the server portion of this application:
java -cp rswt-0.1.0.jar;rswt-examples.jar net.sourceforge.rswt.server.ServerLauncher -port 7070 -class net.sourceforge.rswt.tests.controlexample.ControlExample
The design of RSWT does not dictate how client applications should discover server applications. There are many possible ways to launch RSWT client applications.
RSWT comes with a simple 'browser' for connecting to server applications. This section contains details on using the net.sourceforge.rswt.client.BrowserLauncher class to connect to an RSWT server application that was launched with the ServerLauncher utility. BrowserLauncher is a simple utility that reads a reference to an RSWTApplication instance from a give URL. After obtaining a reference to a server application BrowserLauncher creates an RSWTToolkit instance and passes it to the server application's start method to start the application.
One thing that makes starting the client application a little trickier than starting the server application is that the client should use a native SWT library, not the RSWT implementation of the SWT library. To accomplish this a SWT native library is included in the class path before the RSWT library.
The command below only works on Windows. On other platforms the native SWT library specific to that platform should be used.
java -Djava.library.path=lib/os/win32/x86 -cp lib/ws/win32/swt.jar;rswt-0.1.0.jar net.sourceforge.rswt.client.BrowserLauncher <url>
Use the command below to connect to the RSWT Control Example server application that we started in the Starting the RSWT Control Example section:
java -Djava.library.path=lib/os/win32/x86 -cp lib/ws/win32/swt.jar;rswt-0.1.0.jar net.sourceforge.rswt.client.BrowserLauncher rswt://localhost:7070