Jay
2024-11-08 02722a3f9eca857ce7fffea352e9f7ee692a1b71
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
package com.iailab.netsdk.demo.frame.TargetRecognition;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
 
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
 
import com.iailab.netsdk.demo.module.TargetRecognitionModule;
import com.sun.jna.Memory;
 
import com.iailab.netsdk.common.*;
import com.iailab.netsdk.lib.NetSDKLib.*;
import com.iailab.netsdk.lib.ToolKits;
 
public class ModifyPersonDialog extends JDialog{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    private String groupId = ""; 
    private String groupName = "";
    private String uid = "";
    private String pszFileDst = "";
    private Memory memory = null;
    private CANDIDATE_INFOEX stuCandidate = null;
    
    private WindowCloseListener listener;
    public void addWindowCloseListener(WindowCloseListener listener) {
        this.listener = listener;
    }
    
    /**
     * @param groupId 人脸库ID
     * @param groupName  人脸库名称
     * @param uid  人员标识符
     * @param pszFileDst  下载到本地的图片路径
     * @param memory  图片数据
     * @param stuCandidate  人员信息
     */
    public ModifyPersonDialog(String groupId, 
                              String groupName, 
                              String uid, 
                              String pszFileDst, 
                              Memory memory, 
                              CANDIDATE_INFOEX stuCandidate){
        
        setTitle(Res.string().getModifyPerson());
        setLayout(new BorderLayout());
        setModal(true); 
        pack();
        setSize(520, 400);
        setResizable(false);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);   // 释放窗体
        
        this.groupId = groupId;
        this.groupName = groupName;
        this.uid = uid;
        this.pszFileDst = pszFileDst;
        this.memory = memory;
        this.stuCandidate = stuCandidate;
        
        FaceServerAddPanel faceServerAddPanel = new FaceServerAddPanel();
        add(faceServerAddPanel, BorderLayout.CENTER);
        
