mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
@@ -40,6 +40,8 @@ import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRootPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
@@ -52,10 +54,11 @@ import javax.swing.UnsupportedLookAndFeelException;
|
||||
import javax.swing.UIDefaults.ActiveValue;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import javax.swing.plaf.IconUIResource;
|
||||
import javax.swing.plaf.basic.BasicLookAndFeel;
|
||||
import javax.swing.text.StyleContext;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||
import com.formdev.flatlaf.util.SystemInfo;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
@@ -117,6 +120,11 @@ public abstract class FlatLaf
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getDisabledIcon(JComponent component, Icon icon) {
|
||||
return ( icon == null ) ? null : new IconUIResource( FlatUIUtils.getDisabledIcon( icon ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
if( SystemInfo.IS_MAC )
|
||||
|
||||
@@ -86,6 +86,8 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
* @uiDefault Button.toolbar.spacingInsets Insets
|
||||
* @uiDefault Button.toolbar.hoverBackground Color
|
||||
* @uiDefault Button.toolbar.pressedBackground Color
|
||||
* @uiDefault Button.disabledGrayMinValue int optional
|
||||
* @uiDefault Button.disabledGrayMinValue int optional
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.image.RGBImageFilter;
|
||||
|
||||
/**
|
||||
* Used to create a disabled Icon with the ocean look.
|
||||
* <p>
|
||||
* Imported from MetalUtils.getOceanDisabledButtonIcon
|
||||
*/
|
||||
class FlatDisabledButtonImageFilter extends RGBImageFilter {
|
||||
private float min;
|
||||
private float factor;
|
||||
|
||||
FlatDisabledButtonImageFilter( int min, int max ) {
|
||||
canFilterIndexColorModel = true;
|
||||
this.min = ( float ) min;
|
||||
this.factor = ( max - min ) / 255f;
|
||||
}
|
||||
|
||||
public int filterRGB( int x, int y, int rgb ) {
|
||||
// Coefficients are from the sRGB color space:
|
||||
int gray = Math.min( 255, ( int ) ( ( ( 0.2125f * ( ( rgb >> 16 ) & 0xFF ) ) +
|
||||
( 0.7154f * ( ( rgb >> 8 ) & 0xFF ) ) +
|
||||
( 0.0721f * ( rgb & 0xFF )) + .5f ) * factor + min) );
|
||||
|
||||
return ( rgb & 0xff000000 ) | ( gray << 16 ) | ( gray << 8 ) | ( gray );
|
||||
}
|
||||
}
|
||||
@@ -23,10 +23,15 @@ import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
@@ -34,7 +39,12 @@ import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.FilteredImageSource;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.util.function.Consumer;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.UIManager;
|
||||
@@ -433,6 +443,32 @@ public class FlatUIUtils
|
||||
return explicitlySet;
|
||||
}
|
||||
|
||||
public static Icon getDisabledIcon( Icon icon ) {
|
||||
Image image = safeGetImage(icon);
|
||||
int grayMinValue = FlatUIUtils.getUIInt( "Button.disabledGrayMinValue", 180 );
|
||||
int grayMaxValue = FlatUIUtils.getUIInt( "Button.disabledGrayMaxValue", 215 );
|
||||
FlatDisabledButtonImageFilter imageFilter = new FlatDisabledButtonImageFilter(grayMinValue, grayMaxValue);
|
||||
ImageProducer producer = new FilteredImageSource(image.getSource(), imageFilter);
|
||||
return new ImageIcon(Toolkit.getDefaultToolkit().createImage(producer));
|
||||
}
|
||||
|
||||
private static Image safeGetImage(Icon icon) {
|
||||
if ( icon instanceof ImageIcon ) {
|
||||
return ( ( ImageIcon ) icon ).getImage();
|
||||
} else {
|
||||
int width = icon.getIconWidth();
|
||||
int height = icon.getIconHeight();
|
||||
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice device = environment.getDefaultScreenDevice();
|
||||
GraphicsConfiguration configuration = device.getDefaultConfiguration();
|
||||
BufferedImage image = configuration.createCompatibleImage( width, height );
|
||||
Graphics2D g = image.createGraphics();
|
||||
icon.paintIcon( null, g, 0, 0 );
|
||||
g.dispose();
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
//---- class HoverListener ------------------------------------------------
|
||||
|
||||
public static class HoverListener
|
||||
|
||||
Reference in New Issue
Block a user