From 60febbf3f8014399c9c505a94f2a89543a1d9fde Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sun, 22 Dec 2019 11:38:32 +0100 Subject: [PATCH] Table: hide grid and changed intercell spacing to zero --- CHANGELOG.md | 1 + .../com/formdev/flatlaf/UIDefaultsLoader.java | 8 ++-- .../com/formdev/flatlaf/ui/FlatTableUI.java | 48 +++++++++++++++++++ .../com/formdev/flatlaf/FlatLaf.properties | 2 + 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e74640b..920fa4a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ FlatLaf Change Log "IntelliJ Light Theme", which provides blue coloring that better match platform colors. - Tree: Support wide selection (enabled by default). +- Table: Hide grid and changed intercell spacing to zero. - List and Tree: Paint cell focus indicator (black rectangle) only if more than one item is selected. - Fixed link color (in HTML text) and separator color in IntelliJ platform diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java index 93f5c8be..be889a40 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java @@ -203,7 +203,7 @@ class UIDefaultsLoader return resolveValue( properties, newValue ); } - private enum ValueType { UNKNOWN, STRING, INTEGER, BORDER, ICON, INSETS, SIZE, COLOR, SCALEDINTEGER, INSTANCE, CLASS } + private enum ValueType { UNKNOWN, STRING, INTEGER, BORDER, ICON, INSETS, DIMENSION, COLOR, SCALEDINTEGER, INSTANCE, CLASS } static Object parseValue( String key, String value ) { return parseValue( key, value, v -> v, Collections.emptyList() ); @@ -251,7 +251,7 @@ class UIDefaultsLoader key.endsWith( "Margins" ) || key.endsWith( "Insets" ) ) valueType = ValueType.INSETS; else if( key.endsWith( "Size" ) ) - valueType = ValueType.SIZE; + valueType = ValueType.DIMENSION; else if( key.endsWith( "Width" ) || key.endsWith( "Height" ) ) valueType = ValueType.INTEGER; else if( key.endsWith( "UI" ) ) @@ -265,7 +265,7 @@ class UIDefaultsLoader case BORDER: return parseBorder( value, resolver, addonClassLoaders ); case ICON: return parseInstance( value, addonClassLoaders ); case INSETS: return parseInsets( value ); - case SIZE: return parseSize( value ); + case DIMENSION: return parseDimension( value ); case COLOR: return parseColorOrFunction( value, true ); case SCALEDINTEGER: return parseScaledInteger( value ); case INSTANCE: return parseInstance( value, addonClassLoaders ); @@ -358,7 +358,7 @@ class UIDefaultsLoader } } - private static Dimension parseSize( String value ) { + private static Dimension parseDimension( String value ) { List numbers = StringUtils.split( value, ',' ); try { return new DimensionUIResource( 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 dc04435f..27d9553a 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 @@ -17,6 +17,7 @@ package com.formdev.flatlaf.ui; import java.awt.Color; +import java.awt.Dimension; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import javax.swing.JComponent; @@ -55,6 +56,8 @@ import com.formdev.flatlaf.util.UIScale; * * * @uiDefault Table.rowHeight int + * @uiDefault Table.showGrid boolean + * @uiDefault Table.intercellSpacing Dimension * @uiDefault Table.selectionInactiveBackground Color * @uiDefault Table.selectionInactiveForeground Color * @@ -63,19 +66,39 @@ import com.formdev.flatlaf.util.UIScale; public class FlatTableUI extends BasicTableUI { + protected boolean showGrid; + protected Dimension intercellSpacing; + protected Color selectionBackground; protected Color selectionForeground; protected Color selectionInactiveBackground; protected Color selectionInactiveForeground; + private boolean oldShowHorizontalLines; + private boolean oldShowVerticalLines; + private Dimension oldIntercellSpacing; + public static ComponentUI createUI( JComponent c ) { 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(); + showGrid = UIManager.getBoolean( "Table.showGrid" ); + intercellSpacing = UIManager.getDimension( "Table.intercellSpacing" ); + selectionBackground = UIManager.getColor( "Table.selectionBackground" ); selectionForeground = UIManager.getColor( "Table.selectionForeground" ); selectionInactiveBackground = UIManager.getColor( "Table.selectionInactiveBackground" ); @@ -86,6 +109,17 @@ public class FlatTableUI int rowHeight = FlatUIUtils.getUIInt( "Table.rowHeight", 16 ); if( rowHeight > 0 ) LookAndFeel.installProperty( table, "rowHeight", UIScale.scale( rowHeight ) ); + + if( !showGrid ) { + oldShowHorizontalLines = table.getShowHorizontalLines(); + oldShowVerticalLines = table.getShowVerticalLines(); + table.setShowGrid( false ); + } + + if( intercellSpacing != null ) { + oldIntercellSpacing = table.getIntercellSpacing(); + table.setIntercellSpacing( intercellSpacing ); + } } @Override @@ -96,6 +130,20 @@ public class FlatTableUI selectionForeground = null; selectionInactiveBackground = null; selectionInactiveForeground = null; + + // restore old show grid + if( !showGrid ) { + if( !table.getShowHorizontalLines() ) + table.setShowHorizontalLines( oldShowHorizontalLines ); + if( !table.getShowVerticalLines() ) + table.setShowVerticalLines( oldShowVerticalLines ); + } + + // restore old intercell spacing + if( intercellSpacing != null ) { + if( table.getIntercellSpacing().equals( intercellSpacing ) ) + table.setIntercellSpacing( oldIntercellSpacing ); + } } @Override 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 526784fc..f4d2424f 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -366,6 +366,8 @@ TabbedPane.shadow=@@ComboBox.buttonArrowColor #---- Table ---- Table.rowHeight=20 +Table.showGrid=false +Table.intercellSpacing={dimension}0,0 Table.scrollPaneBorder=com.formdev.flatlaf.ui.FlatBorder Table.ascendingSortIcon=com.formdev.flatlaf.icons.FlatAscendingSortIcon Table.descendingSortIcon=com.formdev.flatlaf.icons.FlatDescendingSortIcon