提交 | 用户 | 时间
|
ce910c
|
1 |
package com.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.IOException; |
|
11 |
|
|
12 |
import javax.swing.JButton; |
|
13 |
import javax.swing.JCheckBox; |
|
14 |
import javax.swing.JComboBox; |
|
15 |
import javax.swing.JDialog; |
|
16 |
import javax.swing.JLabel; |
|
17 |
import javax.swing.JOptionPane; |
|
18 |
import javax.swing.JPanel; |
|
19 |
import javax.swing.JTextField; |
|
20 |
import javax.swing.event.ChangeEvent; |
|
21 |
import javax.swing.event.ChangeListener; |
|
22 |
|
|
23 |
import com.netsdk.demo.module.TargetRecognitionModule; |
|
24 |
import com.sun.jna.Memory; |
|
25 |
|
|
26 |
import com.netsdk.common.*; |
|
27 |
import com.netsdk.lib.ToolKits; |
|
28 |
|
|
29 |
public class AddPersonDialog extends JDialog{ |
|
30 |
|
|
31 |
/** |
|
32 |
* |
|
33 |
*/ |
|
34 |
private static final long serialVersionUID = 1L; |
|
35 |
|
|
36 |
private Memory memory = null; |
|
37 |
private String groupId = ""; |
|
38 |
private String groupName = ""; |
|
39 |
|
|
40 |
private WindowCloseListener listener; |
|
41 |
public void addWindowCloseListener(WindowCloseListener listener) { |
|
42 |
this.listener = listener; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* @param groupId 人脸库ID |
|
47 |
* @param groupName 人脸库名称 |
|
48 |
*/ |
|
49 |
public AddPersonDialog(String groupId, String groupName){ |
|
50 |
setTitle(Res.string().getAddPerson()); |
|
51 |
setLayout(new BorderLayout()); |
|
52 |
setModal(true); |
|
53 |
pack(); |
|
54 |
setSize(520, 400); |
|
55 |
setResizable(false); |
|
56 |
setLocationRelativeTo(null); |
|
57 |
setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 |
|
58 |
|
|
59 |
this.groupId = groupId; |
|
60 |
this.groupName = groupName; |
|
61 |
|
|
62 |
FaceServerAddPanel faceServerAddPanel = new FaceServerAddPanel(); |
|
63 |
add(faceServerAddPanel, BorderLayout.CENTER); |
|
64 |
addWindowListener(new WindowAdapter() { |
|
65 |
public void windowClosing(WindowEvent e){ |
|
66 |
dispose(); |
|
67 |
} |
|
68 |
}); |
|
69 |
} |
|
70 |
|
|
71 |
public class FaceServerAddPanel extends JPanel{ |
|
72 |
/** |
|
73 |
* |
|
74 |
*/ |
|
75 |
private static final long serialVersionUID = 1L; |
|
76 |
|
|
77 |
public FaceServerAddPanel() { |
|
78 |
BorderEx.set(this, "", 4); |
|
79 |
setLayout(new BorderLayout()); |
|
80 |
|
|
81 |
JPanel imagePanel = new JPanel(); |
|
82 |
JPanel personInfoPanel = new JPanel(); |
|
83 |
|
|
84 |
Dimension dimension = this.getPreferredSize(); |
|
85 |
dimension.height = 400; |
|
86 |
dimension.width = 250; |
|
87 |
personInfoPanel.setPreferredSize(dimension); |
|
88 |
|
|
89 |
add(imagePanel, BorderLayout.CENTER); |
|
90 |
add(personInfoPanel, BorderLayout.WEST); |
|
91 |
|
|
92 |
/////////// 添加的人脸图片面板 ////////////////// |
|
93 |
imagePanel.setLayout(new BorderLayout()); |
|
94 |
addImagePanel = new PaintPanel(); // 添加的人员信息图片显示 |
|
95 |
selectImageBtn = new JButton(Res.string().getSelectPicture()); |
|
96 |
imagePanel.add(addImagePanel, BorderLayout.CENTER); |
|
97 |
imagePanel.add(selectImageBtn, BorderLayout.SOUTH); |
|
98 |
|
|
99 |
////////// 添加的人脸信息面板 ///////////////// |
|
100 |
personInfoPanel.setLayout(new FlowLayout()); |
|
101 |
JLabel goroupIdLabel = new JLabel(Res.string().getFaceGroupId(), JLabel.CENTER); |
|
102 |
JLabel goroupNameLabel = new JLabel(Res.string().getFaceGroupName(), JLabel.CENTER); |
|
103 |
JLabel nameLabel = new JLabel(Res.string().getName(), JLabel.CENTER); |
|
104 |
JLabel sexLabel = new JLabel(Res.string().getSex(), JLabel.CENTER); |
|
105 |
JLabel birthdayLabel = new JLabel(Res.string().getBirthday(), JLabel.CENTER); |
|
106 |
JLabel idTypeLabel = new JLabel(Res.string().getIdType(), JLabel.CENTER); |
|
107 |
JLabel idLabel = new JLabel(Res.string().getIdNo(), JLabel.CENTER); |
|
108 |
|
|
109 |
Dimension dimension2 = new Dimension(); |
|
110 |
dimension2.width = 80; |
|
111 |
dimension2.height = 20; |
|
112 |
goroupIdLabel.setPreferredSize(dimension2); |
|
113 |
goroupNameLabel.setPreferredSize(dimension2); |
|
114 |
nameLabel.setPreferredSize(dimension2); |
|
115 |
sexLabel.setPreferredSize(dimension2); |
|
116 |
idTypeLabel.setPreferredSize(dimension2); |
|
117 |
idLabel.setPreferredSize(dimension2); |
|
118 |
birthdayLabel.setPreferredSize(dimension2); |
|
119 |
|
|
120 |
goroupIdTextField = new JTextField(); |
|
121 |
goroupNameTextField = new JTextField(); |
|
122 |
nameTextField = new JTextField(); |
|
123 |
sexComboBox = new JComboBox(Res.string().getSexStrings()); |
|
124 |
birthdayBtn = new DateChooserJButtonEx(); |
|
125 |
idTypeComboBox = new JComboBox(Res.string().getIdStrings()); |
|
126 |
idTextField = new JTextField(); |
|
127 |
birthdayCheckBox = new JCheckBox(); |
|
128 |
|
|
129 |
addBtn = new JButton(Res.string().getAdd()); |
|
130 |
cancelBtn = new JButton(Res.string().getCancel()); |
|
131 |
|
|
132 |
birthdayBtn.setStartYear(1900); |
|
133 |
|
|
134 |
Dimension dimension3 = new Dimension(); |
|
135 |
dimension3.width = 150; |
|
136 |
dimension3.height = 20; |
|
137 |
|
|
138 |
sexComboBox.setPreferredSize(dimension3); |
|
139 |
idTypeComboBox.setPreferredSize(dimension3); |
|
140 |
goroupIdTextField.setPreferredSize(dimension3); |
|
141 |
goroupNameTextField.setPreferredSize(dimension3); |
|
142 |
nameTextField.setPreferredSize(dimension3); |
|
143 |
idTextField.setPreferredSize(dimension3); |
|
144 |
birthdayBtn.setPreferredSize(new Dimension(130, 20)); |
|
145 |
birthdayCheckBox.setPreferredSize(new Dimension(20, 20)); |
|
146 |
addBtn.setPreferredSize(new Dimension(120, 20)); |
|
147 |
cancelBtn.setPreferredSize(new Dimension(120, 20)); |
|
148 |
|
|
149 |
goroupIdTextField.setEditable(false); |
|
150 |
goroupNameTextField.setEditable(false); |
|
151 |
birthdayCheckBox.setSelected(true); |
|
152 |
|
|
153 |
goroupIdTextField.setText(groupId); |
|
154 |
goroupNameTextField.setText(groupName); |
|
155 |
|
|
156 |
personInfoPanel.add(goroupIdLabel); |
|
157 |
personInfoPanel.add(goroupIdTextField); |
|
158 |
personInfoPanel.add(goroupNameLabel); |
|
159 |
personInfoPanel.add(goroupNameTextField); |
|
160 |
personInfoPanel.add(nameLabel); |
|
161 |
personInfoPanel.add(nameTextField); |
|
162 |
personInfoPanel.add(sexLabel); |
|
163 |
personInfoPanel.add(sexComboBox); |
|
164 |
personInfoPanel.add(idTypeLabel); |
|
165 |
personInfoPanel.add(idTypeComboBox); |
|
166 |
personInfoPanel.add(idLabel); |
|
167 |
personInfoPanel.add(idTextField); |
|
168 |
personInfoPanel.add(birthdayLabel); |
|
169 |
personInfoPanel.add(birthdayBtn); |
|
170 |
personInfoPanel.add(birthdayCheckBox); |
|
171 |
personInfoPanel.add(addBtn); |
|
172 |
personInfoPanel.add(cancelBtn); |
|
173 |
|
|
174 |
birthdayCheckBox.addChangeListener(new ChangeListener() { |
|
175 |
@Override |
|
176 |
public void stateChanged(ChangeEvent arg0) { |
|
177 |
if(birthdayCheckBox.isSelected()) { |
|
178 |
birthdayBtn.setEnabled(true); |
|
179 |
} else { |
|
180 |
birthdayBtn.setEnabled(false); |
|
181 |
} |
|
182 |
} |
|
183 |
}); |
|
184 |
|
|
185 |
// 选择图片,获取图片的信息 |
|
186 |
selectImageBtn.addActionListener(new ActionListener() { |
|
187 |
@Override |
|
188 |
public void actionPerformed(ActionEvent arg0) { |
|
189 |
String picPath = ""; |
|
190 |
|
|
191 |
// 选择图片,获取图片路径,并在界面显示 |
|
192 |
picPath = ToolKits.openPictureFile(addImagePanel); |
|
193 |
|
|
194 |
if(!picPath.equals("")) { |
|
195 |
try { |
|
196 |
memory = ToolKits.readPictureFile(picPath); |
|
197 |
} catch (IOException e) { |
|
198 |
// TODO Auto-generated catch block |
|
199 |
e.printStackTrace(); |
|
200 |
} |
|
201 |
} |
|
202 |
|
|
203 |
} |
|
204 |
}); |
|
205 |
|
|
206 |
// 添加人员信息 |
|
207 |
addBtn.addActionListener(new ActionListener() { |
|
208 |
@Override |
|
209 |
public void actionPerformed(ActionEvent arg0) { |
|
210 |
boolean bRet = TargetRecognitionModule.addPerson(goroupIdTextField.getText(), |
|
211 |
memory, |
|
212 |
nameTextField.getText(), |
|
213 |
sexComboBox.getSelectedIndex(), |
|
214 |
birthdayCheckBox.isSelected(), birthdayBtn.getText().toString(), |
|
215 |
idTypeComboBox.getSelectedIndex(), idTextField.getText()); |
|
216 |
|
|
217 |
if(bRet) { |
|
218 |
JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); |
|
219 |
} else { |
|
220 |
JOptionPane.showMessageDialog(null, Res.string().getFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
221 |
} |
|
222 |
|
|
223 |
dispose(); |
|
224 |
|
|
225 |
listener.windowClosing(); |
|
226 |
} |
|
227 |
}); |
|
228 |
|
|
229 |
// 取消,关闭 |
|
230 |
cancelBtn.addActionListener(new ActionListener() { |
|
231 |
@Override |
|
232 |
public void actionPerformed(ActionEvent arg0) { |
|
233 |
dispose(); |
|
234 |
} |
|
235 |
}); |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
|
|
240 |
// 添加人员信息窗口的组件 |
|
241 |
private PaintPanel addImagePanel; |
|
242 |
private JButton selectImageBtn; |
|
243 |
|
|
244 |
private JTextField goroupIdTextField; |
|
245 |
private JTextField goroupNameTextField; |
|
246 |
private JTextField nameTextField; |
|
247 |
private JComboBox sexComboBox; |
|
248 |
private DateChooserJButtonEx birthdayBtn; |
|
249 |
private JComboBox idTypeComboBox; |
|
250 |
private JTextField idTextField; |
|
251 |
private JButton addBtn; |
|
252 |
private JButton cancelBtn; |
|
253 |
private JCheckBox birthdayCheckBox; |
|
254 |
} |