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