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,23 +254,19 @@ public class FlatButtonUI
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case STYLE:
|
case STYLE:
|
||||||
applyStyle( b, this, e.getNewValue() );
|
Object style = e.getNewValue();
|
||||||
|
if( style != null && shared ) {
|
||||||
|
// unshare component UI if necessary
|
||||||
|
// updateUI() invokes applyStyle() from installUI()
|
||||||
|
b.updateUI();
|
||||||
|
} else
|
||||||
|
applyStyle( b, style );
|
||||||
|
b.revalidate();
|
||||||
|
b.repaint();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applyStyle( AbstractButton b, FlatButtonUI ui, Object style ) {
|
|
||||||
// unshare component UI if necessary
|
|
||||||
if( style != null && ui.shared ) {
|
|
||||||
b.updateUI();
|
|
||||||
ui = (FlatButtonUI) b.getUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.applyStyle( b, style );
|
|
||||||
b.revalidate();
|
|
||||||
b.repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 2
|
* @since 2
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -119,24 +119,21 @@ public class FlatLabelUI
|
|||||||
if( name == "text" || name == "font" || name == "foreground" ) {
|
if( name == "text" || name == "font" || name == "foreground" ) {
|
||||||
JLabel label = (JLabel) e.getSource();
|
JLabel label = (JLabel) e.getSource();
|
||||||
updateHTMLRenderer( label, label.getText(), true );
|
updateHTMLRenderer( label, label.getText(), true );
|
||||||
} else if( name.equals( FlatClientProperties.STYLE ) )
|
} else if( name.equals( FlatClientProperties.STYLE ) ) {
|
||||||
applyStyle( (JLabel) e.getSource(), this, e.getNewValue() );
|
JLabel label = (JLabel) e.getSource();
|
||||||
else
|
Object style = e.getNewValue();
|
||||||
|
if( style != null && shared ) {
|
||||||
|
// unshare component UI if necessary
|
||||||
|
// updateUI() invokes applyStyle() from installUI()
|
||||||
|
label.updateUI();
|
||||||
|
} else
|
||||||
|
applyStyle( label, style );
|
||||||
|
label.revalidate();
|
||||||
|
label.repaint();
|
||||||
|
} else
|
||||||
super.propertyChange( e );
|
super.propertyChange( e );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applyStyle( JLabel c, FlatLabelUI ui, Object style ) {
|
|
||||||
// unshare component UI if necessary
|
|
||||||
if( style != null && ui.shared ) {
|
|
||||||
c.updateUI();
|
|
||||||
ui = (FlatLabelUI) c.getUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.applyStyle( c, style );
|
|
||||||
c.revalidate();
|
|
||||||
c.repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 2
|
* @since 2
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -138,23 +138,19 @@ public class FlatRadioButtonUI
|
|||||||
protected void propertyChange( AbstractButton b, PropertyChangeEvent e ) {
|
protected void propertyChange( AbstractButton b, PropertyChangeEvent e ) {
|
||||||
switch( e.getPropertyName() ) {
|
switch( e.getPropertyName() ) {
|
||||||
case FlatClientProperties.STYLE:
|
case FlatClientProperties.STYLE:
|
||||||
applyStyle( b, this, e.getNewValue() );
|
Object style = e.getNewValue();
|
||||||
|
if( style != null && shared ) {
|
||||||
|
// unshare component UI if necessary
|
||||||
|
// updateUI() invokes applyStyle() from installUI()
|
||||||
|
b.updateUI();
|
||||||
|
} else
|
||||||
|
applyStyle( b, style );
|
||||||
|
b.revalidate();
|
||||||
|
b.repaint();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applyStyle( AbstractButton b, FlatRadioButtonUI ui, Object style ) {
|
|
||||||
// unshare component UI if necessary
|
|
||||||
if( style != null && ui.shared ) {
|
|
||||||
b.updateUI();
|
|
||||||
ui = (FlatRadioButtonUI) b.getUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.applyStyle( b, style );
|
|
||||||
b.revalidate();
|
|
||||||
b.repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 2
|
* @since 2
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -125,13 +125,12 @@ public class FlatSeparatorUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void applyStyle( JSeparator s, FlatSeparatorUI ui, Object style ) {
|
private static void applyStyle( JSeparator s, FlatSeparatorUI ui, Object style ) {
|
||||||
// unshare component UI if necessary
|
|
||||||
if( style != null && ui.shared ) {
|
if( style != null && ui.shared ) {
|
||||||
|
// unshare component UI if necessary
|
||||||
|
// updateUI() invokes applyStyle() from installUI()
|
||||||
s.updateUI();
|
s.updateUI();
|
||||||
ui = (FlatSeparatorUI) s.getUI();
|
} else
|
||||||
}
|
ui.applyStyle( s, style );
|
||||||
|
|
||||||
ui.applyStyle( s, style );
|
|
||||||
s.revalidate();
|
s.revalidate();
|
||||||
s.repaint();
|
s.repaint();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,13 +121,12 @@ public class FlatToolBarSeparatorUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void applyStyle( JSeparator s, FlatToolBarSeparatorUI ui, Object style ) {
|
private static void applyStyle( JSeparator s, FlatToolBarSeparatorUI ui, Object style ) {
|
||||||
// unshare component UI if necessary
|
|
||||||
if( style != null && ui.shared ) {
|
if( style != null && ui.shared ) {
|
||||||
|
// unshare component UI if necessary
|
||||||
|
// updateUI() invokes applyStyle() from installUI()
|
||||||
s.updateUI();
|
s.updateUI();
|
||||||
ui = (FlatToolBarSeparatorUI) s.getUI();
|
} else
|
||||||
}
|
ui.applyStyle( style );
|
||||||
|
|
||||||
ui.applyStyle( style );
|
|
||||||
s.revalidate();
|
s.revalidate();
|
||||||
s.repaint();
|
s.repaint();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user