11package com .tagtraum .perf .gcviewer .view .util ;
22
3- import javax .swing .Action ;
4-
5- import com .tagtraum .perf .gcviewer .util .LoggerHelper ;
6-
73import java .awt .Image ;
84import java .awt .Window ;
95import java .lang .reflect .InvocationHandler ;
106import java .lang .reflect .Method ;
117import java .lang .reflect .Proxy ;
128import java .util .logging .Level ;
139import java .util .logging .Logger ;
10+ import javax .swing .Action ;
11+
12+ import com .tagtraum .perf .gcviewer .util .LoggerHelper ;
1413
1514/**
1615 * Handles Mac OS X specific stuff.
@@ -112,7 +111,7 @@ public static void addOSXHandler(String handlerClassName,
112111
113112 Class <?> handlerClass = Class .forName (handlerClassName );
114113 if (action != null ) {
115- Object aboutHandlerProxy =
114+ Object handlerProxy =
116115 Proxy .newProxyInstance (OSXSupport .class .getClassLoader (),
117116 new Class []{handlerClass },
118117 new InvocationHandler () {
@@ -121,10 +120,15 @@ public Object invoke(Object o, Method method, Object[] args) throws Throwable {
121120 if (method .getName ().equals (handlerMethodName )) {
122121 action .actionPerformed (null );
123122 }
123+ if (method .getName ().equals ("handleQuitRequestWith" )) {
124+ // https://www.coderanch.com/how-to/javadoc/appledoc/api/com/apple/eawt/QuitHandler.html
125+ Object quitResponse = args [1 ];
126+ Class .forName ("com.apple.eawt.QuitResponse" ).getDeclaredMethod ("performQuit" ).invoke (quitResponse );
127+ }
124128 return null ;
125129 }
126130 });
127- application .getClass ().getMethod (handlerSetterMethodName , handlerClass ).invoke (application , aboutHandlerProxy );
131+ application .getClass ().getMethod (handlerSetterMethodName , handlerClass ).invoke (application , handlerProxy );
128132 } else {
129133 application .getClass ().getMethod (handlerSetterMethodName , handlerClass ).invoke (application , (Object ) null );
130134 }
0 commit comments