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;
|
}
|
}
|