        showPersonInfo();
        
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e){
                dispose();
            }
        });
    }
    public class FaceServerAddPanel extends JPanel{
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
 
        public FaceServerAddPanel() {
            BorderEx.set(this, "", 4);
            setLayout(new BorderLayout());
            
            JPanel imagePanel = new JPanel();
            JPanel personInfoPanel = new JPanel();
            
            Dimension dimension = this.getPreferredSize();
            dimension.height = 400;
            dimension.width = 250;
            personInfoPanel.setPreferredSize(dimension);
            
            add(imagePanel, BorderLayout.CENTER);
            add(personInfoPanel, BorderLayout.WEST);
            
            /////////// 添加的人脸图片面板 //////////////////
            imagePanel.setLayout(new BorderLayout());
            addImagePanel = new PaintPanel();   // 添加的人员信息图片显示
            selectImageBtn = new JButton(Res.string().getSelectPicture());
            imagePanel.add(addImagePanel, BorderLayout.CENTER);
            imagePanel.add(selectImageBtn, BorderLayout.SOUTH);
            
            ////////// 添加的人脸信息面板 /////////////////
            personInfoPanel.setLayout(new FlowLayout());
            JLabel goroupIdLabel = new JLabel(Res.string().getFaceGroupId(), JLabel.CENTER);
            JLabel goroupNameLabel = new JLabel(Res.string().getFaceGroupName(), JLabel.CENTER);
            JLabel uidLabel = new JLabel(Res.string().getUid(), JLabel.CENTER);
            JLabel nameLabel = new JLabel(Res.string().getName(), JLabel.CENTER);
            JLabel sexLabel = new JLabel(Res.string().getSex(), JLabel.CENTER);
            JLabel birthdayLabel = new JLabel(Res.string().getBirthday(), JLabel.CENTER);
            JLabel idTypeLabel = new JLabel(Res.string().getIdType(), JLabel.CENTER);
            JLabel idLabel = new JLabel(Res.string().getIdNo(), JLabel.CENTER);
            
            Dimension dimension2 = new Dimension();
            dimension2.width = 80;
            dimension2.height = 20;
            uidLabel.setPreferredSize(dimension2);
            goroupIdLabel.setPreferredSize(dimension2);
            goroupNameLabel.setPreferredSize(dimension2);
            nameLabel.setPreferredSize(dimension2);
            sexLabel.setPreferredSize(dimension2);
            birthdayLabel.setPreferredSize(dimension2);
            idTypeLabel.setPreferredSize(dimension2);
            idLabel.setPreferredSize(dimension2);
            
            goroupIdTextField = new JTextField();
            goroupNameTextField = new JTextField();
            uidTextField = new JTextField();
            nameTextField = new JTextField();
            sexComboBox = new JComboBox(Res.string().getSexStrings());
            birthdayBtn = new DateChooserJButtonEx(""); 
            idTypeComboBox = new JComboBox(Res.string().getIdStrings());
            idTextField = new JTextField();
            birthdayCheckBox = new JCheckBox();
            
            modifyBtn = new JButton(Res.string().getModify());
            cancelBtn = new JButton(Res.string().getCancel());
            
            birthdayBtn.setStartYear(1900);
            
            Dimension dimension3 = new Dimension();
            dimension3.width = 150;
            dimension3.height = 20;
            
            sexComboBox.setPreferredSize(dimension3);    
            idTypeComboBox.setPreferredSize(dimension3);
            goroupIdTextField.setPreferredSize(dimension3);
            goroupNameTextField.setPreferredSize(dimension3);
            uidTextField.setPreferredSize(dimension3);
            nameTextField.setPreferredSize(dimension3);
            idTextField.setPreferredSize(dimension3);
            birthdayBtn.setPreferredSize(new Dimension(130, 20));
            birthdayCheckBox.setPreferredSize(new Dimension(20, 20));
            modifyBtn.setPreferredSize(new Dimension(120, 20));
            cancelBtn.setPreferredSize(new Dimension(120, 20));
 
            goroupIdTextField.setEditable(false);
            goroupNameTextField.setEditable(false);
            uidTextField.setEditable(false);
            birthdayCheckBox.setSelected(true);
            
            goroupIdTextField.setText(groupId);
            goroupNameTextField.setText(groupName);
            uidTextField.setText(uid);
            
            personInfoPanel.add(goroupIdLabel);
            personInfoPanel.add(goroupIdTextField);
            personInfoPanel.add(goroupNameLabel);
            personInfoPanel.add(goroupNameTextField);
            personInfoPanel.add(uidLabel);
            personInfoPanel.add(uidTextField);
            personInfoPanel.add(nameLabel);
            personInfoPanel.add(nameTextField);
            personInfoPanel.add(sexLabel);
            personInfoPanel.add(sexComboBox);
            personInfoPanel.add(idTypeLabel);
            personInfoPanel.add(idTypeComboBox);
            personInfoPanel.add(idLabel);
            personInfoPanel.add(idTextField);
            personInfoPanel.add(birthdayLabel);
            personInfoPanel.add(birthdayBtn);
            personInfoPanel.add(birthdayCheckBox);
            personInfoPanel.add(modifyBtn);
            personInfoPanel.add(cancelBtn);
            
            birthdayCheckBox.addChangeListener(new ChangeListener() {        
                @Override
                public void stateChanged(ChangeEvent arg0) {
                    if(birthdayCheckBox.isSelected()) {
                        birthdayBtn.setEnabled(true);
                    } else {
                        birthdayBtn.setEnabled(false);
                    }
                }
            });
            
            // 选择图片,获取图片的信息
            selectImageBtn.addActionListener(new ActionListener() {                
                @Override
                public void actionPerformed(ActionEvent arg0) {
                    String picPath = "";
                    
                    // 选择图片,获取图片路径,并在界面显示
                    picPath = ToolKits.openPictureFile(addImagePanel);
                            
                    if(!picPath.equals("")) {
                        memory = null;
                        try {
                            memory = ToolKits.readPictureFile(picPath);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }                
                }
            });
            
            // 修改人员信息
            modifyBtn.addActionListener(new ActionListener() {            
                @Override
                public void actionPerformed(ActionEvent arg0) {
                    boolean bRet = TargetRecognitionModule.modifyPerson(groupId, uid,
                                                                      memory, 
                                                                      nameTextField.getText(), 
                                                                      sexComboBox.getSelectedIndex(), 
                                                                      birthdayCheckBox.isSelected(), birthdayBtn.getText().toString(), 
                                                                      idTypeComboBox.getSelectedIndex(), idTextField.getText());                                
 
                    if(bRet) {
                        JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(null, Res.string().getFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
                    }
    
                    dispose();
                    
                    listener.windowClosing();                                
                }
            });
            
            // 取消,关闭
            cancelBtn.addActionListener(new ActionListener() {            
                @Override
                public void actionPerformed(ActionEvent arg0) {
                    dispose();    
                }
            });
        }         
    }
    
    private void showPersonInfo() {
        File file = null;
        if(!pszFileDst.equals("")) {
            file = ToolKits.openPictureFile(pszFileDst, addImagePanel);        
        }
        
        if(file != null) {
            file.delete();
        }
        
        try {
            nameTextField.setText(new String(stuCandidate.stPersonInfo.szPersonName, "GBK").trim());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        
        sexComboBox.setSelectedIndex(stuCandidate.stPersonInfo.bySex & 0xff);
        
        idTypeComboBox.setSelectedIndex(stuCandidate.stPersonInfo.byIDType & 0xff);
        
        idTextField.setText(new String(stuCandidate.stPersonInfo.szID).trim());
        
        if(stuCandidate.stPersonInfo == null) {
            birthdayCheckBox.setSelected(false);
            birthdayBtn.setText(birthdayBtn.getDate().toString());
        } else {
            if(String.valueOf((int)stuCandidate.stPersonInfo.wYear).equals("0000") 
                || String.valueOf((int)stuCandidate.stPersonInfo.wYear).equals("0") 
                || String.valueOf( stuCandidate.stPersonInfo.byMonth & 0xff).equals("0") 
                || String.valueOf( stuCandidate.stPersonInfo.byMonth & 0xff).equals("00") 
                || String.valueOf(stuCandidate.stPersonInfo.byDay & 0xff).equals("0") 
                || String.valueOf(stuCandidate.stPersonInfo.byDay & 0xff).equals("00")) {
                birthdayCheckBox.setSelected(false);
                birthdayBtn.setText(birthdayBtn.getDate().toString());
            } else {
                birthdayCheckBox.setSelected(true);
                birthdayBtn.setText(String.valueOf((int)stuCandidate.stPersonInfo.wYear) + "-" + 
                                                      String.valueOf( stuCandidate.stPersonInfo.byMonth & 0xff) + "-" + 
                                                      String.valueOf(stuCandidate.stPersonInfo.byDay & 0xff));
            }
        }
    }
    
    // 添加人员信息窗口的组件
    public PaintPanel addImagePanel;
    private JButton selectImageBtn;
    
    private JTextField goroupIdTextField;
    private JTextField goroupNameTextField;
    private JTextField uidTextField;
    public JTextField nameTextField;
    public JComboBox sexComboBox;
    public DateChooserJButtonEx birthdayBtn; 
    public JComboBox idTypeComboBox;
    public JTextField idTextField;
    private JButton modifyBtn;
    private JButton cancelBtn;
    public JCheckBox birthdayCheckBox;
}