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: import ;
61:
62:
63:
66: public class MetalComboBoxUI extends BasicComboBoxUI
67: {
68:
72: public class MetalComboBoxLayoutManager
73: extends BasicComboBoxUI.ComboBoxLayoutManager
74: {
75:
78: public MetalComboBoxLayoutManager()
79: {
80:
81: }
82:
83:
89: public void layoutContainer(Container parent)
90: {
91: layoutComboBox(parent, this);
92: }
93:
94:
100: public void superLayout(Container parent)
101: {
102: super.layoutContainer(parent);
103: }
104: }
105:
106:
111: public class MetalPropertyChangeListener
112: extends BasicComboBoxUI.PropertyChangeHandler
113: {
114:
117: public MetalPropertyChangeListener()
118: {
119:
120: }
121:
122:
128: public void propertyChange(PropertyChangeEvent e)
129: {
130: super.propertyChange(e);
131: String name = e.getPropertyName();
132: if (name.equals("editable"))
133: editablePropertyChanged(e);
134: else if (name.equals("enabled"))
135: {
136: if (arrowButton instanceof MetalComboBoxButton)
137: {
138: arrowButton.setFocusable(!comboBox.isEditable()
139: && comboBox.isEnabled());
140: comboBox.repaint();
141: }
142: }
143: else if (name.equals("background"))
144: {
145: Color c = (Color) e.getNewValue();
146: arrowButton.setBackground(c);
147: listBox.setBackground(c);
148: }
149: else if (name.equals("foreground"))
150: {
151: Color c = (Color) e.getNewValue();
152: arrowButton.setForeground(c);
153: listBox.setForeground(c);
154: }
155: }
156: }
157:
158:
165: public class MetalComboPopup extends BasicComboPopup
166: {
167:
172: public MetalComboPopup(JComboBox cBox)
173: {
174: super(cBox);
175: }
176:
177: public void delegateFocus(MouseEvent e)
178: {
179: super.delegateFocus(e);
180: }
181: }
182:
183:
186: public MetalComboBoxUI()
187: {
188: super();
189: }
190:
191:
198: public static ComponentUI createUI(JComponent component)
199: {
200: return new MetalComboBoxUI();
201: }
202:
203:
208: protected ComboBoxEditor createEditor()
209: {
210: return new MetalComboBoxEditor.UIResource();
211: }
212:
213:
218: protected ComboPopup createPopup()
219: {
220: return new MetalComboPopup(comboBox);
221: }
222:
223:
228: protected JButton createArrowButton()
229: {
230: JButton button = new MetalComboBoxButton(comboBox, new MetalComboBoxIcon(),
231: new CellRendererPane(), listBox);
232: button.setMargin(new Insets(0, 1, 1, 3));
233: return button;
234: }
235:
236:
241: public PropertyChangeListener createPropertyChangeListener()
242: {
243: return new MetalPropertyChangeListener();
244: }
245:
246: public void paint(Graphics g, JComponent c)
247: {
248:
249: }
250:
251:
259: protected void editablePropertyChanged(PropertyChangeEvent e)
260: {
261: if (arrowButton instanceof MetalComboBoxButton)
262: {
263: MetalComboBoxButton b = (MetalComboBoxButton) arrowButton;
264: b.setIconOnly(comboBox.isEditable());
265: b.setFocusable(!comboBox.isEditable() && comboBox.isEnabled());
266: comboBox.repaint();
267: }
268: }
269:
270:
275: protected LayoutManager createLayoutManager()
276: {
277: return new MetalComboBoxLayoutManager();
278: }
279:
280:
285: protected void removeListeners()
286: {
287:
288: }
289:
290:
297: public Dimension getMinimumSize(JComponent c)
298: {
299: if (!isMinimumSizeDirty)
300: return new Dimension(cachedMinimumSize);
301:
302: Dimension d;
303: if (!comboBox.isEditable() && arrowButton != null
304: && arrowButton instanceof MetalComboBoxButton)
305: {
306: MetalComboBoxButton b = (MetalComboBoxButton) arrowButton;
307: d = getDisplaySize();
308: Insets insets = b.getInsets();
309: Insets arrowInsets = b.getInsets();
310: Insets comboInsets = comboBox.getInsets();
311: Icon icon = b.getComboIcon();
312: d.width += comboInsets.left + comboInsets.right;
313: d.width += arrowInsets.left + arrowInsets.right;
314: d.width += arrowInsets.right + icon.getIconWidth();
315: d.height += comboInsets.top + comboInsets.bottom;
316: d.height += arrowInsets.top + arrowInsets.bottom;
317: }
318: else if (comboBox.isEditable() && arrowButton != null && editor != null)
319: {
320: d = super.getMinimumSize(c);
321: Insets arrowMargin = arrowButton.getMargin();
322: d.height += arrowMargin.top + arrowMargin.bottom;
323: d.width += arrowMargin.left + arrowMargin.right;
324: }
325: else
326: {
327: d = super.getMinimumSize(c);
328: }
329: cachedMinimumSize.setSize(d.width, d.height);
330: isMinimumSizeDirty = false;
331: return new Dimension(cachedMinimumSize);
332: }
333:
334:
337: public void configureEditor()
338: {
339: super.configureEditor();
340: if (popupKeyListener != null)
341: editor.removeKeyListener(popupKeyListener);
342: if (focusListener != null)
343: editor.addFocusListener(focusListener);
344: }
345:
346:
349: public void unconfigureEditor()
350: {
351: super.unconfigureEditor();
352: if (focusListener != null)
353: editor.removeFocusListener(focusListener);
354: }
355:
356:
359: public void layoutComboBox(Container parent,
360: MetalComboBoxUI.MetalComboBoxLayoutManager manager)
361: {
362: if (comboBox.isEditable())
363: manager.superLayout(parent);
364: else if (arrowButton != null)
365: {
366: Insets comboInsets = comboBox.getInsets();
367: int width = comboBox.getWidth();
368: int height = comboBox.getHeight();
369: arrowButton.setBounds(comboInsets.left, comboInsets.top,
370: width - (comboInsets.left + comboInsets.right),
371: height - (comboInsets.top + comboInsets.bottom));
372: }
373: }
374: }