You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2017/01/25 17:08:26 UTC

svn commit: r1780244 - in /jmeter/trunk: src/core/org/apache/jmeter/ src/core/org/apache/jmeter/gui/action/ src/core/org/apache/jmeter/gui/util/ src/core/org/apache/jmeter/resources/ src/core/org/apache/jmeter/util/ xdocs/

Author: pmouawad
Date: Wed Jan 25 17:08:26 2017
New Revision: 1780244

URL: http://svn.apache.org/viewvc?rev=1780244&view=rev
Log:
Bug 59995 - Allow user to change font size with 2 new menu items and use "jmeter.hidpi.scale.factor" for scaling fonts
Contributed by UbikLoadPack
Bugzilla Id: 59995

Added:
    jmeter/trunk/src/core/org/apache/jmeter/gui/action/ZoomInOut.java   (with props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/JMeter.java
    jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionNames.java
    jmeter/trunk/src/core/org/apache/jmeter/gui/action/LookAndFeelCommand.java
    jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/JMeter.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/JMeter.java?rev=1780244&r1=1780243&r2=1780244&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/JMeter.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/JMeter.java Wed Jan 25 17:08:26 2017
@@ -339,6 +339,7 @@ public class JMeter implements JMeterPlu
             log.warn("Could not set LAF to:"+jMeterLaf, ex);
         }
         splash.setProgress(10);
+        JMeterUtils.applyHiDPIOnFonts();
         PluginManager.install(this, true);
 
         JMeterTreeModel treeModel = new JMeterTreeModel();

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionNames.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionNames.java?rev=1780244&r1=1780243&r2=1780244&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionNames.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/ActionNames.java Wed Jan 25 17:08:26 2017
@@ -104,6 +104,8 @@ public final class ActionNames {
     public static final String RUN_TG           = "run_tg"; // $NON-NLS-1$
     public static final String RUN_TG_NO_TIMERS = "run_tg_no_timers"; // $NON-NLS-1$
     public static final String VALIDATE_TG      = "validate_tg"; //$NON-NLS-1$
+    public static final String ZOOM_IN          = "zoom_in"; //$NON-NLS-1$
+    public static final String ZOOM_OUT         = "zoom_out"; //$NON-NLS-1$
 
     // Prevent instantiation
     private ActionNames() {}

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/LookAndFeelCommand.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/LookAndFeelCommand.java?rev=1780244&r1=1780243&r2=1780244&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/LookAndFeelCommand.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/LookAndFeelCommand.java Wed Jan 25 17:08:26 2017
@@ -18,9 +18,6 @@
 
 package org.apache.jmeter.gui.action;
 
-import java.awt.Dialog;
-import java.awt.Frame;
-import java.awt.Window;
 import java.awt.event.ActionEvent;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -29,7 +26,6 @@ import java.util.Locale;
 import java.util.Set;
 import java.util.prefs.Preferences;
 
-import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
 
 import org.apache.jmeter.gui.util.JMeterMenuBar;
@@ -130,15 +126,7 @@ public class LookAndFeelCommand extends
         try {
             String className = ev.getActionCommand().substring(ActionNames.LAF_PREFIX.length()).replace('/', '.');
             UIManager.setLookAndFeel(className);
-            for (Window w : Window.getWindows()) {
-                SwingUtilities.updateComponentTreeUI(w);
-                if (w.isDisplayable() &&
-                    (w instanceof Frame ? !((Frame)w).isResizable() :
-                    w instanceof Dialog ? !((Dialog)w).isResizable() :
-                    true)) {
-                    w.pack();
-                }
-            }
+            JMeterUtils.refreshUI();
             PREFS.put(USER_PREFS_KEY, className);
         } catch (javax.swing.UnsupportedLookAndFeelException | InstantiationException | ClassNotFoundException | IllegalAccessException e) {
             JMeterUtils.reportErrorToUser("Look and Feel unavailable:" + e.toString());

Added: jmeter/trunk/src/core/org/apache/jmeter/gui/action/ZoomInOut.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/ZoomInOut.java?rev=1780244&view=auto
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/ZoomInOut.java (added)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/ZoomInOut.java Wed Jan 25 17:08:26 2017
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.gui.action;
+
+import java.awt.event.ActionEvent;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.jmeter.util.JMeterUtils;
+
+/**
+ * Zoom IN/OUT
+ * @since 3.2
+ */
+public class ZoomInOut extends AbstractAction {
+    private static final Set<String> commands = new HashSet<>();
+
+    private static final float ZOOM_SCALE = JMeterUtils.getPropDefault("zoom_scale", 1.1f);
+
+    static {
+        commands.add(ActionNames.ZOOM_IN);
+        commands.add(ActionNames.ZOOM_OUT);
+    }
+
+    /**
+     * @see org.apache.jmeter.gui.action.AbstractActionWithNoRunningTest#doActionAfterCheck(ActionEvent)
+     */
+    @Override
+    public void doAction(ActionEvent e) {
+        final String actionCommand = e.getActionCommand();
+        if (actionCommand.equals(ActionNames.ZOOM_IN)) {
+            JMeterUtils.applyScaleOnFonts(ZOOM_SCALE);
+        } else if (actionCommand.equals(ActionNames.ZOOM_OUT)) {
+            JMeterUtils.applyScaleOnFonts(1/ZOOM_SCALE);
+        }
+    }
+
+    /**
+     * @see org.apache.jmeter.gui.action.Command#getActionNames()
+     */
+    @Override
+    public Set<String> getActionNames() {
+        return commands;
+    }
+}

Propchange: jmeter/trunk/src/core/org/apache/jmeter/gui/action/ZoomInOut.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java?rev=1780244&r1=1780243&r2=1780244&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java Wed Jan 25 17:08:26 2017
@@ -346,6 +346,11 @@ public class JMeterMenuBar extends JMenu
         JMenuItem expand = makeMenuItemRes("menu_expand_all", ActionNames.EXPAND_ALL, KeyStrokes.EXPAND_ALL); //$NON-NLS-1$
         optionsMenu.add(expand);
 
+        JMenuItem zoomIn = makeMenuItemRes("menu_zoom_in", ActionNames.ZOOM_IN); //$NON-NLS-1$
+        optionsMenu.add(zoomIn);
+        JMenuItem zoomOut = makeMenuItemRes("menu_zoom_out", ActionNames.ZOOM_OUT); //$NON-NLS-1$
+        optionsMenu.add(zoomOut);
+
         addPluginsMenuItems(optionsMenu, menuCreators, MENU_LOCATION.OPTIONS);
     }
 

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1780244&r1=1780243&r2=1780244&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Wed Jan 25 17:08:26 2017
@@ -668,6 +668,8 @@ menu_tables=Table
 menu_threads=Threads (Users)
 menu_timer=Timer
 menu_toolbar=Toolbar
+menu_zoom_in=Zoom In
+menu_zoom_out=Zoom Out
 metadata=MetaData
 method=Method\:
 mimetype=Mimetype

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1780244&r1=1780243&r2=1780244&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Wed Jan 25 17:08:26 2017
@@ -658,6 +658,8 @@ menu_tables=Table
 menu_threads=Moteurs d'utilisateurs
 menu_timer=Compteurs de temps
 menu_toolbar=Barre d'outils
+menu_zoom_in=Agrandir
+menu_zoom_out=R\u00E9duire
 metadata=M\u00E9ta-donn\u00E9es
 method=M\u00E9thode \:
 mimetype=Type MIME

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=1780244&r1=1780243&r2=1780244&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java Wed Jan 25 17:08:26 2017
@@ -18,7 +18,11 @@
 
 package org.apache.jmeter.util;
 
+import java.awt.Dialog;
+import java.awt.Font;
+import java.awt.Frame;
 import java.awt.HeadlessException;
+import java.awt.Window;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
@@ -35,6 +39,7 @@ 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;
 
@@ -42,6 +47,7 @@ import javax.swing.ImageIcon;
 import javax.swing.JOptionPane;
 import javax.swing.JTable;
 import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.jmeter.gui.GuiPackage;
@@ -1144,4 +1150,50 @@ public class JMeterUtils implements Unit
         return delimiterValue;
     }
 
