Styling: support ProgressBar

This commit is contained in:
Karl Tauber
2021-06-17 14:57:10 +02:00
parent 2542c8bd53
commit f291cc2bd3
2 changed files with 42 additions and 3 deletions

View File

@@ -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<String, Object> 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 );

View File

@@ -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 );