diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index c9349e855..d3f85a118 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 { @@ -127,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"); @@ -260,6 +270,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/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); } 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)); }