mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17:13 -06:00
FlatCheckBoxIcon now extends FlatAbstractIcon
This commit is contained in:
@@ -63,13 +63,13 @@ public abstract class FlatAbstractIcon
|
||||
if( color != null )
|
||||
g2.setColor( color );
|
||||
|
||||
paintIcon( g2 );
|
||||
paintIcon( c, g2 );
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void paintIcon( Graphics2D g2 );
|
||||
protected abstract void paintIcon( Component c, Graphics2D g2 );
|
||||
|
||||
@Override
|
||||
public int getIconWidth() {
|
||||
|
||||
@@ -14,20 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
package com.formdev.flatlaf.icons;
|
||||
|
||||
import static com.formdev.flatlaf.util.UIScale.*;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
/**
|
||||
* Icon for {@link javax.swing.JCheckBox}.
|
||||
@@ -48,7 +44,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatCheckBoxIcon
|
||||
implements Icon, UIResource
|
||||
extends FlatAbstractIcon
|
||||
{
|
||||
protected final int focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||
protected final Color focusColor = UIManager.getColor( "Component.focusColor" );
|
||||
@@ -66,46 +62,40 @@ public class FlatCheckBoxIcon
|
||||
|
||||
protected final int iconSize = 15 + (focusWidth * 2);
|
||||
|
||||
public FlatCheckBoxIcon() {
|
||||
super( 0, 0, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintIcon( Component c, Graphics g, int x, int y ) {
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
try {
|
||||
FlatUIUtils.setRenderingHints( g2 );
|
||||
protected void paintIcon( Component c, Graphics2D g2 ) {
|
||||
boolean enabled = c.isEnabled();
|
||||
boolean focused = c.hasFocus();
|
||||
boolean selected = (c instanceof AbstractButton) && ((AbstractButton)c).isSelected();
|
||||
|
||||
g2.translate( x, y );
|
||||
UIScale.scaleGraphics( g2 );
|
||||
// paint focused border
|
||||
if( focused ) {
|
||||
g2.setColor( focusColor );
|
||||
paintFocusBorder( g2 );
|
||||
}
|
||||
|
||||
boolean enabled = c.isEnabled();
|
||||
boolean focused = c.hasFocus();
|
||||
boolean selected = (c instanceof AbstractButton) && ((AbstractButton)c).isSelected();
|
||||
// paint border
|
||||
g2.setColor( enabled
|
||||
? (selected
|
||||
? (focused ? selectedFocusedBorderColor : selectedBorderColor)
|
||||
: (focused ? focusedBorderColor : borderColor))
|
||||
: disabledBorderColor );
|
||||
paintBorder( g2 );
|
||||
|
||||
// paint focused border
|
||||
if( focused ) {
|
||||
g2.setColor( focusColor );
|
||||
paintFocusBorder( g2 );
|
||||
}
|
||||
// paint background
|
||||
g2.setColor( enabled
|
||||
? (selected ? selectedBackground : background)
|
||||
: disabledBackground );
|
||||
paintBackground( g2 );
|
||||
|
||||
// paint border
|
||||
g2.setColor( enabled
|
||||
? (selected
|
||||
? (focused ? selectedFocusedBorderColor : selectedBorderColor)
|
||||
: (focused ? focusedBorderColor : borderColor))
|
||||
: disabledBorderColor );
|
||||
paintBorder( g2 );
|
||||
|
||||
// paint background
|
||||
g2.setColor( enabled
|
||||
? (selected ? selectedBackground : background)
|
||||
: disabledBackground );
|
||||
paintBackground( g2 );
|
||||
|
||||
// paint checkmark
|
||||
if( selected ) {
|
||||
g2.setColor( enabled ? checkmarkColor : disabledCheckmarkColor );
|
||||
paintCheckmark( g2 );
|
||||
}
|
||||
} finally {
|
||||
g2.dispose();
|
||||
// paint checkmark
|
||||
if( selected ) {
|
||||
g2.setColor( enabled ? checkmarkColor : disabledCheckmarkColor );
|
||||
paintCheckmark( g2 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
package com.formdev.flatlaf.icons;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.formdev.flatlaf.icons;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import javax.swing.UIManager;
|
||||
@@ -35,7 +36,7 @@ public class FlatTreeCollapsedIcon
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintIcon( Graphics2D g ) {
|
||||
protected void paintIcon( Component c, Graphics2D g ) {
|
||||
Path2D arrow = new Path2D.Float();
|
||||
arrow.moveTo( 2, 1 );
|
||||
arrow.lineTo( 2, 10 );
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.formdev.flatlaf.icons;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import javax.swing.UIManager;
|
||||
@@ -35,7 +36,7 @@ public class FlatTreeExpandedIcon
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintIcon( Graphics2D g ) {
|
||||
protected void paintIcon( Component c, Graphics2D g ) {
|
||||
Path2D arrow = new Path2D.Float();
|
||||
arrow.moveTo( 1, 2 );
|
||||
arrow.lineTo( 10, 2 );
|
||||
|
||||
@@ -51,7 +51,7 @@ Button.arc=6
|
||||
#---- CheckBox ----
|
||||
|
||||
CheckBox.border=com.formdev.flatlaf.ui.FlatMarginBorder
|
||||
CheckBox.icon=com.formdev.flatlaf.ui.FlatCheckBoxIcon
|
||||
CheckBox.icon=com.formdev.flatlaf.icons.FlatCheckBoxIcon
|
||||
|
||||
|
||||
#---- ComboBox ----
|
||||
@@ -97,7 +97,7 @@ ProgressBar.verticalSize=6,146
|
||||
#---- RadioButton ----
|
||||
|
||||
RadioButton.border=com.formdev.flatlaf.ui.FlatMarginBorder
|
||||
RadioButton.icon=com.formdev.flatlaf.ui.FlatRadioButtonIcon
|
||||
RadioButton.icon=com.formdev.flatlaf.icons.FlatRadioButtonIcon
|
||||
|
||||
|
||||
#---- ScrollBar ----
|
||||
|
||||
Reference in New Issue
Block a user