jview
Class GestureRobot

java.lang.Object
  extended by java.awt.Robot
      extended by jview.GestureRobot
All Implemented Interfaces:
Remote, ExitCleaning, CompressedScreenLinking, InputEventLinking, ScreenLinking

public class GestureRobot
extends Robot
implements InputEventLinking, CompressedScreenLinking, ExitCleaning

This class implements the InputEventLinking interface and uses an AWT Robot to generate events on the local application. It thus act like a server, allowing remote control of an application. The right way to use this class can be described as follows:


Field Summary
private  String binding
          If we are successfully bound, this is our name.
private  float compress
          Defaults to 1, but on jpeg also supports lower values.
static int EXPORTPORT
          The default export port.
private  Point screen
          The host component location on screen.
private  Dimension size
          The host component size.
private  Dimension transfersize
          If null, size of screen dump is preserved during transfer.
private  int transfertype
          If zero, no image conversion is done for transfer.
private  String type
          Defaults to png, but supports also jpeg and a few others.
static List<String> WRITEFORMATS
          All known writer formats.
private  double xzoom
          If scaling is necessary.
private  double yzoom
          If scaling is necessary.
 
Constructor Summary
GestureRobot()
          Default constructor.
GestureRobot(Component c)
          Constructs a robot using the indicated component as the main component, whose on-screen location and size will determine the mouse movement linking.
GestureRobot(GraphicsDevice gd)
          Default constructor with graphics device.
GestureRobot(GraphicsDevice gd, Component c)
          Constructs a robot using the indicated component as the main component, whose on-screen location and size will determine the mouse movement linking.
 
Method Summary
 void bind(String bindname)
          Binds this gesture robot to the provided name using the Naming mecahnism.
 void exit()
          On exit, we unlink ourself from the registry, if we have been bound sucessfully.
 void export()
          Exports the robot to the registry, but does not bind it there.
 void follow(InputEvent ie)
          We try to mimick mouse movements and key presses from the remote client into our component.
static void main(String[] arg)
          In the standalone version, we export the entire screen to the RMI using the provided bind name.
 void setClientDimension(Dimension d)
          If this method is called, the server might be able to correctly translate mouse-movements if the display sizes differ.
 int setColorDepth(int bits)
          Use one of the 'lower' color model buffered image types.
 boolean setCompressedSize(Dimension small)
          Use a smaller than full screen dump size to allow further compression.
 float setCompressionQuality(float between01)
          Sets the quality of the screen capture.
 String setCompressionType(String jpeg)
          Sets the type of the screen shot returned to this type if it is one of the allowed types.
 void setParent(Component c)
          We set the parent component onto which the gestures are delivered.
 SerializableBufferedImage shareScreen()
          Transfers the entire screen.
 SerializableBufferedImage shareScreen(Rectangle box)
          Transfers an excerpt of the entire screen.
 void signalForQuit()
          If we receive a signal here, we unbind and exit the VM.
 
Methods inherited from class java.awt.Robot
createScreenCapture, delay, getAutoDelay, getPixelColor, isAutoWaitForIdle, keyPress, keyRelease, mouseMove, mousePress, mouseRelease, mouseWheel, setAutoDelay, setAutoWaitForIdle, toString, waitForIdle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EXPORTPORT

public static final int EXPORTPORT
The default export port.

See Also:
Constant Field Values

WRITEFORMATS

public static final List<String> WRITEFORMATS
All known writer formats.


binding

private String binding
If we are successfully bound, this is our name.


screen

private Point screen
The host component location on screen.


size

private Dimension size
The host component size.


xzoom

private double xzoom
If scaling is necessary. Might not always be possible.


yzoom

private double yzoom
If scaling is necessary. Might not always be possible.


type

private String type
Defaults to png, but supports also jpeg and a few others.


compress

private float compress
Defaults to 1, but on jpeg also supports lower values.


transfertype

private int transfertype
If zero, no image conversion is done for transfer.


transfersize

private Dimension transfersize
If null, size of screen dump is preserved during transfer.

Constructor Detail

GestureRobot

public GestureRobot()
             throws RemoteException,
                    AWTException
Default constructor.

Throws:
RemoteException
AWTException

GestureRobot

