Browse Source

CHART-22529 切换控件标题自定义—设计器面板

feature/x
方磊 3 years ago
parent
commit
650fd5ccb4
  1. 39
      designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChangeConfigPane.java

39
designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChangeConfigPane.java

@ -71,7 +71,8 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
private UIButtonGroup switchStyleGroup; private UIButtonGroup switchStyleGroup;
private JPanel chartTypesPane; private JPanel chartTypesPane;
private TinyFormulaPane switchTitlePane; private List<TinyFormulaPane> switchTitles = new ArrayList<>();
private JPanel switchTitlePane = new JPanel();
private List<ChangeChartButton> changeChartButtons = new ArrayList<>(); private List<ChangeChartButton> changeChartButtons = new ArrayList<>();
private int selectedChart; // 设置面板里面选取的图表,不是真正切换的图表 private int selectedChart; // 设置面板里面选取的图表,不是真正切换的图表
@ -87,10 +88,11 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
double p = TableLayout.PREFERRED; double p = TableLayout.PREFERRED;
double f = TableLayout.FILL; double f = TableLayout.FILL;
double[] columnSize = {p, f}; double[] columnSize = {p, f};
double[] rowSize = {p,p}; double[] rowSize = {p, p, p};
Component[][] components = new Component[][]{ Component[][] components = new Component[][]{
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Change_Style")),configStyleButton}, new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Change_Style")),configStyleButton},
new Component[]{configPane, null}, new Component[]{configPane, null},
new Component[]{createButtonContentPane(), null}
}; };
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
} }
@ -170,7 +172,7 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
chartTypesPane = new JPanel(); chartTypesPane = new JPanel();
chartTypesPane.setLayout(new BoxLayout(chartTypesPane, BoxLayout.Y_AXIS)); chartTypesPane.setLayout(new BoxLayout(chartTypesPane, BoxLayout.Y_AXIS));
switchTitlePane = new TinyFormulaPane(); switchTitlePane.setLayout(new CardLayout());
buttonContentPane.add(chartTypesPane, BorderLayout.NORTH); buttonContentPane.add(chartTypesPane, BorderLayout.NORTH);
buttonContentPane.add( buttonContentPane.add(
@ -206,15 +208,16 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
changeChartButtons.add(button); changeChartButtons.add(button);
button.setSelected(i == select); button.setSelected(i == select);
pane.add(button); pane.add(button);
populateSwitchTitlePane(i, collection);
} }
chartTypesPane.revalidate(); chartTypesPane.revalidate();
switchTitlePane.revalidate();
selectedChart = select; selectedChart = select;
populateSwitchTitlePane(collection, select);
} }
private void populateSwitchTitlePane(ChartCollection collection, int chartIndex) { private void populateSwitchTitlePane(int chartIndex, ChartCollection collection) {
Chart chart = collection.getChart(chartIndex, Chart.class); Chart chart = collection.getChart(chartIndex, Chart.class);
Object switchTitle = chart.getSwitchTitle(); Object switchTitle = chart.getSwitchTitle();
String result; String result;
@ -227,7 +230,11 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
} else { } else {
result = collection.getChartName(chartIndex); result = collection.getChartName(chartIndex);
} }
switchTitlePane.populateBean(result);
TinyFormulaPane title = new TinyFormulaPane();
title.populateBean(result);
switchTitles.add(title);
switchTitlePane.add(title, collection.getChartName(chartIndex));
} }
private JPanel createButtonConfigPane() { private JPanel createButtonConfigPane() {
@ -238,7 +245,6 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
Component[][] components = new Component[][]{ Component[][] components = new Component[][]{
new Component[]{createTitleStylePane(), null}, new Component[]{createTitleStylePane(), null},
new Component[]{createButtonBackgroundColorPane(), null}, new Component[]{createButtonBackgroundColorPane(), null},
new Component[]{createButtonContentPane(), null}
}; };
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
@ -314,14 +320,17 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
} }
private void updateSwitchTitle(ChartCollection collection) { private void updateSwitchTitle(ChartCollection collection) {
String titleString = switchTitlePane.updateBean(); int count = collection.getChartCount();
for (int i = 0; i < count; i++) {
String titleString = switchTitles.get(i).updateBean();
Object titleObj; Object titleObj;
if (StableUtils.maybeFormula(titleString)) { if (StableUtils.maybeFormula(titleString)) {
titleObj = BaseFormula.createFormulaBuilder().build(titleString); titleObj = BaseFormula.createFormulaBuilder().build(titleString);
} else { } else {
titleObj = titleString; titleObj = titleString;
} }
collection.getChart(selectedChart, Chart.class).setSwitchTitle(titleObj); collection.getChart(i, Chart.class).setSwitchTitle(titleObj);
}
} }
@Override @Override
@ -330,6 +339,9 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
} }
private class ChangeChartButton extends UIToggleButton { private class ChangeChartButton extends UIToggleButton {
private static final int BUTTON_WIDTH = 52;
private static final int BUTTON_HEIGHT = 20;
private ChartCollection collection; private ChartCollection collection;
private int buttonIndex; private int buttonIndex;
@ -345,12 +357,17 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
resetChangeChartButtons(); resetChangeChartButtons();
populateSwitchTitlePane(collection, buttonIndex); CardLayout cardLayout = (CardLayout) switchTitlePane.getLayout();
cardLayout.show(switchTitlePane, collection.getChartName(buttonIndex));
ChangeChartButton.this.setSelected(true); ChangeChartButton.this.setSelected(true);
selectedChart = buttonIndex; selectedChart = buttonIndex;
} }
}; };
} }
public Dimension getPreferredSize() {
return new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT);
}
} }
private void resetChangeChartButtons() { private void resetChangeChartButtons() {

Loading…
Cancel
Save