01: /*
02: * Created on 12.04.2006
03: *
04: */
05: package org.jdesktop.swingx.combobox;
06:
07: import javax.swing.JComboBox;
08:
09: import org.jdesktop.swingx.InteractiveTestCase;
10: import org.jdesktop.swingx.JXFrame;
11:
12: public class EnumComboBoxModelIssues extends InteractiveTestCase {
13: enum MyEnum1 {
14: GoodStuff, BadStuff
15: };
16:
17: public static void main(String[] args) throws Exception {
18: EnumComboBoxModelIssues test = new EnumComboBoxModelIssues();
19: try {
20: test.runInteractiveTests();
21: // test.runInteractiveTests("interactive.*Table.*");
22: } catch (Exception e) {
23: System.err
24: .println("exception when executing interactive tests:");
25: e.printStackTrace();
26: }
27: }
28:
29: /**
30: * Issue #303-swingx: EnumComboBoxModel getSelectedItem throws ClassCastException.
31: *
32: * illegal implementation - doesn't comply to ComboBoxModel contract.
33: *
34: */
35: public void testSelectedItem() {
36: EnumComboBoxModel enumModel = new EnumComboBoxModel(
37: MyEnum1.class);
38: enumModel.setSelectedItem("something else");
39: enumModel.getSelectedItem();
40: }
41:
42: //------------------ visuals
43:
44: /**
45: * Issue #303-swingx: EnumComboBoxModel getSelectedItem throws ClassCastException.
46: *
47: * a visual example as to how easily this might happen.
48: *
49: */
50: public void interactiveSelectedItem() {
51: EnumComboBoxModel enumModel = new EnumComboBoxModel(
52: MyEnum1.class);
53: JComboBox box = new JComboBox(enumModel);
54: box.setEditable(true);
55: JXFrame frame = wrapInFrame(box, "enum combo throwing...");
56: frame.setVisible(true);
57: }
58:
59: }
|