+setToString()

This commit is contained in:
Konstantin Bulenkov
2011-04-15 17:24:54 +04:00
parent 5a1edc83df
commit bc6f186a38
@@ -16,9 +16,11 @@
package com.intellij.ui.components.editors;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBList;
import com.intellij.util.Function;
import com.intellij.util.Icons;
import com.intellij.util.ui.EmptyIcon;
@@ -40,13 +42,14 @@ public class JBComboBoxTableCellEditorComponent extends JBLabel {
private final JBList myList = new JBList();
private Object[] myOptions = {};
private Object myValue;
private Function<Object, String> myToString = StringUtil.createToStringFunction(Object.class);
private ListCellRenderer myRenderer = new DefaultListCellRenderer() {
public Icon myEmptyIcon;
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
final JLabel label = (JLabel)super.getListCellRendererComponent(list, myToString.fun(value), index, isSelected, cellHasFocus);
if (value == myValue) {
label.setIcon(getIcon(isSelected));
} else {
@@ -135,4 +138,8 @@ public class JBComboBoxTableCellEditorComponent extends JBLabel {
public void setDefaultValue(Object value) {
myValue = value;
}
public void setToString(Function<Object, String> toString) {
myToString = toString;
}
}