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