潘志宝
5 天以前 6d75723f3e3bd43895db2470bc5fabb2314dbe8b
提交 | 用户 | 时间
149dd0 1 package com.iailab.netsdk.demo.frame.TargetRecognition;
H 2
3 import java.awt.BorderLayout;
4 import java.awt.Dimension;
5 import java.awt.FlowLayout;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.awt.event.WindowAdapter;
9 import java.awt.event.WindowEvent;
10 import java.io.File;
11 import java.io.IOException;
12 import java.io.UnsupportedEncodingException;
13
14 import javax.swing.JButton;
15 import javax.swing.JCheckBox;
16 import javax.swing.JComboBox;
17 import javax.swing.JDialog;
18 import javax.swing.JLabel;
19 import javax.swing.JOptionPane;
20 import javax.swing.JPanel;
21 import javax.swing.JTextField;
22 import javax.swing.event.ChangeEvent;
23 import javax.swing.event.ChangeListener;
24
25 import com.iailab.netsdk.demo.module.TargetRecognitionModule;
26 import com.sun.jna.Memory;
27
28 import com.iailab.netsdk.common.*;
29 import com.iailab.netsdk.lib.NetSDKLib.*;
30 import com.iailab.netsdk.lib.ToolKits;
31
32 public class ModifyPersonDialog extends JDialog{
33     /**
34      * 
35      */
36     private static final long serialVersionUID = 1L;
37     
38     private String groupId = ""; 
39     private String groupName = "";
40     private String uid = "";
41     private String pszFileDst = "";
42     private Memory memory = null;
43     private CANDIDATE_INFOEX stuCandidate = null;
44     
45     private WindowCloseListener listener;
46     public void addWindowCloseListener(WindowCloseListener listener) {
47         this.listener = listener;
48     }
49     
50     /**
51      * @param groupId 人脸库ID
52      * @param groupName  人脸库名称
53      * @param uid  人员标识符
54      * @param pszFileDst  下载到本地的图片路径
55      * @param memory  图片数据
56      * @param stuCandidate  人员信息
57      */
58     public ModifyPersonDialog(String groupId, 
59                               String groupName, 
60                               String uid, 
61                               String pszFileDst, 
62                               Memory memory, 
63                               CANDIDATE_INFOEX stuCandidate){
64         
65         setTitle(Res.string().getModifyPerson());
66         setLayout(new BorderLayout());
67         setModal(true); 
68         pack();
69         setSize(520, 400);
70         setResizable(false);
71         setLocationRelativeTo(null);
72         setDefaultCloseOperation(DISPOSE_ON_CLOSE);   // 释放窗体
73         
74         this.groupId = groupId;
75         this.groupName = groupName;
76         this.uid = uid;
77         this.pszFileDst = pszFileDst;
78         this.memory = memory;
79         this.stuCandidate = stuCandidate;
80         
81         FaceServerAddPanel faceServerAddPanel = new FaceServerAddPanel();
82         add(faceServerAddPanel, BorderLayout.CENTER);
83         
84         showPersonInfo();
85         
86         addWindowListener(new WindowAdapter() {
87             public void windowClosing(WindowEvent e){
88                 dispose();
89             }
90         });
91     }
92     public class FaceServerAddPanel extends JPanel{
93         /**
94          * 
95          */
96         private static final long serialVersionUID = 1L;
97
98         public FaceServerAddPanel() {
99             BorderEx.set(this, "", 4);
100             setLayout(new BorderLayout());
101             
102             JPanel imagePanel = new JPanel();
103             JPanel personInfoPanel = new JPanel();
104             
105             Dimension dimension = this.getPreferredSize();
106             dimension.height = 400;
107             dimension.width = 250;
108             personInfoPanel.setPreferredSize(dimension);
109             
110             add(imagePanel, BorderLayout.CENTER);
111             add(personInfoPanel, BorderLayout.WEST);
112             
113             /////////// 添加的人脸图片面板 //////////////////
114             imagePanel.setLayout(new BorderLayout());
115             addImagePanel = new PaintPanel();   // 添加的人员信息图片显示
116             selectImageBtn = new JButton(Res.string().getSelectPicture());
117             imagePanel.add(addImagePanel, BorderLayout.CENTER);
118             imagePanel.add(selectImageBtn, BorderLayout.SOUTH);
119             
120             ////////// 添加的人脸信息面板 /////////////////
121             personInfoPanel.setLayout(new FlowLayout());
122             JLabel goroupIdLabel = new JLabel(Res.string().getFaceGroupId(), JLabel.CENTER);
123             JLabel goroupNameLabel = new JLabel(Res.string().getFaceGroupName(), JLabel.CENTER);
124             JLabel uidLabel = new JLabel(Res.string().getUid(), JLabel.CENTER);
125             JLabel nameLabel = new JLabel(Res.string().getName(), JLabel.CENTER);
126             JLabel sexLabel = new JLabel(Res.string().getSex(), JLabel.CENTER);
127             JLabel birthdayLabel = new JLabel(Res.string().getBirthday(), JLabel.CENTER);
128             JLabel idTypeLabel = new JLabel(Res.string().getIdType(), JLabel.CENTER);
129             JLabel idLabel = new JLabel(Res.string().getIdNo(), JLabel.CENTER);
130             
131             Dimension dimension2 = new Dimension();
132             dimension2.width = 80;
133             dimension2.height = 20;
134             uidLabel.setPreferredSize(dimension2);
135             goroupIdLabel.setPreferredSize(dimension2);
136             goroupNameLabel.setPreferredSize(dimension2);
137             nameLabel.setPreferredSize(dimension2);
138             sexLabel.setPreferredSize(dimension2);
139             birthdayLabel.setPreferredSize(dimension2);
140             idTypeLabel.setPreferredSize(dimension2);
141             idLabel.setPreferredSize(dimension2);
142             
143             goroupIdTextField = new JTextField();
144             goroupNameTextField = new JTextField();
145             uidTextField = new JTextField();
146             nameTextField = new JTextField();
147             sexComboBox = new JComboBox(Res.string().getSexStrings());
148             birthdayBtn = new DateChooserJButtonEx(""); 
149             idTypeComboBox = new JComboBox(Res.string().getIdStrings());
150             idTextField = new JTextField();
151             birthdayCheckBox = new JCheckBox();
152             
153             modifyBtn = new JButton(Res.string().getModify());
154             cancelBtn = new JButton(Res.string().getCancel());
155             
156             birthdayBtn.setStartYear(1900);
157             
158             Dimension dimension3 = new Dimension();
159             dimension3.width = 150;
160             dimension3.height = 20;
161             
162             sexComboBox.setPreferredSize(dimension3);    
163             idTypeComboBox.setPreferredSize(dimension3);
164             goroupIdTextField.setPreferredSize(dimension3);
165             goroupNameTextField.setPreferredSize(dimension3);
166             uidTextField.setPreferredSize(dimension3);
167             nameTextField.setPreferredSize(dimension3);
168             idTextField.setPreferredSize(dimension3);
169             birthdayBtn.setPreferredSize(new Dimension(130, 20));
170             birthdayCheckBox.setPreferredSize(new Dimension(20, 20));
171             modifyBtn.setPreferredSize(new Dimension(120, 20));
172             cancelBtn.setPreferredSize(new Dimension(120, 20));
173
174             goroupIdTextField.setEditable(false);
175             goroupNameTextField.setEditable(false);
176             uidTextField.setEditable(false);
177             birthdayCheckBox.setSelected(true);
178             
179             goroupIdTextField.setText(groupId);
180             goroupNameTextField.setText(groupName);
181             uidTextField.setText(uid);
182             
183             personInfoPanel.add(goroupIdLabel);
184             personInfoPanel.add(goroupIdTextField);
185             personInfoPanel.add(goroupNameLabel);
186             personInfoPanel.add(goroupNameTextField);
187             personInfoPanel.add(uidLabel);
188             personInfoPanel.add(uidTextField);
189             personInfoPanel.add(nameLabel);
190             personInfoPanel.add(nameTextField);
191             personInfoPanel.add(sexLabel);
192             personInfoPanel.add(sexComboBox);
193             personInfoPanel.add(idTypeLabel);
194             personInfoPanel.add(idTypeComboBox);
195             personInfoPanel.add(idLabel);
196             personInfoPanel.add(idTextField);
197             personInfoPanel.add(birthdayLabel);
198             personInfoPanel.add(birthdayBtn);
199             personInfoPanel.add(birthdayCheckBox);
200             personInfoPanel.add(modifyBtn);
201             personInfoPanel.add(cancelBtn);
202             
203             birthdayCheckBox.addChangeListener(new ChangeListener() {        
204                 @Override
205                 public void stateChanged(ChangeEvent arg0) {
206                     if(birthdayCheckBox.isSelected()) {
207                         birthdayBtn.setEnabled(true);
208                     } else {
209                         birthdayBtn.setEnabled(false);
210                     }
211                 }
212             });
213             
214             // 选择图片,获取图片的信息
215             selectImageBtn.addActionListener(new ActionListener() {                
216                 @Override
217                 public void actionPerformed(ActionEvent arg0) {
218                     String picPath = "";
219                     
220                     // 选择图片,获取图片路径,并在界面显示
221                     picPath = ToolKits.openPictureFile(addImagePanel);
222                             
223                     if(!picPath.equals("")) {
224                         memory = null;
225                         try {
226                             memory = ToolKits.readPictureFile(picPath);
227                         } catch (IOException e) {
228                             // TODO Auto-generated catch block
229                             e.printStackTrace();
230                         }
231                     }                
232                 }
233             });
234             
235             // 修改人员信息
236             modifyBtn.addActionListener(new ActionListener() {            
237                 @Override
238                 public void actionPerformed(ActionEvent arg0) {
239                     boolean bRet = TargetRecognitionModule.modifyPerson(groupId, uid,
240                                                                       memory, 
241                                                                       nameTextField.getText(), 
242                                                                       sexComboBox.getSelectedIndex(), 
243                                                                       birthdayCheckBox.isSelected(), birthdayBtn.getText().toString(), 
244                                                                       idTypeComboBox.getSelectedIndex(), idTextField.getText());                                
245
246                     if(bRet) {
247                         JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE);
248                     } else {
249                         JOptionPane.showMessageDialog(null, Res.string().getFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
250                     }
251     
252                     dispose();
253                     
254                     listener.windowClosing();                                
255                 }
256             });
257             
258             // 取消,关闭
259             cancelBtn.addActionListener(new ActionListener() {            
260                 @Override
261                 public void actionPerformed(ActionEvent arg0) {
262                     dispose();    
263                 }
264             });
265         }         
266     }
267     
268     private void showPersonInfo() {
269         File file = null;
270         if(!pszFileDst.equals("")) {
271             file = ToolKits.openPictureFile(pszFileDst, addImagePanel);        
272         }
273         
274         if(file != null) {
275             file.delete();
276         }
277         
278         try {
279             nameTextField.setText(new String(stuCandidate.stPersonInfo.szPersonName, "GBK").trim());
280         } catch (UnsupportedEncodingException e) {
281             e.printStackTrace();
282         }
283         
284         sexComboBox.setSelectedIndex(stuCandidate.stPersonInfo.bySex & 0xff);
285         
286         idTypeComboBox.setSelectedIndex(stuCandidate.stPersonInfo.byIDType & 0xff);
287         
288         idTextField.setText(new String(stuCandidate.stPersonInfo.szID).trim());
289         
290         if(stuCandidate.stPersonInfo == null) {
291             birthdayCheckBox.setSelected(false);
292             birthdayBtn.setText(birthdayBtn.getDate().toString());
293         } else {
294             if(String.valueOf((int)stuCandidate.stPersonInfo.wYear).equals("0000") 
295                 || String.valueOf((int)stuCandidate.stPersonInfo.wYear).equals("0") 
296                 || String.valueOf( stuCandidate.stPersonInfo.byMonth & 0xff).equals("0") 
297                 || String.valueOf( stuCandidate.stPersonInfo.byMonth & 0xff).equals("00") 
298                 || String.valueOf(stuCandidate.stPersonInfo.byDay & 0xff).equals("0") 
299                 || String.valueOf(stuCandidate.stPersonInfo.byDay & 0xff).equals("00")) {
300                 birthdayCheckBox.setSelected(false);
301                 birthdayBtn.setText(birthdayBtn.getDate().toString());
302             } else {
303                 birthdayCheckBox.setSelected(true);
304                 birthdayBtn.setText(String.valueOf((int)stuCandidate.stPersonInfo.wYear) + "-" + 
305                                                       String.valueOf( stuCandidate.stPersonInfo.byMonth & 0xff) + "-" + 
306                                                       String.valueOf(stuCandidate.stPersonInfo.byDay & 0xff));
307             }
308         }
309     }
310     
311     // 添加人员信息窗口的组件
312     public PaintPanel addImagePanel;
313     private JButton selectImageBtn;
314     
315     private JTextField goroupIdTextField;
316     private JTextField goroupNameTextField;
317     private JTextField uidTextField;
318     public JTextField nameTextField;
319     public JComboBox sexComboBox;
320     public DateChooserJButtonEx birthdayBtn; 
321     public JComboBox idTypeComboBox;
322     public JTextField idTextField;
323     private JButton modifyBtn;
324     private JButton cancelBtn;
325     public JCheckBox birthdayCheckBox;
326 }