Browse Source

调整代码结构

feature/big-screen
Qinghui.Liu 4 years ago
parent
commit
8950771ced
  1. 20
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldAttrPane.java
  2. 5
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListPane.java
  3. 11
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorModel.java
  4. 74
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorPane.java
  5. 31
      designer-chart/src/main/resources/com/fr/design/editor/rich_editor.html

20
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.BorderLayout;
import java.awt.Component; import java.awt.Component;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.text.Format; import java.text.Format;
public class VanChartFieldAttrPane extends JPanel { public class VanChartFieldAttrPane extends JPanel {
@ -27,6 +26,15 @@ public class VanChartFieldAttrPane extends JPanel {
private JPanel fieldFunctionPane; private JPanel fieldFunctionPane;
public VanChartFieldAttrPane() { 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 p = TableLayout.PREFERRED;
double d = TableLayout4VanChartHelper.DESCRIPTION_AREA_WIDTH; double d = TableLayout4VanChartHelper.DESCRIPTION_AREA_WIDTH;
double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH; double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH;
@ -35,10 +43,6 @@ public class VanChartFieldAttrPane extends JPanel {
protected JPanel createContentPane(Component[][] components) { protected JPanel createContentPane(Component[][] components) {
return TableLayout4VanChartHelper.createGapTableLayoutPane(components, new double[]{p, p, p}, new double[]{d, e}); return TableLayout4VanChartHelper.createGapTableLayoutPane(components, new double[]{p, p, p}, new double[]{d, e});
} }
public void addActionListener(ActionListener listener) {
}
}; };
fieldDataFunction = new CalculateComboBox(); fieldDataFunction = new CalculateComboBox();
@ -49,11 +53,6 @@ public class VanChartFieldAttrPane extends JPanel {
}; };
fieldFunctionPane = TableLayout4VanChartHelper.createGapTableLayoutPane(components, new double[]{p, p}, new double[]{d, e}); 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) { public void registerFunctionListener(ActionListener listener) {
@ -67,7 +66,6 @@ public class VanChartFieldAttrPane extends JPanel {
public void populate(Format format, AbstractDataFunction dataFunction, boolean showDataFunction) { public void populate(Format format, AbstractDataFunction dataFunction, boolean showDataFunction) {
fieldFormatPane.populateBean(format); fieldFormatPane.populateBean(format);
fieldDataFunction.populateBean(dataFunction); fieldDataFunction.populateBean(dataFunction);
fieldFunctionPane.setVisible(showDataFunction); fieldFunctionPane.setVisible(showDataFunction);
} }

5
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) { public void addSelectedField(String fieldName, String fieldId) {
VanChartRichEditorModel model = richEditorPane.update(); VanChartRichEditorModel model = richEditorPane.update();
String content = model.getContent() + getFieldRichText(fieldName, fieldId); model.setAddition(fieldName);
model.setContent(content); VanChartRichEditorPane.richEditorAddField(model);
VanChartRichEditorPane.createRichEditorPane(model);
} }
public void populateFieldFormatPane() { public void populateFieldFormatPane() {

11
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 params = StringUtils.EMPTY;
private String initParams = StringUtils.EMPTY; private String initParams = StringUtils.EMPTY;
private String align = TextAlign.LEFT.getAlign(); private String align = TextAlign.LEFT.getAlign();
private String addition = StringUtils.EMPTY;
public VanChartRichEditorModel() { public VanChartRichEditorModel() {
} }
@ -20,6 +21,7 @@ public class VanChartRichEditorModel {
this.params = params; this.params = params;
this.initParams = initParams; this.initParams = initParams;
this.align = align; this.align = align;
this.addition = StringUtils.EMPTY;
} }
public String getContent() { public String getContent() {
@ -61,4 +63,13 @@ public class VanChartRichEditorModel {
public void setAlign(String align) { public void setAlign(String align) {
this.align = align; this.align = align;
} }
public String getAddition() {
return addition;
}
public void setAddition(String addition) {
this.addition = addition;
}
} }

74
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; package com.fr.van.chart.designer.component.richText;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.ui.ModernUIPane; import com.fr.design.ui.ModernUIPane;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.chart.base.AttrTooltipRichText; import com.fr.plugin.chart.base.AttrTooltipRichText;
import com.fr.plugin.chart.type.TextAlign; import com.fr.plugin.chart.type.TextAlign;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -15,38 +13,20 @@ import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class VanChartRichEditorPane { public class VanChartRichEditorPane {
private static final String namespace = "Pool"; private static final String NAME_SPACE = "Pool";
private static final String variable = "data"; 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 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<VanChartRichEditorModel> richEditorPane; private static ModernUIPane<VanChartRichEditorModel> richEditorPane;
private static Browser browser; 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<VanChartRichEditorModel> createRichEditorPane(AttrTooltipRichText richEditor) { public static ModernUIPane<VanChartRichEditorModel> createRichEditorPane(AttrTooltipRichText richEditor) {
VanChartRichEditorModel model = getRichEditorModel(richEditor); VanChartRichEditorModel model = getRichEditorModel(richEditor);
return createRichEditorPane(model); return createRichEditorPane(model);
@ -55,13 +35,25 @@ public class VanChartRichEditorPane {
public static ModernUIPane<VanChartRichEditorModel> createRichEditorPane(VanChartRichEditorModel model) { public static ModernUIPane<VanChartRichEditorModel> createRichEditorPane(VanChartRichEditorModel model) {
if (richEditorPane == null) { if (richEditorPane == null) {
richEditorPane = initPane(model); richEditorPane = initPane(model);
} else if (browser != null) { } else {
updatePane(browser, model); richEditorRefresh(model);
} }
return richEditorPane; 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<VanChartRichEditorModel> initPane(VanChartRichEditorModel model) { public static ModernUIPane<VanChartRichEditorModel> initPane(VanChartRichEditorModel model) {
return new ModernUIPane.Builder<VanChartRichEditorModel>() return new ModernUIPane.Builder<VanChartRichEditorModel>()
.prepare(new ScriptContextAdapter() { .prepare(new ScriptContextAdapter() {
@ -74,18 +66,26 @@ public class VanChartRichEditorPane {
browser.executeJavaScript(generateTransformI18nJS()); browser.executeJavaScript(generateTransformI18nJS());
browser.executeJavaScript(IOUtils.readResourceAsString("/com/fr/web/ui/materials.min.js")); browser.executeJavaScript(IOUtils.readResourceAsString("/com/fr/web/ui/materials.min.js"));
JSValue ns = browser.executeJavaScriptAndReturnValue("window." + namespace); JSValue ns = browser.executeJavaScriptAndReturnValue("window." + NAME_SPACE);
ns.asObject().setProperty(variable, model); ns.asObject().setProperty(VARIABLE, model);
} }
}) })
.withEMB(richEditorPath) .withEMB(RICH_EDITOR_HTML)
.namespace(namespace).build(); .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) { public static void stateChange(Browser browser, VanChartRichEditorModel model, String trigger) {
JSValue ns = browser.executeJavaScriptAndReturnValue("window." + namespace); JSValue ns = browser.executeJavaScriptAndReturnValue("window." + NAME_SPACE);
ns.asObject().setProperty(variable, model); ns.asObject().setProperty(VARIABLE, model);
browser.executeJavaScript("window." + namespace + "." + expression); browser.executeJavaScript("window." + NAME_SPACE + "." + trigger);
} }
public static VanChartRichEditorModel getRichEditorModel(AttrTooltipRichText richText) { public static VanChartRichEditorModel getRichEditorModel(AttrTooltipRichText richText) {

31
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_color_chooser"},
{type: "bi.rich_editor_align_left_button"}, {type: "bi.rich_editor_align_left_button"},
{type: "bi.rich_editor_align_center_button"}, {type: "bi.rich_editor_align_center_button"},
{type: "bi.rich_editor_align_right_button"}, {type: "bi.rich_editor_align_right_button"}
{type: "bi.design.chart.common.editor.insert_param"}
] ]
}, },
ref: function (_ref) { ref: function (_ref) {
@ -97,7 +96,7 @@
} }
}); });
Pool.dispatch = function () { Pool.refresh = function () {
var content = Pool.data.getContent(); var content = Pool.data.getContent();
var isAuto = Pool.data.isAuto(); var isAuto = Pool.data.isAuto();
var params = Pool.data.getParams(); var params = Pool.data.getParams();
@ -117,7 +116,31 @@
}); });
rich_editor.setFocus(); 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 += '<p style="text-align:' + align + ';">' + editorService.getEditorParamImage(addition) + '<br></p>';
}
rich_editor.editor.bindToolbar(rich_editor.bar);
rich_editor.setValue({
content: content,
isAuto: isAuto,
dimensionIds: getDimensionIds(params)
});
rich_editor.setFocus();
};
Pool.update = function () { Pool.update = function () {
var {content, isAuto} = rich_editor.getValue(); var {content, isAuto} = rich_editor.getValue();

Loading…
Cancel
Save