ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.vci.client.auth2.view;
 
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
import javax.swing.JCheckBox;
import javax.swing.JPanel;
 
import com.vci.client.auth2.vo.OpItem;
 
public class OrdinaryOpPanel extends JPanel {
 
    /**
     * 
     */
    private static final long serialVersionUID = -635225769852964634L;
 
    private int column = 8;
 
    public OrdinaryOpPanel() {
        super();
    }
 
    private String[] operations;
 
    public String[] getOperations() {
        return operations;
    }
 
    public void setOperations(String[] operations) {
        this.operations = operations;
        updateOperation();
    }
    //add by caill start 2015.12.18
        private Map<String, String> operations2;
 
        public Map<String, String> getOperations2() {
            return operations2;
        }
        public void setOperations2(Map<String, String> operations2) {
            this.operations2 = operations2;        
            updateOperation2();
        }
    //add by caill end
    public OpItem[] getOpObject() {
        List<OpItem> ops = new ArrayList<OpItem>();
        JCheckBox[] checkBoxs = getOpCheckBoxs();
        for (JCheckBox cb : checkBoxs) {
            OpItem op = new OpItem();
            //op.setName(cb.getText());
            //add by caill 2015.12.18
            op.setName(cb.getActionCommand());    //将中文显示从JCheckBox的ActionCommand属性中取出来
            //add  by caill end
            op.setValue(cb.isSelected());
            if (!ops.contains(op)) {
                ops.add(op);
            }
        }
        return ops.toArray(new OpItem[ops.size()]);
    }
 
    // 一般操作面板授权控件
    public JCheckBox[] getOpCheckBoxs() {
        Component[] comps = (Component[]) this.getComponents();
        JCheckBox[] checkBoxs = new JCheckBox[comps.length];
        int i = 0;
        for (Component comp : comps) {
            checkBoxs[i] = (JCheckBox) comp;
            ++i;
        }
        return checkBoxs;
    }
    //add by caill start 2015.12.18 将中文放入JCheckBox的text中,将英文放入JCheckBox的ActionCommand中,便于显示
        public void updateOperation2() {
            int x = 0;
            int y = 0;
            this.removeAll();
            Set<String> keys = null;
            if(operations2.size()>0){
                keys = operations2.keySet();
            }        
            if(keys.size() != 0){
                int i = 0;
                for( Iterator<String> iterator = keys.iterator(); iterator.hasNext();){
                    JCheckBox cb = new JCheckBox();
                    String key = iterator.next();
                    cb.setText(key);
                    cb.setActionCommand(operations2.get(key));    //将中文显示放到JCheckBox的ActionCommand属性中
                    GridBagConstraints g_mpnl = new GridBagConstraints();
                    g_mpnl.insets = new Insets(10, 10, 10, 10);
                    g_mpnl.anchor = GridBagConstraints.WEST;
                    g_mpnl.gridx = ++x;
                    g_mpnl.gridy = y;
 
                    if ((i+1) % column == 0) {
                        ++y;
                        x = 0;
                    }
                    this.add(cb, g_mpnl);
                    i++;
                }
            }
            this.updateUI();
        }
    //add by caill end
    public void updateOperation() {
        int x = 0;
        int y = 0;
        this.removeAll();
        for (int i = 0; i < operations.length; i++) {
            JCheckBox cb = new JCheckBox(operations[i]);
 
            GridBagConstraints g_mpnl = new GridBagConstraints();
            g_mpnl.insets = new Insets(10, 10, 10, 10);
            g_mpnl.anchor = GridBagConstraints.WEST;
            g_mpnl.gridx = ++x;
            g_mpnl.gridy = y;
 
            if ((i+1) % column == 0) {
                ++y;
                x = 0;
            }
            this.add(cb, g_mpnl);
        }
        this.updateUI();
    }
 
    public int getColumn() {
        return column;
    }
 
    public void setColumn(int column) {
        this.column = column;
    }
}