From 1ac21709746b541e68c17e27e21e75663826d71f Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 30 Jun 2021 16:18:55 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-54643=20=E6=9C=80=E6=96=B0=E7=9A=84persi?= =?UTF-8?q?st=E5=88=86=E6=94=AF=E5=AE=89=E8=A3=85=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E5=86=85=E5=AD=98=E7=9B=91=E6=8E=A7=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E4=B8=94=E4=BC=9A=E5=AF=BC=E8=87=B4=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E6=97=A0=E6=B3=95=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/DesignerFrame.java | 5 ++ .../design/mainframe/SafeWindowListener.java | 84 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/SafeWindowListener.java diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java index 25948b62c..dc90fb0d0 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java @@ -535,6 +535,11 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta } } + @Override + public synchronized void addWindowListener(WindowListener l) { + super.addWindowListener(new SafeWindowListener(l)); + } + private void addMacOsListener() { OSSupportCenter.buildAction(new MacOsAddListenerAction(), SupportOSImpl.DOCK_QUIT); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/SafeWindowListener.java b/designer-base/src/main/java/com/fr/design/mainframe/SafeWindowListener.java new file mode 100644 index 000000000..4f3c812ad --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/SafeWindowListener.java @@ -0,0 +1,84 @@ +package com.fr.design.mainframe; + +import com.fr.log.FineLoggerFactory; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; + +/** + * 保证监听运行出错也不影响其他功能正常使用 + * + * @author hades + * @version 10.0 + * Created by hades on 2021/6/30 + */ +public class SafeWindowListener implements WindowListener { + + private final WindowListener windowListener; + + public SafeWindowListener(WindowListener windowListener) { + this.windowListener = windowListener; + } + + @Override + public void windowOpened(WindowEvent e) { + try { + windowListener.windowOpened(e); + } catch (Throwable throwable) { + FineLoggerFactory.getLogger().debug(throwable.getMessage(), throwable); + } + } + + @Override + public void windowClosing(WindowEvent e) { + try { + windowListener.windowClosing(e); + } catch (Throwable throwable) { + FineLoggerFactory.getLogger().debug(throwable.getMessage(), throwable); + } + } + + @Override + public void windowClosed(WindowEvent e) { + try { + windowListener.windowClosed(e); + } catch (Throwable throwable) { + FineLoggerFactory.getLogger().debug(throwable.getMessage(), throwable); + } + } + + @Override + public void windowIconified(WindowEvent e) { + try { + windowListener.windowIconified(e); + } catch (Throwable throwable) { + FineLoggerFactory.getLogger().debug(throwable.getMessage(), throwable); + } + } + + @Override + public void windowDeiconified(WindowEvent e) { + try { + windowListener.windowDeiconified(e); + } catch (Throwable throwable) { + FineLoggerFactory.getLogger().debug(throwable.getMessage(), throwable); + } + } + + @Override + public void windowActivated(WindowEvent e) { + try { + windowListener.windowActivated(e); + } catch (Throwable throwable) { + FineLoggerFactory.getLogger().debug(throwable.getMessage(), throwable); + } + } + + @Override + public void windowDeactivated(WindowEvent e) { + try { + windowListener.windowDeactivated(e); + } catch (Throwable throwable) { + FineLoggerFactory.getLogger().debug(throwable.getMessage(), throwable); + } + } +}