From 1ba27730d686af69a54dc3cdaa3e3cbba1e43111 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 19 Jun 2020 13:38:25 +0200 Subject: [PATCH] UIDefaultsDump: fixed order of removed values in diff dumps --- .../testing/uidefaults/UIDefaultsDump.java | 38 +++++++++++-------- .../uidefaults/FlatIntelliJLaf_1.8.0_202.txt | 16 ++++---- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/uidefaults/UIDefaultsDump.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/uidefaults/UIDefaultsDump.java index 8effa9ca..53a01ecf 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/uidefaults/UIDefaultsDump.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/uidefaults/UIDefaultsDump.java @@ -36,6 +36,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; +import java.util.TreeSet; import java.util.function.Predicate; import javax.swing.Icon; import javax.swing.ImageIcon; @@ -208,29 +210,33 @@ public class UIDefaultsDump } private static String diff( Map defaults1, Map defaults2 ) { - defaults1 = new LinkedHashMap<>( defaults1 ); + TreeSet keys = new TreeSet<>(); + keys.addAll( defaults1.keySet() ); + keys.addAll( defaults2.keySet() ); StringBuilder buf = new StringBuilder( 10000 ); - for( Map.Entry e : defaults2.entrySet() ) { - String key = e.getKey(); - String value2 = e.getValue(); - String value1 = defaults1.remove( key ); - if( !value2.equals( value1 ) ) { - if( value1 != null ) - buf.append( "- " ).append( key ).append( value1 ).append( '\n' ); - buf.append( "+ " ).append( key ).append( value2 ).append( '\n' ); - buf.append( '\n' ); - } - } - for( Map.Entry e : defaults1.entrySet() ) { - buf.append( "- " ).append( e.getKey() ).append( e.getValue() ).append( '\n' ); - buf.append( '\n' ); - } + // diff header values + for( String key : new String[] { "Class", "ID", "Name", "Java", "OS" } ) + diffValue( buf, key, defaults1.remove( key ), defaults2.remove( key ) ); + + // diff values + for( String key : keys ) + diffValue( buf, key, defaults1.get( key ), defaults2.get( key ) ); return buf.toString(); } + private static void diffValue( StringBuilder buf, String key, String value1, String value2 ) { + if( !Objects.equals( value1, value2 ) ) { + if( value1 != null ) + buf.append( "- " ).append( key ).append( value1 ).append( '\n' ); + if( value2 != null ) + buf.append( "+ " ).append( key ).append( value2 ).append( '\n' ); + buf.append( '\n' ); + } + } + private static Map parse( Reader in ) throws IOException { Map defaults = new LinkedHashMap<>(); try( BufferedReader reader = new BufferedReader( in ) ) { diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatIntelliJLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatIntelliJLaf_1.8.0_202.txt index 2b3772a2..f42eb6b5 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatIntelliJLaf_1.8.0_202.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatIntelliJLaf_1.8.0_202.txt @@ -21,6 +21,8 @@ - Button.default.borderWidth 2 + Button.default.borderWidth 1 +- Button.default.focusedBackground #e3f1fa javax.swing.plaf.ColorUIResource [UI] + - Button.default.focusedBorderColor #87afda javax.swing.plaf.ColorUIResource [UI] + Button.default.focusedBorderColor #a9c9f5 javax.swing.plaf.ColorUIResource [UI] @@ -30,9 +32,13 @@ - Button.default.hoverBorderColor #87afda javax.swing.plaf.ColorUIResource [UI] + Button.default.hoverBorderColor #a9c9f5 javax.swing.plaf.ColorUIResource [UI] +- Button.focusedBackground #e3f1fa javax.swing.plaf.ColorUIResource [UI] + - CheckBox.icon.checkmarkColor #4f9ee3 javax.swing.plaf.ColorUIResource [UI] + CheckBox.icon.checkmarkColor #ffffff javax.swing.plaf.ColorUIResource [UI] +- CheckBox.icon.focusedBackground #e3f1fa javax.swing.plaf.ColorUIResource [UI] + - CheckBox.icon.selectedBackground #ffffff javax.swing.plaf.ColorUIResource [UI] + CheckBox.icon.selectedBackground #4f9ee3 javax.swing.plaf.ColorUIResource [UI] @@ -63,6 +69,8 @@ - FormattedTextField.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatTextBorder [UI] + FormattedTextField.border [lazy] 3,3,3,3 false com.formdev.flatlaf.ui.FlatTextBorder [UI] +- HelpButton.focusedBackground #e3f1fa javax.swing.plaf.ColorUIResource [UI] + - HelpButton.icon [lazy] 22,22 com.formdev.flatlaf.icons.FlatHelpButtonIcon [UI] + HelpButton.icon [lazy] 26,26 com.formdev.flatlaf.icons.FlatHelpButtonIcon [UI] @@ -90,11 +98,3 @@ - ToggleButton.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatButtonBorder [UI] + ToggleButton.border [lazy] 3,3,3,3 false com.formdev.flatlaf.ui.FlatButtonBorder [UI] -- Button.default.focusedBackground #e3f1fa javax.swing.plaf.ColorUIResource [UI] - -- Button.focusedBackground #e3f1fa javax.swing.plaf.ColorUIResource [UI] - -- CheckBox.icon.focusedBackground #e3f1fa javax.swing.plaf.ColorUIResource [UI] - -- HelpButton.focusedBackground #e3f1fa javax.swing.plaf.ColorUIResource [UI] -