~ubuntu-branches/ubuntu/utopic/sikuli/utopic

« back to all changes in this revision

Viewing changes to sikuli-ide/src/main/java/org/sikuli/ide/NativeLayerForMac.java

  • Committer: Bazaar Package Importer
  • Author(s): Gilles Filippini
  • Date: 2011-10-04 23:32:13 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20111004233213-36fm78hx0z53tkuw
Tags: 1.0~x~rc3-dfsg1-2
* New patch fix-cmake-sikuli-ide.patch:
  + Fix random FTBFS due to missing inter target dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.sikuli.ide;
2
 
 
3
 
import java.awt.event.KeyEvent;
4
 
import java.awt.event.InputEvent;
5
 
import javax.swing.*;
6
 
import java.io.IOException;
7
 
import java.util.prefs.*;
8
 
import com.apple.eawt.*;
9
 
import com.wapmx.nativeutils.jniloader.NativeLoader;
10
 
 
11
 
import org.sikuli.script.Debug;
12
 
 
13
 
// http://lists.apple.com/archives/mac-games-dev/2001/Sep/msg00113.html
14
 
// full key table: http://www.mactech.com/articles/mactech/Vol.04/04.12/Macinkeys/
15
 
// modifiers code: http://www.mactech.com/macintosh-c/chap02-1.html
16
 
 
17
 
public class NativeLayerForMac implements NativeLayer {
18
 
   static final int CARBON_MASK_CMD = 0x0100;
19
 
   static final int CARBON_MASK_SHIFT = 0x0200;
20
 
   static final int CARBON_MASK_OPT = 0x0800;
21
 
   static final int CARBON_MASK_CTRL = 0x1000;
22
 
 
23
 
   static {
24
 
      try{
25
 
         NativeLoader.loadLibrary("NativeLayerForMac");      
26
 
      }
27
 
      catch(IOException e){
28
 
         e.printStackTrace();
29
 
      }
30
 
   }
31
 
 
32
 
   public void initIDE(final SikuliIDE ide){
33
 
   }
34
 
 
35
 
   public void initApp(){
36
 
      Application app = Application.getApplication();
37
 
      app.addPreferencesMenuItem();
38
 
      app.setEnabledPreferencesMenu(true);
39
 
      app.addApplicationListener(
40
 
         new ApplicationAdapter() {
41
 
            public void handleOpenApplication(ApplicationEvent event){
42
 
               Debug.info("open application: Sikuli-IDE");
43
 
               System.setProperty("apple.laf.useScreenMenuBar", "true");
44
 
               System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Sikuli IDE");
45
 
            }
46
 
 
47
 
            public void handleOpenFile(ApplicationEvent evt) {
48
 
               final String fname = evt.getFilename();
49
 
               Debug.log(1, "opening " + fname);
50
 
               if(fname.endsWith(".skl")){
51
 
                  SikuliIDE._runningSkl = true;
52
 
                  Thread t = new Thread() {
53
 
                     public void run() {
54
 
                        try{
55
 
                           SikuliIDE.runSkl(fname, null); 
56
 
                        }
57
 
                        catch(IOException e){
58
 
                           e.printStackTrace();
59
 
                        }
60
 
                     }
61
 
                  };
62
 
                  t.setDaemon(false);
63
 
                  t.start();
64
 
               }
65
 
               else if(fname.endsWith(".sikuli")){
66
 
                  SikuliIDE ide = SikuliIDE.getInstance(null);
67
 
                  ide.loadFile(fname);
68
 
               }
69
 
            }
70
 
 
71
 
            public void handlePreferences(ApplicationEvent evt){
72
 
               Debug.log(1, "opening preferences setting");
73
 
               SikuliIDE ide = SikuliIDE.getInstance();
74
 
               ide.showPreferencesWindow();
75
 
            }
76
 
 
77
 
            public void handleQuit(ApplicationEvent event){
78
 
               SikuliIDE.getInstance().quit();
79
 
            }
80
 
         }
81
 
      ); 
82
 
   }
83
 
 
84
 
