|
|
@ -1,7 +1,10 @@ |
|
|
|
package com.fr.design.os.impl; |
|
|
|
package com.fr.design.os.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fr.design.actions.help.AboutDialog; |
|
|
|
|
|
|
|
import com.fr.design.actions.help.AboutPane; |
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
import com.fr.exit.DesignerExiter; |
|
|
|
import com.fr.exit.DesignerExiter; |
|
|
|
|
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
import com.fr.invoke.Reflect; |
|
|
|
import com.fr.invoke.Reflect; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.stable.os.support.OSBasedAction; |
|
|
|
import com.fr.stable.os.support.OSBasedAction; |
|
|
@ -21,25 +24,55 @@ public class MacOsAddListenerAction implements OSBasedAction { |
|
|
|
public void execute(final Object... objects) { |
|
|
|
public void execute(final Object... objects) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Class app = Class.forName("com.apple.eawt.Application"); |
|
|
|
Class app = Class.forName("com.apple.eawt.Application"); |
|
|
|
Class handler = Class.forName("com.apple.eawt.QuitHandler"); |
|
|
|
Class quitHandler = Class.forName("com.apple.eawt.QuitHandler"); |
|
|
|
Object instance = Proxy.newProxyInstance(handler.getClassLoader(), new Class[]{handler}, |
|
|
|
Object quitInstance = getProxy(quitHandler, "handleQuitRequestWith", new QuitAction()); |
|
|
|
new InvocationHandler() { |
|
|
|
Class aboutHandler = Class.forName("com.apple.eawt.AboutHandler"); |
|
|
|
@Override |
|
|
|
Object aboutInstance = getProxy(aboutHandler, "", new AboutAction()); |
|
|
|
public Object invoke(Object proxy, Method method, |
|
|
|
Reflect.on(Reflect.on(app).call("getApplication").get()).call("setQuitHandler", quitInstance) |
|
|
|
Object[] args) throws Throwable { |
|
|
|
.call("setAboutHandler", aboutInstance); |
|
|
|
if ("handleQuitRequestWith".equals(method.getName())) { |
|
|
|
|
|
|
|
if (DesignerContext.getDesignerFrame() != null && DesignerContext.getDesignerFrame().isShowing()) { |
|
|
|
|
|
|
|
DesignerContext.getDesignerFrame().exit(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
DesignerExiter.getInstance().execute(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
Reflect.on(Reflect.on(app).call("getApplication").get()).call("setQuitHandler", instance); |
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Object getProxy(Class clazz, final String methodName, final Action action) { |
|
|
|
|
|
|
|
return Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, |
|
|
|
|
|
|
|
new InvocationHandler() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Object invoke(Object proxy, Method method, |
|
|
|
|
|
|
|
Object[] args) throws Throwable { |
|
|
|
|
|
|
|
if (ComparatorUtils.equals(methodName, method.getName())) { |
|
|
|
|
|
|
|
action.execute(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface Action { |
|
|
|
|
|
|
|
void execute(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class QuitAction implements Action { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void execute() { |
|
|
|
|
|
|
|
if (DesignerContext.getDesignerFrame() != null && DesignerContext.getDesignerFrame().isShowing()) { |
|
|
|
|
|
|
|
DesignerContext.getDesignerFrame().exit(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
DesignerExiter.getInstance().execute(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class AboutAction implements Action { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void execute() { |
|
|
|
|
|
|
|
AboutPane aboutPane = new AboutPane(); |
|
|
|
|
|
|
|
AboutDialog aboutDialog = new AboutDialog(DesignerContext.getDesignerFrame(), aboutPane); |
|
|
|
|
|
|
|
aboutDialog.setVisible(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|