From f539d9293a904db0449e11a6afa6ba59d4a74151 Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 10 Jun 2022 18:19:01 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-73403=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=91jar?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=BC=B9=E7=AA=97=EF=BC=8C%FR=5FHOME%\lib?= =?UTF-8?q?=E5=92=8C\WEB-INF\lib=E4=B8=8B=E7=9A=84jar=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E6=98=BE=E7=A4=BA=20=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E9=AD=94=E6=9C=AF=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/NotificationDialog.java | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 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 14fb6d007d..4df430b06c 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 @@ -44,8 +44,26 @@ import java.util.stream.Collectors; **/ public class NotificationDialog extends JDialog { - private Dimension contentSize = new Dimension(300, 100); - private Dimension buttonDimension = new Dimension(68, 20); + /** + * 通知框的内部高度 + */ + private static final int CONTENT_INNER_HEIGHT = 60; + /** + * 通知框如果出现滚动条后的内部宽度 + */ + private static final int CONTENT_SCROLL_WIDTH = 280; + + private static final int CONTENT_WIDTH = 300; + private static final int CONTENT_HEIGHT = 100; + /** + * 通知框的外部宽高 + */ + private static final Dimension CONTENT_SIZE = new Dimension(CONTENT_WIDTH, CONTENT_HEIGHT); + private static final Dimension BUTTON_DIMENSION = new Dimension(68, 20); + + private static final UILabel SIGN_LABEL = new UILabel("#"); + + private static final Dimension SIGN_LABEL_DIMENSION = SIGN_LABEL.getPreferredSize(); private NotificationDialogProperties properties; @@ -154,9 +172,9 @@ public class NotificationDialog extends JDialog { }) .collect(Collectors.toList()); - // 当高度 / 15(每个字的大小) 大于 4 时,就会出现滚动条。 + // 当高度 大于 60 时,就会出现滚动条。 // 当出现滚动条时,需要将内部的宽度限制为 280, 否则会展示不出来 - Function calStandardWidth = heightFactor -> heightFactor > 4 ? 280 : 300; + Function calStandardWidth = height -> height > CONTENT_INNER_HEIGHT ? CONTENT_SCROLL_WIDTH : CONTENT_WIDTH; int widthUnit = messageComponents.stream() .map((component) -> { @@ -165,16 +183,17 @@ public class NotificationDialog extends JDialog { }) .reduce(Double::sum) .map(calStandardWidth) - .orElse(300); + .orElse(CONTENT_WIDTH); messageComponents = messageComponents.stream() .peek((component) -> { + int size = component.getFont().getSize(); Dimension preferredSize = component.getPreferredSize(); double componentWidth = preferredSize.getWidth(); double componentHeight = preferredSize.getHeight(); - double heightFactor = Math.ceil(componentHeight / 15); + double heightFactor = Math.ceil(componentHeight / SIGN_LABEL_DIMENSION.getHeight()); double widthFactor = Math.ceil(componentWidth / widthUnit); - int realHeight = (int) (heightFactor + widthFactor - 1) * 15; + int realHeight = (int)Math.ceil(heightFactor + widthFactor - 1) * (int)(Math.ceil(SIGN_LABEL_DIMENSION.getHeight())); component.setPreferredSize(new Dimension(widthUnit, realHeight)); }) .collect(Collectors.toList()); @@ -187,7 +206,7 @@ public class NotificationDialog extends JDialog { jScrollPane.setBorder(BorderFactory.createEmptyBorder()); centerPanel.add(jScrollPane, BorderLayout.CENTER); - centerPanel.setPreferredSize(contentSize); + centerPanel.setPreferredSize(CONTENT_SIZE); contentPanel.add(centerPanel, BorderLayout.CENTER); @@ -256,7 +275,7 @@ public class NotificationDialog extends JDialog { NotificationAction action = currentModel.getAction(); if (action != null) { UIButton actionButton = new UIButton(action.name()); - actionButton.setPreferredSize(buttonDimension); + actionButton.setPreferredSize(BUTTON_DIMENSION); actionButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -267,7 +286,7 @@ public class NotificationDialog extends JDialog { } UIButton knowButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Know")); - knowButton.setPreferredSize(buttonDimension); + knowButton.setPreferredSize(BUTTON_DIMENSION); knowButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {