提交 | 用户 | 时间
|
149dd0
|
1 |
package com.iailab.netsdk.demo.frame; |
H |
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.Color; |
|
5 |
import java.awt.Dimension; |
|
6 |
import java.awt.FlowLayout; |
|
7 |
import java.awt.GridLayout; |
|
8 |
import java.awt.Panel; |
|
9 |
|
|
10 |
import java.awt.event.ActionEvent; |
|
11 |
import java.awt.event.ActionListener; |
|
12 |
import java.awt.event.MouseEvent; |
|
13 |
import java.awt.event.MouseListener; |
|
14 |
import java.awt.event.WindowAdapter; |
|
15 |
import java.awt.event.WindowEvent; |
|
16 |
import java.awt.image.BufferedImage; |
|
17 |
import java.io.ByteArrayInputStream; |
|
18 |
import java.io.File; |
|
19 |
import java.io.IOException; |
|
20 |
import java.util.Vector; |
|
21 |
|
|
22 |
import javax.imageio.ImageIO; |
|
23 |
import javax.swing.DefaultComboBoxModel; |
|
24 |
import javax.swing.JButton; |
|
25 |
import javax.swing.JComboBox; |
|
26 |
import javax.swing.JFrame; |
|
27 |
import javax.swing.JLabel; |
|
28 |
import javax.swing.JOptionPane; |
|
29 |
import javax.swing.JPanel; |
|
30 |
import javax.swing.SwingUtilities; |
|
31 |
import javax.swing.UIManager; |
|
32 |
import javax.swing.border.EmptyBorder; |
|
33 |
|
|
34 |
import com.iailab.netsdk.common.*; |
|
35 |
import com.iailab.netsdk.demo.module.*; |
|
36 |
import com.iailab.netsdk.lib.*; |
|
37 |
import com.iailab.netsdk.lib.NetSDKLib.LLong; |
|
38 |
|
|
39 |
import com.sun.jna.CallbackThreadInitializer; |
|
40 |
import com.sun.jna.Native; |
|
41 |
import com.sun.jna.Pointer; |
|
42 |
|
|
43 |
/** |
|
44 |
* 实时预览Demo |
|
45 |
*/ |
|
46 |
class PTZControlFrame extends JFrame{ |
|
47 |
private static final long serialVersionUID = 1L; |
|
48 |
|
|
49 |
private Vector<String> chnlist = new Vector<String>(); |
|
50 |
|
|
51 |
private boolean b_realplay = false; |
|
52 |
|
|
53 |
// 设备断线通知回调 |
|
54 |
private static DisConnect disConnect = new DisConnect(); |
|
55 |
|
|
56 |
// 网络连接恢复 |
|
57 |
private static HaveReConnect haveReConnect = new HaveReConnect(); |
|
58 |
|
|
59 |
// 预览句柄 |
|
60 |
public static LLong m_hPlayHandle = new LLong(0); |
|
61 |
|
|
62 |
// 获取界面窗口 |
|
63 |
private static JFrame frame = new JFrame(); |
|
64 |
|
|
65 |
public PTZControlFrame() { |
|
66 |
setTitle(Res.string().getPTZ()); |
|
67 |
setLayout(new BorderLayout()); |
|
68 |
pack(); |
|
69 |
setSize(800, 560); |
|
70 |
setResizable(false); |
|
71 |
setLocationRelativeTo(null); |
|
72 |
LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 |
|
73 |
|
|
74 |
try { |
|
75 |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
|
76 |
} catch (Exception e) { |
|
77 |
e.printStackTrace(); |
|
78 |
} |
|
79 |
|
|
80 |
loginPanel = new LoginPanel(); |
|
81 |
realPanel = new RealPanel(); |
|
82 |
ptz_picPanel = new PTZ_PICPanel(); |
|
83 |
|
|
84 |
add(loginPanel, BorderLayout.NORTH); |
|
85 |
add(realPanel, BorderLayout.CENTER); |
|
86 |
add(ptz_picPanel, BorderLayout.EAST); |
|
87 |
|
|
88 |
loginPanel.addLoginBtnActionListener(new ActionListener() { |
|
89 |
@Override |
|
90 |
public void actionPerformed(ActionEvent e) { |
|
91 |
if(loginPanel.checkLoginText()) { |
|
92 |
if(login()) { |
|
93 |
frame = ToolKits.getFrame(e); |
|
94 |
frame.setTitle(Res.string().getPTZ() + " : " + Res.string().getOnline()); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
}); |
|
99 |
|
|
100 |
loginPanel.addLogoutBtnActionListener(new ActionListener() { |
|
101 |
@Override |
|
102 |
public void actionPerformed(ActionEvent e) { |
|
103 |
frame.setTitle(Res.string().getPTZ()); |
|
104 |
logout(); |
|
105 |
} |
|
106 |
}); |
|
107 |
|
|
108 |
addWindowListener(new WindowAdapter() { |
|
109 |
public void windowClosing(WindowEvent e) { |
|
110 |
RealPlayModule.stopRealPlay(m_hPlayHandle); |
|
111 |
LoginModule.logout(); |
|
112 |
LoginModule.cleanup(); // 关闭工程,释放资源 |
|
113 |
dispose(); |
|
114 |
|
|
115 |
SwingUtilities.invokeLater(new Runnable() { |
|
116 |
public void run() { |
|
117 |
FunctionList demo = new FunctionList(); |
|
118 |
demo.setVisible(true); |
|
119 |
} |
|
120 |
}); |
|
121 |
} |
|
122 |
}); |
|
123 |
} |
|
124 |
|
|
125 |
/////////////////面板/////////////////// |
|
126 |
// 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数 |
|
127 |
private static class DisConnect implements NetSDKLib.fDisConnect { |
|
128 |
public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { |
|
129 |
System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); |
|
130 |
// 断线提示 |
|
131 |
SwingUtilities.invokeLater(new Runnable() { |
|
132 |
public void run() { |
|
133 |
frame.setTitle(Res.string().getPTZ() + " : " + Res.string().getDisConnectReconnecting()); |
|
134 |
} |
|
135 |
}); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
// 网络连接恢复,设备重连成功回调 |
|
140 |
// 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 |
|
141 |
private static class HaveReConnect implements NetSDKLib.fHaveReConnect { |
|
142 |
public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { |
|
143 |
System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); |
|
144 |
|
|
145 |
// 重连提示 |
|
146 |
SwingUtilities.invokeLater(new Runnable() { |
|
147 |
public void run() { |
|
148 |
frame.setTitle(Res.string().getPTZ() + " : " + Res.string().getOnline()); |
|
149 |
} |
|
150 |
}); |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
// 登录 |
|
155 |
public boolean login() { |
|
156 |
Native.setCallbackThreadInitializer(m_SnapReceiveCB, |
|
157 |
new CallbackThreadInitializer(false, false, "snapPicture callback thread")); |
|
158 |
if(LoginModule.login(loginPanel.ipTextArea.getText(), |
|
159 |
Integer.parseInt(loginPanel.portTextArea.getText()), |
|
160 |
loginPanel.nameTextArea.getText(), |
|
161 |
new String(loginPanel.passwordTextArea.getPassword()))) { |
|
162 |
|
|
163 |
loginPanel.setButtonEnable(true); |
|
164 |
setButtonEnable(true); |
|
165 |
|
|
166 |
for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) { |
|
167 |
chnlist.add(Res.string().getChannel() + " " + String.valueOf(i)); |
|
168 |
} |
|
169 |
|
|
170 |
// 登陆成功,将通道添加到控件 |
|
171 |
chnComboBox.setModel(new DefaultComboBoxModel(chnlist)); |
|
172 |
|
|
173 |
CapturePictureModule.setSnapRevCallBack(m_SnapReceiveCB); |
|
174 |
} else { |
|
175 |
JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
176 |
return false; |
|
177 |
} |
|
178 |
return true; |
|
179 |
} |
|
180 |
|
|
181 |
// 登出 |
|
182 |
public void logout() { |
|
183 |
RealPlayModule.stopRealPlay(m_hPlayHandle); |
|
184 |
LoginModule.logout(); |
|
185 |
|
|
186 |
loginPanel.setButtonEnable(false); |
|
187 |
setButtonEnable(false); |
|
188 |
realPlayWindow.repaint(); |
|
189 |
pictureShowWindow.setOpaque(true); |
|
190 |
pictureShowWindow.repaint(); |
|
191 |
|
|
192 |
b_realplay = false; |
|
193 |
realplayBtn.setText(Res.string().getStartRealPlay()); |
|
194 |
|
|
195 |
for(int i = 0; i < LoginModule.m_stDeviceInfo.byChanNum; i++) { |
|
196 |
chnlist.clear(); |
|
197 |
} |
|
198 |
|
|
199 |
chnComboBox.setModel(new DefaultComboBoxModel()); |
|
200 |
} |
|
201 |
|
|
202 |
/* |
|
203 |
* 预览界面通道、码流设置 以及抓图面板 |
|
204 |
*/ |
|
205 |
private class RealPanel extends JPanel { |
|
206 |
private static final long serialVersionUID = 1L; |
|
207 |
|
|
208 |
public RealPanel() { |
|
209 |
BorderEx.set(this, Res.string().getRealplay(), 2); |
|
210 |
setLayout(new BorderLayout()); |
|
211 |
|
|
212 |
channelPanel = new Panel(); |
|
213 |
realplayPanel = new JPanel(); |
|
214 |
|
|
215 |
add(channelPanel, BorderLayout.SOUTH); |
|
216 |
add(realplayPanel, BorderLayout.CENTER); |
|
217 |
|
|
218 |
/************ 预览面板 **************/ |
|
219 |
realplayPanel.setLayout(new BorderLayout()); |
|
220 |
realplayPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); |
|
221 |
realPlayWindow = new Panel(); |
|
222 |
realPlayWindow.setBackground(Color.GRAY); |
|
223 |
realplayPanel.add(realPlayWindow, BorderLayout.CENTER); |
|
224 |
|
|
225 |
/************ 通道、码流面板 **************/ |
|
226 |
chnlabel = new JLabel(Res.string().getChannel()); |
|
227 |
chnComboBox = new JComboBox(); |
|
228 |
|
|
229 |
streamLabel = new JLabel(Res.string().getStreamType()); |
|
230 |
String[] stream = {Res.string().getMasterStream(), Res.string().getSubStream()}; |
|
231 |
streamComboBox = new JComboBox(stream); |
|
232 |
|
|
233 |
realplayBtn = new JButton(Res.string().getStartRealPlay()); |
|
234 |
|
|
235 |
channelPanel.setLayout(new FlowLayout()); |
|
236 |
channelPanel.add(chnlabel); |
|
237 |
channelPanel.add(chnComboBox); |
|
238 |
channelPanel.add(streamLabel); |
|
239 |
channelPanel.add(streamComboBox); |
|
240 |
channelPanel.add(realplayBtn); |
|
241 |
|
|
242 |
chnComboBox.setPreferredSize(new Dimension(90, 20)); |
|
243 |
streamComboBox.setPreferredSize(new Dimension(90, 20)); |
|
244 |
realplayBtn.setPreferredSize(new Dimension(120, 20)); |
|
245 |
|
|
246 |
realPlayWindow.setEnabled(false); |
|
247 |
chnComboBox.setEnabled(false); |
|
248 |
streamComboBox.setEnabled(false); |
|
249 |
realplayBtn.setEnabled(false); |
|
250 |
|
|
251 |
realplayBtn.addActionListener(new ActionListener() { |
|
252 |
@Override |
|
253 |
public void actionPerformed(ActionEvent e) { |
|
254 |
realplay(); |
|
255 |
} |
|
256 |
}); |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 |
// 预览 |
|
261 |
public void realplay() { |
|
262 |
if(!b_realplay) { |
|
263 |
m_hPlayHandle = RealPlayModule.startRealPlay(chnComboBox.getSelectedIndex(), |
|
264 |
streamComboBox.getSelectedIndex()==0? 0:3, |
|
265 |
realPlayWindow); |
|
266 |
if(m_hPlayHandle.longValue() != 0) { |
|
267 |
realPlayWindow.repaint(); |
|
268 |
b_realplay = true; |
|
269 |
chnComboBox.setEnabled(false); |
|
270 |
streamComboBox.setEnabled(false); |
|
271 |
realplayBtn.setText(Res.string().getStopRealPlay()); |
|
272 |
} |
|
273 |
} else { |
|
274 |
RealPlayModule.stopRealPlay(m_hPlayHandle); |
|
275 |
realPlayWindow.repaint(); |
|
276 |
b_realplay = false; |
|
277 |
chnComboBox.setEnabled(true); |
|
278 |
streamComboBox.setEnabled(true); |
|
279 |
realplayBtn.setText(Res.string().getStartRealPlay()); |
|
280 |
} |
|
281 |
} |
|
282 |
|
|
283 |
/* |
|
284 |
* 抓图显示与云台控制面板 |
|
285 |
*/ |
|
286 |
private class PTZ_PICPanel extends JPanel { |
|
287 |
private static final long serialVersionUID = 1L; |
|
288 |
|
|
289 |
public PTZ_PICPanel() { |
|
290 |
setLayout(new BorderLayout()); |
|
291 |
Dimension dim = getPreferredSize(); |
|
292 |
dim.width = 320; |
|
293 |
setPreferredSize(dim); |
|
294 |
|
|
295 |
picPanel = new PICPanel(); // 图片显示面板 |
|
296 |
ptzPanel = new PTZPanel(); // 云台面板 |
|
297 |
|
|
298 |
add(picPanel, BorderLayout.CENTER); |
|
299 |
add(ptzPanel, BorderLayout.SOUTH); |
|
300 |
} |
|
301 |
} |
|
302 |
|
|
303 |
/* |
|
304 |
* 抓图显示面板 |
|
305 |
*/ |
|
306 |
private class PICPanel extends JPanel { |
|
307 |
private static final long serialVersionUID = 1L; |
|
308 |
|
|
309 |
public PICPanel() { |
|
310 |
BorderEx.set(this, Res.string().getCapturePicture(), 2); |
|
311 |
setLayout(new BorderLayout()); |
|
312 |
|
|
313 |
pictureShowPanel = new JPanel(); |
|
314 |
snapPanel = new JPanel(); |
|
315 |
|
|
316 |
add(pictureShowPanel, BorderLayout.CENTER); |
|
317 |
add(snapPanel, BorderLayout.SOUTH); |
|
318 |
|
|
319 |
/************** 抓图按钮 ************/ |
|
320 |
snapPanel.setLayout(new BorderLayout()); |
|
321 |
snapPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); |
|
322 |
snapBtn = new JButton(Res.string().getRemoteCapture()); |
|
323 |
snapBtn.setPreferredSize(new Dimension(40, 23)); |
|
324 |
snapPanel.add(snapBtn, BorderLayout.CENTER); |
|
325 |
snapBtn.setEnabled(false); |
|
326 |
|
|
327 |
/************** 图片显示 ************/ |
|
328 |
pictureShowPanel.setLayout(new BorderLayout()); |
|
329 |
pictureShowPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); |
|
330 |
pictureShowWindow = new PaintPanel(); |
|
331 |
pictureShowPanel.add(pictureShowWindow, BorderLayout.CENTER); |
|
332 |
|
|
333 |
snapBtn.addActionListener(new ActionListener() { |
|
334 |
@Override |
|
335 |
public void actionPerformed(ActionEvent arg0) { |
|
336 |
if(!CapturePictureModule.remoteCapturePicture(chnComboBox.getSelectedIndex())) { |
|
337 |
JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
338 |
} |
|
339 |
} |
|
340 |
}); |
|
341 |
} |
|
342 |
} |
|
343 |
|
|
344 |
/* |
|
345 |
* 云台控制面板 |
|
346 |
*/ |
|
347 |
private class PTZPanel extends JPanel { |
|
348 |
private static final long serialVersionUID = 1L; |
|
349 |
|
|
350 |
public PTZPanel() { |
|
351 |
BorderEx.set(this, Res.string().getPTZControl(), 2); |
|
352 |
setPreferredSize(new Dimension(40, 205)); |
|
353 |
setLayout(new GridLayout(2, 1)); |
|
354 |
|
|
355 |
directionPanel = new JPanel(); |
|
356 |
JPanel panel1 = new JPanel(); |
|
357 |
JPanel panel2 = new JPanel(); |
|
358 |
ptzCtrlPanel = new JPanel(); |
|
359 |
|
|
360 |
add(directionPanel); |
|
361 |
add(ptzCtrlPanel); |
|
362 |
|
|
363 |
directionPanel.setLayout(new BorderLayout()); |
|
364 |
|
|
365 |
directionPanel.add(panel1, BorderLayout.NORTH); |
|
366 |
directionPanel.add(panel2, BorderLayout.CENTER); |
|
367 |
|
|
368 |
/*************** 云台方向 **************/ |
|
369 |
panel1.setLayout(new BorderLayout()); |
|
370 |
panel1.setBorder(new EmptyBorder(0, 5, 0, 5)); |
|
371 |
|
|
372 |
panel2.setLayout(new GridLayout(3, 3)); |
|
373 |
panel2.setBorder(new EmptyBorder(0, 5, 0, 5)); |
|
374 |
|
|
375 |
leftUpBtn = new JButton(Res.string().getLeftUp()); |
|
376 |
upBtn = new JButton(Res.string().getUp()); |
|
377 |
rightUpBtn = new JButton(Res.string().getRightUp()); |
|
378 |
leftBtn = new JButton(Res.string().getLeft()); |
|
379 |
rightBtn = new JButton(Res.string().getRight()); |
|
380 |
leftDownBtn = new JButton(Res.string().getLeftDown()); |
|
381 |
downBtn = new JButton(Res.string().getDown()); |
|
382 |
rightDownBtn = new JButton(Res.string().getRightDown()); |
|
383 |
operateJLabel = new JLabel("", JLabel.CENTER); |
|
384 |
|
|
385 |
String[] speed = {Res.string().getSpeed() + " 1", |
|
386 |
Res.string().getSpeed() + " 2", |
|
387 |
Res.string().getSpeed() + " 3", |
|
388 |
Res.string().getSpeed() + " 4", |
|
389 |
Res.string().getSpeed() + " 5", |
|
390 |
Res.string().getSpeed() + " 6", |
|
391 |
Res.string().getSpeed() + " 7", |
|
392 |
Res.string().getSpeed() + " 8"}; |
|
393 |
|
|
394 |
speedComboBox = new JComboBox(speed); |
|
395 |
speedComboBox.setSelectedIndex(4); |
|
396 |
speedComboBox.setPreferredSize(new Dimension(40, 21)); |
|
397 |
|
|
398 |
panel1.add(speedComboBox, BorderLayout.CENTER); |
|
399 |
|
|
400 |
panel2.add(leftUpBtn); |
|
401 |
panel2.add(upBtn); |
|
402 |
panel2.add(rightUpBtn); |
|
403 |
panel2.add(leftBtn); |
|
404 |
panel2.add(operateJLabel); |
|
405 |
panel2.add(rightBtn); |
|
406 |
panel2.add(leftDownBtn); |
|
407 |
panel2.add(downBtn); |
|
408 |
panel2.add(rightDownBtn); |
|
409 |
|
|
410 |
leftUpBtn.setEnabled(false); |
|
411 |
upBtn.setEnabled(false); |
|
412 |
rightUpBtn.setEnabled(false); |
|
413 |
leftBtn.setEnabled(false); |
|
414 |
rightBtn.setEnabled(false); |
|
415 |
leftDownBtn.setEnabled(false); |
|
416 |
downBtn.setEnabled(false); |
|
417 |
rightDownBtn.setEnabled(false); |
|
418 |
speedComboBox.setEnabled(false); |
|
419 |
|
|
420 |
/*************** 变焦、变倍、光圈 **************/ |
|
421 |
ptzCtrlPanel.setLayout(new GridLayout(3, 2)); |
|
422 |
ptzCtrlPanel.setBorder(new EmptyBorder(15, 5, 5, 5)); |
|
423 |
zoomAddBtn = new JButton(Res.string().getZoomAdd()); |
|
424 |
zoomDecBtn = new JButton(Res.string().getZoomDec()); |
|
425 |
focusAddBtn = new JButton(Res.string().getFocusAdd()); |
|
426 |
focusDecBtn = new JButton(Res.string().getFocusDec()); |
|
427 |
irisAddBtn = new JButton(Res.string().getIrisAdd()); |
|
428 |
irisDecBtn = new JButton(Res.string().getIrisDec()); |
|
429 |
|
|
430 |
ptzCtrlPanel.add(zoomAddBtn); |
|
431 |
ptzCtrlPanel.add(zoomDecBtn); |
|
432 |
ptzCtrlPanel.add(focusAddBtn); |
|
433 |
ptzCtrlPanel.add(focusDecBtn); |
|
434 |
ptzCtrlPanel.add(irisAddBtn); |
|
435 |
ptzCtrlPanel.add(irisDecBtn); |
|
436 |
|
|
437 |
zoomAddBtn.setEnabled(false); |
|
438 |
zoomDecBtn.setEnabled(false); |
|
439 |
focusAddBtn.setEnabled(false); |
|
440 |
focusDecBtn.setEnabled(false); |
|
441 |
irisAddBtn.setEnabled(false); |
|
442 |
irisDecBtn.setEnabled(false); |
|
443 |
|
|
444 |
// 向上 |
|
445 |
upBtn.addMouseListener(new MouseListener() { |
|
446 |
@Override |
|
447 |
public void mouseExited(MouseEvent e) { |
|
448 |
} |
|
449 |
@Override |
|
450 |
public void mouseEntered(MouseEvent e) { |
|
451 |
} |
|
452 |
@Override |
|
453 |
public void mouseClicked(MouseEvent e) { |
|
454 |
} |
|
455 |
@Override |
|
456 |
public void mousePressed(MouseEvent e) { |
|
457 |
if(PtzControlModule.ptzControlUpStart(chnComboBox.getSelectedIndex(), |
|
458 |
0, |
|
459 |
speedComboBox.getSelectedIndex())) { |
|
460 |
operateJLabel.setText(Res.string().getSucceed()); |
|
461 |
} else { |
|
462 |
operateJLabel.setText(Res.string().getFailed()); |
|
463 |
} |
|
464 |
} |
|
465 |
@Override |
|
466 |
public void mouseReleased(MouseEvent e) { |
|
467 |
PtzControlModule.ptzControlUpEnd(chnComboBox.getSelectedIndex()); |
|
468 |
operateJLabel.setText(""); |
|
469 |
} |
|
470 |
}); |
|
471 |
|
|
472 |
|
|
473 |
// 向下 |
|
474 |
downBtn.addMouseListener(new MouseListener() { |
|
475 |
@Override |
|
476 |
public void mouseExited(MouseEvent e) { |
|
477 |
} |
|
478 |
@Override |
|
479 |
public void mouseEntered(MouseEvent e) { |
|
480 |
} |
|
481 |
@Override |
|
482 |
public void mouseClicked(MouseEvent e) { |
|
483 |
} |
|
484 |
@Override |
|
485 |
public void mousePressed(MouseEvent e) { |
|
486 |
if(PtzControlModule.ptzControlDownStart(chnComboBox.getSelectedIndex(), |
|
487 |
0, |
|
488 |
speedComboBox.getSelectedIndex())) { |
|
489 |
operateJLabel.setText(Res.string().getSucceed()); |
|
490 |
} else { |
|
491 |
operateJLabel.setText(Res.string().getFailed()); |
|
492 |
} |
|
493 |
} |
|
494 |
@Override |
|
495 |
public void mouseReleased(MouseEvent e) { |
|
496 |
PtzControlModule.ptzControlDownEnd(chnComboBox.getSelectedIndex()); |
|
497 |
operateJLabel.setText(""); |
|
498 |
} |
|
499 |
}); |
|
500 |
|
|
501 |
|
|
502 |
// 向左 |
|
503 |
leftBtn.addMouseListener(new MouseListener() { |
|
504 |
@Override |
|
505 |
public void mouseExited(MouseEvent e) { |
|
506 |
} |
|
507 |
@Override |
|
508 |
public void mouseEntered(MouseEvent e) { |
|
509 |
} |
|
510 |
@Override |
|
511 |
public void mouseClicked(MouseEvent e) { |
|
512 |
} |
|
513 |
@Override |
|
514 |
public void mousePressed(MouseEvent e) { |
|
515 |
if(PtzControlModule.ptzControlLeftStart(chnComboBox.getSelectedIndex(), |
|
516 |
0, |
|
517 |
speedComboBox.getSelectedIndex())) { |
|
518 |
operateJLabel.setText(Res.string().getSucceed()); |
|
519 |
} else { |
|
520 |
operateJLabel.setText(Res.string().getFailed()); |
|
521 |
} |
|
522 |
} |
|
523 |
@Override |
|
524 |
public void mouseReleased(MouseEvent e) { |
|
525 |
PtzControlModule.ptzControlLeftEnd(chnComboBox.getSelectedIndex()); |
|
526 |
operateJLabel.setText(""); |
|
527 |
} |
|
528 |
}); |
|
529 |
|
|
530 |
// 向右 |
|
531 |
rightBtn.addMouseListener(new MouseListener() { |
|
532 |
@Override |
|
533 |
public void mouseExited(MouseEvent e) { |
|
534 |
} |
|
535 |
@Override |
|
536 |
public void mouseEntered(MouseEvent e) { |
|
537 |
} |
|
538 |
@Override |
|
539 |
public void mouseClicked(MouseEvent e) { |
|
540 |
} |
|
541 |
@Override |
|
542 |
public void mousePressed(MouseEvent e) { |
|
543 |
if(PtzControlModule.ptzControlRightStart(chnComboBox.getSelectedIndex(), |
|
544 |
0, |
|
545 |
speedComboBox.getSelectedIndex())) { |
|
546 |
operateJLabel.setText(Res.string().getSucceed()); |
|
547 |
} else { |
|
548 |
operateJLabel.setText(Res.string().getFailed()); |
|
549 |
} |
|
550 |
} |
|
551 |
@Override |
|
552 |
public void mouseReleased(MouseEvent e) { |
|
553 |
PtzControlModule.ptzControlRightEnd(chnComboBox.getSelectedIndex()); |
|
554 |
operateJLabel.setText(""); |
|
555 |
} |
|
556 |
}); |
|
557 |
|
|
558 |
// 向左上 |
|
559 |
leftUpBtn.addMouseListener(new MouseListener() { |
|
560 |
@Override |
|
561 |
public void mouseExited(MouseEvent e) { |
|
562 |
} |
|
563 |
@Override |
|
564 |
public void mouseEntered(MouseEvent e) { |
|
565 |
} |
|
566 |
@Override |
|
567 |
public void mouseClicked(MouseEvent e) { |
|
568 |
} |
|
569 |
@Override |
|
570 |
public void mousePressed(MouseEvent e) { |
|
571 |
if(PtzControlModule.ptzControlLeftUpStart(chnComboBox.getSelectedIndex(), |
|
572 |
speedComboBox.getSelectedIndex(), |
|
573 |
speedComboBox.getSelectedIndex())) { |
|
574 |
operateJLabel.setText(Res.string().getSucceed()); |
|
575 |
} else { |
|
576 |
operateJLabel.setText(Res.string().getFailed()); |
|
577 |
} |
|
578 |
} |
|
579 |
@Override |
|
580 |
public void mouseReleased(MouseEvent e) { |
|
581 |
PtzControlModule.ptzControlLeftUpEnd(chnComboBox.getSelectedIndex()); |
|
582 |
operateJLabel.setText(""); |
|
583 |
} |
|
584 |
}); |
|
585 |
|
|
586 |
// 向右上 |
|
587 |
rightUpBtn.addMouseListener(new MouseListener() { |
|
588 |
@Override |
|
589 |
public void mouseExited(MouseEvent e) { |
|
590 |
} |
|
591 |
@Override |
|
592 |
public void mouseEntered(MouseEvent e) { |
|
593 |
} |
|
594 |
@Override |
|
595 |
public void mouseClicked(MouseEvent e) { |
|
596 |
} |
|
597 |
@Override |
|
598 |
public void mousePressed(MouseEvent e) { |
|
599 |
if(PtzControlModule.ptzControlRightUpStart(chnComboBox.getSelectedIndex(), |
|
600 |
speedComboBox.getSelectedIndex(), |
|
601 |
speedComboBox.getSelectedIndex())) { |
|
602 |
operateJLabel.setText(Res.string().getSucceed()); |
|
603 |
} else { |
|
604 |
operateJLabel.setText(Res.string().getFailed()); |
|
605 |
} |
|
606 |
} |
|
607 |
@Override |
|
608 |
public void mouseReleased(MouseEvent e) { |
|
609 |
PtzControlModule.ptzControlRightUpEnd(chnComboBox.getSelectedIndex()); |
|
610 |
operateJLabel.setText(""); |
|
611 |
} |
|
612 |
}); |
|
613 |
|
|
614 |
// 向左下 |
|
615 |
leftDownBtn.addMouseListener(new MouseListener() { |
|
616 |
@Override |
|
617 |
public void mouseExited(MouseEvent e) { |
|
618 |
} |
|
619 |
@Override |
|
620 |
public void mouseEntered(MouseEvent e) { |
|
621 |
} |
|
622 |
@Override |
|
623 |
public void mouseClicked(MouseEvent e) { |
|
624 |
} |
|
625 |
@Override |
|
626 |
public void mousePressed(MouseEvent e) { |
|
627 |
if(PtzControlModule.ptzControlLeftDownStart(chnComboBox.getSelectedIndex(), |
|
628 |
speedComboBox.getSelectedIndex(), |
|
629 |
speedComboBox.getSelectedIndex())) { |
|
630 |
operateJLabel.setText(Res.string().getSucceed()); |
|
631 |
} else { |
|
632 |
operateJLabel.setText(Res.string().getFailed()); |
|
633 |
} |
|
634 |
} |
|
635 |
@Override |
|
636 |
public void mouseReleased(MouseEvent e) { |
|
637 |
PtzControlModule.ptzControlLeftDownEnd(chnComboBox.getSelectedIndex()); |
|
638 |
operateJLabel.setText(""); |
|
639 |
} |
|
640 |
}); |
|
641 |
|
|
642 |
// 向右下 |
|
643 |
rightDownBtn.addMouseListener(new MouseListener() { |
|
644 |
@Override |
|
645 |
public void mouseExited(MouseEvent e) { |
|
646 |
} |
|
647 |
@Override |
|
648 |
public void mouseEntered(MouseEvent e) { |
|
649 |
} |
|
650 |
@Override |
|
651 |
public void mouseClicked(MouseEvent e) { |
|
652 |
} |
|
653 |
@Override |
|
654 |
public void mousePressed(MouseEvent e) { |
|
655 |
if(PtzControlModule.ptzControlRightDownStart(chnComboBox.getSelectedIndex(), |
|
656 |
speedComboBox.getSelectedIndex(), |
|
657 |
speedComboBox.getSelectedIndex())) { |
|
658 |
operateJLabel.setText(Res.string().getSucceed()); |
|
659 |
} else { |
|
660 |
operateJLabel.setText(Res.string().getFailed()); |
|
661 |
} |
|
662 |
} |
|
663 |
@Override |
|
664 |
public void mouseReleased(MouseEvent e) { |
|
665 |
PtzControlModule.ptzControlRightDownEnd(chnComboBox.getSelectedIndex()); |
|
666 |
operateJLabel.setText(""); |
|
667 |
} |
|
668 |
}); |
|
669 |
|
|
670 |
// 变倍+ |
|
671 |
zoomAddBtn.addMouseListener(new MouseListener() { |
|
672 |
@Override |
|
673 |
public void mouseExited(MouseEvent e) { |
|
674 |
} |
|
675 |
@Override |
|
676 |
public void mouseEntered(MouseEvent e) { |
|
677 |
} |
|
678 |
@Override |
|
679 |
public void mouseClicked(MouseEvent e) { |
|
680 |
} |
|
681 |
@Override |
|
682 |
public void mousePressed(MouseEvent e) { |
|
683 |
if(PtzControlModule.ptzControlZoomAddStart(chnComboBox.getSelectedIndex(), |
|
684 |
speedComboBox.getSelectedIndex())) { |
|
685 |
operateJLabel.setText(Res.string().getSucceed()); |
|
686 |
} else { |
|
687 |
operateJLabel.setText(Res.string().getFailed()); |
|
688 |
} |
|
689 |
} |
|
690 |
@Override |
|
691 |
public void mouseReleased(MouseEvent e) { |
|
692 |
PtzControlModule.ptzControlZoomAddEnd(chnComboBox.getSelectedIndex()); |
|
693 |
operateJLabel.setText(""); |
|
694 |
} |
|
695 |
}); |
|
696 |
|
|
697 |
// 变倍- |
|
698 |
zoomDecBtn.addMouseListener(new MouseListener() { |
|
699 |
@Override |
|
700 |
public void mouseExited(MouseEvent e) { |
|
701 |
} |
|
702 |
@Override |
|
703 |
public void mouseEntered(MouseEvent e) { |
|
704 |
} |
|
705 |
@Override |
|
706 |
public void mouseClicked(MouseEvent e) { |
|
707 |
} |
|
708 |
@Override |
|
709 |
public void mousePressed(MouseEvent e) { |
|
710 |
if(PtzControlModule.ptzControlZoomDecStart(chnComboBox.getSelectedIndex(), |
|
711 |
speedComboBox.getSelectedIndex())) { |
|
712 |
operateJLabel.setText(Res.string().getSucceed()); |
|
713 |
} else { |
|
714 |
operateJLabel.setText(Res.string().getFailed()); |
|
715 |
} |
|
716 |
} |
|
717 |
@Override |
|
718 |
public void mouseReleased(MouseEvent e) { |
|
719 |
PtzControlModule.ptzControlZoomDecEnd(chnComboBox.getSelectedIndex()); |
|
720 |
operateJLabel.setText(""); |
|
721 |
} |
|
722 |
}); |
|
723 |
|
|
724 |
// 变焦+ |
|
725 |
focusAddBtn.addMouseListener(new MouseListener() { |
|
726 |
@Override |
|
727 |
public void mouseExited(MouseEvent e) { |
|
728 |
} |
|
729 |
@Override |
|
730 |
public void mouseEntered(MouseEvent e) { |
|
731 |
} |
|
732 |
@Override |
|
733 |
public void mouseClicked(MouseEvent e) { |
|
734 |
} |
|
735 |
@Override |
|
736 |
public void mousePressed(MouseEvent e) { |
|
737 |
if(PtzControlModule.ptzControlFocusAddStart(chnComboBox.getSelectedIndex(), |
|
738 |
speedComboBox.getSelectedIndex())) { |
|
739 |
operateJLabel.setText(Res.string().getSucceed()); |
|
740 |
} else { |
|
741 |
operateJLabel.setText(Res.string().getFailed()); |
|
742 |
} |
|
743 |
} |
|
744 |
@Override |
|
745 |
public void mouseReleased(MouseEvent e) { |
|
746 |
PtzControlModule.ptzControlFocusAddEnd(chnComboBox.getSelectedIndex()); |
|
747 |
operateJLabel.setText(""); |
|
748 |
} |
|
749 |
}); |
|
750 |
|
|
751 |
// 变焦- |
|
752 |
focusDecBtn.addMouseListener(new MouseListener() { |
|
753 |
@Override |
|
754 |
public void mouseExited(MouseEvent e) { |
|
755 |
} |
|
756 |
@Override |
|
757 |
public void mouseEntered(MouseEvent e) { |
|
758 |
} |
|
759 |
@Override |
|
760 |
public void mouseClicked(MouseEvent e) { |
|
761 |
} |
|
762 |
@Override |
|
763 |
public void mousePressed(MouseEvent e) { |
|
764 |
if(PtzControlModule.ptzControlFocusDecStart(chnComboBox.getSelectedIndex(), |
|
765 |
speedComboBox.getSelectedIndex())) { |
|
766 |
operateJLabel.setText(Res.string().getSucceed()); |
|
767 |
} else { |
|
768 |
operateJLabel.setText(Res.string().getFailed()); |
|
769 |
} |
|
770 |
} |
|
771 |
@Override |
|
772 |
public void mouseReleased(MouseEvent e) { |
|
773 |
PtzControlModule.ptzControlFocusDecEnd(chnComboBox.getSelectedIndex()); |
|
774 |
operateJLabel.setText(""); |
|
775 |
} |
|
776 |
}); |
|
777 |
|
|
778 |
// 光圈+ |
|
779 |
irisAddBtn.addMouseListener(new MouseListener() { |
|
780 |
@Override |
|
781 |
public void mouseExited(MouseEvent e) { |
|
782 |
} |
|
783 |
@Override |
|
784 |
public void mouseEntered(MouseEvent e) { |
|
785 |
} |
|
786 |
@Override |
|
787 |
public void mouseClicked(MouseEvent e) { |
|
788 |
} |
|
789 |
@Override |
|
790 |
public void mousePressed(MouseEvent e) { |
|
791 |
if(PtzControlModule.ptzControlIrisAddStart(chnComboBox.getSelectedIndex(), |
|
792 |
speedComboBox.getSelectedIndex())) { |
|
793 |
operateJLabel.setText(Res.string().getSucceed()); |
|
794 |
} else { |
|
795 |
operateJLabel.setText(Res.string().getFailed()); |
|
796 |
} |
|
797 |
} |
|
798 |
@Override |
|
799 |
public void mouseReleased(MouseEvent e) { |
|
800 |
PtzControlModule.ptzControlIrisAddEnd(chnComboBox.getSelectedIndex()); |
|
801 |
operateJLabel.setText(""); |
|
802 |
} |
|
803 |
}); |
|
804 |
|
|
805 |
// 光圈- |
|
806 |
irisDecBtn.addMouseListener(new MouseListener() { |
|
807 |
@Override |
|
808 |
public void mouseExited(MouseEvent e) { |
|
809 |
} |
|
810 |
@Override |
|
811 |
public void mouseEntered(MouseEvent e) { |
|
812 |
} |
|
813 |
@Override |
|
814 |
public void mouseClicked(MouseEvent e) { |
|
815 |
} |
|
816 |
@Override |
|
817 |
public void mousePressed(MouseEvent e) { |
|
818 |
if(PtzControlModule.ptzControlIrisDecStart(chnComboBox.getSelectedIndex(), |
|
819 |
speedComboBox.getSelectedIndex())) { |
|
820 |
operateJLabel.setText(Res.string().getSucceed()); |
|
821 |
} else { |
|
822 |
operateJLabel.setText(Res.string().getFailed()); |
|
823 |
} |
|
824 |
} |
|
825 |
@Override |
|
826 |
public void mouseReleased(MouseEvent e) { |
|
827 |
PtzControlModule.ptzControlIrisDecEnd(chnComboBox.getSelectedIndex()); |
|
828 |
operateJLabel.setText(""); |
|
829 |
} |
|
830 |
}); |
|
831 |
} |
|
832 |
} |
|
833 |
|
|
834 |
public fSnapReceiveCB m_SnapReceiveCB = new fSnapReceiveCB(); |
|
835 |
public class fSnapReceiveCB implements NetSDKLib.fSnapRev{ |
|
836 |
BufferedImage bufferedImage = null; |
|
837 |
public void invoke( LLong lLoginID, Pointer pBuf, int RevLen, int EncodeType, int CmdSerial, Pointer dwUser) { |
|
838 |
if(pBuf != null && RevLen > 0) { |
|
839 |
String strFileName = SavePath.getSavePath().getSaveCapturePath(); |
|
840 |
|
|
841 |
System.out.println("strFileName = " + strFileName); |
|
842 |
|
|
843 |
byte[] buf = pBuf.getByteArray(0, RevLen); |
|
844 |
ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf); |
|
845 |
try { |
|
846 |
bufferedImage = ImageIO.read(byteArrInput); |
|
847 |
if(bufferedImage == null) { |
|
848 |
return; |
|
849 |
} |
|
850 |
ImageIO.write(bufferedImage, "jpg", new File(strFileName)); |
|
851 |
} catch (IOException e) { |
|
852 |
e.printStackTrace(); |
|
853 |
} |
|
854 |
|
|
855 |
// 界面显示抓图 |
|
856 |
SwingUtilities.invokeLater(new Runnable() { |
|
857 |
@Override |
|
858 |
public void run() { |
|
859 |
pictureShowWindow.setOpaque(false); |
|
860 |
pictureShowWindow.setImage(bufferedImage); |
|
861 |
pictureShowWindow.repaint(); |
|
862 |
} |
|
863 |
}); |
|
864 |
} |
|
865 |
} |
|
866 |
} |
|
867 |
|
|
868 |
private void setButtonEnable(boolean bln) { |
|
869 |
snapBtn.setEnabled(bln); |
|
870 |
leftUpBtn.setEnabled(bln); |
|
871 |
upBtn.setEnabled(bln); |
|
872 |
rightUpBtn.setEnabled(bln); |
|
873 |
leftBtn.setEnabled(bln); |
|
874 |
rightBtn.setEnabled(bln); |
|
875 |
leftDownBtn.setEnabled(bln); |
|
876 |
downBtn.setEnabled(bln); |
|
877 |
rightDownBtn.setEnabled(bln); |
|
878 |
zoomAddBtn.setEnabled(bln); |
|
879 |
zoomDecBtn.setEnabled(bln); |
|
880 |
focusAddBtn.setEnabled(bln); |
|
881 |
focusDecBtn.setEnabled(bln); |
|
882 |
irisAddBtn.setEnabled(bln); |
|
883 |
irisDecBtn.setEnabled(bln); |
|
884 |
speedComboBox.setEnabled(bln); |
|
885 |
realPlayWindow.setEnabled(bln); |
|
886 |
chnComboBox.setEnabled(bln); |
|
887 |
streamComboBox.setEnabled(bln); |
|
888 |
realplayBtn.setEnabled(bln); |
|
889 |
} |
|
890 |
|
|
891 |
/* |
|
892 |
* 登录 |
|
893 |
*/ |
|
894 |
private LoginPanel loginPanel; |
|
895 |
|
|
896 |
/* |
|
897 |
* 预览 |
|
898 |
*/ |
|
899 |
private RealPanel realPanel; |
|
900 |
private JPanel realplayPanel; |
|
901 |
private Panel realPlayWindow; |
|
902 |
private Panel channelPanel; |
|
903 |
|
|
904 |
private JLabel chnlabel; |
|
905 |
private JComboBox chnComboBox; |
|
906 |
private JLabel streamLabel; |
|
907 |
private JComboBox streamComboBox; |
|
908 |
private JButton realplayBtn; |
|
909 |
private JButton snapBtn; |
|
910 |
|
|
911 |
/* |
|
912 |
* 抓图与云台 |
|
913 |
*/ |
|
914 |
private PTZ_PICPanel ptz_picPanel; |
|
915 |
private PICPanel picPanel; |
|
916 |
private JPanel pictureShowPanel; |
|
917 |
private JPanel snapPanel; |
|
918 |
private PaintPanel pictureShowWindow; |
|
919 |
|
|
920 |
/* |
|
921 |
* 云台 |
|
922 |
*/ |
|
923 |
private PTZPanel ptzPanel; |
|
924 |
private JPanel directionPanel; |
|
925 |
private JPanel ptzCtrlPanel; |
|
926 |
private JButton leftUpBtn; |
|
927 |
private JButton upBtn; |
|
928 |
private JButton rightUpBtn; |
|
929 |
private JButton leftBtn; |
|
930 |
private JButton rightBtn; |
|
931 |
private JButton leftDownBtn; |
|
932 |
private JButton downBtn; |
|
933 |
private JButton rightDownBtn; |
|
934 |
private JComboBox speedComboBox; |
|
935 |
private JLabel operateJLabel; |
|
936 |
|
|
937 |
private JButton zoomAddBtn; |
|
938 |
private JButton zoomDecBtn; |
|
939 |
private JButton focusAddBtn; |
|
940 |
private JButton focusDecBtn; |
|
941 |
private JButton irisAddBtn; |
|
942 |
private JButton irisDecBtn; |
|
943 |
} |
|
944 |
|
|
945 |
public class PTZControl { |
|
946 |
public static void main(String[] args) { |
|
947 |
SwingUtilities.invokeLater(new Runnable() { |
|
948 |
public void run() { |
|
949 |
PTZControlFrame demo = new PTZControlFrame(); |
|
950 |
demo.setVisible(true); |
|
951 |
} |
|
952 |
}); |
|
953 |
} |
|
954 |
} |
|
955 |
|
|
956 |
|