package com.fr.plugin.pielinecomb.ui; import com.fr.chart.base.TextAttr; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextarea.UITextArea; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.chart.gui.style.ChartTextAttrPane; import com.fr.general.FRFont; import com.fr.json.JSONObject; import com.fr.van.chart.designer.TableLayout4VanChartHelper; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; /** * @author duan.jingliang * @date 2022/10/22 */ public class LineLabelStylePane extends JPanel { private UIButtonGroup lineValueType; private CardLayout lineCardLayout; private JPanel lineCardPane; private UICheckBox showLineLabel; private UICheckBox showLineCategory; private UICheckBox showLineSeries; private UICheckBox showLineValue; private UITextArea lineJsPane; private ChartTextAttrPane lineTextAttrPane; private UIButtonGroup linePosition; public LineLabelStylePane() { initComponents(); } public void populateBean(JSONObject chartConf) { this.showLineLabel.setSelected(chartConf.getBoolean("showLineLabel")); this.lineValueType.setSelectedItem(chartConf.getInt("lineValueType")); this.showLineCategory.setSelected(chartConf.getBoolean("showLineCategory")); this.showLineSeries.setSelected(chartConf.getBoolean("showLineSeries")); this.showLineValue.setSelected(chartConf.getBoolean("showLineValue")); this.lineJsPane.setText(chartConf.getString("lineJsPane")); this.linePosition.setSelectedItem(chartConf.getString("linePosition")); FRFont textFont = FRFont.getInstance(chartConf.getString("linelabelfamily"), chartConf.getInt("linelabelstyle"), chartConf.getInt("linelabelsize"), MapUtil.toColor(chartConf.getString("linelabelcolor"))); this.lineTextAttrPane.populate(textFont); if (chartConf.getInt("lineValueType") == 2) { this.lineCardLayout.show(this.lineCardPane, "linejs"); } else { this.lineCardLayout.show(this.lineCardPane, "linecheck"); } } public JSONObject update() { JSONObject chartConf = JSONObject.create(); chartConf.put("showLineLabel", this.showLineLabel.isSelected()); chartConf.put("lineValueType", this.lineValueType.getSelectedItem()); chartConf.put("showLineCategory", this.showLineCategory.isSelected()); chartConf.put("showLineSeries", this.showLineSeries.isSelected()); chartConf.put("showLineValue", this.showLineValue.isSelected()); chartConf.put("lineJsPane", this.lineJsPane.getText()); chartConf.put("linePosition", this.linePosition.getSelectedItem()); TextAttr textAttr = this.lineTextAttrPane.update(); chartConf.put("linelabelsize", textAttr.getFRFont().getSize()); chartConf.put("linelabelstyle", textAttr.getFRFont().getStyle()); chartConf.put("linelabelfamily", textAttr.getFRFont().getFamily()); chartConf.put("linelabelcolor", MapUtil.toHex(textAttr.getFRFont().getForeground())); return chartConf; } private void initComponents() { this.setLayout(new BorderLayout()); JPanel mainPane = createLineLabelPane(); 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 createLineLabelPane() { lineValueType = new UIButtonGroup(new String[]{ Toolkit.i18nText("Plugin-Pielinecomb-general"), Toolkit.i18nText("Plugin-Pielinecomb-custom") }, new Integer[]{1, 2} ); lineValueType.setSelectedItem(1); double p = TableLayout.PREFERRED; double f = TableLayout.FILL; Component[][] comp = new Component[][]{ {null}, new Component[]{this.lineValueType} }; JPanel lineValueTypePane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p}, new double[]{f}); showLineLabel = new UICheckBox(Toolkit.i18nText("Plugin-Pielinecomb-showPieLabel")); showLineCategory = new UICheckBox(Toolkit.i18nText("Plugin-Pielinecomb-showPieCategory")); showLineSeries = new UICheckBox(Toolkit.i18nText("Plugin-Pielinecomb-showPieSeries")); showLineValue = new UICheckBox(Toolkit.i18nText("Plugin-Pielinecomb-showPieValue")); Component[][] compCheck = new Component[][]{ new Component[]{showLineCategory}, new Component[]{showLineSeries}, new Component[]{showLineValue} }; final JPanel checkPane = TableLayout4VanChartHelper.createGapTableLayoutPane(compCheck, new double[]{p, p, p, p}, new double[]{f}); lineJsPane = new UITextArea(6, 6); lineCardPane = new JPanel(this.lineCardLayout = new CardLayout()){ @Override public Dimension getPreferredSize() { if (null != lineValueType.getSelectedItem() && lineValueType.getSelectedItem() == 2) { return lineJsPane.getPreferredSize(); } else { return checkPane.getPreferredSize(); } } }; lineCardPane.add(checkPane, "linecheck"); lineCardPane.add(lineJsPane, "linejs"); this.lineCardLayout.show(lineCardPane, "linecheck"); lineValueType.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent var1x) { if (lineValueType.getSelectedItem() == 1) { lineCardLayout.show(lineCardPane, "linecheck"); } else { lineCardLayout.show(lineCardPane, "linejs"); } } }); Component[][] contentComp = new Component[][]{ new Component[]{lineValueTypePane}, new Component[]{lineCardPane} }; JPanel contentCompPane = TableLayout4VanChartHelper.createGapTableLayoutPane(contentComp, new double[]{p, p, p}, new double[]{f}); JPanel contentPane = TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-TitleText"), contentCompPane); JPanel stylePane = createLineTextPane(); JPanel layoutPane = createLinePosition(); Component[][] comps = new Component[][]{ new Component[]{showLineLabel}, new Component[]{contentPane}, new Component[]{stylePane}, new Component[]{layoutPane} }; return TableLayout4VanChartHelper.createGapTableLayoutPane(comps, new double[]{p, p, p, p, p}, new double[]{f}); } private JPanel createLinePosition() { this.linePosition = new UIButtonGroup(new String[]{ Toolkit.i18nText("Plugin-Pielinecomb-postop"), Toolkit.i18nText("Plugin-Pielinecomb-posbottom") }, new String[]{"top", "bottom"} ); double p = TableLayout.PREFERRED; double f = TableLayout.FILL; Component[][] comp = new Component[][]{ {null, null}, new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-TitlePosition")), this.linePosition} }; JPanel pane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p}, new double[]{p, f}); return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-layout"), pane); } private JPanel createLineTextPane() { this.lineTextAttrPane = new ChartTextAttrPane(); return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-TitleStyle"), this.lineTextAttrPane); } }