mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 15:00:54 +03:00
Styling: support ProgressBar
This commit is contained in:
@@ -25,12 +25,14 @@ import java.awt.Insets;
|
|||||||
import java.awt.geom.Area;
|
import java.awt.geom.Area;
|
||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.util.Map;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JProgressBar;
|
import javax.swing.JProgressBar;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicProgressBarUI;
|
import javax.swing.plaf.basic.BasicProgressBarUI;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
|
||||||
import com.formdev.flatlaf.util.HiDPIUtils;
|
import com.formdev.flatlaf.util.HiDPIUtils;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
@@ -59,16 +61,24 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
public class FlatProgressBarUI
|
public class FlatProgressBarUI
|
||||||
extends BasicProgressBarUI
|
extends BasicProgressBarUI
|
||||||
{
|
{
|
||||||
protected int arc;
|
@Styleable protected int arc;
|
||||||
protected Dimension horizontalSize;
|
@Styleable protected Dimension horizontalSize;
|
||||||
protected Dimension verticalSize;
|
@Styleable protected Dimension verticalSize;
|
||||||
|
|
||||||
private PropertyChangeListener propertyChangeListener;
|
private PropertyChangeListener propertyChangeListener;
|
||||||
|
private Map<String, Object> oldStyleValues;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatProgressBarUI();
|
return new FlatProgressBarUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installUI( JComponent c ) {
|
||||||
|
super.installUI( c );
|
||||||
|
|
||||||
|
applyStyle( FlatStyleSupport.getStyle( progressBar ) );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void installDefaults() {
|
protected void installDefaults() {
|
||||||
super.installDefaults();
|
super.installDefaults();
|
||||||
@@ -91,6 +101,12 @@ public class FlatProgressBarUI
|
|||||||
progressBar.revalidate();
|
progressBar.revalidate();
|
||||||
progressBar.repaint();
|
progressBar.repaint();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case COMPONENT_STYLE:
|
||||||
|
applyStyle( e.getNewValue() );
|
||||||
|
progressBar.revalidate();
|
||||||
|
progressBar.repaint();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
progressBar.addPropertyChangeListener( propertyChangeListener );
|
progressBar.addPropertyChangeListener( propertyChangeListener );
|
||||||
@@ -104,6 +120,20 @@ public class FlatProgressBarUI
|
|||||||
propertyChangeListener = null;
|
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
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
Dimension size = super.getPreferredSize( c );
|
Dimension size = super.getPreferredSize( c );
|
||||||
|
|||||||
@@ -74,6 +74,15 @@ public class FlatStylingTests
|
|||||||
radioButton( ui );
|
radioButton( ui );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void progressBar() {
|
||||||
|
FlatProgressBarUI ui = new FlatProgressBarUI();
|
||||||
|
|
||||||
|
ui.applyStyle( "arc: 5" );
|
||||||
|
ui.applyStyle( "horizontalSize: 100,12" );
|
||||||
|
ui.applyStyle( "verticalSize: 12,100" );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void radioButton() {
|
void radioButton() {
|
||||||
FlatRadioButtonUI ui = new FlatRadioButtonUI( false );
|
FlatRadioButtonUI ui = new FlatRadioButtonUI( false );
|
||||||
|
|||||||
Reference in New Issue
Block a user