| | 475 | |
| | 476 | public static boolean withOSXIntegration = false; |
| | 477 | |
| | 478 | public void setupOSX() { |
| | 479 | if (System.getProperty("os.name").toLowerCase().startsWith("mac os x")) { |
| | 480 | try { |
| | 481 | Class Ccom_apple_eawt_Application = Class.forName("com.apple.eawt.Application"); |
| | 482 | Object Ocom_apple_eawt_Application = Ccom_apple_eawt_Application.getConstructor((Class[])null).newInstance((Object[])null); |
| | 483 | Class Ccom_apple_eawt_ApplicationListener = Class.forName("com.apple.eawt.ApplicationListener"); |
| | 484 | Method MaddApplicationListener = Ccom_apple_eawt_Application.getDeclaredMethod("addApplicationListener", new Class[] { Ccom_apple_eawt_ApplicationListener }); |
| | 485 | Object Oproxy = Proxy.newProxyInstance(Main.class.getClassLoader(), new Class[] { Ccom_apple_eawt_ApplicationListener }, this); |
| | 486 | MaddApplicationListener.invoke(Ocom_apple_eawt_Application, new Object[] { Oproxy }); |
| | 487 | Method MsetEnabledPreferencesMenu = Ccom_apple_eawt_Application.getDeclaredMethod("setEnabledPreferencesMenu", new Class[] { boolean.class }); |
| | 488 | MsetEnabledPreferencesMenu.invoke(Ocom_apple_eawt_Application, new Object[] { Boolean.TRUE }); |
| | 489 | withOSXIntegration = true; |
| | 490 | } catch (Exception ex) { |
| | 491 | System.out.println("Failed to report register with OSX: " + ex); |
| | 493 | } |
| | 494 | } |
| | 495 | |
| | 496 | public Object invoke (Object proxy, Method method, Object[] args) throws Throwable { |
| | 497 | Boolean handled = Boolean.TRUE; |
| | 498 | //System.out.println("Going to handle method "+method+" (short: "+method.getName()+") with event "+args[0]); |
| | 499 | if (method.getName().equals("handleQuit")) { |
| | 500 | handled = !breakBecauseUnsavedChanges(); |
| | 501 | } else if (method.getName().equals("handleAbout")) { |
| | 502 | menu.about.actionPerformed(null); |
| | 503 | } else if (method.getName().equals("handlePreferences")) { |
| | 504 | menu.preferences.actionPerformed(null); |
| | 505 | } else { |
| | 506 | return null; |
| | 507 | } |
| | 508 | if (args[0] != null) { |
| | 509 | try { |
| | 510 | args[0].getClass().getDeclaredMethod("setHandled", new Class[] { boolean.class }).invoke(args[0], new Object[] { handled }); |
| | 511 | } catch (Exception ex) { |
| | 512 | System.out.println("Failed to report handled event: " + ex); |
| | 513 | } |
| | 514 | } |
| | 515 | return null; |
| | 516 | } |
| | 517 | } |