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:
219:
220:
221:
222: ListCellRenderer renderer = comboBox.getRenderer();
223: if (renderer == null || renderer instanceof UIResource)
224: comboBox.setRenderer(createRenderer());
225:
226: ComboBoxEditor currentEditor = comboBox.getEditor();
227: if (currentEditor == null || currentEditor instanceof UIResource)
228: {
229: currentEditor = createEditor();
230: comboBox.setEditor(currentEditor);
231: }
232: editor = currentEditor.getEditorComponent();
233:
234: installComponents();
235: installListeners();
236: if (arrowButton != null)
237: configureArrowButton();
238: if (editor != null)
239: configureEditor();
240: comboBox.setLayout(createLayoutManager());
241: comboBox.setFocusable(true);
242: installKeyboardActions();
243: comboBox.putClientProperty(BasicLookAndFeel.DONT_CANCEL_POPUP,
244: Boolean.TRUE);
245: }
246: }
247:
248:
255: public void uninstallUI(JComponent c)
256: {
257: setPopupVisible(comboBox, false);
258: popup.uninstallingUI();
259: uninstallKeyboardActions();
260: comboBox.setLayout(null);
261: uninstallComponents();
262: uninstallListeners();
263: uninstallDefaults();
264: comboBox = null;
265: }
266:
267:
273: protected void installDefaults()
274: {
275: LookAndFeel.installColorsAndFont(comboBox, "ComboBox.background",
276: "ComboBox.foreground", "ComboBox.font");
277: LookAndFeel.installBorder(comboBox, "ComboBox.border");
278: }
279:
280:
285: protected void installListeners()
286: {
287:
288: propertyChangeListener = createPropertyChangeListener();
289: comboBox.addPropertyChangeListener(propertyChangeListener);
290:
291: focusListener = createFocusListener();
292: comboBox.addFocusListener(focusListener);
293:
294: itemListener = createItemListener();
295: comboBox.addItemListener(itemListener);
296:
297: keyListener = createKeyListener();
298: comboBox.addKeyListener(keyListener);
299:
300:
301: listDataListener = createListDataListener();
302: comboBox.getModel().addListDataListener(listDataListener);
303:
304:
305: popupMouseListener = popup.getMouseListener();
306: comboBox.addMouseListener(popupMouseListener);
307:
308: popupMouseMotionListener = popup.getMouseMotionListener();
309: comboBox.addMouseMotionListener(popupMouseMotionListener);
310:
311: popupKeyListener = popup.getKeyListener();
312: comboBox.addKeyListener(popupKeyListener);
313: }
314:
315:
321: protected void uninstallDefaults()
322: {
323: if (comboBox.getFont() instanceof UIResource)
324: comboBox.setFont(null);
325:
326: if (comboBox.getForeground() instanceof UIResource)
327: comboBox.setForeground(null);
328:
329: if (comboBox.getBackground() instanceof UIResource)
330: comboBox.setBackground(null);
331:
332: LookAndFeel.uninstallBorder(comboBox);
333: }
334:
335:
340: protected void uninstallListeners()
341: {
342: comboBox.removePropertyChangeListener(propertyChangeListener);
343: propertyChangeListener = null;
344:
345: comboBox.removeFocusListener(focusListener);
346: listBox.removeFocusListener(focusListener);
347: focusListener = null;
348:
349: comboBox.removeItemListener(itemListener);
350: itemListener = null;
351:
352: comboBox.removeKeyListener(keyListener);
353: keyListener = null;
354:
355: comboBox.getModel().removeListDataListener(listDataListener);
356: listDataListener = null;
357:
358: if (popupMouseListener != null)
359: comboBox.removeMouseListener(popupMouseListener);
360: popupMouseListener = null;
361:
362: if (popupMouseMotionListener != null)
363: comboBox.removeMouseMotionListener(popupMouseMotionListener);
364: popupMouseMotionListener = null;
365:
366: if (popupKeyListener != null)
367: comboBox.removeKeyListener(popupKeyListener);
368: popupKeyListener = null;
369: }
370:
371:
376: protected ComboPopup createPopup()
377: {
378: return new BasicComboPopup(comboBox);
379: }
380:
381:
386: protected KeyListener createKeyListener()
387: {
388: return new KeyHandler();
389: }
390:
391:
397: protected FocusListener createFocusListener()
398: {
399: return new FocusHandler();
400: }
401:
402:
407: protected ListDataListener createListDataListener()
408: {
409: return new ListDataHandler();
410: }
411:
412:
418: protected ItemListener createItemListener()
419: {
420: return new ItemHandler();
421: }
422:
423:
429: protected PropertyChangeListener createPropertyChangeListener()
430: {
431: return new PropertyChangeHandler();
432: }
433:
434:
440: protected LayoutManager createLayoutManager()
441: {
442: return new ComboBoxLayoutManager();
443: }
444:
445:
451: protected ListCellRenderer createRenderer()
452: {
453: return new BasicComboBoxRenderer.UIResource();
454: }
455:
456:
464: protected ComboBoxEditor createEditor()
465: {
466: return new BasicComboBoxEditor.UIResource();
467: }
468:
469:
474: protected void installComponents()
475: {
476:
477: popup = createPopup();
478: listBox = popup.getList();
479:
480:
481: arrowButton = createArrowButton();
482: comboBox.add(arrowButton);
483:
484: if (comboBox.isEditable())
485: addEditor();
486:
487: comboBox.add(currentValuePane);
488: }
489:
490:
495: protected void uninstallComponents()
496: {
497:
498: unconfigureArrowButton();
499: comboBox.remove(arrowButton);
500: arrowButton = null;
501:
502: popup = null;
503:
504: if (comboBox.getRenderer() instanceof UIResource)
505: comboBox.setRenderer(null);
506:
507:
508:
509: ComboBoxEditor currentEditor = comboBox.getEditor();
510: if (currentEditor instanceof UIResource)
511: {
512: comboBox.setEditor(null);
513: editor = null;
514: }
515: }
516:
517:
520: public void addEditor()
521: {
522: removeEditor();
523: editor = comboBox.getEditor().getEditorComponent();
524: comboBox.add(editor);
525: }
526:
527:
530: public void removeEditor()
531: {
532: if (editor != null)
533: {
534: unconfigureEditor();
535: comboBox.remove(editor);
536: }
537: }
538:
539:
542: protected void configureEditor()
543: {
544: editor.setFont(comboBox.getFont());
545: if (popupKeyListener != null)
546: editor.addKeyListener(popupKeyListener);
547: if (keyListener != null)
548: editor.addKeyListener(keyListener);
549: comboBox.configureEditor(comboBox.getEditor(),
550: comboBox.getSelectedItem());
551: }
552:
553:
556: protected void unconfigureEditor()
557: {
558: if (popupKeyListener != null)
559: editor.removeKeyListener(popupKeyListener);
560: if (keyListener != null)
561: editor.removeKeyListener(keyListener);
562: }
563:
564:
569: public void configureArrowButton()
570: {
571: if (arrowButton != null)
572: {
573: arrowButton.setEnabled(comboBox.isEnabled());
574: arrowButton.setFocusable(false);
575: if (popupMouseListener != null)
576: arrowButton.addMouseListener(popupMouseListener);
577: if (popupMouseMotionListener != null)
578: arrowButton.addMouseMotionListener(popupMouseMotionListener);
579:
580:
581: arrowButton.putClientProperty(BasicLookAndFeel.DONT_CANCEL_POPUP,
582: Boolean.TRUE);
583: }
584: }
585:
586:
594: public void unconfigureArrowButton()
595: {
596: if (arrowButton != null)
597: {
598: if (popupMouseListener != null)
599: arrowButton.removeMouseListener(popupMouseListener);
600: if (popupMouseMotionListener != null)
601: arrowButton.removeMouseMotionListener(popupMouseMotionListener);
602: }
603: }
604:
605:
612: protected JButton createArrowButton()
613: {
614: return new BasicArrowButton(BasicArrowButton.SOUTH);
615: }
616:
617:
626: public boolean isPopupVisible(JComboBox c)
627: {
628: return popup.isVisible();
629: }
630:
631:
638: public void setPopupVisible(JComboBox c, boolean v)
639: {
640: if (v)
641: popup.show();
642: else
643: popup.hide();
644: }
645:
646:
653: public boolean isFocusTraversable(JComboBox c)
654: {
655: if (!comboBox.isEditable())
656: return true;
657:
658: return false;
659: }
660:
661:
667: public void paint(Graphics g, JComponent c)
668: {
669: hasFocus = comboBox.hasFocus();
670: if (! comboBox.isEditable())
671: {
672: Rectangle rect = rectangleForCurrentValue();
673: paintCurrentValueBackground(g, rect, hasFocus);
674: paintCurrentValue(g, rect, hasFocus);
675: }
676: }
677:
678:
685: public Dimension getPreferredSize(JComponent c)
686: {
687: return getMinimumSize(c);
688: }
689:
690:
698: public Dimension getMinimumSize(JComponent c)
699: {
700: if (isMinimumSizeDirty)
701: {
702: Insets i = getInsets();
703: Dimension d = getDisplaySize();
704: d.width += i.left + i.right + d.height;
705: cachedMinimumSize = new Dimension(d.width, d.height + i.top + i.bottom);
706: isMinimumSizeDirty = false;
707: }
708: return new Dimension(cachedMinimumSize);
709: }
710:
711:
719: public Dimension getMaximumSize(JComponent c)
720: {
721: return new Dimension(32767, 32767);
722: }
723:
724:
731: public int getAccessibleChildrenCount(JComponent c)
732: {
733: int count = 1;
734: if (comboBox.isEditable())
735: count = 2;
736: return count;
737: }
738:
739:
745: public Accessible getAccessibleChild(JComponent c, int i)
746: {
747: Accessible child = null;
748: switch (i)
749: {
750: case 0:
751: if (popup instanceof Accessible)
752: {
753: AccessibleContext ctx = ((Accessible) popup).getAccessibleContext();
754: ctx.setAccessibleParent(comboBox);
755: child = (Accessible) popup;
756: }
757: break;
758: case 1:
759: if (comboBox.isEditable() && editor instanceof Accessible)
760: {
761: AccessibleContext ctx =
762: ((Accessible) editor).getAccessibleContext();
763: ctx.setAccessibleParent(comboBox);
764: child = (Accessible) editor;
765: }
766: break;
767: }
768: return child;
769: }
770:
771:
779: protected boolean isNavigationKey(int keyCode)
780: {
781: return keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN
782: || keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT
783: || keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_ESCAPE
784: || keyCode == KeyEvent.VK_TAB;
785: }
786:
787:
791: protected void selectNextPossibleValue()
792: {
793: int index = comboBox.getSelectedIndex();
794: if (index != comboBox.getItemCount() - 1)
795: comboBox.setSelectedIndex(index + 1);
796: }
797:
798:
802: protected void selectPreviousPossibleValue()
803: {
804: int index = comboBox.getSelectedIndex();
805: if (index > 0)
806: comboBox.setSelectedIndex(index - 1);
807: }
808:
809:
813: protected void toggleOpenClose()
814: {
815: setPopupVisible(comboBox, ! isPopupVisible(comboBox));
816: }
817:
818:
825: protected Rectangle rectangleForCurrentValue()
826: {
827: int w = comboBox.getWidth();
828: int h = comboBox.getHeight();
829: Insets i = comboBox.getInsets();
830: int arrowSize = h - (i.top + i.bottom);
831: if (arrowButton != null)
832: arrowSize = arrowButton.getWidth();
833: return new Rectangle(i.left, i.top, w - (i.left + i.right + arrowSize),
834: h - (i.top + i.left));
835: }
836:
837:
842: protected Insets getInsets()
843: {
844: return comboBox.getInsets();
845: }
846:
847:
856: public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
857: {
858: Object currentValue = comboBox.getSelectedItem();
859: boolean isPressed = arrowButton.getModel().isPressed();
860:
861:
865: ListCellRenderer renderer = comboBox.getRenderer();
866: if (comboBox.getSelectedIndex() != -1)
867: {
868: Component comp;
869: if (hasFocus && ! isPopupVisible(comboBox))
870: {
871: comp = renderer.getListCellRendererComponent(listBox,
872: comboBox.getSelectedItem(), -1, true, false);
873: }
874: else
875: {
876: comp = renderer.getListCellRendererComponent(listBox,
877: comboBox.getSelectedItem(), -1, false, false);
878: Color bg = UIManager.getColor("ComboBox.disabledForeground");
879: comp.setBackground(bg);
880: }
881: comp.setFont(comboBox.getFont());
882: if (hasFocus && ! isPopupVisible(comboBox))
883: {
884: comp.setForeground(listBox.getSelectionForeground());
885: comp.setBackground(listBox.getSelectionBackground());
886: }
887: else if (comboBox.isEnabled())
888: {
889: comp.setForeground(comboBox.getForeground());
890: comp.setBackground(comboBox.getBackground());
891: }
892: else
893: {
894: Color fg = UIManager.getColor("ComboBox.disabledForeground");
895: comp.setForeground(fg);
896: Color bg = UIManager.getColor("ComboBox.disabledBackground");
897: comp.setBackground(bg);
898: }
899: currentValuePane.paintComponent(g, comp, comboBox, bounds.x, bounds.y,
900: bounds.width, bounds.height);
901: }
902: }
903:
904:
914: public void paintCurrentValueBackground(Graphics g, Rectangle bounds,
915: boolean hasFocus)
916: {
917: Color saved = g.getColor();
918: if (comboBox.isEnabled())
919: g.setColor(UIManager.getColor("UIManager.background"));
920: else
921: g.setColor(UIManager.getColor("UIManager.disabledBackground"));
922: g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
923: g.setColor(saved);
924: }
925:
926: private static final ListCellRenderer DEFAULT_RENDERER
927: = new DefaultListCellRenderer();
928:
929:
938: protected Dimension getDefaultSize()
939: {
940: Component comp = DEFAULT_RENDERER.getListCellRendererComponent(listBox,
941: " ", -1, false, false);
942: currentValuePane.add(comp);
943: comp.setFont(comboBox.getFont());
944: Dimension d = comp.getPreferredSize();
945: currentValuePane.remove(comp);
946: return d;
947: }
948:
949:
955: protected Dimension getDisplaySize()
956: {
957: Dimension dim = new Dimension();
958: ListCellRenderer renderer = comboBox.getRenderer();
959: if (renderer == null)
960: {
961: renderer = DEFAULT_RENDERER;
962: }
963:
964: Object prototype = comboBox.getPrototypeDisplayValue();
965: if (prototype != null)
966: {
967: Component comp = renderer.getListCellRendererComponent(listBox,
968: prototype, -1, false, false);
969: currentValuePane.add(comp);
970: comp.setFont(comboBox.getFont());
971: Dimension renderSize = comp.getPreferredSize();
972: currentValuePane.remove(comp);
973: dim.height = renderSize.height;
974: dim.width = renderSize.width;
975: }
976: else
977: {
978: ComboBoxModel model = comboBox.getModel();
979: int size = model.getSize();
980: if (size > 0)
981: {
982: for (int i = 0; i < size; ++i)
983: {
984: Component comp = renderer.getListCellRendererComponent(listBox,
985: model.getElementAt(i), -1, false, false);
986: currentValuePane.add(comp);
987: comp.setFont(comboBox.getFont());
988: Dimension renderSize = comp.getPreferredSize();
989: currentValuePane.remove(comp);
990: dim.width = Math.max(dim.width, renderSize.width);
991: dim.height = Math.max(dim.height, renderSize.height);
992: }
993: }
994: else
995: {
996: dim = getDefaultSize();
997: if (comboBox.isEditable())
998: dim.width = 100;
999: }
1000: }
1001: if (comboBox.isEditable())
1002: {
1003: Dimension editSize = editor.getPreferredSize();
1004: dim.width = Math.max(dim.width, editSize.width);
1005: dim.height = Math.max(dim.height, editSize.height);
1006: }
1007: displaySize.setSize(dim.width, dim.height);
1008: return dim;
1009: }
1010:
1011:
1015: protected void installKeyboardActions()
1016: {
1017: SwingUtilities.replaceUIInputMap(comboBox,
1018: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
1019: (InputMap) UIManager.get("ComboBox.ancestorInputMap"));
1020:
1021: }
1022:
1023:
1027: protected void uninstallKeyboardActions()
1028: {
1029: SwingUtilities.replaceUIInputMap(comboBox,
1030: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
1031:
1032: }
1033:
1034:
1040: public class ComboBoxLayoutManager implements LayoutManager
1041: {
1042:
1045: public ComboBoxLayoutManager()
1046: {
1047:
1048: }
1049:
1050:
1057: public void addLayoutComponent(String name, Component comp)
1058: {
1059:
1060: }
1061:
1062:
1068: public void removeLayoutComponent(Component comp)
1069: {
1070:
1071: }
1072:
1073:
1081: public Dimension preferredLayoutSize(Container parent)
1082: {
1083: return parent.getPreferredSize();
1084: }
1085:
1086:
1093: public Dimension minimumLayoutSize(Container parent)
1094: {
1095: return parent.getMinimumSize();
1096: }
1097:
1098:
1106: public void layoutContainer(Container parent)
1107: {
1108:
1109:
1110: Insets i = getInsets();
1111: int arrowSize = comboBox.getHeight() - (i.top + i.bottom);
1112: int editorWidth = comboBox.getBounds().width - arrowSize;
1113:
1114: if (arrowButton != null)
1115: arrowButton.setBounds(comboBox.getWidth() - (i.right + arrowSize),
1116: i.top, arrowSize, arrowSize);
1117: if (editor != null)
1118: editor.setBounds(rectangleForCurrentValue());
1119: }
1120: }
1121:
1122:
1128: public class FocusHandler extends Object implements FocusListener
1129: {
1130:
1133: public FocusHandler()
1134: {
1135:
1136: }
1137:
1138:
1144: public void focusGained(FocusEvent e)
1145: {
1146: hasFocus = true;
1147: comboBox.repaint();
1148: }
1149:
1150:
1156: public void focusLost(FocusEvent e)
1157: {
1158: hasFocus = false;
1159: if (! e.isTemporary() && comboBox.isLightWeightPopupEnabled())
1160: setPopupVisible(comboBox, false);
1161: comboBox.repaint();
1162: }
1163: }
1164:
1165:
1169: public class ItemHandler extends Object implements ItemListener
1170: {
1171:
1174: public ItemHandler()
1175: {
1176:
1177: }
1178:
1179:
1185: public void itemStateChanged(ItemEvent e)
1186: {
1187: ComboBoxModel model = comboBox.getModel();
1188: Object v = model.getSelectedItem();
1189: if (editor != null)
1190: comboBox.configureEditor(comboBox.getEditor(), v);
1191: comboBox.repaint();
1192: }
1193: }
1194:
1195:
1198: public class KeyHandler extends KeyAdapter
1199: {
1200: public KeyHandler()
1201: {
1202:
1203: }
1204:
1205:
1208: public void keyPressed(KeyEvent e)
1209: {
1210: if (comboBox.getModel().getSize() != 0 && comboBox.isEnabled())
1211: {
1212: if (! isNavigationKey(e.getKeyCode()))
1213: {
1214: if (! comboBox.isEditable())
1215: if (comboBox.selectWithKeyChar(e.getKeyChar()))
1216: e.consume();
1217: }
1218: else
1219: {
1220: if (e.getKeyCode() == KeyEvent.VK_UP && comboBox.isPopupVisible())
1221: selectPreviousPossibleValue();
1222: else if (e.getKeyCode() == KeyEvent.VK_DOWN)
1223: {
1224: if (comboBox.isPopupVisible())
1225: selectNextPossibleValue();
1226: else
1227: comboBox.showPopup();
1228: }
1229: else if (e.getKeyCode() == KeyEvent.VK_ENTER
1230: || e.getKeyCode() == KeyEvent.VK_ESCAPE)
1231: popup.hide();
1232: }
1233: }
1234: }
1235: }
1236:
1237:
1240: public class ListDataHandler extends Object implements ListDataListener
1241: {
1242:
1245: public ListDataHandler()
1246: {
1247:
1248: }
1249:
1250:
1255: public void contentsChanged(ListDataEvent e)
1256: {
1257: if (e.getIndex0() != -1 || e.getIndex1() != -1)
1258: {
1259: isMinimumSizeDirty = true;
1260: comboBox.revalidate();
1261: }
1262: if (editor != null)
1263: comboBox.configureEditor(comboBox.getEditor(),
1264: comboBox.getSelectedItem());
1265: comboBox.repaint();
1266: }
1267:
1268:
1273: public void intervalAdded(ListDataEvent e)
1274: {
1275: int start = e.getIndex0();
1276: int end = e.getIndex1();
1277: if (start == 0 && comboBox.getItemCount() - (end - start + 1) == 0)
1278: contentsChanged(e);
1279: else if (start != -1 || end != -1)
1280: {
1281: ListCellRenderer renderer = comboBox.getRenderer();
1282: ComboBoxModel model = comboBox.getModel();
1283: int w = displaySize.width;
1284: int h = displaySize.height;
1285:
1286: for (int i = start; i <= end; ++i)
1287: {
1288: Component comp = renderer.getListCellRendererComponent(listBox,
1289: model.getElementAt(i), -1, false, false);
1290: currentValuePane.add(comp);
1291: comp.setFont(comboBox.getFont());
1292: Dimension dim = comp.getPreferredSize();
1293: w = Math.max(w, dim.width);
1294: h = Math.max(h, dim.height);
1295: currentValuePane.remove(comp);
1296: }
1297: if (displaySize.width < w || displaySize.height < h)
1298: {
1299: if (displaySize.width < w)
1300: displaySize.width = w;
1301: if (displaySize.height < h)
1302: displaySize.height = h;
1303: comboBox.revalidate();
1304: if (editor != null)
1305: {
1306: comboBox.configureEditor(comboBox.getEditor(),
1307: comboBox.getSelectedItem());
1308: }
1309: }
1310: }
1311:
1312: }
1313:
1314:
1320: public void intervalRemoved(ListDataEvent e)
1321: {
1322: contentsChanged(e);
1323: }
1324: }
1325:
1326:
1329: public class PropertyChangeHandler extends Object
1330: implements PropertyChangeListener
1331: {
1332:
1335: public PropertyChangeHandler()
1336: {
1337:
1338: }
1339:
1340:
1345: public void propertyChange(PropertyChangeEvent e)
1346: {
1347:
1348: isMinimumSizeDirty = true;
1349:
1350: if (e.getPropertyName().equals("enabled"))
1351: {
1352: arrowButton.setEnabled(comboBox.isEnabled());
1353:
1354: if (comboBox.isEditable())
1355: comboBox.getEditor().getEditorComponent().setEnabled(
1356: comboBox.isEnabled());
1357: }
1358: else if (e.getPropertyName().equals("editable"))
1359: {
1360: if (comboBox.isEditable())
1361: {
1362: configureEditor();
1363: addEditor();
1364: }
1365: else
1366: {
1367: unconfigureEditor();
1368: removeEditor();
1369: }
1370:
1371: comboBox.revalidate();
1372: comboBox.repaint();
1373: }
1374: else if (e.getPropertyName().equals("dataModel"))
1375: {
1376:
1377: ComboBoxModel oldModel = (ComboBoxModel) e.getOldValue();
1378: if (oldModel != null)
1379: oldModel.removeListDataListener(listDataListener);
1380:
1381: if ((ComboBoxModel) e.getNewValue() != null)
1382: comboBox.getModel().addListDataListener(listDataListener);
1383: }
1384: else if (e.getPropertyName().equals("font"))
1385: {
1386: Font font = (Font) e.getNewValue();
1387: editor.setFont(font);
1388: listBox.setFont(font);
1389: arrowButton.setFont(font);
1390: comboBox.revalidate();
1391: comboBox.repaint();
1392: }
1393:
1394:
1395: }
1396: }
1397: }