Browse Source

处理新的富文本界面交互

persist/11.0
Qinghui.Liu 4 years ago
parent
commit
b72b41e034
  1. 6
      designer-base/src/main/java/com/fr/design/gui/style/FormatPane.java
  2. 91
      designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartTooltipContentPane.java
  3. 81
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldAttrPane.java
  4. 29
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldButton.java
  5. 115
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldGroupPane.java
  6. 294
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListPane.java
  7. 6
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListener.java
  8. 64
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorModel.java
  9. 80
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorPane.java
  10. 117
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichTextPane.java
  11. 1
      designer-chart/src/main/resources/com/fr/design/editor/script/editor.js

6
designer-base/src/main/java/com/fr/design/gui/style/FormatPane.java

@ -6,6 +6,7 @@ import com.fr.base.Style;
import com.fr.base.TextFormat;
import com.fr.data.core.FormatField;
import com.fr.data.core.FormatField.FormatContents;
import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.i18n.Toolkit;
import com.fr.design.border.UIRoundedBorder;
@ -469,6 +470,11 @@ public class FormatPane extends AbstractBasicStylePane implements GlobalNameObse
globalNameListener = listener;
}
public void registerChangeListener(UIObserverListener listener) {
typeComboBox.registerChangeListener(listener);
textField.registerChangeListener(listener);
}
@Override
public boolean shouldResponseNameListener() {
return false;

91
designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartTooltipContentPane.java

@ -2,7 +2,6 @@ package com.fr.van.chart.designer.component;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIButtonGroup;
@ -33,11 +32,11 @@ import com.fr.van.chart.designer.component.format.ValueFormatPaneWithCheckBox;
import com.fr.van.chart.designer.component.format.ValueFormatPaneWithoutCheckBox;
import com.fr.van.chart.designer.component.format.VanChartFormatPaneWithCheckBox;
import com.fr.van.chart.designer.component.format.VanChartFormatPaneWithoutCheckBox;
import com.fr.van.chart.designer.component.richText.VanChartRichEditorModel;
import com.fr.van.chart.designer.component.richText.VanChartRichEditorPane;
import com.fr.van.chart.designer.component.richText.VanChartRichTextDialog;
import com.fr.van.chart.designer.component.richText.VanChartRichTextPane;
import com.fr.van.chart.designer.style.VanChartStylePane;
import org.nfunk.jep.function.Str;
import javax.swing.JComponent;
import javax.swing.JPanel;
@ -99,7 +98,7 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
private VanChartStylePane parent;
private JPanel showOnPane;
private AttrTooltipRichText richText;
private AttrTooltipContent richTextTooltipContent;
private boolean inCondition;
public VanChartTooltipContentPane(VanChartStylePane parent, JPanel showOnPane) {
@ -110,7 +109,8 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
this.inCondition = inCondition;
this.parent = parent;
this.showOnPane = showOnPane;
this.richText = new AttrTooltipRichText();
this.richTextTooltipContent = new AttrTooltipContent();
initFormatPane(parent, showOnPane);
initRichTextFormatPane(parent, showOnPane);
@ -232,11 +232,11 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
}
public AttrTooltipRichText getRichTextAttr() {
return richText;
return this.richTextTooltipContent.getRichTextAttr();
}
public void setRichTextAttr(AttrTooltipRichText richText) {
this.richText = richText;
this.richTextTooltipContent.setRichTextAttr(richText);
}
private JPanel createLabelContentPane() {
@ -413,24 +413,16 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH;
double[] columnSize = {f, e};
double[] rowSize = {p, p, p};
double[] rowSize = {p, p};
Component[][] components = new Component[][]{
new Component[]{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Content_Style")), createRichEditorButton()},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Use_Format")), createRichFormatPanel()}
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Content_Style")), createRichEditorButton()}
};
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
}
protected JPanel createRichFormatPanel() {
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
return TableLayoutHelper.createTableLayoutPane(getRichTextComponents(), getRowSize(p), new double[]{f, p});
}
private JComponent createRichEditorButton() {
UIButton contentTextArea = new UIButton(Toolkit.i18nText("Fine-Design_Chart_Rich_Text_Edit"));
@ -444,20 +436,27 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
}
private void fireRichEditor() {
final ModernUIPane<VanChartRichEditorPane.RichEditorModel> richEditorPane = VanChartRichEditorPane.createRichEditorPane(richText);
BasicPane panel = new VanChartRichTextPane(parent, getDefaultFieldNames(), getTableFieldNames(), richEditorPane);
BasicDialog dialog = new VanChartRichTextDialog(DesignerContext.getDesignerFrame(), panel);
AttrTooltipRichText richText = this.richTextTooltipContent.getRichTextAttr();
ModernUIPane<VanChartRichEditorModel> richEditorPane = VanChartRichEditorPane.createRichEditorPane(richText);
VanChartRichTextPane richTextPane = new VanChartRichTextPane(parent, getTableFieldNames(), richEditorPane);
BasicDialog richTextDialog = new VanChartRichTextDialog(DesignerContext.getDesignerFrame(), richTextPane);
// 更新字段格式和汇总方式
richTextPane.populateBean(this.richTextTooltipContent);
// 更新富文本编辑器内容
richEditorPane.populate(VanChartRichEditorPane.getRichEditorModel(richText));
dialog.addDialogActionListener(new DialogActionAdapter() {
richTextDialog.addDialogActionListener(new DialogActionAdapter() {
public void doOk() {
VanChartRichEditorPane.RichEditorModel model = richEditorPane.update();
// 收集字段格式和汇总方式
updateTooltipFormat(richTextTooltipContent, richTextPane.updateBean());
VanChartRichEditorModel model = richEditorPane.update();
String content = model.getContent();
// 收集编辑后的富文本内容
updateLocalRichText(content, model.isAuto());
SwingUtilities.getWindowAncestor(richEditorPane).setVisible(false);
@ -468,24 +467,13 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
}
});
dialog.setVisible(true);
richTextDialog.setVisible(true);
if (parent != null) {
parent.attributeChanged();
}
}
private List<String> getDefaultFieldNames() {
List<String> fieldNames = new ArrayList<>();
fieldNames.add("分类");
fieldNames.add("系列");
fieldNames.add("值");
fieldNames.add("百分比");
return fieldNames;
}
private List<String> getTableFieldNames() {
List<String> fieldNames = new ArrayList<>();
@ -745,8 +733,11 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
attrTooltipContent.getRichTextChangedPercentFormat()
};
richText = new AttrTooltipRichText();
// 传递富文本格式
updateTooltipFormat(richTextTooltipContent, attrTooltipContent);
// 更新富文本可用参数
populateRichTextFormat(formatPaneGroup, formatGroup);
// 更新富文本初始参数
populateRichText(attrTooltipContent.getRichTextAttr());
checkRichEditorState(attrTooltipContent);
@ -761,6 +752,7 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
formatPane.populate(format);
// 填充面板时,更新富文本编辑器参数
AttrTooltipRichText richText = this.richTextTooltipContent.getRichTextAttr();
formatPane.updateFormatParams(richText.getParams(), format.getJs());
}
}
@ -769,11 +761,13 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
protected void populateRichText(AttrTooltipRichText tooltipRichText) {
if (tooltipRichText != null) {
updateLocalRichText(tooltipRichText.getContent(), tooltipRichText.isAuto());
richText.setInitParamsContent(tooltipRichText.getInitParamsContent());
richTextTooltipContent.getRichTextAttr().setInitParamsContent(tooltipRichText.getInitParamsContent());
}
}
protected void checkRichEditorState(AttrTooltipContent attrTooltipContent) {
AttrTooltipRichText richText = this.richTextTooltipContent.getRichTextAttr();
if (ComparatorUtils.equals(richText.getInitParamsContent(), StringUtils.EMPTY)) {
richText.setContent(attrTooltipContent.getRichTextDefaultContent());
richText.setInitParamsContent(attrTooltipContent.getRichTextDefaultParams());
@ -786,7 +780,8 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
updateLabelType(attrTooltipContent);
updateFormatPane(attrTooltipContent);
if (supportRichEditor()) {
updateRichEditor(attrTooltipContent);
// updateRichEditor(attrTooltipContent);
updateTooltipFormat(attrTooltipContent, this.richTextTooltipContent);
updateTooltipRichText(attrTooltipContent);
}
updateTextAttr(attrTooltipContent);
@ -863,17 +858,31 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
}
}
protected void updateTooltipFormat(AttrTooltipContent target, AttrTooltipContent source) {
// 更新富文本字段格式
target.setRichTextCategoryFormat(source.getRichTextCategoryFormat());
target.setRichTextSeriesFormat(source.getRichTextSeriesFormat());
target.setRichTextValueFormat(source.getRichTextValueFormat());
target.setRichTextPercentFormat(source.getRichTextPercentFormat());
// 更新新增字段格式和汇总
target.setFieldCollection(source.getFieldCollection());
}
private void updateLocalRichText(String content, boolean isAuto) {
AttrTooltipRichText richText = this.richTextTooltipContent.getRichTextAttr();
richText.setContent(content);
richText.setAuto(isAuto);
}
private void updateTooltipRichText(AttrTooltipContent attrTooltipContent) {
if (attrTooltipContent != null) {
AttrTooltipRichText tooltipRichText = attrTooltipContent.getRichTextAttr();
tooltipRichText.setContent(richText.getContent());
tooltipRichText.setInitParamsContent(richText.getInitParamsContent());
tooltipRichText.setAuto(richText.isAuto());
AttrTooltipRichText targetRichText = attrTooltipContent.getRichTextAttr();
AttrTooltipRichText localRichText = this.richTextTooltipContent.getRichTextAttr();
targetRichText.setContent(localRichText.getContent());
targetRichText.setInitParamsContent(localRichText.getInitParamsContent());
targetRichText.setAuto(localRichText.isAuto());
}
}
}

