From 59c9d52ca5116a581de7da1c0817ee8ec2fb9a30 Mon Sep 17 00:00:00 2001 From: Patrick Durand Date: Fri, 10 Mar 2023 15:05:57 +0100 Subject: [PATCH] fix font managment; issue issue#8 --- .../genericapp/ui/menu/EZActionManager.java | 4 ++-- .../ui/starter/EZEnvironmentImplem.java | 24 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/com/plealog/genericapp/ui/menu/EZActionManager.java b/src/com/plealog/genericapp/ui/menu/EZActionManager.java index 8c07e25..f54627a 100644 --- a/src/com/plealog/genericapp/ui/menu/EZActionManager.java +++ b/src/com/plealog/genericapp/ui/menu/EZActionManager.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2003-2021 Patrick G. Durand +/* Copyright (C) 2003-2023 Patrick G. Durand * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -421,7 +421,7 @@ private JMenu createMenu(ResourceBundle resource, String key, resource, key + SUFFIX_TEXT); menu.setText(mName); - menu.setFont(EZEnvironmentImplem.getMainFont(null)); + menu.setFont(EZEnvironmentImplem.getMainFont(resource)); items = new ArrayList(); for (i = 0; i < itemKeys.length; i++) { if (itemKeys[i].equals("-")) { diff --git a/src/com/plealog/genericapp/ui/starter/EZEnvironmentImplem.java b/src/com/plealog/genericapp/ui/starter/EZEnvironmentImplem.java index ddd77e3..f10fc9e 100644 --- a/src/com/plealog/genericapp/ui/starter/EZEnvironmentImplem.java +++ b/src/com/plealog/genericapp/ui/starter/EZEnvironmentImplem.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2003-2016 Patrick G. Durand +/* Copyright (C) 2003-2023 Patrick G. Durand * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,6 +45,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingUtilities; +import javax.swing.UIManager; import com.plealog.genericapp.api.EZApplicationBranding; import com.plealog.genericapp.api.EZEnvironment; @@ -66,7 +67,7 @@ public abstract class EZEnvironmentImplem { private static Color _systemTextColor = Color.BLACK; /** generic font for the entire GUI */ - private static final Font MAINFONT = new Font("SansSerif", + private static final Font MAINFONT = new Font("LucidaSans", Font.PLAIN, 12); /** an unknown String value for not defined key (?) */ @@ -307,17 +308,16 @@ public static Color getColor(ResourceBundle rb, String key) { */ public static Font getMainFont(ResourceBundle rb) { String szFntName; - Font fnt = MAINFONT; int size; + if (_mainFont != null) + return _mainFont; try { + _mainFont = MAINFONT; if (rb != null) { - if (_mainFont == null) { - szFntName = rb.getString("app.font.name"); - size = Integer.valueOf(rb.getString("app.font.size")).intValue(); - _mainFont = new Font(szFntName, Font.PLAIN, size); - } - fnt = _mainFont; + szFntName = rb.getString("app.font.name"); + size = Integer.valueOf(rb.getString("app.font.size")).intValue(); + _mainFont = new Font(szFntName, Font.PLAIN, size); } } catch (MissingResourceException mre) { EZLogger.warn("Unable to find resources: " + mre.getMessage()); @@ -325,7 +325,7 @@ public static Font getMainFont(ResourceBundle rb) { EZLogger.warn("Value for font size does not contain an integer: " + nfe.getMessage()); } - return (fnt); + return (_mainFont); } /** @@ -599,6 +599,10 @@ public static void setUserDefinedMessagesResourceBundle(ResourceBundle rb) { public static void setUserDefinedActionsResourceBundle(ResourceBundle rb) { _userDefinedActionsBundle = rb; + // properly install fonts specs for Menu according to Java Swing specs + Font fnt = getMainFont(rb); + UIManager.put("Menu.font", fnt); + UIManager.put("MenuItem.font", fnt); } public static EZActionManager getActionsManager() {