diff --git a/CHANGELOG.md b/CHANGELOG.md index 374b1646..ce29d230 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ FlatLaf Change Log menu bar and main content. If enabled with `UIManager.put( "TitlePane.unifiedBackground", true );` then window title bar and menu bar use same background color as main content. (PR #268; issue #254) -- JIDE Common Layer: Support `JideButton` and `JideToggleButton`. +- JIDE Common Layer: Support `JideButton`, `JideLabel` and `JideToggleButton`. #### Fixed bugs diff --git a/flatlaf-jide-oss/README.md b/flatlaf-jide-oss/README.md index 6815cd46..1a3d089a 100644 --- a/flatlaf-jide-oss/README.md +++ b/flatlaf-jide-oss/README.md @@ -7,6 +7,7 @@ This addon for FlatLaf adds support for **some** Following JIDE Common Layer components are currently supported by this addon: - `JideButton` +- `JideLabel` - `JidePopupMenu` - `JideTabbedPane` - `JideToggleButton` diff --git a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatJideLabelUI.java b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatJideLabelUI.java new file mode 100644 index 00000000..9ec09a01 --- /dev/null +++ b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatJideLabelUI.java @@ -0,0 +1,80 @@ +/* + * 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.jideoss.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 com.formdev.flatlaf.FlatLaf; +import com.formdev.flatlaf.ui.FlatUIUtils; +import com.jidesoft.plaf.LookAndFeelFactory; +import com.jidesoft.plaf.basic.BasicJideLabelUI; + +/** + * Provides the Flat LaF UI delegate for {@link com.jidesoft.swing.JideLabel}. + * + * @author Karl Tauber + */ +public class FlatJideLabelUI + extends BasicJideLabelUI +{ + private Color disabledForeground; + + private boolean defaults_initialized = false; + + public static ComponentUI createUI( JComponent c ) { + // usually JIDE would invoke this in JideLabel.updateUI(), + // but it does not because FlatLaf already has added the UI class to the UI defaults + LookAndFeelFactory.installJideExtension(); + + return FlatUIUtils.createSharedUI( FlatJideLabelUI.class, FlatJideLabelUI::new ); + } + + @Override + protected void installDefaults( JLabel c ) { + super.installDefaults( c ); + + if( !defaults_initialized ) { + disabledForeground = UIManager.getColor( "JideLabel.disabledForeground" ); + + defaults_initialized = true; + } + } + + @Override + protected void uninstallDefaults( JLabel c ) { + super.uninstallDefaults( c ); + defaults_initialized = false; + } + + @Override + protected void paintEnabledText( JLabel l, Graphics g, String s, int textX, int textY ) { + int mnemIndex = FlatLaf.isShowMnemonics() ? l.getDisplayedMnemonicIndex() : -1; + g.setColor( l.getForeground() ); + FlatUIUtils.drawStringUnderlineCharAt( l, g, s, mnemIndex, textX, textY ); + } + + @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-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties b/flatlaf-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties index 9e875f8d..e6ecdcea 100644 --- a/flatlaf-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties +++ b/flatlaf-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties @@ -17,6 +17,7 @@ #---- UI delegates ---- JideButtonUI = com.formdev.flatlaf.jideoss.ui.FlatJideButtonUI +JideLabelUI = com.formdev.flatlaf.jideoss.ui.FlatJideLabelUI JidePopupMenuUI = com.formdev.flatlaf.jideoss.ui.FlatJidePopupMenuUI JideTabbedPaneUI = com.formdev.flatlaf.jideoss.ui.FlatJideTabbedPaneUI RangeSliderUI = com.formdev.flatlaf.jideoss.ui.FlatRangeSliderUI @@ -43,6 +44,13 @@ JideButton.highlight = $Button.selectedBackground Button.disabledForeground = $Button.disabledText +#---- JideLabel ---- + +JideLabel.background = $Label.background +JideLabel.foreground = $Label.foreground +JideLabel.disabledForeground = $Label.disabledForeground + + #---- JidePopup ---- Resizable.resizeBorder = 4,4,4,4,$PopupMenu.borderColor diff --git a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt index 37b884c6..86707370 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt @@ -460,6 +460,14 @@ JideButton.textIconGap [active] 4 JideButtonUI com.formdev.flatlaf.jideoss.ui.FlatJideButtonUI +#---- JideLabel ---- + +JideLabel.background #3c3f41 javax.swing.plaf.ColorUIResource [UI] +JideLabel.disabledForeground #888888 javax.swing.plaf.ColorUIResource [UI] +JideLabel.foreground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +JideLabelUI com.formdev.flatlaf.jideoss.ui.FlatJideLabelUI + + #---- JidePopupMenu ---- JidePopupMenuUI com.formdev.flatlaf.jideoss.ui.FlatJidePopupMenuUI diff --git a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt index 4a00b5de..4eb9e0f4 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt @@ -465,6 +465,14 @@ JideButton.textIconGap [active] 4 JideButtonUI com.formdev.flatlaf.jideoss.ui.FlatJideButtonUI +#---- JideLabel ---- + +JideLabel.background #f2f2f2 javax.swing.plaf.ColorUIResource [UI] +JideLabel.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI] +JideLabel.foreground #000000 javax.swing.plaf.ColorUIResource [UI] +JideLabelUI com.formdev.flatlaf.jideoss.ui.FlatJideLabelUI + + #---- JidePopupMenu ---- JidePopupMenuUI com.formdev.flatlaf.jideoss.ui.FlatJidePopupMenuUI diff --git a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt index 298b9fbf..73e012e5 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt @@ -456,6 +456,14 @@ JideButton.textIconGap [active] 4 JideButtonUI com.formdev.flatlaf.jideoss.ui.FlatJideButtonUI +#---- JideLabel ---- + +JideLabel.background #ccffcc javax.swing.plaf.ColorUIResource [UI] +JideLabel.disabledForeground #000088 javax.swing.plaf.ColorUIResource [UI] +JideLabel.foreground #008800 javax.swing.plaf.ColorUIResource [UI] +JideLabelUI com.formdev.flatlaf.jideoss.ui.FlatJideLabelUI + + #---- JidePopupMenu ---- JidePopupMenuUI com.formdev.flatlaf.jideoss.ui.FlatJidePopupMenuUI diff --git a/flatlaf-testing/dumps/uidefaults/JIDE-FlatDarkLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/JIDE-FlatDarkLaf_1.8.0_202.txt index 2d30c241..b42bc9c1 100644 --- a/flatlaf-testing/dumps/uidefaults/JIDE-FlatDarkLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/JIDE-FlatDarkLaf_1.8.0_202.txt @@ -77,10 +77,7 @@ #---- JideLabel ---- -+ JideLabel.background [active] #f0f0f0 javax.swing.plaf.ColorUIResource [UI] + JideLabel.font Segoe UI plain 12 javax.swing.plaf.FontUIResource [UI] -+ JideLabel.foreground [active] #000000 javax.swing.plaf.ColorUIResource [UI] -+ JideLabelUI com.jidesoft.plaf.basic.BasicJideLabelUI #---- JidePopup ---- diff --git a/flatlaf-testing/dumps/uidefaults/JIDE-FlatLightLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/JIDE-FlatLightLaf_1.8.0_202.txt index 033f752e..3a5d72c3 100644 --- a/flatlaf-testing/dumps/uidefaults/JIDE-FlatLightLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/JIDE-FlatLightLaf_1.8.0_202.txt @@ -77,10 +77,7 @@ #---- JideLabel ---- -+ JideLabel.background [active] #f0f0f0 javax.swing.plaf.ColorUIResource [UI] + JideLabel.font Segoe UI plain 12 javax.swing.plaf.FontUIResource [UI] -+ JideLabel.foreground [active] #000000 javax.swing.plaf.ColorUIResource [UI] -+ JideLabelUI com.jidesoft.plaf.basic.BasicJideLabelUI #---- JidePopup ---- diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java index 2b757cfb..bcd73e0b 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java @@ -88,8 +88,8 @@ public class FlatJideOssTest : SwingUtilities.HORIZONTAL; frame.updateComponentsRecur( this, (c, type) -> { - if( c instanceof JideButton ) - ((JideButton)c).setOrientation( orientation ); + if( c instanceof Alignable ) + ((Alignable)c).setOrientation( orientation ); } ); revalidate(); @@ -108,6 +108,8 @@ public class FlatJideOssTest frame.updateComponentsRecur( this, (c, type) -> { if( c instanceof JideButton ) ((JideButton)c).setIcon( icon ); + else if( c instanceof JideLabel ) + ((JideLabel)c).setIcon( icon ); } ); revalidate(); @@ -155,6 +157,12 @@ public class FlatJideOssTest JToolBar toolBar4 = new JToolBar(); JideToggleButton jideToggleButton10 = new JideToggleButton(); JToggleButton toggleButton2 = new JToggleButton(); + JLabel jideLabelLabel = new JLabel(); + JideLabel jideLabel1 = new JideLabel(); + JideLabel jideLabel2 = new JideLabel(); + JLabel styledLabelLabel = new JLabel(); + StyledLabel styledLabel1 = new StyledLabel(); + StyledLabel styledLabel2 = new StyledLabel(); //======== this ======== setLayout(new MigLayout( @@ -172,6 +180,8 @@ public class FlatJideOssTest "[]" + "[]" + "[]" + + "[]para" + + "[]" + "[]")); //---- jidePopupLabel ---- @@ -368,6 +378,32 @@ public class FlatJideOssTest toolBar4.add(toggleButton2); } add(toolBar4, "cell 1 6 3 1"); + + //---- jideLabelLabel ---- + jideLabelLabel.setText("JideLabel:"); + add(jideLabelLabel, "cell 0 7"); + + //---- jideLabel1 ---- + jideLabel1.setText("enabled"); + add(jideLabel1, "cell 1 7"); + + //---- jideLabel2 ---- + jideLabel2.setText("disabled"); + jideLabel2.setEnabled(false); + add(jideLabel2, "cell 1 7"); + + //---- styledLabelLabel ---- + styledLabelLabel.setText("StyledLabel:"); + add(styledLabelLabel, "cell 0 8"); + + //---- styledLabel1 ---- + styledLabel1.setText("enabled"); + add(styledLabel1, "cell 1 8"); + + //---- styledLabel2 ---- + styledLabel2.setText("disabled"); + styledLabel2.setEnabled(false); + add(styledLabel2, "cell 1 8"); // JFormDesigner - End of component initialization //GEN-END:initComponents } diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.jfd index 3e325195..64cc7831 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.jfd @@ -9,7 +9,7 @@ new FormModel { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "insets dialog,hidemode 3" "$columnConstraints": "[][left][fill][fill][fill]" - "$rowConstraints": "[][][]para[][][][]" + "$rowConstraints": "[][][]para[][][][]para[][]" } ) { name: "this" add( new FormComponent( "javax.swing.JLabel" ) { @@ -277,6 +277,44 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 6 3 1" } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "jideLabelLabel" + "text": "JideLabel:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 7" + } ) + add( new FormComponent( "com.jidesoft.swing.JideLabel" ) { + name: "jideLabel1" + "text": "enabled" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 7" + } ) + add( new FormComponent( "com.jidesoft.swing.JideLabel" ) { + name: "jideLabel2" + "text": "disabled" + "enabled": false + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 7" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "styledLabelLabel" + "text": "StyledLabel:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 8" + } ) + add( new FormComponent( "com.jidesoft.swing.StyledLabel" ) { + name: "styledLabel1" + "text": "enabled" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 8" + } ) + add( new FormComponent( "com.jidesoft.swing.StyledLabel" ) { + name: "styledLabel2" + "text": "disabled" + "enabled": false + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 8" + } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) "size": new java.awt.Dimension( 635, 500 ) diff --git a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt index 26396a60..396aa9ce 100644 --- a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt +++ b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt @@ -328,6 +328,10 @@ JideButton.selectedBackground JideButton.shadow JideButton.textIconGap JideButtonUI +JideLabel.background +JideLabel.disabledForeground +JideLabel.foreground +JideLabelUI JidePopupMenuUI JideTabbedPane.background JideTabbedPane.contentBorderInsets