From d81e07f03a0cce830fdfb2e06535184ad7fe2ddd Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Mon, 2 Sep 2019 17:45:29 +0200 Subject: [PATCH] Table: ascendingSortIcon and descendingSortIcon icons added --- .../flatlaf/icons/FlatAscendingSortIcon.java | 52 +++++++++++++++++++ .../flatlaf/icons/FlatDescendingSortIcon.java | 52 +++++++++++++++++++ .../com/formdev/flatlaf/FlatLaf.properties | 7 +++ .../formdev/flatlaf/FlatComponents2Test.java | 1 + .../formdev/flatlaf/FlatComponents2Test.jfd | 1 + .../formdev/flatlaf/FlatTestLaf.properties | 5 ++ 6 files changed, 118 insertions(+) create mode 100644 flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatAscendingSortIcon.java create mode 100644 flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatDescendingSortIcon.java diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatAscendingSortIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatAscendingSortIcon.java new file mode 100644 index 00000000..d8b079ff --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatAscendingSortIcon.java @@ -0,0 +1,52 @@ +/* + * 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.icons; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics2D; +import java.awt.geom.Path2D; +import javax.swing.UIManager; + +/** + * "ascendingSort" icon for {@link javax.swing.table.JTableHeader}. + * + * @uiDefault Table.sortIconColor Color + * + * @author Karl Tauber + */ +public class FlatAscendingSortIcon + extends FlatAbstractIcon +{ + protected final Color sortIconColor = UIManager.getColor( "Table.sortIconColor" ); + + public FlatAscendingSortIcon() { + super( 10, 5, null ); + } + + @Override + protected void paintIcon( Component c, Graphics2D g ) { + Path2D arrow = new Path2D.Float(); + arrow.moveTo( 0.5, 5 ); + arrow.lineTo( 9.5, 5 ); + arrow.lineTo( 5, 0 ); + arrow.closePath(); + + g.setColor( sortIconColor ); + g.fill( arrow ); + } +} diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatDescendingSortIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatDescendingSortIcon.java new file mode 100644 index 00000000..9c1c7bf5 --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatDescendingSortIcon.java @@ -0,0 +1,52 @@ +/* + * 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.icons; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics2D; +import java.awt.geom.Path2D; +import javax.swing.UIManager; + +/** + * "descendingSort" icon for {@link javax.swing.table.JTableHeader}. + * + * @uiDefault Table.sortIconColor Color + * + * @author Karl Tauber + */ +public class FlatDescendingSortIcon + extends FlatAbstractIcon +{ + protected final Color sortIconColor = UIManager.getColor( "Table.sortIconColor" ); + + public FlatDescendingSortIcon() { + super( 10, 5, null ); + } + + @Override + protected void paintIcon( Component c, Graphics2D g ) { + Path2D arrow = new Path2D.Float(); + arrow.moveTo( 0.5, 0 ); + arrow.lineTo( 9.5, 0 ); + arrow.lineTo( 5, 5 ); + arrow.closePath(); + + g.setColor( sortIconColor ); + g.fill( arrow ); + } +} 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 c6be563d..58af58cb 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -216,6 +216,13 @@ TabbedPane.tabsOverlapBorder=true TabbedPane.shadow=@@ComboBox.buttonArrowColor +#---- Table ---- + +Table.ascendingSortIcon=com.formdev.flatlaf.icons.FlatAscendingSortIcon +Table.descendingSortIcon=com.formdev.flatlaf.icons.FlatDescendingSortIcon +Table.sortIconColor=@icon + + #---- TableHeader ---- TableHeader.height=25 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 93bc8505..a89baad8 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.java @@ -233,6 +233,7 @@ public class FlatComponents2Test "December" })))); } + table1.setAutoCreateRowSorter(true); scrollPane5.setViewportView(table1); } add(scrollPane5, "cell 1 4 2 1,growx,width 300"); 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 28a3545d..e7946227 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.jfd +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/FlatComponents2Test.jfd @@ -165,6 +165,7 @@ new FormModel { 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 ) } ) + "autoCreateRowSorter": true } ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 4 2 1,growx,width 300" 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 51c6c7bb..7bf14aa9 100644 --- a/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties +++ b/flatlaf-core/src/test/resources/com/formdev/flatlaf/FlatTestLaf.properties @@ -179,6 +179,11 @@ TabbedPane.focusColor=dddddd TabbedPane.contentAreaColor=bbbbbb +#---- Table ---- + +Table.sortIconColor=ffff00 + + #---- TableHeader ---- TableHeader.background=4444ff