jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vladimirsitni...@apache.org
Subject [jmeter] branch master updated: UX: improve default sizing for the row height
Date Sun, 29 Mar 2020 21:23:06 GMT
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 3e2fef6  UX: improve default sizing for the row height
3e2fef6 is described below

commit 3e2fef667fd82a37435e7a6915035bee38380ff4
Author: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
AuthorDate: Mon Mar 30 00:22:53 2020 +0300

    UX: improve default sizing for the row height
    
    Previously we used fontHeight, however it did not have enough room.
    Now we use fontHeight*1.3 for the row height.
---
 .../main/java/org/apache/jorphan/gui/JFactory.java    | 10 ++--------
 .../java/org/apache/jorphan/gui/JMeterUIDefaults.java | 19 +++++++++++++------
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/JFactory.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/JFactory.java
index 4d574b8..46d84cf 100644
--- a/src/jorphan/src/main/java/org/apache/jorphan/gui/JFactory.java
+++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/JFactory.java
@@ -137,14 +137,8 @@ public class JFactory {
      */
     @API(since = "5.3", status = API.Status.EXPERIMENTAL)
     public static JTable singleLineRowHeight(JTable component) {
-        return STYLE.withDynamic(component, c -> {
-            Font font = c.getFont();
-            if (font != null) {
-                // Swing has no default property for Table.rowHeight
-                // So we set it for tables that opt-in
-                c.setRowHeight(c.getFontMetrics(font).getHeight());
-            }
-        });
+        return STYLE.withDynamic(component,
+                c -> c.setRowHeight(UIManager.getInt(JMeterUIDefaults.TABLE_ROW_HEIGHT)));
     }
 
     /**
diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/JMeterUIDefaults.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/JMeterUIDefaults.java
index 9d394e7..00cc90c 100644
--- a/src/jorphan/src/main/java/org/apache/jorphan/gui/JMeterUIDefaults.java
+++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/JMeterUIDefaults.java
@@ -72,6 +72,9 @@ public class JMeterUIDefaults {
 
     public static final String BUTTON_ERROR_FOREGROUND = "[jmeter]Button.errorForeground";
// $NON-NLS-1$
 
+    public static final String TABLE_ROW_HEIGHT = "Table.rowHeight"; // $NON-NLS-1$
+    public static final String TREE_ROW_HEIGHT = "Tree.rowHeight"; // $NON-NLS-1$
+
     private static final float SMALL_FONT_SCALE = 10f / 12;
     private static final float BIG_FONT_SCALE = 4f / 3;
     private static final float WARNING_FONT_SCALE = 11f / 10;
@@ -108,6 +111,9 @@ public class JMeterUIDefaults {
                 // We don't want to make controls extra big, so we damp the scaling factors
                 scaleControlsProperties(defaults, (float) Math.sqrt(scale));
             }
+            configureRowHeight(defaults, scale, TABLE_ROW_HEIGHT, "Table.font"); // $NON-NLS-1$
+            configureRowHeight(defaults, scale, TREE_ROW_HEIGHT, "Tree.font"); // $NON-NLS-1$
+
             defaults.put("Button.defaultButtonFollowsFocus", false); // $NON-NLS-1$
             defaults.put(TEXTAREA_BORDER, (UIDefaults.LazyValue) d -> new JTextField().getBorder());
 
@@ -156,8 +162,6 @@ public class JMeterUIDefaults {
         scaleIntProperty(defaults, "FileChooser.rowHeight", scale); // $NON-NLS-1$
         scaleIntProperty(defaults, "Spinner:\"Spinner.codeviousButton\".size", scale); //
$NON-NLS-1$
         scaleIntProperty(defaults, "Spinner:\"Spinner.nextButton\".size", scale); // $NON-NLS-1$
-        configureRowHeight(defaults, scale, "Table.rowHeight", "Table.font"); // $NON-NLS-1$
-        configureRowHeight(defaults, scale, "Tree.rowHeight", "Tree.font"); // $NON-NLS-1$
     }
 
     private void configureRowHeight(UIDefaults defaults, float scale, String rowHeight, String
font) {
@@ -166,10 +170,13 @@ public class JMeterUIDefaults {
         }
         defaults.put(rowHeight, (UIDefaults.LazyValue) d -> {
             Font f = d.getFont(font);
-            if (f == null) {
-                return Math.round(16 * scale);
-            }
-            return FontDesignMetrics.getMetrics(f).getHeight();
+            float height = f == null ? 16 * scale : FontDesignMetrics.getMetrics(f).getHeight();
+            // Set line height to be 1.3 of the font size. The number of completely made
up,
+            // 1.2 seems to be the minimal usable scale. 1.3 looks good.
+            int round = (int) Math.floor(height * 1.3f);
+            // Round to the next even, so the text does not move when editing the cell contents
+            round += round & 1;
+            return round;
         });
     }
 


Mime
View raw message