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

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

commit c144f3c99ad18351575a542ca205eeae19bafe90
Author: Felix Schumacher <[email protected]>
AuthorDate: Sat Apr 29 21:43:01 2023 +0200

    Simplify logic to reduce recursion
    
    and correct a few typos, while we are here.
---
 .../main/java/org/apache/jorphan/gui/ComponentUtil.java   | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git 
a/src/jorphan/src/main/java/org/apache/jorphan/gui/ComponentUtil.java 
b/src/jorphan/src/main/java/org/apache/jorphan/gui/ComponentUtil.java
index a926a78602..754b914939 100644
--- a/src/jorphan/src/main/java/org/apache/jorphan/gui/ComponentUtil.java
+++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/ComponentUtil.java
@@ -23,7 +23,7 @@ import java.awt.Rectangle;
 
 /**
  * This class is a Util for awt Component and could be used to place them in
- * center of an other.
+ * center of another.
  *
  */
 public final class ComponentUtil {
@@ -36,19 +36,12 @@ public final class ComponentUtil {
      * @param component
      *            the component you want to center and set size on
      * @param percentOfScreen
-     *            the percent of the current screensize you want the component
+     *            the percent of the current screen size you want the component
      *            to be
      */
     public static void centerComponentInWindow(Component component, int 
percentOfScreen) {
-        if (percentOfScreen < 0) {
-            centerComponentInWindow(component, -percentOfScreen);
-            return;
-        }
-        if (percentOfScreen > 100) {
-            centerComponentInWindow(component, 100);
-            return;
-        }
-        double percent = percentOfScreen / 100.d;
+        int validPercentOfScreen = Math.min(Math.abs(percentOfScreen), 100);
+        double percent = validPercentOfScreen / 100.d;
         Rectangle bounds = 
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds();
         component.setSize((int) (bounds.getWidth() * percent), (int) 
(bounds.getHeight() * percent));
         centerComponentInWindow(component);

Reply via email to