Browse Source

无JIRA任务 添加一个通用的web组件,其他地方暂时用不到

bugfix/10.0
richie 6 years ago
parent
commit
b21a12482a
  1. 33
      designer-base/src/main/java/com/fr/design/DesignerEnvManager.java
  2. 12
      designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java
  3. 18
      designer-base/src/main/java/com/fr/design/ui/ModernUI.java
  4. 119
      designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java
  5. 76
      designer-base/src/test/java/com/fr/design/ui/ModernUIPaneTest.java
  6. 17
      designer-base/src/test/resources/com/fr/design/ui/demo.html

33
designer-base/src/main/java/com/fr/design/DesignerEnvManager.java

@ -164,6 +164,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
private static List<SwingWorker> mapWorkerList = new ArrayList<SwingWorker>(); private static List<SwingWorker> mapWorkerList = new ArrayList<SwingWorker>();
private boolean imageCompress = false;//图片压缩 private boolean imageCompress = false;//图片压缩
// 开启内嵌web页面的调试窗口
private boolean openDebug = false;
/** /**
* DesignerEnvManager. * DesignerEnvManager.
@ -1383,6 +1385,13 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
reader.readXMLObject(this.configManager); reader.readXMLObject(this.configManager);
} }
private void readOpenDebug(XMLableReader reader) {
String tmpVal;
if (StringUtils.isNotBlank(tmpVal = reader.getElementValue())) {
this.openDebug = Boolean.parseBoolean(tmpVal);
}
}
public String getUUID() { public String getUUID() {
return StringUtils.isEmpty(uuid) ? UUID.randomUUID().toString() : uuid; return StringUtils.isEmpty(uuid) ? UUID.randomUUID().toString() : uuid;
} }
@ -1411,6 +1420,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
this.imageCompress = imageCompress; this.imageCompress = imageCompress;
} }
public boolean isOpenDebug() {
return openDebug;
}
public void setOpenDebug(boolean openDebug) {
this.openDebug = openDebug;
}
/** /**
* Read XML.<br> * Read XML.<br>
* The method will be invoked when read data from XML file.<br> * The method will be invoked when read data from XML file.<br>
@ -1458,12 +1475,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
readUUID(reader); readUUID(reader);
} else if ("status".equals(name)) { } else if ("status".equals(name)) {
readActiveStatus(reader); readActiveStatus(reader);
} else if (ComparatorUtils.equals(CAS_PARAS, name)) { } else if (CAS_PARAS.equals(name)) {
readHttpsParas(reader); readHttpsParas(reader);
} else if (name.equals("AlphaFineConfigManager")) { } else if ("AlphaFineConfigManager".equals(name)) {
readAlphaFineAttr(reader); readAlphaFineAttr(reader);
} else if (name.equals("RecentColors")) { } else if ("RecentColors".equals(name)) {
readRecentColor(reader); readRecentColor(reader);
} else if ("OpenDebug".equals(name)) {
readOpenDebug(reader);
} else { } else {
readLayout(reader, name); readLayout(reader, name);
} }
@ -1683,6 +1702,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
} }
} }
private void writeOpenDebug(XMLPrintWriter writer) {
if (this.openDebug) {
writer.startTAG("OpenDebug");
writer.textNode(String.valueOf(openDebug));
writer.end();
}
}
//写入uuid //写入uuid
private void writeUUID(XMLPrintWriter writer) { private void writeUUID(XMLPrintWriter writer) {

12
designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java

@ -18,6 +18,7 @@ import com.fr.design.gui.ilable.ActionLabel;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.gui.ispinner.UISpinner;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
@ -131,6 +132,7 @@ public class PreferencePane extends BasicPane {
private UITextField jdkHomeTextField; private UITextField jdkHomeTextField;
private UICheckBox oracleSpace; private UICheckBox oracleSpace;
private UISpinner cachingTemplateSpinner; private UISpinner cachingTemplateSpinner;
private UICheckBox openDebugComboBox;
private UICheckBox joinProductImprove; private UICheckBox joinProductImprove;
public PreferencePane() { public PreferencePane() {
@ -171,6 +173,12 @@ public class PreferencePane extends BasicPane {
oracleSpace = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Show_All_Oracle_Tables")); oracleSpace = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Show_All_Oracle_Tables"));
oraclePane.add(oracleSpace); oraclePane.add(oracleSpace);
JPanel debuggerPane = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Design_Basic_Develop_Tools"));
openDebugComboBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Basic_Open_Debug_Window"));
debuggerPane.add(openDebugComboBox, BorderLayout.CENTER);
advancePane.add(debuggerPane);
JPanel improvePane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Product_Improve")); JPanel improvePane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Product_Improve"));
joinProductImprove = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Join_Product_Improve")); joinProductImprove = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Join_Product_Improve"));
improvePane.add(joinProductImprove); improvePane.add(joinProductImprove);
@ -550,6 +558,8 @@ public class PreferencePane extends BasicPane {
this.portEditor.setValue(new Integer(designerEnvManager.getEmbedServerPort())); this.portEditor.setValue(new Integer(designerEnvManager.getEmbedServerPort()));
openDebugComboBox.setSelected(designerEnvManager.isOpenDebug());
this.oracleSpace.setSelected(designerEnvManager.isOracleSystemSpace()); this.oracleSpace.setSelected(designerEnvManager.isOracleSystemSpace());
this.cachingTemplateSpinner.setValue(designerEnvManager.getCachingTemplateLimit()); this.cachingTemplateSpinner.setValue(designerEnvManager.getCachingTemplateLimit());
this.joinProductImprove.setSelected(designerEnvManager.isJoinProductImprove()); this.joinProductImprove.setSelected(designerEnvManager.isJoinProductImprove());
@ -609,6 +619,8 @@ public class PreferencePane extends BasicPane {
designerEnvManager.setJettyServerPort(portEditor.getValue().intValue()); designerEnvManager.setJettyServerPort(portEditor.getValue().intValue());
designerEnvManager.setOpenDebug(openDebugComboBox.isSelected());
designerEnvManager.setOracleSystemSpace(this.oracleSpace.isSelected()); designerEnvManager.setOracleSystemSpace(this.oracleSpace.isSelected());
designerEnvManager.setCachingTemplateLimit((int) this.cachingTemplateSpinner.getValue()); designerEnvManager.setCachingTemplateLimit((int) this.cachingTemplateSpinner.getValue());
designerEnvManager.setJoinProductImprove(this.joinProductImprove.isSelected()); designerEnvManager.setJoinProductImprove(this.joinProductImprove.isSelected());

18
designer-base/src/main/java/com/fr/design/ui/ModernUI.java

@ -0,0 +1,18 @@
package com.fr.design.ui;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-03-05
*/
class ModernUI {
static final String SCRIPT_STRING = "var arr = \"%s\".split(\".\").reverse();\n" +
"var create = function(obj, names) {\n" +
"var name = names.pop();\n" +
"if (!name) {return;}\n" +
"if (!obj[name]) {obj[name] = {};}\n" +
" create(obj[name], names);\n" +
"}\n" +
"create(window, arr);";
}

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

