Browse Source

REPORT-92161 设计器-图标-数据源相关-部分图标无反色处理,选中后就看不到图标了

newui
obo 2 years ago
parent
commit
c8bb1cae57
  1. 9
      designer-base/src/main/java/com/fr/design/gui/controlpane/JListControlPane.java
  2. 66
      designer-base/src/main/java/com/fr/design/utils/IconColorUtils.java

9
designer-base/src/main/java/com/fr/design/gui/controlpane/JListControlPane.java

@ -7,6 +7,7 @@ import com.fr.design.gui.ilist.JNameEdList;
import com.fr.design.gui.ilist.ListModelElement;
import com.fr.design.gui.ilist.ModNameActionListener;
import com.fr.design.i18n.Toolkit;
import com.fr.design.utils.IconColorUtils;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.form.event.Listener;
import com.fr.general.ComparatorUtils;
@ -19,6 +20,7 @@ import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
@ -27,6 +29,7 @@ import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@ -357,7 +360,11 @@ public abstract class JListControlPane extends JControlPane implements ListContr
boolean iconSet = false;
for (NameableCreator creator : JListControlPane.this.creators()) {
if (creator.menuIcon() != null && creator.acceptObject2Populate(nameable) != null) {
this.setIcon(creator.menuIcon());
Icon icon = creator.menuIcon();
if(isSelected) {
icon = IconColorUtils.convert(icon, Color.WHITE);
}
this.setIcon(icon);
this.setToolTipText(creator.createTooltip());
iconSet = true;
break;

66
designer-base/src/main/java/com/fr/design/utils/IconColorUtils.java

@ -0,0 +1,66 @@
package com.fr.design.utils;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
/**
* 对Icon进行颜色处理的工具类
*
* @author obo
* @since 11.0
* Created on 2023/4/3
*/
public final class IconColorUtils {
/**
* 转色处理并返回处理后的Icon
*
* @param icon 需要转色处理的icon
* @param color 需要转的颜色,可能要和视觉沟通
* @return 转色后的icon
*/
public static Icon convert(Icon icon, Color color) {
BufferedImage image = iconToImage(icon);
Image convertedImage = createConvertedImage(image, color);
return new ImageIcon(convertedImage);
}
/**
* 获取icon中的image对象,虽然设计器中未来大部分图标会读取为SVGIcon类型,其中直接包含image对象
* 但存在某些特殊情况,例如绘制带警告图标的数据集时,无法直接获取image对象,因此统一使用此方法获取
*
* @param icon 需要获取image的icon
* @return 获取icon对应的image
*/
private static BufferedImage iconToImage(Icon icon) {
BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
icon.paintIcon(null, g2d, 0, 0);
g2d.dispose();
return image;
}
/**
* 转色
*
* @param image 需要转色的image
* @return 转色后的image
*/
private static Image createConvertedImage(BufferedImage image, Color color) {
int colorRgb = (color.getRGB() & 0x00FFFFFF);
for (int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
int originalArgb = image.getRGB(x, y);
int alpha = (originalArgb >> 24) & 0xFF;
int newArgb = (alpha << 24) | colorRgb;
image.setRGB(x, y, newArgb);
}
}
return image;
}
}
Loading…
Cancel
Save