public GestureRobot(GraphicsDevice gd)
             throws RemoteException,
                    AWTException
Default constructor with graphics device.

Throws:
RemoteException
AWTException

GestureRobot

public GestureRobot(Component c)
             throws RemoteException,
                    AWTException
Constructs a robot using the indicated component as the main component, whose on-screen location and size will determine the mouse movement linking.

Throws:
RemoteException
AWTException

GestureRobot

public GestureRobot(GraphicsDevice gd,
                    Component c)
             throws RemoteException,
                    AWTException
Constructs a robot using the indicated component as the main component, whose on-screen location and size will determine the mouse movement linking.

Throws:
RemoteException
AWTException
Method Detail

export

public void export()
            throws RemoteException
Exports the robot to the registry, but does not bind it there.

Throws:
RemoteException

bind

public void bind(String bindname)
          throws RemoteException,
                 AlreadyBoundException,
                 MalformedURLException
Binds this gesture robot to the provided name using the Naming mecahnism.

Throws:
RemoteException
AlreadyBoundException
MalformedURLException

exit

public void exit()
On exit, we unlink ourself from the registry, if we have been bound sucessfully.

Specified by:
exit in interface ExitCleaning

signalForQuit

public void signalForQuit()
                   throws RemoteException
If we receive a signal here, we unbind and exit the VM.

Throws:
RemoteException

setParent

public void setParent(Component c)
We set the parent component onto which the gestures are delivered. Only reports the screen location to make a proper translation between client and my coordinates possible. IF called with null, we use the entire screen.


setClientDimension

public void setClientDimension(Dimension d)
                        throws RemoteException
Description copied from interface: InputEventLinking
If this method is called, the server might be able to correctly translate mouse-movements if the display sizes differ.

Specified by:
setClientDimension in interface InputEventLinking
Throws:
RemoteException

shareScreen

public SerializableBufferedImage shareScreen()
                                      throws RemoteException
Transfers the entire screen.

Specified by:
shareScreen in interface ScreenLinking
Throws:
RemoteException

shareScreen

public SerializableBufferedImage shareScreen(Rectangle box)
                                      throws RemoteException
Transfers an excerpt of the entire screen.

Specified by:
shareScreen in interface ScreenLinking
Throws:
RemoteException

setCompressionType

public String setCompressionType(String jpeg)
                          throws RemoteException
Sets the type of the screen shot returned to this type if it is one of the allowed types.

Specified by:
setCompressionType in interface CompressedScreenLinking
Returns:
The current compression type used on transfer, which is the argument if the compression type is supported.
Throws:
RemoteException

setCompressionQuality

public float setCompressionQuality(float between01)
                            throws RemoteException
Sets the quality of the screen capture. One is maximum, zero is lowest.

Specified by:
setCompressionQuality in interface CompressedScreenLinking
Returns:
The compression qulaity used.
Throws:
RemoteException

setColorDepth

public int setColorDepth(int bits)
                  throws RemoteException
Use one of the 'lower' color model buffered image types.

Specified by:
setColorDepth in interface CompressedScreenLinking
Returns:
The buffered image type used during transfer
Throws:
RemoteException
See Also:
BufferedImage

setCompressedSize

public boolean setCompressedSize(Dimension small)
                          throws RemoteException
Use a smaller than full screen dump size to allow further compression.

Specified by:
setCompressedSize in interface CompressedScreenLinking
Throws:
RemoteException

follow

public void follow(InputEvent ie)
            throws RemoteException
We try to mimick mouse movements and key presses from the remote client into our component. Coordinates in mouse event are translated for screen location by the upper left corner of our parent component, if scaling is necessary, we also try to reach an identical location in our parent. It is essential, that the coordinates of mouse events are also translated to the main frame already in the client.
Note that the issuing class should best receive events as an AWTEvent listener in the toolkit class.

Specified by:
follow in interface InputEventLinking
Throws:
RemoteException

main

public static void main(String[] arg)
                 throws RemoteException,
                        AWTException,
                        AlreadyBoundException,
                        MalformedURLException
In the standalone version, we export the entire screen to the RMI using the provided bind name.

Throws:
RemoteException
AWTException
AlreadyBoundException
MalformedURLException