diff --git a/CHANGELOG.md b/CHANGELOG.md index 44de89bf..c303a4bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ FlatLaf Change Log - ComboBox: Use small border if used as table editor. - ToolBar: Disable focusability of buttons in toolbar. +- SwingX: Support `JXHeader`, `JXHyperlink`, `JXTaskPaneContainer` and + `JXTaskPane`. (issue #8) ## 0.13 diff --git a/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatHeaderUI.java b/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatHeaderUI.java new file mode 100644 index 00000000..a7bea0c9 --- /dev/null +++ b/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatHeaderUI.java @@ -0,0 +1,71 @@ +/* + * 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.swingx.ui; + +import java.awt.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.LayoutManager; +import javax.swing.JComponent; +import javax.swing.plaf.ComponentUI; +import org.jdesktop.swingx.JXHeader; +import org.jdesktop.swingx.plaf.basic.BasicHeaderUI; +import com.formdev.flatlaf.util.UIScale; + +/** + * Provides the Flat LaF UI delegate for {@link org.jdesktop.swingx.JXHeader}. + * + * @author Karl Tauber + */ +public class FlatHeaderUI + extends BasicHeaderUI +{ + public static ComponentUI createUI( JComponent c ) { + return new FlatHeaderUI(); + } + + @Override + protected void installComponents( JXHeader header ) { + super.installComponents( header ); + + scaleLayout( header ); + } + + @Override + protected void onPropertyChange( JXHeader h, String propertyName, Object oldValue, Object newValue ) { + super.onPropertyChange( h, propertyName, oldValue, newValue ); + + if( "iconPosition".equals( propertyName ) ) + scaleLayout( h ); + } + + private void scaleLayout( JXHeader header ) { + if( UIScale.getUserScaleFactor() == 1f ) + return; + + LayoutManager layout = header.getLayout(); + if( !(layout instanceof GridBagLayout) ) + return; + + GridBagLayout gbl = (GridBagLayout) layout; + for( Component c : header.getComponents() ) { + GridBagConstraints cons = gbl.getConstraints( c ); + cons.insets = UIScale.scale( cons.insets ); + gbl.setConstraints( c, cons ); + } + } +} diff --git a/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatDarkLaf.properties b/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatDarkLaf.properties index 305fb0bc..e221d51c 100644 --- a/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatDarkLaf.properties +++ b/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatDarkLaf.properties @@ -14,6 +14,12 @@ # limitations under the License. # +#---- Header ---- + +JXHeader.background=@background +JXHeader.startBackground=4c5052 + + #---- Hyperlink ---- Hyperlink.linkColor=589df6 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 0ec0bfac..0906acce 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 @@ -16,5 +16,6 @@ #---- UI delegates ---- +HeaderUI=com.formdev.flatlaf.swingx.ui.FlatHeaderUI HyperlinkUI=com.formdev.flatlaf.swingx.ui.FlatHyperlinkUI swingx/TaskPaneUI=com.formdev.flatlaf.swingx.ui.FlatTaskPaneUI diff --git a/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatLightLaf.properties b/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatLightLaf.properties index 6753b290..fc54234a 100644 --- a/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatLightLaf.properties +++ b/flatlaf-swingx/src/main/resources/com/formdev/flatlaf/swingx/FlatLightLaf.properties @@ -14,6 +14,12 @@ # limitations under the License. # +#---- Header ---- + +JXHeader.background=@background +JXHeader.startBackground=ffffff + + #---- Hyperlink ---- Hyperlink.linkColor=4a78c2 diff --git a/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.java b/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.java index 29856471..1b6fb372 100644 --- a/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.java +++ b/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.java @@ -59,6 +59,8 @@ public class FlatSwingXTest JXTaskPane xTaskPane6 = new JXTaskPane(); JXHyperlink xHyperlink9 = new JXHyperlink(); JXHyperlink xHyperlink10 = new JXHyperlink(); + JLabel headerLabel = new JLabel(); + JXHeader xHeader1 = new JXHeader(); //======== this ======== setLayout(new MigLayout( @@ -69,6 +71,7 @@ public class FlatSwingXTest "[]", // rows "[]" + + "[]" + "[]")); //---- hyperlinkLabel ---- @@ -176,6 +179,16 @@ public class FlatSwingXTest scrollPane1.setViewportView(xTaskPaneContainer1); } add(scrollPane1, "cell 1 1,width 150,height 350"); + + //---- headerLabel ---- + headerLabel.setText("JXHeader:"); + add(headerLabel, "cell 0 2"); + + //---- xHeader1 ---- + xHeader1.setTitle("Title"); + xHeader1.setDescription("Description\nMore description"); + xHeader1.setIcon(new ImageIcon(getClass().getResource("/org/jdesktop/swingx/plaf/windows/resources/tipoftheday.png"))); + add(xHeader1, "cell 1 2 2 1,width 200"); // JFormDesigner - End of component initialization //GEN-END:initComponents } diff --git a/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.jfd b/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.jfd index b7c35bb2..9a69cf6d 100644 --- a/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.jfd +++ b/flatlaf-swingx/src/test/java/com/formdev/flatlaf/swingx/FlatSwingXTest.jfd @@ -9,7 +9,7 @@ new FormModel { add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "hidemode 3,ltr" "$columnConstraints": "[left][][]" - "$rowConstraints": "[][]" + "$rowConstraints": "[][][]" } ) { name: "this" add( new FormComponent( "javax.swing.JLabel" ) { @@ -111,6 +111,20 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 1,width 150,height 350" } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "headerLabel" + "text": "JXHeader:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 2" + } ) + add( new FormComponent( "org.jdesktop.swingx.JXHeader" ) { + name: "xHeader1" + "title": "Title" + "description": "Description\nMore description" + "icon": new com.jformdesigner.model.SwingIcon( 0, "/org/jdesktop/swingx/plaf/windows/resources/tipoftheday.png" ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 2 2 1,width 200" + } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) "size": new java.awt.Dimension( 645, 600 ) diff --git a/flatlaf-swingx/src/test/resources/com/formdev/flatlaf/swingx/FlatTestLaf.properties b/flatlaf-swingx/src/test/resources/com/formdev/flatlaf/swingx/FlatTestLaf.properties index fb1be16c..f388fed7 100644 --- a/flatlaf-swingx/src/test/resources/com/formdev/flatlaf/swingx/FlatTestLaf.properties +++ b/flatlaf-swingx/src/test/resources/com/formdev/flatlaf/swingx/FlatTestLaf.properties @@ -14,6 +14,14 @@ # limitations under the License. # +#---- Header ---- + +JXHeader.background=ff8888 +JXHeader.startBackground=ffcccc +JXHeader.titleForeground=0000ff +JXHeader.descriptionForeground=ff0000 + + #---- Hyperlink ---- Hyperlink.linkColor=ff0000