白岳
5 years ago
4 changed files with 406 additions and 5 deletions
@ -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<AbstractVanSingleDataPane> 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<VanChartPlot> 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<VanChartPlot> 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<CustomPlotType, AbstractDataDefinition> 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<CustomPlotType, AbstractDataDefinition> 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); |
||||
} |
||||
} |
@ -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<MultiCategoryColumnFieldCollection> { |
||||
|
||||
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; |
||||
} |
||||
|
||||
} |
@ -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<MultiCategoryColumnFieldCollection> { |
||||
|
||||
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; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue