jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1782519 - /jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java
Date Fri, 10 Feb 2017 20:35:29 GMT
Author: fschumacher
Date: Fri Feb 10 20:35:29 2017
New Revision: 1782519

URL: http://svn.apache.org/viewvc?rev=1782519&view=rev
Log:
Use instanceof instead of a string compare to get the font objects to scale.
Differentiate between Fonts and the more special FontUIResource instances.
Store the new Font instances in the UIDefaults instead of the UIManager.
The last change is needed on ubuntu to make the zoom feature usable for more
then one step.

Bugzilla Id: 59995

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java?rev=1782519&r1=1782518&r2=1782519&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java Fri Feb 10 20:35:29 2017
@@ -39,7 +39,6 @@ import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.Properties;
 import java.util.ResourceBundle;
-import java.util.Set;
 import java.util.Vector;
 import java.util.concurrent.ThreadLocalRandom;
 
@@ -47,7 +46,9 @@ import javax.swing.ImageIcon;
 import javax.swing.JOptionPane;
 import javax.swing.JTable;
 import javax.swing.SwingUtilities;
+import javax.swing.UIDefaults;
 import javax.swing.UIManager;
+import javax.swing.plaf.FontUIResource;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.jmeter.gui.GuiPackage;
@@ -1162,26 +1163,32 @@ public class JMeterUtils implements Unit
     
     /**
      * Apply HiDPI scale factor on fonts
-     * @param scale flot scale to apply
+     * @param scale float scale to apply
      */
     public static void applyScaleOnFonts(final float scale) {
-        log.info("Applying HiDPI scale:"+scale);
+        log.info("Applying HiDPI scale: {}", scale);
         SwingUtilities.invokeLater(() -> {
-            Set<Object> keySet = UIManager.getLookAndFeelDefaults().keySet();
-            Object[] keys = keySet.toArray(new Object[keySet.size()]);
-            for (Object key : keys) {
-                if (key != null && key.toString().toLowerCase().contains("font"))
{
-                    Font font = UIManager.getDefaults().getFont(key);
-                    if (font != null) {
-                        font = font.deriveFont(font.getSize() * scale);
-                        UIManager.put(key, font);
+            UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+            // If I iterate over the entrySet under ubuntu with jre 1.8.0_121
+            // the font objects are missing, so iterate over the keys, only
+            for (Object key : defaults.keySet()) {
+                Object value = defaults.get(key);
+                log.debug("Try key {} with value {}", key, value);
+                if (value instanceof Font) {
+                    Font font = (Font) value;
+                    final float newSize = font.getSize() * scale;
+                    if (font instanceof FontUIResource) {
+                        defaults.put(key, new FontUIResource(font.getName(),
+                                font.getStyle(), Math.round(newSize)));
+                    } else {
+                        defaults.put(key, font.deriveFont(newSize));
                     }
                 }
-            } 
+            }
             JMeterUtils.refreshUI();
         });
     }
-    
+
     /**
      * Refresh UI after LAF change or resizing
      */



Mime
View raw message