From fbdf88ecefa98881c952934141f5b2bf524866e4 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Mon, 28 Jun 2021 20:24:28 -0400 Subject: [PATCH] make it possible to change the interface font from the prefs --- .../app/platform/DefaultPlatform.java | 26 +++++++++++++++++-- build/shared/lib/defaults.txt | 3 +++ todo.txt | 3 +++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/src/processing/app/platform/DefaultPlatform.java b/app/src/processing/app/platform/DefaultPlatform.java index 6cba3b164..e80adac32 100644 --- a/app/src/processing/app/platform/DefaultPlatform.java +++ b/app/src/processing/app/platform/DefaultPlatform.java @@ -29,6 +29,7 @@ import java.io.File; import java.net.URI; import javax.swing.UIManager; +import javax.swing.plaf.FontUIResource; import com.sun.jna.Library; import com.sun.jna.Native; @@ -110,6 +111,24 @@ public class DefaultPlatform { } else { UIManager.setLookAndFeel(laf); } + + // If the default has been overridden in the preferences, set the font + String fontName = Preferences.get("ui.font.family"); + int fontSize = Preferences.getInteger("ui.font.size"); + if (!"Dialog".equals(fontName) || fontSize != 12) { + setUIFont(new FontUIResource(fontName, Font.PLAIN, fontSize)); + } + } + + + // Rewritten from https://stackoverflow.com/a/7434935 + static private void setUIFont(FontUIResource f) { + for (Object key : UIManager.getLookAndFeelDefaults().keySet()) { + Object value = UIManager.get(key); + if (value instanceof FontUIResource) { + UIManager.put(key, f); + } + } } @@ -120,8 +139,11 @@ public class DefaultPlatform { scaleDefaultFont(widgetName); } - UIManager.put("Label.font", new Font("Dialog", Font.PLAIN, Toolkit.zoom(12))); - UIManager.put("TextField.font", new Font("Dialog", Font.PLAIN, Toolkit.zoom(12))); + String fontName = Preferences.get("ui.font.family"); + int fontSize = Preferences.getInteger("ui.font.size"); + FontUIResource uiFont = new FontUIResource(fontName, Font.PLAIN, Toolkit.zoom(fontSize)); + UIManager.put("Label.font", uiFont); + UIManager.put("TextField.font", uiFont); } } diff --git a/build/shared/lib/defaults.txt b/build/shared/lib/defaults.txt index 9fca8867e..6805114d4 100644 --- a/build/shared/lib/defaults.txt +++ b/build/shared/lib/defaults.txt @@ -95,6 +95,9 @@ platform.auto_file_type_associations = true # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# default font used for UI elements +ui.font.family = Dialog +ui.font.size = 12 # default size for the main window editor.window.width.default = 700 diff --git a/todo.txt b/todo.txt index d1b3c2a8e..62e16fc07 100755 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,9 @@ 1275 (4.0a6) X remove java.class.path when launching code from inside the PDE X should prevent conflicts, avoid papering over other bugs +X add ui.font.family and ui.font.size as preferences + +readme _ was fixed in the source for 4.0a5, but may not have been included in the dist _ NoClassDefError: processing/core/PApplet when starting 4.0a2 on Windows 10 _ https://github.com/processing/processing4/issues/154