/**
Khalid
*/
package org.sikuli.slides.sikuli;
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.sikuli.api.ScreenRegion;
import org.sikuli.api.visual.Canvas;
import org.sikuli.api.visual.DesktopCanvas;
import org.sikuli.slides.listeners.GlobalKeyboardListeners;
import org.sikuli.slides.listeners.GlobalMouseListeners;
import org.sikuli.slides.shapes.SlideShape;
import org.sikuli.slides.utils.Constants;
import org.sikuli.slides.utils.Constants.DesktopEvent;

public class SlideTutorial {
	private ScreenRegion targetRegion;
	private Constants.DesktopEvent desktopEvent;
	private SlideShape slideShape;
	
	public SlideTutorial(ScreenRegion targetRegion, SlideShape slideShape, Constants.DesktopEvent desktopEvent){
		this.targetRegion=targetRegion;
		this.slideShape=slideShape;
		this.desktopEvent=desktopEvent;
	}
	
	public void performTutorialSlideAction() {
		Canvas canvas=new DesktopCanvas();
		canvas.addBox(targetRegion);
        System.out.println("Waiting for the user to pefrom "+this.desktopEvent.toString()+" on the highlighted target.");
		try {
        	if(!GlobalScreen.isNativeHookRegistered()){
        		GlobalScreen.registerNativeHook();
        	}
            if(this.desktopEvent==DesktopEvent.KEYBOARD_TYPING){
            	GlobalKeyboardListeners globalKeyboardListener=new GlobalKeyboardListeners(targetRegion,slideShape.getText(),desktopEvent);
            	GlobalScreen.getInstance().addNativeKeyListener(globalKeyboardListener);
            	canvas.displayWhile(globalKeyboardListener);
            }
            else{
            	GlobalMouseListeners globalMouseListener=new GlobalMouseListeners(targetRegion,desktopEvent);
            	GlobalScreen.getInstance().addNativeMouseListener(globalMouseListener);
            	canvas.displayWhile(globalMouseListener);
            }
        }
        catch (NativeHookException ex) {
            System.err.println("There was a problem running the tutorial mode.");
            System.err.println(ex.getMessage());
            System.exit(1);
        }

		
	}
}

@@ -118,24 +118,67 @@
 kException;%0A
+import org.sikuli.api.DesktopScreenRegion;%0A
 import org.s
@@ -905,115 +905,978 @@
 %09%0A%09p
-ublic void performTutorialSlideAction() %7B%0A%09%09Canvas canvas=new DesktopCanvas();%0A%09%09canvas.addBox(targetRegion
+rivate String getActionDisplayName()%7B%0A%09%09if(desktopEvent==DesktopEvent.LEFT_CLICK)%7B%0A%09%09%09return %22Click here%22;%0A%09%09%7D%0A%09%09else if(desktopEvent==DesktopEvent.DOUBLE_CLICK)%7B%0A%09%09%09return %22Double click here%22;%0A%09%09%7D%0A%09%09else if(desktopEvent==DesktopEvent.RIGHT_CLICK)%7B%0A%09%09%09return %22Right click here%22;%0A%09%09%7D%0A%09%09else if(desktopEvent==DesktopEvent.DRAG_N_DROP)%7B%0A%09%09%09if(slideShape.getOrder()==0)%0A%09%09%09%09return %22Drag this%22;%0A%09%09%09else if(slideShape.getOrder()==1)%0A%09%09%09%09return %22and drop it here%22;%0A%09%09%7D%0A%09%09else if(desktopEvent==DesktopEvent.KEYBOARD_TYPING)%7B%0A%09%09%09return %22Type: %22+ slideShape.getText()+%22 here%22;%0A%09%09%7D%0A%09%09return %22%22;%0A%09%7D%0A%09%0A%09public void performTutorialSlideAction() %7B%0A%09%09Canvas canvas=new DesktopCanvas();%0A%09%09canvas.addBox(targetRegion);%0A%09%09int x=targetRegion.getBounds().x;%0A%09%09int y=targetRegion.getBounds().y;%0A%09%09int w=targetRegion.getBounds().width;%0A%09%09int h=targetRegion.getBounds().height;%0A%09%09ScreenRegion labelRegion=new DesktopScreenRegion(x,y-h,w,h);%0A%09%09canvas.addLabel(labelRegion, getActionDisplayName()
 );%0A 

fix label location