1 |
/* BasicComboBoxRenderer.java -- |
/* BasicComboBoxRenderer.java -- |
2 |
Copyright (C) 2004 Free Software Foundation, Inc. |
Copyright (C) 2004, 2005 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
43 |
import java.awt.FontMetrics; |
import java.awt.FontMetrics; |
44 |
import java.io.Serializable; |
import java.io.Serializable; |
45 |
|
|
46 |
|
import javax.swing.JComboBox; |
47 |
import javax.swing.JLabel; |
import javax.swing.JLabel; |
48 |
import javax.swing.JList; |
import javax.swing.JList; |
49 |
import javax.swing.ListCellRenderer; |
import javax.swing.ListCellRenderer; |
55 |
import javax.swing.border.EmptyBorder; |
import javax.swing.border.EmptyBorder; |
56 |
|
|
57 |
/** |
/** |
58 |
* This class is renderer for the combo box. |
* A renderer for a {@link JComboBox}. |
59 |
* |
* |
60 |
* @author Olga Rodimina |
* @author Olga Rodimina |
61 |
*/ |
*/ |
62 |
public class BasicComboBoxRenderer extends JLabel implements ListCellRenderer, |
public class BasicComboBoxRenderer |
63 |
Serializable |
extends JLabel |
64 |
|
implements ListCellRenderer, Serializable |
65 |
{ |
{ |
66 |
/** |
/** |
67 |
* This border is used whenever renderer doesn't have a focus. |
* A shared border instance for all renderers. |
68 |
*/ |
*/ |
69 |
protected static Border noFocusBorder = new EmptyBorder(0, 0, 0, 0); |
protected static Border noFocusBorder = new EmptyBorder(0, 0, 0, 0); |
70 |
|
|
71 |
/** |
/** |
72 |
* Creates a new BasicComboBoxRenderer object. |
* Creates a new <code>BasicComboBoxRenderer</code> object. |
73 |
*/ |
*/ |
74 |
public BasicComboBoxRenderer() |
public BasicComboBoxRenderer() |
75 |
{ |
{ |
87 |
} |
} |
88 |
|
|
89 |
/** |
/** |
90 |
* getListCellRendererComponent |
* Returns a component that has been configured to display the given |
91 |
|
* <code>value</code>. |
92 |
* |
* |
93 |
* @param list List of items for which to the background and foreground |
* @param list List of items for which to the background and foreground |
94 |
* colors |
* colors |
129 |
|
|
130 |
setOpaque(true); |
setOpaque(true); |
131 |
|
|
|
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
|
|
|
|
132 |
if (isSelected) |
if (isSelected) |
133 |
{ |
{ |
134 |
setBackground(list.getSelectionBackground()); |
setBackground(list.getSelectionBackground()); |
135 |
setForeground(list.getSelectionForeground()); |
setForeground(list.getSelectionForeground()); |
136 |
} |
} |
137 |
else |
else |
138 |
{ |
{ |
139 |
setBackground(list.getBackground()); |
setBackground(list.getBackground()); |
140 |
setForeground(list.getForeground()); |
setForeground(list.getForeground()); |
141 |
} |
} |
142 |
|
|
143 |
setEnabled(list.isEnabled()); |
setEnabled(list.isEnabled()); |
153 |
return this; |
return this; |
154 |
} |
} |
155 |
|
|
156 |
|
/** |
157 |
|
* A subclass of {@link BasicComboBoxRenderer} that implements the |
158 |
|
* {@link javax.swing.plaf.UIResource} interface. |
159 |
|
*/ |
160 |
public static class UIResource extends BasicComboBoxRenderer |
public static class UIResource extends BasicComboBoxRenderer |
161 |
implements javax.swing.plaf.UIResource |
implements javax.swing.plaf.UIResource |
162 |
{ |
{ |
163 |
/** |
/** |
164 |
* Creates a new UIResource object. |
* Creates a new <code>UIResource</code> object. |
165 |
*/ |
*/ |
166 |
public UIResource() |
public UIResource() |
167 |
{ |
{ |