package com.vci.client.omd.attribpool.ui;
|
|
import java.awt.BorderLayout;
|
import java.awt.Dimension;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.Insets;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.HashMap;
|
import javax.swing.BorderFactory;
|
import javax.swing.JButton;
|
import javax.swing.JCheckBox;
|
import javax.swing.JComboBox;
|
import javax.swing.JLabel;
|
import javax.swing.JOptionPane;
|
import javax.swing.JPanel;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTextArea;
|
import javax.swing.JTextField;
|
|
import com.vci.client.common.datatype.VTDouble;
|
import com.vci.corba.omd.atm.AttribItem;
|
|
public class VTDoublePanel extends VTDataTypePanel{
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = -2697390825347128628L;
|
private JCheckBox cbNull;
|
// private JComboBox combDim;
|
private JTextField tfAcc, tfLen, tfDefValue;
|
private JTextField tfRage;
|
private JButton btnLar, btnSma, btnLarE, btnSmaE, btnEqu, btnRage, btnUnEqu;
|
private JTextArea taRage;
|
private JButton btnRemove;
|
private HashMap<String, String> detailInfoMap = null;
|
private JPanel rightPanel1, rightPanel2, rightPanel3;
|
private JComboBox combRage1, combRage2;
|
private JTextField tfRage1, tfRage2;
|
private JButton btnRageAdd;
|
private boolean rageFlag = false;
|
|
public VTDoublePanel(){
|
initUI();
|
addListener();
|
}
|
|
private void initUI(){
|
|
this.setLayout(new GridBagLayout());
|
JPanel leftPanel = new JPanel();
|
JPanel rightPanel = new JPanel();
|
|
GridBagConstraints gb = new GridBagConstraints();
|
gb.gridx = 0;
|
gb.gridy = 0;
|
gb.weightx = 1.0;
|
gb.weighty = 1.0;
|
gb.fill = GridBagConstraints.BOTH;
|
|
this.add(leftPanel, gb);
|
gb.gridx = 1;
|
this.add(rightPanel, gb);
|
leftPanel.setPreferredSize(new Dimension(this.getSize().width/2,
|
this.getSize().height));
|
rightPanel.setPreferredSize(new Dimension(this.getSize().width/2,
|
this.getSize().height));
|
|
//设置左边panel的控件
|
leftPanel.setBorder(BorderFactory.createTitledBorder("VTDouble"));
|
leftPanel.setLayout(new BorderLayout());
|
JPanel leftPanel2 = new JPanel();
|
|
JScrollPane spLP1 = new JScrollPane();
|
spLP1.setBorder(null);
|
JScrollPane spLP2 = new JScrollPane();
|
spLP2.setBorder(null);
|
spLP2.setViewportView(leftPanel2);
|
|
leftPanel.add(spLP1, BorderLayout.NORTH);
|
leftPanel.add(spLP2, BorderLayout.CENTER);
|
|
cbNull = new JCheckBox("允许为空");
|
cbNull.setSelected(true);
|
// cbFixLen = new JCheckBox("定长");
|
// leftPanel1.add(cbFixLen);
|
|
leftPanel2.setLayout(new GridBagLayout());
|
GridBagConstraints g = new GridBagConstraints();
|
g.insets = new Insets(15, 10, 5, 10);
|
g.gridx = 0;
|
g.gridy = 0;
|
g.anchor = GridBagConstraints.WEST;//add by caill 2016.1.15将“长度”一列左对齐
|
leftPanel2.add(cbNull,g); //add by caill 2016.1.15将“允许为空”放到“精度”的上面
|
g.gridy = 1;
|
leftPanel2.add(new JLabel("精度"), g);
|
GridBagConstraints g1 = new GridBagConstraints();
|
g1.insets = new Insets(15, 10, 5, 10);
|
g1.anchor = GridBagConstraints.WEST; //add by caill 2016.1.15将文本框左对齐
|
g1.gridx = 1;
|
g1.gridy = 1;
|
//g1.weightx = 1.0;
|
g1.gridwidth = GridBagConstraints.REMAINDER;
|
tfAcc = new JTextField(30); //add by caill 2016.1.15增加文本框长度
|
tfAcc.setText(String.valueOf(VTDouble.accDefault));
|
leftPanel2.add(tfAcc, g1);
|
g.gridy = 2;
|
leftPanel2.add(new JLabel("长度"), g);
|
tfLen = new JTextField(30);
|
tfLen.setText(String.valueOf(VTDouble.lenDefault));
|
g1.gridy = 2;
|
leftPanel2.add(tfLen, g1);
|
//屏蔽使用量纲---start
|
// g.gridy = 2;
|
// leftPanel2.add(new JLabel("使用量纲"), g);
|
// combDim = new JComboBox();
|
// combDim.addItem("kg");
|
// combDim.addItem("km");
|
// combDim.setPreferredSize(new Dimension(120, 20));
|
// g1.gridy = 2;
|
// leftPanel2.add(combDim, g1);
|
//屏蔽使用量纲---end
|
|
g.gridy = 3;
|
leftPanel2.add(new JLabel("默认值"), g);
|
tfDefValue = new JTextField(30);
|
tfDefValue.setText(String.valueOf(VTDouble.defaultValue));
|
g1.gridy = 3;
|
leftPanel2.add(tfDefValue, g1);
|
|
//设置右边panel的控件
|
rightPanel.setBorder(BorderFactory.createTitledBorder("值域"));
|
rightPanel.setLayout(new GridBagLayout());
|
|
rightPanel1 = new JPanel();
|
rightPanel2 = new JPanel();
|
rightPanel3 = new JPanel();
|
|
GridBagConstraints gRight = new GridBagConstraints();
|
gRight.gridx = 0;
|
gRight.gridy = 0;
|
gRight.weightx = 1.0;
|
gRight.weighty = 1.0;
|
gRight.fill = GridBagConstraints.BOTH;
|
|
JScrollPane spRP1 = new JScrollPane();
|
spRP1.setBorder(null);
|
spRP1.setViewportView(rightPanel1);
|
JScrollPane spRP2 = new JScrollPane();
|
spRP2.setBorder(null);
|
spRP2.setViewportView(rightPanel2);
|
JScrollPane spRP3 = new JScrollPane();
|
spRP3.setBorder(null);
|
spRP3.setViewportView(rightPanel3);
|
|
rightPanel.add(spRP1, gRight);
|
gRight.gridy = 1;
|
rightPanel.add(spRP2, gRight);
|
gRight.gridy = 2;
|
rightPanel.add(spRP3, gRight);
|
|
//值域输入框
|
tfRage = new JTextField(30);//add by caill 2016.1.15调整值域输入框大小
|
//tfRage.setPreferredSize(new Dimension(200, 30));
|
rightPanel1.add(tfRage);
|
//当选择btnRage时, 值域输入框切换为区间选择框
|
combRage1 = new JComboBox();
|
combRage2 = new JComboBox();
|
combRage1.setPreferredSize(new Dimension(50, 20));
|
combRage2.setPreferredSize(new Dimension(50, 20));
|
combRage1.addItem("(");
|
combRage1.addItem("[");
|
combRage2.addItem(")");
|
combRage2.addItem("]");
|
tfRage1 = new JTextField(5);
|
tfRage2 = new JTextField(5);
|
btnRageAdd = new JButton("+");
|
|
btnLar = new JButton(">");
|
btnSma = new JButton("<");
|
btnLarE = new JButton(">=");
|
btnSmaE = new JButton("<=");
|
btnEqu = new JButton("=");
|
btnUnEqu = new JButton("!=");
|
btnRage = new JButton("([])");
|
|
rightPanel2.setLayout(new GridBagLayout());
|
GridBagConstraints gRP2 = new GridBagConstraints();
|
gRP2.gridx = 0;
|
gRP2.gridy = 0;
|
rightPanel2.add(btnLar, gRP2);
|
gRP2.gridx = 1;
|
rightPanel2.add(btnSma, gRP2);
|
gRP2.gridx = 2;
|
rightPanel2.add(btnLarE, gRP2);
|
gRP2.gridx = 3;
|
gRP2.gridwidth = 0;
|
rightPanel2.add(btnSmaE, gRP2);
|
gRP2.gridx = 0;
|
gRP2.gridy = 1;
|
gRP2.gridwidth = 1;
|
rightPanel2.add(btnEqu, gRP2);
|
gRP2.gridx = 1;
|
rightPanel2.add(btnUnEqu, gRP2);
|
gRP2.gridx = 2;
|
gRP2.gridwidth = 0;
|
rightPanel2.add(btnRage, gRP2);
|
|
rightPanel3.setLayout(new GridBagLayout());
|
taRage = new JTextArea(4, 20);
|
taRage.setLineWrap(true);
|
GridBagConstraints gr3 = new GridBagConstraints();
|
gr3.insets = new Insets(5, 5, 5, 5); //add by caill 2016.1.16调整文本域和“-”之间的距离
|
gr3.gridx = 0;
|
gr3.gridy = 0;
|
gr3.weightx = 0;
|
rightPanel3.add(new JScrollPane(taRage), gr3);
|
gr3.anchor = GridBagConstraints.NORTHWEST;
|
gr3.gridx = 1;
|
gr3.gridwidth = GridBagConstraints.REMAINDER;
|
gr3.insets = new Insets(5, 5, 5, 38);//add by caill 2016.1.16调整文本域和“-”的位置
|
btnRemove = new JButton("-");
|
rightPanel3.add(btnRemove, gr3);
|
}
|
|
public void addListener(){
|
btnLar.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if(rageFlag){
|
rageFlag = false;
|
rightPanel1.removeAll();
|
rightPanel1.add(tfRage);
|
rightPanel1.updateUI();
|
return;
|
}
|
String rageStr = tfRage.getText();
|
double rageDou;
|
if(rageStr.equals("")){
|
return;
|
}
|
try{
|
rageDou = Double.parseDouble(rageStr);
|
}catch (NumberFormatException e1){
|
JOptionPane.showMessageDialog(null, "请输入数字");
|
tfRage.setText("");
|
return;
|
}
|
|
String str = ">" + rageDou;
|
if(taRage.getText().equals("")){
|
taRage.setText(str);
|
}else if(taRage.getText().contains(str)){
|
JOptionPane.showMessageDialog(null, "该值域规则已经存在");
|
}else{
|
taRage.setText(taRage.getText() + "\n" + str);
|
}
|
|
}
|
});
|
|
btnSma.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if(rageFlag){
|
rageFlag = false;
|
rightPanel1.removeAll();
|
rightPanel1.add(tfRage);
|
rightPanel1.updateUI();
|
return;
|
}
|
String rageStr = tfRage.getText();
|
double rageDou;
|
if(rageStr.equals("")){
|
return;
|
}
|
try{
|
rageDou = Double.parseDouble(rageStr);
|
}catch (NumberFormatException e1){
|
JOptionPane.showMessageDialog(null, "请输入数字");
|
tfRage.setText("");
|
return;
|
}
|
|
String str = "<" + rageDou;
|
if(taRage.getText().equals("")){
|
taRage.setText(str);
|
}else if(taRage.getText().contains(str)){
|
JOptionPane.showMessageDialog(null, "该值域规则已经存在");
|
}else{
|
taRage.setText(taRage.getText() + "\n" + str);
|
}
|
|
}
|
});
|
|
btnEqu.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if(rageFlag){
|
rageFlag = false;
|
rightPanel1.removeAll();
|
rightPanel1.add(tfRage);
|
rightPanel1.updateUI();
|
return;
|
}
|
String rageStr = tfRage.getText();
|
if(rageStr.equals("")){
|
return;
|
}
|
double rageDou;
|
if(rageStr.equals("")){
|
return;
|
}
|
try{
|
rageDou = Double.parseDouble(rageStr);
|
}catch (NumberFormatException e1){
|
JOptionPane.showMessageDialog(null, "请输入数字");
|
tfRage.setText("");
|
return;
|
}
|
|
String str = "=" + rageDou;
|
if(taRage.getText().equals("")){
|
taRage.setText(str);
|
}else if(taRage.getText().contains(str)){
|
JOptionPane.showMessageDialog(null, "该值域规则已经存在");
|
}else{
|
taRage.setText(taRage.getText() + "\n" + str);
|
}
|
}
|
});
|
|
btnLarE.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if(rageFlag){
|
rageFlag = false;
|
rightPanel1.removeAll();
|
rightPanel1.add(tfRage);
|
rightPanel1.updateUI();
|
return;
|
}
|
String rageStr = tfRage.getText();
|
double rageDou;
|
if(rageStr.equals("")){
|
return;
|
}
|
try{
|
rageDou = Double.parseDouble(rageStr);
|
}catch (NumberFormatException e1){
|
JOptionPane.showMessageDialog(null, "请输入数字");
|
tfRage.setText("");
|
return;
|
}
|
|
String str = ">=" + rageDou;
|
if(taRage.getText().equals("")){
|
taRage.setText(str);
|
}else if(taRage.getText().contains(str)){
|
JOptionPane.showMessageDialog(null, "该值域规则已经存在");
|
}else{
|
taRage.setText(taRage.getText() + "\n" + str);
|
}
|
|
}
|
});
|
|
btnSmaE.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if(rageFlag){
|
rageFlag = false;
|
rightPanel1.removeAll();
|
rightPanel1.add(tfRage);
|
rightPanel1.updateUI();
|
return;
|
}
|
String rageStr = tfRage.getText();
|
double rageDou;
|
if(rageStr.equals("")){
|
return;
|
}
|
try{
|
rageDou = Double.parseDouble(rageStr);
|
}catch (NumberFormatException e1){
|
JOptionPane.showMessageDialog(null, "请输入数字");
|
tfRage.setText("");
|
return;
|
}
|
|
String str = "<=" + rageDou;
|
if(taRage.getText().equals("")){
|
taRage.setText(str);
|
}else if(taRage.getText().contains(str)){
|
JOptionPane.showMessageDialog(null, "该值域规则已经存在");
|
}else{
|
taRage.setText(taRage.getText() + "\n" + str);
|
}
|
|
}
|
});
|
|
btnUnEqu.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if(rageFlag){
|
rageFlag = false;
|
rightPanel1.removeAll();
|
rightPanel1.add(tfRage);
|
rightPanel1.updateUI();
|
return;
|
}
|
|
String rageStr = tfRage.getText();
|
double rageDou;
|
if(rageStr.equals("")){
|
return;
|
}
|
try{
|
rageDou = Double.parseDouble(rageStr);
|
}catch (NumberFormatException e1){
|
JOptionPane.showMessageDialog(null, "请输入数字");
|
tfRage.setText("");
|
return;
|
}
|
|
String str = "!=" + rageDou;
|
if(taRage.getText().equals("")){
|
taRage.setText(str);
|
}else if(taRage.getText().contains(str)){
|
JOptionPane.showMessageDialog(null, "该值域规则已经存在");
|
}else{
|
taRage.setText(taRage.getText() + "\n" + str);
|
}
|
|
}
|
});
|
|
//将输入框切换为区间选择框
|
btnRage.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if(rageFlag){
|
return;
|
}else{
|
rageFlag = true;
|
rightPanel1.removeAll();
|
rightPanel1.add(combRage1);
|
rightPanel1.add(tfRage1);
|
rightPanel1.add(new JLabel(","));
|
rightPanel1.add(tfRage2);
|
rightPanel1.add(combRage2);
|
rightPanel1.add(btnRageAdd);
|
rightPanel1.updateUI();
|
}
|
|
}
|
});
|
|
btnRageAdd.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
String rage1 = tfRage1.getText();
|
if(rage1.equals("") || !rage1.matches("[-+]?[0-9]*.*[0-9]*")){
|
JOptionPane.showMessageDialog(null, "请输入数字(左)");
|
tfRage1.setText("");
|
return;
|
}
|
|
String rage2 = tfRage2.getText();
|
if(rage2.equals("") || !rage2.matches("[-+]?[0-9]*.*[0-9]*")){
|
JOptionPane.showMessageDialog(null, "请输入数字(右)");
|
tfRage2.setText("");
|
return;
|
}
|
if(Double.valueOf(rage1) >= Double.valueOf(rage2)){
|
JOptionPane.showMessageDialog(null, "无效区间,请重新输入");
|
return;
|
}
|
String str = combRage1.getSelectedItem() + rage1 + "," + rage2 + combRage2.getSelectedItem();
|
if(taRage.getText().equals("")){
|
taRage.setText(str);
|
}else if(taRage.getText().contains(str)){
|
JOptionPane.showMessageDialog(null, "该值域规则已经存在");
|
}else{
|
taRage.setText(taRage.getText() + "\n" + str);
|
}
|
}
|
});
|
btnRemove.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
int lastN = taRage.getText().lastIndexOf("\n");
|
if(lastN > 0){
|
taRage.setText(taRage.getText().substring(0, lastN));
|
}else{
|
taRage.setText("");
|
}
|
|
}
|
});
|
}
|
|
/**
|
* 获取VTDataType的详细信息
|
* @return
|
*/
|
public HashMap<String, String> getDetailInfo(){
|
detailInfoMap = new HashMap<String, String>();
|
String otherValue = "";
|
|
detailInfoMap.put(VTDataTypePanel.DEFVALUE, tfDefValue.getText());
|
detailInfoMap.put(VTDataTypePanel.RAGE, taRage.getText().replace("\n", ";"));
|
|
if(cbNull.isSelected()){
|
otherValue += VTDataTypePanel.ALLOWNULL + " = yes;";
|
}else{
|
otherValue += VTDataTypePanel.ALLOWNULL + " = no;";
|
}
|
|
// if(cbFixLen.isSelected()){
|
// otherValue += VTDataTypePanel.ISFIXLEN + " = yes;";
|
// }else{
|
// otherValue += VTDataTypePanel.ISFIXLEN + " = no;";
|
// }
|
otherValue += VTDataTypePanel.ACCURACY + " = " +
|
tfAcc.getText() + ";";
|
otherValue += VTDataTypePanel.LENGTH + " = " +
|
tfLen.getText() + ";";
|
// otherValue += VTDataTypePanel.DIMENSION + " = " +
|
// (String)combDim.getSelectedItem() + ";";
|
otherValue = otherValue.substring(0, otherValue.lastIndexOf(";"));
|
detailInfoMap.put(VTDataTypePanel.OTHER, otherValue);
|
return detailInfoMap;
|
}
|
|
/**
|
* 根据当前状态(查看,创建,修改), 设置相关组件的显示情况
|
* @param flag
|
*/
|
public void updataUIStatus(AttribItem abItem, int flag){
|
if(abItem != null){
|
tfDefValue.setText(abItem.defValue);
|
taRage.setText(abItem.rage.replace(";", "\n"));
|
String other = abItem.other;
|
String accuracy = getOtherValueByType(other, "accuracy");
|
tfAcc.setText(accuracy);
|
String length = getOtherValueByType(other, "length");
|
tfLen.setText(length);
|
// String dimension = getOtherValueByType(other, "dimension");
|
// combDim.setSelectedItem(dimension);
|
}
|
if(flag == 0){
|
cbNull.setEnabled(false);
|
// cbFixLen.setEnabled(false);
|
// combDim.setEnabled(false);
|
tfDefValue.setEditable(false);
|
|
|
//值域输入组件群
|
{
|
tfRage.setVisible(false);
|
btnLar.setVisible(false);
|
btnSma.setVisible(false);
|
btnLarE.setVisible(false);
|
btnSmaE.setVisible(false);
|
btnEqu.setVisible(false);
|
btnRage.setVisible(false);
|
btnUnEqu.setVisible(false);
|
}
|
|
//值域显示组件群
|
{
|
taRage.setEditable(false);
|
btnRemove.setVisible(false);
|
}
|
}
|
|
if(flag == 1 || flag == 2){
|
cbNull.setEnabled(true);
|
// cbFixLen.setEnabled(true);
|
// combDim.setEnabled(true);
|
tfDefValue.setEditable(true);
|
|
|
//值域输入组件群
|
{
|
tfRage.setVisible(true);
|
btnLar.setVisible(true);
|
btnSma.setVisible(true);
|
btnLarE.setVisible(true);
|
btnSmaE.setVisible(true);
|
btnEqu.setVisible(true);
|
btnRage.setVisible(true);
|
btnUnEqu.setVisible(true);
|
}
|
|
//值域显示组件群
|
{
|
taRage.setEditable(true);
|
btnRemove.setVisible(true);
|
}
|
}
|
|
}
|
}
|