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.List;
|
|
import javax.swing.JCheckBox;
|
import javax.swing.JPanel;
|
|
import com.vci.client.auth2.vo.OpItem;
|
|
public class RelationAndLifeCycleOpPanel extends JPanel {
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 5604599597365546210L;
|
private int column = 4;
|
|
public RelationAndLifeCycleOpPanel() {
|
super();
|
}
|
|
private String[] operations;
|
|
public String[] getOperations() {
|
return operations;
|
}
|
//add by caill start 2015.1.6
|
private String[] operationsChina;
|
|
public String[] operationsChina() {
|
return operationsChina;
|
}
|
public void setOperations(String[] operations, String[] operationsChina) { //2016.1.6添加参数
|
this.operations = operations;
|
this.operationsChina = operationsChina; //获取传递过来的存放有中文值的list
|
updateOperation();
|
}
|
//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());
|
//op.setName("测试");
|
//add by caill start 2015.1.6 将英文值从ActionCommand中取出存放到数据库中
|
if(cb.getActionCommand().toString() != null && cb.getActionCommand().toString().trim() != ""){
|
op.setName(cb.getActionCommand());
|
}else{
|
op.setName(cb.getText()); //跃迁的英文值还是从text中取出
|
}
|
//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.1.6 将关系和跃迁区域的值以中文的形式显示出来
|
public void updateOperation() {
|
int x = 0;
|
int y = 0;
|
for (int i = 0; i < operations.length; i++) {
|
JCheckBox cb = new JCheckBox();
|
if(i >= operationsChina.length ){
|
cb.setText(operations[i]); //跃迁的直接显示原来的英文即可
|
}else{
|
cb.setText(operationsChina[i]);
|
cb.setActionCommand(operations[i]);
|
//System.out.println(cb.getActionCommand());
|
}
|
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();
|
}
|
//add by caill end
|
/*public void updateOperation() {
|
int x = 0;
|
int y = 0;
|
for (int i = 0; i < operations.length; i++) {
|
JCheckBox cb = new JCheckBox(operations[i]);
|
JCheckBox cb = new JCheckBox();
|
cb.setText("test"+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;
|
}
|
}
|