@ -13,85 +13,55 @@
import java.awt.event.* ;
/ * *
* This class listens to mouse and keyboard event for de k stop sharing at the
* This class listens to mouse and keyboard event for de sk top sharing at the
* client side , in order to send moves , clicks and key strokes to the server .
*
* @author Vincent Lucas
* /
public class DesktopSharingMouseAndKeyboardListener
implements RemoteControlListener ,
KeyListener ,
MouseListener ,
MouseMotionListener
KeyListener ,
MouseListener ,
MouseMotionListener
{
/ * *
* The remote controlled call peer to which the events must be sent .
* /
private CallPeer remoteC allPeer;
private final CallPeer c allPeer;
/ * *
* The video component displqying the remote desktop .
* The operation set which received the granted / revoked desktop sharing
* rights and to which , we are sending the mouse and key events .
* /
private Component videoComponent = null ;
private final OperationSetDesktopSharingClient opSetDesktopSharingClient ;
/ * *
* An object get mutual exclusion access to the videoComponent .
* The video component displaying the remote desktop .
* /
private Object videoComponentMutex = new Object ( ) ;
private Component videoComponent = null ;
/ * *
* The oeration set which received the granted / revoked desktop sharing
* rights and to which , we are sending the mouse and key events .
* An object get mutual exclusion access to the videoComponent .
* /
private OperationSetDesktopSharingClient opSetDesktopSharingClient = null ;
private final Object videoComponentMutex = new Object ( ) ;
/ * *
* Creates a new listener of mouse and key event for a the
* video di playing the streamed remote desktop . The video component is null
* video di s playing the streamed remote desktop . The video component is null
* until calling the setVideoComponent function .
*
* @param remoteC allPeer The remote controlled call peer to which the events
* @param c allPeer The remote controlled call peer to which the events
* must be sent .
* /
public DesktopSharingMouseAndKeyboardListener ( CallPeer remoteC allPeer)
public DesktopSharingMouseAndKeyboardListener ( CallPeer c allPeer)
{
this . remoteCallPeer = remoteC allPeer;
this . callPeer = c allPeer;
this . opSetDesktopSharingClient
= remoteC allPeer. getProtocolProvider ( ) . getOperationSet (
opSetDesktopSharingClient
= c allPeer. getProtocolProvider ( ) . getOperationSet (
OperationSetDesktopSharingClient . class ) ;
}
/ * *
* Sets the video diplaying component for the streamed remote desktop .
*
* @param videoComponenet The video component displqying the remote desktop .
* /
public void setVideoComponent ( Component videoComponent )
{
synchronized ( this . videoComponentMutex )
{
// If there was an old video component, and no new one, then
// unregisters to the operation set.
if ( this . videoComponent ! = null
& & videoComponent = = null )
{
// The remove remote control listener will also be called
// directly by the operationst when the peer state change.
opSetDesktopSharingClient . removeRemoteControlListener ( this ) ;
}
// If there was no video component, and a new one is set, then
// registers to the operation set.
else if ( this . videoComponent = = null
& & videoComponent ! = null )
{
opSetDesktopSharingClient . addRemoteControlListener ( this ) ;
}
this . videoComponent = videoComponent ;
}
}
/ * *
* Returns the remote - controlled CallPeer .
*
@ -99,90 +69,66 @@ else if(this.videoComponent == null
* /
public CallPeer getCallPeer ( )
{
return this . remoteC allPeer;
return c allPeer;
}
/ * *
* This method is called when remote control has been grant ed.
* Invoked when a key has been press ed.
*
* @param event The event which grants us the control of the remote call
* peer .
* @param e The keyboard event .
* /
public void remoteControlGranted( RemoteControlGrantedEvent event )
public void keyPressed( KeyEvent e )
{
synchronized ( this . videoComponentMutex )
{
if ( this . videoComponent ! = null )
{
this . videoComponent . addKeyListener ( this ) ;
this . videoComponent . addMouseListener ( this ) ;
this . videoComponent . addMouseMotionListener ( this ) ;
}
}
}
/ * *
* This method is called when remote control has been revok ed.
* Invoked when a key has been released .
*
* @param event The event which revokes us the control of the remote call
* peer .
* @param e The keyboard event .
* /
public void remoteControlRevoked( RemoteControlRevokedEvent event )
public void keyReleased ( KeyEvent e )
{
synchronized ( this . videoComponentMutex )
{
if ( this . videoComponent ! = null )
{
this . videoComponent . removeKeyListener ( this ) ;
this . videoComponent . removeMouseListener ( this ) ;
this . videoComponent . removeMouseMotionListener ( this ) ;
}
}
}
/ * *
* Invoked when a mouse button is pressed on a
* component and then dragged .
* Invoked when a key has been typed .
*
* @param e The mouse dragge d event .
* @param e The keyboard event .
* /
public void mouseDragged( Mouse Event e )
public void keyTyped ( KeyEvent e )
{
opSetDesktopSharingClient . sendMouseEvent (
remoteCallPeer ,
e ,
videoComponent . getBounds ( ) . getSize ( ) ) ;
opSetDesktopSharingClient . sendKeyboardEvent ( callPeer , e ) ;
}
/ * *
* Invoked when the mouse cursor has been moved
* onto a component but no buttons have been pushed .
* Invoked when the mouse button has been clicked ( pressed and released ) on
* a component .
*
* @param e The mouse moved event.
* @param e The mouse event.
* /
public void mouse Mov ed( MouseEvent e )
public void mouse Click ed( MouseEvent e )
{
opSetDesktopSharingClient . sendMouseEvent (
remoteC allPeer,
c allPeer,
e ,
videoComponent . get Bounds( ) . get Size( ) ) ;
videoComponent . get Size( ) ) ;
}
/ * *
* Invoked when the mouse button has been clicked ( pressed and released ) on
* a component.
* Invoked when a mouse button is pressed on a
* component and then dragged .
*
* @param e The mouse event.
* @param e The mouse dragged event.
* /
public void mouse Click ed( MouseEvent e )
public void mouse Dragg ed( MouseEvent e )
{
opSetDesktopSharingClient . sendMouseEvent (
remoteC allPeer,
c allPeer,
e ,
videoComponent . get Bounds( ) . get Size( ) ) ;
videoComponent . get Size( ) ) ;
}
/ * *
* Invoked when the mouse enters a component .
*
@ -201,6 +147,20 @@ public void mouseExited(MouseEvent e)
{
}
/ * *
* Invoked when the mouse cursor has been moved
* onto a component but no buttons have been pushed .
*
* @param e The mouse moved event .
* /
public void mouseMoved ( MouseEvent e )
{
opSetDesktopSharingClient . sendMouseEvent (
callPeer ,
e ,
videoComponent . getSize ( ) ) ;
}
/ * *
* Invoked when a mouse button has been pressed on a component .
*
@ -209,9 +169,9 @@ public void mouseExited(MouseEvent e)
public void mousePressed ( MouseEvent e )
{
opSetDesktopSharingClient . sendMouseEvent (
remoteC allPeer,
c allPeer,
e ,
videoComponent . get Bounds( ) . get Size( ) ) ;
videoComponent . get Size( ) ) ;
}
/ * *
@ -222,38 +182,78 @@ public void mousePressed(MouseEvent e)
public void mouseReleased ( MouseEvent e )
{
opSetDesktopSharingClient . sendMouseEvent (
remoteC allPeer,
c allPeer,
e ,
videoComponent . get Bounds( ) . get Size( ) ) ;
videoComponent . get Size( ) ) ;
}
/ * *
* Invoked when a key has been press ed.
* This method is called when remote control has been grant ed.
*
* @param e The keyborad event .
* @param event The event which grants us the control of the remote call
* peer .
* /
public void keyPressed( KeyEvent e )
public void remoteControlGranted( RemoteControlGrantedEvent event )
{
synchronized ( videoComponentMutex )
{
if ( videoComponent ! = null )
{
videoComponent . addKeyListener ( this ) ;
videoComponent . addMouseListener ( this ) ;
videoComponent . addMouseMotionListener ( this ) ;
}
}
}
/ * *
* Invoked when a key has been released .
* This method is called when remote control has been revok ed.
*
* @param e The keyborad event .
* @param event The event which revokes us the control of the remote call
* peer .
* /
public void keyReleased ( KeyEvent e )
public void remoteControlRevoked( RemoteControlRevokedEvent event )
{
synchronized ( videoComponentMutex )
{
if ( videoComponent ! = null )
{
videoComponent . removeKeyListener ( this ) ;
videoComponent . removeMouseListener ( this ) ;
videoComponent . removeMouseMotionListener ( this ) ;
}
}
}
/ * *
* Invoked when a key has been typed .
* Sets the video displaying component for the streamed remote desktop .
*
* @param e The keyborad event .
* @param videoComponenet The video component displaying the remote desktop .
* /
public void keyTyped ( KeyEvent e )
public void setVideoComponent( Component videoComponent )
{
opSetDesktopSharingClient . sendKeyboardEvent (
remoteCallPeer ,
e ) ;
synchronized ( videoComponentMutex )
{
if ( this . videoComponent = = null )
{
// If there was no old video component and a new one is set,
// registers to the operation set.
if ( videoComponent ! = null )
opSetDesktopSharingClient . addRemoteControlListener ( this ) ;
}
else
{
// If there was an old video component and no new one is set,
// unregisters from the operation set.
if ( videoComponent = = null )
{
// The remove remote control listener will also be called
// directly by the operation when the peer state change.
opSetDesktopSharingClient . removeRemoteControlListener ( this ) ;
}
}
this . videoComponent = videoComponent ;
}
}
}