1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50:
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60:
61:
62:
65: public class MetalComboBoxUI extends BasicComboBoxUI
66: {
67:
71: public class MetalComboBoxLayoutManager
72: extends BasicComboBoxUI.ComboBoxLayoutManager
73: {
74:
77: public MetalComboBoxLayoutManager()
78: {
79:
80: }
81:
82:
88: public void layoutContainer(Container parent)
89: {
90: layoutComboBox(parent, this);
91: }
92:
93:
99: public void superLayout(Container parent)
100: {
101: super.layoutContainer(parent);
102: }
103: }
104:
105:
110: public class MetalPropertyChangeListener
111: extends BasicComboBoxUI.PropertyChangeHandler
112: {
113:
116: public MetalPropertyChangeListener()
117: {
118:
119: }
120:
121:
127: public void propertyChange(PropertyChangeEvent e)
128: {
129: super.propertyChange(e);
130: String name = e.getPropertyName();
131: if (name.equals("editable"))
132: editablePropertyChanged(e);
133: else if (name.equals("enabled"))
134: {
135: if (arrowButton instanceof MetalComboBoxButton)
136: {
137: arrowButton.setFocusable(!comboBox.isEditable()
138: && comboBox.isEnabled());
139: comboBox.repaint();
140: }
141: }
142: else if (name.equals("background"))
143: {
144: Color c = (Color) e.getNewValue();
145: arrowButton.setBackground(c);
146: listBox.setBackground(c);
147: }
148: else if (name.equals("foreground"))
149: {
150: Color c = (Color) e.getNewValue();
151: arrowButton.setForeground(c);
152: listBox.setForeground(c);
153: }
154: }
155: }
156:
157:
164: public class MetalComboPopup extends BasicComboPopup
165: {
166:
171: public MetalComboPopup(JComboBox cBox)
172: {
173: super(cBox);
174: }
175:
176: public void delegateFocus(MouseEvent e)
177: {
178: super.delegateFocus(e);
179: }
180: }
181:
182:
185: public MetalComboBoxUI()
186: {
187: super();
188: }
189:
190:
197: public static ComponentUI createUI(JComponent component)
198: {
199: return new MetalComboBoxUI();
200: }
201:
202:
207: protected ComboBoxEditor createEditor()
208: {
209: return new MetalComboBoxEditor.UIResource();
210: }
211:
212:
217: protected ComboPopup createPopup()
218: {
219: return super.createPopup();
220: }
221:
222:
227: protected JButton createArrowButton()
228: {
229: JButton button = new MetalComboBoxButton(comboBox, new MetalComboBoxIcon(),
230: currentValuePane, listBox);
231: button.setMargin(new Insets(0, 1, 1, 3));
232: return button;
233: }
234:
235:
240: public PropertyChangeListener createPropertyChangeListener()
241: {
242: return new MetalPropertyChangeListener();
243: }
244:
245: public void paint(Graphics g, JComponent c)
246: {
247:
248: }
249:
250:
258: protected void editablePropertyChanged(PropertyChangeEvent e)
259: {
260: if (arrowButton instanceof MetalComboBoxButton)
261: {
262: MetalComboBoxButton b = (MetalComboBoxButton) arrowButton;
263: b.setIconOnly(comboBox.isEditable());
264: b.setFocusable(!comboBox.isEditable() && comboBox.isEnabled());
265: comboBox.repaint();
266: }
267: }
268:
269:
274: protected LayoutManager createLayoutManager()
275: {
276: return new MetalComboBoxLayoutManager();
277: }
278:
279:
284: protected void removeListeners()
285: {
286:
287: }
288:
289:
296: public Dimension getMinimumSize(JComponent c)
297: {
298: if (!isMinimumSizeDirty)
299: return new Dimension(cachedMinimumSize);
300:
301: Dimension d;
302: if (!comboBox.isEditable() && arrowButton != null
303: && arrowButton instanceof MetalComboBoxButton)
304: {
305: MetalComboBoxButton b = (MetalComboBoxButton) arrowButton;
306: d = getDisplaySize();
307: Insets arrowInsets = b.getInsets();
308: Insets comboInsets = comboBox.getInsets();
309: Icon icon = b.getComboIcon();
310: d.width += comboInsets.left + comboInsets.right;
311: d.width += arrowInsets.left + arrowInsets.right;
312: d.width += arrowInsets.right + icon.getIconWidth();
313: d.height += comboInsets.top + comboInsets.bottom;
314: d.height += arrowInsets.top + arrowInsets.bottom;
315: }
316: else if (comboBox.isEditable() && arrowButton != null && editor != null)
317: {
318: d = super.getMinimumSize(c);
319: Insets arrowMargin = arrowButton.getMargin();
320: d.height += arrowMargin.top + arrowMargin.bottom;
321: d.width += arrowMargin.left + arrowMargin.right;
322: }
323: else
324: {
325: d = super.getMinimumSize(c);
326: }
327: cachedMinimumSize.setSize(d.width, d.height);
328: isMinimumSizeDirty = false;
329: return new Dimension(cachedMinimumSize);
330: }
331:
332:
335: public void configureEditor()
336: {
337: super.configureEditor();
338: if (popupKeyListener != null)
339: editor.removeKeyListener(popupKeyListener);
340: if (focusListener != null)
341: editor.addFocusListener(focusListener);
342: }
343:
344:
347: public void unconfigureEditor()
348: {
349: super.unconfigureEditor();
350: if (focusListener != null)
351: editor.removeFocusListener(focusListener);
352: }
353:
354:
357: public void layoutComboBox(Container parent,
358: MetalComboBoxUI.MetalComboBoxLayoutManager manager)
359: {
360: if (comboBox.isEditable())
361: manager.superLayout(parent);
362: else if (arrowButton != null)
363: {
364: Insets comboInsets = comboBox.getInsets();
365: int width = comboBox.getWidth();
366: int height = comboBox.getHeight();
367: arrowButton.setBounds(comboInsets.left, comboInsets.top,
368: width - (comboInsets.left + comboInsets.right),
369: height - (comboInsets.top + comboInsets.bottom));
370: }
371: }
372: }