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: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61:
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79: import ;
80: import ;
81: import ;
82:
83:
89: public class BasicComboBoxUI extends ComboBoxUI
90: {
91:
95: protected JButton arrowButton;
96:
97:
100: protected JComboBox comboBox;
101:
102:
108: protected Component editor;
109:
110:
113: protected FocusListener focusListener;
114:
115:
118: protected boolean hasFocus;
119:
120:
123: protected ItemListener itemListener;
124:
125:
129: protected KeyListener keyListener;
130:
131:
136: protected JList listBox;
137:
138:
141: protected ListDataListener listDataListener;
142:
143:
146: protected ComboPopup popup;
147:
148: protected KeyListener popupKeyListener;
149:
150: protected MouseListener popupMouseListener;
151:
152: protected MouseMotionListener popupMouseMotionListener;
153:
154:
157: protected PropertyChangeListener propertyChangeListener;
158:
159:
162: Dimension displaySize = new Dimension();
163:
164:
167: protected CellRendererPane currentValuePane;
168:
169:
173: protected Dimension cachedMinimumSize;
174:
175:
178: protected boolean isMinimumSizeDirty = true;
179:
180:
183: public BasicComboBoxUI()
184: {
185: currentValuePane = new CellRendererPane();
186: cachedMinimumSize = new Dimension();
187: }
188:
189:
197: public static ComponentUI createUI(JComponent c)
198: {
199: return new BasicComboBoxUI();
200: }
201:
202:
209: public void installUI(JComponent c)
210: {
211: super.installUI(c);
212:
213: if (c instanceof JComboBox)
214: {
215: isMinimumSizeDirty = true;
216: comboBox = (JComboBox) c;
217: installDefaults();
218: popup = createPopup();
219: listBox = popup.getList();
220:
221:
222:
223:
224: ListCellRenderer renderer = comboBox.getRenderer();
225: if (renderer == null || renderer instanceof UIResource)
226: comboBox.setRenderer(createRenderer());
227:
228: ComboBoxEditor currentEditor = comboBox.getEditor();
229: if (currentEditor == null || currentEditor instanceof UIResource)
230: {
231: currentEditor = createEditor();
232: comboBox.setEditor(currentEditor);
233: }
234:
235: installComponents();
236: installListeners();
237: comboBox.setLayout(createLayoutManager());
238: comboBox.setFocusable(true);
239: installKeyboardActions();
240: comboBox.putClientProperty(BasicLookAndFeel.DONT_CANCEL_POPUP,
241: Boolean.TRUE);
242: }
243: }
244:
245:
252: public void uninstallUI(JComponent c)
253: {
254: setPopupVisible(comboBox, false);
255: popup.uninstallingUI();
256: uninstallKeyboardActions();
257: comboBox.setLayout(null);
258: uninstallComponents();
259: uninstallListeners();
260: uninstallDefaults();
261: comboBox = null;
262: }
263:
264:
270: protected void installDefaults()
271: {
272: LookAndFeel.installColorsAndFont(comboBox, "ComboBox.background",
273: "ComboBox.foreground", "ComboBox.font");
274: LookAndFeel.installBorder(comboBox, "ComboBox.border");
275: }
276:
277:
282: protected void installListeners()
283: {
284:
285: propertyChangeListener = createPropertyChangeListener();
286: comboBox.addPropertyChangeListener(propertyChangeListener);
287:
288: focusListener = createFocusListener();
289: comboBox.addFocusListener(focusListener);
290:
291: itemListener = createItemListener();
292: comboBox.addItemListener(itemListener);
293:
294: keyListener = createKeyListener();
295: comboBox.addKeyListener(keyListener);
296:
297:
298: listDataListener = createListDataListener();
299: comboBox.getModel().addListDataListener(listDataListener);
300:
301:
302: popupMouseListener = popup.getMouseListener();
303: comboBox.addMouseListener(popupMouseListener);
304:
305: popupMouseMotionListener = popup.getMouseMotionListener();
306: comboBox.addMouseMotionListener(popupMouseMotionListener);
307:
308: popupKeyListener = popup.getKeyListener();
309: comboBox.addKeyListener(popupKeyListener);
310: }
311:
312:
318: protected void uninstallDefaults()
319: {
320: if (comboBox.getFont() instanceof UIResource)
321: comboBox.setFont(null);
322:
323: if (comboBox.getForeground() instanceof UIResource)
324: comboBox.setForeground(null);
325:
326: if (comboBox.getBackground() instanceof UIResource)
327: comboBox.setBackground(null);
328:
329: LookAndFeel.uninstallBorder(comboBox);
330: }
331:
332:
337: protected void uninstallListeners()
338: {
339: comboBox.removePropertyChangeListener(propertyChangeListener);
340: propertyChangeListener = null;
341:
342: comboBox.removeFocusListener(focusListener);
343: listBox.removeFocusListener(focusListener);
344: focusListener = null;
345:
346: comboBox.removeItemListener(itemListener);
347: itemListener = null;
348:
349: comboBox.removeKeyListener(keyListener);
350: keyListener = null;
351:
352: comboBox.getModel().removeListDataListener(listDataListener);
353: listDataListener = null;
354:
355: if (popupMouseListener != null)
356: comboBox.removeMouseListener(popupMouseListener);
357: popupMouseListener = null;
358:
359: if (popupMouseMotionListener != null)
360: comboBox.removeMouseMotionListener(popupMouseMotionListener);
361: popupMouseMotionListener = null;
362:
363: if (popupKeyListener != null)
364: comboBox.removeKeyListener(popupKeyListener);
365: popupKeyListener = null;
366: }
367:
368:
373: protected ComboPopup createPopup()
374: {
375: return new BasicComboPopup(comboBox);
376: }
377:
378:
383: protected KeyListener createKeyListener()
384: {
385: return new KeyHandler();
386: }
387:
388:
394: protected FocusListener createFocusListener()
395: {
396: return new FocusHandler();
397: }
398:
399:
404: protected ListDataListener createListDataListener()
405: {
406: return new ListDataHandler();
407: }
408:
409:
415: protected ItemListener createItemListener()
416: {
417: return new ItemHandler();
418: }
419:
420:
426: protected PropertyChangeListener createPropertyChangeListener()
427: {
428: return new PropertyChangeHandler();
429: }
430:
431:
437: protected LayoutManager createLayoutManager()
438: {
439: return new ComboBoxLayoutManager();
440: }
441:
442:
448: protected ListCellRenderer createRenderer()
449: {
450: return new BasicComboBoxRenderer.UIResource();
451: }
452:
453:
461: protected ComboBoxEditor createEditor()
462: {
463: return new BasicComboBoxEditor.UIResource();
464: }
465:
466:
471: protected void installComponents()
472: {
473:
474: arrowButton = createArrowButton();
475: comboBox.add(arrowButton);
476: if (arrowButton != null)
477: configureArrowButton();
478:
479: if (comboBox.isEditable())
480: addEditor();
481:
482: comboBox.add(currentValuePane);
483: }
484:
485:
490: protected void uninstallComponents()
491: {
492:
493: if (arrowButton != null)
494: {
495: unconfigureArrowButton();
496: }
497:
498:
499: if (editor != null)
500: {
501: unconfigureEditor();
502: }
503:
504: comboBox.removeAll();
505: arrowButton = null;
506: }
507:
508:
511: public void addEditor()
512: {
513: removeEditor();
514: editor = comboBox.getEditor().getEditorComponent();
515: if (editor != null)
516: {
517: configureEditor();
518: comboBox.add(editor);
519: }
520: }
521:
522:
525: public void removeEditor()
526: {
527: if (editor != null)
528: {
529: unconfigureEditor();
530: comboBox.remove(editor);
531: }
532: }
533:
534:
537: protected void configureEditor()
538: {
539: editor.setFont(comboBox.getFont());
540: if (popupKeyListener != null)
541: editor.addKeyListener(popupKeyListener);
542: if (keyListener != null)
543: editor.addKeyListener(keyListener);
544: comboBox.configureEditor(comboBox.getEditor(),
545: comboBox.getSelectedItem());
546: }
547:
548:
551: protected void unconfigureEditor()
552: {
553: if (popupKeyListener != null)
554: editor.removeKeyListener(popupKeyListener);
555: if (keyListener != null)
556: editor.removeKeyListener(keyListener);
557: }
558:
559:
564: public void configureArrowButton()
565: {
566: if (arrowButton != null)
567: {
568: arrowButton.setEnabled(comboBox.isEnabled());
569: arrowButton.setFocusable(false);
570: arrowButton.addMouseListener(popup.getMouseListener());
571: arrowButton.addMouseMotionListener(popup.getMouseMotionListener());
572:
573:
574: arrowButton.putClientProperty(BasicLookAndFeel.DONT_CANCEL_POPUP,
575: Boolean.TRUE);
576: }
577: }
578:
579:
587: public void unconfigureArrowButton()
588: {
589: if (arrowButton != null)
590: {
591: if (popupMouseListener != null)
592: arrowButton.removeMouseListener(popupMouseListener);
593: if (popupMouseMotionListener != null)
594: arrowButton.removeMouseMotionListener(popupMouseMotionListener);
595: }
596: }
597:
598:
605: protected JButton createArrowButton()
606: {
607: return new BasicArrowButton(BasicArrowButton.SOUTH);
608: }
609:
610:
619: public boolean isPopupVisible(JComboBox c)
620: {
621: return popup.isVisible();
622: }
623:
624:
631: public void setPopupVisible(JComboBox c, boolean v)
632: {
633: if (v)
634: popup.show();
635: else
636: popup.hide();
637: }
638:
639:
646: public boolean isFocusTraversable(JComboBox c)
647: {
648: if (!comboBox.isEditable())
649: return true;
650:
651: return false;
652: }
653:
654:
660: public void paint(Graphics g, JComponent c)
661: {
662: hasFocus = comboBox.hasFocus();
663: if (! comboBox.isEditable())
664: {
665: Rectangle rect = rectangleForCurrentValue();
666: paintCurrentValueBackground(g, rect, hasFocus);
667: paintCurrentValue(g, rect, hasFocus);
668: }
669: }
670:
671:
678: public Dimension getPreferredSize(JComponent c)
679: {
680: return getMinimumSize(c);
681: }
682:
683:
691: public Dimension getMinimumSize(JComponent c)
692: {
693: if (isMinimumSizeDirty)
694: {
695: Insets i = getInsets();
696: Dimension d = getDisplaySize();
697: d.width += i.left + i.right + d.height;
698: cachedMinimumSize = new Dimension(d.width, d.height + i.top + i.bottom);
699: isMinimumSizeDirty = false;
700: }
701: return new Dimension(cachedMinimumSize);
702: }
703:
704:
712: public Dimension getMaximumSize(JComponent c)
713: {
714: return new Dimension(32767, 32767);
715: }
716:
717:
724: public int getAccessibleChildrenCount(JComponent c)
725: {
726: int count = 1;
727: if (comboBox.isEditable())
728: count = 2;
729: return count;
730: }
731:
732:
738: public Accessible getAccessibleChild(JComponent c, int i)
739: {
740: Accessible child = null;
741: switch (i)
742: {
743: case 0:
744: if (popup instanceof Accessible)
745: {
746: AccessibleContext ctx = ((Accessible) popup).getAccessibleContext();
747: ctx.setAccessibleParent(comboBox);
748: child = (Accessible) popup;
749: }
750: break;
751: case 1:
752: if (comboBox.isEditable() && editor instanceof Accessible)
753: {
754: AccessibleContext ctx =
755: ((Accessible) editor).getAccessibleContext();
756: ctx.setAccessibleParent(comboBox);
757: child = (Accessible) editor;
758: }
759: break;
760: }
761: return child;
762: }
763:
764:
772: protected boolean isNavigationKey(int keyCode)
773: {
774: return keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN
775: || keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT
776: || keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_ESCAPE
777: || keyCode == KeyEvent.VK_TAB;
778: }
779:
780:
784: protected void selectNextPossibleValue()
785: {
786: int index = comboBox.getSelectedIndex();
787: if (index != comboBox.getItemCount() - 1)
788: comboBox.setSelectedIndex(index + 1);
789: }
790:
791:
795: protected void selectPreviousPossibleValue()
796: {
797: int index = comboBox.getSelectedIndex();
798: if (index > 0)
799: comboBox.setSelectedIndex(index - 1);
800: }
801:
802:
806: protected void toggleOpenClose()
807: {
808: setPopupVisible(comboBox, ! isPopupVisible(comboBox));
809: }
810:
811:
818: protected Rectangle rectangleForCurrentValue()
819: {
820: int w = comboBox.getWidth();
821: int h = comboBox.getHeight();
822: Insets i = comboBox.getInsets();
823: int arrowSize = h - (i.top + i.bottom);
824: if (arrowButton != null)
825: arrowSize = arrowButton.getWidth();
826: return new Rectangle(i.left, i.top, w - (i.left + i.right + arrowSize),
827: h - (i.top + i.left));
828: }
829:
830:
835: protected Insets getInsets()
836: {
837: return comboBox.getInsets();
838: }
839:
840:
849: public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
850: {
851:
855: ListCellRenderer renderer = comboBox.getRenderer();
856: if (comboBox.getSelectedIndex() != -1)
857: {
858: Component comp;
859: if (hasFocus && ! isPopupVisible(comboBox))
860: {
861: comp = renderer.getListCellRendererComponent(listBox,
862: comboBox.getSelectedItem(), -1, true, false);
863: }
864: else
865: {
866: comp = renderer.getListCellRendererComponent(listBox,
867: comboBox.getSelectedItem(), -1, false, false);
868: Color bg = UIManager.getColor("ComboBox.disabledForeground");
869: comp.setBackground(bg);
870: }
871: comp.setFont(comboBox.getFont());
872: if (hasFocus && ! isPopupVisible(comboBox))
873: {
874: comp.setForeground(listBox.getSelectionForeground());
875: comp.setBackground(listBox.getSelectionBackground());
876: }
877: else if (comboBox.isEnabled())
878: {
879: comp.setForeground(comboBox.getForeground());
880: comp.setBackground(comboBox.getBackground());
881: }
882: else
883: {
884: Color fg = UIManager.getColor("ComboBox.disabledForeground");
885: comp.setForeground(fg);
886: Color bg = UIManager.getColor("ComboBox.disabledBackground");
887: comp.setBackground(bg);
888: }
889: currentValuePane.paintComponent(g, comp, comboBox, bounds.x, bounds.y,
890: bounds.width, bounds.height);
891: }
892: }
893:
894:
904: public void paintCurrentValueBackground(Graphics g, Rectangle bounds,
905: boolean hasFocus)
906: {
907: Color saved = g.getColor();
908: if (comboBox.isEnabled())
909: g.setColor(UIManager.getColor("UIManager.background"));
910: else
911: g.setColor(UIManager.getColor("UIManager.disabledBackground"));
912: g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
913: g.setColor(saved);
914: }
915:
916: private static final ListCellRenderer DEFAULT_RENDERER
917: = new DefaultListCellRenderer();
918:
919:
928: protected Dimension getDefaultSize()
929: {
930: Component comp = DEFAULT_RENDERER.getListCellRendererComponent(listBox,
931: " ", -1, false, false);
932: currentValuePane.add(comp);
933: comp.setFont(comboBox.getFont());
934: Dimension d = comp.getPreferredSize();
935: currentValuePane.remove(comp);
936: return d;
937: }
938:
939:
945: protected Dimension getDisplaySize()
946: {
947: Dimension dim = new Dimension();
948: ListCellRenderer renderer = comboBox.getRenderer();
949: if (renderer == null)
950: {
951: renderer = DEFAULT_RENDERER;
952: }
953:
954: Object prototype = comboBox.getPrototypeDisplayValue();
955: if (prototype != null)
956: {
957: Component comp = renderer.getListCellRendererComponent(listBox,
958: prototype, -1, false, false);
959: currentValuePane.add(comp);
960: comp.setFont(comboBox.getFont());
961: Dimension renderSize = comp.getPreferredSize();
962: currentValuePane.remove(comp);
963: dim.height = renderSize.height;
964: dim.width = renderSize.width;
965: }
966: else
967: {
968: ComboBoxModel model = comboBox.getModel();
969: int size = model.getSize();
970: if (size > 0)
971: {
972: for (int i = 0; i < size; ++i)
973: {
974: Component comp = renderer.getListCellRendererComponent(listBox,
975: model.getElementAt(i), -1, false, false);
976: currentValuePane.add(comp);
977: comp.setFont(comboBox.getFont());
978: Dimension renderSize = comp.getPreferredSize();
979: currentValuePane.remove(comp);
980: dim.width = Math.max(dim.width, renderSize.width);
981: dim.height = Math.max(dim.height, renderSize.height);
982: }
983: }
984: else
985: {
986: dim = getDefaultSize();
987: if (comboBox.isEditable())
988: dim.width = 100;
989: }
990: }
991: if (comboBox.isEditable())
992: {
993: Dimension editSize = editor.getPreferredSize();
994: dim.width = Math.max(dim.width, editSize.width);
995: dim.height = Math.max(dim.height, editSize.height);
996: }
997: displaySize.setSize(dim.width, dim.height);
998: return dim;
999: }
1000:
1001:
1005: protected void installKeyboardActions()
1006: {
1007: SwingUtilities.replaceUIInputMap(comboBox,
1008: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
1009: (InputMap) UIManager.get("ComboBox.ancestorInputMap"));
1010:
1011: }
1012:
1013:
1017: protected void uninstallKeyboardActions()
1018: {
1019: SwingUtilities.replaceUIInputMap(comboBox,
1020: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
1021:
1022: }
1023:
1024:
1030: public class ComboBoxLayoutManager implements LayoutManager
1031: {
1032:
1035: public ComboBoxLayoutManager()
1036: {
1037:
1038: }
1039:
1040:
1047: public void addLayoutComponent(String name, Component comp)
1048: {
1049:
1050: }
1051:
1052:
1058: public void removeLayoutComponent(Component comp)
1059: {
1060:
1061: }
1062:
1063:
1071: public Dimension preferredLayoutSize(Container parent)
1072: {
1073: return parent.getPreferredSize();
1074: }
1075:
1076:
1083: public Dimension minimumLayoutSize(Container parent)
1084: {
1085: return parent.getMinimumSize();
1086: }
1087:
1088:
1096: public void layoutContainer(Container parent)
1097: {
1098:
1099:
1100: Insets i = getInsets();
1101: int arrowSize = comboBox.getHeight() - (i.top + i.bottom);
1102:
1103: if (arrowButton != null)
1104: arrowButton.setBounds(comboBox.getWidth() - (i.right + arrowSize),
1105: i.top, arrowSize, arrowSize);
1106: if (editor != null)
1107: editor.setBounds(rectangleForCurrentValue());
1108: }
1109: }
1110:
1111:
1117: public class FocusHandler extends Object implements FocusListener
1118: {
1119:
1122: public FocusHandler()
1123: {
1124:
1125: }
1126:
1127:
1133: public void focusGained(FocusEvent e)
1134: {
1135: hasFocus = true;
1136: comboBox.repaint();
1137: }
1138:
1139:
1145: public void focusLost(FocusEvent e)
1146: {
1147: hasFocus = false;
1148: if (! e.isTemporary() && comboBox.isLightWeightPopupEnabled())
1149: setPopupVisible(comboBox, false);
1150: comboBox.repaint();
1151: }
1152: }
1153:
1154:
1158: public class ItemHandler extends Object implements ItemListener
1159: {
1160:
1163: public ItemHandler()
1164: {
1165:
1166: }
1167:
1168:
1174: public void itemStateChanged(ItemEvent e)
1175: {
1176: ComboBoxModel model = comboBox.getModel();
1177: Object v = model.getSelectedItem();
1178: if (editor != null)
1179: comboBox.configureEditor(comboBox.getEditor(), v);
1180: comboBox.repaint();
1181: }
1182: }
1183:
1184:
1187: public class KeyHandler extends KeyAdapter
1188: {
1189: public KeyHandler()
1190: {
1191:
1192: }
1193:
1194:
1197: public void keyPressed(KeyEvent e)
1198: {
1199: if (comboBox.getModel().getSize() != 0 && comboBox.isEnabled())
1200: {
1201: if (! isNavigationKey(e.getKeyCode()))
1202: {
1203: if (! comboBox.isEditable())
1204: if (comboBox.selectWithKeyChar(e.getKeyChar()))
1205: e.consume();
1206: }
1207: else
1208: {
1209: if (e.getKeyCode() == KeyEvent.VK_UP && comboBox.isPopupVisible())
1210: selectPreviousPossibleValue();
1211: else if (e.getKeyCode() == KeyEvent.VK_DOWN)
1212: {
1213: if (comboBox.isPopupVisible())
1214: selectNextPossibleValue();
1215: else
1216: comboBox.showPopup();
1217: }
1218: else if (e.getKeyCode() == KeyEvent.VK_ENTER
1219: || e.getKeyCode() == KeyEvent.VK_ESCAPE)
1220: popup.hide();
1221: }
1222: }
1223: }
1224: }
1225:
1226:
1229: public class ListDataHandler extends Object implements ListDataListener
1230: {
1231:
1234: public ListDataHandler()
1235: {
1236:
1237: }
1238:
1239:
1244: public void contentsChanged(ListDataEvent e)
1245: {
1246: if (e.getIndex0() != -1 || e.getIndex1() != -1)
1247: {
1248: isMinimumSizeDirty = true;
1249: comboBox.revalidate();
1250: }
1251: if (editor != null)
1252: comboBox.configureEditor(comboBox.getEditor(),
1253: comboBox.getSelectedItem());
1254: comboBox.repaint();
1255: }
1256:
1257:
1262: public void intervalAdded(ListDataEvent e)
1263: {
1264: int start = e.getIndex0();
1265: int end = e.getIndex1();
1266: if (start == 0 && comboBox.getItemCount() - (end - start + 1) == 0)
1267: contentsChanged(e);
1268: else if (start != -1 || end != -1)
1269: {
1270: ListCellRenderer renderer = comboBox.getRenderer();
1271: ComboBoxModel model = comboBox.getModel();
1272: int w = displaySize.width;
1273: int h = displaySize.height;
1274:
1275: for (int i = start; i <= end; ++i)
1276: {
1277: Component comp = renderer.getListCellRendererComponent(listBox,
1278: model.getElementAt(i), -1, false, false);
1279: currentValuePane.add(comp);
1280: comp.setFont(comboBox.getFont());
1281: Dimension dim = comp.getPreferredSize();
1282: w = Math.max(w, dim.width);
1283: h = Math.max(h, dim.height);
1284: currentValuePane.remove(comp);
1285: }
1286: if (displaySize.width < w || displaySize.height < h)
1287: {
1288: if (displaySize.width < w)
1289: displaySize.width = w;
1290: if (displaySize.height < h)
1291: displaySize.height = h;
1292: comboBox.revalidate();
1293: if (editor != null)
1294: {
1295: comboBox.configureEditor(comboBox.getEditor(),
1296: comboBox.getSelectedItem());
1297: }
1298: }
1299: }
1300:
1301: }
1302:
1303:
1309: public void intervalRemoved(ListDataEvent e)
1310: {
1311: contentsChanged(e);
1312: }
1313: }
1314:
1315:
1318: public class PropertyChangeHandler extends Object
1319: implements PropertyChangeListener
1320: {
1321:
1324: public PropertyChangeHandler()
1325: {
1326:
1327: }
1328:
1329:
1334: public void propertyChange(PropertyChangeEvent e)
1335: {
1336:
1337: String propName = e.getPropertyName();
1338: if (propName.equals("enabled"))
1339: {
1340: boolean enabled = comboBox.isEnabled();
1341: if (editor != null)
1342: editor.setEnabled(enabled);
1343: if (arrowButton != null)
1344: arrowButton.setEnabled(enabled);
1345:
1346: comboBox.repaint();
1347: }
1348: else if (propName.equals("editor") && comboBox.isEditable())
1349: {
1350: addEditor();
1351: comboBox.revalidate();
1352: }
1353: else if (e.getPropertyName().equals("editable"))
1354: {
1355: if (comboBox.isEditable())
1356: {
1357: addEditor();
1358: }
1359: else
1360: {
1361: removeEditor();
1362: }
1363:
1364: comboBox.revalidate();
1365: }
1366: else if (propName.equals("model"))
1367: {
1368:
1369: ComboBoxModel oldModel = (ComboBoxModel) e.getOldValue();
1370: if (oldModel != null && listDataListener != null)
1371: oldModel.removeListDataListener(listDataListener);
1372:
1373: ComboBoxModel newModel = (ComboBoxModel) e.getNewValue();
1374: if (newModel != null && listDataListener != null)
1375: comboBox.getModel().addListDataListener(listDataListener);
1376:
1377: if (editor != null)
1378: {
1379: comboBox.configureEditor(comboBox.getEditor(),
1380: comboBox.getSelectedItem());
1381: }
1382: isMinimumSizeDirty = true;
1383: comboBox.revalidate();
1384: comboBox.repaint();
1385: }
1386: else if (propName.equals("font"))
1387: {
1388: Font font = (Font) e.getNewValue();
1389: if (editor != null)
1390: {
1391: editor.setFont(font);
1392: }
1393: listBox.setFont(font);
1394: isMinimumSizeDirty = true;
1395: comboBox.revalidate();
1396: }
1397: else if (propName.equals("prototypeDisplayValue"))
1398: {
1399: isMinimumSizeDirty = true;
1400: comboBox.revalidate();
1401: }
1402: else if (propName.equals("renderer"))
1403: {
1404: isMinimumSizeDirty = true;
1405: comboBox.revalidate();
1406: }
1407:
1408: }
1409: }
1410: }