diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeEditorPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeEditorPane.java index 963f387f33..5432109dc0 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeEditorPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeEditorPane.java @@ -5,6 +5,7 @@ import com.fr.base.theme.TemplateTheme; import com.fr.base.theme.TemplateThemeConfig; import com.fr.base.theme.settings.ThemedCellStyleList; import com.fr.base.theme.settings.ThemedColorScheme; +import com.fr.widgettheme.ThemePreviewTerminal; import com.fr.widgettheme.util.WidgetThemeDesignerUtils; import com.fr.design.ExtraDesignClassManager; import com.fr.design.beans.BasicBeanPane; @@ -340,4 +341,20 @@ public abstract class TemplateThemeEditorPane extends J } } } + + /** + * 开启控件显示增强时,从配置面板处获取主题样式预览的终端类型 + * 默认为PC端,兼容原有场景 + */ + public ThemePreviewTerminal getWidgetStyleEditorTerminal() { + if (!WidgetThemeDesignerUtils.enableWidgetEnhance()) { + return ThemePreviewTerminal.PC; + } + for (BasicBeanPane pane : extraPaneList) { + if (pane instanceof WidgetStyleEditContainerPane) { + return ((WidgetStyleEditContainerPane) pane).getTerminalStyle(); + } + } + return ThemePreviewTerminal.PC; + } } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeProfilePane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeProfilePane.java index 92acb5c71e..c79ccd9090 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeProfilePane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeProfilePane.java @@ -14,12 +14,13 @@ import com.fr.design.mainframe.theme.dialog.TemplateThemeProfileDialog; import com.fr.design.mainframe.theme.edit.ui.LabelUtils; import com.fr.design.mainframe.theme.ui.AutoCheckTextField; import com.fr.design.mainframe.theme.ui.AutoCheckThemeNameTextField; -import com.fr.design.mainframe.theme.ui.BorderUtils; import com.fr.design.mainframe.toast.DesignerToastMsgUtil; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; import com.fr.transaction.CallBackAdaptor; +import com.fr.widgettheme.ThemePreviewTerminal; +import com.fr.widgettheme.theme.widget.theme.WidgetThemeDisplayConstants; import javax.swing.BorderFactory; import javax.swing.JDialog; @@ -51,7 +52,8 @@ public abstract class TemplateThemeProfilePane extends protected TemplateThemePreviewPane themePreviewPane; protected TemplateThemeEditorPane themeEditorPane; - + protected UILabel leftTitleLabel; + protected UILabel leftTitlePromptLabel; protected boolean isPopulating = false; protected boolean isMutable = false; @@ -83,10 +85,9 @@ public abstract class TemplateThemeProfilePane extends private JPanel createLeftPane() { JPanel titleContainer = FRGUIPaneFactory.createBorderLayout_S_Pane(); titleContainer.setPreferredSize(new Dimension(LEFT_TITLE_PANE_WIDTH, LEFT_TITLE_PANE_HEIGHT)); - titleContainer.setBorder(BorderUtils.createTitleBorder(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Preview_Pane_Title"), TITLE_BORDER_FONT)); - JPanel previewContainer = FRGUIPaneFactory.createBorderLayout_S_Pane(); previewContainer.setBorder(BorderFactory.createEmptyBorder(5, 4, 10, 4)); + titleContainer.add(createTitlePane(), BorderLayout.NORTH); titleContainer.add(previewContainer, BorderLayout.CENTER); themePreviewPane = createThemePreviewPane(); @@ -103,7 +104,10 @@ public abstract class TemplateThemeProfilePane extends if (isPopulating) { return; } - themePreviewPane.refresh(updateBean()); + ThemePreviewTerminal terminal = themeEditorPane.getWidgetStyleEditorTerminal(); + themePreviewPane.refresh(updateBean(), terminal); + String prompt = terminal == ThemePreviewTerminal.PC ? Toolkit.i18nText("Fine-Design_Theme_Control_PC_Prompt") : Toolkit.i18nText("Fine-Design_Theme_Control_Mobile_Prompt"); + leftTitlePromptLabel.setText(prompt); saveButton.setEnabled(themeEditorPane.checkNameValid() && isMutable); } }); @@ -367,4 +371,20 @@ public abstract class TemplateThemeProfilePane extends @Override public void onSaved(TemplateTheme theme) {} } + + /** + * 创建预览界面标题面板 + */ + protected JPanel createTitlePane() { + JPanel titlePane = new JPanel(); + titlePane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); + titlePane.setLayout(new BorderLayout()); + leftTitleLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Preview_Pane_Title")); + leftTitlePromptLabel = new UILabel(Toolkit.i18nText("Fine-Design_Theme_Control_PC_Prompt")); + leftTitleLabel.setForeground(WidgetThemeDisplayConstants.THEME_PREVIEW_TITLE_COLOR); + leftTitlePromptLabel.setForeground(WidgetThemeDisplayConstants.COMPATIBLE_STYLE_FONT_COLOR); + titlePane.add(leftTitleLabel, BorderLayout.WEST); + titlePane.add(leftTitlePromptLabel, BorderLayout.EAST); + return titlePane; + } } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ThemePreviewed.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ThemePreviewed.java index bb2aa05c22..272c7716c8 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ThemePreviewed.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ThemePreviewed.java @@ -1,5 +1,7 @@ package com.fr.design.mainframe.theme.preview; +import com.fr.widgettheme.ThemePreviewTerminal; + /** * @author Starryi * @version 1.0 @@ -7,4 +9,14 @@ package com.fr.design.mainframe.theme.preview; */ public interface ThemePreviewed { void refresh(T style); + + /** + * 根据主题预览样式类型进行刷新 + * + * @param style 样式,可以包含多个终端展现效果 + * @param terminal 终端类型 + */ + default void refresh(T style, ThemePreviewTerminal terminal) { + refresh(style); + } } diff --git a/designer-base/src/main/java/com/fr/widgettheme/ThemePreviewTerminal.java b/designer-base/src/main/java/com/fr/widgettheme/ThemePreviewTerminal.java new file mode 100644 index 0000000000..844e642191 --- /dev/null +++ b/designer-base/src/main/java/com/fr/widgettheme/ThemePreviewTerminal.java @@ -0,0 +1,62 @@ +package com.fr.widgettheme; + +import com.fr.base.theme.TemplateTheme; +import com.fr.widgettheme.theme.widget.style.MobileThemedWidgetStyle; +import com.fr.widgettheme.theme.widget.style.ThemedWidgetStyle; + +/** + * 主题样式预览终端类型 + * + * @author obo + * @since 11.0 + * Created on 2024/2/2 + */ +public enum ThemePreviewTerminal { + + /** + * 桌面端,为默认类型 + */ + PC(0) { + @Override + public ThemedWidgetStyle getThemeWidgetStyle(TemplateTheme theme) { + return (ThemedWidgetStyle) theme.getWidgetStyle(); + } + }, + + /** + * 移动端 + */ + MOBILE(1) { + @Override + public ThemedWidgetStyle getThemeWidgetStyle(TemplateTheme theme) { + return (MobileThemedWidgetStyle) theme.getMobileWidgetStyle(); + } + }; + + /** + * 类型码 + */ + final int code; + + ThemePreviewTerminal(int code) { + this.code = code; + } + + public int getCode() { + return code; + } + + public abstract ThemedWidgetStyle getThemeWidgetStyle(TemplateTheme theme); + + /** + * 根据code获取对应的枚举 + */ + public static ThemePreviewTerminal getTypeByCode(int code) { + for (ThemePreviewTerminal type : ThemePreviewTerminal.values()) { + if (type.code == code) { + return type; + } + } + throw new IllegalArgumentException("Invalid ThemePreviewTerminalType code :" + code); + } +} diff --git a/designer-base/src/main/java/com/fr/widgettheme/theme/edit/widget/WidgetStyleEditContainerPane.java b/designer-base/src/main/java/com/fr/widgettheme/theme/edit/widget/WidgetStyleEditContainerPane.java index 789c0f61ac..16e4a4f58c 100644 --- a/designer-base/src/main/java/com/fr/widgettheme/theme/edit/widget/WidgetStyleEditContainerPane.java +++ b/designer-base/src/main/java/com/fr/widgettheme/theme/edit/widget/WidgetStyleEditContainerPane.java @@ -8,6 +8,7 @@ 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.widgettheme.ThemePreviewTerminal; import org.jetbrains.annotations.Nullable; import javax.swing.JPanel; @@ -133,4 +134,8 @@ public class WidgetStyleEditContainerPane extends Basic protected String title4PopupWindow() { return Toolkit.i18nText("Fine-Design_Theme_Widget_Style"); } + + public ThemePreviewTerminal getTerminalStyle() { + return ThemePreviewTerminal.getTypeByCode(terminalStyleGroup.getSelectedIndex()); + } } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ControlPreviewCell.java b/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ControlPreviewCell.java index b42c26fcfb..ec36032713 100644 --- a/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ControlPreviewCell.java +++ b/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ControlPreviewCell.java @@ -3,6 +3,8 @@ package com.fr.widgettheme.theme.panel; import com.fr.base.BaseUtils; import com.fr.base.Style; import com.fr.base.theme.TemplateTheme; +import com.fr.widgettheme.ThemePreviewTerminal; +import com.fr.widgettheme.theme.widget.style.ThemeTextStyle; import com.fr.widgettheme.theme.widget.style.ThemedWidgetStyle; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.general.FRFont; @@ -14,7 +16,6 @@ import javax.swing.ImageIcon; import javax.swing.JPanel; import java.awt.Color; import java.awt.Dimension; -import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.LayoutManager; @@ -39,6 +40,11 @@ public class ControlPreviewCell extends JPanel { */ protected String value; protected TemplateTheme reportTheme; + + /** + * 主题预览类型,默认为PC端 + */ + protected ThemePreviewTerminal themePreviewTerminal = ThemePreviewTerminal.PC; /** * 字体的颜色 */ @@ -70,9 +76,10 @@ public class ControlPreviewCell extends JPanel { /** * 主题样式变化后监听改变 */ - public void refresh(TemplateTheme reportTheme) { + public void refresh(TemplateTheme reportTheme, ThemePreviewTerminal type) { this.reportTheme = reportTheme; - ThemedWidgetStyle widgetStyle = (ThemedWidgetStyle) this.reportTheme.getWidgetStyle(); + this.themePreviewTerminal = type; + ThemedWidgetStyle widgetStyle = this.themePreviewTerminal.getThemeWidgetStyle(reportTheme); //主题色设置为透明或者插件启动前已有的主题启动插件后主题色为null if (widgetStyle.getThemeColor() == null) { widgetStyle.setThemeColor(DEFAULT_THEME_COLOR); @@ -87,8 +94,7 @@ public class ControlPreviewCell extends JPanel { } public Color getIconColor() { - ThemedWidgetStyle widgetStyle = (ThemedWidgetStyle) reportTheme.getWidgetStyle(); - return widgetStyle.getIconColor(); + return this.themePreviewTerminal.getThemeWidgetStyle(reportTheme).getIconColor(); } protected Icon setStyleTwoIcon(Icon icon, Icon defaultIcon) { @@ -106,13 +112,15 @@ public class ControlPreviewCell extends JPanel { * 填充圆角矩形背景色 */ public void paintBgColor(Graphics g, ThemedWidgetStyle widgetStyle, int alpha) { - Color themeColor = widgetStyle.getWidgetBackground().getColor(); + ThemedWidgetStyle themeWidgetStyle = this.themePreviewTerminal.getThemeWidgetStyle(this.reportTheme); + Color themeColor = themeWidgetStyle.getThemeColor(); themeColor = themeColor == null ? WidgetThemeDisplayConstants.DEFAULT_TRANSPARENT_COLOR : themeColor; g.setColor(new Color(themeColor.getRed(), themeColor.getGreen(), themeColor.getBlue(), alpha)); g.fillRoundRect(0, 0, getSize().width - 1, getSize().height - 1, (int) widgetStyle.getBorderStyle().getRadius(), (int) widgetStyle.getBorderStyle().getRadius()); //需要重新绘制一遍字体,否则会被颜色填充给遮住 Graphics2D g2d = (Graphics2D) g.create(); - FRFont font = FRFont.getInstance(FRFont.DEFAULT_FONTNAME, Font.PLAIN, widgetStyle.getTextStyle().getFontSize(), textColor); + ThemeTextStyle textStyle = themeWidgetStyle.getTextStyle(); + FRFont font = FRFont.getInstance(textStyle.getName(), textStyle.getCompositeFontStyle(), textStyle.getFontSize(), textStyle.getFontColor()); BaseUtils.drawStringStyleInRotation(g2d, getWidth(), getHeight(), this.value, Style.getInstance(font).deriveHorizontalAlignment(Constants.LEFT) .deriveTextStyle(Style.TEXTSTYLE_SINGLELINE), NO_SCALE_RESOLUTION); @@ -125,8 +133,8 @@ public class ControlPreviewCell extends JPanel { return; } Graphics2D g2d = (Graphics2D) g.create(); - ThemedWidgetStyle widgetStyle = (ThemedWidgetStyle) reportTheme.getWidgetStyle(); - FRFont font = FRFont.getInstance(FRFont.DEFAULT_FONTNAME, Font.PLAIN, widgetStyle.getTextStyle().getFontSize(), textColor); + ThemeTextStyle textStyle = this.themePreviewTerminal.getThemeWidgetStyle(reportTheme).getTextStyle(); + FRFont font = FRFont.getInstance(textStyle.getName(), textStyle.getCompositeFontStyle(), textStyle.getFontSize(), textStyle.getFontColor()); //每个预览格子通用的字体绘制 BaseUtils.drawStringStyleInRotation(g2d, getWidth(), getHeight(), this.value, Style.getInstance(font).deriveHorizontalAlignment(Constants.LEFT) diff --git a/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ControlPreviewPane.java b/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ControlPreviewPane.java index 110e6943c4..69a34fd3bc 100644 --- a/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ControlPreviewPane.java +++ b/designer-base/src/main/java/com/fr/widgettheme/theme/panel/ControlPreviewPane.java @@ -6,6 +6,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.theme.preview.ThemePreviewed; import com.fr.general.Background; +import com.fr.widgettheme.ThemePreviewTerminal; import javax.swing.JPanel; import java.awt.Color; @@ -42,9 +43,14 @@ public class ControlPreviewPane extends JPanel implements ThemePreviewed