Browse Source

调整代码结构

persist/11.0
Qinghui.Liu 4 years ago
parent
commit
5d34cb7880
  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.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);
}

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) {
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() {

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 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;
}
}

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;
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<VanChartRichEditorModel> 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<VanChartRichEditorModel> createRichEditorPane(AttrTooltipRichText richEditor) {
VanChartRichEditorModel model = getRichEditorModel(richEditor);
return createRichEditorPane(model);
@ -55,13 +35,25 @@ public class VanChartRichEditorPane {
public static ModernUIPane<VanChartRichEditorModel> 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<VanChartRichEditorModel> initPane(VanChartRichEditorModel model) {
return new ModernUIPane.Builder<VanChartRichEditorModel>()
.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) {

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_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 += '<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 () {
var {content, isAuto} = rich_editor.getValue();

Loading…
Cancel
Save