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.
343 lines
13 KiB
343 lines
13 KiB
package com.fr.design.widgettheme; |
|
|
|
import com.fr.base.background.ColorBackground; |
|
import com.fr.base.theme.TemplateTheme; |
|
import com.fr.design.gui.frpane.FontSizeComboPane; |
|
import com.fr.design.gui.frpane.UIPercentDragPane; |
|
import com.fr.design.gui.ibutton.UIColorButton; |
|
import com.fr.design.gui.ibutton.UIToggleButton; |
|
import com.fr.design.gui.icombobox.UIComboBox; |
|
import com.fr.general.IOUtils; |
|
import com.fr.util.ColorUtils; |
|
import com.fr.widgettheme.theme.widget.style.BorderStyle; |
|
import com.fr.widgettheme.theme.widget.style.ButtonBackgroundStyle; |
|
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.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 com.fr.widgettheme.util.WidgetStyleComponentCombiner; |
|
import com.fr.widgettheme.util.WidgetThemeDesignerUtils; |
|
|
|
import javax.swing.BorderFactory; |
|
import javax.swing.JPanel; |
|
import java.awt.BorderLayout; |
|
import java.awt.Color; |
|
import java.awt.Component; |
|
import java.util.HashMap; |
|
import java.util.List; |
|
import java.util.Map; |
|
|
|
import static com.fr.widgettheme.theme.widget.theme.WidgetThemeDisplayConstants.THEME_PC_WIDGET_BACKGROUND_WIDTH; |
|
|
|
/** |
|
* 样式设置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; |
|
// 边框线型 |
|
protected LineComboBox lineComboBox; |
|
/** |
|
* 边框颜色 |
|
*/ |
|
protected NewColorSelectBox borderColorSelectBox; |
|
// 圆角边框 |
|
protected UIBoundSpinner borderRadiusSpinner; |
|
// 字体详细设置 |
|
protected FRFontPane frFontPane; |
|
// 按钮背景设置 |
|
protected ButtonStyleDefinedPane buttonStyleDefinedPane; |
|
|
|
protected NewColorSelectBox selectBgColorBox; |
|
|
|
/** |
|
* 主题文本样式的字体大小 |
|
*/ |
|
protected FontSizeComboPane fontSizePane; |
|
|
|
/** |
|
* 主题文本样式的字体颜色 |
|
*/ |
|
protected UIColorButton fontColorButton; |
|
|
|
/** |
|
* 字体名选择器 |
|
*/ |
|
protected UIComboBox fontNameSelectBox; |
|
|
|
/** |
|
* 字体粗体配置 |
|
*/ |
|
protected UIToggleButton bold; |
|
/** |
|
* 字体斜体配置 |
|
*/ |
|
protected UIToggleButton italic; |
|
|
|
/** |
|
* 控件背景颜色配置面板 |
|
*/ |
|
protected NewColorSelectBox widgetBgColorSelectBox; |
|
/** |
|
* 控件背景透明度配置面板 |
|
*/ |
|
protected UIPercentDragPane widgetBgAlphaDragPane; |
|
/** |
|
* 控件图标颜色 |
|
*/ |
|
protected NewColorSelectBox iconColorSelectBox; |
|
|
|
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() { |
|
colorSelectBox = new NewColorSelectBox(WidgetThemeDisplayConstants.THEME_WIDGET_COMPONENT_WIDTH, false); |
|
initBorderPane(); |
|
frFontPane = new FRFontPane(); |
|
buttonStyleDefinedPane = new ButtonStyleDefinedPane(); |
|
selectBgColorBox = new NewColorSelectBox(WidgetThemeDisplayConstants.THEME_WIDGET_COMPONENT_WIDTH, true); |
|
iconColorSelectBox = new NewColorSelectBox(WidgetThemeDisplayConstants.THEME_WIDGET_COMPONENT_WIDTH, true); |
|
fontSizePane = new FontSizeComboPane(); |
|
fontColorButton = new UIColorButton(); |
|
bold = new UIToggleButton(IOUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png")); |
|
italic = new UIToggleButton(IOUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png")); |
|
widgetBgColorSelectBox = new NewColorSelectBox(WidgetThemeDisplayConstants.THEME_WIDGET_COMPONENT_WIDTH, true); |
|
widgetBgAlphaDragPane = new UIPercentDragPane(); |
|
paneMap.put(StyleSetting.THEME_COLOR, colorSelectBox); |
|
paneMap.put(StyleSetting.LINE_TYPE, lineComboBox); |
|
paneMap.put(StyleSetting.LINE_COLOR, borderColorSelectBox); |
|
paneMap.put(StyleSetting.TEXT_STYLE, WidgetStyleComponentCombiner.combineTextStyleComponent(fontNameSelectBox, fontSizePane, fontColorButton, bold, italic)); |
|
paneMap.put(StyleSetting.BORDER_RADIUS, borderRadiusSpinner); |
|
paneMap.put(StyleSetting.FONT, frFontPane); |
|
paneMap.put(StyleSetting.BTN_BACKGROUND, buttonStyleDefinedPane); |
|
paneMap.put(StyleSetting.SELECT_COLOR, selectBgColorBox); |
|
paneMap.put(StyleSetting.WIDGET_BACKGROUND, WidgetStyleComponentCombiner.combineWidgetBackgroundComponent(widgetBgColorSelectBox, widgetBgAlphaDragPane, THEME_PC_WIDGET_BACKGROUND_WIDTH)); |
|
paneMap.put(StyleSetting.ICON_COLOR, iconColorSelectBox); |
|
} |
|
|
|
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 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.getThemeColor()); |
|
setLineComboBox(widgetStyle.getBorderStyle().getLineType()); |
|
setBorderRadiusSpinner(widgetStyle.getBorderStyle().getRadius()); |
|
setTextStylePane(widgetStyle.getTextStyle()); |
|
setFrFontPane(widgetStyle.getFontStyle().getFont()); |
|
setButtonStyleDefinedPane(widgetStyle.getButtonBackgroundStyle()); |
|
setSelectBgColor(widgetStyle.getSelectBackgroundColor()); |
|
setWidgetBackground(widgetStyle.getWidgetBackground()); |
|
setBorderColor(widgetStyle.getBorderStyle().getBorderColor()); |
|
setIconColor(widgetStyle.getIconColor()); |
|
} |
|
|
|
private void setColorSelectBox(Color themeColor) { |
|
if (colorSelectBox != null) { |
|
colorSelectBox.setSelectObject(themeColor); |
|
} |
|
} |
|
|
|
private void setLineComboBox(int lineType) { |
|
if (lineComboBox != null) { |
|
lineComboBox.setSelectedLineStyle(lineType); |
|
} |
|
} |
|
|
|
private void setBorderRadiusSpinner(double radius) { |
|
if (borderRadiusSpinner != null) { |
|
borderRadiusSpinner.setValue(radius); |
|
} |
|
} |
|
|
|
private void setTextStylePane(ThemeTextStyle textStyle) { |
|
if (fontSizePane != null) { |
|
this.fontSizePane.setValue(textStyle.getFontSize()); |
|
} |
|
if (fontColorButton != null) { |
|
this.fontColorButton.setColor(textStyle.getFontColor()); |
|
} |
|
} |
|
|
|
private void setFrFontPane(FRFont font) { |
|
if (frFontPane != null) { |
|
frFontPane.populateBean(font); |
|
} |
|
} |
|
|
|
private void setButtonStyleDefinedPane(ButtonBackgroundStyle backgroundStyle) { |
|
if (buttonStyleDefinedPane != null) { |
|
buttonStyleDefinedPane.populate(ButtonBackground.create(backgroundStyle)); |
|
} |
|
} |
|
|
|
private void setDefaultStyle() { |
|
setColorSelectBox(ThemedWidgetStyle.DEFAULT_COLOR); |
|
setLineComboBox(BorderStyle.DEFAULT_LINE_TYPE); |
|
setBorderRadiusSpinner(BorderStyle.DEFAULT_BORDER_RADIUS); |
|
setTextStylePane(ThemeTextStyle.DEFAULT_WIDGET_STYLE); |
|
setFrFontPane(FRFont.getInstance()); |
|
setSelectBgColor(WidgetThemeDisplayConstants.DEFAULT_TRANSPARENT_COLOR); |
|
setWidgetBackground(WidgetThemeDisplayConstants.DEFAULT_COLOR_BACKGROUND); |
|
setBorderColor(BorderStyle.DEFAULT_WIDGET_BORDER_COLOR); |
|
setIconColor(Color.BLACK); |
|
} |
|
|
|
private void setSelectBgColor(Color selectBgColor) { |
|
if (selectBgColorBox != null) { |
|
selectBgColorBox.setSelectObject(selectBgColor); |
|
} |
|
} |
|
|
|
private void setWidgetBackground(ColorBackground background) { |
|
if (widgetBgColorSelectBox != null) { |
|
widgetBgColorSelectBox.setSelectObject(background.getColor()); |
|
} |
|
if (widgetBgAlphaDragPane != null) { |
|
//0-255,需要转化为 |
|
double alpha = ColorUtils.roundColorAlphaDouble(background.getColor()); |
|
widgetBgAlphaDragPane.populateBean(alpha); |
|
} |
|
} |
|
|
|
private void setBorderColor(Color borderColor) { |
|
if(borderColorSelectBox != null) { |
|
borderColorSelectBox.setSelectObject(borderColor); |
|
} |
|
} |
|
|
|
private void setIconColor(Color iconColor) { |
|
if(iconColorSelectBox != null) { |
|
iconColorSelectBox.setSelectObject(iconColor); |
|
} |
|
} |
|
|
|
/** |
|
* 初始化枚举和UILabel对应的map |
|
*/ |
|
private void initLabelMap() { |
|
for (StyleSetting setting : StyleSetting.values()) { |
|
labelMap.put(setting, WidgetThemeDesignerUtils.createTopAlignmentLabel(Toolkit.i18nText(setting.getLabelI18nKey()))); |
|
} |
|
} |
|
|
|
private void initBorderPane() { |
|
lineComboBox = new LineComboBox(WidgetThemeDisplayConstants.BORDER_LINE_STYLE_ARRAY); |
|
borderColorSelectBox = new NewColorSelectBox(WidgetThemeDisplayConstants.THEME_WIDGET_COMPONENT_WIDTH, true); |
|
borderRadiusSpinner = new UIBoundSpinner(0, Integer.MAX_VALUE, 1); |
|
lineComboBox.addItemListener(e -> borderColorSelectBox.setVisible(!Integer.valueOf(0).equals(e.getItem()))); |
|
} |
|
}
|
|
|