   public void installHotkey(int key, int mod, 
85
 
                              SikuliIDE ide, 
86
 
                              String callbackMethod, String callbackType){
87
 
      int ckey = convertToCarbonKey(key);
88
 
      int cmod = convertToCarbonModifiers(mod);
89
 
      Debug.log(2, "register hotkey Java:" + key + "(" +mod+ 
90
 
                   ") Carbon: " + ckey + "(" + cmod + ")");
91
 
      installGlobalHotkey(ckey, cmod, ide, 
92
 
                          callbackMethod, callbackType);
93
 
   }
94
 
 
95
 
   private native void installGlobalHotkey(int keyCode, int modifiers, 
96
 
                              SikuliIDE ide, 
97
 
                              String callbackMethod, String callbackType);
98
 
 
99
 
   private int convertToCarbonModifiers(int mod){
100
 
      int cmod = 0;
101
 
      if((mod&InputEvent.SHIFT_MASK) != 0) cmod |= CARBON_MASK_SHIFT;
102
 
      if((mod&InputEvent.META_MASK) != 0) cmod |= CARBON_MASK_CMD;
103
 
      if((mod&InputEvent.ALT_MASK) != 0) cmod |= CARBON_MASK_OPT;
104
 
      if((mod&InputEvent.CTRL_MASK) != 0) cmod |= CARBON_MASK_CTRL;
105
 
      return cmod;
106
 
   }
107
 
 
108
 
