package sivantoledo.nxt.mouse;

import org.eclipse.swt.widgets.Display;

import sivantoledo.nxt.Log;
import sivantoledo.nxt.NXTender;
import sivantoledo.nxt.Sender;
import sivantoledo.nxt.NXTender.Plugin;

public class Mouse extends NXTender.Plugin {
  
  private Mouse() {
    super("PCMOUSE");
  }
  
  public void close() {
  }

  public void process(String command) {
    //String key = command.substring(4);
    //Log.println("mouse command <"+key+">");
    
    String[] terms = command.split(" ");

    if (terms.length == 1) {
      Log.println("incorrect PCMOUSE command: "+command);
      return;
    }
    
    if (terms[1].equals("DX-DY")) {
      if (terms.length < 4) return; // wrong format
      int dx = Integer.parseInt(terms[2]);
      int dy = Integer.parseInt(terms[3]);
      
      sivantoledo.win32.SendInput.mouseRelative(dx,dy);
    }
      
    if (terms[1].equals("LEFT")) 
      sivantoledo.win32.SendInput.mouseDownUp(0);
    
    if (terms[1].equals("MIDDLE")) 
      sivantoledo.win32.SendInput.mouseDownUp(1);

    if (terms[1].equals("RIGHT")) 
      sivantoledo.win32.SendInput.mouseDownUp(2);

  }

  private static Mouse instance;  
  public static Mouse getInstance(Sender sender) {
    if (instance == null) instance = new Mouse();
    return instance;
  }
  
  /*
  public static void main(String[] args) {
    sivantoledo.win32.SendInput.mouseDownUp(0);
    sivantoledo.win32.SendInput.mouseDownUp(0);
    try { Thread.sleep(1000); } catch (Exception e) {}
    
    sivantoledo.win32.SendInput.mouseRelative(10,10);
    try { Thread.sleep(1000); } catch (Exception e) {}
    sivantoledo.win32.SendInput.mouseRelative(10,10);
    try { Thread.sleep(1000); } catch (Exception e) {}
    sivantoledo.win32.SendInput.mouseRelative(10,10);
  }
  */
}
