diff options
Diffstat (limited to 'src/cppcheckplus/text/MyButtonEditor.java')
-rw-r--r-- | src/cppcheckplus/text/MyButtonEditor.java | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/cppcheckplus/text/MyButtonEditor.java b/src/cppcheckplus/text/MyButtonEditor.java new file mode 100644 index 0000000..6ce0007 --- /dev/null +++ b/src/cppcheckplus/text/MyButtonEditor.java | |||
@@ -0,0 +1,88 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.Component; | ||
5 | import java.awt.event.ActionEvent; | ||
6 | import java.awt.event.ActionListener; | ||
7 | |||
8 | import javax.swing.AbstractCellEditor; | ||
9 | import javax.swing.Icon; | ||
10 | import javax.swing.JButton; | ||
11 | import javax.swing.JOptionPane; | ||
12 | import javax.swing.JPanel; | ||
13 | import javax.swing.JTable; | ||
14 | import javax.swing.table.TableCellEditor; | ||
15 | |||
16 | import cppcheckplus.control.MyContorlUtil; | ||
17 | |||
18 | public class MyButtonEditor extends AbstractCellEditor implements TableCellEditor { | ||
19 | |||
20 | /** | ||
21 | * serialVersionUID | ||
22 | */ | ||
23 | private static final long serialVersionUID = -6546334664166791132L; | ||
24 | |||
25 | private JPanel panel; | ||
26 | |||
27 | private JButton button; | ||
28 | |||
29 | private int state; | ||
30 | public static Icon icon0; | ||
31 | public static Icon icon1; | ||
32 | public static Icon icon2; | ||
33 | public MyButtonEditor() { | ||
34 | |||
35 | initButton(); | ||
36 | |||
37 | initPanel(); | ||
38 | |||
39 | panel.add(this.button, BorderLayout.CENTER); | ||
40 | } | ||
41 | |||
42 | private void initButton() { | ||
43 | button = new JButton(); | ||
44 | |||
45 | icon0 = MyContorlUtil.getImageIcon("control/images/onError.gif"); | ||
46 | icon1 = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); | ||
47 | icon2 = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); | ||
48 | button.addActionListener(new ActionListener() { | ||
49 | public void actionPerformed(ActionEvent e) { | ||
50 | int res = JOptionPane.showConfirmDialog(null, "你想确认报告吗?", "choose one", | ||
51 | JOptionPane.YES_NO_OPTION); | ||
52 | |||
53 | if (res == JOptionPane.YES_OPTION) { | ||
54 | state=(state+1)%3; | ||
55 | } | ||
56 | // stopped!!!! | ||
57 | fireEditingStopped(); | ||
58 | |||
59 | } | ||
60 | }); | ||
61 | |||
62 | } | ||
63 | |||
64 | private void initPanel() { | ||
65 | panel = new JPanel(); | ||
66 | |||
67 | panel.setLayout(new BorderLayout()); | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { | ||
72 | state = (Integer) value; | ||
73 | |||
74 | if(state==0) | ||
75 | button.setIcon(icon0); | ||
76 | else if(state==1) | ||
77 | button.setIcon(icon1); | ||
78 | else if(state==2) | ||
79 | button.setIcon(icon2); | ||
80 | return panel; | ||
81 | } | ||
82 | |||
83 | @Override | ||
84 | public Object getCellEditorValue() { | ||
85 | return state; | ||
86 | } | ||
87 | |||
88 | } \ No newline at end of file | ||