From 07be63cef322c072d22a16ae4048640b83b5b196 Mon Sep 17 00:00:00 2001 From: Starryi Date: Fri, 10 Dec 2021 16:39:53 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-64080=20=E3=80=90=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E8=BE=B9=E6=A1=86=E3=80=91=E6=A1=86=E9=80=89=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E5=A4=96=E8=BE=B9=E6=A1=86=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E6=A1=86=E9=80=89=E5=B0=8F=E9=83=A8=E5=88=86=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=EF=BC=8C=E4=B9=8B=E5=90=8E=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=99=A8=E9=87=8C=E6=98=BE=E7=A4=BA=E6=9C=89=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 重新规范下交互效果,当框选的单元格样式从跟随主题切换到自定义时, 单元格的样式效果应当保持不变(从NameStyle变为Style),且右侧样式 面板应当是此框选区域的整体样式 【改动思路】 当样式设置从跟随主题切换到自定义时,应当将被选择的单元格样式设置 从NameStyle设置为Style,且不能使用样式面板中的设置重置单元格样式 --- .../fr/design/mainframe/ElementCasePane.java | 30 ++++++++ .../cell/settingpane/CellStylePane.java | 74 +++++++++++++------ .../cell/settingpane/style/StylePane.java | 59 ++++++++++----- 3 files changed, 120 insertions(+), 43 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java b/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java index dbc4269d6..0a580badc 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java @@ -6,6 +6,7 @@ package com.fr.design.mainframe; import com.fr.base.BaseFormula; import com.fr.base.DynamicUnitList; import com.fr.base.Formula; +import com.fr.base.NameStyle; import com.fr.base.ScreenResolution; import com.fr.base.Style; import com.fr.base.vcs.DesignerMode; @@ -97,6 +98,7 @@ import com.fr.page.PageAttributeGetter; import com.fr.page.ReportPageAttrProvider; import com.fr.poly.creator.PolyElementCasePane; import com.fr.report.ReportHelper; +import com.fr.report.cell.CellElement; import com.fr.report.cell.FloatElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.cell.cellattr.core.RichText; @@ -133,6 +135,7 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.lang.reflect.Constructor; +import java.util.Iterator; import java.util.Set; import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; @@ -1374,6 +1377,33 @@ public abstract class ElementCasePane extends Tar return cellNeedTOFormat; } + public void traverseSelectedCellElements(TemplateCellElementVisitor visitor) { + Selection selection = getSelection(); + if (!(selection instanceof CellSelection)) { + return; + } + CellSelection cs = (CellSelection) selection; + TemplateElementCase elementCase = getEditingElementCase(); + int cellRectangleCount = cs.getCellRectangleCount(); + + for (int rect = 0; rect < cellRectangleCount; rect++) { + Rectangle cellRectangle = cs.getCellRectangle(rect); + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + + TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); + visitor.visit(column, row, cellElement); + } + } + } + } + + public interface TemplateCellElementVisitor { + void visit(int column, int row, TemplateCellElement cellElement); + } + private class ElementCaseEditingState implements EditingState { protected Selection selection; diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellStylePane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellStylePane.java index c28c00de5..24ea3209d 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellStylePane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellStylePane.java @@ -1,22 +1,23 @@ package com.fr.design.mainframe.cell.settingpane; import com.fr.base.CellBorderStyle; +import com.fr.base.NameStyle; import com.fr.base.Style; import com.fr.design.actions.utils.ReportActionUtils; import com.fr.design.constants.UIConstants; -import com.fr.design.gui.style.BorderPane; +import com.fr.design.mainframe.ElementCasePane; import com.fr.design.mainframe.cell.settingpane.style.StylePane; import com.fr.design.mainframe.theme.utils.DefaultThemedTemplateCellElementCase; import com.fr.design.style.BorderUtils; import com.fr.design.utils.gui.GUICoreUtils; - import com.fr.report.cell.TemplateCellElement; import com.fr.report.elementcase.TemplateElementCase; -import javax.swing.*; +import javax.swing.JFrame; +import javax.swing.JPanel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import java.awt.*; +import java.awt.BorderLayout; /** * @author zhou @@ -71,29 +72,56 @@ public class CellStylePane extends AbstractCellAttrPane { @Override public void updateBeans() { - Object[] selectionCellBorderObjects = BorderUtils.createCellBorderObject(elementCasePane); + // 因为存在框选多个单元格的情况,跟随主题切换到自定义的行为似乎不太适合由updateBeans完成,它更像是个工具栏上的Action. + // 但它又会触发updateBeans... + boolean isSwitchToCustomStyleAction = stylePane.isFollowingThemeSettingChanged() && !stylePane.isFollowingTheme(); + if (isSwitchToCustomStyleAction) { + switchCellStylesToCustom(); + return; + } + updateCellStylesByPaneSettings(); + } + + private void switchCellStylesToCustom() { TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); - int cellRectangleCount = cs.getCellRectangleCount(); - for (int rect = 0; rect < cellRectangleCount; rect++) { - Rectangle cellRectangle = cs.getCellRectangle(rect); - for (int j = 0; j < cellRectangle.height; j++) { - for (int i = 0; i < cellRectangle.width; i++) { - int column = i + cellRectangle.x; - int row = j + cellRectangle.y; - TemplateCellElement cellElement = elementCase.getTemplateCellElement(column, row); - if (cellElement == null) { - cellElement = DefaultThemedTemplateCellElementCase.createInstance(column, row); - elementCase.addCellElement(cellElement); - } - Style style = stylePane.updateBean(); - cellElement.setStyle(style); + elementCasePane.traverseSelectedCellElements(new ElementCasePane.TemplateCellElementVisitor() { + @Override + public void visit(int column, int row, TemplateCellElement cellElement) { + if (cellElement == null) { + cellElement = DefaultThemedTemplateCellElementCase.createInstance(column, row); + elementCase.addCellElement(cellElement); } + Style style = cellElement.getStyle(); + if (style instanceof NameStyle) { + style = ((NameStyle) style).getRealStyle(); + } + if (style == null) { + style = Style.DEFAULT_STYLE; + } + cellElement.setStyle(style); } - } + }); + } + + private void updateCellStylesByPaneSettings() { + Object[] oldSelectionCellBorderObjects = BorderUtils.createCellBorderObject(elementCasePane); + + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + elementCasePane.traverseSelectedCellElements(new ElementCasePane.TemplateCellElementVisitor() { + @Override + public void visit(int column, int row, TemplateCellElement cellElement) { + if (cellElement == null) { + cellElement = DefaultThemedTemplateCellElementCase.createInstance(column, row); + elementCase.addCellElement(cellElement); + } + Style style = stylePane.updateBean(); + cellElement.setStyle(style); + } + }); // border必须特别处理 - CellBorderStyle cellBorderStyle = stylePane.updateBorderStyle(); - if (cellBorderStyle != null) { - BorderUtils.update(elementCasePane, selectionCellBorderObjects, cellBorderStyle); + CellBorderStyle newCellBorderStyle = stylePane.updateBorderStyle(); + if (newCellBorderStyle != null) { + BorderUtils.update(elementCasePane, oldSelectionCellBorderObjects, newCellBorderStyle); } } 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 c6613befa..7f382ed44 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 @@ -51,6 +51,7 @@ public class StylePane extends BasicPane implements UIObserver { private final List observerListeners = new ArrayList<>(); private Style backupStyleFromPopulating = Style.DEFAULT_STYLE; + private boolean isFollowingThemeSettingChanged = false; public StylePane() { followingThemeButtonGroup = new UIButtonGroup<>(FOLLOWING_THEME_STRING_ARRAYS); @@ -77,6 +78,7 @@ public class StylePane extends BasicPane implements UIObserver { followingThemeButtonGroup.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { + isFollowingThemeSettingChanged = true; AttributeChangeUtils.changeComposedUI(StylePane.this, false, new AttributeChangeUtils.UIChangeAction() { @Override public void changeComposedUI() { @@ -85,6 +87,7 @@ public class StylePane extends BasicPane implements UIObserver { } }); fireStateChanged(); + isFollowingThemeSettingChanged = false; } }); @@ -103,25 +106,33 @@ public class StylePane extends BasicPane implements UIObserver { cardLayout.show(contentPane, FOLLOWING_THEME_STRING_ARRAYS[selectedIndex]); if (!isFollowingTheme) { // 对于同一个单元格,跟随主题切换到自定义,自定义中的配置与其保持一致 - NameStyle lastSelectedNameStyle = nameStyleListPane.updateNameStyle(); - if (lastSelectedNameStyle != null) { - Style lastSelectedRealStyle = lastSelectedNameStyle.getRealStyle(); - try { - lastSelectedRealStyle = (Style) lastSelectedRealStyle.clone(); - if (lastSelectedRealStyle != null) { - customStylePane.populateBean(lastSelectedRealStyle); - customStylePane.dealWithBorder(); - } - } catch (CloneNotSupportedException ex) { - FineLoggerFactory.getLogger().error(ex.getMessage(), ex); - } - } + syncCustomStylePaneBySelectedNameStyle(); } else { // 对于同一个单元格,自定义切换到跟随主题,跟随主题选中"默认"样式,并使用默认样式设置选中的单元格 nameStyleListPane.reset(); } } + private void syncCustomStylePaneBySelectedNameStyle() { + NameStyle lastSelectedNameStyle = nameStyleListPane.updateNameStyle(); + if (lastSelectedNameStyle != null) { + Style lastSelectedRealStyle = lastSelectedNameStyle.getRealStyle(); + try { + lastSelectedRealStyle = (Style) lastSelectedRealStyle.clone(); + if (lastSelectedRealStyle != null) { + customStylePane.populateBean(lastSelectedRealStyle); + customStylePane.dealWithBorder(); + } + } catch (CloneNotSupportedException ex) { + FineLoggerFactory.getLogger().error(ex.getMessage(), ex); + } + } + } + + public boolean isFollowingThemeSettingChanged() { + return isFollowingThemeSettingChanged; + } + protected JPanel createTabbedContentPane() { JPanel contentPane = new JPanel(cardLayout) { @Override @@ -161,14 +172,22 @@ public class StylePane extends BasicPane implements UIObserver { return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style"); } - public void setSelectedIndex(int index) { + public boolean isFollowingTheme() { + return getSelectedIndex() == 0; + } + + public void setFollowingTheme(boolean followingTheme) { + setSelectedIndex(followingTheme ? 0 : 1); + } + + private void setSelectedIndex(int index) { if (0 <= index && index < FOLLOWING_THEME_STRING_ARRAYS.length) { followingThemeButtonGroup.setSelectedIndex(index); cardLayout.show(contentPane, FOLLOWING_THEME_STRING_ARRAYS[index]); } } - public int getSelectedIndex() { + private int getSelectedIndex() { return followingThemeButtonGroup.getSelectedIndex(); } @@ -185,11 +204,11 @@ public class StylePane extends BasicPane implements UIObserver { } public void setSelctedByName(String id) { - setSelectedIndex(ComparatorUtils.equals(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom"), id)? 1 : 0); + setFollowingTheme(!ComparatorUtils.equals(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom"), id)); } public CellBorderStyle updateBorderStyle() { - if (getSelectedIndex() == 0) { + if (isFollowingTheme()) { return nameStyleListPane.updateBorderStyle(); } else if (customStylePane.isBorderPaneSelected()) { return customStylePane.updateBorderStyle(); @@ -199,7 +218,7 @@ public class StylePane extends BasicPane implements UIObserver { public Style updateBean() { Style finalStyle = null; - if (getSelectedIndex() == 0) { + if (isFollowingTheme()) { finalStyle = nameStyleListPane.updateNameStyle(); } if (finalStyle == null) { @@ -215,7 +234,7 @@ public class StylePane extends BasicPane implements UIObserver { if (style instanceof NameStyle) { NameStyle nameStyle = (NameStyle) style; - setSelectedIndex(0); + setFollowingTheme(true); nameStyleListPane.populateNameStyle(nameStyle); Style realStyle = nameStyle.getRealStyle(); try { @@ -225,7 +244,7 @@ public class StylePane extends BasicPane implements UIObserver { e.printStackTrace(); } } else { - setSelectedIndex(1); + setFollowingTheme(false); customStylePane.populateBean(style); } //单元格配置界面是单例 所以直接在populate的时候把跟随主题的按钮组设置不可见