diff --git a/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java b/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java new file mode 100644 index 000000000..d566bbf98 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java @@ -0,0 +1,82 @@ +package com.fr.design.cell; + +import com.fr.base.NameStyle; +import com.fr.base.ScreenResolution; +import com.fr.base.Style; +import com.fr.design.mainframe.theme.TemplateThemeBlock; +import com.fr.general.IOUtils; + +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JPanel; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Toolkit; + +/** + * @author Starryi + * @version 1.0 + * Created by Starryi on 2021/9/3 + */ +public class CellStylePreviewPane extends JPanel { + + private static final Image transparentBackgroundImage = Toolkit.getDefaultToolkit().createImage(CellStylePreviewPane.class.getResource("/com/fr/design/images/transparent_background.png")); + private final float transparentBackgroundWidth; + private final float transparentBackgroundHeight; + private final float transparentBackgroundAspect; + private String paintText = "Report"; + private Style style = Style.DEFAULT_STYLE; + + public CellStylePreviewPane() { + transparentBackgroundWidth = transparentBackgroundImage.getWidth(null); + transparentBackgroundHeight = transparentBackgroundImage.getHeight(null); + transparentBackgroundAspect = 1.0F * transparentBackgroundImage.getWidth(null) / transparentBackgroundImage.getHeight(null); + } + + public void setStyle(Style style) { + this.style = style; + if (style instanceof NameStyle) { + paintText = ((NameStyle) style).getName(); + } + repaint(); + } + + @Override + public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + int resolution = ScreenResolution.getScreenResolution(); + + int width = getWidth(); + int height = getHeight(); + + float scaleWidth = 1.0F * getWidth() / transparentBackgroundWidth; + float scaleHeight = 1.0F * getHeight() / transparentBackgroundHeight; + float maxScale = Math.max(scaleWidth, scaleHeight); + + if (maxScale <= 1) { + scaleWidth = scaleHeight = 1; + } else { + scaleHeight = scaleWidth = maxScale; + } + g2d.drawImage(transparentBackgroundImage, 0, 0, (int) (transparentBackgroundWidth * scaleWidth), (int) (transparentBackgroundHeight * scaleHeight), null); + + if (style == Style.DEFAULT_STYLE) { + // 如果是默认的style,就只写"Report"上去 + Style.paintContent(g2d, paintText, style, width, height, resolution); + return; + } + + Style.paintBackground(g2d, style, width, height); + + Style.paintContent(g2d, paintText, style, width, height, resolution); + + Style.paintBorder(g2d, style, getWidth() - 3, getHeight() - 3); + } + + @Override + public Dimension getMinimumSize() { + return getPreferredSize(); + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 4e0a8090e..8bb23786f 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -625,8 +625,6 @@ public abstract class JTemplate> */ public void redo() { this.getUndoManager().redo(); - // 重做前模版使用主题可能已经被删除或修改,需要重置模版样式 - checkAndResetTheme(); fireSuperTargetModified(); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeListPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeListPane.java index 524c272ac..493033512 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeListPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeListPane.java @@ -126,15 +126,17 @@ public class TemplateThemeListPane extends BasicPane { } private void setSelectedBlock(TemplateThemeBlock block) { - if (selectedBlock != null) { - selectedBlock.setSelected(false); - } - selectedBlock = block; - if (selectedBlock != null) { - selectedBlock.setSelected(true); - } - if (changeListener != null) { - changeListener.fireChanged(new ChangeEvent(this)); + if (selectedBlock != block) { + if (selectedBlock != null) { + selectedBlock.setSelected(false); + } + selectedBlock = block; + if (selectedBlock != null) { + selectedBlock.setSelected(true); + } + if (changeListener != null) { + changeListener.fireChanged(new ChangeEvent(this)); + } } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeUsingDialog.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeUsingDialog.java index 1d17bb4eb..e4f4b5fd2 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeUsingDialog.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeUsingDialog.java @@ -1,9 +1,8 @@ package com.fr.design.mainframe.theme.dialog; -import com.fr.base.theme.ThemedTemplate; import com.fr.base.theme.TemplateTheme; import com.fr.base.theme.TemplateThemeConfig; -import com.fr.design.base.mode.DesignModeContext; +import com.fr.base.theme.ThemedTemplate; import com.fr.design.event.ChangeEvent; import com.fr.design.event.ChangeListener; import com.fr.design.gui.ibutton.UIButton; @@ -11,7 +10,6 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.theme.TemplateThemeListPane; import com.fr.design.mainframe.theme.ui.BorderUtils; -import com.fr.stable.StringUtils; import com.fr.workspace.WorkContext; import javax.swing.BorderFactory; @@ -43,56 +41,27 @@ TemplateThemeUsingDialog extends TemplateThemeDialog { JPanel content = createContent(); UIButton openThemeManagerButton = createOpenThemeManagerButton(); - UIButton usingCurrentThemeButton = createUsingCurrentThemeButton(); UIButton completeButton = createCompleteButton(); setContentPane(createDialogContentPane(content, new UIButton[]{ openThemeManagerButton }, - new UIButton[]{ usingCurrentThemeButton, completeButton } + new UIButton[]{ completeButton } )); themeListPane.startListenThemeConfig(); - resetEnableCurrentThemeButton(themeListPane.getSelectedTheme(), usingCurrentThemeButton); themeListPane.setSelectedChangeListener(new ChangeListener() { @Override public void fireChanged(ChangeEvent event) { - resetEnableCurrentThemeButton(themeListPane.getSelectedTheme(), usingCurrentThemeButton); + TemplateTheme theme = themeListPane.getSelectedTheme(); + if (theme != null) { + currentTemplate.setTemplateTheme(theme); + themeListPane.repaint(); + } } }); } - private void resetEnableCurrentThemeButton(T selectedTheme, UIButton usingCurrentThemeButton) { - if (selectedTheme == null) { - usingCurrentThemeButton.setEnabled(false); - return; - } - String selectedThemeName = selectedTheme.getName(); - if (StringUtils.isEmpty(selectedThemeName)) { - usingCurrentThemeButton.setEnabled(false); - return; - } - - if (currentTemplate == null) { - usingCurrentThemeButton.setEnabled(false); - return; - } - - TemplateTheme templateUsingTheme = currentTemplate.getTemplateTheme(); - if (templateUsingTheme == null) { - usingCurrentThemeButton.setEnabled(true); - return; - } - - String templateUsingThemeName = templateUsingTheme.getName(); - if (StringUtils.isEmpty(templateUsingThemeName)) { - usingCurrentThemeButton.setEnabled(true); - return; - } - - usingCurrentThemeButton.setEnabled(!StringUtils.equals(templateUsingThemeName, selectedTheme.getName())); - } - private JPanel createContent() { JPanel container = FRGUIPaneFactory.createBorderLayout_S_Pane(); container.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); @@ -123,17 +92,6 @@ TemplateThemeUsingDialog extends TemplateThemeDialog { return null; } - private UIButton createUsingCurrentThemeButton() { - UIButton button = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Using_Dialog_Use")); - button.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - apply2CurrentTemplate(button); - } - }); - return button; - } - private UIButton createCompleteButton() { UIButton button = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Using_Dialog_Complete")); button.addActionListener(new ActionListener() { @@ -150,13 +108,4 @@ TemplateThemeUsingDialog extends TemplateThemeDialog { themeListPane.stopAsyncFetchTheme(); super.exit(); } - - private void apply2CurrentTemplate(UIButton usingCurrentThemeButton) { - TemplateTheme theme = themeListPane.getSelectedTheme(); - if (theme != null) { - currentTemplate.setTemplateTheme(theme); - themeListPane.repaint(); - usingCurrentThemeButton.setEnabled(false); - } - } } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/cell/CellStyleEditPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/cell/CellStyleEditPane.java index a2991a89f..53e4d9a91 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/cell/CellStyleEditPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/cell/CellStyleEditPane.java @@ -1,8 +1,7 @@ package com.fr.design.mainframe.theme.edit.cell; -import com.fr.base.ScreenResolution; -import com.fr.base.Style; import com.fr.base.theme.settings.ThemedCellStyle; +import com.fr.design.cell.CellStylePreviewPane; import com.fr.design.constants.UIConstants; import com.fr.design.dialog.AttrScrollPane; import com.fr.design.dialog.BasicPane; @@ -18,12 +17,9 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.theme.ui.BorderUtils; import javax.swing.BorderFactory; -import javax.swing.JComponent; import javax.swing.JPanel; import java.awt.BorderLayout; import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; import java.awt.GridLayout; import java.util.ArrayList; import java.util.List; @@ -39,7 +35,7 @@ import static com.fr.design.i18n.Toolkit.i18nText; */ public class CellStyleEditPane extends MultiTabPane { private ThemedCellStyle cellStyle; - private PreviewArea previewArea; + private CellStylePreviewPane previewArea; private boolean populating; private AttributeChangeListener attributeChangeListener; @@ -78,7 +74,7 @@ public class CellStyleEditPane extends MultiTabPane { for (BasicPane basicPane : paneList) { ((AbstractBasicStylePane) basicPane).populateBean(ob.getStyle()); - previewArea.preview(ob.getStyle()); + previewArea.setStyle(ob.getStyle()); } this.populating = false; } @@ -112,7 +108,8 @@ public class CellStyleEditPane extends MultiTabPane { jPanel.setLayout(new BorderLayout(0, 4)); JPanel previewPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - previewArea = new PreviewArea(); + previewArea = new CellStylePreviewPane(); + previewArea.setPreferredSize(new Dimension(223, 30)); previewPane.setBorder(BorderUtils.createTitleBorder(i18nText("Fine-Design_Basic_Preview"))); previewPane.add(previewArea, BorderLayout.CENTER); @@ -138,7 +135,7 @@ public class CellStyleEditPane extends MultiTabPane { } ThemedCellStyle cellStyle = updateBean(); if (cellStyle != null) { - previewArea.preview(cellStyle.getStyle()); + previewArea.setStyle(cellStyle.getStyle()); } fireAttrChangeListener(); } @@ -157,42 +154,4 @@ public class CellStyleEditPane extends MultiTabPane { @Override public void updateBean(ThemedCellStyle ob) {} - - private static class PreviewArea extends JComponent { - - private static final String paintText = "Report"; - private Style style = Style.DEFAULT_STYLE; - - public PreviewArea() { - setPreferredSize(new Dimension(223, 30)); - } - - public void preview(Style style) { - this.style = style; - repaint(); - } - - @Override - public void paintComponent(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - int resolution = ScreenResolution.getScreenResolution(); - - if (style == Style.DEFAULT_STYLE) { - // 如果是默认的style,就只写"Report"上去 - Style.paintContent(g2d, paintText, style, getWidth() - 3, getHeight() - 3, resolution); - return; - } - - Style.paintBackground(g2d, style, getWidth() - 3, getHeight() - 3); - - Style.paintContent(g2d, paintText, style, getWidth() - 3, getHeight() - 3, resolution); - - Style.paintBorder(g2d, style, getWidth() - 3, getHeight() - 3); - } - - @Override - public Dimension getMinimumSize() { - return getPreferredSize(); - } - } } diff --git a/designer-base/src/main/resources/com/fr/design/images/transparent_background.png b/designer-base/src/main/resources/com/fr/design/images/transparent_background.png new file mode 100644 index 000000000..cfb233f46 Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/transparent_background.png differ diff --git a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java index 04dd92243..9d03edbc0 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java @@ -664,9 +664,11 @@ public class JForm extends JTemplate implements BaseJForm implements BaseJForm implements BaseJForm { @Override protected void applyUndoState(WorkBookUndoState u) { try { - this.setTarget((WorkBook) u.getWorkBook().clone()); + WorkBook undoWorkBook = (WorkBook) u.getWorkBook().clone(); + undoWorkBook.checkAndResetTheme(); + this.setTarget(undoWorkBook); if (!DesignerMode.isAuthorityEditing()) { if (u.getAuthorityType() != BaseUndoState.NORMAL_STATE) { applyAll(u); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/StylePane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/StylePane.java index 93bf52397..e559cfaa4 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/StylePane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/StylePane.java @@ -7,7 +7,6 @@ import com.fr.design.dialog.BasicPane; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; import com.fr.design.gui.ibutton.UIButtonGroup; -import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; @@ -132,8 +131,7 @@ public class StylePane extends BasicPane implements UIObserver { uiLabel.setPreferredSize(new Dimension(uiLabel.getPreferredSize().width, 20)); container.add(uiLabel, BorderLayout.NORTH); themedCellStyleListPane.setBorder(BorderFactory.createEmptyBorder()); - UIScrollPane scrollPane = new UIScrollPane(themedCellStyleListPane); - container.add(scrollPane, BorderLayout.CENTER); + container.add(themedCellStyleListPane, BorderLayout.CENTER); return container; } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/ThemedCellStyleListPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/ThemedCellStyleListPane.java index 570d0d88d..17300f00d 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/ThemedCellStyleListPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/style/ThemedCellStyleListPane.java @@ -1,11 +1,11 @@ package com.fr.design.mainframe.cell.settingpane.style; import com.fr.base.NameStyle; -import com.fr.base.ScreenResolution; import com.fr.base.Style; import com.fr.base.theme.TemplateTheme; import com.fr.base.theme.settings.ThemedCellStyle; import com.fr.design.beans.FurtherBasicBeanPane; +import com.fr.design.cell.CellStylePreviewPane; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.i18n.Toolkit; @@ -17,7 +17,6 @@ import com.fr.general.ComparatorUtils; import javax.swing.BorderFactory; import javax.swing.DefaultListModel; -import javax.swing.JComponent; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.ListCellRenderer; @@ -26,8 +25,6 @@ import javax.swing.event.ChangeListener; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.Serializable; @@ -142,7 +139,7 @@ public class ThemedCellStyleListPane extends FurtherBasicBeanPane imp private static class RadioButtonListCellRenderer extends JPanel implements ListCellRenderer, Serializable { private final UIRadioButton button; - private final PreviewArea previewArea; + private final CellStylePreviewPane previewArea; public RadioButtonListCellRenderer() { super(); @@ -150,7 +147,7 @@ public class ThemedCellStyleListPane extends FurtherBasicBeanPane imp setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setPreferredSize(new Dimension(getPreferredSize().width, 40)); button = new UIRadioButton(); - previewArea = new PreviewArea(); + previewArea = new CellStylePreviewPane(); add(button, BorderLayout.WEST); add(previewArea, BorderLayout.CENTER); } @@ -162,41 +159,4 @@ public class ThemedCellStyleListPane extends FurtherBasicBeanPane imp return this; } } - - private static class PreviewArea extends JComponent { - - private String paintText = "Report"; - private Style style = Style.DEFAULT_STYLE; - - public void setStyle(Style style) { - this.style = style; - if (style instanceof NameStyle) { - paintText = ((NameStyle) style).getName(); - } - repaint(); - } - - @Override - public void paintComponent(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - int resolution = ScreenResolution.getScreenResolution(); - - if (style == Style.DEFAULT_STYLE) { - // 如果是默认的style,就只写"Report"上去 - Style.paintContent(g2d, paintText, style, getWidth() - 3, getHeight() - 3, resolution); - return; - } - - Style.paintBackground(g2d, style, getWidth() - 3, getHeight() - 3); - - Style.paintContent(g2d, paintText, style, getWidth() - 3, getHeight() - 3, resolution); - - Style.paintBorder(g2d, style, getWidth() - 3, getHeight() - 3); - } - - @Override - public Dimension getMinimumSize() { - return getPreferredSize(); - } - } } \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/report/ReportStylePane.java b/designer-realize/src/main/java/com/fr/design/report/ReportStylePane.java index 91b3641ff..94b18f969 100644 --- a/designer-realize/src/main/java/com/fr/design/report/ReportStylePane.java +++ b/designer-realize/src/main/java/com/fr/design/report/ReportStylePane.java @@ -1,9 +1,9 @@ package com.fr.design.report; import com.fr.base.NameStyle; -import com.fr.base.ScreenResolution; import com.fr.base.Style; import com.fr.design.border.UIRoundedBorder; +import com.fr.design.cell.CellStylePreviewPane; import com.fr.design.constants.UIConstants; import com.fr.design.designer.IntervalConstants; import com.fr.design.dialog.BasicPane; @@ -52,8 +52,6 @@ import java.awt.CardLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; @@ -66,7 +64,7 @@ public class ReportStylePane extends BasicPane { }; public static final int DEFAULT_SELECTED_INDEX = 0; - private final PreviewArea previewArea; + private final CellStylePreviewPane previewArea; private final UIButtonGroup followingThemeButtonGroup; private final CustomFloatStyleSettingPane customStylePane; private final ThemedCellStyleListPane themedCellStyleListPane; @@ -78,7 +76,7 @@ public class ReportStylePane extends BasicPane { setLayout(FRGUIPaneFactory.createBorderLayout()); setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); - previewArea = new PreviewArea(); + previewArea = new CellStylePreviewPane(); followingThemeButtonGroup = new UIButtonGroup<>(FOLLOWING_THEME_STRING_ARRAYS); customStylePane = new CustomFloatStyleSettingPane(); themedCellStyleListPane = new ThemedCellStyleListPane(); @@ -333,40 +331,6 @@ public class ReportStylePane extends BasicPane { previewArea.setStyle(updateBean()); } - private static class PreviewArea extends JComponent { - - private static final String paintText = "Report"; - private Style style = Style.DEFAULT_STYLE; - - public void setStyle(Style style) { - this.style = style; - repaint(); - } - - @Override - public void paintComponent(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - int resolution = ScreenResolution.getScreenResolution(); - - if (style == Style.DEFAULT_STYLE) { - // 如果是默认的style,就只写"Report"上去 - Style.paintContent(g2d, paintText, style, getWidth() - 3, getHeight() - 3, resolution); - return; - } - - Style.paintBackground(g2d, style, getWidth() - 3, getHeight() - 3); - - Style.paintContent(g2d, paintText, style, getWidth() - 3, getHeight() - 3, resolution); - - Style.paintBorder(g2d, style, getWidth() - 3, getHeight() - 3); - } - - @Override - public Dimension getMinimumSize() { - return getPreferredSize(); - } - } - private static class CustomFloatStyleSettingPane extends BasicPane implements ChangeListener { private static final int ALIGNMENT_INDEX = 1; private static final int FONT_INDEX = 2;