From 6d1ffd15fa7bab6fa3828fd548799cdf4a06280c Mon Sep 17 00:00:00 2001 From: kuangshuai Date: Fri, 22 Oct 2021 11:51:10 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-61207=20=E5=BC=95=E5=AF=BC=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=AD=97=E4=BD=93=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=AF=B9?= =?UTF-8?q?=E4=B8=94=E8=A2=AB=E6=88=AA=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guide/ui/GuideCompleteDialog.java | 21 ++++---------- .../guide/ui/GuideLoadingGlassPane.java | 2 +- .../guide/ui/bubble/BubbleWithClose.java | 25 ++++------------- .../mainframe/guide/utils/GuideUIUtils.java | 28 +++++++++++++++++++ 4 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/guide/utils/GuideUIUtils.java diff --git a/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideCompleteDialog.java b/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideCompleteDialog.java index b90c5718c..1d5b907e3 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideCompleteDialog.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideCompleteDialog.java @@ -7,6 +7,7 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.guide.utils.GuideUIUtils; import com.fr.design.utils.gui.GUIPaintUtils; import com.fr.general.IOUtils; @@ -14,9 +15,7 @@ import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JDialog; import javax.swing.JPanel; -import javax.swing.JTextPane; import javax.swing.SwingConstants; -import javax.swing.text.MutableAttributeSet; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; @@ -37,9 +36,9 @@ public class GuideCompleteDialog extends JDialog { private static final int ICON_HEIGHT = 182; private static final Color FONT_COLOR = new Color(51, 51, 52); private static final Color BUTTON_BG_COLOR = new Color(65, 155,249); - private static final Font TITLE_FONT = new Font(Font.SANS_SERIF, Font.BOLD, 22); - private static final Font CONTENT_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 18); - private static final Font BUTTON_FONT = new Font(Font.SANS_SERIF, Font.BOLD, 14); + private static final Font TITLE_FONT = new Font("Default", Font.BOLD, 22); + private static final Font CONTENT_FONT = new Font("Default", Font.PLAIN, 18); + private static final Font BUTTON_FONT = new Font("Default", Font.BOLD, 14); private static GuideCompleteDialog dialog; public static GuideCompleteDialog getInstance() { @@ -78,12 +77,11 @@ public class GuideCompleteDialog extends JDialog { title.setForeground(FONT_COLOR); textArea = new UITextPane(); - changeLineSpacing(textArea, 0.15f,false); + textArea.setFont(CONTENT_FONT); + GuideUIUtils.setTextPaneLineHeight(textArea, 26); textArea.setEnabled(false); textArea.setOpaque(false); - textArea.setFont(CONTENT_FONT); textArea.setPreferredSize(new Dimension(236, 52)); - textArea.setBorder(null); textArea.setDisabledTextColor(FONT_COLOR); StyledDocument doc = textArea.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); @@ -141,11 +139,4 @@ public class GuideCompleteDialog extends JDialog { } } }; - - private void changeLineSpacing(JTextPane pane, float factor, boolean replace) { - pane.selectAll(); - MutableAttributeSet set = new SimpleAttributeSet(pane.getParagraphAttributes()); - StyleConstants.setLineSpacing(set, factor); - pane.setParagraphAttributes(set, replace); - } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingGlassPane.java b/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingGlassPane.java index 47a10d0be..44590540d 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingGlassPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/GuideLoadingGlassPane.java @@ -40,7 +40,7 @@ public class GuideLoadingGlassPane extends JPanel { imageContainer.add(GuideLoadingPane.getInstance()); UILabel hintLabel = new UILabel(Toolkit.i18nText("Fine-Design_Guide_Loading_Wait")); - hintLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14)); + hintLabel.setFont(new Font("Default", Font.PLAIN, 14)); hintLabel.setHorizontalAlignment(SwingConstants.CENTER); hintLabel.setForeground(Color.WHITE); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/bubble/BubbleWithClose.java b/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/bubble/BubbleWithClose.java index 62e0ed65d..6851c09cd 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/bubble/BubbleWithClose.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/guide/ui/bubble/BubbleWithClose.java @@ -4,12 +4,12 @@ package com.fr.design.mainframe.guide.ui.bubble; import com.fr.base.GraphHelper; import com.fr.design.gui.frpane.UITextPane; import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.mainframe.guide.utils.GuideUIUtils; import com.fr.general.IOUtils; import com.fr.stable.StringUtils; import javax.swing.Icon; import javax.swing.JTextPane; -import javax.swing.text.MutableAttributeSet; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; @@ -32,8 +32,8 @@ import java.text.AttributedCharacterIterator; import java.text.AttributedString; public class BubbleWithClose extends Bubble { - private static final Font TITLE_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 14); - private static final Font CONTENT_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 12); + private static final Font TITLE_FONT = new Font("Default", Font.PLAIN, 14); + private static final Font CONTENT_FONT = new Font("Default", Font.PLAIN, 12); private static final int TITLE_LINE_HEIGHT = 22; private static final int CONTENT_LINE_HEIGHT = 18; @@ -157,33 +157,18 @@ public class BubbleWithClose extends Bubble { } private UITextPane createTextArea(String str, Font font, int lineHeight, Color foreground) { - int lineSpace = lineHeight - font.getSize(); - UITextPane textArea= new UITextPane(){ - @Override - public Insets getInsets() { - return new Insets(lineSpace / 2 - 1, 0, lineSpace / 2, 0); - } - }; + UITextPane textArea= new UITextPane(); textArea.setFont(font); - changeLineSpacing(textArea, lineHeight, true); + GuideUIUtils.setTextPaneLineHeight(textArea, lineHeight); textArea.setEditable(false); textArea.setForeground(foreground); textArea.setDisabledTextColor(foreground); - textArea.setBorder(null); textArea.setOpaque(false); textArea.setText(str); highlightText(textArea); return textArea; } - private void changeLineSpacing(JTextPane pane, int lineHeight, boolean replace) { - pane.selectAll(); - MutableAttributeSet set = new SimpleAttributeSet(pane.getParagraphAttributes()); - FontMetrics fontMetrics = GraphHelper.getFontMetrics(pane.getFont()); - StyleConstants.setLineSpacing(set, (float)(lineHeight - fontMetrics.getHeight()) / fontMetrics.getHeight()); - pane.setParagraphAttributes(set, replace); - } - private void highlightText(JTextPane textArea) { SimpleAttributeSet sas = new SimpleAttributeSet(); StyleConstants.setForeground(sas, HIGHLIGHT_COLOR); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/guide/utils/GuideUIUtils.java b/designer-base/src/main/java/com/fr/design/mainframe/guide/utils/GuideUIUtils.java new file mode 100644 index 000000000..bd6ee3310 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/guide/utils/GuideUIUtils.java @@ -0,0 +1,28 @@ +package com.fr.design.mainframe.guide.utils; + +import com.fr.base.GraphHelper; + +import javax.swing.BorderFactory; +import javax.swing.JTextPane; +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import java.awt.FontMetrics; +import java.awt.Insets; + +public class GuideUIUtils { + public static void setTextPaneLineHeight(JTextPane pane, int lineHeight) { + pane.selectAll(); + pane.setMargin(new Insets(0,0,0,0)); + MutableAttributeSet set = new SimpleAttributeSet(pane.getParagraphAttributes()); + FontMetrics fontMetrics = GraphHelper.getFontMetrics(pane.getFont()); + int delta = (lineHeight - fontMetrics.getHeight()) / 2 * 2 ; + if (delta > 0) { + StyleConstants.setLineSpacing(set, delta/ 2.0f / fontMetrics.getHeight()); + pane.setParagraphAttributes(set, false); + int dis = fontMetrics.getDescent() - fontMetrics.getLeading(); + int marginTop = dis > 0 ? ((delta - dis) / 2 + dis) : ((delta - dis) / 2); + pane.setBorder(BorderFactory.createEmptyBorder(marginTop, 0,0,0)); + } + } +}