mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
get UI defaults in shared instances only once (same as used in e.g. MetalRadioButtonUI)
Note: this optimization does not work when switching from one Flat LaF to another Flat LaF because UI uninstall/install is done per component
This commit is contained in:
@@ -81,6 +81,8 @@ public class FlatButtonUI
|
||||
|
||||
private Icon helpButtonIcon;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
private static ComponentUI instance;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
@@ -93,27 +95,31 @@ public class FlatButtonUI
|
||||
protected void installDefaults( AbstractButton b ) {
|
||||
super.installDefaults( b );
|
||||
|
||||
String prefix = getPropertyPrefix();
|
||||
if( !defaults_initialized ) {
|
||||
String prefix = getPropertyPrefix();
|
||||
|
||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||
arc = UIManager.getInt( prefix + "arc" );
|
||||
minimumWidth = UIManager.getInt( prefix + "minimumWidth" );
|
||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||
arc = UIManager.getInt( prefix + "arc" );
|
||||
minimumWidth = UIManager.getInt( prefix + "minimumWidth" );
|
||||
|
||||
focusedBackground = UIManager.getColor( prefix + "focusedBackground" );
|
||||
hoverBackground = UIManager.getColor( prefix + "hoverBackground" );
|
||||
pressedBackground = UIManager.getColor( prefix + "pressedBackground" );
|
||||
disabledText = UIManager.getColor( prefix + "disabledText" );
|
||||
focusedBackground = UIManager.getColor( prefix + "focusedBackground" );
|
||||
hoverBackground = UIManager.getColor( prefix + "hoverBackground" );
|
||||
pressedBackground = UIManager.getColor( prefix + "pressedBackground" );
|
||||
disabledText = UIManager.getColor( prefix + "disabledText" );
|
||||
|
||||
defaultBackground = UIManager.getColor( "Button.default.background" );
|
||||
defaultForeground = UIManager.getColor( "Button.default.foreground" );
|
||||
defaultFocusedBackground = UIManager.getColor( "Button.default.focusedBackground" );
|
||||
defaultHoverBackground = UIManager.getColor( "Button.default.hoverBackground" );
|
||||
defaultPressedBackground = UIManager.getColor( "Button.default.pressedBackground" );
|
||||
defaultBackground = UIManager.getColor( "Button.default.background" );
|
||||
defaultForeground = UIManager.getColor( "Button.default.foreground" );
|
||||
defaultFocusedBackground = UIManager.getColor( "Button.default.focusedBackground" );
|
||||
defaultHoverBackground = UIManager.getColor( "Button.default.hoverBackground" );
|
||||
defaultPressedBackground = UIManager.getColor( "Button.default.pressedBackground" );
|
||||
|
||||
toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" );
|
||||
toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" );
|
||||
toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" );
|
||||
toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" );
|
||||
|
||||
helpButtonIcon = UIManager.getIcon( "HelpButton.icon" );
|
||||
helpButtonIcon = UIManager.getIcon( "HelpButton.icon" );
|
||||
|
||||
defaults_initialized = true;
|
||||
}
|
||||
|
||||
MigLayoutVisualPadding.install( b, focusWidth );
|
||||
}
|
||||
@@ -123,6 +129,7 @@ public class FlatButtonUI
|
||||
super.uninstallDefaults( b );
|
||||
|
||||
MigLayoutVisualPadding.uninstall( b );
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
static boolean isContentAreaFilled( Component c ) {
|
||||
|
||||
@@ -39,6 +39,8 @@ public class FlatLabelUI
|
||||
{
|
||||
private Color disabledForeground;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
private static ComponentUI instance;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
@@ -51,7 +53,17 @@ public class FlatLabelUI
|
||||
protected void installDefaults( JLabel c ) {
|
||||
super.installDefaults( c );
|
||||
|
||||
disabledForeground = UIManager.getColor( "Label.disabledForeground" );
|
||||
if( !defaults_initialized ) {
|
||||
disabledForeground = UIManager.getColor( "Label.disabledForeground" );
|
||||
|
||||
defaults_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void uninstallDefaults( JLabel c ) {
|
||||
super.uninstallDefaults( c );
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,6 +45,8 @@ public class FlatSeparatorUI
|
||||
protected int stripeWidth;
|
||||
protected int stripeIndent;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
private static ComponentUI instance;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
@@ -57,10 +59,20 @@ public class FlatSeparatorUI
|
||||
protected void installDefaults( JSeparator s ) {
|
||||
super.installDefaults( s );
|
||||
|
||||
String prefix = getPropertyPrefix();
|
||||
height = UIManager.getInt( prefix + ".height" );
|
||||
stripeWidth = UIManager.getInt( prefix + ".stripeWidth" );
|
||||
stripeIndent = UIManager.getInt( prefix + ".stripeIndent" );
|
||||
if( !defaults_initialized ) {
|
||||
String prefix = getPropertyPrefix();
|
||||
height = UIManager.getInt( prefix + ".height" );
|
||||
stripeWidth = UIManager.getInt( prefix + ".stripeWidth" );
|
||||
stripeIndent = UIManager.getInt( prefix + ".stripeIndent" );
|
||||
|
||||
defaults_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void uninstallDefaults( JSeparator s ) {
|
||||
super.uninstallDefaults( s );
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
protected String getPropertyPrefix() {
|
||||
|
||||
@@ -51,6 +51,8 @@ public class FlatToggleButtonUI
|
||||
|
||||
protected Color toolbarSelectedBackground;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
private static ComponentUI instance;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
@@ -68,11 +70,21 @@ public class FlatToggleButtonUI
|
||||
protected void installDefaults( AbstractButton b ) {
|
||||
super.installDefaults( b );
|
||||
|
||||
selectedBackground = UIManager.getColor( "ToggleButton.selectedBackground" );
|
||||
selectedForeground = UIManager.getColor( "ToggleButton.selectedForeground" );
|
||||
disabledSelectedBackground = UIManager.getColor( "ToggleButton.disabledSelectedBackground" );
|
||||
if( !defaults_initialized ) {
|
||||
selectedBackground = UIManager.getColor( "ToggleButton.selectedBackground" );
|
||||
selectedForeground = UIManager.getColor( "ToggleButton.selectedForeground" );
|
||||
disabledSelectedBackground = UIManager.getColor( "ToggleButton.disabledSelectedBackground" );
|
||||
|
||||
toolbarSelectedBackground = UIManager.getColor( "ToggleButton.toolbar.selectedBackground" );
|
||||
toolbarSelectedBackground = UIManager.getColor( "ToggleButton.toolbar.selectedBackground" );
|
||||
|
||||
defaults_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void uninstallDefaults( AbstractButton b ) {
|
||||
super.uninstallDefaults( b );
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,6 +46,8 @@ public class FlatToolBarSeparatorUI
|
||||
protected int separatorWidth;
|
||||
protected Color separatorColor;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
private static ComponentUI instance;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
@@ -58,14 +60,24 @@ public class FlatToolBarSeparatorUI
|
||||
protected void installDefaults( JSeparator c ) {
|
||||
super.installDefaults( c );
|
||||
|
||||
separatorWidth = UIManager.getInt( "ToolBar.separatorWidth" );
|
||||
separatorColor = UIManager.getColor( "ToolBar.separatorColor" );
|
||||
if( !defaults_initialized ) {
|
||||
separatorWidth = UIManager.getInt( "ToolBar.separatorWidth" );
|
||||
separatorColor = UIManager.getColor( "ToolBar.separatorColor" );
|
||||
|
||||
defaults_initialized = true;
|
||||
}
|
||||
|
||||
// necessary for vertical toolbars if separator size was set using setSeparatorSize()
|
||||
// (otherwise there will be a gap on the left side of the vertical toolbar)
|
||||
c.setAlignmentX( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void uninstallDefaults( JSeparator s ) {
|
||||
super.uninstallDefaults( s );
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize( JComponent c ) {
|
||||
Dimension size = ((JToolBar.Separator)c).getSeparatorSize();
|
||||
|
||||
Reference in New Issue
Block a user