帆软报表设计器源代码。
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.
 
 
 
 

177 lines
7.9 KiB

package com.fr.widgettheme.theme.edit.widget;
import com.fine.swing.ui.layout.Column;
import com.fr.base.background.ColorBackground;
import com.fr.base.theme.TemplateTheme;
import com.fr.design.gui.icombobox.LineComboBox;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.style.color.NewColorSelectBox;
import com.fr.design.utils.DesignUtils;
import com.fr.design.widget.FRWidgetFactory;
import com.fr.locale.InterProviderFactory;
import com.fr.stable.StringUtils;
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.widget.theme.WidgetThemeDisplayConstants;
import com.fr.widgettheme.util.WidgetStyleComponentCombiner;
import com.fr.widgettheme.util.WidgetThemeDesignerUtils;
import java.awt.Color;
import java.awt.Component;
import static com.fine.swing.ui.layout.Layouts.cell;
import static com.fine.swing.ui.layout.Layouts.column;
/**
* 桌面端主题面板
*
* @author Coral.Chen
* @since 11.0
* Created on 2023/3/28
*/
public class DesktopWidgetStyleEditPane<T extends TemplateTheme> extends WidgetStyleEditPane<T> {
/**
* 字体名选择器
*/
protected UIComboBox fontNameSelectBox;
/**
* 下拉面板背景颜色
*/
private NewColorSelectBox selectBackgroundColorBox;
public DesktopWidgetStyleEditPane() {
super();
}
@Override
public Component[][] generateComponent() {
initSelectBackgroundColorBox();
initFontNameSelectBox();
return new Component[][]{
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Color")), colorSelectBox},
new Component[]{WidgetThemeDesignerUtils.createTopAlignmentLabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Widget_Background")), initBackGroundComponent()},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Border_Line")), lineComboBox},
new Component[]{null, lineComboColorSelectBox},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Border_Radius")), borderRadiusSpinner},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Icon_Color")), iconColorSelectBox},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Text_Style")), fontNameSelectBox},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Theme_Text_Style")), WidgetStyleComponentCombiner.combineTextStyleComponent(fontSizePane, fontColorButton, italic, bold)},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Widget_Background_Select_Box")), selectBackgroundColorBox}
};
}
private Column initBackGroundComponent() {
return column(10,
cell(widgetBgColorSelectBox),
cell(FRWidgetFactory.createLineWrapLabel(Toolkit.i18nText("Fine-Design_Form_Widget-Style_Alpha"))),
cell(widgetBgAlphaDragPane)).getComponent();
}
private void initSelectBackgroundColorBox() {
selectBackgroundColorBox = new NewColorSelectBox(140, true);
selectBackgroundColorBox.setSelectObject(WidgetThemeDisplayConstants.DEFAULT_THEME_COLOR);
}
private void initFontNameSelectBox() {
fontNameSelectBox = new UIComboBox(DesignUtils.getAvailableFontFamilyNames4Report());
}
@Override
public void populateBean(T t) {
ThemedWidgetStyle style = (ThemedWidgetStyle) t.getWidgetStyle();
if (style == null) {
style = new ThemedWidgetStyle();
t.setWidgetStyle(style);
}
colorSelectBox.setSelectObject(style.getThemeColor());
selectBackgroundColorBox.setSelectObject(style.getSelectBackgroundColor());
iconColorSelectBox.setSelectObject(style.getIconColor());
populateBorder(style);
populateTextStyle(style);
populateWidgetBackground(style);
}
@Override
public void updateBean(T t) {
ThemedWidgetStyle style = (ThemedWidgetStyle) t.getWidgetStyle();
if (style == null) {
style = new ThemedWidgetStyle();
t.setWidgetStyle(style);
}
updateBorderStyle(style);
updateTextStyle(style);
updateButtonBackground(style);
updateWidgetBackground(style);
style.setThemeColor(colorSelectBox.getSelectObject());
style.setSelectBackgroundColor(selectBackgroundColorBox.getSelectObject());
style.setIconColor(iconColorSelectBox.getSelectObject());
}
private void updateBorderStyle(ThemedWidgetStyle style) {
BorderStyle borderStyle = new BorderStyle();
borderStyle.setLineType(lineComboBox.getSelectedLineStyle());
borderStyle.setRadius((int) borderRadiusSpinner.getValue());
borderStyle.setBorderColor(lineComboColorSelectBox.getSelectObject());
style.setBorderStyle(borderStyle);
}
private void updateTextStyle(ThemedWidgetStyle style) {
ThemeTextStyle textStyle = new ThemeTextStyle();
textStyle.setFontSize(fontSizePane.getValue());
textStyle.setFontColor(fontColorButton.getColor());
textStyle.setName((String) fontNameSelectBox.getSelectedItem());
textStyle.setBold(bold.isSelected());
textStyle.setItalic(italic.isSelected());
style.setTextStyle(textStyle);
}
private void updateButtonBackground(ThemedWidgetStyle style) {
ButtonBackgroundStyle buttonBackgroundStyle = new ButtonBackgroundStyle();
ColorBackground buttonBackground = ColorBackground.getInstance(style.getThemeColor());
buttonBackgroundStyle.setInitialBackground(buttonBackground);
buttonBackgroundStyle.setOverBackground(buttonBackground);
buttonBackgroundStyle.setClickBackground(buttonBackground);
style.setButtonBackgroundStyle(buttonBackgroundStyle);
}
private void updateWidgetBackground(ThemedWidgetStyle style) {
Color bgColor = widgetBgColorSelectBox.getSelectObject();
style.setWidgetBackground(ColorUtils.createColorBackgroundWithAlpha(bgColor, widgetBgAlphaDragPane.updateBean()));
}
private void populateTextStyle(ThemedWidgetStyle style) {
ThemeTextStyle textStyle = style.getTextStyle();
fontSizePane.setValue(textStyle.getFontSize());
fontColorButton.setColor(textStyle.getFontColor());
bold.setSelected(textStyle.isBold());
italic.setSelected(textStyle.isItalic());
String fontName = StringUtils.isEmpty(textStyle.getName()) ? InterProviderFactory.getProvider().getLocText("Fine-Engine_Base_Song_TypeFace") : textStyle.getName();
fontNameSelectBox.setSelectedItem(fontName);
}
private void populateBorder(ThemedWidgetStyle style) {
lineComboBox.setSelectedLineStyle(style.getBorderStyle().getLineType());
lineComboColorSelectBox.setSelectObject(style.getBorderStyle().getBorderColor());
borderRadiusSpinner.setValue(style.getBorderStyle().getRadius());
}
private void populateWidgetBackground(ThemedWidgetStyle style) {
widgetBgColorSelectBox.setSelectObject(ColorUtils.ignoreColorAlpha(style.getWidgetBackground().getColor()));
widgetBgAlphaDragPane.populateBean(ColorUtils.roundColorAlphaDouble(style.getWidgetBackground().getColor()));
}
@Override
public void initLineBox() {
lineComboBox = new LineComboBox(WidgetThemeDisplayConstants.BORDER_LINE_STYLE_ARRAY);
lineComboColorSelectBox = new NewColorSelectBox(WidgetThemeDisplayConstants.THEME_WIDGET_COMPONENT_WIDTH, true);
lineComboBox.addItemListener(e -> lineComboColorSelectBox.setVisible(!Integer.valueOf(0).equals(e.getItem())));
}
}