From 5c113a8dbb63ee07f559d3d14ea440dd1da40285 Mon Sep 17 00:00:00 2001 From: zheng Date: Tue, 4 Jun 2019 16:11:47 +0800 Subject: [PATCH] =?UTF-8?q?CHART-4027=20=E7=B3=BB=E5=88=97+=E5=80=BC=20?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E7=9B=B8=E5=85=B3celldata=20design?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractChartDataCorrelationPane.java | 106 ++++++++++++++++++ .../CellDataSeriesValueFieldsPane.java | 55 +++++++++ .../FieldEditorComponentWrapper.java | 19 ++++ .../TinyFormulaPaneEditorComponent.java | 61 ++++++++++ .../fields/AbstractCellDataFieldsPane.java | 16 ++- ...ractCellDataFieldsWithSeriesValuePane.java | 41 +++++++ ...tractDataSetFieldsWithSeriesValuePane.java | 4 +- .../diff/MultiCategoryCellDataFieldsPane.java | 9 +- .../diff/MultiCategoryDataSetFieldsPane.java | 4 +- 9 files changed, 302 insertions(+), 13 deletions(-) create mode 100644 designer-chart/src/main/java/com/fr/design/chartx/component/AbstractChartDataCorrelationPane.java create mode 100644 designer-chart/src/main/java/com/fr/design/chartx/component/CellDataSeriesValueFieldsPane.java create mode 100644 designer-chart/src/main/java/com/fr/design/chartx/component/FieldEditorComponentWrapper.java create mode 100644 designer-chart/src/main/java/com/fr/design/chartx/component/TinyFormulaPaneEditorComponent.java create mode 100644 designer-chart/src/main/java/com/fr/design/chartx/fields/diff/AbstractCellDataFieldsWithSeriesValuePane.java diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/AbstractChartDataCorrelationPane.java b/designer-chart/src/main/java/com/fr/design/chartx/component/AbstractChartDataCorrelationPane.java new file mode 100644 index 0000000000..1e29a818e8 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/AbstractChartDataCorrelationPane.java @@ -0,0 +1,106 @@ +package com.fr.design.chartx.component; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.gui.frpane.UICorrelationPane; +import com.fr.design.gui.itable.UITable; +import com.fr.design.gui.itable.UITableEditor; +import com.fr.stable.StringUtils; + +import javax.swing.JTable; +import javax.swing.event.ChangeEvent; +import java.awt.BorderLayout; +import java.awt.Component; +import java.util.List; + +/** + * Created by shine on 2019/6/4. + */ +public abstract class AbstractChartDataCorrelationPane extends BasicBeanPane { + private FieldEditorComponentWrapper[] editorComponents; + + private UICorrelationPane correlationPane; + + public AbstractChartDataCorrelationPane() { + + this.editorComponents = fieldEditorComponentWrappers(); + + String[] headers = new String[editorComponents.length]; + + for (int i = 0, len = editorComponents.length; i < len; i++) { + headers[i] = editorComponents[i].headerName(); + } + + initComps(headers); + } + + protected abstract FieldEditorComponentWrapper[] fieldEditorComponentWrappers(); + + protected List update() { + return correlationPane.updateBean(); + } + + protected void populate(List list) { + correlationPane.populateBean(list); + } + + @Override + public T updateBean() { + return null; + } + + private void initComps(String[] headers) { + correlationPane = new UICorrelationPane(headers) { + public UITableEditor createUITableEditor() { + return new Editor(); + } + + protected UITable initUITable() { + return new UITable(columnCount) { + + public UITableEditor createTableEditor() { + return createUITableEditor(); + } + + public void tableCellEditingStopped(ChangeEvent e) { + stopPaneEditing(e); + } + }; + } + }; + + this.setLayout(new BorderLayout()); + this.add(correlationPane, BorderLayout.CENTER); + } + + private class Editor extends UITableEditor { + + private Component currentComponent; + private FieldEditorComponentWrapper currentEditorWrapper; + + public Object getCellEditorValue() { + return currentEditorWrapper.value(currentComponent); + } + + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (column == table.getModel().getColumnCount()) { + return null; + } + + correlationPane.stopCellEditing(); + + currentEditorWrapper = AbstractChartDataCorrelationPane.this.editorComponents[column]; + + currentComponent = currentEditorWrapper.createEditorComponent(correlationPane); + currentEditorWrapper.setValue(currentComponent, value); + + return currentComponent; + } + + } + + @Override + protected String title4PopupWindow() { + return StringUtils.EMPTY; + } + +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/CellDataSeriesValueFieldsPane.java b/designer-chart/src/main/java/com/fr/design/chartx/component/CellDataSeriesValueFieldsPane.java new file mode 100644 index 0000000000..21d4280124 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/CellDataSeriesValueFieldsPane.java @@ -0,0 +1,55 @@ +package com.fr.design.chartx.component; + +import com.fr.chartx.data.field.ColumnField; +import com.fr.chartx.data.field.SeriesValueColumnFields; +import com.fr.chartx.data.field.SeriesValueField; +import com.fr.design.i18n.Toolkit; +import com.fr.general.GeneralUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by shine on 2019/6/4. + */ +public class CellDataSeriesValueFieldsPane extends AbstractChartDataCorrelationPane { + + @Override + protected FieldEditorComponentWrapper[] fieldEditorComponentWrappers() { + return new FieldEditorComponentWrapper[]{ + new TinyFormulaPaneEditorComponent(Toolkit.i18nText("Fine-Design_Chart_Series_Name")), + new TinyFormulaPaneEditorComponent(Toolkit.i18nText("Fine-Design_Chart_Series_Value")) + }; + } + + @Override + public void populateBean(SeriesValueColumnFields ob) { + List list = new ArrayList(); + + List seriesValueFieldList = ob.getSeriesValueFieldList(); + for (SeriesValueField seriesValueField : seriesValueFieldList) { + Object[] array = new Object[]{seriesValueField.getSeries().getFieldName(), seriesValueField.getValue().getFieldName()}; + list.add(array); + } + + populate(list); + } + + @Override + public void updateBean(SeriesValueColumnFields ob) { + List list = update(); + + List seriesValueFieldList = new ArrayList(); + + for (Object[] objects : list) { + SeriesValueField seriesValueField = new SeriesValueField(); + ColumnField series = new ColumnField(GeneralUtils.objectToString(objects[0])); + ColumnField value = new ColumnField(GeneralUtils.objectToString(objects[1])); + seriesValueField.setSeries(series); + seriesValueField.setValue(value); + seriesValueFieldList.add(seriesValueField); + } + + ob.setSeriesValueFieldList(seriesValueFieldList); + } +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/FieldEditorComponentWrapper.java b/designer-chart/src/main/java/com/fr/design/chartx/component/FieldEditorComponentWrapper.java new file mode 100644 index 0000000000..9d8f1a0436 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/FieldEditorComponentWrapper.java @@ -0,0 +1,19 @@ +package com.fr.design.chartx.component; + +import com.fr.design.gui.frpane.UICorrelationPane; + +import java.awt.Component; + +/** + * Created by shine on 2019/6/4. + */ +public interface FieldEditorComponentWrapper { + + String headerName(); + + T createEditorComponent(UICorrelationPane parent); + + Object value(T t); + + void setValue(T t, Object o); +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/TinyFormulaPaneEditorComponent.java b/designer-chart/src/main/java/com/fr/design/chartx/component/TinyFormulaPaneEditorComponent.java new file mode 100644 index 0000000000..6234450731 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/TinyFormulaPaneEditorComponent.java @@ -0,0 +1,61 @@ +package com.fr.design.chartx.component; + +import com.fr.base.BaseFormula; +import com.fr.base.Utils; +import com.fr.design.constants.UIConstants; +import com.fr.design.event.UIObserverListener; +import com.fr.design.formula.TinyFormulaPane; +import com.fr.design.gui.frpane.UICorrelationPane; + +/** + * Created by shine on 2019/6/4. + */ +public class TinyFormulaPaneEditorComponent implements FieldEditorComponentWrapper { + + private String header; + + public TinyFormulaPaneEditorComponent(String header) { + this.header = header; + } + + @Override + public String headerName() { + return this.header; + } + + @Override + public TinyFormulaPane createEditorComponent(final UICorrelationPane parent) { + TinyFormulaPane editorComponent = new TinyFormulaPane() { + @Override + public void okEvent() { + parent.stopCellEditing(); + parent.fireTargetChanged(); + } + + @Override + protected void populateTextField(BaseFormula fm) { + formulaTextField.setText(fm.getContent()); + } + }; + editorComponent.setBackground(UIConstants.FLESH_BLUE); + + editorComponent.getUITextField().registerChangeListener(new UIObserverListener() { + @Override + public void doChange() { + parent.fireTargetChanged(); + } + }); + + return editorComponent; + } + + @Override + public Object value(TinyFormulaPane formulaPane) { + return formulaPane.getUITextField().getText(); + } + + @Override + public void setValue(TinyFormulaPane formulaPane, Object o) { + formulaPane.getUITextField().setText(Utils.objectToString(o)); + } +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/fields/AbstractCellDataFieldsPane.java b/designer-chart/src/main/java/com/fr/design/chartx/fields/AbstractCellDataFieldsPane.java index 98400ed7ae..6b6408d937 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/fields/AbstractCellDataFieldsPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/fields/AbstractCellDataFieldsPane.java @@ -31,19 +31,23 @@ public abstract class AbstractCellDataFieldsPane + extends AbstractCellDataFieldsPane { + + private CellDataSeriesValueFieldsPane seriesValueFieldsPane; + + @Override + protected JPanel createCenterPane() { + JPanel normalCenter = super.createCenterPane(); + seriesValueFieldsPane = new CellDataSeriesValueFieldsPane(); + + if (normalCenter != null) { + JPanel panel = new JPanel(new BorderLayout()); + panel.add(normalCenter, BorderLayout.CENTER); + panel.add(seriesValueFieldsPane, BorderLayout.SOUTH); + return panel; + } else { + return seriesValueFieldsPane; + } + } + + protected void populateSeriesValuePane(AbstractColumnFieldCollectionWithSeriesValue t) { + seriesValueFieldsPane.populateBean(t.getSeriesValueColumnFields()); + } + + protected void updateSeriesValuePane(AbstractColumnFieldCollectionWithSeriesValue t) { + seriesValueFieldsPane.updateBean(t.getSeriesValueColumnFields()); + } + +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/AbstractDataSetFieldsWithSeriesValuePane.java b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/AbstractDataSetFieldsWithSeriesValuePane.java index 7c4f0f083f..c62a7deaa2 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/AbstractDataSetFieldsWithSeriesValuePane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/AbstractDataSetFieldsWithSeriesValuePane.java @@ -50,11 +50,11 @@ public abstract class AbstractDataSetFieldsWithSeriesValuePane { +public class MultiCategoryCellDataFieldsPane extends AbstractCellDataFieldsWithSeriesValuePane { private MultiTinyFormulaPane multiCategoryPane; @@ -23,7 +22,7 @@ public class MultiCategoryCellDataFieldsPane extends AbstractCellDataFieldsPane< } @Override - protected JPanel addNorthPane() { + protected JPanel createNorthPane() { createMultiFormulaPane(); @@ -50,6 +49,8 @@ public class MultiCategoryCellDataFieldsPane extends AbstractCellDataFieldsPane< List categoryList = ob.getCategoryList(); multiCategoryPane.populate(categoryList); + + populateSeriesValuePane(ob); } @Override @@ -60,6 +61,8 @@ public class MultiCategoryCellDataFieldsPane extends AbstractCellDataFieldsPane< multiCategoryPane.update(categoryList); + updateSeriesValuePane(fieldCollection); + return fieldCollection; } } diff --git a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/MultiCategoryDataSetFieldsPane.java b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/MultiCategoryDataSetFieldsPane.java index 6a6983fc1d..f638cad223 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/MultiCategoryDataSetFieldsPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/MultiCategoryDataSetFieldsPane.java @@ -46,7 +46,7 @@ public class MultiCategoryDataSetFieldsPane extends AbstractDataSetFieldsWithSer multiCategoryPane.populate(categoryList); - populateCustomPane(ob); + populateSeriesValuePane(ob); } @Override @@ -57,7 +57,7 @@ public class MultiCategoryDataSetFieldsPane extends AbstractDataSetFieldsWithSer multiCategoryPane.update(categoryList); - updateCustomPane(columnFieldCollection); + updateSeriesValuePane(columnFieldCollection); return columnFieldCollection; }