|
|
|
@ -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(); |
|
|
|
|