ludc
2024-09-14 36c2449aec5b51e5ed4e5c6841154b746060e09a
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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.util.HashMap;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
 
import com.vci.client.common.datatype.VTBoolean;
import com.vci.corba.omd.atm.AttribItem;
 
public class VTBooleanPanel extends VTDataTypePanel{
 
    /**
     * 
     */
    private static final long serialVersionUID = -3163232240849784069L;
    private JCheckBox cbNull;
    private JComboBox combDefValue;
    private HashMap<String, String> detailInfoMap = null;
    
    public VTBooleanPanel(){
        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("VTBoolean"));
        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);
        combDefValue = new JComboBox();
        combDefValue.addItem("false");
        combDefValue.addItem("true");
        combDefValue.setSelectedItem(String.valueOf(VTBoolean.defaultValue));
        combDefValue.setPreferredSize(new Dimension(187, 20));
        GridBagConstraints g1 = new GridBagConstraints();
        g1.insets = new Insets(15, 10, 5, 10);
        g1.gridx = 1;
        g1.gridy = 1;
        g1.gridwidth = GridBagConstraints.REMAINDER;
        leftPanel2.add(combDefValue, g1);
        
        //设置右边panel的控件
        rightPanel.setBorder(BorderFactory.createTitledBorder("值域"));
        rightPanel.setLayout(new GridBagLayout());
        
        JPanel rightPanel1 = new JPanel();
        JPanel rightPanel2 = new JPanel();
        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);
        
        rightPanel3.setLayout(new GridBagLayout());
    }
    
    public void addListener(){
    }
    
    /**
     * 获取VTDataType的详细信息
     * @return
     */
    public HashMap<String, String> getDetailInfo(){
        detailInfoMap = new HashMap<String, String>();
        String otherValue = "";
        
        detailInfoMap.put(VTDataTypePanel.DEFVALUE, (String)combDefValue.getSelectedItem());
        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 = otherValue.substring(0, otherValue.lastIndexOf(";"));
        detailInfoMap.put(VTDataTypePanel.OTHER, otherValue);
        
        return detailInfoMap;
    }
    
    /**
     * 根据当前状态(查看,创建,修改), 设置相关组件的显示情况
     * @param flag
     */
    public void updataUIStatus(AttribItem abItem, int flag){
        if(abItem != null){
            combDefValue.setSelectedItem(abItem.defValue);
        }
        if(flag == 0){
            cbNull.setEnabled(false);
//            cbFixLen.setEnabled(false);
            combDefValue.setEditable(false);
        }
        
        if(flag == 1 || flag == 2){
            cbNull.setEnabled(true);
//            cbFixLen.setEnabled(true);
            combDefValue.setEditable(true);
            
        }
        
    }
}