|
|
|
@ -1,12 +1,17 @@
|
|
|
|
|
package com.fr.design.icon; |
|
|
|
|
|
|
|
|
|
import com.fr.base.svg.SVGLoader; |
|
|
|
|
import com.fr.base.svg.SystemScaleUtils; |
|
|
|
|
import com.fr.design.utils.SvgPaintUtils; |
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
|
|
|
|
|
import javax.swing.GrayFilter; |
|
|
|
|
import javax.swing.ImageIcon; |
|
|
|
|
import java.awt.*; |
|
|
|
|
import java.awt.Component; |
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
import java.awt.Image; |
|
|
|
|
import java.awt.MediaTracker; |
|
|
|
|
import java.awt.image.ImageObserver; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -20,7 +25,8 @@ public class WarningIcon extends ImageIcon {
|
|
|
|
|
}; |
|
|
|
|
protected final static MediaTracker TRACKER = new MediaTracker(COMPONENT); |
|
|
|
|
private final static Image WARNING_IMAGE = SVGLoader.load("/com/fr/design/standard/warning.svg"); |
|
|
|
|
|
|
|
|
|
private static final boolean HI_DPI_SUPPORT = SystemScaleUtils.isJreHiDPIEnabled(); |
|
|
|
|
public static final float SYSTEM_SCALE = SystemScaleUtils.sysScale(); |
|
|
|
|
private Image mainImage = null; |
|
|
|
|
private ImageObserver imageObserver; |
|
|
|
|
private int width = -1; |
|
|
|
@ -36,14 +42,16 @@ public class WarningIcon extends ImageIcon {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public synchronized void paintIcon(Component c, Graphics g, int x, int y) { |
|
|
|
|
SvgPaintUtils.beforePaint((Graphics2D) g); |
|
|
|
|
//裁剪绘制svg的位置,以免影响到图标右侧的文字
|
|
|
|
|
Graphics2D graphics = (Graphics2D) g.create(x, y, WARNING_IMAGE.getWidth(null), WARNING_IMAGE.getHeight(null)); |
|
|
|
|
SvgPaintUtils.beforePaint(graphics); |
|
|
|
|
if (mainImage != null) { |
|
|
|
|
g.drawImage(mainImage, x, y, c); |
|
|
|
|
graphics.drawImage(mainImage, x, y, null); |
|
|
|
|
} |
|
|
|
|
if (WARNING_IMAGE != null) { |
|
|
|
|
g.drawImage(WARNING_IMAGE, x, y, c); |
|
|
|
|
graphics.drawImage(WARNING_IMAGE, x, y, null); |
|
|
|
|
} |
|
|
|
|
SvgPaintUtils.afterPaint((Graphics2D) g); |
|
|
|
|
SvgPaintUtils.afterPaint(graphics); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -91,7 +99,8 @@ public class WarningIcon extends ImageIcon {
|
|
|
|
|
* @return the width in pixels of this icon |
|
|
|
|
*/ |
|
|
|
|
public int getIconWidth() { |
|
|
|
|
return width; |
|
|
|
|
//如果环境支持高清化,drawImage可能会缩放绘制的图像比例,需要保证svg正常显示的同时调整绘制范围
|
|
|
|
|
return HI_DPI_SUPPORT ? (int) (width / SYSTEM_SCALE) : width; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -100,7 +109,8 @@ public class WarningIcon extends ImageIcon {
|
|
|
|
|
* @return the height in pixels of this icon |
|
|
|
|
*/ |
|
|
|
|
public int getIconHeight() { |
|
|
|
|
return height; |
|
|
|
|
//如果环境支持高清化,drawImage可能会缩放绘制的图像比例,需要保证svg正常显示的同时调整绘制范围
|
|
|
|
|
return HI_DPI_SUPPORT ? (int) (height / SYSTEM_SCALE) : height; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|