Browse Source

Pull request #5773: CHART-20402 增加几个接口

Merge in DESIGN/design from ~EASON/design:feature/10.0 to feature/10.0

* commit '1248729a97b44d788b8f2b1408301793f7d43410':
  新接口
  新接口
  CHART-20402 增加几个接口
  CHART-20402 增加几个接口
  CHART-20402 增加几个接口
feature/10.0
eason 3 years ago
parent
commit
c083183945
  1. 38
      designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java
  2. 2
      designer-base/src/main/java/com/fr/design/ui/compatible/BuilderDiff.java
  3. 19
      designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java
  4. 32
      designer-base/src/main/java/com/fr/design/ui/compatible/NewModernUIPane.java

38
designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java

@ -11,12 +11,14 @@ import com.fr.web.struct.AssembleComponent;
import com.teamdev.jxbrowser.browser.callback.InjectJsCallback; import com.teamdev.jxbrowser.browser.callback.InjectJsCallback;
import com.teamdev.jxbrowser.chromium.Browser; import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserType; import com.teamdev.jxbrowser.chromium.BrowserType;
import com.teamdev.jxbrowser.chromium.JSObject;
import com.teamdev.jxbrowser.chromium.JSValue; import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.events.LoadListener; import com.teamdev.jxbrowser.chromium.events.LoadListener;
import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter; import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter;
import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent; import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent;
import com.teamdev.jxbrowser.chromium.events.ScriptContextListener; import com.teamdev.jxbrowser.chromium.events.ScriptContextListener;
import com.teamdev.jxbrowser.chromium.swing.BrowserView; import com.teamdev.jxbrowser.chromium.swing.BrowserView;
import com.teamdev.jxbrowser.event.Observer;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@ -157,6 +159,36 @@ public class ModernUIPane<T> extends BasicPane {
return null; return null;
} }
public void disposeBrowser() {
if(browser != null) {
browser.dispose();
browser = null;
}
}
public void clearCache() {
if (browser != null) {
browser.getCacheStorage().clearCache();
}
}
public void executeJavaScript(String javaScript) {
if (browser != null) {
browser.executeJavaScript(javaScript);
}
}
public JSObject getEmptyJSObjectV6() {
if (browser != null) {
return browser.executeJavaScriptAndReturnValue("var __empty_props__ = {};__empty_props__").asObject();
}
return null;
}
public static class Builder<T> implements BuilderDiff<T> { public static class Builder<T> implements BuilderDiff<T> {
private ModernUIPane<T> pane; private ModernUIPane<T> pane;
@ -293,6 +325,12 @@ public class ModernUIPane<T> extends BasicPane {
return this; return this;
} }
@Override
public Builder<T> prepareForV7(Class event, Observer listener) {
// do nothing
return this;
}
public ModernUIPane<T> build() { public ModernUIPane<T> build() {
return pane; return pane;
} }

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

@ -4,6 +4,7 @@ import com.fr.design.ui.ModernUIPane;
import com.teamdev.jxbrowser.browser.callback.InjectJsCallback; import com.teamdev.jxbrowser.browser.callback.InjectJsCallback;
import com.teamdev.jxbrowser.chromium.events.LoadListener; import com.teamdev.jxbrowser.chromium.events.LoadListener;
import com.teamdev.jxbrowser.chromium.events.ScriptContextListener; import com.teamdev.jxbrowser.chromium.events.ScriptContextListener;
import com.teamdev.jxbrowser.event.Observer;
/** /**
* 封装jxbrwoser v6/v7的构建方式的差异 * 封装jxbrwoser v6/v7的构建方式的差异
@ -20,5 +21,6 @@ public interface BuilderDiff<T> {
ModernUIPane.Builder<T> prepareForV7(InjectJsCallback callback); ModernUIPane.Builder<T> prepareForV7(InjectJsCallback callback);
ModernUIPane.Builder<T> prepareForV7(Class event, Observer listener);
} }

19
designer-base/src/main/java/com/fr/design/ui/compatible/ModernUIPaneFactory.java

@ -11,6 +11,17 @@ import com.fr.stable.os.OperatingSystem;
public class ModernUIPaneFactory { public class ModernUIPaneFactory {
public static <T> ModernUIPane.Builder<T> modernUIPaneBuilder() { public static <T> ModernUIPane.Builder<T> modernUIPaneBuilder() {
if (isV7()) {
return new NewModernUIPane.Builder<>();
} else {
return new ModernUIPane.Builder<>();
}
}
public static boolean isV7() {
// 7.15的class不存在时 走老版本 // 7.15的class不存在时 走老版本
boolean hasJxBrowserV7_15 = true; boolean hasJxBrowserV7_15 = true;
try { try {
@ -18,10 +29,8 @@ public class ModernUIPaneFactory {
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
hasJxBrowserV7_15 = false; hasJxBrowserV7_15 = false;
} }
if (OperatingSystem.isWindows() && hasJxBrowserV7_15) {
return new NewModernUIPane.Builder<>(); return OperatingSystem.isWindows() && hasJxBrowserV7_15;
} else {
return new ModernUIPane.Builder<>();
}
} }
} }

32
designer-base/src/main/java/com/fr/design/ui/compatible/NewModernUIPane.java

@ -15,6 +15,7 @@ import com.teamdev.jxbrowser.chromium.events.ScriptContextListener;
import com.teamdev.jxbrowser.engine.Engine; import com.teamdev.jxbrowser.engine.Engine;
import com.teamdev.jxbrowser.engine.EngineOptions; import com.teamdev.jxbrowser.engine.EngineOptions;
import com.teamdev.jxbrowser.engine.RenderingMode; import com.teamdev.jxbrowser.engine.RenderingMode;
import com.teamdev.jxbrowser.event.Observer;
import com.teamdev.jxbrowser.js.JsObject; import com.teamdev.jxbrowser.js.JsObject;
import com.teamdev.jxbrowser.net.Scheme; import com.teamdev.jxbrowser.net.Scheme;
import com.teamdev.jxbrowser.view.swing.BrowserView; import com.teamdev.jxbrowser.view.swing.BrowserView;
@ -161,6 +162,29 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
return null; return null;
} }
public void disposeBrowser() {
if (browser != null) {
browser.close();
browser = null;
}
}
public void clearCache() {
if (browser != null) {
browser.engine().httpCache().clear();
}
}
public void executeJavaScript(String javaScript) {
if (browser != null) {
browser.mainFrame().ifPresent(frame -> {
frame.executeJavaScript(javaScript);
});
}
}
public static class Builder<T> extends ModernUIPane.Builder<T> { public static class Builder<T> extends ModernUIPane.Builder<T> {
private NewModernUIPane<T> pane = new NewModernUIPane<>(); private NewModernUIPane<T> pane = new NewModernUIPane<>();
@ -301,6 +325,14 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
return prepare(callback); return prepare(callback);
} }
@Override
public ModernUIPane.Builder<T> prepareForV7(Class event, Observer listener) {
pane.browser.navigation().on(event, listener);
return this;
}
@Override @Override
public NewModernUIPane<T> build() { public NewModernUIPane<T> build() {
return pane; return pane;

Loading…
Cancel
Save