mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Styling: avoid duplicate applying styles to buttons, labels and separators (which use shared UI delegates)
This commit is contained in:
@@ -254,21 +254,17 @@ public class FlatButtonUI
|
||||
break;
|
||||
|
||||
case STYLE:
|
||||
applyStyle( b, this, e.getNewValue() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyStyle( AbstractButton b, FlatButtonUI ui, Object style ) {
|
||||
Object style = e.getNewValue();
|
||||
if( style != null && shared ) {
|
||||
// unshare component UI if necessary
|
||||
if( style != null && ui.shared ) {
|
||||
// updateUI() invokes applyStyle() from installUI()
|
||||
b.updateUI();
|
||||
ui = (FlatButtonUI) b.getUI();
|
||||
}
|
||||
|
||||
ui.applyStyle( b, style );
|
||||
} else
|
||||
applyStyle( b, style );
|
||||
b.revalidate();
|
||||
b.repaint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -119,22 +119,19 @@ public class FlatLabelUI
|
||||
if( name == "text" || name == "font" || name == "foreground" ) {
|
||||
JLabel label = (JLabel) e.getSource();
|
||||
updateHTMLRenderer( label, label.getText(), true );
|
||||
} else if( name.equals( FlatClientProperties.STYLE ) )
|
||||
applyStyle( (JLabel) e.getSource(), this, e.getNewValue() );
|
||||
else
|
||||
super.propertyChange( e );
|
||||
}
|
||||
|
||||
private static void applyStyle( JLabel c, FlatLabelUI ui, Object style ) {
|
||||
} else if( name.equals( FlatClientProperties.STYLE ) ) {
|
||||
JLabel label = (JLabel) e.getSource();
|
||||
Object style = e.getNewValue();
|
||||
if( style != null && shared ) {
|
||||
// unshare component UI if necessary
|
||||
if( style != null && ui.shared ) {
|
||||
c.updateUI();
|
||||
ui = (FlatLabelUI) c.getUI();
|
||||
}
|
||||
|
||||
ui.applyStyle( c, style );
|
||||
c.revalidate();
|
||||
c.repaint();
|
||||
// updateUI() invokes applyStyle() from installUI()
|
||||
label.updateUI();
|
||||
} else
|
||||
applyStyle( label, style );
|
||||
label.revalidate();
|
||||
label.repaint();
|
||||
} else
|
||||
super.propertyChange( e );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -138,21 +138,17 @@ public class FlatRadioButtonUI
|
||||
protected void propertyChange( AbstractButton b, PropertyChangeEvent e ) {
|
||||
switch( e.getPropertyName() ) {
|
||||
case FlatClientProperties.STYLE:
|
||||
applyStyle( b, this, e.getNewValue() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyStyle( AbstractButton b, FlatRadioButtonUI ui, Object style ) {
|
||||
Object style = e.getNewValue();
|
||||
if( style != null && shared ) {
|
||||
// unshare component UI if necessary
|
||||
if( style != null && ui.shared ) {
|
||||
// updateUI() invokes applyStyle() from installUI()
|
||||
b.updateUI();
|
||||
ui = (FlatRadioButtonUI) b.getUI();
|
||||
}
|
||||
|
||||
ui.applyStyle( b, style );
|
||||
} else
|
||||
applyStyle( b, style );
|
||||
b.revalidate();
|
||||
b.repaint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -125,12 +125,11 @@ public class FlatSeparatorUI
|
||||
}
|
||||
|
||||
private static void applyStyle( JSeparator s, FlatSeparatorUI ui, Object style ) {
|
||||
// unshare component UI if necessary
|
||||
if( style != null && ui.shared ) {
|
||||
// unshare component UI if necessary
|
||||
// updateUI() invokes applyStyle() from installUI()
|
||||
s.updateUI();
|
||||
ui = (FlatSeparatorUI) s.getUI();
|
||||
}
|
||||
|
||||
} else
|
||||
ui.applyStyle( s, style );
|
||||
s.revalidate();
|
||||
s.repaint();
|
||||
|
||||
@@ -121,12 +121,11 @@ public class FlatToolBarSeparatorUI
|
||||
}
|
||||
|
||||
private static void applyStyle( JSeparator s, FlatToolBarSeparatorUI ui, Object style ) {
|
||||
// unshare component UI if necessary
|
||||
if( style != null && ui.shared ) {
|
||||
// unshare component UI if necessary
|
||||
// updateUI() invokes applyStyle() from installUI()
|
||||
s.updateUI();
|
||||
ui = (FlatToolBarSeparatorUI) s.getUI();
|
||||
}
|
||||
|
||||
} else
|
||||
ui.applyStyle( style );
|
||||
s.revalidate();
|
||||
s.repaint();
|
||||
|
||||
Reference in New Issue
Block a user