Skip to content

Commit

Permalink
fix font managment; issue issue#8
Browse files Browse the repository at this point in the history
  • Loading branch information
pgdurand committed Mar 10, 2023
1 parent e312d49 commit 59c9d52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/com/plealog/genericapp/ui/menu/EZActionManager.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<Component>();
for (i = 0; i < itemKeys.length; i++) {
if (itemKeys[i].equals("-")) {
Expand Down
24 changes: 14 additions & 10 deletions src/com/plealog/genericapp/ui/starter/EZEnvironmentImplem.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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 (?) */
Expand Down Expand Up @@ -307,25 +308,24 @@ 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());
} catch (NumberFormatException nfe) {
EZLogger.warn("Value for font size does not contain an integer: "
+ nfe.getMessage());
}
return (fnt);
return (_mainFont);
}

/**
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 59c9d52

Please sign in to comment.