From c564a875cf7b4bb24eb86aa93cf73b7e0995be58 Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 10 Jun 2022 11:39:31 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-73262=E3=80=90=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E7=8E=AF=E5=A2=83=E7=9B=91=E6=B5=8B=E3=80=91=E5=8F=B3?= =?UTF-8?q?=E4=B8=8B=E8=A7=92=E5=BC=B9=E7=AA=97=E6=96=87=E5=AD=97=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E5=85=A8=20=E6=B5=8B=E8=AF=95=E5=8F=B3?= =?UTF-8?q?=E4=B8=8B=E8=A7=92=E5=BC=B9=E7=AA=97=E6=96=87=E5=AD=97=E7=9A=84?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/NotificationDialog.java | 22 +++++++++++++++---- .../notification/NotificationDialogTest.java | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/components/notification/NotificationDialog.java b/designer-base/src/main/java/com/fr/design/components/notification/NotificationDialog.java index 5956cc9e33..05a3149b80 100644 --- a/designer-base/src/main/java/com/fr/design/components/notification/NotificationDialog.java +++ b/designer-base/src/main/java/com/fr/design/components/notification/NotificationDialog.java @@ -32,6 +32,7 @@ import java.awt.event.MouseEvent; import java.net.URI; import java.util.Arrays; import java.util.List; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -151,18 +152,31 @@ public class NotificationDialog extends JDialog { } return new UILabel(LinkStrUtils.generateHtmlTag(messageModel.format())); }) + .collect(Collectors.toList()); + + Function calStandardWidth = e -> e > 4 ? 280 : 300; + + int widthUnit = messageComponents.stream() + .map((component) -> { + Dimension preferredSize = component.getPreferredSize(); + return preferredSize.getHeight(); + }) + .reduce(Double::sum) + .map(calStandardWidth) + .orElse(300); + + messageComponents = messageComponents.stream() .peek((component) -> { Dimension preferredSize = component.getPreferredSize(); double componentWidth = preferredSize.getWidth(); double componentHeight = preferredSize.getHeight(); - double widthFactor = Math.ceil(componentWidth / 300); double heightFactor = Math.ceil(componentHeight / 15); + double widthFactor = Math.ceil(componentWidth / widthUnit); int realHeight = (int) (heightFactor + widthFactor - 1) * 15; - component.setPreferredSize(new Dimension(300, realHeight)); - + component.setPreferredSize(new Dimension(widthUnit, realHeight)); }) .collect(Collectors.toList()); - + // 竖向排列 JPanel messageSummaryPanel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, VerticalFlowLayout.TOP, 0, 0); messageComponents.forEach(messageSummaryPanel::add); diff --git a/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java b/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java index 1536dd2622..b4ae293979 100644 --- a/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java +++ b/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java @@ -31,7 +31,7 @@ public class NotificationDialogTest { public void run(Object... args) { System.out.println("1111"); } - }, new NotificationMessage.LinkMessage("1111 2222 33333333 4444 555 6666 66555 888 999 333
3333", ""),new NotificationMessage.LinkMessage("display model2 test", "abc")); + }, new NotificationMessage.LinkMessage("1111 2222 33333333 4444 555 6666 66555 888 999 333
3333
444
555
", ""),new NotificationMessage.LinkMessage("display model2 test", "abc")); NotificationDialogProperties properties = new NotificationDialogProperties(frame, "test"); NotificationDialog dialog = new NotificationDialog(properties, Lists.newArrayList(model1, model2));