make it possible to change the interface font from the prefs

This commit is contained in:
Ben Fry
2021-06-28 20:24:28 -04:00
parent 6771c5c178
commit fbdf88ecef
3 changed files with 30 additions and 2 deletions
@@ -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);
}
}
+3
View File
@@ -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
+3
View File
@@ -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