@ -0,0 +1,119 @@
package com.fr.design.ui;
import com.fr.design.DesignerEnvManager;
import com.fr.design.dialog.BasicPane;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserPreferences;
import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent;
import com.teamdev.jxbrowser.chromium.events.LoadAdapter;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
import javax.swing.*;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-03-04
* 用于加载html5的Swing容器可以在设计选项设置中打开调试窗口示例可查看com.fr.design.ui.ModernUIPaneTest
*/
public class ModernUIPane<T> extends BasicPane {
private Browser browser;
private String namespace = "NS";
private String variable = "data";
private String expression = "update()";
private ModernUIPane() {
initialize();
}
private void initialize() {
if (browser == null) {
setLayout(new BorderLayout());
BrowserPreferences.setChromiumSwitches("--disable-google-traffic");
if (DesignerEnvManager.getEnvManager().isOpenDebug()) {
JSplitPane splitPane = new JSplitPane();
add(splitPane, BorderLayout.CENTER);
splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
splitPane.setDividerLocation(500);
BrowserPreferences.setChromiumSwitches("--remote-debugging-port=9222");
initializeBrowser();
splitPane.setLeftComponent(new BrowserView(browser));
Browser debugger = new Browser();
debugger.loadURL(browser.getRemoteDebuggingURL());
BrowserView debuggerView = new BrowserView(debugger);
splitPane.setRightComponent(debuggerView);
} else {
initializeBrowser();
add(new BrowserView(browser), BorderLayout.CENTER);
}
}
}
private void initializeBrowser() {
browser = new Browser();
}
@Override
protected String title4PopupWindow() {
return "Modern";
}
public void populate(final T t) {
browser.addLoadListener(new LoadAdapter() {
@Override
public void onFinishLoadingFrame(FinishLoadingEvent event) {
if (event.isMainFrame()) {
event.getBrowser().executeJavaScript(String.format(ModernUI.SCRIPT_STRING, namespace));
JSValue ns = event.getBrowser().executeJavaScriptAndReturnValue("window." + namespace);
ns.asObject().setProperty(variable, t);
}
}
});
}
public T update() {
JSValue jsValue = browser.executeJavaScriptAndReturnValue("window." + namespace + "." + expression);
if (jsValue.isObject()) {
return (T)jsValue.asJavaObject();
}
return null;
}
public static class Builder<T> {
private ModernUIPane<T> pane = new ModernUIPane<>();
public Builder<T> withURL(String url) {
pane.browser.loadURL(url);
return this;
}
public Builder<T> withHTML(String html) {
pane.browser.loadHTML(html);
return this;
}
public Builder<T> namespace(String namespace) {
pane.namespace = namespace;
return this;
}
public Builder<T> variable(String name) {
pane.variable = name;
return this;
}
public Builder<T> expression(String expression) {
pane.expression = expression;
return this;
}
public ModernUIPane<T> build() {
return pane;
}
}
}

