From 122afeb9732025698125d9511029666e5cf128b3 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Mon, 2 Sep 2019 22:17:00 +0200 Subject: [PATCH] Table basic implementation --- .../com/formdev/flatlaf/ui/FlatTableUI.java | 49 +++++++++++++++++++ .../formdev/flatlaf/FlatDarkLaf.properties | 6 +++ .../com/formdev/flatlaf/FlatLaf.properties | 3 ++ .../formdev/flatlaf/FlatLightLaf.properties | 6 +++ .../formdev/flatlaf/FlatComponents2Test.java | 10 ++-- .../formdev/flatlaf/FlatComponents2Test.jfd | 6 +++ .../formdev/flatlaf/FlatTestLaf.properties | 3 ++ 7 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java 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 new file mode 100644 index 00000000..7757e9ae --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java @@ -0,0 +1,49 @@ +/* + * Copyright 2019 FormDev Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.formdev.flatlaf.ui; + +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicTableUI; +import com.formdev.flatlaf.util.UIScale; + +/** + * Provides the Flat LaF UI delegate for {@link javax.swing.JTable}. + * + * TODO document used UI defaults of superclass + * + * @uiDefault Table.rowHeight int + * + * @author Karl Tauber + */ +public class FlatTableUI + extends BasicTableUI +{ + public static ComponentUI createUI( JComponent c ) { + return new FlatTableUI(); + } + + @Override + protected void installDefaults() { + super.installDefaults(); + + int rowHeight = FlatUIUtils.getUIInt( "Table.rowHeight", 16 ); + if( rowHeight > 0 ) + LookAndFeel.installProperty( table, "rowHeight", UIScale.scale( rowHeight ) ); + } +} diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties index cd12d36a..3415afcc 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties @@ -169,6 +169,12 @@ TabbedPane.focusColor=3d4b5c TabbedPane.contentAreaColor=323232 +#---- Table ---- + +Table.background=@textComponentBackground +Table.gridColor=4F5152 + + #---- TableHeader ---- TableHeader.background=45494A 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 58af58cb..b38a0c44 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -39,6 +39,7 @@ SliderUI=com.formdev.flatlaf.ui.FlatSliderUI SpinnerUI=com.formdev.flatlaf.ui.FlatSpinnerUI SplitPaneUI=com.formdev.flatlaf.ui.FlatSplitPaneUI TabbedPaneUI=com.formdev.flatlaf.ui.FlatTabbedPaneUI +TableUI=com.formdev.flatlaf.ui.FlatTableUI TableHeaderUI=com.formdev.flatlaf.ui.FlatTableHeaderUI TextAreaUI=com.formdev.flatlaf.ui.FlatTextAreaUI TextFieldUI=com.formdev.flatlaf.ui.FlatTextFieldUI @@ -218,6 +219,8 @@ TabbedPane.shadow=@@ComboBox.buttonArrowColor #---- Table ---- +Table.rowHeight=20 +Table.scrollPaneBorder=com.formdev.flatlaf.ui.FlatBorder Table.ascendingSortIcon=com.formdev.flatlaf.icons.FlatAscendingSortIcon Table.descendingSortIcon=com.formdev.flatlaf.icons.FlatDescendingSortIcon Table.sortIconColor=@icon diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties index e41e6f9e..d74d0a59 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties @@ -169,6 +169,12 @@ TabbedPane.focusColor=dae4ed TabbedPane.contentAreaColor=bfbfbf +#---- Table ---- + +Table.background=@textComponentBackground +Table.gridColor=F7F7F7 + + #---- TableHeader ---- TableHeader.background=ffffff diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.java index a89baad8..da973a27 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.java @@ -178,18 +178,18 @@ public class FlatComponents2Test //---- table1 ---- table1.setModel(new DefaultTableModel( new Object[][] { - {"Item 1a", "Item 2a", "January", "July", null}, - {"Item 1b", "Item 2b", "February", "August", true}, + {"Item 1a", "Item 2a", "January", "July", 123, null}, + {"Item 1b", "Item 2b", "February", "August", 456, true}, }, new String[] { - "Not editable", "Text", "Combo", "Combo Editable", "Boolean" + "Not editable", "Text", "Combo", "Combo Editable", "Integer", "Boolean" } ) { Class[] columnTypes = new Class[] { - Object.class, Object.class, String.class, String.class, Boolean.class + Object.class, Object.class, String.class, String.class, Integer.class, Boolean.class }; boolean[] columnEditable = new boolean[] { - false, true, true, true, true + false, true, true, true, true, true }; @Override public Class getColumnClass(int columnIndex) { diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.jfd b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.jfd index e7946227..60e1d5dd 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.jfd +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.jfd @@ -131,6 +131,7 @@ new FormModel { add( "Item 2a" ) add( "January" ) add( "July" ) + add( 123 ) add( null ) } ) add( new java.util.Vector { @@ -138,6 +139,7 @@ new FormModel { add( "Item 2b" ) add( "February" ) add( "August" ) + add( 456 ) add( true ) } ) }, new java.util.Vector { @@ -145,12 +147,14 @@ new FormModel { add( "Text" ) add( "Combo" ) add( "Combo Editable" ) + add( "Integer" ) add( "Boolean" ) }, new java.util.Vector { add( null ) add( null ) add( class java.lang.String ) add( class java.lang.String ) + add( class java.lang.Integer ) add( class java.lang.Boolean ) }, new java.util.Vector { add( false ) @@ -158,12 +162,14 @@ new FormModel { add( null ) add( null ) add( null ) + add( null ) }, new java.util.Vector { add( null ) add( null ) add( new com.jformdesigner.model.SwingTableColumn( new java.lang.Object[ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], 0, 0, 0, true ) ) add( new com.jformdesigner.model.SwingTableColumn( new java.lang.Object[ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], 0, 0, 0, true ) ) add( null ) + add( null ) } ) "autoCreateRowSorter": true } ) diff --git a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties index 7bf14aa9..f3bbda7a 100644 --- a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties +++ b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties @@ -181,7 +181,10 @@ TabbedPane.contentAreaColor=bbbbbb #---- Table ---- +Table.rowHeight=25 +Table.background=fffff0 Table.sortIconColor=ffff00 +Table.gridColor=00ffff #---- TableHeader ----