package com.fr.widgettheme; import com.fr.base.theme.TemplateTheme; import com.fr.design.beans.BasicBeanPane; import com.fr.design.constants.LayoutConstants; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.widget.accessibles.AccessibleBackgroundEditor; import com.fr.form.ui.container.WParameterLayout; import com.fr.general.Background; import org.jetbrains.annotations.Nullable; import javax.swing.JPanel; import java.awt.BorderLayout; /** * 设计器参数面板的“高级”设置增加背景的主题样式设置 * * @author Bruce.Deng * @since 11.0 * Created on 2023/2/20 */ public class ParameterBackgroundStyleSettingPane extends BasicBeanPane { public static final String[] FOLLOWING_THEME_STRING_ARRAYS = new String[]{ Toolkit.i18nText("Fine-Design_Widget_Follow_Theme"), Toolkit.i18nText("Fine-Design_Widget_Theme_Custom") }; private UIButtonGroup head; private JPanel customPane; private AccessibleBackgroundEditor background; public ParameterBackgroundStyleSettingPane() { this.setLayout(new BorderLayout(0, LayoutConstants.VGAP_SMALL)); head = new UIButtonGroup(FOLLOWING_THEME_STRING_ARRAYS) { @Override public void setSelectedIndex(int newSelectedIndex, boolean fireChanged) { //表示从跟随主题切换到自定义 if (selectedIndex != newSelectedIndex && newSelectedIndex == 1) { background.setValue(getThemeBackground()); } super.setSelectedIndex(newSelectedIndex, fireChanged); } }; customPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); background = new AccessibleBackgroundEditor(); customPane.add(background); this.add(head, BorderLayout.NORTH); this.add(customPane, BorderLayout.CENTER); } private void attributeChange() { customPane.setVisible(head.getSelectedIndex() == 1); } @Override public void populateBean(WParameterLayout wParameterLayout) { if (wParameterLayout.isBackgroundFollowTheme()) { head.setSelectedIndex(0); } else { head.setSelectedIndex(1); background.setValue(wParameterLayout.getBackground()); } attributeChange(); } @Override @Nullable public WParameterLayout updateBean() { return null; } @Override public void updateBean(WParameterLayout wParameterLayout) { attributeChange(); if (head.getSelectedIndex() != 1) { wParameterLayout.setBackgroundFollowTheme(true); wParameterLayout.setBackground(getThemeBackground()); } else { wParameterLayout.setBackgroundFollowTheme(false); wParameterLayout.setBackground((Background) background.getValue()); } } private Background getThemeBackground() { JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); if (JTemplate.isValid(template)) { TemplateTheme theme = template.getTemplateTheme(); return theme.getParamContainerStyle().getBackground(); } return (Background) background.getValue(); } @Override protected String title4PopupWindow() { return Toolkit.i18nText("Fine-Design_Widget_Theme_ParamContainer_Background"); } }