/*
 * Copyright 2010-2011, Sikuli.org
 * Released under the MIT License.
 *
 */
package org.sikuli.script.internal.hotkey;

import org.sikuli.script.HotkeyListener;

public class HotkeyManager {
   protected static HotkeyManager _instance = null;

   public static HotkeyManager getInstance(){
      if(_instance==null){
            _instance = new MacHotkeyManager();
            //FIXME
         /*
         if(Env.isWindows())
            _instance = new WindowsHotkeyManager();
         else if(Env.isMac())
            _instance = new MacHotkeyManager();
         else if(Env.isLinux())
            _instance = new LinuxHotkeyManager();
         else{
            Debug.error("Hotkey manager doesn't support your OS.");
         }
         */
      }
      return _instance;
   }
   
   /**
    *  install a hotkey listener.
    *
    *  @return true if success. false otherwise.
    */
   public boolean addHotkey(int keyCode, int modifiers, HotkeyListener listener){
      return _instance.addHotkey(keyCode, modifiers, listener);
   }

   /**
    *  uninstall a hotkey listener.
    *
    *  @return true if success. false otherwise.
    */
   public boolean removeHotkey(int keyCode, int modifiers){
      return _instance.removeHotkey(keyCode, modifiers);
   }

   public void cleanUp(){
      _instance.cleanUp();
   }
}

@@ -128,40 +128,141 @@
 ort 
-org.sikuli.script.HotkeyListener
+java.lang.reflect.Constructor;%0A%0Aimport org.sikuli.script.HotkeyListener;%0Aimport org.sikuli.script.Env;%0Aimport org.sikuli.script.Debug
 ;%0A%0Ap
@@ -350,21 +350,22 @@
    p
-ublic
+rivate
  static 
 Hotk
@@ -352,32 +352,44 @@
  private static 
+String getOS
 HotkeyManager ge
@@ -389,82 +389,259 @@
 ager
- getInstance()%7B%0A      if(_instance==null)%7B%0A            _instance = new Mac
+Class()%7B%0A      String pkg = %22org.sikuli.script.internal.hotkey.%22;%0A      switch(Env.getOS())%7B%0A         case MAC:       return pkg+%22MacHotkeyManager%22;%0A         case WINDOWS:   return pkg+%22WindowsHotkeyManager%22;%0A         case LINUX:     return pkg+%22Linux
 Hotk
@@ -641,34 +641,33 @@
 nuxHotkeyManager
-()
+%22
 ;%0A            //
@@ -665,19 +665,24 @@
     
-   //FIXME%0A
+default:%0A       
     
@@ -686,19 +686,16 @@
         
-/*%0A
         
@@ -699,63 +699,130 @@
     
-if(Env.isWindows())
+Debug.error(%22Error: Hotkey registration is not supported on your OS.%22);
 %0A      
+%7D%0A
       
-_instance = new Windows
+return null;%0A   %7D%0A%0A   public static 
 Hotk
@@ -834,73 +834,78 @@
 ager
+ getInstance
 ()
-;
+%7B
 %0A      
-   else if(Env.isMac())%0A            _instance = new Mac
+if(_instance==null)%7B%0A         String cls = getOS
 Hotk
@@ -905,32 +905,37 @@
 tOSHotkeyManager
+Class
 ();%0A         els
@@ -935,31 +935,146 @@
     
-else if(Env.isLinux())%0A
+if(cls != null)%7B%0A            try%7B%0A               Class c = Class.forName(cls);%0A               Constructor constr = c.getConstructor();%0A   
     
@@ -1097,17 +1097,9 @@
 e = 
-new Linux
+(
 Hotk
@@ -1107,16 +1107,35 @@
 yManager
+)constr.newInstance
 ();%0A    
@@ -1143,82 +1143,123 @@
     
+   
-else%7B%0A            Debug.error(%22Hotkey manager doesn't support your OS.%22);%0A
+%7D%0A            catch(Exception e)%7B%0A               Debug.error(%22Can't create %22 + cls + %22: %22 + e.getMessage());%0A   
     
@@ -1270,26 +1270,25 @@
  %7D%0A         
-*/
+%7D
 %0A      %7D%0A   

create hotkey manager instance with reflection