forked from fanruan/design
Qinghui.Liu
4 years ago
11 changed files with 563 additions and 321 deletions
@ -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(); |
||||
} |
||||
} |
@ -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() { |
||||
|
||||
} |
||||
}; |
||||
} |
||||
} |
@ -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) { |
||||
|
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
Loading…
Reference in new issue