summaryrefslogtreecommitdiffstats
path: root/src/cppcheckplus/text/MyButtonRenderer.java
blob: e030620c141cdfa9ead7cd3d0fdff9a7a82b5adf (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
package cppcheckplus.text;

import java.awt.BorderLayout;
import java.awt.Component;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import cppcheckplus.control.MyContorlUtil;

public class MyButtonRenderer implements TableCellRenderer {
    private JPanel panel;

    private JButton button;

    public static Icon icon0;
	public static Icon icon1;
	public static Icon icon2;
	private int state;//0是未确认, 1是确认正确, 2是确认误报
	
    public MyButtonRenderer() {
        initButton();

        initPanel();

        panel.add(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");
		if(state==0)
			button.setIcon(icon0);
		else if(state==1)
			button.setIcon(icon1);
		else if(state==2)
			button.setIcon(icon2);
    }

    private void initPanel() {
        panel = new JPanel();
        panel.setLayout(new BorderLayout());
    }

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, 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;
    }

}