1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package cppcheckplus.text;
import cppcheckplus.control.MyContorlUtil;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractCellEditor;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
public class MyButtonEditor extends AbstractCellEditor
implements TableCellEditor {
/**
* serialVersionUID
*/
private static final long serialVersionUID = -6546334664166791132L;
public static Icon[] icon = new Icon[3];
// public static Icon icon[1];
// public static Icon icon[2];
private JPanel panel;
private JButton button;
private DeflectRow.Issure state = DeflectRow.Issure.NOTSURE_ISSURE;
public MyButtonEditor() {
initButton();
initPanel();
panel.add(this.button, BorderLayout.CENTER);
}
private void initButton() {
button = new JButton();
icon[0] =
MyContorlUtil.getImageIcon("control/images/agree_notsure.png");
icon[1] = MyContorlUtil.getImageIcon("control/images/agree_ok.gif");
icon[2] = MyContorlUtil.getImageIcon("control/images/agree_no.gif");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object[] options = {"待定", "确认", "误报"};
int res = JOptionPane.showOptionDialog(null, "请确认报告状态",
"选择状态", JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
state = DeflectRow.Issure.values()[res];
fireEditingStopped();
}
});
}
private void initPanel() {
panel = new JPanel();
panel.setLayout(new BorderLayout());
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row,
int column) {
state = (DeflectRow.Issure) value;
switch (state) {
case NOTSURE_ISSURE:
button.setIcon(icon[0]);
break;
case CURRECT_ISSURE:
button.setIcon(icon[1]);
break;
case WRONG_ISSURE:
button.setIcon(icon[2]);
break;
default:
button.setIcon(icon[0]);
break;
}
return panel;
}
@Override
public Object getCellEditorValue() {
return state;
}
}
|