   private int convertToCarbonKey(int keycode){
109
 
      switch(keycode){
110
 
         case KeyEvent.VK_BACK_SPACE: return 0x33;
111
 
         case KeyEvent.VK_TAB: return 0x30;
112
 
         case KeyEvent.VK_CLEAR: return 0x47;
113
 
         case KeyEvent.VK_ENTER: return 0x24;
114
 
         case KeyEvent.VK_SHIFT: return 0xF0;
115
 
         case KeyEvent.VK_CONTROL: return 0xF1;
116
 
         case KeyEvent.VK_META: return 0xF2; 
117
 
         case KeyEvent.VK_PAUSE: return 0x71; // = F15
118
 
         case KeyEvent.VK_ESCAPE: return 0x35;
119
 
         case KeyEvent.VK_SPACE: return 0x31;
120
 
         case KeyEvent.VK_OPEN_BRACKET: return 0x21;
121
 
         case KeyEvent.VK_BACK_SLASH: return 0x2A;
122
 
         case KeyEvent.VK_CLOSE_BRACKET: return 0x1E;
123
 
         case KeyEvent.VK_SLASH: return 0x2C;
124
 
         case KeyEvent.VK_PERIOD: return 0x2F;
125
 
         case KeyEvent.VK_COMMA: return 0x2B;
126
 
         case KeyEvent.VK_SEMICOLON: return 0x29;
127
 
         case KeyEvent.VK_END: return 0x77;
128
 
         case KeyEvent.VK_HOME: return 0x73;
129
 
         case KeyEvent.VK_LEFT: return 0x7B;
130
 
         case KeyEvent.VK_UP: return 0x7E;
131
 
         case KeyEvent.VK_RIGHT: return 0x7C;
132
 
         case KeyEvent.VK_DOWN: return 0x7D;
133
 
         case KeyEvent.VK_PRINTSCREEN: return 0x69; // F13
134
 
         case KeyEvent.VK_INSERT: return 0x72; // help
135
 
         case KeyEvent.VK_DELETE: return 0x75;
136
 
         case KeyEvent.VK_HELP: return 0x72;
137
 
         case KeyEvent.VK_0: return 0x1D;
138
 
         case KeyEvent.VK_1: return 0x12;
139
 
         case KeyEvent.VK_2: return 0x13;
140
 
         case KeyEvent.VK_3: return 0x14;
141
 
         case KeyEvent.VK_4: return 0x15;
142
 
         case KeyEvent.VK_5: return 0x17;
143
 
         case KeyEvent.VK_6: return 0x16;
144
 
         case KeyEvent.VK_7: return 0x1A;
145
 
         case KeyEvent.VK_8: return 0x1C;
146
 
         case KeyEvent.VK_9: return 0x19;
147
 
         case KeyEvent.VK_MINUS: return 0x1B;
148
 
         case KeyEvent.VK_EQUALS: return 0x18;
149
 
         case KeyEvent.VK_A: return 0x00;
150
 
         case KeyEvent.VK_B: return 0x0B;
151
 
         case KeyEvent.VK_C: return 0x08;
152
 
         case KeyEvent.VK_D: return 0x02;
153
 
         case KeyEvent.VK_E: return 0x0E;
154
 
         case KeyEvent.VK_F: return 0x03;
155
 
         case KeyEvent.VK_G: return 0x05;
156
 
         case KeyEvent.VK_H: return 0x04;
157
 
         case KeyEvent.VK_I: return 0x22;
158
 
         case KeyEvent.VK_J: return 0x26;
159
 
         case KeyEvent.VK_K: return 0x28;
160
 
         case KeyEvent.VK_L: return 0x25;
161
 
         case KeyEvent.VK_M: return 0x2E;
162
 
         case KeyEvent.VK_N: return 0x2D;
163
 
         case KeyEvent.VK_O: return 0x1F;
164
 
         case KeyEvent.VK_P: return 0x23;
165
 
         case KeyEvent.VK_Q: return 0x0C;
166
 
         case KeyEvent.VK_R: return 0x0F;
167
 
         case KeyEvent.VK_S: return 0x01;
168
 
         case KeyEvent.VK_T: return 0x11;
169
 
         case KeyEvent.VK_U: return 0x20;
170
 
         case KeyEvent.VK_V: return 0x09;
171
 
         case KeyEvent.VK_W: return 0x0D;
172
 
         case KeyEvent.VK_X: return 0x07;
173
 
         case KeyEvent.VK_Y: return 0x10;
174
 
         case KeyEvent.VK_Z: return 0x06;
175
 
         case KeyEvent.VK_NUMPAD0: return 0x52;
176
 
         case KeyEvent.VK_NUMPAD1: return 0x53;
177
 
         case KeyEvent.VK_NUMPAD2: return 0x54;
178
 
         case KeyEvent.VK_NUMPAD3: return 0x55;
179
 
         case KeyEvent.VK_NUMPAD4: return 0x56;
180
 
         case KeyEvent.VK_NUMPAD5: return 0x57;
181
 
         case KeyEvent.VK_NUMPAD6: return 0x58;
182
 
         case KeyEvent.VK_NUMPAD7: return 0x59;
183
 
         case KeyEvent.VK_NUMPAD8: return 0x5B;
184
 
         case KeyEvent.VK_NUMPAD9: return 0x5C;
185
 
         case KeyEvent.VK_MULTIPLY: return 0x43;
186
 
         case KeyEvent.VK_ADD: return 0x45;
187
 
         case KeyEvent.VK_SEPARATOR: return 0xFF; // not supported with Button or GetKeys
188
 
         case KeyEvent.VK_SUBTRACT: return 0x4E;
189
 
         case KeyEvent.VK_DECIMAL: return 0x41;
190
 
         case KeyEvent.VK_DIVIDE: return 0x4B;
191
 
         case KeyEvent.VK_F1: return 0x7A;
192
 
         case KeyEvent.VK_F2: return 0x7B;
193
 
         case KeyEvent.VK_F3: return 0x63;
194
 
         case KeyEvent.VK_F4: return 0x76;
195
 
         case KeyEvent.VK_F5: return 0x60;
196
 
         case KeyEvent.VK_F6: return 0x61;
197
 
         case KeyEvent.VK_F7: return 0x62;
198
 
         case KeyEvent.VK_F8: return 0x64;
199
 
         case KeyEvent.VK_F9: return 0x65;
200
 
         case KeyEvent.VK_F10: return 0x6D;
201
 
         case KeyEvent.VK_F11: return 0x67;
202
 
         case KeyEvent.VK_F12: return 0x6F;
203
 
         case KeyEvent.VK_F13: return 0x69;
204
 
         case KeyEvent.VK_F14: return 0x6B;
205
 
         case KeyEvent.VK_F15: return 0x71;
206
 
         case KeyEvent.VK_NUM_LOCK: return 0x47;
207
 
         default: return 0xFF;
208
 
      }
209
 
 
210
 
   }
211
 
}
212
 
 
213
 
 
 
