Table: allow disabling swapped behavior of Home/End and Ctrl+Home/End with Table.consistentHomeEndKeyBehavior=false (issue #95)

This commit is contained in:
Karl Tauber
2020-07-27 17:54:12 +02:00
parent a8423f7741
commit e3cda9905a
6 changed files with 27 additions and 15 deletions

View File

@@ -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> 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] );

View File

@@ -71,6 +71,10 @@ import com.formdev.flatlaf.util.UIScale;
* @uiDefault Table.cellFocusColor Color
* @uiDefault Table.showCellFocusIndicator boolean
*
* <!-- FlatInputMaps -->
*
* @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();

View File

@@ -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

View File

@@ -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]

View File

@@ -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]

View File

@@ -665,6 +665,7 @@ Table.background
Table.cellFocusColor
Table.cellMargins
Table.cellNoFocusBorder
Table.consistentHomeEndKeyBehavior
Table.descendingSortIcon
Table.dropCellBackground
Table.dropCellForeground