You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by vl...@apache.org on 2020/04/05 12:09:21 UTC

[jmeter] branch master updated: Mark the currently selected language in the options menu

This is an automated email from the ASF dual-hosted git repository.

vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new 200a64a  Mark the currently selected language in the options menu
200a64a is described below

commit 200a64ab937c10cf007d70b2bf9eaf36d42ee4ea
Author: Vladimir Sitnikov <si...@gmail.com>
AuthorDate: Sun Apr 5 15:09:00 2020 +0300

    Mark the currently selected language in the options menu
---
 .../org/apache/jmeter/gui/util/JMeterMenuBar.java    | 20 +++++++++++++++++---
 xdocs/changes.xml                                    |  1 +
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java b/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java
index 964da96..4ebb954 100644
--- a/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java
+++ b/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java
@@ -358,13 +358,19 @@ public class JMeterMenuBar extends JMenuBar implements LocaleChangeListener {
          * Create a language entry from the locale name.
          *
          * @param locale - must also be a valid resource name
+         * @param languageGroup - group for radio items
+         * @param selected - if the menu item is selected
          */
-        void addLang(String locale){
+        void addLang(String locale, ButtonGroup languageGroup, boolean selected) {
             String localeString = JMeterUtils.getLocaleString(locale);
-            JMenuItem language = new JMenuItem(localeString);
+            JMenuItem language = new JRadioButtonMenuItem(localeString);
             language.addActionListener(actionRouter);
             language.setActionCommand(ActionNames.CHANGE_LANGUAGE);
             language.setName(locale); // This is used by the ChangeLanguage class to define the Locale
+            if (selected) {
+                language.setSelected(true);
+            }
+            languageGroup.add(language);
             languageMenu.add(language);
         }
    }
@@ -409,8 +415,16 @@ public class JMeterMenuBar extends JMenuBar implements LocaleChangeListener {
          * Also, need to ensure that the names are valid resource entries too.
          */
 
+        Locale currentLocale = JMeterUtils.getLocale();
+        String selectedLocale = currentLocale == null ? "" : currentLocale.toString();
+        if (selectedLocale.equals(JMeterUtils.getLocaleString(selectedLocale))) {
+            // E.g. if the current locale has no localized name, then it is unknown to JMeter,
+            // so it can't appear in the menu. In that case, we assume English locale is used.
+            selectedLocale = Locale.ENGLISH.toString();
+        }
+        ButtonGroup languageGroup = new ButtonGroup();
         for (String lang : getLanguages()) {
-            langMenu.addLang(lang);
+            langMenu.addLang(lang, languageGroup, selectedLocale.equals(lang));
         }
         return languageMenu;
     }
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index f677321..3b71c14 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -102,6 +102,7 @@ For instance: log viewer, JSR223 code editor were not previously scaled with zoo
 Undo is implemented on a field level basis (each fields has its own history), and the history is
 invalidated when tree selection changes.</p>
 
+<p>Mark the currently selected language in the options menu</p>
 <!--
 <ch_title>Functions</ch_title>
 -->