+    /**
+     * Apply HiDPI scale factor on font if HiDPI mode is enabled
+     */
+    public static void applyHiDPIOnFonts() {
+        if (!getHiDPIMode()) {
+            return;
+        }
+        applyScaleOnFonts((float) getHiDPIScaleFactor());
+    }
+    
+    /**
+     * Apply HiDPI scale factor on fonts
+     * @param scale flot scale to apply
+     */
+    public static void applyScaleOnFonts(final float 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);
+                    }
+                }
+            } 
+            JMeterUtils.refreshUI();
+        });
+    }
+    
+    /**
+     * Refresh UI after LAF change or resizing
+     */
+    public static final void refreshUI() {
+        for (Window w : Window.getWindows()) {
+            SwingUtilities.updateComponentTreeUI(w);
+            if (w.isDisplayable() &&
+                (w instanceof Frame ? !((Frame)w).isResizable() :
+                w instanceof Dialog ? !((Dialog)w).isResizable() :
+                true)) {
+                w.pack();
+            }
+        }
+    }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1780244&r1=1780243&r2=1780244&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Wed Jan 25 17:08:26 2017
@@ -159,6 +159,7 @@ JMeter now requires Java 8. Ensure you u
     <li><bug>60593</bug>Switch to G1 GC algorithm</li>
     <li><bug>60595</bug>Add a SplashScreen at the start of JMeter GUI. Contributed by Maxime Chassagneux (maxime.chassagneux at gmail.com).</li>
     <li><bug>55258</bug>Drop "Close" icon from toolbar and add "New" to menu. Partly based on contribution from Sanduni Kanishka (https://github.com/SanduniKanishka)</li>
+    <li><bug>59995</bug>Allow user to change font size with 2 new menu items and use <code>jmeter.hidpi.scale.factor</code> for scaling fonts. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
 </ul>
 
 <ch_section>Non-functional changes</ch_section>