1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.desy.acop.chart.customizer;
24
25 import java.lang.reflect.Method;
26 import java.util.Vector;
27 import javax.swing.ComboBoxModel;
28 import javax.swing.JComboBox;
29 import de.desy.acop.chart.Acop;
30
31 public class AcopJComBox extends JComboBox
32 {
33 private Acop acopBean;
34 private String proper;
35 private int index;
36 public AcopJComBox(ComboBoxModel aModel)
37 {
38 super(aModel);
39
40 }
41 public AcopJComBox(Object[] items)
42 {
43 super(items);
44
45 }
46 public AcopJComBox(Vector<?> items)
47 {
48 super(items);
49
50 }
51 public AcopJComBox()
52 {
53 super();
54
55 }
56 public void setAcopBean(Acop Bean)
57 {
58 acopBean = Bean;
59 try
60 {
61 Method m = acopBean.getClass().getMethod("get" + proper, null);
62 index = (int) (Integer) m.invoke(acopBean, null);
63 this.setSelectedIndex(index);
64 }
65 catch (Exception ex)
66 {
67 ex.printStackTrace();
68 }
69 }
70 public AcopJComBox(String property, Object[] enumObject)
71 {
72 super();
73 proper = property;
74 for (int i = 0; i < enumObject.length; i++)
75 this.addItem(enumObject[i].toString());
76 addItemListener(new java.awt.event.ItemListener()
77 {
78 public void itemStateChanged(java.awt.event.ItemEvent e)
79 {
80 if (index != getSelectedIndex())
81 {
82 if (acopBean != null)
83 {
84 try
85 {
86 Method m = acopBean.getClass().getMethod("set" + proper, int.class);
87 int soll = getSelectedIndex();
88 m.invoke(acopBean, soll);
89
90
91
92
93
94 firePropertyChange(proper, index, soll);
95 index = soll;
96 }
97 catch (Exception ex)
98 {
99 ex.printStackTrace();
100 }
101 }
102 }
103 }
104 });
105 }
106 }