1
/*
 
2
 * Copyright 2010-2011, Sikuli.org
 
3
 * Released under the MIT License.
 
4
 *
 
5
 */
 
6
package org.sikuli.ide;
 
7
 
 
8
import java.awt.event.KeyEvent;
 
9
import java.awt.event.InputEvent;
 
10
import javax.swing.*;
 
11
import java.io.IOException;
 
12
import java.util.prefs.*;
 
13
import com.apple.eawt.*;
 
14
 
 
15
import org.sikuli.script.Debug;
 
16
 
 
17
// http://lists.apple.com/archives/mac-games-dev/2001/Sep/msg00113.html
 
18
// full key table: http://www.mactech.com/articles/mactech/Vol.04/04.12/Macinkeys/
 
19
// modifiers code: http://www.mactech.com/macintosh-c/chap02-1.html
 
20
 
 
21
public class NativeLayerForMac implements NativeLayer {
 
22
 
 
23
   public void initIDE(final SikuliIDE ide){
 
24
   }
 
25
 
 
26
   public void initApp(){
 
27
      Application app = Application.getApplication();
 
28
      app.addPreferencesMenuItem();
 
29
      app.setEnabledPreferencesMenu(true);
 
30
      app.addApplicationListener(
 
31
         new ApplicationAdapter() {
 
32
            public void handleOpenApplication(ApplicationEvent event){
 
33
               Debug.info("open application: Sikuli-IDE");
 
34
               System.setProperty("apple.laf.useScreenMenuBar", "true");
 
35
               System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Sikuli IDE");
 
36
            }
 
37
 
 
38
            public void handleOpenFile(ApplicationEvent evt) {
 
39
               final String fname = evt.getFilename();
 
40
               Debug.log(1, "opening " + fname);
 
41
               if(fname.endsWith(".skl")){
 
42
                  SikuliIDE._runningSkl = true;
 
43
                  Thread t = new Thread() {
 
44
                     public void run() {
 
45
                        try{
 
46
                           SikuliIDE.runSkl(fname, null); 
 
47
                        }
 
48
                        catch(IOException e){
 
49
                           e.printStackTrace();
 
50
                        }
 
51
                     }
 
52
                  };
 
53
                  t.setDaemon(false);
 
54
                  t.start();
 
55
               }
 
56
               else if(fname.endsWith(".sikuli")){
 
57
                  SikuliIDE ide = SikuliIDE.getInstance(null);
 
58
                  ide.loadFile(fname);
 
59
               }
 
60
            }
 
61
 
 
62
            public void handlePreferences(ApplicationEvent evt){
 
63
               Debug.log(1, "opening preferences setting");
 
64
               SikuliIDE ide = SikuliIDE.getInstance();
 
65
               ide.showPreferencesWindow();
 
66
            }
 
67
 
 
68
            public void handleQuit(ApplicationEvent event){
 
69
               SikuliIDE.getInstance().quit();
 
70
            }
 
71
         }
 
72
      ); 
 
73
   }
 
74
 
 
75
}
 
76
 
 
77