From 8950771cede13a46c10d1960730fe1a90944f559 Mon Sep 17 00:00:00 2001 From: "Qinghui.Liu" Date: Mon, 28 Dec 2020 09:53:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../richText/VanChartFieldAttrPane.java | 20 +++-- .../richText/VanChartFieldListPane.java | 5 +- .../richText/VanChartRichEditorModel.java | 11 +++ .../richText/VanChartRichEditorPane.java | 74 +++++++++---------- .../com/fr/design/editor/rich_editor.html | 31 +++++++- 5 files changed, 86 insertions(+), 55 deletions(-) diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldAttrPane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldAttrPane.java index cc99a2ce1..89c3cd73e 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldAttrPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldAttrPane.java @@ -16,7 +16,6 @@ import javax.swing.SwingConstants; import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ActionListener; -import java.awt.event.MouseListener; import java.text.Format; public class VanChartFieldAttrPane extends JPanel { @@ -27,6 +26,15 @@ public class VanChartFieldAttrPane extends JPanel { private JPanel fieldFunctionPane; public VanChartFieldAttrPane() { + initComponents(); + + this.setLayout(new BorderLayout()); + this.add(fieldFormatPane, BorderLayout.NORTH); + this.add(fieldFunctionPane, BorderLayout.CENTER); + this.setBorder(BorderFactory.createEmptyBorder(0, 30, 0, 0)); + } + + private void initComponents() { double p = TableLayout.PREFERRED; double d = TableLayout4VanChartHelper.DESCRIPTION_AREA_WIDTH; double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH; @@ -35,10 +43,6 @@ public class VanChartFieldAttrPane extends JPanel { protected JPanel createContentPane(Component[][] components) { return TableLayout4VanChartHelper.createGapTableLayoutPane(components, new double[]{p, p, p}, new double[]{d, e}); } - - public void addActionListener(ActionListener listener) { - - } }; fieldDataFunction = new CalculateComboBox(); @@ -49,11 +53,6 @@ public class VanChartFieldAttrPane extends JPanel { }; fieldFunctionPane = TableLayout4VanChartHelper.createGapTableLayoutPane(components, new double[]{p, p}, new double[]{d, e}); - - this.setLayout(new BorderLayout()); - this.add(fieldFormatPane, BorderLayout.NORTH); - this.add(fieldFunctionPane, BorderLayout.CENTER); - this.setBorder(BorderFactory.createEmptyBorder(0, 30, 0, 0)); } public void registerFunctionListener(ActionListener listener) { @@ -67,7 +66,6 @@ public class VanChartFieldAttrPane extends JPanel { public void populate(Format format, AbstractDataFunction dataFunction, boolean showDataFunction) { fieldFormatPane.populateBean(format); fieldDataFunction.populateBean(dataFunction); - fieldFunctionPane.setVisible(showDataFunction); } diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListPane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListPane.java index aa3dbd17b..c4039c691 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListPane.java @@ -194,9 +194,8 @@ public class VanChartFieldListPane extends JPanel { public void addSelectedField(String fieldName, String fieldId) { VanChartRichEditorModel model = richEditorPane.update(); - String content = model.getContent() + getFieldRichText(fieldName, fieldId); - model.setContent(content); - VanChartRichEditorPane.createRichEditorPane(model); + model.setAddition(fieldName); + VanChartRichEditorPane.richEditorAddField(model); } public void populateFieldFormatPane() { diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorModel.java b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorModel.java index 245eaa951..83df27c0f 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorModel.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorModel.java @@ -10,6 +10,7 @@ public class VanChartRichEditorModel { private String params = StringUtils.EMPTY; private String initParams = StringUtils.EMPTY; private String align = TextAlign.LEFT.getAlign(); + private String addition = StringUtils.EMPTY; public VanChartRichEditorModel() { } @@ -20,6 +21,7 @@ public class VanChartRichEditorModel { this.params = params; this.initParams = initParams; this.align = align; + this.addition = StringUtils.EMPTY; } public String getContent() { @@ -61,4 +63,13 @@ public class VanChartRichEditorModel { public void setAlign(String align) { this.align = align; } + + public String getAddition() { + return addition; + } + + public void setAddition(String addition) { + this.addition = addition; + } + } diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorPane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorPane.java index 99afba30e..87710da55 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorPane.java @@ -1,10 +1,8 @@ package com.fr.van.chart.designer.component.richText; -import com.fr.concurrent.NamedThreadFactory; import com.fr.design.DesignerEnvManager; import com.fr.design.ui.ModernUIPane; import com.fr.general.IOUtils; -import com.fr.log.FineLoggerFactory; import com.fr.plugin.chart.base.AttrTooltipRichText; import com.fr.plugin.chart.type.TextAlign; import com.fr.stable.StringUtils; @@ -15,38 +13,20 @@ import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent; import java.util.Locale; import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; public class VanChartRichEditorPane { - private static final String namespace = "Pool"; - private static final String variable = "data"; - private static final String richEditorPath = "/com/fr/design/editor/rich_editor.html"; - private static final String expression = "dispatch()"; + private static final String NAME_SPACE = "Pool"; + private static final String VARIABLE = "data"; + + private static final String RICH_EDITOR_HTML = "/com/fr/design/editor/rich_editor.html"; + + private static final String REFRESH = "refresh()"; + private static final String ADD_FIELD = "addField()"; private static ModernUIPane richEditorPane; private static Browser browser; - public static void initRichEditorPane() { - ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("VanChartRichEditor")); - - try { - singleThreadExecutor.submit(new Runnable() { - @Override - public void run() { - try { - richEditorPane = initPane(new VanChartRichEditorModel()); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - } - }); - } finally { - singleThreadExecutor.shutdown(); - } - } - public static ModernUIPane createRichEditorPane(AttrTooltipRichText richEditor) { VanChartRichEditorModel model = getRichEditorModel(richEditor); return createRichEditorPane(model); @@ -55,13 +35,25 @@ public class VanChartRichEditorPane { public static ModernUIPane createRichEditorPane(VanChartRichEditorModel model) { if (richEditorPane == null) { richEditorPane = initPane(model); - } else if (browser != null) { - updatePane(browser, model); + } else { + richEditorRefresh(model); } return richEditorPane; } + public static void richEditorRefresh(VanChartRichEditorModel model) { + if (richEditorPane != null && browser != null) { + refresh(browser, model); + } + } + + public static void richEditorAddField(VanChartRichEditorModel model) { + if (richEditorPane != null && browser != null) { + addField(browser, model); + } + } + public static ModernUIPane initPane(VanChartRichEditorModel model) { return new ModernUIPane.Builder() .prepare(new ScriptContextAdapter() { @@ -74,18 +66,26 @@ public class VanChartRichEditorPane { browser.executeJavaScript(generateTransformI18nJS()); browser.executeJavaScript(IOUtils.readResourceAsString("/com/fr/web/ui/materials.min.js")); - JSValue ns = browser.executeJavaScriptAndReturnValue("window." + namespace); - ns.asObject().setProperty(variable, model); + JSValue ns = browser.executeJavaScriptAndReturnValue("window." + NAME_SPACE); + ns.asObject().setProperty(VARIABLE, model); } }) - .withEMB(richEditorPath) - .namespace(namespace).build(); + .withEMB(RICH_EDITOR_HTML) + .namespace(NAME_SPACE).build(); + } + + public static void refresh(Browser browser, VanChartRichEditorModel model) { + stateChange(browser, model, REFRESH); + } + + public static void addField(Browser browser, VanChartRichEditorModel model) { + stateChange(browser, model, ADD_FIELD); } - public static void updatePane(Browser browser, VanChartRichEditorModel model) { - JSValue ns = browser.executeJavaScriptAndReturnValue("window." + namespace); - ns.asObject().setProperty(variable, model); - browser.executeJavaScript("window." + namespace + "." + expression); + public static void stateChange(Browser browser, VanChartRichEditorModel model, String trigger) { + JSValue ns = browser.executeJavaScriptAndReturnValue("window." + NAME_SPACE); + ns.asObject().setProperty(VARIABLE, model); + browser.executeJavaScript("window." + NAME_SPACE + "." + trigger); } public static VanChartRichEditorModel getRichEditorModel(AttrTooltipRichText richText) { diff --git a/designer-chart/src/main/resources/com/fr/design/editor/rich_editor.html b/designer-chart/src/main/resources/com/fr/design/editor/rich_editor.html index e6c769f0a..f62d7dbb2 100644 --- a/designer-chart/src/main/resources/com/fr/design/editor/rich_editor.html +++ b/designer-chart/src/main/resources/com/fr/design/editor/rich_editor.html @@ -88,8 +88,7 @@ {type: "bi.rich_editor_color_chooser"}, {type: "bi.rich_editor_align_left_button"}, {type: "bi.rich_editor_align_center_button"}, - {type: "bi.rich_editor_align_right_button"}, - {type: "bi.design.chart.common.editor.insert_param"} + {type: "bi.rich_editor_align_right_button"} ] }, ref: function (_ref) { @@ -97,7 +96,7 @@ } }); - Pool.dispatch = function () { + Pool.refresh = function () { var content = Pool.data.getContent(); var isAuto = Pool.data.isAuto(); var params = Pool.data.getParams(); @@ -117,7 +116,31 @@ }); rich_editor.setFocus(); - } + }; + + Pool.addField = function () { + var editorService = BI.Services.getService("bi.service.design.chart.common.editor"); + + var content = Pool.data.getContent(); + var isAuto = Pool.data.isAuto(); + var params = Pool.data.getParams(); + var addition = Pool.data.getAddition(); + + if (addition) { + // todo 暂时先处理成在content后加一行 + content += '

' + editorService.getEditorParamImage(addition) + '

'; + } + + rich_editor.editor.bindToolbar(rich_editor.bar); + + rich_editor.setValue({ + content: content, + isAuto: isAuto, + dimensionIds: getDimensionIds(params) + }); + + rich_editor.setFocus(); + }; Pool.update = function () { var {content, isAuto} = rich_editor.getValue();