81
designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldAttrPane.java

@ -0,0 +1,81 @@
package com.fr.van.chart.designer.component.richText;
import com.fr.data.util.function.AbstractDataFunction;
import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.style.FormatPane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.TableLayout;
import com.fr.design.mainframe.chart.gui.data.CalculateComboBox;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import com.fr.van.chart.designer.component.format.FormatPaneWithOutFont;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
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 {
private FormatPane fieldFormatPane;
private CalculateComboBox fieldDataFunction;
private JPanel fieldFunctionPane;
public VanChartFieldAttrPane() {
double p = TableLayout.PREFERRED;
double d = TableLayout4VanChartHelper.DESCRIPTION_AREA_WIDTH;
double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH;
fieldFormatPane = new FormatPaneWithOutFont() {
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();
Component[][] components = new Component[][]{
new Component[]{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Summary_Method"), SwingConstants.LEFT), fieldDataFunction}
};
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) {
fieldDataFunction.addActionListener(listener);
}
public void registerChangeListener(UIObserverListener listener) {
fieldFormatPane.registerChangeListener(listener);
}
public void populate(Format format, AbstractDataFunction dataFunction, boolean showDataFunction) {
fieldFormatPane.populateBean(format);
fieldDataFunction.populateBean(dataFunction);
fieldFunctionPane.setVisible(showDataFunction);
}
public Format updateFormat() {
return fieldFormatPane.update();
}
public AbstractDataFunction updateDataFunction() {
return fieldDataFunction.updateBean();
}
}

29
designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldAddPane.java → designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldButton.java

@ -18,29 +18,29 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.Format;
public class VanChartFieldAddPane extends JPanel {
public class VanChartFieldButton extends JPanel {
private static final Icon ADD_ICON = BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png");
private static final int W = 200;
private static final int H = 28;
private final String fieldName;
private final String fieldId;
private final boolean showDataFunction;
private UIToggleButton fieldButton;
private UIButton addButton;
private Format format;
private DataFunction dataFunction;
private String fieldName;
private boolean showSummary;
public VanChartFieldAddPane(String fieldName, VanChartFieldListener listener) {
this(fieldName, false, listener);
}
public VanChartFieldAddPane(String fieldName, boolean showSummary, VanChartFieldListener listener) {
public VanChartFieldButton(String fieldName, String fieldId, boolean showSummary, VanChartFieldListener listener) {
this.fieldName = fieldName;
this.showSummary = showSummary;
this.fieldId = fieldId;
this.showDataFunction = showSummary;
initComponents(fieldName, listener);
@ -68,8 +68,8 @@ public class VanChartFieldAddPane extends JPanel {
this.dataFunction = dataFunction;
}
public boolean isShowSummary() {
return showSummary;
public boolean isShowDataFunction() {
return showDataFunction;
}
private void initComponents(String fieldName, VanChartFieldListener listener) {
@ -81,8 +81,9 @@ public class VanChartFieldAddPane extends JPanel {
public void mousePressed(MouseEvent e) {
setSelected(true);
listener.refreshSelectedField(fieldName);
listener.refreshSelectedPane(fieldName);
listener.setGlobalName(fieldName);
listener.populateFieldFormatPane();
}
};
}
@ -95,7 +96,7 @@ public class VanChartFieldAddPane extends JPanel {
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
listener.addSelectedField(fieldName);
listener.addSelectedField(fieldName, fieldId);
}
});
}

115
designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldGroupPane.java

@ -1,115 +0,0 @@
package com.fr.van.chart.designer.component.richText;
import com.fr.general.ComparatorUtils;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;
public class VanChartFieldGroupPane extends JPanel {
private static final int FIELD_ADD_W = 400;
private static final int FIELD_ADD_H = 28;
private List<String> defaultFieldNameList;
private List<String> tableFieldNameList;
private List<VanChartFieldAddPane> defaultFieldPaneList = new ArrayList<>();
private List<VanChartFieldAddPane> tableFieldPaneList = new ArrayList<>();
private VanChartFieldListener fieldListener;
public VanChartFieldGroupPane(List<String> defaultFieldNameList, List<String> tableFieldNameList) {
this.defaultFieldNameList = defaultFieldNameList;
this.tableFieldNameList = tableFieldNameList;
initFieldListener();
this.setLayout(new BorderLayout());
this.add(createDefaultFieldPane(), BorderLayout.CENTER);
this.add(createTableFieldPane(), BorderLayout.SOUTH);
}
private JPanel createDefaultFieldPane() {
JPanel defaultField = new JPanel();
defaultField.setLayout(new GridLayout(0, 1, 1, 0));
for (String title : defaultFieldNameList) {
VanChartFieldAddPane fieldAddPane = new VanChartFieldAddPane(title, fieldListener);
defaultField.add(fieldAddPane);
defaultFieldPaneList.add(fieldAddPane);
}
defaultField.setPreferredSize(new Dimension(FIELD_ADD_W, defaultFieldNameList.size() * FIELD_ADD_H));
defaultField.setBorder(BorderFactory.createEmptyBorder(10, 5, 0, 0));
return defaultField;
}
private JPanel createTableFieldPane() {
JPanel tableField = new JPanel();
tableField.setLayout(new GridLayout(0, 1, 1, 0));
for (String title : tableFieldNameList) {
VanChartFieldAddPane fieldAddPane = new VanChartFieldAddPane(title, fieldListener);
tableField.add(fieldAddPane);
tableFieldPaneList.add(fieldAddPane);
}
tableField.setPreferredSize(new Dimension(FIELD_ADD_W, defaultFieldNameList.size() * FIELD_ADD_H));
return TableLayout4VanChartHelper.createExpandablePaneWithTitleTopGap("数据集字段", tableField);
}
private void initFieldListener() {
fieldListener = new VanChartFieldListener() {
private String fieldName;
public void setGlobalName(String fieldName) {
this.fieldName = fieldName;
}
public String getGlobalName() {
return this.fieldName;
}
public void refreshSelectedField(String fieldName) {
if (ComparatorUtils.equals(fieldName, this.fieldName)) {
return;
}
for (VanChartFieldAddPane fieldAddPane : defaultFieldPaneList) {
fieldAddPane.setSelectedState(ComparatorUtils.equals(fieldAddPane.getFieldName(), fieldName));
}
for (VanChartFieldAddPane fieldAddPane : tableFieldPaneList) {
fieldAddPane.setSelectedState(ComparatorUtils.equals(fieldAddPane.getFieldName(), fieldName));
}
}
public void addSelectedField(String fieldName) {
System.out.println(fieldName);
}
public void populateFieldFormatPane() {
}
public void updateFieldFormatPane() {
}
};
}
}

294
designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListPane.java

@ -0,0 +1,294 @@
package com.fr.van.chart.designer.component.richText;
import com.fr.data.util.function.AbstractDataFunction;
import com.fr.design.event.UIObserverListener;
import com.fr.design.i18n.Toolkit;
import com.fr.design.ui.ModernUIPane;
import com.fr.general.ComparatorUtils;
import com.fr.plugin.chart.base.AttrTooltipContent;
import com.fr.plugin.chart.base.format.AttrTooltipCategoryFormat;
import com.fr.plugin.chart.base.format.AttrTooltipPercentFormat;
import com.fr.plugin.chart.base.format.AttrTooltipSeriesFormat;
import com.fr.plugin.chart.base.format.AttrTooltipValueFormat;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.Format;
import java.util.ArrayList;
import java.util.List;
public class VanChartFieldListPane extends JPanel {
private static final int FIELD_ADD_W = 400;
private static final int FIELD_ADD_H = 28;
private VanChartFieldButton categoryNameButton;
private VanChartFieldButton seriesNameButton;
private VanChartFieldButton valueButton;
private VanChartFieldButton percentButton;
private VanChartFieldAttrPane fieldAttrPane;
private ModernUIPane<VanChartRichEditorModel> richEditorPane;
private List<String> tableFieldNameList;
private List<VanChartFieldButton> tableFieldButtonList = new ArrayList<>();
private VanChartFieldListener fieldListener;
public VanChartFieldListPane(List<String> tableFieldNameList, VanChartFieldAttrPane fieldAttrPane,
ModernUIPane<VanChartRichEditorModel> richEditorPane) {
this.tableFieldNameList = tableFieldNameList;
this.fieldAttrPane = fieldAttrPane;
this.richEditorPane = richEditorPane;
initFieldListListener();
registerAttrListener();
this.setLayout(new BorderLayout());
this.add(createDefaultFieldPane(), BorderLayout.CENTER);
this.add(createTableFieldPane(), BorderLayout.SOUTH);
}
private JPanel createDefaultFieldPane() {
JPanel defaultField = new JPanel();
defaultField.setLayout(new GridLayout(0, 1, 1, 0));
createDefaultButtonGroup(defaultField);
List<VanChartFieldButton> defaultFieldButtonList = getDefaultFieldButtonList();
defaultField.setPreferredSize(new Dimension(FIELD_ADD_W, defaultFieldButtonList.size() * FIELD_ADD_H));
defaultField.setBorder(BorderFactory.createEmptyBorder(10, 5, 0, 0));
return defaultField;
}
protected void createDefaultButtonGroup(JPanel field) {
categoryNameButton = createCategoryFieldButton();
seriesNameButton = createSeriesFieldButton();
valueButton = createValueFieldButton();
percentButton = createPercentFieldButton();
field.add(categoryNameButton);
field.add(seriesNameButton);
field.add(valueButton);
field.add(percentButton);
}
// 不同图表的name和id不一样
protected VanChartFieldButton createCategoryFieldButton() {
String name = Toolkit.i18nText("Fine-Design_Chart_Category_Use_Name");
String id = new AttrTooltipCategoryFormat().getFormatJSONKey();
return new VanChartFieldButton(name, id, false, fieldListener);
}
protected VanChartFieldButton createSeriesFieldButton() {
String name = Toolkit.i18nText("Fine-Design_Chart_Series_Name");
String id = new AttrTooltipSeriesFormat().getFormatJSONKey();
return new VanChartFieldButton(name, id, false, fieldListener);
}
protected VanChartFieldButton createValueFieldButton() {
String name = Toolkit.i18nText("Fine-Design_Chart_Use_Value");
String id = new AttrTooltipValueFormat().getFormatJSONKey();
return new VanChartFieldButton(name, id, false, fieldListener);
}
protected VanChartFieldButton createPercentFieldButton() {
String name = Toolkit.i18nText("Fine-Design_Chart_Use_Percent");
String id = new AttrTooltipPercentFormat().getFormatJSONKey();
return new VanChartFieldButton(name, id, false, fieldListener);
}
private JPanel createTableFieldPane() {
if (tableFieldNameList == null || tableFieldNameList.isEmpty()) {
return new JPanel();
}
JPanel tableField = new JPanel();
tableField.setLayout(new GridLayout(0, 1, 1, 0));
for (String name : tableFieldNameList) {
VanChartFieldButton fieldButton = new VanChartFieldButton(name, name, true, fieldListener);
tableField.add(fieldButton);
tableFieldButtonList.add(fieldButton);
}
tableField.setPreferredSize(new Dimension(FIELD_ADD_W, tableFieldNameList.size() * FIELD_ADD_H));
return TableLayout4VanChartHelper.createExpandablePaneWithTitleTopGap("数据集字段", tableField);
}
protected List<VanChartFieldButton> getDefaultFieldButtonList() {
List<VanChartFieldButton> defaultFieldButtonList = new ArrayList<>();
defaultFieldButtonList.add(categoryNameButton);
defaultFieldButtonList.add(seriesNameButton);
defaultFieldButtonList.add(valueButton);
defaultFieldButtonList.add(percentButton);
return defaultFieldButtonList;
}
private void initFieldListListener() {
fieldListener = new VanChartFieldListener() {
private String fieldName;
public void setGlobalName(String fieldName) {
this.fieldName = fieldName;
}
public String getGlobalName() {
return this.fieldName;
}
public VanChartFieldButton getSelectedField() {
List<VanChartFieldButton> defaultFieldButtonList = getDefaultFieldButtonList();
for (VanChartFieldButton fieldButton : defaultFieldButtonList) {
if (ComparatorUtils.equals(fieldButton.getFieldName(), this.fieldName)) {
return fieldButton;
}
}
for (VanChartFieldButton fieldButton : tableFieldButtonList) {
if (ComparatorUtils.equals(fieldButton.getFieldName(), this.fieldName)) {
return fieldButton;
}
}
return null;
}
public void refreshSelectedPane(String fieldName) {
if (ComparatorUtils.equals(fieldName, this.fieldName)) {
return;
}
List<VanChartFieldButton> defaultFieldButtonList = getDefaultFieldButtonList();
for (VanChartFieldButton fieldButton : defaultFieldButtonList) {
fieldButton.setSelectedState(ComparatorUtils.equals(fieldButton.getFieldName(), fieldName));
}
for (VanChartFieldButton fieldButton : tableFieldButtonList) {
fieldButton.setSelectedState(ComparatorUtils.equals(fieldButton.getFieldName(), fieldName));
}
}
public void addSelectedField(String fieldName, String fieldId) {
VanChartRichEditorModel model = richEditorPane.update();
String content = model.getContent() + getFieldRichText(fieldName, fieldId);
model.setContent(content);
VanChartRichEditorPane.createRichEditorPane(model);
}
public void populateFieldFormatPane() {
VanChartFieldButton fieldButton = this.getSelectedField();
if (fieldButton == null) {
return;
}
Format format = fieldButton.getFormat();
AbstractDataFunction dataFunction = (AbstractDataFunction) fieldButton.getDataFunction();
boolean showDataFunction = fieldButton.isShowDataFunction();
fieldAttrPane.populate(format, dataFunction, showDataFunction);
}
public void updateFieldFormatPane() {
VanChartFieldButton fieldButton = this.getSelectedField();
if (fieldButton == null) {
return;
}
fieldButton.setFormat(fieldAttrPane.updateFormat());
fieldButton.setDataFunction(fieldAttrPane.updateDataFunction());
}
};
}
private void registerAttrListener() {
fieldAttrPane.registerFunctionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fieldListener.updateFieldFormatPane();
}
});
fieldAttrPane.registerChangeListener(new UIObserverListener() {
public void doChange() {
fieldListener.updateFieldFormatPane();
}
});
}
private void checkFieldListSelected() {
List<VanChartFieldButton> defaultFieldButtonList = getDefaultFieldButtonList();
if (defaultFieldButtonList != null && defaultFieldButtonList.size() > 0) {
String selected = defaultFieldButtonList.get(0).getFieldName();
fieldListener.refreshSelectedPane(selected);
fieldListener.setGlobalName(selected);
fieldListener.populateFieldFormatPane();
}
}
private String getFieldRichText(String fieldName, String fieldId) {
return "<p><span>" + fieldName + "</span></p>";
}
public void populate(AttrTooltipContent tooltipContent) {
populateDefaultField(tooltipContent);
populateTableField(tooltipContent);
// 初次打开富文本界面选中第一个
checkFieldListSelected();
}
public void populateDefaultField(AttrTooltipContent tooltipContent) {
categoryNameButton.setFormat(tooltipContent.getRichTextCategoryFormat().getFormat());
seriesNameButton.setFormat(tooltipContent.getRichTextSeriesFormat().getFormat());
valueButton.setFormat(tooltipContent.getRichTextValueFormat().getFormat());
percentButton.setFormat(tooltipContent.getRichTextPercentFormat().getFormat());
}
public void populateTableField(AttrTooltipContent tooltipContent) {
}
public void update(AttrTooltipContent tooltipContent) {
updateDefaultField(tooltipContent);
updateTableField(tooltipContent);
}
public void updateDefaultField(AttrTooltipContent tooltipContent) {
tooltipContent.getRichTextCategoryFormat().setFormat(categoryNameButton.getFormat());
tooltipContent.getRichTextSeriesFormat().setFormat(seriesNameButton.getFormat());
tooltipContent.getRichTextValueFormat().setFormat(valueButton.getFormat());
tooltipContent.getRichTextPercentFormat().setFormat(percentButton.getFormat());
}
public void updateTableField(AttrTooltipContent tooltipContent) {
}
}

6
designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldListener.java

@ -4,9 +4,11 @@ import com.fr.design.event.GlobalNameListener;
public interface VanChartFieldListener extends GlobalNameListener {
public void refreshSelectedField(String fieldName);
public VanChartFieldButton getSelectedField();
public void addSelectedField(String fieldName);
public void refreshSelectedPane(String fieldName);
public void addSelectedField(String fieldName, String fieldId);
public void populateFieldFormatPane();

64
designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorModel.java

@ -0,0 +1,64 @@
package com.fr.van.chart.designer.component.richText;
import com.fr.plugin.chart.type.TextAlign;
import com.fr.stable.StringUtils;
public class VanChartRichEditorModel {
private String content = StringUtils.EMPTY;
private boolean auto = true;
private String params = StringUtils.EMPTY;
private String initParams = StringUtils.EMPTY;
private String align = TextAlign.LEFT.getAlign();
public VanChartRichEditorModel() {
}
public VanChartRichEditorModel(String content, boolean auto, String params, String initParams, String align) {
this.content = content;
this.auto = auto;
this.params = params;
this.initParams = initParams;
this.align = align;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public boolean isAuto() {
return auto;
}
public void setAuto(boolean auto) {
this.auto = auto;
}
public String getParams() {
return params;
}
public void setParams(String params) {
this.params = params;
}
public String getInitParams() {
return initParams;
}
public void setInitParams(String initParams) {
this.initParams = initParams;
}
public String getAlign() {
return align;
}
public void setAlign(String align) {
this.align = align;
}
}

80
designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichEditorPane.java

@ -25,7 +25,7 @@ public class VanChartRichEditorPane {
private static final String richEditorPath = "/com/fr/design/editor/rich_editor.html";
private static final String expression = "dispatch()";
private static ModernUIPane<RichEditorModel> richEditorPane;
private static ModernUIPane<VanChartRichEditorModel> richEditorPane;
private static Browser browser;
public static void initRichEditorPane() {
@ -36,7 +36,7 @@ public class VanChartRichEditorPane {
@Override
public void run() {
try {
richEditorPane = initPane(new RichEditorModel());
richEditorPane = initPane(new VanChartRichEditorModel());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
@ -47,9 +47,12 @@ public class VanChartRichEditorPane {
}
}
public static ModernUIPane<RichEditorModel> createRichEditorPane(AttrTooltipRichText richEditor) {
RichEditorModel model = getRichEditorModel(richEditor);
public static ModernUIPane<VanChartRichEditorModel> createRichEditorPane(AttrTooltipRichText richEditor) {
VanChartRichEditorModel model = getRichEditorModel(richEditor);
return createRichEditorPane(model);
}
public static ModernUIPane<VanChartRichEditorModel> createRichEditorPane(VanChartRichEditorModel model) {
if (richEditorPane == null) {
richEditorPane = initPane(model);
} else if (browser != null) {
@ -59,8 +62,8 @@ public class VanChartRichEditorPane {
return richEditorPane;
}
public static ModernUIPane<RichEditorModel> initPane(RichEditorModel model) {
return new ModernUIPane.Builder<RichEditorModel>()
public static ModernUIPane<VanChartRichEditorModel> initPane(VanChartRichEditorModel model) {
return new ModernUIPane.Builder<VanChartRichEditorModel>()
.prepare(new ScriptContextAdapter() {
public void onScriptContextCreated(ScriptContextEvent event) {
browser = event.getBrowser();
@ -79,13 +82,13 @@ public class VanChartRichEditorPane {
.namespace(namespace).build();
}
public static void updatePane(Browser browser, RichEditorModel model) {
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 RichEditorModel getRichEditorModel(AttrTooltipRichText richText) {
public static VanChartRichEditorModel getRichEditorModel(AttrTooltipRichText richText) {
Map<String, String> paramsMap = richText.getParams();
StringBuilder paramsStr = new StringBuilder(StringUtils.EMPTY);
@ -115,7 +118,7 @@ public class VanChartRichEditorPane {
align = content.contains(left) ? left : center;
}
return new RichEditorModel(content, richText.isAuto(), paramsStr.toString(), initParams, align);
return new VanChartRichEditorModel(content, richText.isAuto(), paramsStr.toString(), initParams, align);
}
public static String generateTransformI18nJS() {
@ -129,63 +132,4 @@ public class VanChartRichEditorPane {
return "!(function () { window.transformI18n && window.transformI18n('" + language + "' || 'zh_CN'); }());";
}
public static class RichEditorModel {
private String content = StringUtils.EMPTY;
private boolean auto = true;
private String params = StringUtils.EMPTY;
private String initParams = StringUtils.EMPTY;
private String align = TextAlign.LEFT.getAlign();
public RichEditorModel() {
}
public RichEditorModel(String content, boolean auto, String params, String initParams, String align) {
this.content = content;
this.auto = auto;
this.params = params;
this.initParams = initParams;
this.align = align;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public boolean isAuto() {
return auto;
}
public void setAuto(boolean auto) {
this.auto = auto;
}
public String getParams() {
return params;
}
public void setParams(String params) {
this.params = params;
}
public String getInitParams() {
return initParams;
}
public void setInitParams(String initParams) {
this.initParams = initParams;
}
public String getAlign() {
return align;
}
public void setAlign(String align) {
this.align = align;
}
}
}

117
designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartRichTextPane.java

@ -1,25 +1,16 @@
package com.fr.van.chart.designer.component.richText;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.style.FormatPane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.mainframe.chart.gui.data.CalculateComboBox;
import com.fr.design.ui.ModernUIPane;
import com.fr.plugin.chart.base.AttrTooltipContent;
import com.fr.stable.StringUtils;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import com.fr.van.chart.designer.component.format.FormatPaneWithOutFont;
import com.fr.van.chart.designer.style.VanChartStylePane;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.util.List;
@ -32,110 +23,74 @@ public class VanChartRichTextPane extends BasicBeanPane<AttrTooltipContent> {
private static final int RICH_EDITOR_W = 940;
private static final int RICH_EDITOR_H = 260;
private static final double P = TableLayout.PREFERRED;
private static final double D = TableLayout4VanChartHelper.DESCRIPTION_AREA_WIDTH;
private static final double E = TableLayout4VanChartHelper.EDIT_AREA_WIDTH;
private JScrollPane fieldContentPane;
private JScrollPane fieldPropsPane;
private FormatPane fieldFormatPane;
private JPanel fieldSummaryPane;
private UIComboBox fieldSummaryBox;
private VanChartFieldListPane fieldListPane;
private VanChartFieldAttrPane fieldAttrPane;
private VanChartStylePane parent;
private List<String> defaultFieldsFormat;
private List<String> tableFieldsFormat;
public VanChartRichTextPane(VanChartStylePane parent, List<String> defaultFieldsFormat, List<String> tableFieldsFormat, JPanel richEditor) {
this.parent = parent;
private ModernUIPane<VanChartRichEditorModel> richEditor;
this.defaultFieldsFormat = defaultFieldsFormat;
public VanChartRichTextPane(VanChartStylePane parent, List<String> tableFieldsFormat, ModernUIPane<VanChartRichEditorModel> richEditor) {
this.parent = parent;
this.tableFieldsFormat = tableFieldsFormat;
this.richEditor = richEditor;
initFieldContentPane();
initFieldPropsPane();
initFieldContent();
this.setLayout(new BorderLayout());
this.add(createFieldDetailPane(), BorderLayout.CENTER);
this.add(createRichEditorPane(richEditor), BorderLayout.SOUTH);
this.add(createFieldContentPane(), BorderLayout.CENTER);
this.add(createRichEditorPane(), BorderLayout.SOUTH);
}
private void initFieldContentPane() {
JPanel content = new JPanel();
content.setLayout(new BorderLayout());
content.add(createDefaultContentPane(), BorderLayout.NORTH);
content.add(createTableFieldsPane(), BorderLayout.CENTER);
fieldContentPane = new JScrollPane(content);
fieldContentPane.setPreferredSize(new Dimension(FIELD_PANE_W, FIELD_PANE_H));
fieldContentPane.setHorizontalScrollBar(null);
fieldContentPane.setBorder(BorderFactory.createTitledBorder("添加字段"));
}
private void initFieldPropsPane() {
fieldFormatPane = new FormatPaneWithOutFont() {
protected JPanel createContentPane(Component[][] components) {
return TableLayout4VanChartHelper.createGapTableLayoutPane(components, new double[]{P, P, P}, new double[]{D, E});
}
};
fieldSummaryBox = new CalculateComboBox();
Component[][] components = new Component[][]{
new Component[]{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Summary_Method"), SwingConstants.LEFT), fieldSummaryBox}
};
fieldSummaryPane = TableLayout4VanChartHelper.createGapTableLayoutPane(components, new double[]{P, P}, new double[]{D, E});
JPanel props = new JPanel();
props.setLayout(new BorderLayout());
props.add(fieldFormatPane, BorderLayout.NORTH);
props.add(fieldSummaryPane, BorderLayout.CENTER);
props.setBorder(BorderFactory.createEmptyBorder(0, 30, 0, 0));
fieldPropsPane = new JScrollPane(props);
fieldPropsPane.setPreferredSize(new Dimension(FIELD_PANE_W, FIELD_PANE_H));
fieldPropsPane.setBorder(BorderFactory.createTitledBorder("字段设置"));
private void initFieldContent() {
fieldAttrPane = new VanChartFieldAttrPane();
fieldListPane = new VanChartFieldListPane(tableFieldsFormat, fieldAttrPane, richEditor);
}
private JPanel createDefaultContentPane() {
private JPanel createFieldContentPane() {
JPanel fieldPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
return new VanChartFieldGroupPane(defaultFieldsFormat, tableFieldsFormat);
}
// 新增字段目录
JPanel fieldListContent = new JPanel();
fieldListContent.setLayout(new BorderLayout());
fieldListContent.add(fieldListPane, BorderLayout.NORTH);
private JPanel createTableFieldsPane() {
return new JPanel();
}
JScrollPane fieldListScrollPane = new JScrollPane(fieldListContent);
fieldListScrollPane.setPreferredSize(new Dimension(FIELD_PANE_W, FIELD_PANE_H));
fieldListScrollPane.setHorizontalScrollBar(null);
fieldListScrollPane.setBorder(BorderFactory.createTitledBorder("添加字段"));
private JPanel createFieldDetailPane() {
JPanel fieldPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
// 字段格式和汇总
JScrollPane fieldAttrScrollPane = new JScrollPane(fieldAttrPane);
fieldAttrScrollPane.setPreferredSize(new Dimension(FIELD_PANE_W, FIELD_PANE_H));
fieldAttrScrollPane.setBorder(BorderFactory.createTitledBorder("字段设置"));
fieldPane.add(fieldContentPane);
fieldPane.add(fieldPropsPane);
fieldPane.add(fieldListScrollPane);
fieldPane.add(fieldAttrScrollPane);
return fieldPane;
}
private JPanel createRichEditorPane(JPanel richEditor) {
private JPanel createRichEditorPane() {
JPanel richEditorPane = new JPanel();
richEditorPane.setLayout(new BorderLayout());
richEditorPane.setPreferredSize(new Dimension(RICH_EDITOR_W, RICH_EDITOR_H));
richEditorPane.add(richEditor, BorderLayout.CENTER);
richEditorPane.add(this.richEditor, BorderLayout.CENTER);
return richEditorPane;
}
public void populateBean(AttrTooltipContent ob) {
public void populateBean(AttrTooltipContent tooltipContent) {
fieldListPane.populate(tooltipContent);
}
public AttrTooltipContent updateBean() {
return null;
AttrTooltipContent content = new AttrTooltipContent();
fieldListPane.update(content);
return content;
}
protected String title4PopupWindow() {

1
designer-chart/src/main/resources/com/fr/design/editor/script/editor.js

@ -50,6 +50,7 @@
},
items: [{
type: "bi.htape",
tgap: 5,
items: [{
type: "bi.label",
text: BI.i18nText("BI-Design_Font_Style") + ": ",

Loading…
Cancel
Save