Browse Source

Pull request #12247: REPORT-93559 补充兼容插件接口

Merge in DESIGN/design from ~VITO/c-design:release/11.0 to release/11.0

* commit '08cf5012c634b51e7366a809acea1e120b6f8fdf':
  无jira任务 代码规范
  REPORT-93559 补充兼容插件接口
release/11.0
vito-刘恒霖 1 year ago
parent
commit
51dce538b1
  1. 1
      build.gradle
  2. 38
      designer-base/src/main/java/com/fr/design/jxbrowser/JxUIPane.java
  3. 21
      designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java
  4. 55
      designer-base/src/main/java/com/fr/design/ui/compatible/BuilderDiff.java
  5. 45
      designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java

1
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}"
}
}

38
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<T> extends ModernUIPane<T> {
*
* @param <T> 参数
*/
public static class Builder<T> {
public static class Builder<T> extends ModernUIPane.Builder<T> {
private String namespace;
private String variable;
private String expression;
private InjectJsCallback callback;
private Pair<Class, Observer> listenerPair;
private final Map<String, Object> namespacePropertyMap;
private final Map<String, Object> propertyMap;
private final Map<String, PropertyBuild> buildPropertyMap;
private Object variableProperty;
private Map<String, String> parameterMap;
@ -239,6 +247,7 @@ public class JxUIPane<T> extends ModernUIPane<T> {
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<T> extends ModernUIPane<T> {
* @param callback 回调
* @return builder
*/
public JxUIPane.Builder<T> prepare(InjectJsCallback callback) {
public Builder<T> prepare(InjectJsCallback callback) {
this.callback = callback;
return this;
}
@Override
public Builder<T> prepareForV6(ScriptContextListener contextListener) {
return this;
}
@Override
public Builder<T> prepareForV6(LoadListener loadListener) {
return this;
}
@Override
public JxUIPane.Builder<T> prepareForV7(InjectJsCallback callback) {
prepare(callback);
return this;
}
@Override
public JxUIPane.Builder<T> prepareForV7(Class event, Observer listener) {
listenerPair = new Pair<>(event, listener);
return this;
}
/**
* 加载jar包中的资源
*
@ -457,6 +488,9 @@ public class JxUIPane<T> extends ModernUIPane<T> {
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)) {

21
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<T> extends BasicPane {
*
* @param <T>
*/
public static class Builder<T> {
public static class Builder<T> implements BuilderDiff<T> {
private ModernUIPane<T> pane;
@ -332,14 +335,28 @@ public class ModernUIPane<T> extends BasicPane {
return this;
}
@Override
public Builder<T> prepareForV6(ScriptContextListener contextListener) {
return prepare(contextListener);
}
@Override
public Builder<T> prepareForV6(LoadListener loadListener) {
return prepare(loadListener);
}
@Override
public Builder<T> prepareForV7(InjectJsCallback callback) {
// do nothing
return this;
}
@Override
public Builder<T> prepareForV7(Class event, Observer listener) {
// do nothing
return this;
}
public ModernUIPane<T> build() {
return pane;
}

55
designer-base/src/main/java/com/fr/design/ui/compatible/BuilderDiff.java

@ -0,0 +1,55 @@
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
* @see {@link JxUIPane}
* @since 10.0
* Created on 2021/6/13
* @deprecated 6在下个版本弃用
*/
@Deprecated
public interface BuilderDiff<T> {
/**
* v6准备工作
*
* @param contextListener 上下文监听器
* @return 构造器
*/
ModernUIPane.Builder<T> prepareForV6(ScriptContextListener contextListener);
/**
* v6准备工作
*
* @param loadListener 加载监听器
* @return 构造器
*/
ModernUIPane.Builder<T> prepareForV6(LoadListener loadListener);
/**
* v7准备工作
*
* @param callback 注入js回调器
* @return 构造器
*/
ModernUIPane.Builder<T> prepareForV7(InjectJsCallback callback);
/**
* v7准备工作
*
* @param event 事件
* @param listener 监听器
* @return 构造器
*/
ModernUIPane.Builder<T> prepareForV7(Class event, Observer listener);
}

45
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
* @see {@link JxUIPane}
* @since 10.0
* Created on 2021/6/13
* @deprecated 6在下个版本弃用
*/
public class ModernUIPaneFactory {
/**
* 获取一个 JxBrowser pane 的构造器
*
* @param <T> 参数
* @return 构造器
*/
public static <T> ModernUIPane.Builder<T> modernUIPaneBuilder() {
if (isV7()) {
return new JxUIPane.Builder<>();
} else {
return new ModernUIPane.Builder<>();
}
}
/**
* 判断 JxBrowser 版本是否在7或之上
*
* @return 是否7或之上
*/
public static boolean isV7() {
boolean jxBrowserV7 = true;
try {
Class.forName("com.teamdev.jxbrowser.net.Scheme");
} catch (ClassNotFoundException e) {
jxBrowserV7 = false;
}
return jxBrowserV7;
}
}
Loading…
Cancel
Save