From 3389d16af77ff3dc7d36e42c6a3693081f4bb23a Mon Sep 17 00:00:00 2001 From: Starryi Date: Thu, 9 Dec 2021 10:49:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-63760=20=E3=80=90=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E3=80=91=E6=92=A4=E9=94=80=E4=BB=A5=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E6=A0=B7=E5=BC=8F=E8=AE=BE=E7=BD=AE=E6=9C=89=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20&=20REPORT-64006=20=E3=80=90=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E3=80=91=E5=8D=95=E5=85=83=E6=A0=BC=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=A0=B7=E5=BC=8F=E8=83=8C=E6=99=AF=E8=89=B2?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=8D=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 ColorBackgroundQuickPane注册监听器ChangeListenerImpl的逻辑不 能丢,因为里面有修改字段backgroundChange的逻辑.所以在监听器重复注 册以及UndoState重复生成时,应该保留ChangeListenerImpl, 而放弃 NewColorSelectBox内部自己注册ChangeListener. 【改动思路】 同上 --- .../ColorBackgroundQuickPane.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java b/designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java index 88bedf17c..9d9eb0058 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java @@ -19,7 +19,17 @@ public class ColorBackgroundQuickPane extends BackgroundQuickPane { public ColorBackgroundQuickPane() { this.setLayout(FRGUIPaneFactory.createBorderLayout()); - colorSelectBox = new NewColorSelectBox(100); + colorSelectBox = new NewColorSelectBox(100) { + @Override + public boolean shouldResponseChangeListener() { + // ColorBackgroundQuickPane注册监听器ChangeListenerImpl的逻辑不能丢,因为里面有修改字段backgroundChange的逻辑. + // 所以在监听器重复注册以及UndoState重复生成时,应该保留ChangeListenerImpl, 而放弃NewColorSelectBox内部自己注册 + // ChangeListener + // REPORT-63760 【主题切换】撤销以后,样式设置有问题 + // REPORT-64006 【模板主题】单元格自定义样式背景色设置不生效 + return false; + } + }; this.add(colorSelectBox, BorderLayout.NORTH); } @@ -41,14 +51,10 @@ public class ColorBackgroundQuickPane extends BackgroundQuickPane { } @Override - public boolean shouldResponseChangeListener() { - // NewColorSelectBox实现了UIObserver接口,这里就不要重复注册监听器了,以避免产生重复UndoState. - return false; + public void registerChangeListener(final UIObserverListener listener) { + this.colorSelectBox.addSelectChangeListener(new ChangeListenerImpl(listener)); } - @Override - public void registerChangeListener(final UIObserverListener listener) { } - @Override /** * 是否为ColorBackground 类型 From 100d24c16cc297feff52dbde0f9522eaaad14d10 Mon Sep 17 00:00:00 2001 From: Starryi Date: Thu, 9 Dec 2021 16:08:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-64005=20=E3=80=90=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E8=BE=B9=E6=A1=86=E3=80=91=E5=8D=95=E5=85=83=E6=A0=BC=E7=9A=84?= =?UTF-8?q?=E9=AB=98=E5=BA=A6=E6=B2=A1=E6=9C=89=E8=87=AA=E9=80=82=E5=BA=94?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 单元格样式预览面板自适应内容高度 【改动思路】 同上 --- .../cell/CellRectangleStylePreviewPane.java | 23 +++++++++- .../fr/design/cell/CellStylePreviewPane.java | 45 ++++++++++++++++++- .../theme/ThemedCellStyleListPane.java | 7 ++- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java b/designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java index bde6b1371..c87199beb 100644 --- a/designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java @@ -73,7 +73,26 @@ public class CellRectangleStylePreviewPane extends JPanel { } @Override - public Dimension getMinimumSize() { - return getPreferredSize(); + public void setPreferredSize(Dimension preferredSize) { + super.setPreferredSize(preferredSize); + int hw = preferredSize.width / 2; + int hh = preferredSize.height / 2; + cellStylePreviewPaneGrid[0][0].setPreferredSize(new Dimension(hw, hh)); + cellStylePreviewPaneGrid[0][1].setPreferredSize(new Dimension(hw, hh)); + cellStylePreviewPaneGrid[1][0].setPreferredSize(new Dimension(hw, hh)); + cellStylePreviewPaneGrid[1][1].setPreferredSize(new Dimension(hw, hh)); + } + + @Override + public Dimension getPreferredSize() { + Dimension d00 = cellStylePreviewPaneGrid[0][0].getPreferredSize(); + Dimension d01 = cellStylePreviewPaneGrid[0][1].getPreferredSize(); + Dimension d10 = cellStylePreviewPaneGrid[1][0].getPreferredSize(); + Dimension d11 = cellStylePreviewPaneGrid[1][1].getPreferredSize(); + + int width = Math.max(d00.width + d01.width, d10.width + d11.width); + int height = Math.max(d00.height + d10.height, d01.height + d11.height); + + return new Dimension(width, height); } } 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 index 885d3e8e1..8495aa6ec 100644 --- a/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java @@ -1,19 +1,26 @@ package com.fr.design.cell; +import com.fr.base.BaseUtils; +import com.fr.base.GraphHelper; import com.fr.base.NameStyle; import com.fr.base.ScreenResolution; import com.fr.base.Style; +import com.fr.general.FRFont; import com.fr.general.IOUtils; +import com.fr.stable.unit.PT; import javax.swing.JPanel; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Composite; import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; +import java.util.List; /** * @author Starryi @@ -22,6 +29,7 @@ import java.awt.image.BufferedImage; */ public class CellStylePreviewPane extends JPanel { + public static final int MINIMUM_HEIGHT = 40; private static final BufferedImage transparentBackgroundImage = IOUtils.readImage("/com/fr/design/images/transparent_background.png"); private final float transparentBackgroundWidth; private final float transparentBackgroundHeight; @@ -31,6 +39,7 @@ public class CellStylePreviewPane extends JPanel { public CellStylePreviewPane() { transparentBackgroundWidth = transparentBackgroundImage.getWidth(null); transparentBackgroundHeight = transparentBackgroundImage.getHeight(null); + setPreferredSize(new Dimension(0, 0)); } public void setPaintText(String paintText) { @@ -118,7 +127,39 @@ public class CellStylePreviewPane extends JPanel { } @Override - public Dimension getMinimumSize() { - return getPreferredSize(); + public Dimension getPreferredSize() { + Dimension size = super.getPreferredSize(); + int width = size.width; + int height = size.height; + + if (height != 0) { + // 使用者设置了一个高度 + return size; + } else if (width == 0) { + // 使用者未设置任何尺寸 + return new Dimension(width, MINIMUM_HEIGHT); + } else { + // 使用者设置了宽度,但未设置高度 + return getAutoWrapContentPreferredSize(width, height); + } + } + + private Dimension getAutoWrapContentPreferredSize(int width, int height) { + int resolution = ScreenResolution.getScreenResolution(); + + // 计算文本区域高度 + final FRFont frFont = style.getFRFont(); + final Font rfont = frFont.applyResolutionNP(resolution); + final FontMetrics metrics = GraphHelper.getFontMetrics(rfont); + final int textLineHeight = metrics.getHeight(); + final double textLineSpacing = PT.pt2pix(style.getLineSpacing(), resolution); + + List textLineList = BaseUtils.getLineTextList(paintText, style, rfont, height, width, resolution); + + double textLinesHeight = textLineList.size() * textLineHeight + Math.max(0, textLineList.size() - 1) * textLineSpacing; + + height = (int) Math.max(MINIMUM_HEIGHT, textLinesHeight); + + return new Dimension(width, height); } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedCellStyleListPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedCellStyleListPane.java index 53838d1c7..ae8c4910c 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedCellStyleListPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedCellStyleListPane.java @@ -149,7 +149,6 @@ public class ThemedCellStyleListPane extends FurtherBasicBeanPane