Styling: use FlatStyleSupport.createPropertyChangeListener() where possible/useful

This commit is contained in:
Karl Tauber
2021-06-21 17:27:46 +02:00
parent 28fb2e2a08
commit b46233087b
3 changed files with 5 additions and 33 deletions

View File

@@ -28,7 +28,6 @@ import javax.swing.JSeparator;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSeparatorUI; import javax.swing.plaf.basic.BasicSeparatorUI;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
/** /**
@@ -107,15 +106,8 @@ public class FlatSeparatorUI
protected void installListeners( JSeparator s ) { protected void installListeners( JSeparator s ) {
super.installListeners( s ); super.installListeners( s );
propertyChangeListener = e -> { propertyChangeListener = FlatStyleSupport.createPropertyChangeListener(
switch( e.getPropertyName() ) { s, style -> applyStyle( s, this, style ), null );
case FlatClientProperties.STYLE:
applyStyle( s, this, e.getNewValue() );
s.revalidate();
s.repaint();
break;
}
};
s.addPropertyChangeListener( propertyChangeListener ); s.addPropertyChangeListener( propertyChangeListener );
} }

View File

@@ -36,7 +36,6 @@ import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSliderUI; import javax.swing.plaf.basic.BasicSliderUI;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.util.Graphics2DProxy; import com.formdev.flatlaf.util.Graphics2DProxy;
import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.HiDPIUtils;
@@ -185,18 +184,8 @@ public class FlatSliderUI
@Override @Override
protected PropertyChangeListener createPropertyChangeListener( JSlider slider ) { protected PropertyChangeListener createPropertyChangeListener( JSlider slider ) {
PropertyChangeListener superListener = super.createPropertyChangeListener( slider ); return FlatStyleSupport.createPropertyChangeListener( slider, this::applyStyle,
return e -> { super.createPropertyChangeListener( slider ) );
superListener.propertyChange( e );
switch( e.getPropertyName() ) {
case FlatClientProperties.STYLE:
applyStyle( e.getNewValue() );
slider.revalidate();
slider.repaint();
break;
}
};
} }
/** /**

View File

@@ -34,7 +34,6 @@ import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSplitPaneDivider; import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI; import javax.swing.plaf.basic.BasicSplitPaneUI;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable; import com.formdev.flatlaf.ui.FlatStyleSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException; import com.formdev.flatlaf.ui.FlatStyleSupport.UnknownStyleException;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -117,15 +116,7 @@ public class FlatSplitPaneUI
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
propertyChangeListener = e -> { propertyChangeListener = FlatStyleSupport.createPropertyChangeListener( splitPane, this::applyStyle, null );
switch( e.getPropertyName() ) {
case FlatClientProperties.STYLE:
applyStyle( e.getNewValue() );
splitPane.revalidate();
splitPane.repaint();
break;
}
};
splitPane.addPropertyChangeListener( propertyChangeListener ); splitPane.addPropertyChangeListener( propertyChangeListener );
} }