From 0aca08205e8f7075850b25efa90d191ec9765fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E7=A3=8A?= <294531121@qq.com> Date: Wed, 5 Jan 2022 15:26:43 +0800 Subject: [PATCH] =?UTF-8?q?CHART-22529=20=E5=88=87=E6=8D=A2=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E6=A0=87=E9=A2=98=E8=87=AA=E5=AE=9A=E4=B9=89=E2=80=94?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E5=99=A8=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/chart/gui/ChangeConfigPane.java | 138 +++++++++++++++++- 1 file changed, 133 insertions(+), 5 deletions(-) diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChangeConfigPane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChangeConfigPane.java index 3de9aaa09..bed7c58c8 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChangeConfigPane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChangeConfigPane.java @@ -4,29 +4,42 @@ package com.fr.design.mainframe.chart.gui; * Created by hufan on 2016/10/20. */ +import com.fr.base.BaseFormula; +import com.fr.base.Utils; import com.fr.chart.base.AttrChangeConfig; import com.fr.chart.base.AttrChangeType; +import com.fr.chart.chartattr.Chart; import com.fr.chart.chartattr.ChartCollection; import com.fr.design.beans.BasicBeanPane; +import com.fr.design.foldablepane.UIExpandablePane; +import com.fr.design.formula.TinyFormulaPane; import com.fr.design.gui.ibutton.UIButtonGroup; +import com.fr.design.gui.ibutton.UIToggleButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ispinner.UISpinner; +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.design.i18n.Toolkit; - +import com.fr.stable.StableUtils; import com.fr.van.chart.designer.TableLayout4VanChartHelper; import javax.swing.BorderFactory; +import javax.swing.BoxLayout; import javax.swing.JPanel; import javax.swing.SwingConstants; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Component; import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ArrayList; +import java.util.List; /** * 图表切换设置面板 @@ -40,6 +53,7 @@ public class ChangeConfigPane extends BasicBeanPane { private static final int CONSTANT_TEN = 10; private static final int CONSTANT_THIRTY = 30; private static final int CONSTANT_ZERO = 0; + private static final int COL_COUNT = 4; private JPanel contentPane; //配置方式按钮 private UIButtonGroup configStyleButton; @@ -56,6 +70,10 @@ public class ChangeConfigPane extends BasicBeanPane { private ColorSelectBoxWithOutTransparent colorSelectBox4carousel; private UIButtonGroup switchStyleGroup; + private JPanel chartTypesPane; + private TinyFormulaPane switchTitlePane; + private List changeChartButtons = new ArrayList<>(); + private int selectedChart; // 设置面板里面选取的图表,不是真正切换的图表 public ChangeConfigPane(){ initButtonGroup(); @@ -147,14 +165,80 @@ public class ChangeConfigPane extends BasicBeanPane { return TableLayout4VanChartHelper.createGapTableLayoutPane(Toolkit.i18nText("Fine-Design_Basic_Background"), colorSelectBox4button, EDIT_AREA_WIDTH); } + private JPanel createButtonContentPane() { + JPanel buttonContentPane = new JPanel(new BorderLayout()); + + chartTypesPane = new JPanel(); + chartTypesPane.setLayout(new BoxLayout(chartTypesPane, BoxLayout.Y_AXIS)); + switchTitlePane = new TinyFormulaPane(); + + buttonContentPane.add(chartTypesPane, BorderLayout.NORTH); + buttonContentPane.add( + TableLayout4VanChartHelper.createGapTableLayoutPane( + Toolkit.i18nText("Fine-Design_Chart_Switch_Title_Label"), + switchTitlePane, + EDIT_AREA_WIDTH + ), + BorderLayout.CENTER + ); + + UIExpandablePane expandablePane = new UIExpandablePane(Toolkit.i18nText("Fine-Design_Chart_Button_Content"), 20, buttonContentPane) { + protected void setcontentPanelontentPanelBorder() { + + } + }; + expandablePane.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0)); + return expandablePane; + } + + private void populateButtonContentPane(ChartCollection collection) { + int count = collection.getChartCount(); + int select = collection.getSelectedIndex(); + + JPanel pane = null; + for (int i = 0; i < count; i++) { + if (i % COL_COUNT == 0) { + pane = new JPanel(new FlowLayout(FlowLayout.LEFT)); + chartTypesPane.add(pane); + } + + ChangeChartButton button = new ChangeChartButton(i, collection); + changeChartButtons.add(button); + button.setSelected(i == select); + pane.add(button); + } + + chartTypesPane.revalidate(); + selectedChart = select; + populateSwitchTitlePane(collection, select); + + } + + private void populateSwitchTitlePane(ChartCollection collection, int chartIndex) { + Chart chart = collection.getChart(chartIndex, Chart.class); + Object switchTitle = chart.getSwitchTitle(); + String result; + if (switchTitle != null) { + if (switchTitle instanceof BaseFormula) { + result = ((BaseFormula) switchTitle).getContent(); + } else { + result = Utils.objectToString(switchTitle); + } + } else { + result = collection.getChartName(chartIndex); + } + switchTitlePane.populateBean(result); + } + private JPanel createButtonConfigPane() { double p = TableLayout.PREFERRED; double f = TableLayout.FILL; double[] columnSize = {p, f}; - double[] rowSize = {p,p}; + double[] rowSize = {p, p, p}; Component[][] components = new Component[][]{ - new Component[]{createTitleStylePane(),null}, - new Component[]{createButtonBackgroundColorPane(),null}, + new Component[]{createTitleStylePane(), null}, + new Component[]{createButtonBackgroundColorPane(), null}, + new Component[]{createButtonContentPane(), null} }; return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); @@ -195,6 +279,7 @@ public class ChangeConfigPane extends BasicBeanPane { //按钮切换界面 styleAttrPane.populate(changeConfigAttr.getStyleAttr()); colorSelectBox4button.setSelectObject(changeConfigAttr.getButtonColor()); + populateButtonContentPane(ob); //轮播切换界面 timeInterval.setValue(changeConfigAttr.getTimeInterval()); @@ -224,10 +309,53 @@ public class ChangeConfigPane extends BasicBeanPane { changeConfigAttr.setTimeInterval((int) timeInterval.getValue()); changeConfigAttr.setCarouselColor(colorSelectBox4carousel.getSelectObject()); changeConfigAttr.setShowArrow(switchStyleGroup.getSelectedIndex() == 0); + + updateSwitchTitle(ob); + } + + private void updateSwitchTitle(ChartCollection collection) { + String titleString = switchTitlePane.updateBean(); + Object titleObj; + if (StableUtils.maybeFormula(titleString)) { + titleObj = BaseFormula.createFormulaBuilder().build(titleString); + } else { + titleObj = titleString; + } + collection.getChart(selectedChart, Chart.class).setSwitchTitle(titleObj); } @Override protected String title4PopupWindow() { return Toolkit.i18nText("Fine-Design_Chart_Change_Config_Attributes"); } + + private class ChangeChartButton extends UIToggleButton { + private ChartCollection collection; + private int buttonIndex; + + public ChangeChartButton(int i, ChartCollection collection) { + super(collection.getChartName(i)); + this.collection = collection; + this.buttonIndex = i; + } + + @Override + protected MouseListener getMouseListener() { + return new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + resetChangeChartButtons(); + populateSwitchTitlePane(collection, buttonIndex); + ChangeChartButton.this.setSelected(true); + selectedChart = buttonIndex; + } + }; + } + } + + private void resetChangeChartButtons() { + for (ChangeChartButton changeChartButton : changeChartButtons) { + changeChartButton.setSelected(false); + } + } }