提交 | 用户 | 时间
|
149dd0
|
1 |
package com.iailab.netsdk.demo.frame.vto; |
H |
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.FlowLayout; |
|
5 |
import java.awt.event.*; |
|
6 |
|
|
7 |
import javax.swing.JButton; |
|
8 |
import javax.swing.JDialog; |
|
9 |
import javax.swing.JLabel; |
|
10 |
import javax.swing.JOptionPane; |
|
11 |
import javax.swing.JPanel; |
|
12 |
import javax.swing.JPasswordField; |
|
13 |
import javax.swing.JTextField; |
|
14 |
import javax.swing.UIManager; |
|
15 |
import javax.swing.UnsupportedLookAndFeelException; |
|
16 |
import javax.swing.border.EmptyBorder; |
|
17 |
import javax.swing.border.TitledBorder; |
|
18 |
|
|
19 |
import com.sun.jna.Memory; |
|
20 |
import com.sun.jna.Pointer; |
|
21 |
|
|
22 |
import com.iailab.netsdk.common.Base64; |
|
23 |
import com.iailab.netsdk.common.Res; |
|
24 |
import com.iailab.netsdk.demo.module.LoginModule; |
|
25 |
import com.iailab.netsdk.lib.NetSDKLib; |
|
26 |
import com.iailab.netsdk.lib.ToolKits; |
|
27 |
|
|
28 |
public class CollectionFingerPrint extends JDialog { |
|
29 |
|
|
30 |
private final JPanel contentPanel = new JPanel(); |
|
31 |
private JTextField ipTextField; |
|
32 |
private JTextField portTextField; |
|
33 |
private JTextField usernameTextField; |
|
34 |
private JPasswordField passwordField; |
|
35 |
private JLabel collectionResult; |
|
36 |
|
|
37 |
private JButton btnLogin; |
|
38 |
private JButton btnLogout; |
|
39 |
private JButton btnCollection; |
|
40 |
|
|
41 |
private byte[] packageData; |
|
42 |
private int packageLen; |
|
43 |
private boolean bcollectionResult = false; |
|
44 |
private boolean isListen; |
|
45 |
|
|
46 |
public byte[] getPackageData() { |
|
47 |
return packageData; |
|
48 |
} |
|
49 |
|
|
50 |
public void setPackageData(byte[] packageData) { |
|
51 |
this.packageData = packageData; |
|
52 |
|
|
53 |
} |
|
54 |
|
|
55 |
public void setLabelResult(byte[] packageData) { |
|
56 |
collectionResult.setText(Base64.getEncoder().encodeToString(packageData)); |
|
57 |
} |
|
58 |
|
|
59 |
public int getPackageLen() { |
|
60 |
return packageLen; |
|
61 |
} |
|
62 |
|
|
63 |
public void setPackageLen(int packageLen) { |
|
64 |
this.packageLen = packageLen; |
|
65 |
} |
|
66 |
|
|
67 |
public boolean isCollectionResult() { |
|
68 |
return bcollectionResult; |
|
69 |
} |
|
70 |
|
|
71 |
public void setCollectionResult(boolean bcollectionResult) { |
|
72 |
this.bcollectionResult = bcollectionResult; |
|
73 |
//显示结果 |
|
74 |
collectionResult.setText(this.bcollectionResult ? "success" : "failed"); |
|
75 |
} |
|
76 |
|
|
77 |
public void stopListen() { |
|
78 |
//获取到信息,停止监听 |
|
79 |
if (loginHandler != null && loginHandler.longValue() != 0) { |
|
80 |
stopListen(loginHandler); |
|
81 |
} |
|
82 |
//获取按钮使能 |
|
83 |
btnCollection.setEnabled(true); |
|
84 |
//设置监听状态 |
|
85 |
isListen = false; |
|
86 |
} |
|
87 |
|
|
88 |
private NetSDKLib.LLong loginHandler; |
|
89 |
private NetSDKLib.NET_DEVICEINFO_Ex deviceinfoEx = new NetSDKLib.NET_DEVICEINFO_Ex(); |
|
90 |
|
|
91 |
/** |
|
92 |
* Launch the application. |
|
93 |
*/ |
|
94 |
public static void main(String[] args) { |
|
95 |
try { |
|
96 |
CollectionFingerPrint dialog = new CollectionFingerPrint(); |
|
97 |
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
|
98 |
dialog.setVisible(true); |
|
99 |
} catch (Exception e) { |
|
100 |
e.printStackTrace(); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Create the dialog. |
|
106 |
*/ |
|
107 |
public CollectionFingerPrint() { |
|
108 |
setBounds(100, 100, 304, 397); |
|
109 |
setTitle(Res.string().getVTOOperateCollectionFingerPrintTitle()); |
|
110 |
setDefaultCloseOperation(DISPOSE_ON_CLOSE); |
|
111 |
try { |
|
112 |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
|
113 |
} catch (ClassNotFoundException e) { |
|
114 |
e.printStackTrace(); |
|
115 |
} catch (InstantiationException e) { |
|
116 |
e.printStackTrace(); |
|
117 |
} catch (IllegalAccessException e) { |
|
118 |
e.printStackTrace(); |
|
119 |
} catch (UnsupportedLookAndFeelException e) { |
|
120 |
e.printStackTrace(); |
|
121 |
} |
|
122 |
getContentPane().setLayout(new BorderLayout()); |
|
123 |
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); |
|
124 |
getContentPane().add(contentPanel, BorderLayout.CENTER); |
|
125 |
contentPanel.setLayout(null); |
|
126 |
{ |
|
127 |
JPanel panel = new JPanel(); |
|
128 |
panel.setBorder(new TitledBorder(null, Res.string().getLogin(), TitledBorder.LEADING, |
|
129 |
TitledBorder.TOP, null, null)); |
|
130 |
panel.setBounds(10, 10, 268, 167); |
|
131 |
contentPanel.add(panel); |
|
132 |
panel.setLayout(null); |
|
133 |
{ |
|
134 |
JLabel lblNewLabel = new JLabel(Res.string().getIp()); |
|
135 |
lblNewLabel.setBounds(10, 23, 66, 15); |
|
136 |
panel.add(lblNewLabel); |
|
137 |
} |
|
138 |
{ |
|
139 |
ipTextField = new JTextField(); |
|
140 |
ipTextField.setText("172.23.32.61"); |
|
141 |
ipTextField.setBounds(103, 20, 155, 21); |
|
142 |
panel.add(ipTextField); |
|
143 |
ipTextField.setColumns(10); |
|
144 |
} |
|
145 |
{ |
|
146 |
JLabel lblPort = new JLabel(Res.string().getPort()); |
|
147 |
lblPort.setBounds(10, 48, 83, 15); |
|
148 |
panel.add(lblPort); |
|
149 |
} |
|
150 |
{ |
|
151 |
portTextField = new JTextField(); |
|
152 |
portTextField.setText("37777"); |
|
153 |
portTextField.setColumns(10); |
|
154 |
portTextField.setBounds(103, 45, 155, 21); |
|
155 |
panel.add(portTextField); |
|
156 |
} |
|
157 |
{ |
|
158 |
JLabel lblName = new JLabel(Res.string().getUserName()); |
|
159 |
lblName.setBounds(10, 73, 83, 15); |
|
160 |
panel.add(lblName); |
|
161 |
} |
|
162 |
{ |
|
163 |
usernameTextField = new JTextField(); |
|
164 |
usernameTextField.setText("admin"); |
|
165 |
usernameTextField.setColumns(10); |
|
166 |
usernameTextField.setBounds(103, 70, 155, 21); |
|
167 |
panel.add(usernameTextField); |
|
168 |
} |
|
169 |
{ |
|
170 |
JLabel lblPassword = new JLabel(Res.string().getPassword()); |
|
171 |
lblPassword.setBounds(10, 98, 90, 15); |
|
172 |
panel.add(lblPassword); |
|
173 |
} |
|
174 |
|
|
175 |
passwordField = new JPasswordField(); |
|
176 |
passwordField.setBounds(103, 95, 155, 18); |
|
177 |
passwordField.setText("admin123"); |
|
178 |
panel.add(passwordField); |
|
179 |
{ |
|
180 |
btnLogin = new JButton(Res.string().getLogin()); |
|
181 |
btnLogin.setBounds(7, 134, 111, 23); |
|
182 |
panel.add(btnLogin); |
|
183 |
btnLogin.addMouseListener(new MouseAdapter() { |
|
184 |
@Override |
|
185 |
public void mouseClicked(MouseEvent e) { |
|
186 |
if (login()) { |
|
187 |
btnCollection.setEnabled(true); |
|
188 |
} |
|
189 |
} |
|
190 |
}); |
|
191 |
} |
|
192 |
{ |
|
193 |
btnLogout = new JButton(Res.string().getLogout()); |
|
194 |
btnLogout.setBounds(153, 134, 105, 23); |
|
195 |
panel.add(btnLogout); |
|
196 |
btnLogout.setEnabled(false); |
|
197 |
btnLogout.addMouseListener(new MouseAdapter() { |
|
198 |
@Override |
|
199 |
public void mouseClicked(MouseEvent e) { |
|
200 |
logout(); |
|
201 |
} |
|
202 |
}); |
|
203 |
} |
|
204 |
} |
|
205 |
{ |
|
206 |
JPanel panel = new JPanel(); |
|
207 |
panel.setBorder(new TitledBorder(null, Res.string().getOperate(), TitledBorder.LEADING, TitledBorder.TOP, |
|
208 |
null, null)); |
|
209 |
panel.setBounds(10, 187, 268, 129); |
|
210 |
contentPanel.add(panel); |
|
211 |
panel.setLayout(null); |
|
212 |
{ |
|
213 |
btnCollection = new JButton(Res.string().getStartCollection()); |
|
214 |
btnCollection.setBounds(10, 26, 227, 41); |
|
215 |
panel.add(btnCollection); |
|
216 |
|
|
217 |
collectionResult = new JLabel(Res.string().getCollectionResult()); |
|
218 |
collectionResult.setBounds(10, 77, 227, 26); |
|
219 |
panel.add(collectionResult); |
|
220 |
btnCollection.setEnabled(false); |
|
221 |
final CollectionFingerPrint print = this; |
|
222 |
btnCollection.addActionListener(new ActionListener() { |
|
223 |
@Override |
|
224 |
public void actionPerformed(ActionEvent e) { |
|
225 |
isListen = startListen(loginHandler, VTOMessageCallBack.getINSTANCE(null, print)); |
|
226 |
if (isListen) { |
|
227 |
//下发采集信息指令 |
|
228 |
if (!collectionFinger()) { |
|
229 |
stopListen(loginHandler); |
|
230 |
} else { |
|
231 |
// 使其失效 |
|
232 |
btnCollection.setEnabled(false); |
|
233 |
} |
|
234 |
new Thread(new Runnable() { |
|
235 |
@Override |
|
236 |
public void run() { |
|
237 |
try { |
|
238 |
Thread.sleep(20000); |
|
239 |
//等待二十秒,如果没有获取到信息,则停止获取 |
|
240 |
if (isListen) { |
|
241 |
stopListen(); |
|
242 |
} |
|
243 |
|
|
244 |
} catch (InterruptedException interruptedException) { |
|
245 |
interruptedException.printStackTrace(); |
|
246 |
} |
|
247 |
} |
|
248 |
}).start(); |
|
249 |
} |
|
250 |
|
|
251 |
} |
|
252 |
}); |
|
253 |
addWindowListener(new WindowAdapter() { |
|
254 |
|
|
255 |
@Override |
|
256 |
public void windowClosed(WindowEvent e) { |
|
257 |
super.windowClosed(e); |
|
258 |
//已经登录 |
|
259 |
if (loginHandler != null && loginHandler.longValue() != 0) { |
|
260 |
if (isListen) { |
|
261 |
//停止监听 |
|
262 |
stopListen(loginHandler); |
|
263 |
} |
|
264 |
//登出 |
|
265 |
logout(); |
|
266 |
} |
|
267 |
//按钮复位 |
|
268 |
btnLogin.setEnabled(true); |
|
269 |
btnLogout.setEnabled(false); |
|
270 |
btnCollection.setEnabled(false); |
|
271 |
//清除信息数据 |
|
272 |
bcollectionResult=false; |
|
273 |
packageData=null; |
|
274 |
//清除label显示 |
|
275 |
collectionResult.setText(Res.string().getCollectionResult()); |
|
276 |
} |
|
277 |
}); |
|
278 |
} |
|
279 |
|
|
280 |
} |
|
281 |
{ |
|
282 |
JPanel buttonPane = new JPanel(); |
|
283 |
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
|
284 |
getContentPane().add(buttonPane, BorderLayout.SOUTH); |
|
285 |
{ |
|
286 |
JButton okButton = new JButton("OK"); |
|
287 |
okButton.setActionCommand("OK"); |
|
288 |
buttonPane.add(okButton); |
|
289 |
getRootPane().setDefaultButton(okButton); |
|
290 |
okButton.addActionListener(new ActionListener() { |
|
291 |
@Override |
|
292 |
public void actionPerformed(ActionEvent e) { |
|
293 |
setVisible(false); |
|
294 |
} |
|
295 |
}); |
|
296 |
|
|
297 |
} |
|
298 |
} |
|
299 |
} |
|
300 |
|
|
301 |
/** |
|
302 |
* 登录 |
|
303 |
*/ |
|
304 |
public boolean login() { |
|
305 |
if (login(ipTextField.getText(), Integer.parseInt(portTextField.getText()), usernameTextField.getText(), |
|
306 |
new String(passwordField.getPassword()))) { |
|
307 |
btnLogin.setEnabled(false); |
|
308 |
btnLogout.setEnabled(true); |
|
309 |
btnCollection.setEnabled(true); |
|
310 |
} else { |
|
311 |
JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), |
|
312 |
Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
313 |
return false; |
|
314 |
} |
|
315 |
return true; |
|
316 |
} |
|
317 |
|
|
318 |
/** |
|
319 |
* \if ENGLISH_LANG Login Device \else 登录设备 \endif |
|
320 |
*/ |
|
321 |
public boolean login(String m_strIp, int m_nPort, String m_strUser, String m_strPassword) { |
|
322 |
// IntByReference nError = new IntByReference(0); |
|
323 |
// 入参 |
|
324 |
NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY pstInParam = new NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY(); |
|
325 |
pstInParam.nPort = m_nPort; |
|
326 |
pstInParam.szIP = m_strIp.getBytes(); |
|
327 |
pstInParam.szPassword = m_strPassword.getBytes(); |
|
328 |
pstInParam.szUserName = m_strUser.getBytes(); |
|
329 |
// 出参 |
|
330 |
NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY pstOutParam = new NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY(); |
|
331 |
pstOutParam.stuDeviceInfo = deviceinfoEx; |
|
332 |
loginHandler = LoginModule.netsdk.CLIENT_LoginWithHighLevelSecurity(pstInParam, pstOutParam); |
|
333 |
if (loginHandler.longValue() == 0) { |
|
334 |
JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), |
|
335 |
Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
336 |
} else { |
|
337 |
System.out.println("Login Success [ " + m_strIp + " ]"); |
|
338 |
} |
|
339 |
|
|
340 |
return loginHandler.longValue() == 0 ? false : true; |
|
341 |
} |
|
342 |
|
|
343 |
public long getLoginHandler() { |
|
344 |
if (loginHandler != null) { |
|
345 |
return loginHandler.longValue(); |
|
346 |
} |
|
347 |
return 0; |
|
348 |
} |
|
349 |
|
|
350 |
/** |
|
351 |
* \if ENGLISH_LANG Logout Device \else 登出设备 \endif |
|
352 |
*/ |
|
353 |
public boolean logout() { |
|
354 |
if (loginHandler.longValue() == 0) { |
|
355 |
return false; |
|
356 |
} |
|
357 |
|
|
358 |
boolean bRet = LoginModule.netsdk.CLIENT_Logout(loginHandler); |
|
359 |
if (bRet) { |
|
360 |
loginHandler.setValue(0); |
|
361 |
btnLogin.setEnabled(true); |
|
362 |
btnLogout.setEnabled(false); |
|
363 |
} else { |
|
364 |
JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), |
|
365 |
Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
366 |
} |
|
367 |
|
|
368 |
return bRet; |
|
369 |
} |
|
370 |
|
|
371 |
/** |
|
372 |
* 下发采集信息指令 |
|
373 |
* |
|
374 |
* @return |
|
375 |
*/ |
|
376 |
public boolean collectionFinger() { |
|
377 |
NetSDKLib.NET_CTRL_CAPTURE_FINGER_PRINT capture = new NetSDKLib.NET_CTRL_CAPTURE_FINGER_PRINT(); |
|
378 |
capture.nChannelID = 0; |
|
379 |
System.arraycopy("1".getBytes(), 0, capture.szReaderID, 0, "1".getBytes().length); |
|
380 |
Pointer pointer = new Memory(capture.size()); |
|
381 |
ToolKits.SetStructDataToPointer(capture, pointer, 0); |
|
382 |
boolean ret = LoginModule.netsdk.CLIENT_ControlDevice(loginHandler, NetSDKLib.CtrlType.CTRLTYPE_CTRL_CAPTURE_FINGER_PRINT, pointer, 100000); |
|
383 |
if (!ret) { |
|
384 |
JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), |
|
385 |
Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
386 |
return false; |
|
387 |
} |
|
388 |
return true; |
|
389 |
|
|
390 |
} |
|
391 |
|
|
392 |
public boolean startListen(NetSDKLib.LLong loginHandler, NetSDKLib.fMessCallBack cbMessage) { |
|
393 |
|
|
394 |
LoginModule.netsdk.CLIENT_SetDVRMessCallBack(cbMessage, null); // set alarm listen callback |
|
395 |
|
|
396 |
if (!LoginModule.netsdk.CLIENT_StartListenEx(loginHandler)) { |
|
397 |
JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), |
|
398 |
Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
399 |
return false; |
|
400 |
} else { |
|
401 |
System.out.println("CLIENT_StartListenEx success."); |
|
402 |
} |
|
403 |
return true; |
|
404 |
} |
|
405 |
|
|
406 |
public boolean stopListen(NetSDKLib.LLong loginHandler) { |
|
407 |
if (!LoginModule.netsdk.CLIENT_StopListen(loginHandler)) { |
|
408 |
JOptionPane.showMessageDialog(null, Res.string().getStopListenFailed()+","+ ToolKits.getErrorCodeShow(), |
|
409 |
Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
410 |
return false; |
|
411 |
} else { |
|
412 |
System.out.println("CLIENT_StopListen success."); |
|
413 |
} |
|
414 |
return true; |
|
415 |
} |
|
416 |
|
|
417 |
/** |
|
418 |
* 清除获取信息的状态 |
|
419 |
*/ |
|
420 |
public void clearStatus() { |
|
421 |
this.setPackageData(null); |
|
422 |
this.setCollectionResult(false); |
|
423 |
this.setPackageLen(0); |
|
424 |
} |
|
425 |
} |