Browse Source

REPORT-41492 jdk11设计器默认字体有不一致的情况

final/10.0
vito 4 years ago
parent
commit
578d4145bc
  1. 10
      designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java
  2. 27
      designer-base/src/main/java/com/fr/design/utils/DesignUtils.java

10
designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java

@ -3,11 +3,12 @@ package com.fr.design.gui.iprogressbar;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.dialog.UIDialog; import com.fr.design.dialog.UIDialog;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.stable.os.support.OSBasedAction;
import com.fr.stable.os.support.OSSupportCenter;
import com.fr.design.os.impl.SupportOSImpl; import com.fr.design.os.impl.SupportOSImpl;
import com.fr.design.utils.DesignUtils;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.FRFont; import com.fr.general.FRFont;
import com.fr.stable.os.support.OSBasedAction;
import com.fr.stable.os.support.OSSupportCenter;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JLabel; import javax.swing.JLabel;
@ -57,7 +58,10 @@ public class ProgressDialog extends UIDialog {
progressBar.setMaximum(1000); progressBar.setMaximum(1000);
panel.add(progressBar, BorderLayout.CENTER); panel.add(progressBar, BorderLayout.CENTER);
text = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Loading_Project"), JLabel.CENTER); text = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Loading_Project"), JLabel.CENTER);
FRFont font = FRFont.getInstance().applySize(14).applyForeground(new ColorUIResource(333334)); FRFont font = DesignUtils
.getDefaultGUIFont()
.applySize(14)
.applyForeground(new ColorUIResource(333334));
text.setFont(font); text.setFont(font);
panel.add(text, BorderLayout.SOUTH); panel.add(text, BorderLayout.SOUTH);
panel.setVisible(true); panel.setVisible(true);

27
designer-base/src/main/java/com/fr/design/utils/DesignUtils.java

@ -8,6 +8,7 @@ import com.fr.design.ExtraDesignClassManager;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.fun.DesignerEnvProcessor;
import com.fr.design.gui.UILookAndFeel; import com.fr.design.gui.UILookAndFeel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.exit.DesignerExiter; import com.fr.exit.DesignerExiter;
import com.fr.file.FileFILE; import com.fr.file.FileFILE;
@ -21,7 +22,9 @@ import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.os.OperatingSystem; import com.fr.stable.os.OperatingSystem;
import com.fr.start.ServerStarter; import com.fr.start.ServerStarter;
import com.fr.value.NotNullLazyValue;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import org.jetbrains.annotations.NotNull;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
@ -248,6 +251,7 @@ public class DesignUtils {
// 刷新DesignerFrame里面的面板 // 刷新DesignerFrame里面的面板
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() { public void run() {
if (DesignerContext.getDesignerFrame() == null) { if (DesignerContext.getDesignerFrame() == null) {
return; return;
@ -269,7 +273,7 @@ public class DesignUtils {
FineLoggerFactory.getLogger().error("Substance Raven Graphite failed to initialize"); FineLoggerFactory.getLogger().error("Substance Raven Graphite failed to initialize");
} }
//获取当前系统语言下设计器用的默认字体 //获取当前系统语言下设计器用的默认字体
FRFont guiFRFont = getCurrentLocaleFont(); FRFont guiFRFont = getDefaultGUIFont();
//指定UIManager中字体 //指定UIManager中字体
Enumeration keys = UIManager.getDefaults().keys(); Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) { while (keys.hasMoreElements()) {
@ -286,11 +290,21 @@ public class DesignUtils {
} }
/** /**
* 获取当前系统语言下设计器用的默认字体 * 获取当前系统语言下设计器界面使用的默认字体
* *
* @return 默认字体 * @return 默认字体
*/ */
private static FRFont getCurrentLocaleFont() { public static FRFont getDefaultGUIFont() {
return CURRENT_LOCALE_FONT.getValue();
}
/**
* 获取当前系统语言下设计器用的默认字体
*/
private static final NotNullLazyValue<FRFont> CURRENT_LOCALE_FONT = new NotNullLazyValue<FRFont>() {
@NotNull
@Override
protected FRFont compute() {
FRFont guiFRFont; FRFont guiFRFont;
Locale defaultLocale = Locale.getDefault(); Locale defaultLocale = Locale.getDefault();
// JDK9 之后宋体在计算label中字母的空间上出现问题,暂时先用雅黑兼容,以后再统一字体 // JDK9 之后宋体在计算label中字母的空间上出现问题,暂时先用雅黑兼容,以后再统一字体
@ -302,9 +316,7 @@ public class DesignUtils {
guiFRFont = getNamedFont("Dialog"); guiFRFont = getNamedFont("Dialog");
} }
//先初始化的设计器locale, 后初始化lookandfeel.如果顺序改了, 这边也要调整. String file = Toolkit.i18nText("Fine-Design_Basic_File");
Locale designerLocale = GeneralContext.getLocale();
String file = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_File");
char displayChar = file.charAt(0); char displayChar = file.charAt(0);
if (!guiFRFont.canDisplay(displayChar)) { if (!guiFRFont.canDisplay(displayChar)) {
//如果不能用默认的语言显示字体, 比如想在英文系统里用中文设计器 //如果不能用默认的语言显示字体, 比如想在英文系统里用中文设计器
@ -314,13 +326,14 @@ public class DesignUtils {
//比如想在中文或英文系统里用韩文设计器 //比如想在中文或英文系统里用韩文设计器
guiFRFont = getNamedFont("Dialog"); guiFRFont = getNamedFont("Dialog");
if (!guiFRFont.canDisplay(displayChar)) { if (!guiFRFont.canDisplay(displayChar)) {
FineLoggerFactory.getLogger().error(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Base_SimSun_Not_Found")); FineLoggerFactory.getLogger().error(Toolkit.i18nText("Fine-Design_Basic_Base_SimSun_Not_Found"));
} }
} }
} }
return guiFRFont; return guiFRFont;
} }
};
private static FRFont getNamedFont(String name) { private static FRFont getNamedFont(String name) {
return FRFont.getInstance(name, Font.PLAIN, 12); return FRFont.getInstance(name, Font.PLAIN, 12);

Loading…
Cancel
Save