From 8c0e683fd33712ded635f1d5d63a98a91bacb333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B2=B3?= <445798420@qq.com> Date: Mon, 28 Oct 2019 11:40:32 +0800 Subject: [PATCH] =?UTF-8?q?CHART-10229=20=E5=8D=95=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E6=95=B0=E6=8D=AE=E6=BA=90=EF=BC=8C?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=A0=BC=E6=95=B0=E6=8D=AE=E6=BA=90=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF&=E7=BB=84=E5=90=88=E5=9B=BE=E9=9D=A2=E6=9D=BF&?= =?UTF-8?q?=E7=BB=84=E5=90=88=E5=9B=BE=E7=B1=BB=E5=9E=8B=E9=80=89=E6=8B=A9?= =?UTF-8?q?update=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/chartx/CustomChartDataPane.java | 202 ++++++++++++++++++ .../SingleCategoryCellDataFieldsPane.java | 84 ++++++++ .../diff/SingleCategoryDataSetFieldsPane.java | 88 ++++++++ .../chart/custom/VanChartCustomPlotPane.java | 37 +++- 4 files changed, 406 insertions(+), 5 deletions(-) create mode 100644 designer-chart/src/main/java/com/fr/design/chartx/CustomChartDataPane.java create mode 100644 designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryCellDataFieldsPane.java create mode 100644 designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryDataSetFieldsPane.java diff --git a/designer-chart/src/main/java/com/fr/design/chartx/CustomChartDataPane.java b/designer-chart/src/main/java/com/fr/design/chartx/CustomChartDataPane.java new file mode 100644 index 0000000000..44677b627c --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/CustomChartDataPane.java @@ -0,0 +1,202 @@ +package com.fr.design.chartx; + +import com.fr.chart.chartattr.ChartCollection; +import com.fr.chartx.data.AbstractDataDefinition; +import com.fr.chartx.data.CustomChartDataDefinition; +import com.fr.design.chartx.fields.diff.MultiCategoryCellDataFieldsPane; +import com.fr.design.chartx.fields.diff.MultiCategoryDataSetFieldsPane; +import com.fr.design.chartx.fields.diff.SingleCategoryCellDataFieldsPane; +import com.fr.design.chartx.fields.diff.SingleCategoryDataSetFieldsPane; +import com.fr.design.chartx.single.SingleDataPane; +import com.fr.design.gui.frpane.AttributeChangeListener; +import com.fr.design.gui.ibutton.UITabGroup; +import com.fr.design.mainframe.chart.gui.ChartDataPane; +import com.fr.plugin.chart.attr.plot.VanChartPlot; +import com.fr.plugin.chart.custom.CustomPlotFactory; +import com.fr.plugin.chart.custom.VanChartCustomPlot; +import com.fr.plugin.chart.custom.type.CustomPlotType; +import com.fr.plugin.chart.custom.type.CustomStyle; +import com.fr.plugin.chart.vanchart.VanChart; +import com.fr.stable.StringUtils; +import com.fr.van.chart.custom.component.VanChartCustomPlotUITabGroup; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Dimension; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2019-10-23 + */ +public class CustomChartDataPane extends ChartDataPane { + + public CustomChartDataPane(AttributeChangeListener listener) { + super(listener); + } + + private VanChartCustomPlot customPlot; + + private CardLayout cardLayout; + private JPanel centerPane; + private List paneList; + private UITabGroup tabPane; + + private String[] nameArray; + + @Override + protected void initContentPane() { + if (customPlot == null) { + return; + } + cardLayout = new CardLayout(); + initPaneList(); + relayoutWhenListChange(); + } + + private void initPaneList() { + + paneList = new ArrayList<>(); + + List customPlotList = customPlot.getCustomPlotList(); + + for (int i = 0; i < customPlotList.size(); i++) { + //根据不同的plot创建不同的数据配置界面 + final VanChartPlot vanChartPlot = customPlotList.get(i); + paneList.add(new AbstractVanSingleDataPane(listener) { + @Override + protected SingleDataPane createSingleDataPane() { + return createSingleDataPaneByPlot(vanChartPlot); + } + }); + } + } + + private SingleDataPane createSingleDataPaneByPlot(VanChartPlot plot) { + CustomPlotType customType = CustomPlotFactory.getCustomType(plot); + switch (customType) { + case RING: + case SLOT: + case CUVETTE: + //todo 仪表板没写好 + return new SingleDataPane(new SingleCategoryDataSetFieldsPane(), new SingleCategoryCellDataFieldsPane()); + case SCATTER: + case BUBBLE: + //todo 散点图没写好 + return new SingleDataPane(new SingleCategoryDataSetFieldsPane(), new SingleCategoryCellDataFieldsPane()); + default: + return StringUtils.equals(CustomStyle.CUSTOM.toString(), plot.getCustomType()) ? + new SingleDataPane(new SingleCategoryDataSetFieldsPane(), new SingleCategoryCellDataFieldsPane()) : + new SingleDataPane(new MultiCategoryDataSetFieldsPane(), new MultiCategoryCellDataFieldsPane()); + } + } + + private void relayoutWhenListChange() { + centerPane = new JPanel(cardLayout) { + @Override + public Dimension getPreferredSize() { + return paneList.get(tabPane.getSelectedIndex()).getPreferredSize(); + } + }; + + //获取tab的标题 + initTabTitle(); + + tabPane = new VanChartCustomPlotUITabGroup(nameArray) { + @Override + public void tabChanged(int index) { + dealWithTabChanged(index); + } + }; + tabPane.setSelectedIndex(0); + tabPane.tabChanged(0); + initLayout(); + } + + private void initTabTitle() { + + if (customPlot == null) { + return; + } + + List customPlotList = customPlot.getCustomPlotList(); + nameArray = new String[Math.min(customPlotList.size(), paneList.size())]; + for (int i = 0; i < nameArray.length; i++) { + JPanel pane = paneList.get(i); + VanChartPlot vanChartPlot = customPlotList.get(i); + CustomPlotType plotType = CustomPlotFactory.getCustomType(vanChartPlot); + + nameArray[i] = CustomPlotFactory.getTitle(plotType); + centerPane.add(pane, nameArray[i]); + } + } + + protected void dealWithTabChanged(int index) { + cardLayout.show(centerPane, nameArray[index]); + } + + private void initLayout() { + JPanel tabPanel = new JPanel(new BorderLayout()); + tabPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 0, getBackground())); + tabPanel.add(tabPane, BorderLayout.CENTER); + this.setLayout(new BorderLayout(0, 6)); + this.add(tabPanel, BorderLayout.NORTH); + this.add(centerPane, BorderLayout.CENTER); + } + + @Override + public void populate(ChartCollection collection) { + if (collection == null) { + return; + } + VanChart chart = collection.getSelectedChart(VanChart.class); + if (chart == null) { + return; + } + customPlot = chart.getPlot(); + + this.removeAll(); + initContentPane(); + + CustomChartDataDefinition dataSetCollection = (CustomChartDataDefinition) chart.getChartDataDefinition(); + + if (dataSetCollection != null) { + Map customDefinitions = dataSetCollection.getCustomDefinitions(); + for (int i = 0; i < paneList.size(); i++) { + VanChartPlot vanChartPlot = customPlot.getCustomPlotList().get(i); + AbstractDataDefinition dataDefinition = customDefinitions.get(CustomPlotFactory.getCustomType(vanChartPlot)); + if (dataDefinition != null) { + paneList.get(i).populate(dataDefinition); + } + } + } + + this.initAllListeners(); + this.validate(); + } + + + @Override + public void update(ChartCollection collection) { + if (collection == null) { + return; + } + VanChart chart = collection.getSelectedChart(VanChart.class); + if (chart == null) { + return; + } + Map definitions = new HashMap<>(); + for (int i = 0; i < paneList.size(); i++) { + definitions.put(CustomPlotFactory.getCustomType(customPlot.getCustomPlotList().get(i)), paneList.get(i).update()); + } + CustomChartDataDefinition customDefinition = new CustomChartDataDefinition(); + customDefinition.setCustomDefinitions(definitions); + chart.setChartDataDefinition(customDefinition); + } +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryCellDataFieldsPane.java b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryCellDataFieldsPane.java new file mode 100644 index 0000000000..dc90ee09f0 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryCellDataFieldsPane.java @@ -0,0 +1,84 @@ +package com.fr.design.chartx.fields.diff; + +import com.fr.chartx.data.field.ColumnField; +import com.fr.chartx.data.field.diff.MultiCategoryColumnFieldCollection; +import com.fr.design.chartx.component.CategorySeriesFilterPane; +import com.fr.design.formula.TinyFormulaPane; +import com.fr.design.gui.ilable.BoldFontTextLabel; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.chart.gui.ChartDataPane; +import com.fr.design.utils.gui.GUICoreUtils; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2019-10-24 + */ +public class SingleCategoryCellDataFieldsPane extends AbstractCellDataFieldsWithSeriesValuePane { + + private TinyFormulaPane categoryPane; + + private CategorySeriesFilterPane filterPane; + + @Override + protected void initComponents() { + categoryPane = new TinyFormulaPane(); + filterPane = new CategorySeriesFilterPane(); + + UILabel label = new BoldFontTextLabel(Toolkit.i18nText("Fine-Design_Chart_Style_Category")); + label.setPreferredSize(new Dimension(ChartDataPane.LABEL_WIDTH, ChartDataPane.LABEL_HEIGHT)); + + JPanel northPane = new JPanel(new BorderLayout(0, 6)); + northPane.add(GUICoreUtils.createBorderLayoutPane(new Component[]{categoryPane, null, null, label, null}), BorderLayout.NORTH); + northPane.add(createCenterPane(), BorderLayout.CENTER); + northPane.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 8)); + + this.setLayout(new BorderLayout(0, 6)); + this.add(northPane, BorderLayout.NORTH); + this.add(filterPane, BorderLayout.CENTER); + } + + @Override + protected String[] fieldLabels() { + return new String[0]; + } + + @Override + protected TinyFormulaPane[] formulaPanes() { + return new TinyFormulaPane[]{categoryPane}; + } + + @Override + public void populateBean(MultiCategoryColumnFieldCollection fieldCollection) { + if (fieldCollection.getCategoryList().size() > 0) { + populateField(categoryPane, fieldCollection.getCategoryList().get(0)); + } + + populateSeriesValuePane(fieldCollection); + + filterPane.populateMultiCategoryFieldCollection(fieldCollection); + } + + @Override + public MultiCategoryColumnFieldCollection updateBean() { + + MultiCategoryColumnFieldCollection fieldCollection = new MultiCategoryColumnFieldCollection(); + fieldCollection.getCategoryList().add(new ColumnField()); + + updateField(categoryPane, fieldCollection.getCategoryList().get(0)); + + updateSeriesValuePane(fieldCollection); + + filterPane.updateMultiCategoryFieldCollection(fieldCollection); + + return fieldCollection; + } + +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryDataSetFieldsPane.java b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryDataSetFieldsPane.java new file mode 100644 index 0000000000..07936dfcb2 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryDataSetFieldsPane.java @@ -0,0 +1,88 @@ +package com.fr.design.chartx.fields.diff; + +import com.fr.chartx.data.field.ColumnField; +import com.fr.chartx.data.field.diff.MultiCategoryColumnFieldCollection; +import com.fr.design.chartx.component.CategorySeriesFilterPane; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.BoldFontTextLabel; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.chart.gui.ChartDataPane; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.extended.chart.UIComboBoxWithNone; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.JSeparator; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2019-10-24 + */ +public class SingleCategoryDataSetFieldsPane extends AbstractDataSetFieldsWithSeriesValuePane { + + private UIComboBox categoryPane; + + private CategorySeriesFilterPane filterPane; + + @Override + protected void initComponents() { + categoryPane = new UIComboBoxWithNone(); + filterPane = new CategorySeriesFilterPane(); + + UILabel label = new BoldFontTextLabel(Toolkit.i18nText("Fine-Design_Chart_Style_Category")); + label.setPreferredSize(new Dimension(ChartDataPane.LABEL_WIDTH, ChartDataPane.LABEL_HEIGHT)); + + JPanel northPane = new JPanel(new BorderLayout(0, 6)); + northPane.add(GUICoreUtils.createBorderLayoutPane(new Component[]{categoryPane, null, null, label, null}), BorderLayout.NORTH); + northPane.add(new JSeparator(), BorderLayout.CENTER); + northPane.add(createCenterPane(), BorderLayout.SOUTH); + northPane.setBorder(BorderFactory.createEmptyBorder(4, 24, 0, 15)); + + this.setLayout(new BorderLayout(0, 6)); + this.add(northPane, BorderLayout.NORTH); + this.add(filterPane, BorderLayout.CENTER); + } + + @Override + protected String[] fieldLabels() { + return new String[0]; + } + + @Override + protected UIComboBox[] filedComboBoxes() { + return new UIComboBox[]{categoryPane}; + } + + + @Override + public void populateBean(MultiCategoryColumnFieldCollection columnFieldCollection) { + if (columnFieldCollection.getCategoryList().size() > 0) { + populateField(categoryPane, columnFieldCollection.getCategoryList().get(0)); + } + + populateSeriesValuePane(columnFieldCollection); + + filterPane.populateMultiCategoryFieldCollection(columnFieldCollection); + } + + @Override + public MultiCategoryColumnFieldCollection updateBean() { + + MultiCategoryColumnFieldCollection columnFieldCollection = new MultiCategoryColumnFieldCollection(); + columnFieldCollection.getCategoryList().add(new ColumnField()); + + updateField(categoryPane, columnFieldCollection.getCategoryList().get(0)); + + updateSeriesValuePane(columnFieldCollection); + + filterPane.updateMultiCategoryFieldCollection(columnFieldCollection); + + return columnFieldCollection; + } + +} diff --git a/designer-chart/src/main/java/com/fr/van/chart/custom/VanChartCustomPlotPane.java b/designer-chart/src/main/java/com/fr/van/chart/custom/VanChartCustomPlotPane.java index 927fa31485..70431b2e79 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/custom/VanChartCustomPlotPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/custom/VanChartCustomPlotPane.java @@ -6,6 +6,8 @@ import com.fr.chart.chartattr.Chart; import com.fr.chart.chartattr.Plot; import com.fr.chart.chartglyph.ConditionAttr; import com.fr.chart.chartglyph.ConditionCollection; +import com.fr.chartx.data.AbstractDataDefinition; +import com.fr.chartx.data.CustomChartDataDefinition; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.chart.gui.type.ChartImagePane; @@ -24,11 +26,11 @@ import com.fr.van.chart.designer.type.AbstractVanChartTypePane; import javax.swing.JPanel; import javax.swing.JSeparator; +import java.util.HashMap; +import java.util.Map; import java.awt.CardLayout; import java.awt.Component; import java.awt.Dimension; -import java.util.HashMap; -import java.util.Map; /** * Created by Mitisky on 16/2/16. @@ -123,6 +125,7 @@ public class VanChartCustomPlotPane extends AbstractVanChartTypePane { //如果上次的状态和这次的装填不在同一个页面,说明同一个图表內切换了,需要情況数据配置 if (lastState != chart.getPlot().getDetailType()) { chart.setFilterDefinition(null); + ((VanChart) chart).setChartDataDefinition(null); } Chart[] customChart = CustomIndependentVanChart.CustomVanChartTypes; @@ -137,6 +140,9 @@ public class VanChartCustomPlotPane extends AbstractVanChartTypePane { dealCustomDefinition(chart); customSelectPane.updateBean(chart); + + //更新新的数据配置 + dealCustomChartDataDefinition(chart); } else if (isSamePlot()) {//如果是同一个图表切换过来,则重置面板 customSelectPane.populateBean(chart); } @@ -150,6 +156,27 @@ public class VanChartCustomPlotPane extends AbstractVanChartTypePane { } + private void dealCustomChartDataDefinition(Chart chart) { + CustomChartDataDefinition chartDataDefinition = (CustomChartDataDefinition) ((VanChart) chart).getChartDataDefinition(); + + if (chartDataDefinition == null) { + return; + } + + Map customDefinitions = chartDataDefinition.getCustomDefinitions(); + + Map newCustomDefinitions = new HashMap<>(); + + VanChartCustomPlot customPlot = chart.getPlot(); + for (int i = 0; i < customPlot.getCustomPlotList().size(); i++) { + CustomPlotType plotType = CustomPlotFactory.getCustomType(customPlot.getCustomPlotList().get(i)); + AbstractDataDefinition definition = customDefinitions.get(plotType); + newCustomDefinitions.put(plotType, definition); + } + + chartDataDefinition.setCustomDefinitions(newCustomDefinitions); + } + private void dealCustomDefinition(Chart chart) { CustomDefinition definition = (CustomDefinition) chart.getFilterDefinition(); @@ -229,9 +256,9 @@ public class VanChartCustomPlotPane extends AbstractVanChartTypePane { } Plot cloned = null; try { - if(newPlot != null) { - cloned = (Plot) newPlot.clone(); - } + if (newPlot != null) { + cloned = (Plot) newPlot.clone(); + } } catch (CloneNotSupportedException e) { FineLoggerFactory.getLogger().error("Error In ScatterChart"); }