From 39ab4d57117658e7b9fef0feeb0e5cd003ee11bf Mon Sep 17 00:00:00 2001 From: Tom Eugelink Date: Sun, 14 May 2023 09:34:59 +0200 Subject: [PATCH] toLowerCase either needs hardcode text or use Locale.ROOT because of Locale (tr_TR) issues --- core/src/main/java/net/miginfocom/layout/AlignX.java | 12 +++++++++++- core/src/main/java/net/miginfocom/layout/AlignY.java | 12 +++++++++++- core/src/main/java/net/miginfocom/layout/CC.java | 4 ++-- .../java/net/miginfocom/layout/ConstraintParser.java | 5 +++-- core/src/main/java/net/miginfocom/layout/Grid.java | 2 +- core/src/main/java/net/miginfocom/layout/LC.java | 4 ++-- .../java/net/miginfocom/layout/PlatformDefaults.java | 3 ++- .../scene/layout/test/MigPaneInternalLayoutTest.java | 3 ++- 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/net/miginfocom/layout/AlignX.java b/core/src/main/java/net/miginfocom/layout/AlignX.java index a43ad2f..aa09552 100644 --- a/core/src/main/java/net/miginfocom/layout/AlignX.java +++ b/core/src/main/java/net/miginfocom/layout/AlignX.java @@ -1,5 +1,15 @@ package net.miginfocom.layout; public enum AlignX { - LEADING, LEFT, CENTER, RIGHT, TRAILING; + LEADING("leading"), LEFT("left"), CENTER("center"), RIGHT("right"), TRAILING("trailing"); + + private final String code; // toString().toLowerCase() is not an alternative because of Locale issues (e.g. tr_TR) + + private AlignX(String code) { + this.code = code; + } + + public String code() { + return code; + } } diff --git a/core/src/main/java/net/miginfocom/layout/AlignY.java b/core/src/main/java/net/miginfocom/layout/AlignY.java index 1535fc7..95a4b5b 100644 --- a/core/src/main/java/net/miginfocom/layout/AlignY.java +++ b/core/src/main/java/net/miginfocom/layout/AlignY.java @@ -1,5 +1,15 @@ package net.miginfocom.layout; public enum AlignY { - TOP, CENTER, BOTTOM, BASELINE; + TOP("top"), CENTER("center"), BOTTOM("bottom"), BASELINE("baseline"); + + private final String code; // toString().toLowerCase() is not an alternative because of Locale issues (e.g. tr_TR) + + private AlignY(String code) { + this.code = code; + } + + public String code() { + return code; + } } diff --git a/core/src/main/java/net/miginfocom/layout/CC.java b/core/src/main/java/net/miginfocom/layout/CC.java index 25131b4..76c5589 100755 --- a/core/src/main/java/net/miginfocom/layout/CC.java +++ b/core/src/main/java/net/miginfocom/layout/CC.java @@ -238,7 +238,7 @@ public final CC alignX(String align) * @return this so it is possible to chain calls. */ public final CC alignX(AlignX align) { - return alignX(align == null ? null : align.toString().toLowerCase()); + return alignX(align == null ? null : align.code()); } /** The grow priority compared to other components in the same cell. @@ -523,7 +523,7 @@ public final CC alignY(String align) */ public final CC alignY(AlignY align) { - return alignY(align == null ? null : align.toString().toLowerCase()); + return alignY(align == null ? null : align.code()); } /** The grow priority compared to other components in the same cell. diff --git a/core/src/main/java/net/miginfocom/layout/ConstraintParser.java b/core/src/main/java/net/miginfocom/layout/ConstraintParser.java index 3b85a67..4dd69f6 100755 --- a/core/src/main/java/net/miginfocom/layout/ConstraintParser.java +++ b/core/src/main/java/net/miginfocom/layout/ConstraintParser.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.Locale; import java.util.Map; /* * License (BSD): @@ -315,7 +316,7 @@ private static AC parseAxisConstraint(String s, boolean isCols) if (s.length() == 0) return new AC(); // Short circuit for performance. - s = s.toLowerCase(); + s = s.toLowerCase(Locale.ROOT); ArrayList parts = getRowColAndGapsTrimmed(s); @@ -1441,7 +1442,7 @@ private static ArrayList getRowColAndGapsTrimmed(String s) */ public static String prepare(String s) { - return s != null ? s.trim().toLowerCase() : ""; + return s != null ? s.trim().toLowerCase(Locale.ROOT) : ""; } // /** Tests to serialize and deserialize the object with both XMLEncoder/Decoder and through Serializable diff --git a/core/src/main/java/net/miginfocom/layout/Grid.java b/core/src/main/java/net/miginfocom/layout/Grid.java index 43b47f0..63be416 100755 --- a/core/src/main/java/net/miginfocom/layout/Grid.java +++ b/core/src/main/java/net/miginfocom/layout/Grid.java @@ -780,7 +780,7 @@ private void wrap(int[] cellXY, BoundSize gapSize) private static void sortCellsByPlatform(Collection cells, ContainerWrapper parent) { String order = PlatformDefaults.getButtonOrder(); - String orderLo = order.toLowerCase(); + String orderLo = order.toLowerCase(Locale.ROOT); int unrelSize = PlatformDefaults.convertToPixels(1, "u", true, 0, parent, null); diff --git a/core/src/main/java/net/miginfocom/layout/LC.java b/core/src/main/java/net/miginfocom/layout/LC.java index 6375180..8a51fde 100755 --- a/core/src/main/java/net/miginfocom/layout/LC.java +++ b/core/src/main/java/net/miginfocom/layout/LC.java @@ -843,7 +843,7 @@ public final LC alignX(String align) * @return this so it is possible to chain calls. */ public final LC alignX(AlignX align) { - return alignX(align == null ? null : align.toString().toLowerCase()); + return alignX(align == null ? null : align.code()); } /** Same functionality as setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false)) only this method returns this for chaining multiple calls. @@ -869,7 +869,7 @@ public final LC alignY(String align) */ public final LC alignY(AlignY align) { - return alignY(align == null ? null : align.toString().toLowerCase()); + return alignY(align == null ? null : align.code()); } /** Sets both the alignX and alignY as the same time. diff --git a/core/src/main/java/net/miginfocom/layout/PlatformDefaults.java b/core/src/main/java/net/miginfocom/layout/PlatformDefaults.java index 6b896f5..e52ac33 100755 --- a/core/src/main/java/net/miginfocom/layout/PlatformDefaults.java +++ b/core/src/main/java/net/miginfocom/layout/PlatformDefaults.java @@ -1,6 +1,7 @@ package net.miginfocom.layout; import java.util.HashMap; +import java.util.Locale; /* * License (BSD): @@ -529,7 +530,7 @@ public static UnitValue getUnitValueY(String unit) public static void setUnitValue(String[] unitStrings, UnitValue x, UnitValue y) { for (String unitString : unitStrings) { - String s = unitString.toLowerCase().trim(); + String s = unitString.toLowerCase(Locale.ROOT).trim(); if (x != null) HOR_DEFS.put(s, x); if (y != null) diff --git a/javafx/src/test/java/org/tbee/javafx/scene/layout/test/MigPaneInternalLayoutTest.java b/javafx/src/test/java/org/tbee/javafx/scene/layout/test/MigPaneInternalLayoutTest.java index 6141621..6e21a22 100644 --- a/javafx/src/test/java/org/tbee/javafx/scene/layout/test/MigPaneInternalLayoutTest.java +++ b/javafx/src/test/java/org/tbee/javafx/scene/layout/test/MigPaneInternalLayoutTest.java @@ -1,6 +1,7 @@ package org.tbee.javafx.scene.layout.test; import java.util.List; +import java.util.Locale; import javafx.scene.Parent; import javafx.scene.Scene; @@ -75,7 +76,7 @@ public void before() { } private boolean isUnix() { - String OS = System.getProperty("os.name").toLowerCase(); + String OS = System.getProperty("os.name").toLowerCase(Locale.ROOT); return (OS.contains("nix") || OS.contains("nux") || OS.contains("aix")); }