帆软报表设计器源代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

303 lines
12 KiB

package com.fr.design.widgettheme;
import com.fr.base.theme.TemplateTheme;
import com.fr.widgettheme.theme.panel.WidgetTextStylePane;
import com.fr.widgettheme.theme.widget.style.BorderStyle;
import com.fr.widgettheme.theme.widget.style.ThemeTextStyle;
import com.fr.widgettheme.theme.widget.style.ThemedWidgetStyle;
import com.fr.widgettheme.theme.bean.ButtonBackground;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.designer.IntervalConstants;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.ibutton.UIButtonGroup;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.icombobox.LineComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.style.FRFontPane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.style.color.NewColorSelectBox;
import com.fr.design.widget.ui.designer.component.UIBoundSpinner;
import com.fr.form.ui.Widget;
import com.fr.general.FRFont;
import com.fr.widgettheme.theme.panel.ButtonStyleDefinedPane;
import com.fr.widgettheme.theme.widget.theme.WidgetThemeDisplayConstants;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 样式设置pane抽象类
*
* @author obo
* @since 11.0
* Created on 2023/11/13
*/
public abstract class BaseStyleSettingPane<T extends Widget> extends BasicBeanPane<T> {
protected List<StyleSetting> styleSettingList;
//样式切换标题头部
protected UIButtonGroup<String> styleSettingHead;
// 自定义样式
protected JPanel customPane;
// 主题色
protected NewColorSelectBox colorSelectBox;
// 风格1
protected UIRadioButton style1;
// 风格2
protected UIRadioButton style2;
// 边框线型
protected LineComboBox lineComboBox;
// 圆角边框
protected UIBoundSpinner borderRadiusSpinner;
// 字体详细设置
protected FRFontPane frFontPane;
// 按钮背景设置
protected ButtonStyleDefinedPane buttonStyleDefinedPane;
/**
* 文本样式
* 包含字体大小字体颜色
*/
protected WidgetTextStylePane textStylePane;
protected NewColorSelectBox selectBgColorBox;
private final Map<StyleSetting, UILabel> labelMap = new HashMap<>();
private final Map<StyleSetting, Component> paneMap = new HashMap<>();
public BaseStyleSettingPane(List<StyleSetting> styleSettingList) {
this.styleSettingList = styleSettingList;
initLabelMap();
initStyleEditor();
initPane();
initDefaultValue();
}
protected void initPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.add(createHeadPane(), BorderLayout.NORTH);
this.add(createCustomPane(), BorderLayout.CENTER);
}
protected void initStyleEditor() {
initStyle();
colorSelectBox = new NewColorSelectBox(160, true);
lineComboBox = new LineComboBox(WidgetThemeDisplayConstants.BORDER_LINE_STYLE_ARRAY);
borderRadiusSpinner = new UIBoundSpinner(0, Integer.MAX_VALUE, 1);
frFontPane = new FRFontPane();
buttonStyleDefinedPane = new ButtonStyleDefinedPane();
textStylePane = new WidgetTextStylePane(105);
selectBgColorBox = new NewColorSelectBox(160, true);
paneMap.put(StyleSetting.STYLE_TYPE, createStyleTypePane());
paneMap.put(StyleSetting.THEME_COLOR, colorSelectBox);
paneMap.put(StyleSetting.LINE_TYPE, lineComboBox);
paneMap.put(StyleSetting.TEXT_STYLE, textStylePane);
paneMap.put(StyleSetting.BORDER_RADIUS, borderRadiusSpinner);
paneMap.put(StyleSetting.FONT, frFontPane);
paneMap.put(StyleSetting.BTN_BACKGROUND, buttonStyleDefinedPane);
paneMap.put(StyleSetting.SELECT_COLOR, selectBgColorBox);
}
/**
* 初始化style1和style2
*/
private void initStyle() {
style1 = new UIRadioButton(Toolkit.i18nText("Fine-Design_Widget_Theme_Style_1"));
style2 = new UIRadioButton(Toolkit.i18nText("Fine-Design_Widget_Theme_Style_2"));
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(style1);
buttonGroup.add(style2);
}
protected JPanel createHeadPane() {
UILabel headLabel = new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Style_Setting"));
String[] titles = new String[]{Toolkit.i18nText("Fine-Design_Widget_Follow_Theme"), Toolkit.i18nText("Fine-Design_Widget_Theme_Custom")};
styleSettingHead = new UIButtonGroup(titles) {
@Override
public void setSelectedIndex(int newSelectedIndex, boolean fireChanged) {
super.setSelectedIndex(newSelectedIndex, fireChanged);
switchCard();
}
};
JPanel headPane = TableLayoutHelper.createGapTableLayoutPane(new Component[][]{
new Component[]{headLabel, styleSettingHead}}, TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W1, IntervalConstants.INTERVAL_L1);
headPane.setBorder(BorderFactory.createEmptyBorder(0, 0, IntervalConstants.INTERVAL_L1, 0));
return headPane;
}
protected JPanel createStyleTypePane() {
// 容纳风格1和风格2的panel
JPanel stylePane = new JPanel(FRGUIPaneFactory.createBoxFlowLayout());
stylePane.add(style1);
stylePane.add(style2);
return stylePane;
}
protected JPanel createCustomPane() {
int size = styleSettingList.size();
double f = TableLayout.FILL;
double p = TableLayout.PREFERRED;
int columnCount = 2;
double[] rowSize = new double[size];
for (int i = 0; i < size; i++) {
rowSize[i] = p;
}
double[] columnSize = {p, f};
int[][] rowCount = new int[size][columnCount];
for (int i = 0; i < size; i++) {
for (int j = 0; j < columnCount; j++) {
rowCount[i][j] = 1;
}
}
customPane = TableLayoutHelper.createGapTableLayoutPane(createComponents(size), rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_W1, IntervalConstants.INTERVAL_L1);
customPane.setBorder(BorderFactory.createEmptyBorder(0, 0, IntervalConstants.INTERVAL_L1, 0));
return customPane;
}
protected Component[][] createComponents(int size) {
Component[][] result = new Component[size][2];
for (int i = 0; i < size; i++) {
result[i] = createComponentByStyleSetting(styleSettingList.get(i));
}
return result;
}
protected Component[] createComponentByStyleSetting(StyleSetting styleSetting) {
Component[] components = new Component[2];
components[0] = labelMap.get(styleSetting);
components[1] = paneMap.get(styleSetting);
return components;
}
protected void switchCard() {
customPane.setVisible(styleSettingHead.getSelectedIndex() == 1);
}
protected void initDefaultValue() {
// 读取当前模板的主题
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (JTemplate.isValid(template)) {
TemplateTheme theme = template.getTemplateTheme();
ThemedWidgetStyle widgetStyle = (ThemedWidgetStyle) theme.getWidgetStyle();
if (widgetStyle != null) {
setThemedStyle(widgetStyle);
return;
}
}
setDefaultStyle();
}
private void setThemedStyle(ThemedWidgetStyle widgetStyle) {
setColorSelectBox(widgetStyle);
setStyle(widgetStyle);
setLineComboBox(widgetStyle);
setBorderRadiusSpinner(widgetStyle);
setTextStylePane(widgetStyle);
setFrFontPane();
setButtonStyleDefinedPane(widgetStyle);
setSelectBgColor(widgetStyle);
}
private void setColorSelectBox(ThemedWidgetStyle widgetStyle) {
if (colorSelectBox != null) {
colorSelectBox.setSelectObject(widgetStyle.getThemeColor());
}
}
private void setStyle(ThemedWidgetStyle widgetStyle) {
if (widgetStyle.getStyleType() == ThemedWidgetStyle.DEFAULT_STYLE) {
if (style1 != null) {
style1.setSelected(true);
}
} else {
if (style2 != null) {
style2.setSelected(true);
}
}
}
private void setLineComboBox(ThemedWidgetStyle widgetStyle) {
if (lineComboBox != null) {
lineComboBox.setSelectedLineStyle(widgetStyle.getBorderStyle().getLineType());
}
}
private void setBorderRadiusSpinner(ThemedWidgetStyle widgetStyle) {
if (borderRadiusSpinner != null) {
borderRadiusSpinner.setValue(widgetStyle.getBorderStyle().getRadius());
}
}
private void setTextStylePane(ThemedWidgetStyle widgetStyle) {
this.textStylePane.setTextStyle(widgetStyle.getTextStyle());
}
private void setFrFontPane() {
if (frFontPane != null) {
frFontPane.populateBean(FRFont.getInstance());
}
}
private void setButtonStyleDefinedPane(ThemedWidgetStyle widgetStyle) {
if (buttonStyleDefinedPane != null) {
buttonStyleDefinedPane.populate(ButtonBackground.create(widgetStyle.getButtonBackgroundStyle()));
}
}
private void setDefaultStyle() {
if (colorSelectBox != null) {
colorSelectBox.setSelectObject(ThemedWidgetStyle.DEFAULT_COLOR);
}
if (style1 != null) {
style1.setSelected(true);
}
if (lineComboBox != null) {
lineComboBox.setSelectedLineStyle(BorderStyle.DEFAULT_LINE_TYPE);
}
if (borderRadiusSpinner != null) {
borderRadiusSpinner.setValue(BorderStyle.DEFAULT_BORDER_RADIUS);
}
if (textStylePane != null) {
textStylePane.setTextStyle(new ThemeTextStyle());
}
if (frFontPane != null) {
frFontPane.populateBean(FRFont.getInstance());
}
if (selectBgColorBox != null) {
selectBgColorBox.setSelectObject(null);
}
}
private void setSelectBgColor(ThemedWidgetStyle widgetStyle) {
if(selectBgColorBox != null) {
selectBgColorBox.setSelectObject(widgetStyle.getSelectBackgroundColor());
}
}
/**
* 初始化枚举和UILabel对应的map
*/
private void initLabelMap() {
labelMap.put(StyleSetting.THEME_COLOR, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Color")));
labelMap.put(StyleSetting.TEXT_STYLE, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Text_Style")));
labelMap.put(StyleSetting.FONT, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Font")));
labelMap.put(StyleSetting.STYLE_TYPE, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Style")));
labelMap.put(StyleSetting.LINE_TYPE, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Border_Line")));
labelMap.put(StyleSetting.BORDER_RADIUS, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Border_Radius")));
labelMap.put(StyleSetting.BTN_BACKGROUND, new UILabel(Toolkit.i18nText("Fine-Design_Theme_Widget_Background")));
7 months ago
labelMap.put(StyleSetting.SELECT_COLOR, new UILabel(Toolkit.i18nText("Fine-Design_Widget_Background_Select_Box")));
}
}