From c9a38f0a1340581b40178a4aa86ef2c2e9a40969 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 7 Dec 2021 17:45:25 +0100 Subject: [PATCH] SwingX: new "column control" icon for `JXTable` that scales and uses antialiasing (issue #434) --- CHANGELOG.md | 4 +- .../swingx/icons/FlatColumnControlIcon.java | 68 +++++++++++++++++++ .../src/main/module-info/module-info.java | 1 + .../formdev/flatlaf/swingx/FlatLaf.properties | 6 ++ .../flatlaf/testing/FlatComponents2Test.java | 1 + 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/icons/FlatColumnControlIcon.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 95156014..539f053b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,7 +73,9 @@ FlatLaf Change Log - `FlatSVGIcon`: Support loading SVG from `URL` (for JPMS), `URI`, `File` or `InputStream`. (issues #419 and #325) - `FlatSVGUtils`: Support loading SVG from `URL` (for JPMS). (issue #325) - +- SwingX: + - New "column control" icon for `JXTable` that scales and uses antialiasing. + (issue #434) ## 1.6.5 diff --git a/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/icons/FlatColumnControlIcon.java b/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/icons/FlatColumnControlIcon.java new file mode 100644 index 00000000..7b3e2f3e --- /dev/null +++ b/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/icons/FlatColumnControlIcon.java @@ -0,0 +1,68 @@ +/* + * Copyright 2021 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 + * + * https://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.swingx.icons; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics2D; +import java.awt.geom.Area; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; +import javax.swing.UIManager; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.icon.ColumnControlIcon; +import com.formdev.flatlaf.icons.FlatAbstractIcon; +import com.formdev.flatlaf.ui.FlatUIUtils; + +/** + * Column control icon for {@link JXTable}. + * Replaces {@link ColumnControlIcon}. + * + * @author Karl Tauber + */ +public class FlatColumnControlIcon + extends FlatAbstractIcon +{ + protected Color iconColor = UIManager.getColor( "ColumnControlButton.iconColor" ); + + public FlatColumnControlIcon() { + super( 10, 10, null ); + } + + @Override + protected void paintIcon( Component c, Graphics2D g ) { + g.setColor( iconColor ); + + // table + Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD ); + path.append( new Rectangle2D.Float( 1, 0, 8, 8 ), false ); // table outline + path.append( new Rectangle2D.Float( 2, 1, 2, 1 ), false ); // subtract top left + path.append( new Rectangle2D.Float( 5, 1, 3, 1 ), false ); // subtract top right + path.append( new Rectangle2D.Float( 2, 3, 2, 4 ), false ); // subtract bottom left + path.append( new Rectangle2D.Float( 5, 3, 3, 4 ), false ); // subtract bottom right + + // subtract area for arrow from table + Area area = new Area( path ); + area.subtract( new Area( new Rectangle2D.Float( 3, 5, 7, 5 ) ) ); + + // paint table + g.fill( area ); + + // paint triangle arrow + g.fill( FlatUIUtils.createPath( 3,6, 6.5,10, 10,6 ) ); + } +} diff --git a/flatlaf-swingx/src/main/module-info/module-info.java b/flatlaf-swingx/src/main/module-info/module-info.java index 36afe50d..6e3ffc4f 100644 --- a/flatlaf-swingx/src/main/module-info/module-info.java +++ b/flatlaf-swingx/src/main/module-info/module-info.java @@ -23,6 +23,7 @@ module com.formdev.flatlaf.swingx { requires com.formdev.flatlaf; exports com.formdev.flatlaf.swingx; + exports com.formdev.flatlaf.swingx.icons; exports com.formdev.flatlaf.swingx.ui; // this allows com.formdev.flatlaf.FlatDefaultsAddon to read .properties files diff --git a/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatLaf.properties b/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatLaf.properties index 54e323ce..afa37b4b 100644 --- a/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatLaf.properties +++ b/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatLaf.properties @@ -25,6 +25,12 @@ swingx/TaskPaneUI = com.formdev.flatlaf.swingx.ui.FlatTaskPaneUI TitledPanelUI = com.formdev.flatlaf.swingx.ui.FlatTitledPanelUI +#---- ColumnControlButton ---- + +ColumnControlButton.actionIcon = com.formdev.flatlaf.swingx.icons.FlatColumnControlIcon +ColumnControlButton.iconColor = @disabledForeground + + #---- DatePicker ---- JXDatePicker.border = com.formdev.flatlaf.swingx.ui.FlatDatePickerBorder diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java index 6c36afe2..54aae794 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java @@ -117,6 +117,7 @@ public class FlatComponents2Test ColorHighlighter rollover = new ColorHighlighter( HighlightPredicate.ROLLOVER_ROW, Color.cyan, null ); Highlighter shading = new ShadingColorHighlighter( new HighlightPredicate.ColumnHighlightPredicate( 1 ) ); xTable1.setHighlighters( simpleStriping, magenta, rollover, shading ); + xTable1.setColumnControlVisible( true ); // JXTreeTable xTreeTable1.setTreeTableModel( new FileSystemModel( new File( "." ) ) );