From dfc5d0bd98ee5756468cd35290150096072be2dc Mon Sep 17 00:00:00 2001 From: vito Date: Mon, 19 Jun 2023 19:26:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-93559=20=E8=A1=A5=E5=85=85=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=8F=92=E4=BB=B6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../com/fr/design/jxbrowser/JxUIPane.java | 38 +++++++++++++++- .../java/com/fr/design/ui/ModernUIPane.java | 21 ++++++++- .../fr/design/ui/compatible/BuilderDiff.java | 30 +++++++++++++ .../ui/compatible/ModernUIPaneFactory.java | 45 +++++++++++++++++++ 5 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/ui/compatible/BuilderDiff.java create mode 100644 designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java diff --git a/build.gradle b/build.gradle index 73aede69a1..a0599e7549 100644 --- a/build.gradle +++ b/build.gradle @@ -100,6 +100,7 @@ allprojects { } } else if (OperatingSystem.current().isWindows()) { dependencies { + implementation 'com.fr.third:jxbrowser-win64:6.23' implementation "com.fr.third:jxbrowser-win64-v7:${jxBrowserVersion}" } } diff --git a/designer-base/src/main/java/com/fr/design/jxbrowser/JxUIPane.java b/designer-base/src/main/java/com/fr/design/jxbrowser/JxUIPane.java index 44f81ef3d6..1a968551df 100644 --- a/designer-base/src/main/java/com/fr/design/jxbrowser/JxUIPane.java +++ b/designer-base/src/main/java/com/fr/design/jxbrowser/JxUIPane.java @@ -7,9 +7,13 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.ui.ModernUIConstants; import com.fr.design.ui.ModernUIPane; import com.fr.stable.StringUtils; +import com.fr.stable.collections.combination.Pair; import com.fr.web.struct.AssembleComponent; import com.teamdev.jxbrowser.browser.Browser; import com.teamdev.jxbrowser.browser.callback.InjectJsCallback; +import com.teamdev.jxbrowser.chromium.events.LoadListener; +import com.teamdev.jxbrowser.chromium.events.ScriptContextListener; +import com.teamdev.jxbrowser.event.Observer; import com.teamdev.jxbrowser.frame.Frame; import com.teamdev.jxbrowser.js.JsObject; import com.teamdev.jxbrowser.view.swing.BrowserView; @@ -20,6 +24,7 @@ import javax.swing.SwingUtilities; import java.awt.BorderLayout; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.Optional; import static com.fr.design.ui.ModernUIConstants.COMPONENT_TAG; @@ -220,13 +225,16 @@ public class JxUIPane extends ModernUIPane { * * @param 参数 */ - public static class Builder { + public static class Builder extends ModernUIPane.Builder { private String namespace; private String variable; private String expression; private InjectJsCallback callback; + + private Pair listenerPair; private final Map namespacePropertyMap; private final Map propertyMap; + private final Map buildPropertyMap; private Object variableProperty; private Map parameterMap; @@ -239,6 +247,7 @@ public class JxUIPane extends ModernUIPane { this.variable = DEFAULT_VARIABLE; this.expression = DEFAULT_EXPRESSION; this.callback = null; + this.listenerPair = null; this.namespacePropertyMap = new HashMap<>(); this.propertyMap = new HashMap<>(); this.buildPropertyMap = new HashMap<>(); @@ -255,11 +264,33 @@ public class JxUIPane extends ModernUIPane { * @param callback 回调 * @return builder */ - public JxUIPane.Builder prepare(InjectJsCallback callback) { + public Builder prepare(InjectJsCallback callback) { this.callback = callback; return this; } + @Override + public Builder prepareForV6(ScriptContextListener contextListener) { + return this; + } + + @Override + public Builder prepareForV6(LoadListener loadListener) { + return this; + } + + @Override + public JxUIPane.Builder prepareForV7(InjectJsCallback callback) { + prepare(callback); + return this; + } + + @Override + public JxUIPane.Builder prepareForV7(Class event, Observer listener) { + listenerPair = new Pair<>(event, listener); + return this; + } + /** * 加载jar包中的资源 * @@ -457,6 +488,9 @@ public class JxUIPane extends ModernUIPane { pane.setComponent(component); pane.initialize(); injectJs(pane); + if (!Objects.isNull(listenerPair)) { + pane.browser.navigation().on(listenerPair.getFirst(), listenerPair.getSecond()); + } if (StringUtils.isNotEmpty(this.url)) { pane.browser.navigation().loadUrl(this.url); } else if (StringUtils.isNotEmpty(this.html)) { diff --git a/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java b/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java index 69c7a81ab3..f3aceb8476 100644 --- a/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java +++ b/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java @@ -5,8 +5,10 @@ import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.i18n.Toolkit; +import com.fr.design.ui.compatible.BuilderDiff; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.web.struct.AssembleComponent; +import com.teamdev.jxbrowser.browser.callback.InjectJsCallback; import com.teamdev.jxbrowser.chromium.Browser; import com.teamdev.jxbrowser.chromium.BrowserType; import com.teamdev.jxbrowser.chromium.JSValue; @@ -15,6 +17,7 @@ import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter; import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent; import com.teamdev.jxbrowser.chromium.events.ScriptContextListener; import com.teamdev.jxbrowser.chromium.swing.BrowserView; +import com.teamdev.jxbrowser.event.Observer; import javax.swing.JDialog; import javax.swing.SwingUtilities; @@ -31,7 +34,7 @@ import java.util.Map; * @version 10.0 * Created by richie on 2019-03-04 * 用于加载html5的Swing容器,可以在设计选项设置中打开调试窗口,示例可查看:com.fr.design.ui.ModernUIPaneTest - * @see com.fr.design.jxbrowser.JxUIPane + * @see {@link com.fr.design.jxbrowser.JxUIPane} * @deprecated 主要用于jxbrowser6,将在下个版本删除 */ @Deprecated @@ -199,7 +202,7 @@ public class ModernUIPane extends BasicPane { * * @param */ - public static class Builder { + public static class Builder implements BuilderDiff { private ModernUIPane pane; @@ -332,14 +335,28 @@ public class ModernUIPane extends BasicPane { return this; } + @Override public Builder prepareForV6(ScriptContextListener contextListener) { return prepare(contextListener); } + @Override public Builder prepareForV6(LoadListener loadListener) { return prepare(loadListener); } + @Override + public Builder prepareForV7(InjectJsCallback callback) { + // do nothing + return this; + } + + @Override + public Builder prepareForV7(Class event, Observer listener) { + // do nothing + return this; + } + public ModernUIPane build() { return pane; } diff --git a/designer-base/src/main/java/com/fr/design/ui/compatible/BuilderDiff.java b/designer-base/src/main/java/com/fr/design/ui/compatible/BuilderDiff.java new file mode 100644 index 0000000000..483257e9b3 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/ui/compatible/BuilderDiff.java @@ -0,0 +1,30 @@ +package com.fr.design.ui.compatible; + +import com.fr.design.jxbrowser.JxUIPane; +import com.fr.design.ui.ModernUIPane; +import com.teamdev.jxbrowser.browser.callback.InjectJsCallback; +import com.teamdev.jxbrowser.chromium.events.LoadListener; +import com.teamdev.jxbrowser.chromium.events.ScriptContextListener; +import com.teamdev.jxbrowser.event.Observer; + +/** + * 封装jxbrwoser v6/v7的构建方式的差异 + * + * @author hades + * @version 10.0 + * Created by hades on 2021/6/13 + * @see {@link JxUIPane} + * @deprecated 6在下个版本弃用 + */ +@Deprecated +public interface BuilderDiff { + + ModernUIPane.Builder prepareForV6(ScriptContextListener contextListener); + + ModernUIPane.Builder prepareForV6(LoadListener loadListener); + + ModernUIPane.Builder prepareForV7(InjectJsCallback callback); + + ModernUIPane.Builder prepareForV7(Class event, Observer listener); + +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java b/designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java new file mode 100644 index 0000000000..f6e29e81c5 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java @@ -0,0 +1,45 @@ +package com.fr.design.ui.compatible; + +import com.fr.design.jxbrowser.JxUIPane; +import com.fr.design.ui.ModernUIPane; + +/** + * 根据版本选择构造器 + * + * @author hades + * @version 10.0 + * Created by hades on 2021/6/13 + * @see {@link JxUIPane} + * @deprecated 6在下个版本弃用 + */ +public class ModernUIPaneFactory { + + /** + * 获取一个 JxBrowser pane 的构造器 + * + * @param 参数 + * @return 构造器 + */ + public static ModernUIPane.Builder modernUIPaneBuilder() { + if (isV7()) { + return new JxUIPane.Builder<>(); + } else { + return new ModernUIPane.Builder<>(); + } + } + + /** + * 判断 JxBrowser 版本是否在7或之上 + * + * @return 是否7或之上 + */ + public static boolean isV7() { + boolean hasJxBrowserV7 = true; + try { + Class.forName("com.teamdev.jxbrowser.net.Scheme"); + } catch (ClassNotFoundException e) { + hasJxBrowserV7 = false; + } + return hasJxBrowserV7; + } +} From 08cf5012c634b51e7366a809acea1e120b6f8fdf Mon Sep 17 00:00:00 2001 From: vito Date: Mon, 19 Jun 2023 19:35:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/ui/compatible/BuilderDiff.java | 31 +++++++++++++++++-- .../ui/compatible/ModernUIPaneFactory.java | 10 +++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/ui/compatible/BuilderDiff.java b/designer-base/src/main/java/com/fr/design/ui/compatible/BuilderDiff.java index 483257e9b3..99daa4555a 100644 --- a/designer-base/src/main/java/com/fr/design/ui/compatible/BuilderDiff.java +++ b/designer-base/src/main/java/com/fr/design/ui/compatible/BuilderDiff.java @@ -11,20 +11,45 @@ import com.teamdev.jxbrowser.event.Observer; * 封装jxbrwoser v6/v7的构建方式的差异 * * @author hades - * @version 10.0 - * Created by hades on 2021/6/13 * @see {@link JxUIPane} + * @since 10.0 + * Created on 2021/6/13 * @deprecated 6在下个版本弃用 */ @Deprecated public interface BuilderDiff { + /** + * v6准备工作 + * + * @param contextListener 上下文监听器 + * @return 构造器 + */ ModernUIPane.Builder prepareForV6(ScriptContextListener contextListener); + /** + * v6准备工作 + * + * @param loadListener 加载监听器 + * @return 构造器 + */ ModernUIPane.Builder prepareForV6(LoadListener loadListener); + /** + * v7准备工作 + * + * @param callback 注入js回调器 + * @return 构造器 + */ ModernUIPane.Builder prepareForV7(InjectJsCallback callback); + /** + * v7准备工作 + * + * @param event 事件 + * @param listener 监听器 + * @return 构造器 + */ ModernUIPane.Builder prepareForV7(Class event, Observer listener); -} \ No newline at end of file +} diff --git a/designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java b/designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java index f6e29e81c5..31774e90c9 100644 --- a/designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java +++ b/designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java @@ -7,9 +7,9 @@ import com.fr.design.ui.ModernUIPane; * 根据版本选择构造器 * * @author hades - * @version 10.0 - * Created by hades on 2021/6/13 * @see {@link JxUIPane} + * @since 10.0 + * Created on 2021/6/13 * @deprecated 6在下个版本弃用 */ public class ModernUIPaneFactory { @@ -34,12 +34,12 @@ public class ModernUIPaneFactory { * @return 是否7或之上 */ public static boolean isV7() { - boolean hasJxBrowserV7 = true; + boolean jxBrowserV7 = true; try { Class.forName("com.teamdev.jxbrowser.net.Scheme"); } catch (ClassNotFoundException e) { - hasJxBrowserV7 = false; + jxBrowserV7 = false; } - return hasJxBrowserV7; + return jxBrowserV7; } }