package com.fr.plugin.pielinecomb.ui; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.extended.chart.ExtendedScrollPane; import com.fr.json.JSONObject; import com.fr.plugin.pielinecomb.PieLineCombChart; import com.fr.van.chart.designer.TableLayout4VanChartHelper; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; public class PieLineCombStyleLabelPane extends ExtendedScrollPane { private UIButtonGroup chartType; private CardLayout cardLayout; private JPanel cardPane; /** * 柱形图 配置 * */ private PieLabelStylePane pieLabelStylePane; /** * 折线图 配置 * */ private LineLabelStylePane lineLabelStylePane; @Override protected JPanel createContentPane() { return new ContentPane(); } @Override public void populateBean(PieLineCombChart chart) { JSONObject chartConf = chart.getLabelConf(); this.chartType.setSelectedItem(chartConf.getInt("chartType")); this.pieLabelStylePane.populateBean(chartConf); this.lineLabelStylePane.populateBean(chartConf); } @Override public void updateBean(PieLineCombChart chart) { JSONObject chartConf = new JSONObject(); chartConf.put("chartType", this.chartType.getSelectedItem()); JSONObject pieLabel = this.pieLabelStylePane.update(); JSONObject lineLabel = this.lineLabelStylePane.update(); chartConf.mergeIn(pieLabel); chartConf.mergeIn(lineLabel); chart.setLabelConf(chartConf); } @Override protected String title4PopupWindow() { return Toolkit.i18nText("Plugin-Pielinecomb-StyleLegendLabel"); } private class ContentPane extends JPanel { public ContentPane() { initComponents(); } private void initComponents() { this.setLayout(new BorderLayout()); JPanel mainPane = createMainPane(); double p = TableLayout.PREFERRED; double f = TableLayout.FILL; Component[][] acomponents = new Component[][]{ new Component[]{mainPane} }; JPanel panel = TableLayoutHelper.createTableLayoutPane(acomponents, new double[]{p, p}, new double[]{f}); this.add(panel,BorderLayout.CENTER); this.setVisible(true); } } private JPanel createChartTypePane() { chartType = new UIButtonGroup(new String[]{ Toolkit.i18nText("Plugin-Pielinecomb-Typepie"), Toolkit.i18nText("Plugin-Pielinecomb-Typeline") }, new Integer[]{1, 2} ); chartType.setSelectedItem(1); double p = TableLayout.PREFERRED; double f = TableLayout.FILL; Component[][] comp = new Component[][]{ {null}, new Component[]{this.chartType} }; return TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p}, new double[]{f}); } private JPanel createMainPane() { double p = TableLayout.PREFERRED; double f = TableLayout.FILL; this.pieLabelStylePane = new PieLabelStylePane(); this.lineLabelStylePane = new LineLabelStylePane(); JPanel chartTypePane = createChartTypePane(); cardPane = new JPanel(this.cardLayout = new CardLayout()){ @Override public Dimension getPreferredSize() { if (null != chartType.getSelectedItem() && chartType.getSelectedItem() == 2) { return lineLabelStylePane.getPreferredSize(); } else { return pieLabelStylePane.getPreferredSize(); } } }; cardPane.add(pieLabelStylePane, "pie"); cardPane.add(lineLabelStylePane, "line"); this.cardLayout.show(cardPane, "pie"); chartType.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent var1x) { if (chartType.getSelectedItem() == 1) { cardLayout.show(cardPane, "pie"); } else { cardLayout.show(cardPane, "line"); } } }); Component[][] comp = new Component[][]{ new Component[]{chartTypePane}, new Component[]{cardPane} }; return TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p, p}, new double[]{f}); } }