76
designer-base/src/test/java/com/fr/design/ui/ModernUIPaneTest.java

@ -0,0 +1,76 @@
package com.fr.design.ui;
import com.fr.design.DesignerEnvManager;
import com.fr.general.IOUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-03-05
*/
public class ModernUIPaneTest {
public static void main(String... args) {
JFrame frame = new JFrame();
frame.setSize(1200, 800);
JPanel contentPane = (JPanel) frame.getContentPane();
// 是否需要开启调试窗口
DesignerEnvManager.getEnvManager().setOpenDebug(true);
final ModernUIPane<Model> pane = new ModernUIPane.Builder<Model>()
.withHTML(IOUtils.readResourceAsString("/com/fr/design/ui/demo.html")).namespace("MyNS").build();
contentPane.add(pane, BorderLayout.CENTER);
Model model = new Model();
model.setAge(20);
model.setName("Pick");
pane.populate(model);
JPanel panel = new JPanel(new FlowLayout());
contentPane.add(panel, BorderLayout.SOUTH);
JButton button = new JButton("点击我可以看到JAVA控制台输出的新值:99");
panel.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Model returnValue = pane.update();
if (returnValue != null) {
System.out.println(returnValue.getAge());
}
}
});
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static class Model {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void print(String message) {
System.out.println(message);
}
}
}

17
designer-base/src/test/resources/com/fr/design/ui/demo.html

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
window.MyNS = window.MyNS || {};
MyNS.update = function () {
MyNS.data.setAge(111.11);
return MyNS.data;
};
</script>
</head>
<body>
<div>测试页面,请点击最下面的按钮</div>
</body>
</html>
Loading…
Cancel
Save