Browse Source

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

Merge in DESIGN/design from ~OBO/design:release/11.0 to release/11.0

* commit '2f158aec7f773a38f17fe1867f7634bedd02a431':
  REPORT-92161 设计器-图标-数据源相关-部分图标无反色处理,选中后就看不到图标了
  REPORT-92161 设计器-图标-数据源相关-部分图标无反色处理,选中后就看不到图标了
  REPORT-92161 设计器-图标-数据源相关-部分图标无反色处理,选中后就看不到图标了
  REPORT-92161 设计器-图标-数据源相关-部分图标无反色处理,选中后就看不到图标了
  REPORT-92161 设计器-图标-数据源相关-部分图标无反色处理,选中后就看不到图标了
newui
Obo-王学仁 2 years ago
parent
commit
4beb25da7a
  1. 50
      designer-base/src/main/java/com/fr/design/gui/controlpane/JListControlPane.java
  2. 11
      designer-base/src/main/java/com/fr/design/gui/ilist/JNameEdList.java

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

@ -17,16 +17,19 @@ import com.fr.stable.Nameable;
import com.fr.stable.StringUtils;
import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.ListCellRenderer;
import javax.swing.ListSelectionModel;
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;
@ -343,21 +346,46 @@ public abstract class JListControlPane extends JControlPane implements ListContr
}
protected class NameableListCellRenderer extends
DefaultListCellRenderer {
JPanel implements ListCellRenderer<Object> {
private final JLabel textLabel;
private final JLabel iconLabel;
/**
* JList默认单元格渲染器的选中背景色
*/
private final Color selectedBgColor = new Color(65, 155, 249);
protected NameableListCellRenderer() {
setLayout(new BorderLayout());
this.textLabel = new JLabel();
this.iconLabel = new JLabel();
add(this.textLabel, BorderLayout.CENTER);
add(this.iconLabel, BorderLayout.WEST);
this.iconLabel.setBackground(Color.WHITE);
//iconLabel和textLabel的背景颜色不会被JList背景颜色覆盖,开发者自定义
this.textLabel.setOpaque(true);
this.iconLabel.setOpaque(true);
}
@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected,
cellHasFocus);
if (value instanceof ListModelElement) {
ListModelElement element = ((ListModelElement) value);
Nameable nameable = element.wrapper;
this.setText(nameable.getName());
this.textLabel.setText(nameable.getName());
boolean iconSet = false;
for (NameableCreator creator : JListControlPane.this.creators()) {
if (creator.menuIcon() != null && creator.acceptObject2Populate(nameable) != null) {
this.setIcon(creator.menuIcon());
this.iconLabel.setIcon(creator.menuIcon());
if(isSelected) {
this.textLabel.setBackground(selectedBgColor);
this.textLabel.setForeground(Color.WHITE);
} else {
this.textLabel.setBackground(Color.WHITE);
this.textLabel.setForeground(Color.BLACK);
}
this.setToolTipText(creator.createTooltip());
iconSet = true;
break;
@ -369,8 +397,16 @@ public abstract class JListControlPane extends JControlPane implements ListContr
}
return this;
}
}
/**
* 改造后兼容子类NoIconNameableListCellRenderer使用,添加此setIcon函数
*
* @param icon 图标,可为null
*/
public void setIcon(Icon icon) {
this.iconLabel.setIcon(icon);
}
}
@Override
public BasicBeanPane createPaneByCreators(NameableCreator creator) {
return Reflect.on(creator.getUpdatePane()).create().get();

11
designer-base/src/main/java/com/fr/design/gui/ilist/JNameEdList.java

@ -11,15 +11,20 @@ import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.ListModel;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import java.util.ArrayList;
import java.util.Vector;
import java.awt.Component;
import java.awt.Rectangle;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.ArrayList;
import java.util.Vector;
public class JNameEdList extends UIList implements CellEditorListener {
private static final int ICON_WIDTH = 20;
/**
* 原值为20,设计器图标由png替换为svg之后JNameEdList的icon大小为16x16
* 重命名是会出现左侧一部分带有背景色的渲染
*/
private static final int ICON_WIDTH = 16;
private boolean editable = true;
// kunsnat: 是否强制ListName是数字 (int型)

Loading…
Cancel
Save