diff --git a/CHANGELOG.md b/CHANGELOG.md index 92ee3606..bdb4e2ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,8 @@ 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`, `JideLabel` and `JideToggleButton`. +- JIDE Common Layer: Support `JideButton`, `JideLabel`, `JideSplitButton`, + `JideToggleButton` and `JideToggleSplitButton`. - Support running in [JetBrains Projector](https://jetbrains.com/projector/). #### Fixed bugs diff --git a/flatlaf-jide-oss/README.md b/flatlaf-jide-oss/README.md index 1a3d089a..6ca146a4 100644 --- a/flatlaf-jide-oss/README.md +++ b/flatlaf-jide-oss/README.md @@ -9,8 +9,10 @@ Following JIDE Common Layer components are currently supported by this addon: - `JideButton` - `JideLabel` - `JidePopupMenu` +- `JideSplitButton` - `JideTabbedPane` - `JideToggleButton` +- `JideToggleSplitButton` - `RangeSlider` - `TristateCheckBox` diff --git a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java index 1c868868..42b269c5 100644 --- a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java +++ b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java @@ -104,6 +104,9 @@ public class FlatJideOssDefaultsAddon // painter UIDefaultsLookup.put( defaults, "Theme.painter", FlatJidePainter.getInstance() ); + // avoid that JideButton and JideSplitButton shift icon on hover/selection + defaults.put( "Icon.floating", false ); + // fonts ActiveValue font = FlatLaf.createActiveFontValue( 1f ); defaults.put( "JideButton.font", font ); diff --git a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatJidePainter.java b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatJidePainter.java index a7fe8ab0..c007e315 100644 --- a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatJidePainter.java +++ b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatJidePainter.java @@ -20,13 +20,17 @@ import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; +import java.awt.Shape; +import java.awt.geom.Rectangle2D; import javax.swing.JComponent; +import javax.swing.SwingConstants; import javax.swing.UIManager; import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.util.UIScale; import com.jidesoft.plaf.basic.BasicPainter; import com.jidesoft.plaf.basic.ThemePainter; import com.jidesoft.swing.JideButton; +import com.jidesoft.swing.JideSplitButton; /** * @author Karl Tauber @@ -41,17 +45,61 @@ public class FlatJidePainter return new FlatJidePainter(); } + @Override + public void installDefaults() { + // avoid white background in arrow area of selected split button + if( _bk0 == null ) + _bk0 = UIManager.getColor( "Panel.background" ); + + super.installDefaults(); + } + @Override protected void paintBackground( JComponent c, Graphics g, Rectangle rect, Color borderColor, Color background, int orientation ) { - if( c instanceof JideButton && ((JideButton)c).getButtonStyle() == JideButton.TOOLBAR_STYLE ) { + if( (c instanceof JideButton && ((JideButton)c).getButtonStyle() == JideButton.TOOLBAR_STYLE) || + (c instanceof JideSplitButton && ((JideSplitButton)c).getButtonStyle() == JideButton.TOOLBAR_STYLE) ) + { Color oldColor = g.getColor(); g.setColor( FlatUIUtils.deriveColor( background, c.getBackground() ) ); Object[] oldRenderingHints = FlatUIUtils.setRenderingHints( g ); - FlatUIUtils.paintComponentBackground( (Graphics2D) g, rect.x, rect.y, - rect.width, rect.height, 0, UIScale.scale( (float) arc ) ); + if( c instanceof JideSplitButton ) { + // For split buttons, this method is invoked twice: + // - first for main button + // - second for arrow button + // To show a single rounded rectangle for the whole button we always paint + // the rounded rectangle with component bounds, but clip to the passed rectangle. + + boolean horizontal = (((JideSplitButton)c).getOrientation() == SwingConstants.HORIZONTAL); + + // for vertical orientation, the graphics context is rotated, but 1px wrong + if( !horizontal ) + g.translate( 0, -1 ); + + Shape oldClip = g.getClip(); + g.clipRect( rect.x, rect.y, rect.width, rect.height ); + + FlatUIUtils.paintComponentBackground( (Graphics2D) g, 0, 0, + horizontal ? c.getWidth() : c.getHeight(), + horizontal ? c.getHeight() : c.getWidth(), + 0, UIScale.scale( (float) arc ) ); + + g.setClip( oldClip ); + + // paint separator line + if( rect.x > 0 ) { + g.setColor( borderColor ); + ((Graphics2D)g).fill( new Rectangle2D.Float( rect.x, rect.y, UIScale.scale( 1f ), rect.height ) ); + } + + if( !horizontal ) + g.translate( 0, 1 ); + } else { + FlatUIUtils.paintComponentBackground( (Graphics2D) g, rect.x, rect.y, + rect.width, rect.height, 0, UIScale.scale( (float) arc ) ); + } FlatUIUtils.resetRenderingHints( g, oldRenderingHints ); g.setColor( oldColor ); diff --git a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatJideSplitButtonUI.java b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatJideSplitButtonUI.java new file mode 100644 index 00000000..22a29c4c --- /dev/null +++ b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatJideSplitButtonUI.java @@ -0,0 +1,126 @@ +/* + * 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.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.geom.Rectangle2D; +import javax.swing.ButtonModel; +import javax.swing.JComponent; +import javax.swing.JMenuItem; +import javax.swing.SwingConstants; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import com.formdev.flatlaf.ui.FlatUIUtils; +import com.formdev.flatlaf.util.UIScale; +import com.jidesoft.plaf.LookAndFeelFactory; +import com.jidesoft.plaf.UIDefaultsLookup; +import com.jidesoft.plaf.basic.BasicJideSplitButtonUI; +import com.jidesoft.swing.JideSplitButton; +import com.jidesoft.swing.JideSwingUtilities; + +/** + * Provides the Flat LaF UI delegate for {@link com.jidesoft.swing.JideSplitButton}. + * + * @author Karl Tauber + */ +public class FlatJideSplitButtonUI + extends BasicJideSplitButtonUI +{ + protected String arrowType; + protected Color buttonArrowColor; + protected Color buttonDisabledArrowColor; + + public static ComponentUI createUI( JComponent c ) { + // usually JIDE would invoke this in JideSplitButton.updateUI(), + // but it does not because FlatLaf already has added the UI class to the UI defaults + LookAndFeelFactory.installJideExtension(); + + return new FlatJideSplitButtonUI(); + } + + @Override + protected void installDefaults() { + super.installDefaults(); + + arrowType = UIManager.getString( "Component.arrowType" ); + buttonArrowColor = UIManager.getColor( "JideSplitButton.buttonArrowColor" ); + buttonDisabledArrowColor = UIManager.getColor( "JideSplitButton.buttonDisabledArrowColor" ); + } + + @Override + protected int getRightMargin() { + // scale margins + _splitButtonMargin = UIScale.scale( 14 ); + _splitButtonMarginOnMenu = UIScale.scale( 20 ); + + return super.getRightMargin(); + } + + @Override + protected Rectangle getButtonRect( JComponent c, int orientation, int width, int height ) { + return c.getComponentOrientation().isLeftToRight() + ? new Rectangle( 0, 0, width - _splitButtonMargin + 1, height ) + : new Rectangle( _splitButtonMargin - 1, 0, width - _splitButtonMargin + 1, height ); + } + + @Override + protected Rectangle getDropDownRect( JComponent c, int orientation, int width, int height ) { + return c.getComponentOrientation().isLeftToRight() + ? new Rectangle( width - _splitButtonMargin, 0, _splitButtonMargin, height ) + : new Rectangle( 0, 0, _splitButtonMargin, height ); + } + + @Override + protected void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, String text ) { + ButtonModel model = menuItem.getModel(); + if( !model.isEnabled() || + (menuItem instanceof JideSplitButton && !((JideSplitButton)menuItem).isButtonEnabled()) ) + { + FontMetrics fm = menuItem.getFontMetrics( menuItem.getFont() ); + + if( !menuItem.getComponentOrientation().isLeftToRight() && + menuItem.getComponentOrientation().isHorizontal() ) + { + Rectangle2D rectText = fm.getStringBounds( text, g ); + textRect.x = (int) (menuItem.getWidth() - textRect.x - rectText.getWidth() + (4 + menuItem.getHeight() / 2 - 1)); + } + + g.setColor( UIDefaultsLookup.getColor( "Button.disabledForeground" ) ); + drawStringUnderlineCharAt( menuItem, g, text, -1, textRect.x, textRect.y + fm.getAscent() ); + } else + super.paintText( g, menuItem, textRect, text ); + } + + @Override + protected void paintArrow( JMenuItem menuItem, Graphics g ) { + g.setColor( menuItem.isEnabled() ? buttonArrowColor : buttonDisabledArrowColor ); + + int orientation = JideSwingUtilities.getOrientationOf( menuItem ); + int menuWidth = (orientation == SwingConstants.HORIZONTAL) ? menuItem.getWidth() : menuItem.getHeight(); + int menuHeight = (orientation == SwingConstants.HORIZONTAL) ? menuItem.getHeight() : menuItem.getWidth(); + Rectangle r = getDropDownRect( menuItem, orientation, menuWidth, menuHeight ); + + Object[] oldRenderingHints = FlatUIUtils.setRenderingHints( g ); + FlatUIUtils.paintArrow( (Graphics2D) g, r.x, r.y, r.width, r.height, + SwingConstants.SOUTH, FlatUIUtils.isChevron( arrowType ), 6, 0, 0 ); + FlatUIUtils.resetRenderingHints( g, oldRenderingHints ); + } +} 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 e6ecdcea..4f285d01 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 @@ -19,6 +19,7 @@ JideButtonUI = com.formdev.flatlaf.jideoss.ui.FlatJideButtonUI JideLabelUI = com.formdev.flatlaf.jideoss.ui.FlatJideLabelUI JidePopupMenuUI = com.formdev.flatlaf.jideoss.ui.FlatJidePopupMenuUI +JideSplitButtonUI = com.formdev.flatlaf.jideoss.ui.FlatJideSplitButtonUI JideTabbedPaneUI = com.formdev.flatlaf.jideoss.ui.FlatJideTabbedPaneUI RangeSliderUI = com.formdev.flatlaf.jideoss.ui.FlatRangeSliderUI @@ -56,6 +57,17 @@ JideLabel.disabledForeground = $Label.disabledForeground Resizable.resizeBorder = 4,4,4,4,$PopupMenu.borderColor +#---- JideSplitButton and JideToggleSplitButton ---- + +JideSplitButton.border = com.formdev.flatlaf.ui.FlatMarginBorder +JideSplitButton.margin = $Button.toolbar.margin +JideSplitButton.textIconGap = {scaledInteger}4 + +JideSplitButton.selectionForeground = $Button.foreground +JideSplitButton.buttonArrowColor = @buttonArrowColor +JideSplitButton.buttonDisabledArrowColor = @buttonDisabledArrowColor + + #---- JideTabbedPane ---- JideTabbedPane.background = @background 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 86707370..f4c9ebb2 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt @@ -473,6 +473,17 @@ JideLabelUI com.formdev.flatlaf.jideoss.ui.FlatJideLabelUI JidePopupMenuUI com.formdev.flatlaf.jideoss.ui.FlatJidePopupMenuUI +#---- JideSplitButton ---- + +JideSplitButton.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMarginBorder [UI] +JideSplitButton.buttonArrowColor #9a9da1 javax.swing.plaf.ColorUIResource [UI] +JideSplitButton.buttonDisabledArrowColor #5a5d61 javax.swing.plaf.ColorUIResource [UI] +JideSplitButton.margin 3,3,3,3 javax.swing.plaf.InsetsUIResource [UI] +JideSplitButton.selectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +JideSplitButton.textIconGap [active] 4 +JideSplitButtonUI com.formdev.flatlaf.jideoss.ui.FlatJideSplitButtonUI + + #---- JideTabbedPane ---- JideTabbedPane.background #3c3f41 javax.swing.plaf.ColorUIResource [UI] 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 4eb9e0f4..3ca9c77e 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt @@ -478,6 +478,17 @@ JideLabelUI com.formdev.flatlaf.jideoss.ui.FlatJideLabelUI JidePopupMenuUI com.formdev.flatlaf.jideoss.ui.FlatJidePopupMenuUI +#---- JideSplitButton ---- + +JideSplitButton.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMarginBorder [UI] +JideSplitButton.buttonArrowColor #666666 javax.swing.plaf.ColorUIResource [UI] +JideSplitButton.buttonDisabledArrowColor #a6a6a6 javax.swing.plaf.ColorUIResource [UI] +JideSplitButton.margin 3,3,3,3 javax.swing.plaf.InsetsUIResource [UI] +JideSplitButton.selectionForeground #000000 javax.swing.plaf.ColorUIResource [UI] +JideSplitButton.textIconGap [active] 4 +JideSplitButtonUI com.formdev.flatlaf.jideoss.ui.FlatJideSplitButtonUI + + #---- JideTabbedPane ---- JideTabbedPane.background #f2f2f2 javax.swing.plaf.ColorUIResource [UI] 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 73e012e5..6d609689 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt @@ -469,6 +469,17 @@ JideLabelUI com.formdev.flatlaf.jideoss.ui.FlatJideLabelUI JidePopupMenuUI com.formdev.flatlaf.jideoss.ui.FlatJidePopupMenuUI +#---- JideSplitButton ---- + +JideSplitButton.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMarginBorder [UI] +JideSplitButton.buttonArrowColor #666666 javax.swing.plaf.ColorUIResource [UI] +JideSplitButton.buttonDisabledArrowColor #ababab javax.swing.plaf.ColorUIResource [UI] +JideSplitButton.margin 3,3,3,3 javax.swing.plaf.InsetsUIResource [UI] +JideSplitButton.selectionForeground #ff0000 javax.swing.plaf.ColorUIResource [UI] +JideSplitButton.textIconGap [active] 4 +JideSplitButtonUI com.formdev.flatlaf.jideoss.ui.FlatJideSplitButtonUI + + #---- JideTabbedPane ---- JideTabbedPane.background #ccffcc javax.swing.plaf.ColorUIResource [UI] 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 eb316ca0..c6a60a4f 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 @@ -55,7 +55,7 @@ #---- Icon ---- -+ Icon.floating true ++ Icon.floating false #---- JideButton ---- @@ -86,13 +86,8 @@ #---- JideSplitButton ---- -+ JideSplitButton.border 0,0,0,0 false javax.swing.plaf.basic.BasicBorders$MarginBorder [UI] + JideSplitButton.borderPainted false + JideSplitButton.font [active] $defaultFont [UI] -+ JideSplitButton.margin 3,3,3,7 javax.swing.plaf.InsetsUIResource [UI] -+ JideSplitButton.selectionForeground [active] #000000 javax.swing.plaf.ColorUIResource [UI] -+ JideSplitButton.textIconGap 4 -+ JideSplitButtonUI com.jidesoft.plaf.basic.BasicJideSplitButtonUI #---- JideSplitPane ---- 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 d45012d1..24f9de05 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 @@ -55,7 +55,7 @@ #---- Icon ---- -+ Icon.floating true ++ Icon.floating false #---- JideButton ---- @@ -86,13 +86,8 @@ #---- JideSplitButton ---- -+ JideSplitButton.border 0,0,0,0 false javax.swing.plaf.basic.BasicBorders$MarginBorder [UI] + JideSplitButton.borderPainted false + JideSplitButton.font [active] $defaultFont [UI] -+ JideSplitButton.margin 3,3,3,7 javax.swing.plaf.InsetsUIResource [UI] -+ JideSplitButton.selectionForeground [active] #000000 javax.swing.plaf.ColorUIResource [UI] -+ JideSplitButton.textIconGap 4 -+ JideSplitButtonUI com.jidesoft.plaf.basic.BasicJideSplitButtonUI #---- JideSplitPane ---- diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java index 94df07b0..d2c608c2 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponentsTest.java @@ -151,22 +151,18 @@ public class FlatComponentsTest } private void outlineChanged() { - FlatTestFrame frame = (FlatTestFrame) SwingUtilities.getAncestorOfClass( FlatTestFrame.class, this ); - if( frame == null ) - return; - Object outline = errorOutlineRadioButton.isSelected() ? "error" : warningOutlineRadioButton.isSelected() ? "warning" : magentaOutlineRadioButton.isSelected() ? Color.magenta : magentaCyanOutlineRadioButton.isSelected() ? new Color[] { Color.magenta, Color.cyan } : null; - frame.updateComponentsRecur( this, (c, type) -> { + FlatTestFrame.updateComponentsRecur( this, (c, type) -> { if( c instanceof JComponent ) ((JComponent)c).putClientProperty( FlatClientProperties.OUTLINE, outline ); } ); - frame.repaint(); + repaint(); textField1.requestFocusInWindow(); } diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatTestFrame.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatTestFrame.java index bff25e82..d4006a2c 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatTestFrame.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatTestFrame.java @@ -618,7 +618,7 @@ public class FlatTestFrame sizeVariantComboBox.setVisible( visible ); } - public void updateComponentsRecur( Container container, BiConsumer action ) { + public static void updateComponentsRecur( Container container, BiConsumer action ) { for( Component c : container.getComponents() ) { if( c instanceof JPanel || c instanceof JDesktopPane ) { updateComponentsRecur( (Container) c, action ); 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 bcd73e0b..f98a6271 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 @@ -43,6 +43,17 @@ public class FlatJideOssTest initComponents(); tristateCheckBox1Changed(); + + FlatTestFrame.updateComponentsRecur( this, (c, type) -> { + if( c instanceof JideSplitButton ) { + JideSplitButton splitButton = (JideSplitButton) c; + if( splitButton.getMenuComponentCount() == 0 ) { + splitButton.add( "Item 1" ); + splitButton.add( "Item 2" ); + splitButton.add( "Item 3" ); + } + } + } ); } private void showJidePopup( ActionEvent e ) { @@ -79,15 +90,11 @@ public class FlatJideOssTest } private void verticalChanged() { - FlatTestFrame frame = (FlatTestFrame) SwingUtilities.getAncestorOfClass( FlatTestFrame.class, this ); - if( frame == null ) - return; - int orientation = verticalCheckBox.isSelected() ? SwingUtilities.VERTICAL : SwingUtilities.HORIZONTAL; - frame.updateComponentsRecur( this, (c, type) -> { + FlatTestFrame.updateComponentsRecur( this, (c, type) -> { if( c instanceof Alignable ) ((Alignable)c).setOrientation( orientation ); } ); @@ -96,18 +103,16 @@ public class FlatJideOssTest } private void iconChanged() { - FlatTestFrame frame = (FlatTestFrame) SwingUtilities.getAncestorOfClass( FlatTestFrame.class, this ); - if( frame == null ) - return; - Icon icon = iconCheckBox.isSelected() ? new ScaledImageIcon( new ImageIcon(getClass().getResource( "/com/formdev/flatlaf/testing/test16.png" ) ) ) : null; - frame.updateComponentsRecur( this, (c, type) -> { + FlatTestFrame.updateComponentsRecur( this, (c, type) -> { if( c instanceof JideButton ) ((JideButton)c).setIcon( icon ); + else if( c instanceof JideSplitButton ) + ((JideSplitButton)c).setIcon( icon ); else if( c instanceof JideLabel ) ((JideLabel)c).setIcon( icon ); } ); @@ -115,6 +120,24 @@ public class FlatJideOssTest revalidate(); } + private void alwaysDropdownChanged() { + boolean alwaysDropdown = alwaysDropdownCheckBox.isSelected(); + + FlatTestFrame.updateComponentsRecur( this, (c, type) -> { + if( c instanceof JideSplitButton ) + ((JideSplitButton)c).setAlwaysDropdown( alwaysDropdown ); + } ); + } + + private void buttonEnabledChanged() { + boolean buttonEnabled = buttonEnabledCheckBox.isSelected(); + + FlatTestFrame.updateComponentsRecur( this, (c, type) -> { + if( c instanceof JideSplitButton ) + ((JideSplitButton)c).setButtonEnabled( buttonEnabled ); + } ); + } + private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents JLabel jidePopupLabel = new JLabel(); @@ -157,6 +180,24 @@ public class FlatJideOssTest JToolBar toolBar4 = new JToolBar(); JideToggleButton jideToggleButton10 = new JideToggleButton(); JToggleButton toggleButton2 = new JToggleButton(); + JLabel jideSplitButtonLabel = new JLabel(); + JideSplitButton jideSplitButton1 = new JideSplitButton(); + JideSplitButton jideSplitButton2 = new JideSplitButton(); + JideSplitButton jideSplitButton3 = new JideSplitButton(); + alwaysDropdownCheckBox = new JCheckBox(); + JLabel label3 = new JLabel(); + JideSplitButton jideSplitButton5 = new JideSplitButton(); + JideSplitButton jideSplitButton6 = new JideSplitButton(); + JideSplitButton jideSplitButton7 = new JideSplitButton(); + buttonEnabledCheckBox = new JCheckBox(); + JLabel jideToggleSplitButtonLabel2 = new JLabel(); + JideToggleSplitButton jideToggleSplitButton1 = new JideToggleSplitButton(); + JideToggleSplitButton jideToggleSplitButton2 = new JideToggleSplitButton(); + JideToggleSplitButton jideToggleSplitButton3 = new JideToggleSplitButton(); + JLabel label4 = new JLabel(); + JideToggleSplitButton jideToggleSplitButton4 = new JideToggleSplitButton(); + JideToggleSplitButton jideToggleSplitButton5 = new JideToggleSplitButton(); + JideToggleSplitButton jideToggleSplitButton6 = new JideToggleSplitButton(); JLabel jideLabelLabel = new JLabel(); JideLabel jideLabel1 = new JideLabel(); JideLabel jideLabel2 = new JideLabel(); @@ -182,6 +223,10 @@ public class FlatJideOssTest "[]" + "[]para" + "[]" + + "[]" + + "[]" + + "[]para" + + "[]" + "[]")); //---- jidePopupLabel ---- @@ -379,31 +424,146 @@ public class FlatJideOssTest } add(toolBar4, "cell 1 6 3 1"); + //---- jideSplitButtonLabel ---- + jideSplitButtonLabel.setText("JideSplitButton:"); + add(jideSplitButtonLabel, "cell 0 7"); + + //======== jideSplitButton1 ======== + { + jideSplitButton1.setText("TOOLBAR"); + } + add(jideSplitButton1, "cell 1 7 3 1"); + + //======== jideSplitButton2 ======== + { + jideSplitButton2.setText("TOOLBOX"); + jideSplitButton2.setButtonStyle(1); + } + add(jideSplitButton2, "cell 1 7 3 1"); + + //======== jideSplitButton3 ======== + { + jideSplitButton3.setText("FLAT"); + jideSplitButton3.setButtonStyle(2); + } + add(jideSplitButton3, "cell 1 7 3 1"); + + //---- alwaysDropdownCheckBox ---- + alwaysDropdownCheckBox.setText("always dropdown"); + alwaysDropdownCheckBox.addActionListener(e -> alwaysDropdownChanged()); + add(alwaysDropdownCheckBox, "cell 4 7"); + + //---- label3 ---- + label3.setText("selected"); + label3.setEnabled(false); + add(label3, "cell 0 8,alignx right,growx 0"); + + //======== jideSplitButton5 ======== + { + jideSplitButton5.setText("TOOLBAR"); + jideSplitButton5.setButtonSelected(true); + } + add(jideSplitButton5, "cell 1 8 3 1"); + + //======== jideSplitButton6 ======== + { + jideSplitButton6.setText("TOOLBOX"); + jideSplitButton6.setButtonStyle(1); + jideSplitButton6.setButtonSelected(true); + } + add(jideSplitButton6, "cell 1 8 3 1"); + + //======== jideSplitButton7 ======== + { + jideSplitButton7.setText("FLAT"); + jideSplitButton7.setButtonStyle(2); + jideSplitButton7.setButtonSelected(true); + } + add(jideSplitButton7, "cell 1 8 3 1"); + + //---- buttonEnabledCheckBox ---- + buttonEnabledCheckBox.setText("button enabled"); + buttonEnabledCheckBox.setSelected(true); + buttonEnabledCheckBox.addActionListener(e -> buttonEnabledChanged()); + add(buttonEnabledCheckBox, "cell 4 8"); + + //---- jideToggleSplitButtonLabel2 ---- + jideToggleSplitButtonLabel2.setText("JideToggleSplitButton:"); + add(jideToggleSplitButtonLabel2, "cell 0 9"); + + //======== jideToggleSplitButton1 ======== + { + jideToggleSplitButton1.setText("TOOLBAR"); + } + add(jideToggleSplitButton1, "cell 1 9"); + + //======== jideToggleSplitButton2 ======== + { + jideToggleSplitButton2.setText("TOOLBOX"); + jideToggleSplitButton2.setButtonStyle(1); + } + add(jideToggleSplitButton2, "cell 1 9"); + + //======== jideToggleSplitButton3 ======== + { + jideToggleSplitButton3.setText("FLAT"); + jideToggleSplitButton3.setButtonStyle(2); + } + add(jideToggleSplitButton3, "cell 1 9"); + + //---- label4 ---- + label4.setText("selected"); + label4.setEnabled(false); + add(label4, "cell 0 10,alignx right,growx 0"); + + //======== jideToggleSplitButton4 ======== + { + jideToggleSplitButton4.setText("TOOLBAR"); + jideToggleSplitButton4.setButtonSelected(true); + } + add(jideToggleSplitButton4, "cell 1 10"); + + //======== jideToggleSplitButton5 ======== + { + jideToggleSplitButton5.setText("TOOLBOX"); + jideToggleSplitButton5.setButtonStyle(1); + jideToggleSplitButton5.setButtonSelected(true); + } + add(jideToggleSplitButton5, "cell 1 10"); + + //======== jideToggleSplitButton6 ======== + { + jideToggleSplitButton6.setText("FLAT"); + jideToggleSplitButton6.setButtonStyle(2); + jideToggleSplitButton6.setButtonSelected(true); + } + add(jideToggleSplitButton6, "cell 1 10"); + //---- jideLabelLabel ---- jideLabelLabel.setText("JideLabel:"); - add(jideLabelLabel, "cell 0 7"); + add(jideLabelLabel, "cell 0 11"); //---- jideLabel1 ---- jideLabel1.setText("enabled"); - add(jideLabel1, "cell 1 7"); + add(jideLabel1, "cell 1 11"); //---- jideLabel2 ---- jideLabel2.setText("disabled"); jideLabel2.setEnabled(false); - add(jideLabel2, "cell 1 7"); + add(jideLabel2, "cell 1 11"); //---- styledLabelLabel ---- styledLabelLabel.setText("StyledLabel:"); - add(styledLabelLabel, "cell 0 8"); + add(styledLabelLabel, "cell 0 12"); //---- styledLabel1 ---- styledLabel1.setText("enabled"); - add(styledLabel1, "cell 1 8"); + add(styledLabel1, "cell 1 12"); //---- styledLabel2 ---- styledLabel2.setText("disabled"); styledLabel2.setEnabled(false); - add(styledLabel2, "cell 1 8"); + add(styledLabel2, "cell 1 12"); // JFormDesigner - End of component initialization //GEN-END:initComponents } @@ -412,5 +572,7 @@ public class FlatJideOssTest private JLabel triStateLabel1; private JCheckBox verticalCheckBox; private JCheckBox iconCheckBox; + private JCheckBox alwaysDropdownCheckBox; + private JCheckBox buttonEnabledCheckBox; // JFormDesigner - End of variables declaration //GEN-END:variables } 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 64cc7831..f6cbc0cb 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[][][][]para[][]" + "$rowConstraints": "[][][]para[][][][]para[][][][]para[][]" } ) { name: "this" add( new FormComponent( "javax.swing.JLabel" ) { @@ -277,47 +277,180 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 6 3 1" } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "jideSplitButtonLabel" + "text": "JideSplitButton:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 7" + } ) + add( new FormContainer( "com.jidesoft.swing.JideSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideSplitButton1" + "text": "TOOLBAR" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 7 3 1" + } ) + add( new FormContainer( "com.jidesoft.swing.JideSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideSplitButton2" + "text": "TOOLBOX" + "buttonStyle": 1 + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 7 3 1" + } ) + add( new FormContainer( "com.jidesoft.swing.JideSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideSplitButton3" + "text": "FLAT" + "buttonStyle": 2 + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 7 3 1" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "alwaysDropdownCheckBox" + "text": "always dropdown" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "alwaysDropdownChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 4 7" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label3" + "text": "selected" + "enabled": false + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 8,alignx right,growx 0" + } ) + add( new FormContainer( "com.jidesoft.swing.JideSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideSplitButton5" + "text": "TOOLBAR" + "buttonSelected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 8 3 1" + } ) + add( new FormContainer( "com.jidesoft.swing.JideSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideSplitButton6" + "text": "TOOLBOX" + "buttonStyle": 1 + "buttonSelected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 8 3 1" + } ) + add( new FormContainer( "com.jidesoft.swing.JideSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideSplitButton7" + "text": "FLAT" + "buttonStyle": 2 + "buttonSelected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 8 3 1" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "buttonEnabledCheckBox" + "text": "button enabled" + "selected": true + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "buttonEnabledChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 4 8" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "jideToggleSplitButtonLabel2" + "text": "JideToggleSplitButton:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 9" + } ) + add( new FormContainer( "com.jidesoft.swing.JideToggleSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideToggleSplitButton1" + "text": "TOOLBAR" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 9" + } ) + add( new FormContainer( "com.jidesoft.swing.JideToggleSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideToggleSplitButton2" + "text": "TOOLBOX" + "buttonStyle": 1 + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 9" + } ) + add( new FormContainer( "com.jidesoft.swing.JideToggleSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideToggleSplitButton3" + "text": "FLAT" + "buttonStyle": 2 + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 9" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label4" + "text": "selected" + "enabled": false + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 10,alignx right,growx 0" + } ) + add( new FormContainer( "com.jidesoft.swing.JideToggleSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideToggleSplitButton4" + "text": "TOOLBAR" + "buttonSelected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 10" + } ) + add( new FormContainer( "com.jidesoft.swing.JideToggleSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideToggleSplitButton5" + "text": "TOOLBOX" + "buttonStyle": 1 + "buttonSelected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 10" + } ) + add( new FormContainer( "com.jidesoft.swing.JideToggleSplitButton", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "jideToggleSplitButton6" + "text": "FLAT" + "buttonStyle": 2 + "buttonSelected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 10" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "jideLabelLabel" "text": "JideLabel:" }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 7" + "value": "cell 0 11" } ) add( new FormComponent( "com.jidesoft.swing.JideLabel" ) { name: "jideLabel1" "text": "enabled" }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 1 7" + "value": "cell 1 11" } ) add( new FormComponent( "com.jidesoft.swing.JideLabel" ) { name: "jideLabel2" "text": "disabled" "enabled": false }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 1 7" + "value": "cell 1 11" } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "styledLabelLabel" "text": "StyledLabel:" }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 0 8" + "value": "cell 0 12" } ) add( new FormComponent( "com.jidesoft.swing.StyledLabel" ) { name: "styledLabel1" "text": "enabled" }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 1 8" + "value": "cell 1 12" } ) add( new FormComponent( "com.jidesoft.swing.StyledLabel" ) { name: "styledLabel2" "text": "disabled" "enabled": false }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 1 8" + "value": "cell 1 12" } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) - "size": new java.awt.Dimension( 635, 500 ) + "size": new java.awt.Dimension( 665, 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 396aa9ce..68bd8896 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 @@ -333,6 +333,13 @@ JideLabel.disabledForeground JideLabel.foreground JideLabelUI JidePopupMenuUI +JideSplitButton.border +JideSplitButton.buttonArrowColor +JideSplitButton.buttonDisabledArrowColor +JideSplitButton.margin +JideSplitButton.selectionForeground +JideSplitButton.textIconGap +JideSplitButtonUI JideTabbedPane.background JideTabbedPane.contentBorderInsets JideTabbedPane.foreground