mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
disabledIcon
This commit is contained in:
@@ -36,20 +36,13 @@ import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRootPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.PopupFactory;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIDefaults;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
import javax.swing.plaf.IconUIResource;
|
||||
import javax.swing.plaf.basic.BasicLookAndFeel;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||
import com.formdev.flatlaf.util.SystemInfo;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
@@ -111,6 +104,11 @@ public abstract class FlatLaf
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getDisabledIcon(JComponent component, Icon icon) {
|
||||
return 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 );
|
||||
}
|
||||
}
|
||||
@@ -16,17 +16,7 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.*;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
@@ -34,10 +24,11 @@ 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.JComponent;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import com.formdev.flatlaf.FlatClientProperties;
|
||||
import com.formdev.flatlaf.util.DerivedColor;
|
||||
@@ -433,6 +424,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