mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
CheckBox and RadioButton: no longer extend Metal UI delegates
This commit is contained in:
@@ -181,18 +181,20 @@ public class FlatButtonUI
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintText( Graphics g, JComponent c, Rectangle textRect, String text ) {
|
||||
if( isHelpButton( c ) )
|
||||
protected void paintText( Graphics g, AbstractButton b, Rectangle textRect, String text ) {
|
||||
if( isHelpButton( b ) )
|
||||
return;
|
||||
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
FontMetrics fm = c.getFontMetrics( c.getFont() );
|
||||
paintText( g, b, textRect, text, b.isEnabled() ? getForeground( b ) : disabledText );
|
||||
}
|
||||
|
||||
static void paintText( Graphics g, AbstractButton b, Rectangle textRect, String text, Color foreground ) {
|
||||
FontMetrics fm = b.getFontMetrics( b.getFont() );
|
||||
int mnemonicIndex = b.getDisplayedMnemonicIndex();
|
||||
|
||||
g.setColor( b.getModel().isEnabled() ? getForeground( c ) : disabledText );
|
||||
FlatUIUtils.drawStringUnderlineCharAt( c, g, text, mnemonicIndex,
|
||||
textRect.x + getTextShiftOffset(),
|
||||
textRect.y + fm.getAscent() + getTextShiftOffset() );
|
||||
g.setColor( foreground );
|
||||
FlatUIUtils.drawStringUnderlineCharAt( b, g, text, mnemonicIndex,
|
||||
textRect.x, textRect.y + fm.getAscent() );
|
||||
}
|
||||
|
||||
protected Color getBackground( JComponent c ) {
|
||||
|
||||
@@ -16,13 +16,8 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.metal.MetalCheckBoxUI;
|
||||
|
||||
/**
|
||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JCheckBox}.
|
||||
@@ -30,7 +25,7 @@ import javax.swing.plaf.metal.MetalCheckBoxUI;
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatCheckBoxUI
|
||||
extends MetalCheckBoxUI
|
||||
extends FlatRadioButtonUI
|
||||
{
|
||||
private static ComponentUI instance;
|
||||
|
||||
@@ -41,21 +36,7 @@ public class FlatCheckBoxUI
|
||||
}
|
||||
|
||||
@Override
|
||||
public void installDefaults( AbstractButton b ) {
|
||||
super.installDefaults( b );
|
||||
|
||||
MigLayoutVisualPadding.install( b, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void uninstallDefaults( AbstractButton b ) {
|
||||
super.uninstallDefaults( b );
|
||||
|
||||
MigLayoutVisualPadding.uninstall( b );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintFocus( Graphics g, Rectangle t, Dimension d ) {
|
||||
// focus border painted in icon
|
||||
public String getPropertyPrefix() {
|
||||
return "CheckBox.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,22 +16,31 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.metal.MetalRadioButtonUI;
|
||||
import javax.swing.plaf.basic.BasicRadioButtonUI;
|
||||
|
||||
/**
|
||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JRadioButton}.
|
||||
*
|
||||
* TODO document used UI defaults of superclass
|
||||
*
|
||||
* @uiDefault Button.disabledText Color
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatRadioButtonUI
|
||||
extends MetalRadioButtonUI
|
||||
extends BasicRadioButtonUI
|
||||
{
|
||||
protected Color disabledText;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
private static ComponentUI instance;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
@@ -44,6 +53,14 @@ public class FlatRadioButtonUI
|
||||
public void installDefaults( AbstractButton b ) {
|
||||
super.installDefaults( b );
|
||||
|
||||
if( !defaults_initialized ) {
|
||||
String prefix = getPropertyPrefix();
|
||||
|
||||
disabledText = UIManager.getColor( prefix + "disabledText" );
|
||||
|
||||
defaults_initialized = true;
|
||||
}
|
||||
|
||||
MigLayoutVisualPadding.install( b, null );
|
||||
}
|
||||
|
||||
@@ -52,10 +69,11 @@ public class FlatRadioButtonUI
|
||||
super.uninstallDefaults( b );
|
||||
|
||||
MigLayoutVisualPadding.uninstall( b );
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintFocus( Graphics g, Rectangle t, Dimension d ) {
|
||||
// focus border painted in icon
|
||||
protected void paintText( Graphics g, AbstractButton b, Rectangle textRect, String text ) {
|
||||
FlatButtonUI.paintText( g, b, textRect, text, b.isEnabled() ? b.getForeground() : disabledText );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user