mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Avoid costly component creation
This commit is contained in:
@@ -25,6 +25,8 @@ import java.awt.*;
|
||||
* @author Vladimir Kondratyev
|
||||
*/
|
||||
public abstract class ColoredListCellRenderer extends SimpleColoredComponent implements ListCellRenderer {
|
||||
private final ListCellRenderer myDefaultGtkRenderer = UIUtil.isUnderGTKLookAndFeel() ? new JComboBox().getRenderer() : null;
|
||||
|
||||
protected boolean mySelected;
|
||||
protected Color myForeground;
|
||||
protected Color mySelectionForeground;
|
||||
@@ -60,8 +62,8 @@ public abstract class ColoredListCellRenderer extends SimpleColoredComponent imp
|
||||
|
||||
customizeCellRenderer(list, value, index, selected, hasFocus);
|
||||
|
||||
if (UIUtil.isUnderGTKLookAndFeel() && list.getModel() instanceof ComboBoxModel) {
|
||||
final Component component = new JComboBox().getRenderer().getListCellRendererComponent(list, value, index, selected, hasFocus);
|
||||
if (myDefaultGtkRenderer != null && list.getModel() instanceof ComboBoxModel) {
|
||||
final Component component = myDefaultGtkRenderer.getListCellRendererComponent(list, value, index, selected, hasFocus);
|
||||
if (component instanceof JLabel) {
|
||||
return formatToLabel((JLabel)component);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ import java.awt.*;
|
||||
* @since 30.09.2010
|
||||
*/
|
||||
public abstract class ListCellRendererWrapper<T> implements ListCellRenderer {
|
||||
private final ListCellRenderer myDefaultRenderer = new JComboBox().getRenderer();
|
||||
|
||||
private boolean mySeparator;
|
||||
private Icon myIcon;
|
||||
private String myText;
|
||||
@@ -70,7 +72,7 @@ public abstract class ListCellRendererWrapper<T> implements ListCellRenderer {
|
||||
return separator;
|
||||
}
|
||||
|
||||
final Component component = new JComboBox().getRenderer().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
final Component component = myDefaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
if (component instanceof JLabel) {
|
||||
final JLabel label = (JLabel)component;
|
||||
label.setIcon(myIcon);
|
||||
|
||||
Reference in New Issue
Block a user