From 33e37a7167b24f87f589b0a306ac6fbafcfe6cf9 Mon Sep 17 00:00:00 2001 From: Dar Date: Tue, 22 Oct 2024 16:46:30 +0200 Subject: [PATCH 1/5] new: support for alternate row color in jtree see: https://github.com/JFormDesigner/FlatLaf/issues/900 --- .../src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java | 9 +++++++++ .../com/formdev/flatlaf/ui/TestFlatStyleableInfo.java | 1 + .../com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt | 1 + 3 files changed, 11 insertions(+) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java index 6eecb751..db0cc821 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java @@ -102,6 +102,7 @@ import com.formdev.flatlaf.util.UIScale; * @uiDefault Tree.selectionForeground Color * @uiDefault Tree.selectionInactiveBackground Color * @uiDefault Tree.selectionInactiveForeground Color + * @uiDefault Tree.alternateRowColor Color * @uiDefault Tree.selectionInsets Insets * @uiDefault Tree.selectionArc int * @uiDefault Tree.wideSelection boolean @@ -141,6 +142,7 @@ public class FlatTreeUI @Styleable protected Color selectionInactiveBackground; @Styleable protected Color selectionInactiveForeground; @Styleable protected Color selectionBorderColor; + @Styleable protected Color alternateRowColor; /** @since 3 */ @Styleable protected Insets selectionInsets; /** @since 3 */ @Styleable protected int selectionArc; @Styleable protected boolean wideSelection; @@ -192,6 +194,7 @@ public class FlatTreeUI selectionInactiveBackground = UIManager.getColor( "Tree.selectionInactiveBackground" ); selectionInactiveForeground = UIManager.getColor( "Tree.selectionInactiveForeground" ); selectionBorderColor = UIManager.getColor( "Tree.selectionBorderColor" ); + alternateRowColor = UIManager.getColor( "Tree.alternateRowColor" ); selectionInsets = UIManager.getInsets( "Tree.selectionInsets" ); selectionArc = UIManager.getInt( "Tree.selectionArc" ); wideSelection = UIManager.getBoolean( "Tree.wideSelection" ); @@ -227,6 +230,7 @@ public class FlatTreeUI selectionInactiveBackground = null; selectionInactiveForeground = null; selectionBorderColor = null; + alternateRowColor = null; defaultLeafIcon = null; defaultClosedIcon = null; @@ -570,6 +574,11 @@ public class FlatTreeUI boolean isSelected = tree.isRowSelected( row ); boolean isDropRow = isDropRow( row ); boolean needsSelectionPainting = (isSelected || isDropRow) && isPaintSelection(); + + if( alternateRowColor != null && row % 2 != 0 ) { + g.setColor( alternateRowColor ); + FlatUIUtils.paintComponentBackground((Graphics2D) g, bounds.x, bounds.y, tree.getWidth(), bounds.height, 0, 0); + } // do not paint row if editing if( isEditing ) { diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java index ea536a16..8058bed2 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java @@ -965,6 +965,7 @@ public class TestFlatStyleableInfo "selectionInactiveBackground", Color.class, "selectionInactiveForeground", Color.class, "selectionBorderColor", Color.class, + "alternateRowColor", Color.class, "selectionInsets", Insets.class, "selectionArc", int.class, "wideSelection", boolean.class, diff --git a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt index 60549ff4..b42eba60 100644 --- a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt +++ b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt @@ -1182,6 +1182,7 @@ Tree.dropCellForeground Tree.dropLineColor Tree.editorBorder Tree.editorBorderSelectionColor +Tree.alternateRowColor Tree.expandedIcon Tree.focusInputMap Tree.focusInputMap.RightToLeft From 25c2bbc85154713cab4c91d95c10f48192a697f9 Mon Sep 17 00:00:00 2001 From: Dar Date: Tue, 22 Oct 2024 18:05:14 +0200 Subject: [PATCH 2/5] fix: alternate row color paint --- .../src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java index db0cc821..65146698 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java @@ -577,7 +577,7 @@ public class FlatTreeUI if( alternateRowColor != null && row % 2 != 0 ) { g.setColor( alternateRowColor ); - FlatUIUtils.paintComponentBackground((Graphics2D) g, bounds.x, bounds.y, tree.getWidth(), bounds.height, 0, 0); + FlatUIUtils.paintComponentBackground((Graphics2D) g, 0, bounds.y, tree.getWidth(), bounds.height, 0, 0); } // do not paint row if editing From 8004d2761a66a8cc989ca5e1e402a050db6428d5 Mon Sep 17 00:00:00 2001 From: Dar Date: Wed, 23 Oct 2024 15:30:06 +0200 Subject: [PATCH 3/5] fix: respect the selection arc --- .../src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java index 65146698..82a3e3e9 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java @@ -577,7 +577,11 @@ public class FlatTreeUI if( alternateRowColor != null && row % 2 != 0 ) { g.setColor( alternateRowColor ); - FlatUIUtils.paintComponentBackground((Graphics2D) g, 0, bounds.y, tree.getWidth(), bounds.height, 0, 0); + + // paint respecting selection arc + final float arc = UIScale.scale( selectionArc / 2f ); + FlatUIUtils.paintSelection( (Graphics2D) g, 0, bounds.y, tree.getWidth(), bounds.height, + UIScale.scale( selectionInsets ), arc, arc, arc, arc, 0 ); } // do not paint row if editing From 6ac6698ecf8251d45c1b7d69c8af1fd31eaf52ef Mon Sep 17 00:00:00 2001 From: Dar Date: Wed, 23 Oct 2024 15:32:16 +0200 Subject: [PATCH 4/5] mod: added 3.6 tag --- .../src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java index 82a3e3e9..5933ae6e 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java @@ -142,7 +142,7 @@ public class FlatTreeUI @Styleable protected Color selectionInactiveBackground; @Styleable protected Color selectionInactiveForeground; @Styleable protected Color selectionBorderColor; - @Styleable protected Color alternateRowColor; + /** @since 3.6 */ @Styleable protected Color alternateRowColor; /** @since 3 */ @Styleable protected Insets selectionInsets; /** @since 3 */ @Styleable protected int selectionArc; @Styleable protected boolean wideSelection; From a20cfa6db331d7ade584287a542a54fdb8262718 Mon Sep 17 00:00:00 2001 From: Dar Date: Wed, 23 Oct 2024 15:36:17 +0200 Subject: [PATCH 5/5] mod: style tester --- .../test/java/com/formdev/flatlaf/ui/TestFlatStyleableValue.java | 1 + .../src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java | 1 + 2 files changed, 2 insertions(+) diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableValue.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableValue.java index ed4708fe..b5fab0a9 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableValue.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableValue.java @@ -938,6 +938,7 @@ public class TestFlatStyleableValue testColor( c, ui, "selectionInactiveBackground", 0x123456 ); testColor( c, ui, "selectionInactiveForeground", 0x123456 ); testColor( c, ui, "selectionBorderColor", 0x123456 ); + testColor( c, ui, "alternateRowColor", 0x123456 ); testInsets( c, ui, "selectionInsets", 1,2,3,4 ); testInteger( c, ui, "selectionArc", 123 ); testBoolean( c, ui, "wideSelection", true ); diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java index 204cf8be..621daa01 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java @@ -1187,6 +1187,7 @@ public class TestFlatStyling ui.applyStyle( "selectionInactiveBackground: #fff" ); ui.applyStyle( "selectionInactiveForeground: #fff" ); ui.applyStyle( "selectionBorderColor: #fff" ); + ui.applyStyle( "alternateRowColor: #fff" ); ui.applyStyle( "selectionInsets: 1,2,3,4" ); ui.applyStyle( "selectionArc: 8" ); ui.applyStyle( "wideSelection: true" );