提交 | 用户 | 时间
|
149dd0
|
1 |
package com.iailab.netsdk.demo.frame.Attendance; |
H |
2 |
|
|
3 |
import java.awt.AWTEvent; |
|
4 |
import java.awt.Dimension; |
|
5 |
import java.awt.EventQueue; |
|
6 |
import java.awt.FlowLayout; |
|
7 |
import java.awt.Toolkit; |
|
8 |
import java.awt.event.ActionEvent; |
|
9 |
import java.awt.event.ActionListener; |
|
10 |
|
|
11 |
import javax.swing.JButton; |
|
12 |
import javax.swing.JOptionPane; |
|
13 |
import javax.swing.JPanel; |
|
14 |
|
|
15 |
import com.sun.jna.Pointer; |
|
16 |
|
|
17 |
import com.iailab.netsdk.common.BorderEx; |
|
18 |
import com.iailab.netsdk.common.Res; |
|
19 |
import com.iailab.netsdk.demo.frame.Attendance.AttendanceShowPanel.EventInfoShowPanel; |
|
20 |
import com.iailab.netsdk.demo.module.AttendanceModule; |
|
21 |
import com.iailab.netsdk.demo.module.AttendanceModule.AccessEventInfo; |
|
22 |
import com.iailab.netsdk.lib.NetSDKLib; |
|
23 |
import com.iailab.netsdk.lib.ToolKits; |
|
24 |
import com.iailab.netsdk.lib.NetSDKLib.*; |
|
25 |
|
|
26 |
/** |
|
27 |
* 订阅面板 |
|
28 |
*/ |
|
29 |
public class SubscribePanel extends JPanel{ |
|
30 |
/** |
|
31 |
* |
|
32 |
*/ |
|
33 |
private static final long serialVersionUID = 1L; |
|
34 |
private java.awt.Component target = this; // 目标 |
|
35 |
private boolean bSubscribe = false; // 订阅标志 |
|
36 |
private EventInfoShowPanel eventShowPanel; // 事件显示界面 |
|
37 |
public SubscribePanel(EventInfoShowPanel eventPanel) { |
|
38 |
BorderEx.set(this, Res.string().getSubscribe(), 1); |
|
39 |
setLayout(new FlowLayout(FlowLayout.CENTER, 5, 30)); |
|
40 |
setPreferredSize(new Dimension(180, 80)); |
|
41 |
|
|
42 |
eventShowPanel = eventPanel; |
|
43 |
callback = new fAnalyzerDataCB(); |
|
44 |
|
|
45 |
subscribeBtn = new JButton(Res.string().getSubscribe()); |
|
46 |
subscribeBtn.setPreferredSize(new Dimension(150, 20)); |
|
47 |
|
|
48 |
add(subscribeBtn); |
|
49 |
|
|
50 |
subscribeBtn.addActionListener(new ActionListener() { |
|
51 |
@Override |
|
52 |
public void actionPerformed(ActionEvent e) { |
|
53 |
if (bSubscribe) { |
|
54 |
AttendanceModule.stopRealLoadPicture(); |
|
55 |
eventShowPanel.clearEvent(); |
|
56 |
setSubscribeStatus(false); |
|
57 |
}else { |
|
58 |
if (AttendanceModule.realLoadPicture(callback)) { |
|
59 |
setSubscribeStatus(true); |
|
60 |
}else { |
|
61 |
JOptionPane.showMessageDialog(null, Res.string().getSubscribeFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
62 |
return; |
|
63 |
} |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
}); |
|
68 |
|
|
69 |
subscribeBtn.setEnabled(false); |
|
70 |
} |
|
71 |
|
|
72 |
public void setButtonEnable(boolean b) { |
|
73 |
setSubscribeStatus(false); |
|
74 |
subscribeBtn.setEnabled(b); |
|
75 |
} |
|
76 |
|
|
77 |
public void setSubscribeStatus(boolean b) { |
|
78 |
bSubscribe = b; |
|
79 |
if (bSubscribe) { |
|
80 |
subscribeBtn.setText(Res.string().getUnSubscribe()); |
|
81 |
}else { |
|
82 |
subscribeBtn.setText(Res.string().getSubscribe()); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* 智能报警事件回调 |
|
88 |
**/ |
|
89 |
public class fAnalyzerDataCB implements fAnalyzerDataCallBack { |
|
90 |
public final EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); |
|
91 |
@Override |
|
92 |
public int invoke(LLong lAnalyzerHandle, int dwAlarmType, |
|
93 |
Pointer pAlarmInfo, Pointer pBuffer, int dwBufSize, |
|
94 |
Pointer dwUser, int nSequence, Pointer reserved) { |
|
95 |
if(pAlarmInfo == null) { |
|
96 |
return 0; |
|
97 |
} |
|
98 |
|
|
99 |
switch(dwAlarmType) { |
|
100 |
case NetSDKLib.EVENT_IVS_ACCESS_CTL: // 门禁事件 |
|
101 |
DEV_EVENT_ACCESS_CTL_INFO event = new DEV_EVENT_ACCESS_CTL_INFO(); |
|
102 |
ToolKits.GetPointerData(pAlarmInfo, event); |
|
103 |
AccessEventInfo accessEvent = new AccessEventInfo(); |
|
104 |
accessEvent.userId = new String(event.szUserID).trim(); |
|
105 |
accessEvent.cardNo = new String(event.szCardNo).trim(); |
|
106 |
accessEvent.eventTime = event.UTC.toStringTime(); |
|
107 |
accessEvent.openDoorMethod = event.emOpenMethod; |
|
108 |
if (eventQueue != null) { |
|
109 |
eventQueue.postEvent(new AccessEvent(target, accessEvent)); |
|
110 |
} |
|
111 |
break; |
|
112 |
default: |
|
113 |
break; |
|
114 |
} |
|
115 |
|
|
116 |
return 0; |
|
117 |
} |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* 门禁事件 |
|
122 |
**/ |
|
123 |
class AccessEvent extends AWTEvent { |
|
124 |
/** |
|
125 |
* |
|
126 |
*/ |
|
127 |
private static final long serialVersionUID = 1L; |
|
128 |
public static final int EVENT_ID = AWTEvent.RESERVED_ID_MAX + 1; |
|
129 |
private AccessEventInfo accessEvent; |
|
130 |
|
|
131 |
public AccessEvent(Object target, AccessEventInfo accessEvent) { |
|
132 |
super(target, EVENT_ID); |
|
133 |
this.accessEvent = accessEvent; |
|
134 |
} |
|
135 |
|
|
136 |
public AccessEventInfo getAccessEventInfo() { |
|
137 |
return this.accessEvent; |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
@Override |
|
142 |
protected void processEvent( AWTEvent event) { |
|
143 |
if ( event instanceof AccessEvent) { |
|
144 |
AccessEventInfo accessEventInfo = ((AccessEvent)event).getAccessEventInfo(); |
|
145 |
eventShowPanel.insertEvent(accessEventInfo); |
|
146 |
} else { |
|
147 |
super.processEvent(event); |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
private JButton subscribeBtn; // 订阅按钮 |
|
152 |
private fAnalyzerDataCallBack callback; // 事件回调 |
|
153 |
} |