From 65d4ea90d39e17666431c0e1be8cea604d036a66 Mon Sep 17 00:00:00 2001 From: A Pottinger Date: Mon, 29 Jun 2020 14:21:08 -0700 Subject: [PATCH 1/3] Ensure not trying to use Toolkit zoom before ready. --- app/src/processing/app/Preferences.java | 7 +++++++ app/src/processing/app/ui/Editor.java | 7 +++++++ app/src/processing/app/ui/Toolkit.java | 12 +++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index c9349e855..5117d5436 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -55,11 +55,13 @@ public class Preferences { static Map defaults; static Map table = new HashMap<>(); static File preferencesFile; + private static boolean initalized = false; // /** @return true if the sketchbook file did not exist */ // static public boolean init() { static public void init() { + initalized = true; // start by loading the defaults, in case something // important was deleted from the user prefs try { @@ -260,6 +262,11 @@ public class Preferences { // all the information from preferences.txt static public String get(String attribute /*, String defaultValue */) { + if (!initalized) { + throw new RuntimeException( + "Tried reading preferences prior to initalization." + ); + } return table.get(attribute); } diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index 832be571b..a542b27e5 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -713,6 +713,13 @@ public abstract class Editor extends JFrame implements RunnerListener { protected void buildMenuBar() { + Font menubarFont = new Font( + Preferences.get("editor.font.family"), + Font.PLAIN, + Toolkit.zoom(10) + ); + UIManager.put("Menu.font", menubarFont); + JMenuBar menubar = new JMenuBar(); fileMenu = buildFileMenu(); menubar.add(fileMenu); diff --git a/app/src/processing/app/ui/Toolkit.java b/app/src/processing/app/ui/Toolkit.java index f1cbf56dc..181db4b68 100644 --- a/app/src/processing/app/ui/Toolkit.java +++ b/app/src/processing/app/ui/Toolkit.java @@ -829,6 +829,13 @@ public class Toolkit { new StringList("100%", "150%", "200%", "300%"); + /** + * Calculate the desired size in pixels of an element using preferences or + * system zoom if preferences set to auto. + * + * @param pixels The size in pixels to scale. + * @return The scaled size. + */ static public int zoom(int pixels) { if (zoom == 0) { zoom = parseZoom(); @@ -844,8 +851,7 @@ public class Toolkit { } - static public final int BORDER = - Toolkit.zoom(Platform.isMacOS() ? 20 : 13); + static public final int BORDER = Platform.isMacOS() ? 20 : 13; static public void setBorder(JComponent comp) { @@ -903,7 +909,7 @@ public class Toolkit { static public boolean highResImages() { - return isRetina() || (zoom > 1); + return isRetina() || (Platform.getSystemZoom() > 1); } From 2e3f573ef87d629e69efa7b4fec5f816b5fca936 Mon Sep 17 00:00:00 2001 From: A Pottinger Date: Mon, 29 Jun 2020 14:42:39 -0700 Subject: [PATCH 2/3] Allow for emulated Preferences in testing. --- app/src/processing/app/Preferences.java | 8 ++++++++ java/test/processing/mode/java/ProcessingTestUtil.java | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 5117d5436..d3f85a118 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -129,6 +129,14 @@ public class Preferences { } + /** + * For testing, pretend to load preferences without a real file. + */ + static public void skipInit() { + initalized = true; + } + + static void handleProxy(String protocol, String hostProp, String portProp) { String proxyHost = get("proxy." + protocol + ".host"); String proxyPort = get("proxy." + protocol + ".port"); diff --git a/java/test/processing/mode/java/ProcessingTestUtil.java b/java/test/processing/mode/java/ProcessingTestUtil.java index cd8e43e9e..40c7dde34 100644 --- a/java/test/processing/mode/java/ProcessingTestUtil.java +++ b/java/test/processing/mode/java/ProcessingTestUtil.java @@ -17,7 +17,7 @@ public class ProcessingTestUtil { static void init() { // noop; just causes class to be loaded } - + private static final String RESOURCES = "test/resources/"; private static final String RESOURCES_UP_DIR = "../java/test/resources"; static final UTCompiler COMPILER; @@ -64,9 +64,10 @@ public class ProcessingTestUtil { return normalize(out); } - + static String format(final File resource) { + Preferences.skipInit(); return format(read(resource)); } From 25f67253d21e93a8a95b4fb27e744f6f0ce6f315 Mon Sep 17 00:00:00 2001 From: A Pottinger Date: Tue, 30 Jun 2020 08:36:37 -0700 Subject: [PATCH 3/3] Keep edits to menubar to later. --- app/src/processing/app/ui/Editor.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index a542b27e5..832be571b 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -713,13 +713,6 @@ public abstract class Editor extends JFrame implements RunnerListener { protected void buildMenuBar() { - Font menubarFont = new Font( - Preferences.get("editor.font.family"), - Font.PLAIN, - Toolkit.zoom(10) - ); - UIManager.put("Menu.font", menubarFont); - JMenuBar menubar = new JMenuBar(); fileMenu = buildFileMenu(); menubar.add(fileMenu);