diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatInputMaps.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatInputMaps.java index cbe54d2a..7a463291 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatInputMaps.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatInputMaps.java @@ -22,9 +22,11 @@ import javax.swing.KeyStroke; import javax.swing.LookAndFeel; import javax.swing.UIDefaults; import javax.swing.UIDefaults.LazyValue; +import javax.swing.UIManager; import javax.swing.plaf.InputMapUIResource; import com.formdev.flatlaf.util.SystemInfo; import static javax.swing.text.DefaultEditorKit.*; +import java.util.function.BooleanSupplier; /** * @author Karl Tauber @@ -81,8 +83,11 @@ class FlatInputMaps "shift ctrl TAB", "navigatePrevious" ); - modifyInputMap( defaults, "Table.ancestorInputMap", - // swap to make it consistent with List and Tree + // swap Home/End with Ctrl+Home/End to make it consistent with List and Tree + modifyInputMap( () -> { + return UIManager.getBoolean( "Table.consistentHomeEndKeyBehavior" ); + }, + defaults, "Table.ancestorInputMap", "HOME", "selectFirstRow", "END", "selectLastRow", "shift HOME", "selectFirstRowExtendSelection", @@ -574,8 +579,12 @@ class FlatInputMaps } private static void modifyInputMap( UIDefaults defaults, String key, Object... bindings ) { - // Note: not using `defaults.get(key)` here because this would resolve the lazy value - defaults.put( key, new LazyModifyInputMap( defaults.remove( key ), bindings ) ); + modifyInputMap( null, defaults, key, bindings ); + } + + private static void modifyInputMap( BooleanSupplier condition, UIDefaults defaults, String key, Object... bindings ) { + // Note: not using `defaults.get(key)` here because this would resolve a lazy value + defaults.put( key, new LazyModifyInputMap( condition, defaults.remove( key ), bindings ) ); } private static T mac( T value, T macValue ) { @@ -614,10 +623,12 @@ class FlatInputMaps private static class LazyModifyInputMap implements LazyValue { + private final BooleanSupplier condition; private final Object baseInputMap; private final Object[] bindings; - LazyModifyInputMap( Object baseInputMap, Object[] bindings ) { + LazyModifyInputMap( BooleanSupplier condition, Object baseInputMap, Object[] bindings ) { + this.condition = condition; this.baseInputMap = baseInputMap; this.bindings = bindings; } @@ -629,6 +640,9 @@ class FlatInputMaps ? (InputMap) ((LazyValue)baseInputMap).createValue( table ) : (InputMap) baseInputMap; + if( condition != null && !condition.getAsBoolean() ) + return inputMap; + // modify input map (replace or remove) for( int i = 0; i < bindings.length; i += 2 ) { KeyStroke keyStroke = KeyStroke.getKeyStroke( (String) bindings[i] ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java index 12f0a43a..3f171417 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java @@ -71,6 +71,10 @@ import com.formdev.flatlaf.util.UIScale; * @uiDefault Table.cellFocusColor Color * @uiDefault Table.showCellFocusIndicator boolean * + * + * + * @uiDefault Table.consistentHomeEndKeyBehavior boolean + * * @author Karl Tauber */ public class FlatTableUI @@ -93,16 +97,6 @@ public class FlatTableUI return new FlatTableUI(); } - @Override - public void installUI( JComponent c ) { - super.installUI( c ); - } - - @Override - public void uninstallUI( JComponent c ) { - super.uninstallUI( c ); - } - @Override protected void installDefaults() { super.installDefaults(); diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties index 4c004423..ca60fa56 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -530,6 +530,7 @@ TabbedPane.contentBorderInsets=null Table.rowHeight=20 Table.showHorizontalLines=false Table.showVerticalLines=false +Table.consistentHomeEndKeyBehavior=true Table.intercellSpacing={dimension}0,0 Table.scrollPaneBorder=com.formdev.flatlaf.ui.FlatBorder Table.ascendingSortIcon=com.formdev.flatlaf.icons.FlatAscendingSortIcon diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt index 3a62a9d7..73055251 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt @@ -937,6 +937,7 @@ Table.background #45494a javax.swing.plaf.ColorUIResource [UI] Table.cellFocusColor #000000 javax.swing.plaf.ColorUIResource [UI] Table.cellMargins 2,3,2,3 javax.swing.plaf.InsetsUIResource [UI] Table.cellNoFocusBorder [lazy] 2,3,2,3 false com.formdev.flatlaf.ui.FlatTableCellBorder$Default [UI] lineColor=#000000 javax.swing.plaf.ColorUIResource [UI] lineThickness=1.000000 +Table.consistentHomeEndKeyBehavior true Table.descendingSortIcon [lazy] 10,5 com.formdev.flatlaf.icons.FlatDescendingSortIcon [UI] Table.dropCellBackground [lazy] #3c588b javax.swing.plaf.ColorUIResource [UI] Table.dropCellForeground [lazy] #bbbbbb javax.swing.plaf.ColorUIResource [UI] diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt index d1bb5c28..e5f6d1e6 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt @@ -942,6 +942,7 @@ Table.background #ffffff javax.swing.plaf.ColorUIResource [UI] Table.cellFocusColor #000000 javax.swing.plaf.ColorUIResource [UI] Table.cellMargins 2,3,2,3 javax.swing.plaf.InsetsUIResource [UI] Table.cellNoFocusBorder [lazy] 2,3,2,3 false com.formdev.flatlaf.ui.FlatTableCellBorder$Default [UI] lineColor=#000000 javax.swing.plaf.ColorUIResource [UI] lineThickness=1.000000 +Table.consistentHomeEndKeyBehavior true Table.descendingSortIcon [lazy] 10,5 com.formdev.flatlaf.icons.FlatDescendingSortIcon [UI] Table.dropCellBackground [lazy] #3f8fd9 javax.swing.plaf.ColorUIResource [UI] Table.dropCellForeground [lazy] #ffffff javax.swing.plaf.ColorUIResource [UI] 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 a4b55754..6cd70c7b 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 @@ -665,6 +665,7 @@ Table.background Table.cellFocusColor Table.cellMargins Table.cellNoFocusBorder +Table.consistentHomeEndKeyBehavior Table.descendingSortIcon Table.dropCellBackground Table.dropCellForeground