blob: 6ce0007db3db9ae985805f2d6e44ec0ba52e16a4 (
plain) (
blame)
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 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;
import cppcheckplus.control.MyContorlUtil;
public class MyButtonEditor extends AbstractCellEditor implements TableCellEditor {
/**
* serialVersionUID
*/
private static final long serialVersionUID = -6546334664166791132L;
private JPanel panel;
private JButton button;
private int state;
public static Icon icon0;
public static Icon icon1;
public static Icon icon2;
public MyButtonEditor() {
initButton();
initPanel();
panel.add(this.button, BorderLayout.CENTER);
}
private void initButton() {
button = new JButton();
icon0 = MyContorlUtil.getImageIcon("control/images/onError.gif");
icon1 = MyContorlUtil.getImageIcon("control/images/agree_ok.gif");
icon2 = MyContorlUtil.getImageIcon("control/images/agree_no.gif");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int res = JOptionPane.showConfirmDialog(null, "你想确认报告吗?", "choose one",
JOptionPane.YES_NO_OPTION);
if (res == JOptionPane.YES_OPTION) {
state=(state+1)%3;
}
// stopped!!!!
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 = (Integer) value;
if(state==0)
button.setIcon(icon0);
else if(state==1)
button.setIcon(icon1);
else if(state==2)
button.setIcon(icon2);
return panel;
}
@Override
public Object getCellEditorValue() {
return state;
}
}
|