Browse Source

fix 适配

feature/big-screen
hades 5 years ago
parent
commit
f4fe8314e8
  1. 23
      designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java
  2. 44
      designer-base/src/main/java/com/fr/design/os/impl/MacOsAction.java

23
designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java

@ -40,6 +40,7 @@ import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus;
import com.fr.design.mainframe.vcs.common.VcsHelper; import com.fr.design.mainframe.vcs.common.VcsHelper;
import com.fr.design.menu.MenuManager; import com.fr.design.menu.MenuManager;
import com.fr.design.menu.ShortCut; import com.fr.design.menu.ShortCut;
import com.fr.design.os.impl.MacOsAction;
import com.fr.design.os.impl.SupportOSImpl; import com.fr.design.os.impl.SupportOSImpl;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.event.EventDispatcher; import com.fr.event.EventDispatcher;
@ -529,26 +530,8 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta
} }
private void addMacOsListener() { private void addMacOsListener() {
if (OperatingSystem.isMacos()) { MacOsAction macOsAction = OSSupportCenter.getAction(MacOsAction.class);
try { macOsAction.execute(this);
Class app = Class.forName("com.apple.eawt.Application");
Class handler = Class.forName("com.apple.eawt.QuitHandler");
Object instance = Proxy.newProxyInstance(handler.getClassLoader(), new Class[]{handler},
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method,
Object[] args) throws Throwable {
if ("handleQuitRequestWith".equals(method.getName())) {
DesignerFrame.this.exit();
}
return null;
}
});
Reflect.on(Reflect.on(app).call("getApplication").get()).call("setQuitHandler", instance);
} catch (ClassNotFoundException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
} }
protected ArrayList<WindowListener> getFrameListeners() { protected ArrayList<WindowListener> getFrameListeners() {

44
designer-base/src/main/java/com/fr/design/os/impl/MacOsAction.java

@ -0,0 +1,44 @@
package com.fr.design.os.impl;
import com.fr.design.mainframe.DesignerFrame;
import com.fr.invoke.Reflect;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.os.OperatingSystem;
import com.fr.stable.os.support.OSBasedAction;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* @author hades
* @version 10.0
* Created by hades on 2020/3/13
*/
public class MacOsAction implements OSBasedAction {
@Override
public void execute(final Object... objects) {
if (OperatingSystem.isMacos()) {
try {
Class app = Class.forName("com.apple.eawt.Application");
Class handler = Class.forName("com.apple.eawt.QuitHandler");
Object instance = Proxy.newProxyInstance(handler.getClassLoader(), new Class[]{handler},
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method,
Object[] args) throws Throwable {
if ("handleQuitRequestWith".equals(method.getName())) {
DesignerFrame designerFrame = (DesignerFrame) objects[0];
designerFrame.exit();
}
return null;
}
});
Reflect.on(Reflect.on(app).call("getApplication").get()).call("setQuitHandler", instance);
} catch (ClassNotFoundException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
}
Loading…
Cancel
Save