diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java index dddc87b7..d3129f8b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java @@ -25,12 +25,14 @@ import java.awt.Insets; import java.awt.geom.Area; import java.awt.geom.RoundRectangle2D; import java.beans.PropertyChangeListener; +import java.util.Map; import javax.swing.JComponent; import javax.swing.JProgressBar; import javax.swing.LookAndFeel; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicProgressBarUI; +import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.UIScale; @@ -59,16 +61,24 @@ import com.formdev.flatlaf.util.UIScale; public class FlatProgressBarUI extends BasicProgressBarUI { - protected int arc; - protected Dimension horizontalSize; - protected Dimension verticalSize; + @Styleable protected int arc; + @Styleable protected Dimension horizontalSize; + @Styleable protected Dimension verticalSize; private PropertyChangeListener propertyChangeListener; + private Map oldStyleValues; public static ComponentUI createUI( JComponent c ) { return new FlatProgressBarUI(); } + @Override + public void installUI( JComponent c ) { + super.installUI( c ); + + applyStyle( FlatStyleSupport.getStyle( progressBar ) ); + } + @Override protected void installDefaults() { super.installDefaults(); @@ -91,6 +101,12 @@ public class FlatProgressBarUI progressBar.revalidate(); progressBar.repaint(); break; + + case COMPONENT_STYLE: + applyStyle( e.getNewValue() ); + progressBar.revalidate(); + progressBar.repaint(); + break; } }; progressBar.addPropertyChangeListener( propertyChangeListener ); @@ -104,6 +120,20 @@ public class FlatProgressBarUI propertyChangeListener = null; } + /** + * @since TODO + */ + protected void applyStyle( Object style ) { + oldStyleValues = FlatStyleSupport.parseAndApply( oldStyleValues, style, this::applyStyleProperty ); + } + + /** + * @since TODO + */ + protected Object applyStyleProperty( String key, Object value ) { + return FlatStyleSupport.applyToAnnotatedObject( this, key, value ); + } + @Override public Dimension getPreferredSize( JComponent c ) { Dimension size = super.getPreferredSize( c ); diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/FlatStylingTests.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/FlatStylingTests.java index 52f7889b..4ca2ee6c 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/FlatStylingTests.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/FlatStylingTests.java @@ -74,6 +74,15 @@ public class FlatStylingTests radioButton( ui ); } + @Test + void progressBar() { + FlatProgressBarUI ui = new FlatProgressBarUI(); + + ui.applyStyle( "arc: 5" ); + ui.applyStyle( "horizontalSize: 100,12" ); + ui.applyStyle( "verticalSize: 12,100" ); + } + @Test void radioButton() { FlatRadioButtonUI ui = new FlatRadioButtonUI( false );