Browse Source

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

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

138
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<ChartCollection> {
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<Integer> configStyleButton;
@ -56,6 +70,10 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
private ColorSelectBoxWithOutTransparent colorSelectBox4carousel;
private UIButtonGroup switchStyleGroup;
private JPanel chartTypesPane;
private TinyFormulaPane switchTitlePane;
private List<ChangeChartButton> changeChartButtons = new ArrayList<>();
private int selectedChart; // 设置面板里面选取的图表,不是真正切换的图表
public ChangeConfigPane(){
initButtonGroup();
@ -147,14 +165,80 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
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<ChartCollection> {
//按钮切换界面
styleAttrPane.populate(changeConfigAttr.getStyleAttr());
colorSelectBox4button.setSelectObject(changeConfigAttr.getButtonColor());
populateButtonContentPane(ob);
//轮播切换界面
timeInterval.setValue(changeConfigAttr.getTimeInterval());
@ -224,10 +309,53 @@ public class ChangeConfigPane extends BasicBeanPane<ChartCollection> {
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);
}
}
}

Loading…
Cancel
Save