mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 15:27:16 -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 Icon helpButtonIcon;
|
||||||
|
|
||||||
|
private boolean defaults_initialized = false;
|
||||||
|
|
||||||
private static ComponentUI instance;
|
private static ComponentUI instance;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
@@ -93,27 +95,31 @@ public class FlatButtonUI
|
|||||||
protected void installDefaults( AbstractButton b ) {
|
protected void installDefaults( AbstractButton b ) {
|
||||||
super.installDefaults( b );
|
super.installDefaults( b );
|
||||||
|
|
||||||
String prefix = getPropertyPrefix();
|
if( !defaults_initialized ) {
|
||||||
|
String prefix = getPropertyPrefix();
|
||||||
|
|
||||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||||
arc = UIManager.getInt( prefix + "arc" );
|
arc = UIManager.getInt( prefix + "arc" );
|
||||||
minimumWidth = UIManager.getInt( prefix + "minimumWidth" );
|
minimumWidth = UIManager.getInt( prefix + "minimumWidth" );
|
||||||
|
|
||||||
focusedBackground = UIManager.getColor( prefix + "focusedBackground" );
|
focusedBackground = UIManager.getColor( prefix + "focusedBackground" );
|
||||||
hoverBackground = UIManager.getColor( prefix + "hoverBackground" );
|
hoverBackground = UIManager.getColor( prefix + "hoverBackground" );
|
||||||
pressedBackground = UIManager.getColor( prefix + "pressedBackground" );
|
pressedBackground = UIManager.getColor( prefix + "pressedBackground" );
|
||||||
disabledText = UIManager.getColor( prefix + "disabledText" );
|
disabledText = UIManager.getColor( prefix + "disabledText" );
|
||||||
|
|
||||||
defaultBackground = UIManager.getColor( "Button.default.background" );
|
defaultBackground = UIManager.getColor( "Button.default.background" );
|
||||||
defaultForeground = UIManager.getColor( "Button.default.foreground" );
|
defaultForeground = UIManager.getColor( "Button.default.foreground" );
|
||||||
defaultFocusedBackground = UIManager.getColor( "Button.default.focusedBackground" );
|
defaultFocusedBackground = UIManager.getColor( "Button.default.focusedBackground" );
|
||||||
defaultHoverBackground = UIManager.getColor( "Button.default.hoverBackground" );
|
defaultHoverBackground = UIManager.getColor( "Button.default.hoverBackground" );
|
||||||
defaultPressedBackground = UIManager.getColor( "Button.default.pressedBackground" );
|
defaultPressedBackground = UIManager.getColor( "Button.default.pressedBackground" );
|
||||||
|
|
||||||
toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" );
|
toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" );
|
||||||
toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" );
|
toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" );
|
||||||
|
|
||||||
helpButtonIcon = UIManager.getIcon( "HelpButton.icon" );
|
helpButtonIcon = UIManager.getIcon( "HelpButton.icon" );
|
||||||
|
|
||||||
|
defaults_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
MigLayoutVisualPadding.install( b, focusWidth );
|
MigLayoutVisualPadding.install( b, focusWidth );
|
||||||
}
|
}
|
||||||
@@ -123,6 +129,7 @@ public class FlatButtonUI
|
|||||||
super.uninstallDefaults( b );
|
super.uninstallDefaults( b );
|
||||||
|
|
||||||
MigLayoutVisualPadding.uninstall( b );
|
MigLayoutVisualPadding.uninstall( b );
|
||||||
|
defaults_initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isContentAreaFilled( Component c ) {
|
static boolean isContentAreaFilled( Component c ) {
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ public class FlatLabelUI
|
|||||||
{
|
{
|
||||||
private Color disabledForeground;
|
private Color disabledForeground;
|
||||||
|
|
||||||
|
private boolean defaults_initialized = false;
|
||||||
|
|
||||||
private static ComponentUI instance;
|
private static ComponentUI instance;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
@@ -51,7 +53,17 @@ public class FlatLabelUI
|
|||||||
protected void installDefaults( JLabel c ) {
|
protected void installDefaults( JLabel c ) {
|
||||||
super.installDefaults( 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
|
@Override
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ public class FlatSeparatorUI
|
|||||||
protected int stripeWidth;
|
protected int stripeWidth;
|
||||||
protected int stripeIndent;
|
protected int stripeIndent;
|
||||||
|
|
||||||
|
private boolean defaults_initialized = false;
|
||||||
|
|
||||||
private static ComponentUI instance;
|
private static ComponentUI instance;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
@@ -57,10 +59,20 @@ public class FlatSeparatorUI
|
|||||||
protected void installDefaults( JSeparator s ) {
|
protected void installDefaults( JSeparator s ) {
|
||||||
super.installDefaults( s );
|
super.installDefaults( s );
|
||||||
|
|
||||||
String prefix = getPropertyPrefix();
|
if( !defaults_initialized ) {
|
||||||
height = UIManager.getInt( prefix + ".height" );
|
String prefix = getPropertyPrefix();
|
||||||
stripeWidth = UIManager.getInt( prefix + ".stripeWidth" );
|
height = UIManager.getInt( prefix + ".height" );
|
||||||
stripeIndent = UIManager.getInt( prefix + ".stripeIndent" );
|
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() {
|
protected String getPropertyPrefix() {
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ public class FlatToggleButtonUI
|
|||||||
|
|
||||||
protected Color toolbarSelectedBackground;
|
protected Color toolbarSelectedBackground;
|
||||||
|
|
||||||
|
private boolean defaults_initialized = false;
|
||||||
|
|
||||||
private static ComponentUI instance;
|
private static ComponentUI instance;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
@@ -68,11 +70,21 @@ public class FlatToggleButtonUI
|
|||||||
protected void installDefaults( AbstractButton b ) {
|
protected void installDefaults( AbstractButton b ) {
|
||||||
super.installDefaults( b );
|
super.installDefaults( b );
|
||||||
|
|
||||||
selectedBackground = UIManager.getColor( "ToggleButton.selectedBackground" );
|
if( !defaults_initialized ) {
|
||||||
selectedForeground = UIManager.getColor( "ToggleButton.selectedForeground" );
|
selectedBackground = UIManager.getColor( "ToggleButton.selectedBackground" );
|
||||||
disabledSelectedBackground = UIManager.getColor( "ToggleButton.disabledSelectedBackground" );
|
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
|
@Override
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ public class FlatToolBarSeparatorUI
|
|||||||
protected int separatorWidth;
|
protected int separatorWidth;
|
||||||
protected Color separatorColor;
|
protected Color separatorColor;
|
||||||
|
|
||||||
|
private boolean defaults_initialized = false;
|
||||||
|
|
||||||
private static ComponentUI instance;
|
private static ComponentUI instance;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
@@ -58,14 +60,24 @@ public class FlatToolBarSeparatorUI
|
|||||||
protected void installDefaults( JSeparator c ) {
|
protected void installDefaults( JSeparator c ) {
|
||||||
super.installDefaults( c );
|
super.installDefaults( c );
|
||||||
|
|
||||||
separatorWidth = UIManager.getInt( "ToolBar.separatorWidth" );
|
if( !defaults_initialized ) {
|
||||||
separatorColor = UIManager.getColor( "ToolBar.separatorColor" );
|
separatorWidth = UIManager.getInt( "ToolBar.separatorWidth" );
|
||||||
|
separatorColor = UIManager.getColor( "ToolBar.separatorColor" );
|
||||||
|
|
||||||
|
defaults_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
// necessary for vertical toolbars if separator size was set using setSeparatorSize()
|
// 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)
|
// (otherwise there will be a gap on the left side of the vertical toolbar)
|
||||||
c.setAlignmentX( 0 );
|
c.setAlignmentX( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void uninstallDefaults( JSeparator s ) {
|
||||||
|
super.uninstallDefaults( s );
|
||||||
|
defaults_initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize( JComponent c ) {
|
public Dimension getPreferredSize( JComponent c ) {
|
||||||
Dimension size = ((JToolBar.Separator)c).getSeparatorSize();
|
Dimension size = ((JToolBar.Separator)c).getSeparatorSize();
|
||||||
|
|||||||
Reference in New Issue
Block a user