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.
142 lines
4.9 KiB
142 lines
4.9 KiB
package com.fr.design.widgettheme.common; |
|
|
|
import com.fr.widgettheme.theme.widget.style.BorderStyle; |
|
import com.fr.widgettheme.theme.widget.style.ButtonBackgroundStyle; |
|
import com.fr.widgettheme.theme.bean.ButtonBackground; |
|
import com.fr.design.widgettheme.StyleSettingPane; |
|
import com.fr.form.ui.FreeButton; |
|
import com.fr.form.ui.Widget; |
|
import com.fr.design.widgettheme.StyleSetting; |
|
import com.fr.widgettheme.theme.widget.theme.cell.NormalButtonTheme; |
|
import org.jetbrains.annotations.Nullable; |
|
|
|
import java.util.Arrays; |
|
import java.util.List; |
|
|
|
/** |
|
* 设计器控件属性的“高级”设置增加主题样式设置项,包括: |
|
* 按钮组件 |
|
* |
|
* @author John.Ying |
|
* @version 11.0 |
|
* Created by John.Ying on 2023/4/27 |
|
*/ |
|
public class NormalButtonSettingPane<T extends Widget> extends StyleSettingPane<T> { |
|
|
|
public NormalButtonSettingPane() { |
|
super(Arrays.asList( |
|
StyleSetting.BTN_BACKGROUND, |
|
StyleSetting.LINE_TYPE, |
|
StyleSetting.BORDER_RADIUS |
|
)); |
|
} |
|
|
|
public NormalButtonSettingPane(List<StyleSetting> styleSettingList) { |
|
super(styleSettingList); |
|
} |
|
|
|
@Override |
|
public void populateBean(T t) { |
|
NormalButtonTheme widgetTheme = initNormalButtonTheme(t); |
|
|
|
if (t instanceof FreeButton && ((FreeButton) t).isCustomStyle()) { |
|
initCustomStyle((FreeButton) t, widgetTheme); |
|
} |
|
|
|
populateNormalButtonBean(widgetTheme); |
|
} |
|
|
|
/** |
|
* 根据freeButton自定义样式,初始化widgetTheme |
|
*/ |
|
protected void initCustomStyle(FreeButton freeButton, NormalButtonTheme widgetTheme) { |
|
ButtonBackgroundStyle buttonBackgroundStyle = new ButtonBackgroundStyle(freeButton.getInitialBackground(), freeButton.getOverBackground(), freeButton.getClickBackground()); |
|
widgetTheme.setButtonBackgroundStyle(buttonBackgroundStyle); |
|
widgetTheme.setFollowTheme(false); |
|
} |
|
|
|
protected void populateNormalButtonBean(NormalButtonTheme widgetTheme) { |
|
if (widgetTheme.isFollowTheme()) { |
|
styleSettingHead.setSelectedIndex(0); |
|
// todo 参数面板里的控件样式跟随改变 |
|
} else { |
|
styleSettingHead.setSelectedIndex(1); |
|
lineComboBox.setSelectedLineStyle(widgetTheme.getBorderStyle().getLineType()); |
|
borderRadiusSpinner.setValue(widgetTheme.getBorderStyle().getRadius()); |
|
assignFontPane(widgetTheme); |
|
buttonStyleDefinedPane.populate(ButtonBackground.create(widgetTheme.getButtonBackgroundStyle())); |
|
} |
|
switchCard(); |
|
} |
|
|
|
protected void assignFontPane(NormalButtonTheme normalButtonTheme) { |
|
|
|
} |
|
|
|
protected void assignFontStyle(NormalButtonTheme normalButtonTheme) { |
|
|
|
} |
|
|
|
protected NormalButtonTheme initNormalButtonTheme(T t) { |
|
NormalButtonTheme widgetTheme = (NormalButtonTheme) t.getWidgetTheme(); |
|
if (widgetTheme == null) { |
|
widgetTheme = getDefaultNormalButtonTheme(); |
|
t.setWidgetTheme(widgetTheme); |
|
} |
|
return widgetTheme; |
|
} |
|
|
|
protected NormalButtonTheme getDefaultNormalButtonTheme() { |
|
return new NormalButtonTheme(); |
|
} |
|
|
|
@Override |
|
public void updateBean(T t) { |
|
NormalButtonTheme widgetTheme = initNormalButtonTheme(t); |
|
|
|
int selectIndex = styleSettingHead.getSelectedIndex(); |
|
widgetTheme.setFollowTheme(selectIndex == 0); |
|
|
|
updateNormalButtonStyleBean(widgetTheme); |
|
|
|
// 切换到跟随主题时,修改主题样式为默认样式,防止将自定义样式写入到模版,被主jar读取解析 |
|
if (widgetTheme.isFollowTheme()) { |
|
t.setWidgetTheme(getDefaultNormalButtonTheme()); |
|
} |
|
|
|
if (t instanceof FreeButton) { |
|
FreeButton freeButton = (FreeButton) t; |
|
freeButton.setCustomStyle(!widgetTheme.isFollowTheme()); |
|
updateCustomStyle(freeButton, widgetTheme); |
|
} |
|
} |
|
|
|
/** |
|
* 更新freeButton的自定义样式 |
|
*/ |
|
protected void updateCustomStyle(FreeButton freeButton, NormalButtonTheme widgetTheme) { |
|
ButtonBackgroundStyle backgroundStyle = widgetTheme.getButtonBackgroundStyle(); |
|
freeButton.setInitialBackground(backgroundStyle.getInitialBackground()); |
|
freeButton.setOverBackground(backgroundStyle.getOverBackground()); |
|
freeButton.setClickBackground(backgroundStyle.getClickBackground()); |
|
} |
|
|
|
protected void updateNormalButtonStyleBean(NormalButtonTheme normalButtonTheme) { |
|
assignFontStyle(normalButtonTheme); |
|
normalButtonTheme.setButtonBackgroundStyle(buttonStyleDefinedPane.update()); |
|
normalButtonTheme.setBorderStyle(new BorderStyle((int) borderRadiusSpinner.getValue(), lineComboBox.getSelectedLineStyle())); |
|
|
|
switchCard(); |
|
} |
|
|
|
@Override |
|
@Nullable |
|
public T updateBean() { |
|
return null; |
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return "normalButtonSetting"; |
|
} |
|
}
|
|
|