Changeset 7287 in josm for trunk/src/org
- Timestamp:
- 2014-07-04T00:00:19+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r7283 r7287 10 10 import java.lang.reflect.Method; 11 11 import java.lang.reflect.Proxy; 12 import java.util.Arrays; 12 13 import java.util.List; 13 14 … … 15 16 16 17 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.actions.OpenFileAction ;18 import org.openstreetmap.josm.actions.OpenFileAction.OpenFileTask; 18 19 import org.openstreetmap.josm.data.Preferences; 20 import org.openstreetmap.josm.io.OsmTransferException; 21 import org.xml.sax.SAXException; 19 22 20 23 /** … … 37 40 @Override 38 41 public void startupHook() { 39 // Here we register callbacks for the menu entries in the system menu 42 // Here we register callbacks for the menu entries in the system menu and file opening through double-click 40 43 try { 41 44 Class<?> Ccom_apple_eawt_Application = Class.forName("com.apple.eawt.Application"); 45 Class<?> Ccom_apple_eawt_QuitHandler = Class.forName("com.apple.eawt.QuitHandler"); 46 Class<?> Ccom_apple_eawt_AboutHandler = Class.forName("com.apple.eawt.AboutHandler"); 47 Class<?> Ccom_apple_eawt_OpenFilesHandler = Class.forName("com.apple.eawt.OpenFilesHandler"); 48 Class<?> Ccom_apple_eawt_PreferencesHandler = Class.forName("com.apple.eawt.PreferencesHandler"); 42 49 Object Ocom_apple_eawt_Application = Ccom_apple_eawt_Application.getConstructor((Class[])null).newInstance((Object[])null); 43 Class<?> Ccom_apple_eawt_ApplicationListener = Class.forName("com.apple.eawt.ApplicationListener"); 44 Method MaddApplicationListener = Ccom_apple_eawt_Application.getDeclaredMethod("addApplicationListener", Ccom_apple_eawt_ApplicationListener); 45 Object Oproxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] { Ccom_apple_eawt_ApplicationListener }, ivhandler); 46 MaddApplicationListener.invoke(Ocom_apple_eawt_Application, Oproxy); 47 Method MsetEnabledPreferencesMenu = Ccom_apple_eawt_Application.getDeclaredMethod("setEnabledPreferencesMenu", boolean.class); 48 MsetEnabledPreferencesMenu.invoke(Ocom_apple_eawt_Application, Boolean.TRUE); 49 // Register callback for file opening through double-click 50 Class<?> Ccom_apple_eawt_OpenFilesHandler = Class.forName("com.apple.eawt.OpenFilesHandler"); 51 Method MsetOpenFileHandler = Ccom_apple_eawt_Application.getDeclaredMethod("setOpenFileHandler", Ccom_apple_eawt_OpenFilesHandler); 52 Object Oproxy2 = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] { Ccom_apple_eawt_OpenFilesHandler }, ivhandler); 53 MsetOpenFileHandler.invoke(Ocom_apple_eawt_Application, Oproxy2); 50 Object Oproxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class<?>[] { 51 Ccom_apple_eawt_QuitHandler, Ccom_apple_eawt_AboutHandler, Ccom_apple_eawt_OpenFilesHandler, Ccom_apple_eawt_PreferencesHandler}, ivhandler); 52 Ccom_apple_eawt_Application.getDeclaredMethod("setQuitHandler", Ccom_apple_eawt_QuitHandler).invoke(Ocom_apple_eawt_Application, Oproxy); 53 Ccom_apple_eawt_Application.getDeclaredMethod("setAboutHandler", Ccom_apple_eawt_AboutHandler).invoke(Ocom_apple_eawt_Application, Oproxy); 54 Ccom_apple_eawt_Application.getDeclaredMethod("setOpenFileHandler", Ccom_apple_eawt_OpenFilesHandler).invoke(Ocom_apple_eawt_Application, Oproxy); 55 Ccom_apple_eawt_Application.getDeclaredMethod("setPreferencesHandler", Ccom_apple_eawt_PreferencesHandler).invoke(Ocom_apple_eawt_Application, Oproxy); 56 // this method has been deprecated, but without replacement ATM 57 Ccom_apple_eawt_Application.getDeclaredMethod("setEnabledPreferencesMenu", boolean.class).invoke(Ocom_apple_eawt_Application, Boolean.TRUE); 54 58 } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) { 55 59 // We'll just ignore this for now. The user will still be able to close JOSM by closing all its windows. … … 61 65 @Override 62 66 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 63 Boolean handled = Boolean.TRUE;64 67 if (Main.isDebugEnabled()) { 65 Main.debug("OSX handler: "+method.getName()+" - "+ args);68 Main.debug("OSX handler: "+method.getName()+" - "+Arrays.toString(args)); 66 69 } 67 70 switch (method.getName()) { … … 69 72 if (args[0] != null) { 70 73 try { 71 Object oFiles = args[0].getClass().get DeclaredMethod("getFiles").invoke(args[0]);74 Object oFiles = args[0].getClass().getMethod("getFiles").invoke(args[0]); 72 75 if (oFiles instanceof List) { 73 OpenFileAction.openFiles((List<File>)oFiles, true); 74 } else { 75 Main.warn("OSX openFiles called without List: "+oFiles); 76 Main.worker.submit(new OpenFileTask((List<File>)oFiles, null) { 77 @Override 78 protected void realRun() throws SAXException, IOException, OsmTransferException { 79 // Wait for JOSM startup is advanced enough to load a file 80 while (Main.parent == null || !Main.parent.isVisible()) { 81 try { 82 Thread.sleep(25); 83 } catch (InterruptedException e) { 84 Main.warn(e); 85 } 86 } 87 super.realRun(); 88 } 89 }); 76 90 } 77 91 } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) { 78 92 Main.warn("Failed to access open files event: " + ex); 79 93 } 80 } else {81 Main.warn("OSX openFiles called without args");82 94 } 83 return null; 84 case "handleQuit": 85 handled = Main.exitJosm(false, 0); 95 break; 96 case "handleQuitRequestWith": 97 boolean closed = Main.exitJosm(false, 0); 98 if (args[1] != null) { 99 args[1].getClass().getDeclaredMethod(closed ? "performQuit" : "cancelQuit").invoke(args[1]); 100 } 86 101 break; 87 102 case "handleAbout": … … 92 107 break; 93 108 default: 94 return null; 95 } 96 if (args[0] != null) { 97 try { 98 args[0].getClass().getDeclaredMethod("setHandled", new Class<?>[] { boolean.class }).invoke(args[0], new Object[] { handled }); 99 } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) { 100 Main.warn("Failed to report handled event: " + ex); 101 } 109 Main.warn("OSX unsupported method: "+method.getName()); 102 110 } 103 111 return null;
Note:
See TracChangeset
for help on using the changeset viewer.