diff --git a/CHANGELOG.md b/CHANGELOG.md index c303a4bf..b3f4975f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +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) +- SwingX: Support `JXBusyLabel`, `JXHeader`, `JXHyperlink`, + `JXTaskPaneContainer` and `JXTaskPane`. (issue #8) ## 0.13 diff --git a/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatBusyLabelUI.java b/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatBusyLabelUI.java new file mode 100644 index 00000000..b029c814 --- /dev/null +++ b/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatBusyLabelUI.java @@ -0,0 +1,79 @@ +/* + * 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.Color; +import java.awt.Graphics; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import org.jdesktop.swingx.JXBusyLabel; +import org.jdesktop.swingx.plaf.basic.BasicBusyLabelUI; +import com.formdev.flatlaf.FlatLaf; +import com.formdev.flatlaf.ui.FlatUIUtils; + +//TODO scale busy spinner + +/** + * Provides the Flat LaF UI delegate for {@link org.jdesktop.swingx.JXBusyLabel}. + * + * @author Karl Tauber + */ +public class FlatBusyLabelUI + extends BasicBusyLabelUI +{ + private Color disabledForeground; + + public static ComponentUI createUI( JComponent c ) { + return new FlatBusyLabelUI( (JXBusyLabel) c ); + } + + public FlatBusyLabelUI( JXBusyLabel busyLabel ) { + super( busyLabel ); + } + + @Override + protected void installDefaults( JLabel c ) { + super.installDefaults( c ); + + disabledForeground = UIManager.getColor( "Label.disabledForeground" ); + + // force recreation of busy painter for correct colors when switching LaF + if( c.getIcon() != null ) { + JXBusyLabel busyLabel = (JXBusyLabel) c; + boolean oldBusy = busyLabel.isBusy(); + busyLabel.setBusy( false ); + busyLabel.setBusyPainter( null ); + busyLabel.setBusy( oldBusy ); + } + } + + @Override + protected void uninstallDefaults( JLabel c ) { + super.uninstallDefaults( c ); + + disabledForeground = null; + } + + @Override + protected void paintDisabledText( JLabel l, Graphics g, String s, int textX, int textY ) { + int mnemIndex = FlatLaf.isShowMnemonics() ? l.getDisplayedMnemonicIndex() : -1; + g.setColor( disabledForeground ); + FlatUIUtils.drawStringUnderlineCharAt( l, g, s, mnemIndex, textX, textY ); + } +} 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 e221d51c..286d11a9 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. # +#---- BusyLabel ---- + +JXBusyLabel.baseColor=777777 +JXBusyLabel.highlightColor=e0e0e0 + + #---- Header ---- JXHeader.background=@background 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 0906acce..5d6efade 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,6 +16,7 @@ #---- UI delegates ---- +BusyLabelUI=com.formdev.flatlaf.swingx.ui.FlatBusyLabelUI 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 fc54234a..3fe879b6 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. # +#---- BusyLabel ---- + +JXBusyLabel.baseColor=c4c4c4 +JXBusyLabel.highlightColor=808080 + + #---- Header ---- JXHeader.background=@background 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 1b6fb372..d0b21566 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 @@ -37,11 +37,21 @@ public class FlatSwingXTest initComponents(); } + private void busyChanged() { + boolean busy = busyCheckBox.isSelected(); + xBusyLabel1.setBusy( busy ); + xBusyLabel2.setBusy( busy ); + } + private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents JLabel hyperlinkLabel = new JLabel(); JXHyperlink xHyperlink1 = new JXHyperlink(); JXHyperlink xHyperlink2 = new JXHyperlink(); + JLabel label2 = new JLabel(); + xBusyLabel1 = new JXBusyLabel(); + xBusyLabel2 = new JXBusyLabel(); + busyCheckBox = new JCheckBox(); JPanel panel1 = new JPanel(); JLabel taskPaneContainerLabel = new JLabel(); JLabel taskPaneLabel = new JLabel(); @@ -68,10 +78,12 @@ public class FlatSwingXTest // columns "[left]" + "[]" + + "[]" + "[]", // rows "[]" + "[]" + + "[]" + "[]")); //---- hyperlinkLabel ---- @@ -87,6 +99,25 @@ public class FlatSwingXTest xHyperlink2.setEnabled(false); add(xHyperlink2, "cell 2 0"); + //---- label2 ---- + label2.setText("JXBusyLabel:"); + add(label2, "cell 0 1"); + + //---- xBusyLabel1 ---- + xBusyLabel1.setText("enabled"); + add(xBusyLabel1, "cell 1 1"); + + //---- xBusyLabel2 ---- + xBusyLabel2.setText("disabled"); + xBusyLabel2.setEnabled(false); + add(xBusyLabel2, "cell 2 1"); + + //---- busyCheckBox ---- + busyCheckBox.setText("busy"); + busyCheckBox.setMnemonic('B'); + busyCheckBox.addActionListener(e -> busyChanged()); + add(busyCheckBox, "cell 3 1"); + //======== panel1 ======== { panel1.setLayout(new MigLayout( @@ -105,7 +136,7 @@ public class FlatSwingXTest taskPaneLabel.setText("JXTaskPane:"); panel1.add(taskPaneLabel, "cell 0 1"); } - add(panel1, "cell 0 1,aligny top,growy 0"); + add(panel1, "cell 0 2,aligny top,growy 0"); //======== scrollPane1 ======== { @@ -178,20 +209,23 @@ public class FlatSwingXTest } scrollPane1.setViewportView(xTaskPaneContainer1); } - add(scrollPane1, "cell 1 1,width 150,height 350"); + add(scrollPane1, "cell 1 2,width 150,height 350"); //---- headerLabel ---- headerLabel.setText("JXHeader:"); - add(headerLabel, "cell 0 2"); + add(headerLabel, "cell 0 3"); //---- 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"); + add(xHeader1, "cell 1 3 2 1,width 200"); // JFormDesigner - End of component initialization //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables + private JXBusyLabel xBusyLabel1; + private JXBusyLabel xBusyLabel2; + private JCheckBox busyCheckBox; // JFormDesigner - End of variables declaration //GEN-END:variables } 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 9a69cf6d..12bc2644 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 @@ -8,8 +8,8 @@ new FormModel { } add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "hidemode 3,ltr" - "$columnConstraints": "[left][][]" - "$rowConstraints": "[][][]" + "$columnConstraints": "[left][][][]" + "$rowConstraints": "[][][][]" } ) { name: "this" add( new FormComponent( "javax.swing.JLabel" ) { @@ -31,6 +31,42 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 2 0" } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label2" + "text": "JXBusyLabel:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 1" + } ) + add( new FormComponent( "org.jdesktop.swingx.JXBusyLabel" ) { + name: "xBusyLabel1" + "text": "enabled" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 1" + } ) + add( new FormComponent( "org.jdesktop.swingx.JXBusyLabel" ) { + name: "xBusyLabel2" + "text": "disabled" + "enabled": false + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 1" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "busyCheckBox" + "text": "busy" + "mnemonic": 66 + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "busyChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 3 1" + } ) add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$columnConstraints": "[left]" "$rowConstraints": "[][]" @@ -50,7 +86,7 @@ new FormModel { "value": "cell 0 1" } ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 1,aligny top,growy 0" + "value": "cell 0 2,aligny top,growy 0" } ) add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { name: "scrollPane1" @@ -109,13 +145,13 @@ new FormModel { } ) } ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 1 1,width 150,height 350" + "value": "cell 1 2,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" + "value": "cell 0 3" } ) add( new FormComponent( "org.jdesktop.swingx.JXHeader" ) { name: "xHeader1" @@ -123,7 +159,7 @@ new FormModel { "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" + "value": "cell 1 3 2 1,width 200" } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) 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 f388fed7..cc79e717 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,12 @@ # limitations under the License. # +#---- BusyLabel ---- + +JXBusyLabel.baseColor=00ff00 +JXBusyLabel.highlightColor=ff0000 + + #---- Header ---- JXHeader.background=ff8888