| @@ -0,0 +1,553 @@ | |||
| /* | |||
| * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. | |||
| * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| * | |||
| */ | |||
| // Base64解码 使用1.8版本源码 鉴于1.8部分特性1.6版本使用不到 故只保留能使用到的代码 其余删除 | |||
| package com.netsdk.common; | |||
| import java.nio.ByteBuffer; | |||
| import java.nio.charset.Charset; | |||
| import java.util.Arrays; | |||
| /** | |||
| * This class consists exclusively of static methods for obtaining | |||
| * encoders and decoders for the Base64 encoding scheme. The | |||
| * implementation of this class supports the following types of Base64 | |||
| * as specified in | |||
| * <a href="http://www.ietf.org/rfc/rfc4648.txt">RFC 4648</a> and | |||
| * | |||
| * <ul> | |||
| * <li><a name="basic"><b>Basic</b></a> | |||
| * <p> Uses "The Base64 Alphabet" as specified in Table 1 of | |||
| * RFC 4648 and RFC 2045 for encoding and decoding operation. | |||
| * The encoder does not add any line feed (line separator) | |||
| * character. The decoder rejects data that contains characters | |||
| * outside the base64 alphabet.</p></li> | |||
| * | |||
| * <p> Unless otherwise noted, passing a {@code null} argument to a | |||
| * method of this class will cause a {@link java.lang.NullPointerException | |||
| * NullPointerException} to be thrown. | |||
| * | |||
| * @author Xueming Shen | |||
| * @since 1.8 | |||
| */ | |||
| public class Base64 { | |||
| private Base64() {} | |||
| /** | |||
| * Returns a {@link Encoder} that encodes using the | |||
| * <a href="#basic">Basic</a> type base64 encoding scheme. | |||
| * | |||
| * @return A Base64 encoder. | |||
| */ | |||
| public static Encoder getEncoder() { | |||
| return Encoder.RFC4648; | |||
| } | |||
| /** | |||
| * This class implements an encoder for encoding byte data using | |||
| * the Base64 encoding scheme as specified in RFC 4648 and RFC 2045. | |||
| * | |||
| * <p> Instances of {@link Encoder} class are safe for use by | |||
| * multiple concurrent threads. | |||
| * | |||
| * <p> Unless otherwise noted, passing a {@code null} argument to | |||
| * a method of this class will cause a | |||
| * {@link java.lang.NullPointerException NullPointerException} to | |||
| * be thrown. | |||
| * | |||
| * @see Decoder | |||
| * @since 1.8 | |||
| */ | |||
| public static class Encoder { | |||
| private final byte[] newline; | |||
| private final int linemax; | |||
| private final boolean isURL; | |||
| private final boolean doPadding; | |||
| private Encoder(boolean isURL, byte[] newline, int linemax, boolean doPadding) { | |||
| this.isURL = isURL; | |||
| this.newline = newline; | |||
| this.linemax = linemax; | |||
| this.doPadding = doPadding; | |||
| } | |||
| /** | |||
| * This array is a lookup table that translates 6-bit positive integer | |||
| * index values into their "Base64 Alphabet" equivalents as specified | |||
| * in "Table 1: The Base64 Alphabet" of RFC 2045 (and RFC 4648). | |||
| */ | |||
| private static final char[] toBase64 = { | |||
| 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', | |||
| 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', | |||
| 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', | |||
| 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', | |||
| '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' | |||
| }; | |||
| /** | |||
| * It's the lookup table for "URL and Filename safe Base64" as specified | |||
| * in Table 2 of the RFC 4648, with the '+' and '/' changed to '-' and | |||
| * '_'. This table is used when BASE64_URL is specified. | |||
| */ | |||
| private static final char[] toBase64URL = { | |||
| 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', | |||
| 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', | |||
| 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', | |||
| 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', | |||
| '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' | |||
| }; | |||
| static final Encoder RFC4648 = new Encoder(false, null, -1, true); | |||
| private final int outLength(int srclen) { | |||
| int len = 0; | |||
| if (doPadding) { | |||
| len = 4 * ((srclen + 2) / 3); | |||
| } else { | |||
| int n = srclen % 3; | |||
| len = 4 * (srclen / 3) + (n == 0 ? 0 : n + 1); | |||
| } | |||
| if (linemax > 0) // line separators | |||
| len += (len - 1) / linemax * newline.length; | |||
| return len; | |||
| } | |||
| /** | |||
| * Encodes all bytes from the specified byte array into a newly-allocated | |||
| * byte array using the {@link Base64} encoding scheme. The returned byte | |||
| * array is of the length of the resulting bytes. | |||
| * | |||
| * @param src | |||
| * the byte array to encode | |||
| * @return A newly-allocated byte array containing the resulting | |||
| * encoded bytes. | |||
| */ | |||
| public byte[] encode(byte[] src) { | |||
| int len = outLength(src.length); // dst array size | |||
| byte[] dst = new byte[len]; | |||
| int ret = encode0(src, 0, src.length, dst); | |||
| if (ret != dst.length) | |||
| return Arrays.copyOf(dst, ret); | |||
| return dst; | |||
| } | |||
| /** | |||
| * Encodes all bytes from the specified byte array using the | |||
| * {@link Base64} encoding scheme, writing the resulting bytes to the | |||
| * given output byte array, starting at offset 0. | |||
| * | |||
| * <p> It is the responsibility of the invoker of this method to make | |||
| * sure the output byte array {@code dst} has enough space for encoding | |||
| * all bytes from the input byte array. No bytes will be written to the | |||
| * output byte array if the output byte array is not big enough. | |||
| * | |||
| * @param src | |||
| * the byte array to encode | |||
| * @param dst | |||
| * the output byte array | |||
| * @return The number of bytes written to the output byte array | |||
| * | |||
| * @throws IllegalArgumentException if {@code dst} does not have enough | |||
| * space for encoding all input bytes. | |||
| */ | |||
| public int encode(byte[] src, byte[] dst) { | |||
| int len = outLength(src.length); // dst array size | |||
| if (dst.length < len) | |||
| throw new IllegalArgumentException( | |||
| "Output byte array is too small for encoding all input bytes"); | |||
| return encode0(src, 0, src.length, dst); | |||
| } | |||
| /** | |||
| * Encodes the specified byte array into a String using the {@link Base64} | |||
| * encoding scheme. | |||
| * | |||
| * <p> In other words, an invocation of this method has exactly the same | |||
| * effect as invoking | |||
| * {@code new String(encode(src), StandardCharsets.ISO_8859_1)}. | |||
| * | |||
| * @param src | |||
| * the byte array to encode | |||
| * @return A String containing the resulting Base64 encoded characters | |||
| */ | |||
| @SuppressWarnings("deprecation") | |||
| public String encodeToString(byte[] src) { | |||
| byte[] encoded = encode(src); | |||
| return new String(encoded, 0, 0, encoded.length); | |||
| } | |||
| /** | |||
| * Returns an encoder instance that encodes equivalently to this one, | |||
| * but without adding any padding character at the end of the encoded | |||
| * byte data. | |||
| * | |||
| * <p> The encoding scheme of this encoder instance is unaffected by | |||
| * this invocation. The returned encoder instance should be used for | |||
| * non-padding encoding operation. | |||
| * | |||
| * @return an equivalent encoder that encodes without adding any | |||
| * padding character at the end | |||
| */ | |||
| public Encoder withoutPadding() { | |||
| if (!doPadding) | |||
| return this; | |||
| return new Encoder(isURL, newline, linemax, false); | |||
| } | |||
| private int encode0(byte[] src, int off, int end, byte[] dst) { | |||
| char[] base64 = isURL ? toBase64URL : toBase64; | |||
| int sp = off; | |||
| int slen = (end - off) / 3 * 3; | |||
| int sl = off + slen; | |||
| if (linemax > 0 && slen > linemax / 4 * 3) | |||
| slen = linemax / 4 * 3; | |||
| int dp = 0; | |||
| while (sp < sl) { | |||
| int sl0 = Math.min(sp + slen, sl); | |||
| for (int sp0 = sp, dp0 = dp ; sp0 < sl0; ) { | |||
| int bits = (src[sp0++] & 0xff) << 16 | | |||
| (src[sp0++] & 0xff) << 8 | | |||
| (src[sp0++] & 0xff); | |||
| dst[dp0++] = (byte)base64[(bits >>> 18) & 0x3f]; | |||
| dst[dp0++] = (byte)base64[(bits >>> 12) & 0x3f]; | |||
| dst[dp0++] = (byte)base64[(bits >>> 6) & 0x3f]; | |||
| dst[dp0++] = (byte)base64[bits & 0x3f]; | |||
| } | |||
| int dlen = (sl0 - sp) / 3 * 4; | |||
| dp += dlen; | |||
| sp = sl0; | |||
| if (dlen == linemax && sp < end) { | |||
| for (byte b : newline){ | |||
| dst[dp++] = b; | |||
| } | |||
| } | |||
| } | |||
| if (sp < end) { // 1 or 2 leftover bytes | |||
| int b0 = src[sp++] & 0xff; | |||
| dst[dp++] = (byte)base64[b0 >> 2]; | |||
| if (sp == end) { | |||
| dst[dp++] = (byte)base64[(b0 << 4) & 0x3f]; | |||
| if (doPadding) { | |||
| dst[dp++] = '='; | |||
| dst[dp++] = '='; | |||
| } | |||
| } else { | |||
| int b1 = src[sp++] & 0xff; | |||
| dst[dp++] = (byte)base64[(b0 << 4) & 0x3f | (b1 >> 4)]; | |||
| dst[dp++] = (byte)base64[(b1 << 2) & 0x3f]; | |||
| if (doPadding) { | |||
| dst[dp++] = '='; | |||
| } | |||
| } | |||
| } | |||
| return dp; | |||
| } | |||
| } | |||
| /** | |||
| * Returns a {@link Decoder} that decodes using the | |||
| * <a href="#basic">Basic</a> type base64 encoding scheme. | |||
| * | |||
| * @return A Base64 decoder. | |||
| */ | |||
| public static Decoder getDecoder() { | |||
| return Decoder.RFC4648; | |||
| } | |||
| /** | |||
| * This class implements a decoder for decoding byte data using the | |||
| * Base64 encoding scheme as specified in RFC 4648 and RFC 2045. | |||
| * | |||
| * <p> The Base64 padding character {@code '='} is accepted and | |||
| * interpreted as the end of the encoded byte data, but is not | |||
| * required. So if the final unit of the encoded byte data only has | |||
| * two or three Base64 characters (without the corresponding padding | |||
| * character(s) padded), they are decoded as if followed by padding | |||
| * character(s). If there is a padding character present in the | |||
| * final unit, the correct number of padding character(s) must be | |||
| * present, otherwise {@code IllegalArgumentException} ( | |||
| * {@code IOException} when reading from a Base64 stream) is thrown | |||
| * during decoding. | |||
| * | |||
| * <p> Instances of {@link Decoder} class are safe for use by | |||
| * multiple concurrent threads. | |||
| * | |||
| * <p> Unless otherwise noted, passing a {@code null} argument to | |||
| * a method of this class will cause a | |||
| * {@link java.lang.NullPointerException NullPointerException} to | |||
| * be thrown. | |||
| * | |||
| * @see Encoder | |||
| * @since 1.8 | |||
| */ | |||
| public static class Decoder { | |||
| private final boolean isURL; | |||
| private final boolean isMIME; | |||
| private Decoder(boolean isURL, boolean isMIME) { | |||
| this.isURL = isURL; | |||
| this.isMIME = isMIME; | |||
| } | |||
| /** | |||
| * Lookup table for decoding unicode characters drawn from the | |||
| * "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into | |||
| * their 6-bit positive integer equivalents. Characters that | |||
| * are not in the Base64 alphabet but fall within the bounds of | |||
| * the array are encoded to -1. | |||
| * | |||
| */ | |||
| private static final int[] fromBase64 = new int[256]; | |||
| static { | |||
| Arrays.fill(fromBase64, -1); | |||
| for (int i = 0; i < Encoder.toBase64.length; i++) | |||
| fromBase64[Encoder.toBase64[i]] = i; | |||
| fromBase64['='] = -2; | |||
| } | |||
| /** | |||
| * Lookup table for decoding "URL and Filename safe Base64 Alphabet" | |||
| * as specified in Table2 of the RFC 4648. | |||
| */ | |||
| private static final int[] fromBase64URL = new int[256]; | |||
| static { | |||
| Arrays.fill(fromBase64URL, -1); | |||
| for (int i = 0; i < Encoder.toBase64URL.length; i++) | |||
| fromBase64URL[Encoder.toBase64URL[i]] = i; | |||
| fromBase64URL['='] = -2; | |||
| } | |||
| static final Decoder RFC4648 = new Decoder(false, false); | |||
| static final Decoder RFC4648_URLSAFE = new Decoder(true, false); | |||
| static final Decoder RFC2045 = new Decoder(false, true); | |||
| /** | |||
| * Decodes all bytes from the input byte array using the {@link Base64} | |||
| * encoding scheme, writing the results into a newly-allocated output | |||
| * byte array. The returned byte array is of the length of the resulting | |||
| * bytes. | |||
| * | |||
| * @param src | |||
| * the byte array to decode | |||
| * | |||
| * @return A newly-allocated byte array containing the decoded bytes. | |||
| * | |||
| * @throws IllegalArgumentException | |||
| * if {@code src} is not in valid Base64 scheme | |||
| */ | |||
| public byte[] decode(byte[] src) { | |||
| byte[] dst = new byte[outLength(src, 0, src.length)]; | |||
| int ret = decode0(src, 0, src.length, dst); | |||
| if (ret != dst.length) { | |||
| dst = Arrays.copyOf(dst, ret); | |||
| } | |||
| return dst; | |||
| } | |||
| public byte[] decode(String src) { | |||
| return decode(src.getBytes(Charset.forName("ISO-8859-1"))); | |||
| } | |||
| /** | |||
| * Decodes all bytes from the input byte array using the {@link Base64} | |||
| * encoding scheme, writing the results into the given output byte array, | |||
| * starting at offset 0. | |||
| * | |||
| * <p> It is the responsibility of the invoker of this method to make | |||
| * sure the output byte array {@code dst} has enough space for decoding | |||
| * all bytes from the input byte array. No bytes will be be written to | |||
| * the output byte array if the output byte array is not big enough. | |||
| * | |||
| * <p> If the input byte array is not in valid Base64 encoding scheme | |||
| * then some bytes may have been written to the output byte array before | |||
| * IllegalargumentException is thrown. | |||
| * | |||
| * @param src | |||
| * the byte array to decode | |||
| * @param dst | |||
| * the output byte array | |||
| * | |||
| * @return The number of bytes written to the output byte array | |||
| * | |||
| * @throws IllegalArgumentException | |||
| * if {@code src} is not in valid Base64 scheme, or {@code dst} | |||
| * does not have enough space for decoding all input bytes. | |||
| */ | |||
| public int decode(byte[] src, byte[] dst) { | |||
| int len = outLength(src, 0, src.length); | |||
| if (dst.length < len) | |||
| throw new IllegalArgumentException( | |||
| "Output byte array is too small for decoding all input bytes"); | |||
| return decode0(src, 0, src.length, dst); | |||
| } | |||
| /** | |||
| * Decodes all bytes from the input byte buffer using the {@link Base64} | |||
| * encoding scheme, writing the results into a newly-allocated ByteBuffer. | |||
| * | |||
| * <p> Upon return, the source buffer's position will be updated to | |||
| * its limit; its limit will not have been changed. The returned | |||
| * output buffer's position will be zero and its limit will be the | |||
| * number of resulting decoded bytes | |||
| * | |||
| * <p> {@code IllegalArgumentException} is thrown if the input buffer | |||
| * is not in valid Base64 encoding scheme. The position of the input | |||
| * buffer will not be advanced in this case. | |||
| * | |||
| * @param buffer | |||
| * the ByteBuffer to decode | |||
| * | |||
| * @return A newly-allocated byte buffer containing the decoded bytes | |||
| * | |||
| * @throws IllegalArgumentException | |||
| * if {@code src} is not in valid Base64 scheme. | |||
| */ | |||
| public ByteBuffer decode(ByteBuffer buffer) { | |||
| int pos0 = buffer.position(); | |||
| try { | |||
| byte[] src; | |||
| int sp, sl; | |||
| if (buffer.hasArray()) { | |||
| src = buffer.array(); | |||
| sp = buffer.arrayOffset() + buffer.position(); | |||
| sl = buffer.arrayOffset() + buffer.limit(); | |||
| buffer.position(buffer.limit()); | |||
| } else { | |||
| src = new byte[buffer.remaining()]; | |||
| buffer.get(src); | |||
| sp = 0; | |||
| sl = src.length; | |||
| } | |||
| byte[] dst = new byte[outLength(src, sp, sl)]; | |||
| return ByteBuffer.wrap(dst, 0, decode0(src, sp, sl, dst)); | |||
| } catch (IllegalArgumentException iae) { | |||
| buffer.position(pos0); | |||
| throw iae; | |||
| } | |||
| } | |||
| private int outLength(byte[] src, int sp, int sl) { | |||
| int[] base64 = isURL ? fromBase64URL : fromBase64; | |||
| int paddings = 0; | |||
| int len = sl - sp; | |||
| if (len == 0) | |||
| return 0; | |||
| if (len < 2) { | |||
| if (isMIME && base64[0] == -1) | |||
| return 0; | |||
| throw new IllegalArgumentException( | |||
| "Input byte[] should at least have 2 bytes for base64 bytes"); | |||
| } | |||
| if (isMIME) { | |||
| // scan all bytes to fill out all non-alphabet. a performance | |||
| // trade-off of pre-scan or Arrays.copyOf | |||
| int n = 0; | |||
| while (sp < sl) { | |||
| int b = src[sp++] & 0xff; | |||
| if (b == '=') { | |||
| len -= (sl - sp + 1); | |||
| break; | |||
| } | |||
| if ((b = base64[b]) == -1) | |||
| n++; | |||
| } | |||
| len -= n; | |||
| } else { | |||
| if (src[sl - 1] == '=') { | |||
| paddings++; | |||
| if (src[sl - 2] == '=') | |||
| paddings++; | |||
| } | |||
| } | |||
| if (paddings == 0 && (len & 0x3) != 0) | |||
| paddings = 4 - (len & 0x3); | |||
| return 3 * ((len + 3) / 4) - paddings; | |||
| } | |||
| private int decode0(byte[] src, int sp, int sl, byte[] dst) { | |||
| int[] base64 = isURL ? fromBase64URL : fromBase64; | |||
| int dp = 0; | |||
| int bits = 0; | |||
| int shiftto = 18; // pos of first byte of 4-byte atom | |||
| while (sp < sl) { | |||
| int b = src[sp++] & 0xff; | |||
| if ((b = base64[b]) < 0) { | |||
| if (b == -2) { // padding byte '=' | |||
| // = shiftto==18 unnecessary padding | |||
| // x= shiftto==12 a dangling single x | |||
| // x to be handled together with non-padding case | |||
| // xx= shiftto==6&&sp==sl missing last = | |||
| // xx=y shiftto==6 last is not = | |||
| if (shiftto == 6 && (sp == sl || src[sp++] != '=') || | |||
| shiftto == 18) { | |||
| throw new IllegalArgumentException( | |||
| "Input byte array has wrong 4-byte ending unit"); | |||
| } | |||
| break; | |||
| } | |||
| if (isMIME) // skip if for rfc2045 | |||
| continue; | |||
| else | |||
| throw new IllegalArgumentException( | |||
| "Illegal base64 character " + | |||
| Integer.toString(src[sp - 1], 16)); | |||
| } | |||
| bits |= (b << shiftto); | |||
| shiftto -= 6; | |||
| if (shiftto < 0) { | |||
| dst[dp++] = (byte)(bits >> 16); | |||
| dst[dp++] = (byte)(bits >> 8); | |||
| dst[dp++] = (byte)(bits); | |||
| shiftto = 18; | |||
| bits = 0; | |||
| } | |||
| } | |||
| // reached end of byte array or hit padding '=' characters. | |||
| if (shiftto == 6) { | |||
| dst[dp++] = (byte)(bits >> 16); | |||
| } else if (shiftto == 0) { | |||
| dst[dp++] = (byte)(bits >> 16); | |||
| dst[dp++] = (byte)(bits >> 8); | |||
| } else if (shiftto == 12) { | |||
| // dangling single "x", incorrectly encoded. | |||
| throw new IllegalArgumentException( | |||
| "Last unit does not have enough valid bits"); | |||
| } | |||
| // anything left is invalid, if is not MIME. | |||
| // if MIME, ignore all non-base64 character | |||
| while (sp < sl) { | |||
| if (isMIME && base64[src[sp++]] < 0) | |||
| continue; | |||
| throw new IllegalArgumentException( | |||
| "Input byte array has incorrect ending byte at " + sp); | |||
| } | |||
| return dp; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| package com.netsdk.common; | |||
| import javax.swing.BorderFactory; | |||
| import javax.swing.JComponent; | |||
| import javax.swing.border.Border; | |||
| /* | |||
| * 边框设置 | |||
| */ | |||
| public class BorderEx { | |||
| public static void set(JComponent object, String title, int width) { | |||
| Border innerBorder = BorderFactory.createTitledBorder(title); | |||
| Border outerBorder = BorderFactory.createEmptyBorder(width, width, width, width); | |||
| object.setBorder(BorderFactory.createCompoundBorder(outerBorder, innerBorder)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,93 @@ | |||
| package com.netsdk.common; | |||
| import java.lang.reflect.Method; | |||
| import java.util.NoSuchElementException; | |||
| import java.util.Scanner; | |||
| import java.util.Vector; | |||
| public class CaseMenu { | |||
| public static class Item { | |||
| private Object object; | |||
| private String itemName; | |||
| private String methodName; | |||
| public Item(Object object, String itemName, String methodName) { | |||
| super(); | |||
| this.object = object; | |||
| this.itemName = itemName; | |||
| this.methodName = methodName; | |||
| } | |||
| public Object getObject() { | |||
| return object; | |||
| } | |||
| public String getItemName() { | |||
| return itemName; | |||
| } | |||
| public String getMethodName() { | |||
| return methodName; | |||
| } | |||
| } | |||
| private Vector<Item> items; | |||
| public CaseMenu() { | |||
| super(); | |||
| items = new Vector<Item>(); | |||
| } | |||
| public void addItem(Item item) { | |||
| items.add(item); | |||
| } | |||
| private void showItem() { | |||
| final String format = "%2d\t%-20s\n"; | |||
| int index = 0; | |||
| System.out.printf(format, index++, "exit App"); | |||
| for (Item item : items) { | |||
| System.out.printf(format, index++, item.getItemName()); | |||
| } | |||
| System.out.println("Please input a item index to invoke the method:"); | |||
| } | |||
| public void run() { | |||
| Scanner scanner = new Scanner(System.in); | |||
| while(true) { | |||
| showItem(); | |||
| try { | |||
| int input = Integer.parseInt(scanner.nextLine()); | |||
| if (input <= 0 ) { | |||
| System.err.println("input <= 0 || scanner.nextLine() == null"); | |||
| // scanner.close(); | |||
| // System.exit(0); | |||
| break; | |||
| } | |||
| if (input < 0 || input > items.size()) { | |||
| System.err.println("Input Error Item Index."); | |||
| continue; | |||
| } | |||
| Item item = items.get(input - 1); | |||
| Class<?> itemClass = item.getObject().getClass(); | |||
| Method method = itemClass.getMethod(item.getMethodName()); | |||
| method.invoke(item.getObject()); | |||
| } catch (NoSuchElementException e) { | |||
| // scanner.close(); | |||
| // System.exit(0); | |||
| break; | |||
| } catch (NumberFormatException e) { | |||
| System.err.println("Input Error NumberFormat."); | |||
| continue; | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| scanner.close(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,625 @@ | |||
| package com.netsdk.common; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Color; | |||
| import java.awt.Cursor; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.Font; | |||
| import java.awt.GridLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.MouseEvent; | |||
| import java.awt.event.MouseListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.text.ParseException; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Calendar; | |||
| import java.util.Date; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JSpinner; | |||
| import javax.swing.SpinnerNumberModel; | |||
| import javax.swing.SwingConstants; | |||
| import javax.swing.UIManager; | |||
| import javax.swing.border.LineBorder; | |||
| import javax.swing.event.ChangeEvent; | |||
| import javax.swing.event.ChangeListener; | |||
| /** | |||
| * 时间选择器, 年月日-时分秒 | |||
| */ | |||
| public class DateChooserJButton extends JButton { | |||
| private static final long serialVersionUID = 1L; | |||
| int startYear = 1980; // 默认【最小】显示年份 | |||
| int lastYear = 2050; // 默认【最大】显示年份 | |||
| private DateChooser dateChooser = null; | |||
| private String preLabel = ""; | |||
| private String originalText = null; | |||
| private SimpleDateFormat sdf = null; | |||
| private JSpinner yearSpin; | |||
| private JSpinner monthSpin; | |||
| private JSpinner daySpin; | |||
| private JSpinner hourSpin; | |||
| private JSpinner minuteSpin; | |||
| private JSpinner secondSpin; | |||
| public DateChooserJButton() { | |||
| this(getNowDate()); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| public DateChooserJButton(String dateString) { | |||
| this(); | |||
| setText(getDefaultDateFormat(), dateString); | |||
| //保存原始是日期时间 | |||
| initOriginalText(dateString); | |||
| } | |||
| public DateChooserJButton(SimpleDateFormat df, String dateString) { | |||
| this(); | |||
| setText(df, dateString); | |||
| //记忆当前的日期格式化器 | |||
| this.sdf = df; | |||
| //记忆原始日期时间 | |||
| Date originalDate = null; | |||
| try { | |||
| originalDate = df.parse(dateString); | |||
| } catch (ParseException ex) { | |||
| originalDate = getNowDate(); | |||
| } | |||
| initOriginalText(originalDate); | |||
| } | |||
| public DateChooserJButton(Date date) { | |||
| this("", date); | |||
| //记忆原始日期时间 | |||
| initOriginalText(date); | |||
| } | |||
| public DateChooserJButton(String preLabel, Date date) { | |||
| if (preLabel != null) { | |||
| this.preLabel = preLabel; | |||
| } | |||
| setDate(date); | |||
| //记忆原始是日期时间 | |||
| initOriginalText(date); | |||
| setBorder(null); | |||
| setCursor(new Cursor(Cursor.HAND_CURSOR)); | |||
| super.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if (dateChooser == null) { | |||
| dateChooser = new DateChooser(); | |||
| } | |||
| dateChooser.showDateChooser(); | |||
| } | |||
| }); | |||
| } | |||
| public DateChooserJButton(int startYear, int lastYear) { | |||
| this(); | |||
| this.startYear = startYear; | |||
| this.lastYear = lastYear; | |||
| } | |||
| private static Date getNowDate() { | |||
| return Calendar.getInstance().getTime(); | |||
| } | |||
| private static SimpleDateFormat getDefaultDateFormat() { | |||
| return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
| } | |||
| /** | |||
| * 得到当前使用的日期格式化器 | |||
| * @return 日期格式化器 | |||
| */ | |||
| public SimpleDateFormat getCurrentSimpleDateFormat(){ | |||
| if(this.sdf != null){ | |||
| return sdf; | |||
| }else{ | |||
| return getDefaultDateFormat(); | |||
| } | |||
| } | |||
| //保存原始是日期时间 | |||
| private void initOriginalText(String dateString) { | |||
| this.originalText = dateString; | |||
| } | |||
| //保存原始是日期时间 | |||
| private void initOriginalText(Date date) { | |||
| this.originalText = preLabel + getDefaultDateFormat().format(date); | |||
| } | |||
| /** | |||
| * 得到当前记忆的原始日期时间 | |||
| * @return 当前记忆的原始日期时间(未修改前的日期时间) | |||
| */ | |||
| public String getOriginalText() { | |||
| return originalText; | |||
| } | |||
| // 覆盖父类的方法 | |||
| @Override | |||
| public void setText(String s) { | |||
| Date date; | |||
| try { | |||
| date = getDefaultDateFormat().parse(s); | |||
| } catch (ParseException e) { | |||
| date = getNowDate(); | |||
| } | |||
| setDate(date); | |||
| initOriginalText(date); | |||
| } | |||
| public void setText(SimpleDateFormat df, String s) { | |||
| Date date; | |||
| try { | |||
| date = df.parse(s); | |||
| } catch (ParseException e) { | |||
| date = getNowDate(); | |||
| } | |||
| setDate(date); | |||
| initOriginalText(date); | |||
| } | |||
| public void setDate(Date date) { | |||
| super.setText(preLabel + getDefaultDateFormat().format(date)); | |||
| } | |||
| public Date getDate() { | |||
| String dateString = getText().substring(preLabel.length()); | |||
| try { | |||
| SimpleDateFormat currentSdf = getCurrentSimpleDateFormat(); | |||
| return currentSdf.parse(dateString); | |||
| } catch (ParseException e) { | |||
| return getNowDate(); | |||
| } | |||
| } | |||
| /** | |||
| * 覆盖父类的方法使之无效 | |||
| * @param listener 响应监听器 | |||
| */ | |||
| @Override | |||
| public void addActionListener(ActionListener listener) { | |||
| } | |||
| /** | |||
| * 内部类,主要是定义一个JPanel,然后把日历相关的所有内容填入本JPanel, | |||
| * 然后再创建一个JDialog,把本内部类定义的JPanel放入JDialog的内容区 | |||
| */ | |||
| private class DateChooser extends JPanel implements MouseListener, ChangeListener { | |||
| private static final long serialVersionUID = 1L; | |||
| JLabel yearLabel; | |||
| JLabel monthLabel; | |||
| JLabel dayLabel; | |||
| JLabel hourLabel; | |||
| JLabel minuteLabel; | |||
| JLabel secondLabel; | |||
| int width = 485; // 界面宽度 | |||
| int height = 230; // 界面高度 | |||
| Color backGroundColor = Color.gray; // 底色 | |||
| // 月历表格配色----------------// | |||
| Color palletTableColor = Color.white; // 日历表底色 | |||
| Color todayBackColor = Color.orange; // 今天背景色 | |||
| Color weekFontColor = Color.blue; // 星期文字色 | |||
| Color dateFontColor = Color.black; // 日期文字色 | |||
| Color weekendFontColor = Color.red; // 周末文字色 | |||
| // 控制条配色------------------// | |||
| Color controlLineColor = Color.pink; // 控制条底色 | |||
| Color controlTextColor = Color.white; // 控制条标签文字色 | |||
| /** 点击DateChooserButton时弹出的对话框,日历内容在这个对话框内 */ | |||
| JDialog dialog; | |||
| JLabel[][] daysLabels = new JLabel[6][7]; | |||
| DateChooser() { | |||
| setLayout(new BorderLayout()); | |||
| setBorder(new LineBorder(backGroundColor, 2)); | |||
| setBackground(backGroundColor); | |||
| JPanel topYearAndMonth = createYearAndMonthPanal(); | |||
| add(topYearAndMonth, BorderLayout.NORTH); | |||
| JPanel centerWeekAndDay = createWeekAndDayPanal(); | |||
| add(centerWeekAndDay, BorderLayout.CENTER); | |||
| JPanel buttonBarPanel = createButtonBarPanel(); | |||
| this.add(buttonBarPanel, java.awt.BorderLayout.SOUTH); | |||
| } | |||
| private JPanel createYearAndMonthPanal() { | |||
| Calendar c = getCalendar(); | |||
| int currentYear = c.get(Calendar.YEAR); | |||
| int currentMonth = c.get(Calendar.MONTH) + 1; | |||
| int currentDay = c.get(Calendar.DAY_OF_MONTH); | |||
| int currentHour = c.get(Calendar.HOUR_OF_DAY); | |||
| int currentMinute = c.get(Calendar.MINUTE); | |||
| int currentSecond = c.get(Calendar.SECOND); | |||
| JPanel result = new JPanel(); | |||
| result.setLayout(new FlowLayout()); | |||
| result.setBackground(controlLineColor); | |||
| yearSpin = new JSpinner(new SpinnerNumberModel(currentYear, startYear, lastYear, 1)); | |||
| yearSpin.setPreferredSize(new Dimension(48, 20)); | |||
| yearSpin.setName("Year"); | |||
| yearSpin.setEditor(new JSpinner.NumberEditor(yearSpin, "####")); | |||
| yearSpin.addChangeListener(this); | |||
| result.add(yearSpin); | |||
| yearLabel = new JLabel(Res.string().getYear()); | |||
| yearLabel.setForeground(controlTextColor); | |||
| result.add(yearLabel); | |||
| monthSpin = new JSpinner(new SpinnerNumberModel(currentMonth, 1, 12, 1)); | |||
| monthSpin.setPreferredSize(new Dimension(35, 20)); | |||
| monthSpin.setName("Month"); | |||
| monthSpin.addChangeListener(this); | |||
| result.add(monthSpin); | |||
| monthLabel = new JLabel(Res.string().getMonth()); | |||
| monthLabel.setForeground(controlTextColor); | |||
| result.add(monthLabel); | |||
| //如果这里要能够选择,会要判断很多东西,比如每个月分别由多少日,以及闰年问题.所以,就干脆把Enable设为false | |||
| daySpin = new JSpinner(new SpinnerNumberModel(currentDay, 1, 31, 1)); | |||
| daySpin.setPreferredSize(new Dimension(35, 20)); | |||
| daySpin.setName("Day"); | |||
| daySpin.addChangeListener(this); | |||
| daySpin.setEnabled(false); | |||
| result.add(daySpin); | |||
| dayLabel = new JLabel(Res.string().getDay()); | |||
| dayLabel.setForeground(controlTextColor); | |||
| result.add(dayLabel); | |||
| hourSpin = new JSpinner(new SpinnerNumberModel(currentHour, 0, 23, 1)); | |||
| hourSpin.setPreferredSize(new Dimension(35, 20)); | |||
| hourSpin.setName("Hour"); | |||
| hourSpin.addChangeListener(this); | |||
| result.add(hourSpin); | |||
| hourLabel = new JLabel(Res.string().getHour()); | |||
| hourLabel.setForeground(controlTextColor); | |||
| result.add(hourLabel); | |||
| minuteSpin = new JSpinner(new SpinnerNumberModel(currentMinute, 0, 59, 1)); | |||
| minuteSpin.setPreferredSize(new Dimension(35, 20)); | |||
| minuteSpin.setName("Minute"); | |||
| minuteSpin.addChangeListener(this); | |||
| result.add(minuteSpin); | |||
| minuteLabel = new JLabel(Res.string().getMinute()); | |||
| minuteLabel.setForeground(controlTextColor); | |||
| result.add(minuteLabel); | |||
| secondSpin = new JSpinner(new SpinnerNumberModel(currentSecond, 0, 59, 1)); | |||
| secondSpin.setPreferredSize(new Dimension(35, 20)); | |||
| secondSpin.setName("Second"); | |||
| secondSpin.addChangeListener(this); | |||
| result.add(secondSpin); | |||
| secondLabel = new JLabel(Res.string().getSecond()); | |||
| secondLabel.setForeground(controlTextColor); | |||
| result.add(secondLabel); | |||
| return result; | |||
| } | |||
| private JPanel createWeekAndDayPanal() { | |||
| Res.string().getWeek(); | |||
| JPanel result = new JPanel(); | |||
| // 设置固定字体,以免调用环境改变影响界面美观 | |||
| result.setFont(new Font("宋体", Font.PLAIN, 12)); | |||
| result.setLayout(new GridLayout(7, 7)); | |||
| result.setBackground(Color.white); | |||
| JLabel cell; | |||
| for (int i = 0; i < 7; i++) { | |||
| cell = new JLabel(Res.string().getWeek()[i]); | |||
| cell.setHorizontalAlignment(JLabel.RIGHT); | |||
| if (i == 0 || i == 6) { | |||
| cell.setForeground(weekendFontColor); | |||
| } else { | |||
| cell.setForeground(weekFontColor); | |||
| } | |||
| result.add(cell); | |||
| } | |||
| // int actionCommandId = 0; | |||
| for (int i = 0; i < 6; i++) { | |||
| for (int j = 0; j < 7; j++) { | |||
| JLabel numberLabel = new JLabel(); | |||
| numberLabel.setBorder(null); | |||
| numberLabel.setHorizontalAlignment(SwingConstants.RIGHT); | |||
| // numberLabel.setActionCommand(String.valueOf(actionCommandId)); | |||
| numberLabel.addMouseListener(this); | |||
| numberLabel.setBackground(palletTableColor); | |||
| numberLabel.setForeground(dateFontColor); | |||
| if (j == 0 || j == 6) { | |||
| numberLabel.setForeground(weekendFontColor); | |||
| } else { | |||
| numberLabel.setForeground(dateFontColor); | |||
| } | |||
| daysLabels[i][j] = numberLabel; | |||
| result.add(numberLabel); | |||
| // actionCommandId++; | |||
| } | |||
| } | |||
| return result; | |||
| } | |||
| /** 得到DateChooserButton的当前text,本方法是为按钮事件匿名类准备的。 */ | |||
| public String getTextOfDateChooserButton() { | |||
| return getText(); | |||
| } | |||
| /** 恢复DateChooserButton的原始日期时间text,本方法是为按钮事件匿名类准备的。 */ | |||
| public void restoreTheOriginalDate() { | |||
| String originalText = getOriginalText(); | |||
| setText(originalText); | |||
| } | |||
| private JPanel createButtonBarPanel() { | |||
| JPanel panel = new JPanel(); | |||
| panel.setLayout(new java.awt.GridLayout(1, 2)); | |||
| JButton ok = new JButton(Res.string().getConfirm()); | |||
| ok.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| //记忆原始日期时间 | |||
| initOriginalText(getTextOfDateChooserButton()); | |||
| //隐藏日历对话框 | |||
| dialog.setVisible(false); | |||
| } | |||
| }); | |||
| panel.add(ok); | |||
| JButton cancel = new JButton(Res.string().getCancel()); | |||
| cancel.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| //恢复原始的日期时间 | |||
| restoreTheOriginalDate(); | |||
| //隐藏日历对话框 | |||
| dialog.setVisible(false); | |||
| } | |||
| }); | |||
| panel.add(cancel); | |||
| return panel; | |||
| } | |||
| private JDialog createDialog() { | |||
| JDialog result = new JDialog(); | |||
| result.setTitle(Res.string().getDateChooser()); | |||
| result.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); | |||
| result.getContentPane().add(this, BorderLayout.CENTER); | |||
| result.pack(); | |||
| result.setSize(width, height); | |||
| result.setModal(true); | |||
| result.addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| //恢复原始的日期时间 | |||
| restoreTheOriginalDate(); | |||
| //隐藏日历对话框 | |||
| dialog.setVisible(false); | |||
| } | |||
| }); | |||
| return result; | |||
| } | |||
| void showDateChooser() { | |||
| if (dialog == null) { | |||
| dialog = createDialog(); | |||
| } | |||
| dialog.setLocationRelativeTo(null); | |||
| flushWeekAndDay(); | |||
| dialog.setVisible(true); | |||
| } | |||
| private Calendar getCalendar() { | |||
| Calendar result = Calendar.getInstance(); | |||
| result.setTime(getDate()); | |||
| return result; | |||
| } | |||
| private int getSelectedYear() { | |||
| return ((Integer) yearSpin.getValue()).intValue(); | |||
| } | |||
| private int getSelectedMonth() { | |||
| return ((Integer) monthSpin.getValue()).intValue(); | |||
| } | |||
| private int getSelectedHour() { | |||
| return ((Integer) hourSpin.getValue()).intValue(); | |||
| } | |||
| private int getSelectedMinite() { | |||
| return ((Integer) minuteSpin.getValue()).intValue(); | |||
| } | |||
| private int getSelectedSecond() { | |||
| return ((Integer) secondSpin.getValue()).intValue(); | |||
| } | |||
| private void dayColorUpdate(boolean isOldDay) { | |||
| Calendar c = getCalendar(); | |||
| int day = c.get(Calendar.DAY_OF_MONTH); | |||
| c.set(Calendar.DAY_OF_MONTH, 1); | |||
| int actionCommandId = day - 2 + c.get(Calendar.DAY_OF_WEEK); | |||
| int i = actionCommandId / 7; | |||
| int j = actionCommandId % 7; | |||
| if (isOldDay) { | |||
| daysLabels[i][j].setForeground(dateFontColor); | |||
| } else { | |||
| daysLabels[i][j].setForeground(todayBackColor); | |||
| } | |||
| } | |||
| private void flushWeekAndDay() { | |||
| Calendar c = getCalendar(); | |||
| c.set(Calendar.DAY_OF_MONTH, 1); | |||
| int maxDayNo = c.getActualMaximum(Calendar.DAY_OF_MONTH); | |||
| int dayNo = 2 - c.get(Calendar.DAY_OF_WEEK); | |||
| for (int i = 0; i < 6; i++) { | |||
| for (int j = 0; j < 7; j++) { | |||
| String s = ""; | |||
| if (dayNo >= 1 && dayNo <= maxDayNo) { | |||
| s = String.valueOf(dayNo); | |||
| } | |||
| daysLabels[i][j].setText(s); | |||
| dayNo++; | |||
| } | |||
| } | |||
| // 打开日历时,根据按钮的时间,设置日历的时间 | |||
| String[] date1 = getText().split(" ")[0].split("-"); | |||
| String[] date2 = getText().split(" ")[1].split(":"); | |||
| yearSpin.setValue(new Integer(date1[0])); | |||
| monthSpin.setValue(new Integer(date1[1])); | |||
| daySpin.setValue(new Integer(date1[2])); | |||
| hourSpin.setValue(new Integer(date2[0])); | |||
| minuteSpin.setValue(new Integer(date2[1])); | |||
| secondSpin.setValue(new Integer(date2[2])); | |||
| // 重置日历天的数字颜色 | |||
| for(int i = 0; i < 6; i++) { | |||
| for(int j = 0; j < 7; j++) { | |||
| if(!daysLabels[i][j].getText().equals("")) { | |||
| daysLabels[i][j].setForeground(Color.BLACK); | |||
| } | |||
| } | |||
| } | |||
| // 重置日历星期六、星期日的数字颜色 | |||
| for(int i = 0; i < 6; i++) { | |||
| if(!daysLabels[i][0].getText().equals("")) { | |||
| daysLabels[i][0].setForeground(weekendFontColor); | |||
| } | |||
| if(!daysLabels[i][6].getText().equals("")) { | |||
| daysLabels[i][6].setForeground(weekendFontColor); | |||
| } | |||
| } | |||
| // 设置当天的数字颜色 | |||
| for(int i = 0; i < 6; i++) { | |||
| for(int j = 0; j < 7; j++) { | |||
| if(daysLabels[i][j].getText().equals(date1[2])) { | |||
| daysLabels[i][j].setForeground(todayBackColor); | |||
| } | |||
| } | |||
| } | |||
| dayColorUpdate(false); | |||
| } | |||
| /** | |||
| * 选择日期时的响应事件 | |||
| */ | |||
| @Override | |||
| public void stateChanged(ChangeEvent e) { | |||
| JSpinner source = (JSpinner) e.getSource(); | |||
| Calendar c = getCalendar(); | |||
| if (source.getName().equals("Hour")) { | |||
| c.set(Calendar.HOUR_OF_DAY, getSelectedHour()); | |||
| setDate(c.getTime()); | |||
| return; | |||
| } | |||
| if (source.getName().equals("Minute")) { | |||
| c.set(Calendar.MINUTE, getSelectedMinite()); | |||
| setDate(c.getTime()); | |||
| return; | |||
| } | |||
| if (source.getName().equals("Second")) { | |||
| c.set(Calendar.SECOND, getSelectedSecond()); | |||
| setDate(c.getTime()); | |||
| return; | |||
| } | |||
| dayColorUpdate(true); | |||
| if (source.getName().equals("Year")) { | |||
| c.set(Calendar.YEAR, getSelectedYear()); | |||
| } else if (source.getName().equals("Month")) { | |||
| c.set(Calendar.MONTH, getSelectedMonth() - 1); | |||
| } | |||
| setDate(c.getTime()); | |||
| flushWeekAndDay(); | |||
| } | |||
| /** | |||
| * 选择日期时的响应事件 | |||
| */ | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| JLabel source = (JLabel) e.getSource(); | |||
| if (source.getText().length() == 0) { | |||
| return; | |||
| } | |||
| dayColorUpdate(true); | |||
| source.setForeground(todayBackColor); | |||
| int newDay = Integer.parseInt(source.getText()); | |||
| Calendar c = getCalendar(); | |||
| c.set(Calendar.DAY_OF_MONTH, newDay); | |||
| setDate(c.getTime()); | |||
| //把daySpin中的值也变了 | |||
| daySpin.setValue(Integer.valueOf(newDay)); | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent arg0) { | |||
| // TODO Auto-generated method stub | |||
| } | |||
| @Override | |||
| public void mouseExited(MouseEvent arg0) { | |||
| // TODO Auto-generated method stub | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent arg0) { | |||
| // TODO Auto-generated method stub | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent arg0) { | |||
| // TODO Auto-generated method stub | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,587 @@ | |||
| package com.netsdk.common; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Color; | |||
| import java.awt.Cursor; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.Font; | |||
| import java.awt.GridLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.MouseEvent; | |||
| import java.awt.event.MouseListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.text.ParseException; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Calendar; | |||
| import java.util.Date; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JSpinner; | |||
| import javax.swing.SpinnerNumberModel; | |||
| import javax.swing.SwingConstants; | |||
| import javax.swing.UIManager; | |||
| import javax.swing.border.LineBorder; | |||
| import javax.swing.event.ChangeEvent; | |||
| import javax.swing.event.ChangeListener; | |||
| /** | |||
| * 时间选择器, 年月日 | |||
| */ | |||
| public class DateChooserJButtonEx extends JButton { | |||
| private static final long serialVersionUID = 1L; | |||
| int startYear = 1980; // 默认【最小】显示年份 | |||
| int lastYear = 2050; // 默认【最大】显示年份 | |||
| private DateChooser dateChooser = null; | |||
| private String preLabel = ""; | |||
| private String originalText = null; | |||
| private SimpleDateFormat sdf = null; | |||
| private JSpinner yearSpin; | |||
| private JSpinner monthSpin; | |||
| private JSpinner daySpin; | |||
| private JSpinner hourSpin; | |||
| private JSpinner minuteSpin; | |||
| private JSpinner secondSpin; | |||
| public DateChooserJButtonEx() { | |||
| this(getNowDate()); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| public DateChooserJButtonEx(String dateString) { | |||
| this(); | |||
| setText(getDefaultDateFormat(), dateString); | |||
| //保存原始是日期时间 | |||
| initOriginalText(dateString); | |||
| } | |||
| public DateChooserJButtonEx(SimpleDateFormat df, String dateString) { | |||
| this(); | |||
| setText(df, dateString); | |||
| //记忆当前的日期格式化器 | |||
| this.sdf = df; | |||
| //记忆原始日期时间 | |||
| Date originalDate = null; | |||
| try { | |||
| originalDate = df.parse(dateString); | |||
| } catch (ParseException ex) { | |||
| originalDate = getNowDate(); | |||
| } | |||
| initOriginalText(originalDate); | |||
| } | |||
| public DateChooserJButtonEx(Date date) { | |||
| this("", date); | |||
| //记忆原始日期时间 | |||
| initOriginalText(date); | |||
| } | |||
| public DateChooserJButtonEx(String preLabel, Date date) { | |||
| if (preLabel != null) { | |||
| this.preLabel = preLabel; | |||
| } | |||
| setDate(date); | |||
| //记忆原始是日期时间 | |||
| initOriginalText(date); | |||
| setBorder(null); | |||
| setCursor(new Cursor(Cursor.HAND_CURSOR)); | |||
| super.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if (dateChooser == null) { | |||
| dateChooser = new DateChooser(); | |||
| } | |||
| dateChooser.showDateChooser(); | |||
| } | |||
| }); | |||
| } | |||
| public void setStartYear(int startYear) { | |||
| this.startYear = startYear; | |||
| } | |||
| public void setLastYear(int lastYear) { | |||
| this.lastYear = lastYear; | |||
| } | |||
| private static Date getNowDate() { | |||
| return Calendar.getInstance().getTime(); | |||
| } | |||
| private static SimpleDateFormat getDefaultDateFormat() { | |||
| return new SimpleDateFormat("yyyy-MM-dd"); | |||
| } | |||
| /** | |||
| * 得到当前使用的日期格式化器 | |||
| * @return 日期格式化器 | |||
| */ | |||
| public SimpleDateFormat getCurrentSimpleDateFormat(){ | |||
| if(this.sdf != null){ | |||
| return sdf; | |||
| }else{ | |||
| return getDefaultDateFormat(); | |||
| } | |||
| } | |||
| //保存原始是日期时间 | |||
| private void initOriginalText(String dateString) { | |||
| this.originalText = dateString; | |||
| } | |||
| //保存原始是日期时间 | |||
| private void initOriginalText(Date date) { | |||
| this.originalText = preLabel + getDefaultDateFormat().format(date); | |||
| } | |||
| /** | |||
| * 得到当前记忆的原始日期时间 | |||
| * @return 当前记忆的原始日期时间(未修改前的日期时间) | |||
| */ | |||
| public String getOriginalText() { | |||
| return originalText; | |||
| } | |||
| // 覆盖父类的方法 | |||
| @Override | |||
| public void setText(String s) { | |||
| Date date; | |||
| try { | |||
| date = getDefaultDateFormat().parse(s); | |||
| } catch (ParseException e) { | |||
| date = getNowDate(); | |||
| } | |||
| setDate(date); | |||
| initOriginalText(date); | |||
| } | |||
| public void setText(SimpleDateFormat df, String s) { | |||
| Date date; | |||
| try { | |||
| date = df.parse(s); | |||
| } catch (ParseException e) { | |||
| date = getNowDate(); | |||
| } | |||
| setDate(date); | |||
| initOriginalText(date); | |||
| } | |||
| public void setDate(Date date) { | |||
| super.setText(preLabel + getDefaultDateFormat().format(date)); | |||
| } | |||
| public Date getDate() { | |||
| String dateString = getText().substring(preLabel.length()); | |||
| try { | |||
| SimpleDateFormat currentSdf = getCurrentSimpleDateFormat(); | |||
| return currentSdf.parse(dateString); | |||
| } catch (ParseException e) { | |||
| return getNowDate(); | |||
| } | |||
| } | |||
| /** | |||
| * 覆盖父类的方法使之无效 | |||
| * @param listener 响应监听器 | |||
| */ | |||
| @Override | |||
| public void addActionListener(ActionListener listener) { | |||
| } | |||
| /** | |||
| * 内部类,主要是定义一个JPanel,然后把日历相关的所有内容填入本JPanel, | |||
| * 然后再创建一个JDialog,把本内部类定义的JPanel放入JDialog的内容区 | |||
| */ | |||
| private class DateChooser extends JPanel implements MouseListener, ChangeListener { | |||
| private static final long serialVersionUID = 1L; | |||
| JLabel yearLabel; | |||
| JLabel monthLabel; | |||
| JLabel dayLabel; | |||
| int width = 485; // 界面宽度 | |||
| int height = 230; // 界面高度 | |||
| Color backGroundColor = Color.gray; // 底色 | |||
| // 月历表格配色----------------// | |||
| Color palletTableColor = Color.white; // 日历表底色 | |||
| Color todayBackColor = Color.orange; // 今天背景色 | |||
| Color weekFontColor = Color.blue; // 星期文字色 | |||
| Color dateFontColor = Color.black; // 日期文字色 | |||
| Color weekendFontColor = Color.red; // 周末文字色 | |||
| // 控制条配色------------------// | |||
| Color controlLineColor = Color.pink; // 控制条底色 | |||
| Color controlTextColor = Color.white; // 控制条标签文字色 | |||
| /** 点击DateChooserButton时弹出的对话框,日历内容在这个对话框内 */ | |||
| JDialog dialog; | |||
| JLabel[][] daysLabels = new JLabel[6][7]; | |||
| DateChooser() { | |||
| setLayout(new BorderLayout()); | |||
| setBorder(new LineBorder(backGroundColor, 2)); | |||
| setBackground(backGroundColor); | |||
| JPanel topYearAndMonth = createYearAndMonthPanal(); | |||
| add(topYearAndMonth, BorderLayout.NORTH); | |||
| JPanel centerWeekAndDay = createWeekAndDayPanal(); | |||
| add(centerWeekAndDay, BorderLayout.CENTER); | |||
| JPanel buttonBarPanel = createButtonBarPanel(); | |||
| this.add(buttonBarPanel, java.awt.BorderLayout.SOUTH); | |||
| } | |||
| private JPanel createYearAndMonthPanal() { | |||
| Calendar c = getCalendar(); | |||
| int currentYear = c.get(Calendar.YEAR); | |||
| int currentMonth = c.get(Calendar.MONTH) + 1; | |||
| int currentDay = c.get(Calendar.DAY_OF_MONTH); | |||
| JPanel result = new JPanel(); | |||
| result.setLayout(new FlowLayout()); | |||
| result.setBackground(controlLineColor); | |||
| yearSpin = new JSpinner(new SpinnerNumberModel(currentYear, startYear, lastYear, 1)); | |||
| yearSpin.setPreferredSize(new Dimension(48, 20)); | |||
| yearSpin.setName("Year"); | |||
| yearSpin.setEditor(new JSpinner.NumberEditor(yearSpin, "####")); | |||
| yearSpin.addChangeListener(this); | |||
| result.add(yearSpin); | |||
| yearLabel = new JLabel(Res.string().getYear()); | |||
| yearLabel.setForeground(controlTextColor); | |||
| result.add(yearLabel); | |||
| monthSpin = new JSpinner(new SpinnerNumberModel(currentMonth, 1, 12, 1)); | |||
| monthSpin.setPreferredSize(new Dimension(35, 20)); | |||
| monthSpin.setName("Month"); | |||
| monthSpin.addChangeListener(this); | |||
| result.add(monthSpin); | |||
| monthLabel = new JLabel(Res.string().getMonth()); | |||
| monthLabel.setForeground(controlTextColor); | |||
| result.add(monthLabel); | |||
| //如果这里要能够选择,会要判断很多东西,比如每个月分别由多少日,以及闰年问题.所以,就干脆把Enable设为false | |||
| daySpin = new JSpinner(new SpinnerNumberModel(currentDay, 1, 31, 1)); | |||
| daySpin.setPreferredSize(new Dimension(35, 20)); | |||
| daySpin.setName("Day"); | |||
| daySpin.addChangeListener(this); | |||
| daySpin.setEnabled(false); | |||
| result.add(daySpin); | |||
| dayLabel = new JLabel(Res.string().getDay()); | |||
| dayLabel.setForeground(controlTextColor); | |||
| result.add(dayLabel); | |||
| return result; | |||
| } | |||
| private JPanel createWeekAndDayPanal() { | |||
| Res.string().getWeek(); | |||
| JPanel result = new JPanel(); | |||
| // 设置固定字体,以免调用环境改变影响界面美观 | |||
| result.setFont(new Font("宋体", Font.PLAIN, 12)); | |||
| result.setLayout(new GridLayout(7, 7)); | |||
| result.setBackground(Color.white); | |||
| JLabel cell; | |||
| for (int i = 0; i < 7; i++) { | |||
| cell = new JLabel(Res.string().getWeek()[i]); | |||
| cell.setHorizontalAlignment(JLabel.RIGHT); | |||
| if (i == 0 || i == 6) { | |||
| cell.setForeground(weekendFontColor); | |||
| } else { | |||
| cell.setForeground(weekFontColor); | |||
| } | |||
| result.add(cell); | |||
| } | |||
| // int actionCommandId = 0; | |||
| for (int i = 0; i < 6; i++) { | |||
| for (int j = 0; j < 7; j++) { | |||
| JLabel numberLabel = new JLabel(); | |||
| numberLabel.setBorder(null); | |||
| numberLabel.setHorizontalAlignment(SwingConstants.RIGHT); | |||
| // numberLabel.setActionCommand(String.valueOf(actionCommandId)); | |||
| numberLabel.addMouseListener(this); | |||
| numberLabel.setBackground(palletTableColor); | |||
| numberLabel.setForeground(dateFontColor); | |||
| if (j == 0 || j == 6) { | |||
| numberLabel.setForeground(weekendFontColor); | |||
| } else { | |||
| numberLabel.setForeground(dateFontColor); | |||
| } | |||
| daysLabels[i][j] = numberLabel; | |||
| result.add(numberLabel); | |||
| // actionCommandId++; | |||
| } | |||
| } | |||
| return result; | |||
| } | |||
| /** 得到DateChooserButton的当前text,本方法是为按钮事件匿名类准备的。 */ | |||
| public String getTextOfDateChooserButton() { | |||
| return getText(); | |||
| } | |||
| /** 恢复DateChooserButton的原始日期时间text,本方法是为按钮事件匿名类准备的。 */ | |||
| public void restoreTheOriginalDate() { | |||
| String originalText = getOriginalText(); | |||
| setText(originalText); | |||
| } | |||
| private JPanel createButtonBarPanel() { | |||
| JPanel panel = new JPanel(); | |||
| panel.setLayout(new java.awt.GridLayout(1, 2)); | |||
| JButton ok = new JButton(Res.string().getConfirm()); | |||
| ok.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| //记忆原始日期时间 | |||
| initOriginalText(getTextOfDateChooserButton()); | |||
| //隐藏日历对话框 | |||
| dialog.setVisible(false); | |||
| } | |||
| }); | |||
| panel.add(ok); | |||
| JButton cancel = new JButton(Res.string().getCancel()); | |||
| cancel.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| //恢复原始的日期时间 | |||
| restoreTheOriginalDate(); | |||
| //隐藏日历对话框 | |||
| dialog.setVisible(false); | |||
| } | |||
| }); | |||
| panel.add(cancel); | |||
| return panel; | |||
| } | |||
| private JDialog createDialog() { | |||
| JDialog result = new JDialog(); | |||
| result.setTitle(Res.string().getDateChooser()); | |||
| result.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); | |||
| result.getContentPane().add(this, BorderLayout.CENTER); | |||
| result.pack(); | |||
| result.setSize(width, height); | |||
| result.setModal(true); | |||
| result.addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| //恢复原始的日期时间 | |||
| restoreTheOriginalDate(); | |||
| //隐藏日历对话框 | |||
| dialog.setVisible(false); | |||
| } | |||
| }); | |||
| return result; | |||
| } | |||
| void showDateChooser() { | |||
| if (dialog == null) { | |||
| dialog = createDialog(); | |||
| } | |||
| dialog.setLocationRelativeTo(null); | |||
| flushWeekAndDay(); | |||
| dialog.setVisible(true); | |||
| } | |||
| private Calendar getCalendar() { | |||
| Calendar result = Calendar.getInstance(); | |||
| result.setTime(getDate()); | |||
| return result; | |||
| } | |||
| private int getSelectedYear() { | |||
| return ((Integer) yearSpin.getValue()).intValue(); | |||
| } | |||
| private int getSelectedMonth() { | |||
| return ((Integer) monthSpin.getValue()).intValue(); | |||
| } | |||
| private int getSelectedHour() { | |||
| return ((Integer) hourSpin.getValue()).intValue(); | |||
| } | |||
| private int getSelectedMinite() { | |||
| return ((Integer) minuteSpin.getValue()).intValue(); | |||
| } | |||
| private int getSelectedSecond() { | |||
| return ((Integer) secondSpin.getValue()).intValue(); | |||
| } | |||
| private void dayColorUpdate(boolean isOldDay) { | |||
| Calendar c = getCalendar(); | |||
| int day = c.get(Calendar.DAY_OF_MONTH); | |||
| c.set(Calendar.DAY_OF_MONTH, 1); | |||
| int actionCommandId = day - 2 + c.get(Calendar.DAY_OF_WEEK); | |||
| int i = actionCommandId / 7; | |||
| int j = actionCommandId % 7; | |||
| if (isOldDay) { | |||
| daysLabels[i][j].setForeground(dateFontColor); | |||
| } else { | |||
| daysLabels[i][j].setForeground(todayBackColor); | |||
| } | |||
| } | |||
| private void flushWeekAndDay() { | |||
| Calendar c = getCalendar(); | |||
| c.set(Calendar.DAY_OF_MONTH, 1); | |||
| int maxDayNo = c.getActualMaximum(Calendar.DAY_OF_MONTH); | |||
| int dayNo = 2 - c.get(Calendar.DAY_OF_WEEK); | |||
| for (int i = 0; i < 6; i++) { | |||
| for (int j = 0; j < 7; j++) { | |||
| String s = ""; | |||
| if (dayNo >= 1 && dayNo <= maxDayNo) { | |||
| s = String.valueOf(dayNo); | |||
| } | |||
| daysLabels[i][j].setText(s); | |||
| dayNo++; | |||
| } | |||
| } | |||
| // 打开日历时,根据按钮的时间,设置日历的时间 | |||
| String[] date1 = getText().split(" ")[0].split("-"); | |||
| yearSpin.setValue(new Integer(date1[0])); | |||
| monthSpin.setValue(new Integer(date1[1])); | |||
| daySpin.setValue(new Integer(date1[2])); | |||
| // 重置日历天的数字颜色 | |||
| for(int i = 0; i < 6; i++) { | |||
| for(int j = 0; j < 7; j++) { | |||
| if(!daysLabels[i][j].getText().equals("")) { | |||
| daysLabels[i][j].setForeground(Color.BLACK); | |||
| } | |||
| } | |||
| } | |||
| // 重置日历星期六、星期日的数字颜色 | |||
| for(int i = 0; i < 6; i++) { | |||
| if(!daysLabels[i][0].getText().equals("")) { | |||
| daysLabels[i][0].setForeground(weekendFontColor); | |||
| } | |||
| if(!daysLabels[i][6].getText().equals("")) { | |||
| daysLabels[i][6].setForeground(weekendFontColor); | |||
| } | |||
| } | |||
| // 设置当天的数字颜色 | |||
| for(int i = 0; i < 6; i++) { | |||
| for(int j = 0; j < 7; j++) { | |||
| if(daysLabels[i][j].getText().equals(date1[2])) { | |||
| daysLabels[i][j].setForeground(todayBackColor); | |||
| } | |||
| } | |||
| } | |||
| dayColorUpdate(false); | |||
| } | |||
| /** | |||
| * 选择日期时的响应事件 | |||
| */ | |||
| @Override | |||
| public void stateChanged(ChangeEvent e) { | |||
| JSpinner source = (JSpinner) e.getSource(); | |||
| Calendar c = getCalendar(); | |||
| if (source.getName().equals("Hour")) { | |||
| c.set(Calendar.HOUR_OF_DAY, getSelectedHour()); | |||
| setDate(c.getTime()); | |||
| return; | |||
| } | |||
| if (source.getName().equals("Minute")) { | |||
| c.set(Calendar.MINUTE, getSelectedMinite()); | |||
| setDate(c.getTime()); | |||
| return; | |||
| } | |||
| if (source.getName().equals("Second")) { | |||
| c.set(Calendar.SECOND, getSelectedSecond()); | |||
| setDate(c.getTime()); | |||
| return; | |||
| } | |||
| dayColorUpdate(true); | |||
| if (source.getName().equals("Year")) { | |||
| c.set(Calendar.YEAR, getSelectedYear()); | |||
| } else if (source.getName().equals("Month")) { | |||
| c.set(Calendar.MONTH, getSelectedMonth() - 1); | |||
| } | |||
| setDate(c.getTime()); | |||
| flushWeekAndDay(); | |||
| } | |||
| /** | |||
| * 选择日期时的响应事件 | |||
| */ | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| JLabel source = (JLabel) e.getSource(); | |||
| if (source.getText().length() == 0) { | |||
| return; | |||
| } | |||
| dayColorUpdate(true); | |||
| source.setForeground(todayBackColor); | |||
| int newDay = Integer.parseInt(source.getText()); | |||
| Calendar c = getCalendar(); | |||
| c.set(Calendar.DAY_OF_MONTH, newDay); | |||
| setDate(c.getTime()); | |||
| //把daySpin中的值也变了 | |||
| daySpin.setValue(Integer.valueOf(newDay)); | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent arg0) { | |||
| // TODO Auto-generated method stub | |||
| } | |||
| @Override | |||
| public void mouseExited(MouseEvent arg0) { | |||
| // TODO Auto-generated method stub | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent arg0) { | |||
| // TODO Auto-generated method stub | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent arg0) { | |||
| // TODO Auto-generated method stub | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,5 @@ | |||
| package com.netsdk.common; | |||
| public interface DeviceManagerListener { | |||
| void onDeviceManager(String deviceId, String username, String password); | |||
| } | |||
| @@ -0,0 +1,872 @@ | |||
| package com.netsdk.common; | |||
| import com.netsdk.lib.LastError; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| /** | |||
| * 登录设备设备错误状态 | |||
| */ | |||
| public class ErrorCode { | |||
| /** | |||
| * 登录设备设备错误状态中英文 | |||
| * @param err 接口CLIENT_GetLastError返回, error code: (0x80000000|" + (LoginModule.netsdk.CLIENT_GetLastError() & 0x7fffffff) +") | |||
| * @return | |||
| */ | |||
| public static String getErrorCode(int err) { | |||
| String msg = ""; | |||
| switch(err) { | |||
| case LastError.NET_NOERROR: // 0 没有错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR"); | |||
| break; | |||
| case LastError.NET_ERROR: // -1 未知错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR"); | |||
| break; | |||
| case LastError.NET_SYSTEM_ERROR: // (0x80000000|1) Windows系统出错 | |||
| msg = Res.string().getBundle().getString("NET_SYSTEM_ERROR"); | |||
| break; | |||
| case LastError.NET_NETWORK_ERROR: // (0x80000000|2) 网络错误,可能是因为网络超时 | |||
| msg = Res.string().getBundle().getString("NET_NETWORK_ERROR"); | |||
| break; | |||
| case LastError.NET_DEV_VER_NOMATCH: // (0x80000000|3) 设备协议不匹配 | |||
| msg = Res.string().getBundle().getString("NET_DEV_VER_NOMATCH"); | |||
| break; | |||
| case LastError.NET_INVALID_HANDLE: // (0x80000000|4) 句柄无效 | |||
| msg = Res.string().getBundle().getString("NET_INVALID_HANDLE"); | |||
| break; | |||
| case LastError.NET_OPEN_CHANNEL_ERROR: // (0x80000000|5) 打开通道失败 | |||
| msg = Res.string().getBundle().getString("NET_OPEN_CHANNEL_ERROR"); | |||
| break; | |||
| case LastError.NET_CLOSE_CHANNEL_ERROR: // (0x80000000|6) 关闭通道失败 | |||
| msg = Res.string().getBundle().getString("NET_CLOSE_CHANNEL_ERROR"); | |||
| break; | |||
| case LastError.NET_ILLEGAL_PARAM: // (0x80000000|7) 用户参数不合法 | |||
| msg = Res.string().getBundle().getString("NET_ILLEGAL_PARAM"); | |||
| break; | |||
| case LastError.NET_SDK_INIT_ERROR: // (0x80000000|8) SDK初始化出错 | |||
| msg = Res.string().getBundle().getString("NET_SDK_INIT_ERROR"); | |||
| break; | |||
| case LastError.NET_SDK_UNINIT_ERROR: // (0x80000000|9) SDK清理出错 | |||
| msg = Res.string().getBundle().getString("NET_SDK_UNINIT_ERROR"); | |||
| break; | |||
| case LastError.NET_RENDER_OPEN_ERROR: // (0x80000000|10) 申请render资源出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_OPEN_ERROR"); | |||
| break; | |||
| case LastError.NET_DEC_OPEN_ERROR: // (0x80000000|11) 打开解码库出错 | |||
| msg = Res.string().getBundle().getString("NET_DEC_OPEN_ERROR"); | |||
| break; | |||
| case LastError.NET_DEC_CLOSE_ERROR: // (0x80000000|12) 关闭解码库出错 | |||
| msg = Res.string().getBundle().getString("NET_DEC_CLOSE_ERROR"); | |||
| break; | |||
| case LastError.NET_MULTIPLAY_NOCHANNEL: // (0x80000000|13) 多画面预览中检测到通道数为0 | |||
| msg = Res.string().getBundle().getString("NET_MULTIPLAY_NOCHANNEL"); | |||
| break; | |||
| case LastError.NET_TALK_INIT_ERROR: // (0x80000000|14) 录音库初始化失败 | |||
| msg = Res.string().getBundle().getString("NET_TALK_INIT_ERROR"); | |||
| break; | |||
| case LastError.NET_TALK_NOT_INIT: // (0x80000000|15) 录音库未经初始化 | |||
| msg = Res.string().getBundle().getString("NET_TALK_NOT_INIT"); | |||
| break; | |||
| case LastError.NET_TALK_SENDDATA_ERROR: // (0x80000000|16) 发送音频数据出错 | |||
| msg = Res.string().getBundle().getString("NET_TALK_SENDDATA_ERROR"); | |||
| break; | |||
| case LastError.NET_REAL_ALREADY_SAVING: // (0x80000000|17) 实时数据已经处于保存状态 | |||
| msg = Res.string().getBundle().getString("NET_REAL_ALREADY_SAVING"); | |||
| break; | |||
| case LastError.NET_NOT_SAVING: // (0x80000000|18) 未保存实时数据 | |||
| msg = Res.string().getBundle().getString("NET_NOT_SAVING"); | |||
| break; | |||
| case LastError.NET_OPEN_FILE_ERROR: // (0x80000000|19) 打开文件出错 | |||
| msg = Res.string().getBundle().getString("NET_OPEN_FILE_ERROR"); | |||
| break; | |||
| case LastError.NET_PTZ_SET_TIMER_ERROR: // (0x80000000|20) 启动云台控制定时器失败 | |||
| msg = Res.string().getBundle().getString("NET_PTZ_SET_TIMER_ERROR"); | |||
| break; | |||
| case LastError.NET_RETURN_DATA_ERROR: // (0x80000000|21) 对返回数据的校验出错 | |||
| msg = Res.string().getBundle().getString("NET_RETURN_DATA_ERROR"); | |||
| break; | |||
| case LastError.NET_INSUFFICIENT_BUFFER: // (0x80000000|22) 没有足够的缓存 | |||
| msg = Res.string().getBundle().getString("NET_INSUFFICIENT_BUFFER"); | |||
| break; | |||
| case LastError.NET_NOT_SUPPORTED: // (0x80000000|23) 当前SDK未支持该功能 | |||
| msg = Res.string().getBundle().getString("NET_NOT_SUPPORTED"); | |||
| break; | |||
| case LastError.NET_NO_RECORD_FOUND: // (0x80000000|24) 查询不到录像 | |||
| msg = Res.string().getBundle().getString("NET_NO_RECORD_FOUND"); | |||
| break; | |||
| case LastError.NET_NOT_AUTHORIZED: // (0x80000000|25) 无操作权限 | |||
| msg = Res.string().getBundle().getString("NET_NOT_AUTHORIZED"); | |||
| break; | |||
| case LastError.NET_NOT_NOW: // (0x80000000|26) 暂时无法执行 | |||
| msg = Res.string().getBundle().getString("NET_NOT_NOW"); | |||
| break; | |||
| case LastError.NET_NO_TALK_CHANNEL: // (0x80000000|27) 未发现对讲通道 | |||
| msg = Res.string().getBundle().getString("NET_NO_TALK_CHANNEL"); | |||
| break; | |||
| case LastError.NET_NO_AUDIO: // (0x80000000|28) 未发现音频 | |||
| msg = Res.string().getBundle().getString("NET_NO_AUDIO"); | |||
| break; | |||
| case LastError.NET_NO_INIT: // (0x80000000|29) 网络SDK未经初始化 | |||
| msg = Res.string().getBundle().getString("NET_NO_INIT"); | |||
| break; | |||
| case LastError.NET_DOWNLOAD_END: // (0x80000000|30) 下载已结束 | |||
| msg = Res.string().getBundle().getString("NET_DOWNLOAD_END"); | |||
| break; | |||
| case LastError.NET_EMPTY_LIST: // (0x80000000|31) 查询结果为空 | |||
| msg = Res.string().getBundle().getString("NET_EMPTY_LIST"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_SYSATTR: // (0x80000000|32) 获取系统属性配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_SYSATTR"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_SERIAL: // (0x80000000|33) 获取序列号失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_SERIAL"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_GENERAL: // (0x80000000|34) 获取常规属性失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_GENERAL"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_DSPCAP: // (0x80000000|35) 获取DSP能力描述失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_DSPCAP"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_NETCFG: // (0x80000000|36) 获取网络配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_NETCFG"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_CHANNAME: // (0x80000000|37) 获取通道名称失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_CHANNAME"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_VIDEO: // (0x80000000|38) 获取视频属性失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_VIDEO"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_RECORD: // (0x80000000|39) 获取录象配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_RECORD"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_PRONAME: // (0x80000000|40) 获取解码器协议名称失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_PRONAME"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_FUNCNAME: // (0x80000000|41) 获取232串口功能名称失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_FUNCNAME"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_485DECODER: // (0x80000000|42) 获取解码器属性失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_485DECODER"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_232COM: // (0x80000000|43) 获取232串口配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_232COM"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_ALARMIN: // (0x80000000|44) 获取外部报警输入配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_ALARMIN"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_ALARMDET: // (0x80000000|45) 获取动态检测报警失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_ALARMDET"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_SYSTIME: // (0x80000000|46) 获取设备时间失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_SYSTIME"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_PREVIEW: // (0x80000000|47) 获取预览参数失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_PREVIEW"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_AUTOMT: // (0x80000000|48) 获取自动维护配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_AUTOMT"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_VIDEOMTRX: // (0x80000000|49) 获取视频矩阵配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_VIDEOMTRX"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_COVER: // (0x80000000|50) 获取区域遮挡配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_COVER"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_WATERMAKE: // (0x80000000|51) 获取图象水印配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_WATERMAKE"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_MULTICAST: // (0x80000000|52) 获取配置失败位置:组播端口按通道配置 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_MULTICAST"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_GENERAL: // (0x80000000|55) 修改常规属性失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_GENERAL"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_NETCFG: // (0x80000000|56) 改网络配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_NETCFG"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_CHANNAME: // (0x80000000|57) 修改通道名称失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_CHANNAME"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_VIDEO: // (0x80000000|58) 修改视频属性失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_VIDEO"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_RECORD: // (0x80000000|59) 修改录象配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_RECORD"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_485DECODER: // (0x80000000|60) 修改解码器属性失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_485DECODER"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_232COM: // (0x80000000|61) 修改232串口配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_232COM"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_ALARMIN: // (0x80000000|62) 修改外部输入报警配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_ALARMIN"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_ALARMDET: // (0x80000000|63) 修改动态检测报警配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_ALARMDET"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_SYSTIME: // (0x80000000|64) 修改设备时间失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_SYSTIME"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_PREVIEW: // (0x80000000|65) 修改预览参数失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_PREVIEW"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_AUTOMT: // (0x80000000|66) 修改自动维护配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_AUTOMT"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_VIDEOMTRX: // (0x80000000|67) 修改视频矩阵配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_VIDEOMTRX"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_COVER: // (0x80000000|68) 修改区域遮挡配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_COVER"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_WATERMAKE: // (0x80000000|69) 修改图象水印配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_WATERMAKE"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_WLAN: // (0x80000000|70) 修改无线网络信息失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_WLAN"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_WLANDEV: // (0x80000000|71) 选择无线网络设备失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_WLANDEV"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_REGISTER: // (0x80000000|72) 修改主动注册参数配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_REGISTER"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_CAMERA: // (0x80000000|73) 修改摄像头属性配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_CAMERA"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_INFRARED: // (0x80000000|74) 修改红外报警配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_INFRARED"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_SOUNDALARM: // (0x80000000|75) 修改音频报警配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_SOUNDALARM"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_STORAGE: // (0x80000000|76) 修改存储位置配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_STORAGE"); | |||
| break; | |||
| case LastError.NET_AUDIOENCODE_NOTINIT: // (0x80000000|77) 音频编码接口没有成功初始化 | |||
| msg = Res.string().getBundle().getString("NET_AUDIOENCODE_NOTINIT"); | |||
| break; | |||
| case LastError.NET_DATA_TOOLONGH: // (0x80000000|78) 数据过长 | |||
| msg = Res.string().getBundle().getString("NET_DATA_TOOLONGH"); | |||
| break; | |||
| case LastError.NET_UNSUPPORTED: // (0x80000000|79) 备不支持该操作 | |||
| msg = Res.string().getBundle().getString("NET_UNSUPPORTED"); | |||
| break; | |||
| case LastError.NET_DEVICE_BUSY: // (0x80000000|80) 设备资源不足 | |||
| msg = Res.string().getBundle().getString("NET_DEVICE_BUSY"); | |||
| break; | |||
| case LastError.NET_SERVER_STARTED: // (0x80000000|81) 服务器已经启动 | |||
| msg = Res.string().getBundle().getString("NET_SERVER_STARTED"); | |||
| break; | |||
| case LastError.NET_SERVER_STOPPED: // (0x80000000|82) 服务器尚未成功启动 | |||
| msg = Res.string().getBundle().getString("NET_SERVER_STOPPED"); | |||
| break; | |||
| case LastError.NET_LISTER_INCORRECT_SERIAL: // (0x80000000|83) 输入序列号有误 | |||
| msg = Res.string().getBundle().getString("NET_LISTER_INCORRECT_SERIAL"); | |||
| break; | |||
| case LastError.NET_QUERY_DISKINFO_FAILED: // (0x80000000|84) 获取硬盘信息失败 | |||
| msg = Res.string().getBundle().getString("NET_QUERY_DISKINFO_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_SESSION: // (0x80000000|85) 获取连接Session信息 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_SESSION"); | |||
| break; | |||
| case LastError.NET_USER_FLASEPWD_TRYTIME: // (0x80000000|86) 输入密码错误超过限制次数 | |||
| msg = Res.string().getBundle().getString("NET_USER_FLASEPWD_TRYTIME"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_PASSWORD: // (0x80000000|100) 密码不正确 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_PASSWORD"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_USER: // (0x80000000|101) 帐户不存在 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_USER"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_TIMEOUT: // (0x80000000|102) 等待登录返回超时 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_TIMEOUT"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_RELOGGIN: // (0x80000000|103) 帐号已登录 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_RELOGGIN"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_LOCKED: // (0x80000000|104) 帐号已被锁定 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_LOCKED"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_BLACKLIST: // (0x80000000|105) 帐号已被列为禁止名单 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_BLACKLIST"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_BUSY: // (0x80000000|106) 资源不足,系统忙 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_BUSY"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_CONNECT: // (0x80000000|107) 登录设备超时,请检查网络并重试 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_CONNECT"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_NETWORK: // (0x80000000|108) 网络连接失败 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_NETWORK"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_SUBCONNECT: // (0x80000000|109) 登录设备成功,但无法创建视频通道,请检查网 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_SUBCONNECT"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_MAXCONNECT: // (0x80000000|110) 超过最大连接数 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_MAXCONNECT"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_PROTOCOL3_ONLY: // (0x80000000|111) 只支持3代协议 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_PROTOCOL3_ONLY"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_UKEY_LOST: // (0x80000000|112) 插入U盾或U盾信息错误 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_UKEY_LOST"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_NO_AUTHORIZED: // (0x80000000|113) 客户端IP地址没有登录权限 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_NO_AUTHORIZED"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_USER_OR_PASSOWRD: // (0x80000000|117) 账号或密码错误 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_USER_OR_PASSOWRD"); | |||
| break; | |||
| case LastError.NET_LOGIN_ERROR_DEVICE_NOT_INIT: // (0x80000000|118) 设备尚未初始化,不能登录,请先初始化设备 | |||
| msg = Res.string().getBundle().getString("NET_LOGIN_ERROR_DEVICE_NOT_INIT"); | |||
| break; | |||
| case LastError.NET_RENDER_SOUND_ON_ERROR: // (0x80000000|120) Render库打开音频出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_SOUND_ON_ERROR"); | |||
| break; | |||
| case LastError.NET_RENDER_SOUND_OFF_ERROR: // (0x80000000|121) Render库关闭音频出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_SOUND_OFF_ERROR"); | |||
| break; | |||
| case LastError.NET_RENDER_SET_VOLUME_ERROR: // (0x80000000|122) Render库控制音量出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_SET_VOLUME_ERROR"); | |||
| break; | |||
| case LastError.NET_RENDER_ADJUST_ERROR: // (0x80000000|123) Render库设置画面参数出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_ADJUST_ERROR"); | |||
| break; | |||
| case LastError.NET_RENDER_PAUSE_ERROR: // (0x80000000|124) Render库暂停播放出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_PAUSE_ERROR"); | |||
| break; | |||
| case LastError.NET_RENDER_SNAP_ERROR: // (0x80000000|125) Render库抓图出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_SNAP_ERROR"); | |||
| break; | |||
| case LastError.NET_RENDER_STEP_ERROR: // (0x80000000|126) Render库步进出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_STEP_ERROR"); | |||
| break; | |||
| case LastError.NET_RENDER_FRAMERATE_ERROR: // (0x80000000|127) Render库设置帧率出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_FRAMERATE_ERROR"); | |||
| break; | |||
| case LastError.NET_RENDER_DISPLAYREGION_ERROR: // (0x80000000|128) Render库设置显示区域出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_DISPLAYREGION_ERROR"); | |||
| break; | |||
| case LastError.NET_RENDER_GETOSDTIME_ERROR: // (0x80000000|129) Render库获取当前播放时间出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_GETOSDTIME_ERROR"); | |||
| break; | |||
| case LastError.NET_GROUP_EXIST: // (0x80000000|140) 组名已存在 | |||
| msg = Res.string().getBundle().getString("NET_GROUP_EXIST"); | |||
| break; | |||
| case LastError.NET_GROUP_NOEXIST: // (0x80000000|141) 组名不存在 | |||
| msg = Res.string().getBundle().getString("NET_GROUP_NOEXIST"); | |||
| break; | |||
| case LastError.NET_GROUP_RIGHTOVER: // (0x80000000|142) 组的权限超出权限列表范围 | |||
| msg = Res.string().getBundle().getString("NET_GROUP_RIGHTOVER"); | |||
| break; | |||
| case LastError.NET_GROUP_HAVEUSER: // (0x80000000|143) 组下有用户,不能删除 | |||
| msg = Res.string().getBundle().getString("NET_GROUP_HAVEUSER"); | |||
| break; | |||
| case LastError.NET_GROUP_RIGHTUSE: // (0x80000000|144) 组的某个权限被用户使用,不能出除 | |||
| msg = Res.string().getBundle().getString("NET_GROUP_RIGHTUSE"); | |||
| break; | |||
| case LastError.NET_GROUP_SAMENAME: // (0x80000000|145) 新组名同已有组名重复 | |||
| msg = Res.string().getBundle().getString("NET_GROUP_SAMENAME"); | |||
| break; | |||
| case LastError.NET_USER_EXIST: // (0x80000000|146) 用户已存在 | |||
| msg = Res.string().getBundle().getString("NET_USER_EXIST"); | |||
| break; | |||
| case LastError.NET_USER_NOEXIST: // (0x80000000|147) 用户不存在 | |||
| msg = Res.string().getBundle().getString("NET_USER_NOEXIST"); | |||
| break; | |||
| case LastError.NET_USER_RIGHTOVER: // (0x80000000|148) 用户权限超出组权限 | |||
| msg = Res.string().getBundle().getString("NET_USER_RIGHTOVER"); | |||
| break; | |||
| case LastError.NET_USER_PWD: // (0x80000000|149) 保留帐号,不容许修改密码 | |||
| msg = Res.string().getBundle().getString("NET_USER_PWD"); | |||
| break; | |||
| case LastError.NET_USER_FLASEPWD: // (0x80000000|150) 密码不正确 | |||
| msg = Res.string().getBundle().getString("NET_USER_FLASEPWD"); | |||
| break; | |||
| case LastError.NET_USER_NOMATCHING: // (0x80000000|151) 密码不匹配 | |||
| msg = Res.string().getBundle().getString("NET_USER_NOMATCHING"); | |||
| break; | |||
| case LastError.NET_USER_INUSE: // (0x80000000|152) 账号正在使用中 | |||
| msg = Res.string().getBundle().getString("NET_USER_INUSE"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_ETHERNET: // (0x80000000|300) 获取网卡配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_ETHERNET"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_WLAN: // (0x80000000|301) 获取无线网络信息失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_WLAN"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_WLANDEV: // (0x80000000|302) 获取无线网络设备失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_WLANDEV"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_REGISTER: // (0x80000000|303) 获取主动注册参数失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_REGISTER"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_CAMERA: // (0x80000000|304) 获取摄像头属性失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_CAMERA"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_INFRARED: // (0x80000000|305) 获取红外报警配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_INFRARED"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_SOUNDALARM: // (0x80000000|306) 获取音频报警配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_SOUNDALARM"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_STORAGE: // (0x80000000|307) 获取存储位置配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_STORAGE"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_MAIL: // (0x80000000|308) 获取邮件配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_MAIL"); | |||
| break; | |||
| case LastError.NET_CONFIG_DEVBUSY: // (0x80000000|309) 暂时无法设置 | |||
| msg = Res.string().getBundle().getString("NET_CONFIG_DEVBUSY"); | |||
| break; | |||
| case LastError.NET_CONFIG_DATAILLEGAL: // (0x80000000|310) 配置数据不合法 | |||
| msg = Res.string().getBundle().getString("NET_CONFIG_DATAILLEGAL"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_DST: // (0x80000000|311) 获取夏令时配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_DST"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_DST: // (0x80000000|312) 设置夏令时配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_DST"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_VIDEO_OSD: // (0x80000000|313) 获取视频OSD叠加配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_VIDEO_OSD"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_VIDEO_OSD: // (0x80000000|314) 设置视频OSD叠加配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_VIDEO_OSD"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_GPRSCDMA: // (0x80000000|315) 获取CDMA\GPRS网络配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_GPRSCDMA"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_GPRSCDMA: // (0x80000000|316) 设置CDMA\GPRS网络配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_GPRSCDMA"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_IPFILTER: // (0x80000000|317) 获取IP过滤配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_IPFILTER"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_IPFILTER: // (0x80000000|318) 设置IP过滤配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_IPFILTER"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_TALKENCODE: // (0x80000000|319) 获取语音对讲编码配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_TALKENCODE"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_TALKENCODE: // (0x80000000|320) 设置语音对讲编码配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_TALKENCODE"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_RECORDLEN: // (0x80000000|321) 获取录像打包长度配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_RECORDLEN"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_RECORDLEN: // (0x80000000|322) 设置录像打包长度配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_RECORDLEN"); | |||
| break; | |||
| case LastError.NET_DONT_SUPPORT_SUBAREA: // (0x80000000|323) 不支持网络硬盘分区 | |||
| msg = Res.string().getBundle().getString("NET_DONT_SUPPORT_SUBAREA"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_AUTOREGSERVER: // (0x80000000|324) 获取设备上主动注册服务器信息失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_AUTOREGSERVER"); | |||
| break; | |||
| case LastError.NET_ERROR_CONTROL_AUTOREGISTER: // (0x80000000|325) 主动注册重定向注册错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_CONTROL_AUTOREGISTER"); | |||
| break; | |||
| case LastError.NET_ERROR_DISCONNECT_AUTOREGISTER: // (0x80000000|326) 断开主动注册服务器错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_DISCONNECT_AUTOREGISTER"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_MMS: // (0x80000000|327) 获取mms配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_MMS"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_MMS: // (0x80000000|328) 设置mms配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_MMS"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_SMSACTIVATION: // (0x80000000|329) 获取短信激活无线连接配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_SMSACTIVATION"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_SMSACTIVATION: // (0x80000000|330) 设置短信激活无线连接配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_SMSACTIVATION"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_DIALINACTIVATION: // (0x80000000|331) 获取拨号激活无线连接配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_DIALINACTIVATION"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_DIALINACTIVATION: // (0x80000000|332) 设置拨号激活无线连接配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_DIALINACTIVATION"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_VIDEOOUT: // (0x80000000|333) 查询视频输出参数配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_VIDEOOUT"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_VIDEOOUT: // (0x80000000|334) 设置视频输出参数配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_VIDEOOUT"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_OSDENABLE: // (0x80000000|335) 获取osd叠加使能配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_OSDENABLE"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_OSDENABLE: // (0x80000000|336) 设置osd叠加使能配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_OSDENABLE"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_ENCODERINFO: // (0x80000000|337) 设置数字通道前端编码接入配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_ENCODERINFO"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_TVADJUST: // (0x80000000|338) 获取TV调节配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_TVADJUST"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_TVADJUST: // (0x80000000|339) 设置TV调节配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_TVADJUST"); | |||
| break; | |||
| case LastError.NET_ERROR_CONNECT_FAILED: // (0x80000000|340) 请求建立连接失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_CONNECT_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_BURNFILE: // (0x80000000|341) 请求刻录文件上传失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_BURNFILE"); | |||
| break; | |||
| case LastError.NET_ERROR_SNIFFER_GETCFG: // (0x80000000|342) 获取抓包配置信息失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SNIFFER_GETCFG"); | |||
| break; | |||
| case LastError.NET_ERROR_SNIFFER_SETCFG: // (0x80000000|343) 设置抓包配置信息失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SNIFFER_SETCFG"); | |||
| break; | |||
| case LastError.NET_ERROR_DOWNLOADRATE_GETCFG: // (0x80000000|344) 查询下载限制信息失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_DOWNLOADRATE_GETCFG"); | |||
| break; | |||
| case LastError.NET_ERROR_DOWNLOADRATE_SETCFG: // (0x80000000|345) 设置下载限制信息失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_DOWNLOADRATE_SETCFG"); | |||
| break; | |||
| case LastError.NET_ERROR_SEARCH_TRANSCOM: // (0x80000000|346) 查询串口参数失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SEARCH_TRANSCOM"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_POINT: // (0x80000000|347) 获取预制点信息错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_POINT"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_POINT: // (0x80000000|348) 设置预制点信息错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_POINT"); | |||
| break; | |||
| case LastError.NET_SDK_LOGOUT_ERROR: // (0x80000000|349) SDK没有正常登出设备 | |||
| msg = Res.string().getBundle().getString("NET_SDK_LOGOUT_ERROR"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_VEHICLE_CFG: // (0x80000000|350) 获取车载配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_VEHICLE_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_SET_VEHICLE_CFG: // (0x80000000|351) 设置车载配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SET_VEHICLE_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_ATM_OVERLAY_CFG: // (0x80000000|352) 获取atm叠加配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_ATM_OVERLAY_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_SET_ATM_OVERLAY_CFG: // (0x80000000|353) 设置atm叠加配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SET_ATM_OVERLAY_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_ATM_OVERLAY_ABILITY: // (0x80000000|354) 获取atm叠加能力失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_ATM_OVERLAY_ABILITY"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_DECODER_TOUR_CFG: // (0x80000000|355) 获取解码器解码轮巡配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_DECODER_TOUR_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_SET_DECODER_TOUR_CFG: // (0x80000000|356) 设置解码器解码轮巡配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SET_DECODER_TOUR_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_CTRL_DECODER_TOUR: // (0x80000000|357) 控制解码器解码轮巡失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_CTRL_DECODER_TOUR"); | |||
| break; | |||
| case LastError.NET_GROUP_OVERSUPPORTNUM: // (0x80000000|358) 超出设备支持最大用户组数目 | |||
| msg = Res.string().getBundle().getString("NET_GROUP_OVERSUPPORTNUM"); | |||
| break; | |||
| case LastError.NET_USER_OVERSUPPORTNUM: // (0x80000000|359) 超出设备支持最大用户数目 | |||
| msg = Res.string().getBundle().getString("NET_USER_OVERSUPPORTNUM"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_SIP_CFG: // (0x80000000|368) 获取SIP配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_SIP_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_SET_SIP_CFG: // (0x80000000|369) 设置SIP配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SET_SIP_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_SIP_ABILITY: // (0x80000000|370) 获取SIP能力失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_SIP_ABILITY"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_WIFI_AP_CFG: // (0x80000000|371) 获取WIFI ap配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_WIFI_AP_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_SET_WIFI_AP_CFG: // (0x80000000|372) 设置WIFI ap配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SET_WIFI_AP_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_DECODE_POLICY: // (0x80000000|373) 获取解码策略配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_DECODE_POLICY"); | |||
| break; | |||
| case LastError.NET_ERROR_SET_DECODE_POLICY: // (0x80000000|374) 设置解码策略配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SET_DECODE_POLICY"); | |||
| break; | |||
| case LastError.NET_ERROR_TALK_REJECT: // (0x80000000|375) 拒绝对讲 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_TALK_REJECT"); | |||
| break; | |||
| case LastError.NET_ERROR_TALK_OPENED: // (0x80000000|376) 对讲被其他客户端打开 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_TALK_OPENED"); | |||
| break; | |||
| case LastError.NET_ERROR_TALK_RESOURCE_CONFLICIT: // (0x80000000|377) 资源冲突 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_TALK_RESOURCE_CONFLICIT"); | |||
| break; | |||
| case LastError.NET_ERROR_TALK_UNSUPPORTED_ENCODE: // (0x80000000|378) 不支持的语音编码格式 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_TALK_UNSUPPORTED_ENCODE"); | |||
| break; | |||
| case LastError.NET_ERROR_TALK_RIGHTLESS: // (0x80000000|379) 无权限 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_TALK_RIGHTLESS"); | |||
| break; | |||
| case LastError.NET_ERROR_TALK_FAILED: // (0x80000000|380) 请求对讲失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_TALK_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_MACHINE_CFG: // (0x80000000|381) 获取机器相关配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_MACHINE_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_SET_MACHINE_CFG: // (0x80000000|382) 设置机器相关配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SET_MACHINE_CFG"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_DATA_FAILED: // (0x80000000|383) 设备无法获取当前请求数据 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_DATA_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_MAC_VALIDATE_FAILED: // (0x80000000|384) MAC地址验证失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_MAC_VALIDATE_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_INSTANCE: // (0x80000000|385) 获取服务器实例失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_INSTANCE"); | |||
| break; | |||
| case LastError.NET_ERROR_JSON_REQUEST: // (0x80000000|386) 生成的json字符串错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_JSON_REQUEST"); | |||
| break; | |||
| case LastError.NET_ERROR_JSON_RESPONSE: // (0x80000000|387) 响应的json字符串错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_JSON_RESPONSE"); | |||
| break; | |||
| case LastError.NET_ERROR_VERSION_HIGHER: // (0x80000000|388) 协议版本低于当前使用的版本 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_VERSION_HIGHER"); | |||
| break; | |||
| case LastError.NET_SPARE_NO_CAPACITY: // (0x80000000|389) 热备操作失败, 容量不足 | |||
| msg = Res.string().getBundle().getString("NET_SPARE_NO_CAPACITY"); | |||
| break; | |||
| case LastError.NET_ERROR_SOURCE_IN_USE: // (0x80000000|390) 显示源被其他输出占用 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SOURCE_IN_USE"); | |||
| break; | |||
| case LastError.NET_ERROR_REAVE: // (0x80000000|391) 高级用户抢占低级用户资源 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_REAVE"); | |||
| break; | |||
| case LastError.NET_ERROR_NETFORBID: // (0x80000000|392) 禁止入网 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_NETFORBID"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_MACFILTER: // (0x80000000|393) 获取MAC过滤配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_MACFILTER"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_MACFILTER: // (0x80000000|394) 设置MAC过滤配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_MACFILTER"); | |||
| break; | |||
| case LastError.NET_ERROR_GETCFG_IPMACFILTER: // (0x80000000|395) 获取IP/MAC过滤配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GETCFG_IPMACFILTER"); | |||
| break; | |||
| case LastError.NET_ERROR_SETCFG_IPMACFILTER: // (0x80000000|396) 设置IP/MAC过滤配置失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SETCFG_IPMACFILTER"); | |||
| break; | |||
| case LastError.NET_ERROR_OPERATION_OVERTIME: // (0x80000000|397) 当前操作超时 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_OPERATION_OVERTIME"); | |||
| break; | |||
| case LastError.NET_ERROR_SENIOR_VALIDATE_FAILED: // (0x80000000|398) 高级校验失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SENIOR_VALIDATE_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_DEVICE_ID_NOT_EXIST: // (0x80000000|399) 设备ID不存在 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_DEVICE_ID_NOT_EXIST"); | |||
| break; | |||
| case LastError.NET_ERROR_UNSUPPORTED: // (0x80000000|400) 不支持当前操作 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_UNSUPPORTED"); | |||
| break; | |||
| case LastError.NET_ERROR_PROXY_DLLLOAD: // (0x80000000|401) 代理库加载失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PROXY_DLLLOAD"); | |||
| break; | |||
| case LastError.NET_ERROR_PROXY_ILLEGAL_PARAM: // (0x80000000|402) 代理用户参数不合法 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PROXY_ILLEGAL_PARAM"); | |||
| break; | |||
| case LastError.NET_ERROR_PROXY_INVALID_HANDLE: // (0x80000000|403) 代理句柄无效 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PROXY_INVALID_HANDLE"); | |||
| break; | |||
| case LastError.NET_ERROR_PROXY_LOGIN_DEVICE_ERROR: // (0x80000000|404) 代理登入前端设备失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PROXY_LOGIN_DEVICE_ERROR"); | |||
| break; | |||
| case LastError.NET_ERROR_PROXY_START_SERVER_ERROR: // (0x80000000|405) 启动代理服务失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PROXY_START_SERVER_ERROR"); | |||
| break; | |||
| case LastError.NET_ERROR_SPEAK_FAILED: // (0x80000000|406) 请求喊话失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SPEAK_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_NOT_SUPPORT_F6: // (0x80000000|407) 设备不支持此F6接口调用 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_NOT_SUPPORT_F6"); | |||
| break; | |||
| case LastError.NET_ERROR_CD_UNREADY: // (0x80000000|408) 光盘未就绪 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_CD_UNREADY"); | |||
| break; | |||
| case LastError.NET_ERROR_DIR_NOT_EXIST: // (0x80000000|409) 目录不存在 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_DIR_NOT_EXIST"); | |||
| break; | |||
| case LastError.NET_ERROR_UNSUPPORTED_SPLIT_MODE: // (0x80000000|410) 设备不支持的分割模式 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_UNSUPPORTED_SPLIT_MODE"); | |||
| break; | |||
| case LastError.NET_ERROR_OPEN_WND_PARAM: // (0x80000000|411) 开窗参数不合法 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_OPEN_WND_PARAM"); | |||
| break; | |||
| case LastError.NET_ERROR_LIMITED_WND_COUNT: // (0x80000000|412) 开窗数量超过限制 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_LIMITED_WND_COUNT"); | |||
| break; | |||
| case LastError.NET_ERROR_UNMATCHED_REQUEST: // (0x80000000|413) 请求命令与当前模式不匹配 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_UNMATCHED_REQUEST"); | |||
| break; | |||
| case LastError.NET_RENDER_ENABLELARGEPICADJUSTMENT_ERROR: // (0x80000000|414) Render库启用高清图像内部调整策略出错 | |||
| msg = Res.string().getBundle().getString("NET_RENDER_ENABLELARGEPICADJUSTMENT_ERROR"); | |||
| break; | |||
| case LastError.NET_ERROR_UPGRADE_FAILED: // (0x80000000|415) 设备升级失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_UPGRADE_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_NO_TARGET_DEVICE: // (0x80000000|416) 找不到目标设备 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_NO_TARGET_DEVICE"); | |||
| break; | |||
| case LastError.NET_ERROR_NO_VERIFY_DEVICE: // (0x80000000|417) 找不到验证设备 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_NO_VERIFY_DEVICE"); | |||
| break; | |||
| case LastError.NET_ERROR_CASCADE_RIGHTLESS: // (0x80000000|418) 无级联权限 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_CASCADE_RIGHTLESS"); | |||
| break; | |||
| case LastError.NET_ERROR_LOW_PRIORITY: // (0x80000000|419) 低优先级 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_LOW_PRIORITY"); | |||
| break; | |||
| case LastError.NET_ERROR_REMOTE_REQUEST_TIMEOUT: // (0x80000000|420) 远程设备请求超时 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_REMOTE_REQUEST_TIMEOUT"); | |||
| break; | |||
| case LastError.NET_ERROR_LIMITED_INPUT_SOURCE: // (0x80000000|421) 输入源超出最大路数限制 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_LIMITED_INPUT_SOURCE"); | |||
| break; | |||
| case LastError.NET_ERROR_SET_LOG_PRINT_INFO: // (0x80000000|422) 设置日志打印失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SET_LOG_PRINT_INFO"); | |||
| break; | |||
| case LastError.NET_ERROR_PARAM_DWSIZE_ERROR: // (0x80000000|423) 入参的dwsize字段出错 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PARAM_DWSIZE_ERROR"); | |||
| break; | |||
| case LastError.NET_ERROR_LIMITED_MONITORWALL_COUNT: // (0x80000000|424) 电视墙数量超过上限 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_LIMITED_MONITORWALL_COUNT"); | |||
| break; | |||
| case LastError.NET_ERROR_PART_PROCESS_FAILED: // (0x80000000|425) 部分过程执行失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PART_PROCESS_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_TARGET_NOT_SUPPORT: // (0x80000000|426) 该功能不支持转发 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_TARGET_NOT_SUPPORT"); | |||
| break; | |||
| case LastError.NET_ERROR_VISITE_FILE: // (0x80000000|510) 访问文件失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_VISITE_FILE"); | |||
| break; | |||
| case LastError.NET_ERROR_DEVICE_STATUS_BUSY: // (0x80000000|511) 设备忙 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_DEVICE_STATUS_BUSY"); | |||
| break; | |||
| case LastError.NET_USER_PWD_NOT_AUTHORIZED: // (0x80000000|512)修改密码无权限 | |||
| msg = Res.string().getBundle().getString("NET_USER_PWD_NOT_AUTHORIZED"); | |||
| break; | |||
| case LastError.NET_USER_PWD_NOT_STRONG: // (0x80000000|513) 密码强度不够 | |||
| msg = Res.string().getBundle().getString("NET_USER_PWD_NOT_STRONG"); | |||
| break; | |||
| case LastError.NET_ERROR_NO_SUCH_CONFIG: // (0x80000000|514) 没有对应的配置 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_NO_SUCH_CONFIG"); | |||
| break; | |||
| case LastError.NET_ERROR_AUDIO_RECORD_FAILED: // (0x80000000|515) 录音失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_AUDIO_RECORD_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_SEND_DATA_FAILED: // (0x80000000|516) 数据发送失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SEND_DATA_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_OBSOLESCENT_INTERFACE: // (0x80000000|517) 废弃接口 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_OBSOLESCENT_INTERFACE"); | |||
| break; | |||
| case LastError.NET_ERROR_INSUFFICIENT_INTERAL_BUF: // (0x80000000|518) 内部缓冲不足 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_INSUFFICIENT_INTERAL_BUF"); | |||
| break; | |||
| case LastError.NET_ERROR_NEED_ENCRYPTION_PASSWORD: // (0x80000000|519) 修改设备ip时,需要校验密码 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_NEED_ENCRYPTION_PASSWORD"); | |||
| break; | |||
| case LastError.NET_ERROR_NOSUPPORT_RECORD: // (0x80000000|520) 设备不支持此记录集 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_NOSUPPORT_RECORD"); | |||
| break; | |||
| case LastError.NET_ERROR_SERIALIZE_ERROR: // (0x80000000|1010) 数据序列化错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SERIALIZE_ERROR"); | |||
| break; | |||
| case LastError.NET_ERROR_DESERIALIZE_ERROR: // (0x80000000|1011) 数据反序列化错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_DESERIALIZE_ERROR"); | |||
| break; | |||
| case LastError.NET_ERROR_LOWRATEWPAN_ID_EXISTED: // (0x80000000|1012) 该无线ID已存在 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_LOWRATEWPAN_ID_EXISTED"); | |||
| break; | |||
| case LastError.NET_ERROR_LOWRATEWPAN_ID_LIMIT: // (0x80000000|1013) 无线ID数量已超限 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_LOWRATEWPAN_ID_LIMIT"); | |||
| break; | |||
| case LastError.NET_ERROR_LOWRATEWPAN_ID_ABNORMAL: // (0x80000000|1014) 无线异常添加 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_LOWRATEWPAN_ID_ABNORMAL"); | |||
| break; | |||
| case LastError.NET_ERROR_ENCRYPT: // (0x80000000|1015) 加密数据失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_ENCRYPT"); | |||
| break; | |||
| case LastError.NET_ERROR_PWD_ILLEGAL: // (0x80000000|1016) 新密码不合规范 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PWD_ILLEGAL"); | |||
| break; | |||
| case LastError.NET_ERROR_DEVICE_ALREADY_INIT: // (0x80000000|1017) 设备已经初始化 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_DEVICE_ALREADY_INIT"); | |||
| break; | |||
| case LastError.NET_ERROR_SECURITY_CODE: // (0x80000000|1018) 安全码错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SECURITY_CODE"); | |||
| break; | |||
| case LastError.NET_ERROR_SECURITY_CODE_TIMEOUT: // (0x80000000|1019) 安全码超出有效期 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_SECURITY_CODE_TIMEOUT"); | |||
| break; | |||
| case LastError.NET_ERROR_GET_PWD_SPECI: // (0x80000000|1020) 获取密码规范失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_GET_PWD_SPECI"); | |||
| break; | |||
| case LastError.NET_ERROR_NO_AUTHORITY_OF_OPERATION: // (0x80000000|1021) 无权限进行该操作 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_NO_AUTHORITY_OF_OPERATION"); | |||
| break; | |||
| case LastError.NET_ERROR_DECRYPT: // (0x80000000|1022) 解密数据失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_DECRYPT"); | |||
| break; | |||
| case LastError.NET_ERROR_2D_CODE: // (0x80000000|1023) 2D code校验失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_2D_CODE"); | |||
| break; | |||
| case LastError.NET_ERROR_INVALID_REQUEST: // (0x80000000|1024) 非法的RPC请求 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_INVALID_REQUEST"); | |||
| break; | |||
| case LastError.NET_ERROR_PWD_RESET_DISABLE: // (0x80000000|1025) 密码重置功能已关闭 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PWD_RESET_DISABLE"); | |||
| break; | |||
| case LastError.NET_ERROR_PLAY_PRIVATE_DATA: // (0x80000000|1026) 显示私有数据,比如规则框等失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PLAY_PRIVATE_DATA"); | |||
| break; | |||
| case LastError.NET_ERROR_ROBOT_OPERATE_FAILED: // (0x80000000|1027) 机器人操作失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_ROBOT_OPERATE_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_PHOTOSIZE_EXCEEDSLIMIT: // (0x80000000|1028) 图片大小超限 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PHOTOSIZE_EXCEEDSLIMIT"); | |||
| break; | |||
| case LastError.NET_ERROR_USERID_INVALID: // (0x80000000|1029) 用户ID不存在 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_USERID_INVALID"); | |||
| break; | |||
| case LastError.NET_ERROR_EXTRACTFEATURE_FAILED: // (0x80000000|1030) 照片特征值提取失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_EXTRACTFEATURE_FAILED"); | |||
| break; | |||
| case LastError.NET_ERROR_PHOTO_EXIST: // (0x80000000|1031) 照片已存在 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PHOTO_EXIST"); | |||
| break; | |||
| case LastError.NET_ERROR_PHOTO_OVERFLOW: // (0x80000000|1032) 照片数量超过上限 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_PHOTO_OVERFLOW"); | |||
| break; | |||
| case LastError.NET_ERROR_CHANNEL_ALREADY_OPENED: // (0x80000000|1033) 通道已经打开 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_CHANNEL_ALREADY_OPENED"); | |||
| break; | |||
| case LastError.NET_ERROR_CREATE_SOCKET: // (0x80000000|1034) 创建套接字失败 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_CREATE_SOCKET"); | |||
| break; | |||
| case LastError.NET_ERROR_CHANNEL_NUM: // (0x80000000|1035) 通道号错误 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_CHANNEL_NUM"); | |||
| break; | |||
| case LastError.NET_ERROR_FACE_RECOGNITION_SERVER_GROUP_ID_EXCEED: // (0x80000000|1051) 组ID超过最大值 | |||
| msg = Res.string().getBundle().getString("NET_ERROR_FACE_RECOGNITION_SERVER_GROUP_ID_EXCEED"); | |||
| break; | |||
| default: | |||
| msg = Res.string().getBundle().getString("NET_ERROR"); | |||
| break; | |||
| } | |||
| return msg; | |||
| } | |||
| } | |||
| @@ -0,0 +1,79 @@ | |||
| package com.netsdk.common; | |||
| import java.util.concurrent.ExecutorService; | |||
| import java.util.concurrent.Executors; | |||
| import java.util.concurrent.Future; | |||
| import java.util.concurrent.LinkedBlockingDeque; | |||
| public class EventTaskCommonQueue { | |||
| // 设置一个队列,容量看情况改 | |||
| private final int MAX_TASK_COUNT = 10000; // 队列容量 | |||
| private final LinkedBlockingDeque<EventTaskHandler> eventTasks = new LinkedBlockingDeque<EventTaskHandler>(MAX_TASK_COUNT); | |||
| // 起一个线程池 | |||
| private final int MAX_THREAD_COUNT = 10; // 线程池容量 | |||
| private ExecutorService eventQueueService = Executors.newFixedThreadPool(MAX_THREAD_COUNT); | |||
| // 用于检验服务运行状态 | |||
| private volatile boolean running = true; | |||
| // 用于查看当前线程状态 | |||
| private Future<?> eventQueueThreadStatus; | |||
| // 初始化 | |||
| public void init() { | |||
| eventQueueThreadStatus = eventQueueService.submit(new Thread(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| while (running) { | |||
| try { | |||
| EventTaskHandler task = eventTasks.take(); //开始一个任务 | |||
| try { | |||
| task.eventTaskProcess(); // 主要的运行函数 | |||
| } catch (Exception e) { | |||
| System.err.println("任务处理发生错误"); // error | |||
| } | |||
| } catch (InterruptedException e) { | |||
| System.err.println("任务已意外停止"); // error | |||
| running = false; | |||
| } | |||
| } | |||
| } | |||
| }, "Event call back thread init")); | |||
| } | |||
| // 向队列添加新的任务 | |||
| public boolean addEvent(EventTaskHandler eventHandler) { | |||
| if (!running) { | |||
| System.out.println("任务已停止"); // warning | |||
| return false; | |||
| } | |||
| boolean success = eventTasks.offer(eventHandler); | |||
| if (!success) { | |||
| // 队列已满,无法再添加 | |||
| System.out.println("添加到事件队列失败"); | |||
| } | |||
| return success; | |||
| } | |||
| // 手动启动服务 | |||
| public void activeService() { | |||
| running = true; | |||
| if (eventQueueService.isShutdown()) { | |||
| eventQueueService = Executors.newFixedThreadPool(MAX_THREAD_COUNT);; | |||
| init(); | |||
| System.out.println("线程池已关闭,重新初始化线程池及任务"); | |||
| } | |||
| if (eventQueueThreadStatus.isDone()) { | |||
| init(); | |||
| System.out.println("线程池任务结束,重新初始化任务"); | |||
| } | |||
| } | |||
| // 手动关闭服务 | |||
| public void destroy() { | |||
| running = false; | |||
| eventQueueService.shutdownNow(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,6 @@ | |||
| package com.netsdk.common; | |||
| public interface EventTaskHandler { | |||
| void eventTaskProcess(); | |||
| } | |||
| @@ -0,0 +1,365 @@ | |||
| package com.netsdk.common; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.GridLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.border.EmptyBorder; | |||
| import com.netsdk.demo.frame.*; | |||
| import com.netsdk.demo.frame.Attendance.Attendance; | |||
| import com.netsdk.demo.frame.AutoRegister.AutoRegister; | |||
| import com.netsdk.demo.frame.FaceRecognition.NewLatticeScreen; | |||
| import com.netsdk.demo.frame.Gate.Gate; | |||
| import com.netsdk.demo.frame.ThermalCamera.ThermalCamera; | |||
| import com.netsdk.demo.frame.scada.SCADADemo; | |||
| import com.netsdk.demo.frame.vto.VTODemo; | |||
| /** | |||
| * 功能列表界面 | |||
| */ | |||
| public class FunctionList extends JFrame { | |||
| private static final long serialVersionUID = 1L; | |||
| public FunctionList() { | |||
| setTitle(Res.string().getFunctionList()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(450, 300); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| add(new FunctionPanel(), BorderLayout.CENTER); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| dispose(); | |||
| System.exit(0); | |||
| } | |||
| }); | |||
| } | |||
| public class FunctionPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public FunctionPanel() { | |||
| setLayout(new GridLayout(9, 2)); | |||
| setBorder(new EmptyBorder(30, 50, 0, 50)); | |||
| //faceRecognitionBtn = new JButton(Res.string().getFaceRecognition()); | |||
| gateBtn = new JButton(Res.string().getGate()); | |||
| capturePictureBtn = new JButton(Res.string().getCapturePicture()); | |||
| realPlayBtn = new JButton(Res.string().getRealplay()); | |||
| itsEventBtn = new JButton(Res.string().getITSEvent()); | |||
| downloadBtn = new JButton(Res.string().getDownloadRecord()); | |||
| talkBtn = new JButton(Res.string().getTalk()); | |||
| deviceSearchAndInitBtn = new JButton(Res.string().getDeviceSearchAndInit()); | |||
| ptzBtn = new JButton(Res.string().getPTZ()); | |||
| deviceCtlBtn = new JButton(Res.string().getDeviceControl()); | |||
| alarmListenBtn = new JButton(Res.string().getAlarmListen()); | |||
| autoRegisterBtn = new JButton(Res.string().getAutoRegister()); | |||
| attendanceBtn = new JButton(Res.string().getAttendance()); | |||
| thermalCameraBtn = new JButton(Res.string().getThermalCamera()); | |||
| matrixScreenBtn = new JButton(Res.string().getmatrixScreen()); | |||
| humanNumberStatisticBtn = new JButton(Res.string().getHumanNumberStatistic()); | |||
| vtoBtn = new JButton(Res.string().getVTO()); | |||
| SCADABtn = new JButton(Res.string().getSCADA()); | |||
| trafficAllowListBtn = new JButton(Res.string().getTrafficAllowList()); | |||
| add(gateBtn); | |||
| // add(faceRecognitionBtn); | |||
| add(deviceSearchAndInitBtn); | |||
| add(ptzBtn); | |||
| add(realPlayBtn); | |||
| add(capturePictureBtn); | |||
| add(talkBtn); | |||
| add(itsEventBtn); | |||
| add(downloadBtn); | |||
| add(deviceCtlBtn); | |||
| add(alarmListenBtn); | |||
| add(autoRegisterBtn); | |||
| //add(attendanceBtn); | |||
| add(thermalCameraBtn); | |||
| add(matrixScreenBtn); | |||
| add(humanNumberStatisticBtn); | |||
| add(vtoBtn); | |||
| add(SCADABtn); | |||
| add(trafficAllowListBtn); | |||
| gateBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| Gate.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| /* faceRecognitionBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| FaceRecognition.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| */ | |||
| capturePictureBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| CapturePicture.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| realPlayBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| RealPlay.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| downloadBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| DownLoadRecord.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| talkBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| Talk.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| itsEventBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| TrafficEvent.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| deviceSearchAndInitBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| DeviceSearchAndInit.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| ptzBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| PTZControl.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| deviceCtlBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| DeviceControl.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| alarmListenBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| AlarmListen.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| autoRegisterBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| AutoRegister.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| attendanceBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| Attendance.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| thermalCameraBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| ThermalCamera.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| matrixScreenBtn.addActionListener(new ActionListener() { | |||
| @Override public void actionPerformed(ActionEvent e) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() | |||
| { | |||
| dispose(); | |||
| NewLatticeScreen.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| humanNumberStatisticBtn.addActionListener(new ActionListener() { | |||
| @Override public void actionPerformed(ActionEvent e) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() | |||
| { | |||
| dispose(); | |||
| HumanNumberStatistic.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| vtoBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| dispose(); | |||
| VTODemo.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| SCADABtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| dispose(); | |||
| SCADADemo.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| trafficAllowListBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| dispose(); | |||
| TrafficAllowList.main(null); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /* | |||
| * 功能列表组件 | |||
| */ | |||
| //private JButton faceRecognitionBtn; | |||
| private JButton capturePictureBtn; | |||
| private JButton realPlayBtn; | |||
| private JButton downloadBtn; | |||
| private JButton itsEventBtn; | |||
| private JButton talkBtn; | |||
| private JButton deviceSearchAndInitBtn; | |||
| private JButton ptzBtn; | |||
| private JButton deviceCtlBtn; | |||
| private JButton alarmListenBtn; | |||
| private JButton autoRegisterBtn; | |||
| private JButton attendanceBtn; | |||
| private JButton gateBtn; | |||
| private JButton thermalCameraBtn; | |||
| private JButton matrixScreenBtn; | |||
| private JButton humanNumberStatisticBtn; | |||
| private JButton vtoBtn; | |||
| /** | |||
| * 动环主机按钮 | |||
| */ | |||
| private JButton SCADABtn; | |||
| /** | |||
| * 允许名单注册 | |||
| */ | |||
| private JButton trafficAllowListBtn; | |||
| } | |||
| } | |||
| @@ -0,0 +1,35 @@ | |||
| package com.netsdk.common; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import javax.swing.JDialog; | |||
| /* | |||
| * 智能交通列表双击展示图片框架 | |||
| */ | |||
| public class ListPictureShowDialog extends JDialog { | |||
| private static final long serialVersionUID = 1L; | |||
| public ListPictureShowDialog() { | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(800, 600); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| listPanel = new PaintPanel(); | |||
| add(listPanel, BorderLayout.CENTER); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| public PaintPanel listPanel; | |||
| } | |||
| @@ -0,0 +1,115 @@ | |||
| package com.netsdk.common; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionListener; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JPasswordField; | |||
| import javax.swing.JTextField; | |||
| import com.netsdk.lib.ToolKits; | |||
| /* | |||
| * 登陆面板 | |||
| */ | |||
| public class LoginPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| //登陆参数 | |||
| private String s_strIp = "192.168.69.142";/*"172.23.12.17";*/ //"192.168.7.61"; | |||
| private Integer s_nPort = new Integer("37777"); | |||
| private String s_strUser = "admin"; | |||
| private String s_strPassword = "yzx123456"; | |||
| public LoginPanel() { | |||
| BorderEx.set(this, Res.string().getLogin(), 2); | |||
| setLayout(new FlowLayout()); | |||
| //////////////////////////////// | |||
| loginBtn = new JButton(Res.string().getLogin()); | |||
| logoutBtn = new JButton(Res.string().getLogout()); | |||
| ipLabel = new JLabel(Res.string().getDeviceIp()); | |||
| portLabel = new JLabel(" " + Res.string().getPort()); | |||
| nameLabel = new JLabel(" " + Res.string().getUserName()); | |||
| passwordLabel = new JLabel(" " + Res.string().getPassword()); | |||
| ipTextArea = new JTextField(s_strIp); | |||
| nameTextArea = new JTextField(s_strUser); | |||
| passwordTextArea = new JPasswordField(s_strPassword); | |||
| portTextArea = new JTextField(s_nPort.toString()); | |||
| add(ipLabel); | |||
| add(ipTextArea); | |||
| add(portLabel); | |||
| add(portTextArea); | |||
| add(nameLabel); | |||
| add(nameTextArea); | |||
| add(passwordLabel); | |||
| add(passwordTextArea); | |||
| add(loginBtn); | |||
| add(logoutBtn); | |||
| ipTextArea.setPreferredSize(new Dimension(90, 20)); | |||
| nameTextArea.setPreferredSize(new Dimension(90, 20)); | |||
| passwordTextArea.setPreferredSize(new Dimension(90, 20)); | |||
| portTextArea.setPreferredSize(new Dimension(90, 20)); | |||
| loginBtn.setPreferredSize(new Dimension(80, 20)); | |||
| logoutBtn.setPreferredSize(new Dimension(80, 20)); | |||
| ToolKits.limitTextFieldLength(portTextArea, 6); | |||
| logoutBtn.setEnabled(false); | |||
| } | |||
| public void addLoginBtnActionListener(ActionListener e) { | |||
| loginBtn.addActionListener(e); | |||
| } | |||
| public void addLogoutBtnActionListener(ActionListener e) { | |||
| logoutBtn.addActionListener(e); | |||
| } | |||
| public void setButtonEnable(boolean bln) { | |||
| loginBtn.setEnabled(!bln); | |||
| logoutBtn.setEnabled(bln); | |||
| } | |||
| public boolean checkLoginText() { | |||
| if(ipTextArea.getText().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInputDeviceIP(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| if(portTextArea.getText().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInputDevicePort(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| if(nameTextArea.getText().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInputUsername(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| if(new String(passwordTextArea.getPassword()).equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInputPassword(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| public JLabel nameLabel; | |||
| public JLabel passwordLabel; | |||
| public JLabel ipLabel; | |||
| public JLabel portLabel; | |||
| public JTextField ipTextArea; | |||
| public JTextField portTextArea; | |||
| public JTextField nameTextArea; | |||
| public JPasswordField passwordTextArea; | |||
| public JButton loginBtn; | |||
| public JButton logoutBtn; | |||
| } | |||
| @@ -0,0 +1,35 @@ | |||
| package com.netsdk.common; | |||
| import java.awt.Color; | |||
| import java.awt.Graphics; | |||
| import java.awt.Image; | |||
| import javax.swing.JPanel; | |||
| /* | |||
| * 带背景的绘图面板 | |||
| */ | |||
| public class PaintPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| private Image image; //背景图片 | |||
| public PaintPanel() { | |||
| super(); | |||
| setOpaque(true); //非透明 | |||
| setLayout(null); | |||
| setBackground(Color.GRAY); | |||
| setForeground(new Color(0, 0, 0)); | |||
| } | |||
| //设置图片的方法 | |||
| public void setImage(Image image) { | |||
| this.image = image; | |||
| } | |||
| protected void paintComponent(Graphics g) { //重写绘制组件外观 | |||
| if(image != null) { | |||
| g.drawImage(image, 0, 0, getWidth(), getHeight(), this);//绘制图片与组件大小相同 | |||
| } | |||
| super.paintComponent(g); // 执行超类方法 | |||
| } | |||
| } | |||
| @@ -0,0 +1,76 @@ | |||
| package com.netsdk.common; | |||
| import java.io.File; | |||
| import com.netsdk.lib.ToolKits; | |||
| public class SavePath { | |||
| private SavePath() {} | |||
| private static class SavePathHolder { | |||
| private static SavePath instance = new SavePath(); | |||
| } | |||
| public static SavePath getSavePath() { | |||
| return SavePathHolder.instance; | |||
| } | |||
| String s_captureSavePath = "./Capture/" + ToolKits.getDay() + "/"; // 抓拍图片保存路径 | |||
| String s_imageSavePath = "./Image/" + ToolKits.getDay() + "/"; // 图片保存路径 | |||
| String s_recordFileSavePath = "./RecordFile/" + ToolKits.getDay() + "/"; // 录像保存路径 | |||
| /* | |||
| * 设置抓图保存路径 | |||
| */ | |||
| public String getSaveCapturePath() { | |||
| File path1 = new File("./Capture/"); | |||
| if (!path1.exists()) { | |||
| path1.mkdir(); | |||
| } | |||
| File path2 = new File(s_captureSavePath); | |||
| if (!path2.exists()) { | |||
| path2.mkdir(); | |||
| } | |||
| String strFileName = path2.getAbsolutePath() + "/" + ToolKits.getDate() + ".jpg"; | |||
| return strFileName; | |||
| } | |||
| /* | |||
| * 设置智能交通图片保存路径 | |||
| */ | |||
| public String getSaveTrafficImagePath() { | |||
| File path1 = new File("./Image/"); | |||
| if (!path1.exists()) { | |||
| path1.mkdir(); | |||
| } | |||
| File path = new File(s_imageSavePath); | |||
| if (!path.exists()) { | |||
| path.mkdir(); | |||
| } | |||
| return s_imageSavePath; | |||
| } | |||
| /* | |||
| * 设置录像保存路径 | |||
| */ | |||
| public String getSaveRecordFilePath() { | |||
| File path1 = new File("./RecordFile/"); | |||
| if (!path1.exists()) { | |||
| path1.mkdir(); | |||
| } | |||
| File path2 = new File(s_recordFileSavePath); | |||
| if (!path2.exists()) { | |||
| path2.mkdir(); | |||
| } | |||
| String SavedFileName = s_recordFileSavePath + ToolKits.getDate() + ".dav"; // 默认保存路径 | |||
| return SavedFileName; | |||
| } | |||
| } | |||
| @@ -0,0 +1,105 @@ | |||
| package com.netsdk.common; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.Frame; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.ItemEvent; | |||
| import java.awt.event.ItemListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.UIManager; | |||
| import javax.swing.border.EmptyBorder; | |||
| import com.netsdk.common.Res.LanguageType; | |||
| /** | |||
| * 选择语言界面Demo | |||
| */ | |||
| public class SwitchLanguage extends JFrame{ | |||
| private static final long serialVersionUID = 1L; | |||
| public SwitchLanguage() { | |||
| setTitle("请选择语言/Please Select Language"); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(350, 200); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| add(new SwitchLanguagePanel(this), BorderLayout.CENTER); | |||
| this.addWindowListener(new WindowAdapter() { | |||
| @Override | |||
| public void windowClosing(WindowEvent e) { | |||
| dispose(); | |||
| System.exit(0); | |||
| } | |||
| }); | |||
| } | |||
| /* | |||
| * 切换语言面板 | |||
| */ | |||
| public class SwitchLanguagePanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public SwitchLanguagePanel(final Frame frame) { | |||
| setLayout(new FlowLayout()); | |||
| setBorder(new EmptyBorder(50, 0, 0, 0)); | |||
| String[] CnEn = {"简体中文", "English"}; | |||
| jComboBox = new JComboBox(CnEn); | |||
| nextButton = new JButton("下一步"); | |||
| add(jComboBox); | |||
| add(nextButton); | |||
| jComboBox.addItemListener(new ItemListener() { | |||
| @Override | |||
| public void itemStateChanged(ItemEvent arg0) { | |||
| LanguageType type = jComboBox.getSelectedIndex() == 0 ? LanguageType.Chinese : LanguageType.English; | |||
| Res.string().switchLanguage(type); | |||
| if(jComboBox.getSelectedIndex() == 0) { | |||
| nextButton.setText("下一步"); | |||
| } else { | |||
| nextButton.setText("next"); | |||
| } | |||
| } | |||
| }); | |||
| nextButton.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.dispose(); | |||
| FunctionList functiondemo = new FunctionList(); | |||
| functiondemo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| private JComboBox jComboBox; | |||
| private JButton nextButton; | |||
| } | |||
| } | |||
| @@ -0,0 +1,5 @@ | |||
| package com.netsdk.common; | |||
| public interface WindowCloseListener { | |||
| void windowClosing(); | |||
| } | |||
| @@ -0,0 +1,116 @@ | |||
| package com.netsdk.demo; | |||
| import com.netsdk.demo.util.CaseMenu; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.callback.impl.DefaultDisconnectCallback; | |||
| import com.netsdk.lib.callback.impl.DefaultHaveReconnectCallBack; | |||
| import com.netsdk.module.BaseModule; | |||
| import com.netsdk.module.entity.DeviceInfo; | |||
| /** | |||
| * @author 47081 | |||
| * @version 1.0 | |||
| * @description 基础demo,包括一些基础接口如初始化,登录,登出 | |||
| * @date 2020/10/21 | |||
| */ | |||
| public class BaseDemo { | |||
| private NetSDKLib netSdkApi = NetSDKLib.NETSDK_INSTANCE; | |||
| /** 二次封装模块,包含一些基础接口 */ | |||
| private BaseModule baseModule; | |||
| private long loginHandler; | |||
| private long attachHandler; | |||
| private CaseMenu caseMenu; | |||
| public BaseDemo() { | |||
| baseModule = new BaseModule(netSdkApi); | |||
| caseMenu = new CaseMenu(); | |||
| } | |||
| public void addItem(CaseMenu.Item item) { | |||
| caseMenu.addItem(item); | |||
| } | |||
| public void run() { | |||
| caseMenu.run(); | |||
| } | |||
| /** | |||
| * sdk初始化 | |||
| * | |||
| * @return | |||
| */ | |||
| public boolean init() { | |||
| return baseModule.init( | |||
| DefaultDisconnectCallback.getINSTANCE(), DefaultHaveReconnectCallBack.getINSTANCE(), true); | |||
| } | |||
| /** 释放sdk资源 */ | |||
| public void clean() { | |||
| baseModule.clean(); | |||
| } | |||
| /** | |||
| * 登录设备 | |||
| * | |||
| * @param ip 设备ip | |||
| * @param port 设备端口 | |||
| * @param username 用户名 | |||
| * @param password 密码 | |||
| * @return | |||
| */ | |||
| public boolean login(String ip, int port, String username, String password) { | |||
| DeviceInfo info = baseModule.login(ip, port, username, password); | |||
| loginHandler = info.getLoginHandler(); | |||
| return loginHandler != 0; | |||
| } | |||
| /** | |||
| * 登出 | |||
| * | |||
| * @return | |||
| */ | |||
| public boolean logout() { | |||
| return baseModule.logout(loginHandler); | |||
| } | |||
| public NetSDKLib getNetSdkApi() { | |||
| return netSdkApi; | |||
| } | |||
| public void setNetSdkApi(NetSDKLib netSdkApi) { | |||
| this.netSdkApi = netSdkApi; | |||
| } | |||
| public BaseModule getBaseModule() { | |||
| return baseModule; | |||
| } | |||
| public void setBaseModule(BaseModule baseModule) { | |||
| this.baseModule = baseModule; | |||
| } | |||
| public long getLoginHandler() { | |||
| return loginHandler; | |||
| } | |||
| public void setLoginHandler(long loginHandler) { | |||
| this.loginHandler = loginHandler; | |||
| } | |||
| public long getAttachHandler() { | |||
| return attachHandler; | |||
| } | |||
| public void setAttachHandler(long attachHandler) { | |||
| this.attachHandler = attachHandler; | |||
| } | |||
| public CaseMenu getCaseMenu() { | |||
| return caseMenu; | |||
| } | |||
| public void setCaseMenu(CaseMenu caseMenu) { | |||
| this.caseMenu = caseMenu; | |||
| } | |||
| } | |||
| @@ -0,0 +1,133 @@ | |||
| package com.netsdk.demo; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.DeviceLogModule; | |||
| import com.netsdk.demo.module.GateModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.structure.NET_TIME; | |||
| import com.sun.jna.Pointer; | |||
| import javax.imageio.ImageIO; | |||
| import java.awt.image.BufferedImage; | |||
| import java.io.ByteArrayInputStream; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.UnsupportedEncodingException; | |||
| public class DeviceLogDemo { | |||
| // 设备断线通知回调 | |||
| private static DisConnect disConnect = new DisConnect(); | |||
| // 网络连接恢复 | |||
| private static HaveReConnect haveReConnect = new HaveReConnect(); | |||
| // 订阅句柄 | |||
| public static NetSDKLib.LLong m_hAttachHandle = new NetSDKLib.LLong(0); | |||
| private AnalyzerDataCB analyzerCallback = new AnalyzerDataCB(); | |||
| public static void main(String[] args) { | |||
| //初始化 | |||
| LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 | |||
| //登录 | |||
| login(); | |||
| NET_TIME startTime = new NET_TIME(2023,10,7,0,0,0); | |||
| NET_TIME endTime = new NET_TIME(2023,10,8,0,0,0); | |||
| //查询系统日志 | |||
| getAllSystemLog(startTime,endTime); | |||
| //登出 | |||
| logout(); | |||
| } | |||
| /** | |||
| * 获取开门记录 | |||
| * @param startTime | |||
| * @param endTime | |||
| * @return | |||
| */ | |||
| public static boolean getAllSystemLog(NET_TIME startTime,NET_TIME endTime){ | |||
| DeviceLogModule.getSystemLog(startTime,endTime); | |||
| return true; | |||
| } | |||
| private static class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| // 断线提示 | |||
| System.out.println(Res.string().getGate() + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| } | |||
| // 网络连接恢复,设备重连成功回调 | |||
| // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 | |||
| private static class HaveReConnect implements NetSDKLib.fHaveReConnect { | |||
| public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| // 重连提示 | |||
| System.out.println(Res.string().getGate() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| //消息订阅 | |||
| private class AnalyzerDataCB implements NetSDKLib.fAnalyzerDataCallBack { | |||
| private BufferedImage gateBufferedImage = null; | |||
| public int invoke(NetSDKLib.LLong lAnalyzerHandle, int dwAlarmType, | |||
| Pointer pAlarmInfo, Pointer pBuffer, int dwBufSize, | |||
| Pointer dwUser, int nSequence, Pointer reserved) | |||
| { | |||
| if (lAnalyzerHandle.longValue() == 0 || pAlarmInfo == null) { | |||
| return -1; | |||
| } | |||
| File path = new File("./GateSnapPicture/"); | |||
| if (!path.exists()) { | |||
| path.mkdir(); | |||
| } | |||
| ///< 门禁事件 | |||
| if(dwAlarmType == NetSDKLib.EVENT_IVS_ACCESS_CTL) { | |||
| NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO msg = new NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO(); | |||
| ToolKits.GetPointerData(pAlarmInfo, msg); | |||
| // 保存图片,获取图片缓存 | |||
| String snapPicPath = path + "\\" + System.currentTimeMillis() + "GateSnapPicture.jpg"; // 保存图片地址 | |||
| byte[] buffer = pBuffer.getByteArray(0, dwBufSize); | |||
| ByteArrayInputStream byteArrInputGlobal = new ByteArrayInputStream(buffer); | |||
| try { | |||
| gateBufferedImage = ImageIO.read(byteArrInputGlobal); | |||
| if(gateBufferedImage != null) { | |||
| ImageIO.write(gateBufferedImage, "jpg", new File(snapPicPath)); | |||
| } | |||
| } catch (IOException e2) { | |||
| e2.printStackTrace(); | |||
| } | |||
| // 图片以及门禁信息界面显示 | |||
| } | |||
| return 0; | |||
| } | |||
| } | |||
| // 登录 | |||
| public static boolean login() { | |||
| if(LoginModule.login("192.168.69.142", | |||
| Integer.parseInt("37777"), | |||
| "admin", | |||
| "yzx123456")) { | |||
| // 登陆成功,将通道添加到控件 | |||
| } else { | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| // 登出 | |||
| public static void logout() { | |||
| LoginModule.logout(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,185 @@ | |||
| package com.netsdk.demo; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.GateModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.sun.jna.Pointer; | |||
| import javax.imageio.ImageIO; | |||
| import java.awt.image.BufferedImage; | |||
| import java.io.ByteArrayInputStream; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.UnsupportedEncodingException; | |||
| public class GateDemo { | |||
| // 设备断线通知回调 | |||
| private static DisConnect disConnect = new DisConnect(); | |||
| // 网络连接恢复 | |||
| private static HaveReConnect haveReConnect = new HaveReConnect(); | |||
| // 订阅句柄 | |||
| public static NetSDKLib.LLong m_hAttachHandle = new NetSDKLib.LLong(0); | |||
| private AnalyzerDataCB analyzerCallback = new AnalyzerDataCB(); | |||
| public static void main(String[] args) { | |||
| //初始化 | |||
| LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 | |||
| //登录 | |||
| login(); | |||
| //查询开门记录 | |||
| NetSDKLib.NET_TIME time = new NetSDKLib.NET_TIME(); | |||
| time.dwYear = 2023; | |||
| time.dwMonth = 9; | |||
| time.dwDay = 28; | |||
| getAllRecord(time); | |||
| //登出 | |||
| logout(); | |||
| } | |||
| /** | |||
| * 获取开门记录 | |||
| * @param time | |||
| * @return | |||
| */ | |||
| public static boolean getAllRecord(NetSDKLib.NET_TIME time){ | |||
| int count = 0; | |||
| int index = 0; | |||
| int nFindCount = 10; | |||
| // 日期: 为空,查询所有开门信息 | |||
| // 获取查询句柄 | |||
| if(!GateModule.findRecord(time)) { | |||
| return false; | |||
| } | |||
| // 查询具体信息 | |||
| while(true) { | |||
| NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARDREC[] pstRecord = GateModule.findNextRecord(nFindCount); | |||
| if(pstRecord == null) { | |||
| break; | |||
| } | |||
| for(int i = 0; i < pstRecord.length; i++) { | |||
| index = i + count * nFindCount; | |||
| try { | |||
| StringBuilder sb = new StringBuilder(); | |||
| sb.append("位置序号:").append(index).append("\n");// 位置序号 | |||
| sb.append("时间序号:").append(pstRecord[i].stuTime.dwYear) | |||
| .append(String.format("%02d", pstRecord[i].stuTime.dwMonth))//占位 | |||
| .append(String.format("%02d", pstRecord[i].stuTime.dwDay)).append("\n");//占位 | |||
| sb.append("记录编号:").append(pstRecord[i].nRecNo).append("\n"); // 序号 | |||
| sb.append("卡号:").append(new String(pstRecord[i].szCardNo).trim()).append("\n"); // 卡号 | |||
| sb.append("卡名:").append(new String(pstRecord[i].szCardName, "GBK").trim()).append("\n"); // 卡名 -> employeeName | |||
| sb.append("用户ID:").append(new String(pstRecord[i].szUserID).trim()).append("\n"); // 用户ID -> employeeNo | |||
| sb.append("卡密:").append(new String(pstRecord[i].szPwd).trim()).append("\n"); // 卡密码 | |||
| sb.append("刷卡结果:").append(pstRecord[i].bStatus).append("\n"); // 刷卡结果 | |||
| sb.append("开门方式:").append(Res.string().getOpenMethods(pstRecord[i].emMethod)).append("\n"); // 开门方式 | |||
| sb.append("开门方式:").append(pstRecord[i].emMethod).append("\n"); // 开门方式 | |||
| pstRecord[i].stuTime.dwHour = pstRecord[i].stuTime.dwHour + 8; | |||
| sb.append("刷卡时间:").append(pstRecord[i].stuTime.toStringTimeEx()).append("\n"); // 刷卡时间 | |||
| sb.append("人脸图片地址:").append(new String(pstRecord[i].szSnapFtpUrl).trim()).append("\n"); //人脸图片地址 | |||
| System.out.println("sb = " + sb); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| if (pstRecord.length < nFindCount) { | |||
| break; | |||
| } else { | |||
| count ++; | |||
| } | |||
| } | |||
| // 关闭查询接口 | |||
| GateModule.findRecordClose(); | |||
| return true; | |||
| } | |||
| private static class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| // 断线提示 | |||
| System.out.println(Res.string().getGate() + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| } | |||
| // 网络连接恢复,设备重连成功回调 | |||
| // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 | |||
| private static class HaveReConnect implements NetSDKLib.fHaveReConnect { | |||
| public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| // 重连提示 | |||
| System.out.println(Res.string().getGate() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| //消息订阅 | |||
| private class AnalyzerDataCB implements NetSDKLib.fAnalyzerDataCallBack { | |||
| private BufferedImage gateBufferedImage = null; | |||
| public int invoke(NetSDKLib.LLong lAnalyzerHandle, int dwAlarmType, | |||
| Pointer pAlarmInfo, Pointer pBuffer, int dwBufSize, | |||
| Pointer dwUser, int nSequence, Pointer reserved) | |||
| { | |||
| if (lAnalyzerHandle.longValue() == 0 || pAlarmInfo == null) { | |||
| return -1; | |||
| } | |||
| File path = new File("./GateSnapPicture/"); | |||
| if (!path.exists()) { | |||
| path.mkdir(); | |||
| } | |||
| ///< 门禁事件 | |||
| if(dwAlarmType == NetSDKLib.EVENT_IVS_ACCESS_CTL) { | |||
| NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO msg = new NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO(); | |||
| ToolKits.GetPointerData(pAlarmInfo, msg); | |||
| // 保存图片,获取图片缓存 | |||
| String snapPicPath = path + "\\" + System.currentTimeMillis() + "GateSnapPicture.jpg"; // 保存图片地址 | |||
| byte[] buffer = pBuffer.getByteArray(0, dwBufSize); | |||
| ByteArrayInputStream byteArrInputGlobal = new ByteArrayInputStream(buffer); | |||
| try { | |||
| gateBufferedImage = ImageIO.read(byteArrInputGlobal); | |||
| if(gateBufferedImage != null) { | |||
| ImageIO.write(gateBufferedImage, "jpg", new File(snapPicPath)); | |||
| } | |||
| } catch (IOException e2) { | |||
| e2.printStackTrace(); | |||
| } | |||
| // 图片以及门禁信息界面显示 | |||
| } | |||
| return 0; | |||
| } | |||
| } | |||
| // 登录 | |||
| public static boolean login() { | |||
| if(LoginModule.login("192.168.69.142", | |||
| Integer.parseInt("37777"), | |||
| "admin", | |||
| "yzx123456")) { | |||
| // 登陆成功,将通道添加到控件 | |||
| } else { | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| // 登出 | |||
| public static void logout() { | |||
| LoginModule.logout(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,27 @@ | |||
| package com.netsdk.demo; | |||
| import com.netsdk.lib.callback.impl.DefaultDisconnectCallback; | |||
| import com.netsdk.lib.callback.impl.DefaultHaveReconnectCallBack; | |||
| import com.netsdk.lib.enumeration.ENUMERROR; | |||
| import com.netsdk.module.BaseModule; | |||
| import com.netsdk.module.entity.DeviceInfo; | |||
| public class NetSDKDemo { | |||
| public static void main(String[] args) { | |||
| BaseModule baseModule = new BaseModule(); | |||
| baseModule.init( | |||
| DefaultDisconnectCallback.getINSTANCE(), DefaultHaveReconnectCallBack.getINSTANCE(), true); | |||
| DeviceInfo info = baseModule.login("192.168.69.142", 37777, "admin", "yzx123456"); | |||
| if (info.getLoginHandler() != 0L) { | |||
| System.out.println("login success."); | |||
| // 登出 | |||
| if (baseModule.logout(info.getLoginHandler())) { | |||
| System.out.println("logout success."); | |||
| } else { | |||
| System.out.println("logout failed.error is " + ENUMERROR.getErrorMessage()); | |||
| } | |||
| } | |||
| baseModule.clean(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,143 @@ | |||
| package com.netsdk.demo; | |||
| import com.netsdk.demo.BaseDemo; | |||
| import com.netsdk.demo.callback.RealPlayByDataTypeCallback; | |||
| import com.netsdk.demo.util.CaseMenu; | |||
| import com.netsdk.lib.callback.impl.DefaultRealPlayCallback; | |||
| import com.netsdk.lib.enumeration.EM_AUDIO_DATA_TYPE; | |||
| import com.netsdk.lib.enumeration.EM_REAL_DATA_TYPE; | |||
| import com.netsdk.lib.enumeration.ENUMERROR; | |||
| import com.netsdk.module.PlayModule; | |||
| import java.io.File; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Scanner; | |||
| import java.util.UUID; | |||
| /** | |||
| * @author 47081 | |||
| * @version 1.0 | |||
| * @description 转码流demo | |||
| * @date 2021/3/2 | |||
| */ | |||
| public class RealPlayByDataTypeDemo extends BaseDemo { | |||
| private final PlayModule playModule; | |||
| private long realPlay; | |||
| /** | |||
| * 生成一个随机文件名称 | |||
| * | |||
| * @param postfix | |||
| * @return | |||
| */ | |||
| private String createFileName(String postfix) { | |||
| /*String absolutePath = this.getClass().getClassLoader().getResource("").getPath(); | |||
| File file = new File(absolutePath); | |||
| if (!file.exists()) { | |||
| file.mkdirs(); | |||
| }*/ | |||
| String uuid = UUID.randomUUID().toString().substring(0, 4).replace(".", "").replace("-", ""); | |||
| SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
| String date = simpleDate.format(new java.util.Date()).replace(" ", "_").replace(":", "-"); | |||
| /*if (!(absolutePath.endsWith("/") || absolutePath.endsWith("\\"))) { | |||
| absolutePath += "/"; | |||
| }*/ | |||
| return uuid + "-" + date + "." + postfix; | |||
| } | |||
| public RealPlayByDataTypeDemo() { | |||
| playModule = new PlayModule(); | |||
| } | |||
| public void detach() { | |||
| if (playModule.stopRealPlayByDataType(realPlay)) { | |||
| realPlay = 0; | |||
| } else { | |||
| System.out.println(ENUMERROR.getErrorMessage()); | |||
| } | |||
| } | |||
| public void attachDav() { | |||
| // demo同一时间只拉一个流,支持拉多个流 | |||
| if (realPlay != 0) { | |||
| detach(); | |||
| } | |||
| realPlay = | |||
| playModule.realPlayByDataType( | |||
| getLoginHandler(), | |||
| 0, | |||
| EM_REAL_DATA_TYPE.EM_REAL_DATA_TYPE_PRIVATE, | |||
| EM_AUDIO_DATA_TYPE.EM_AUDIO_DATA_TYPE_AAC, | |||
| RealPlayByDataTypeCallback.getInstance(), | |||
| 0, | |||
| null, | |||
| createFileName("dav"), | |||
| 3000); | |||
| } | |||
| public void attachFlv() { | |||
| // demo同一时间只拉一个流,支持拉多个流 | |||
| if (realPlay != 0) { | |||
| detach(); | |||
| } | |||
| realPlay = | |||
| playModule.realPlayByDataType( | |||
| getLoginHandler(), | |||
| 0, | |||
| EM_REAL_DATA_TYPE.EM_REAL_DATA_TYPE_FLV_STREAM, | |||
| EM_AUDIO_DATA_TYPE.EM_AUDIO_DATA_TYPE_AAC, | |||
| RealPlayByDataTypeCallback.getInstance(), | |||
| 0, | |||
| null, | |||
| createFileName("flv"), | |||
| 3000); | |||
| } | |||
| public static void main(String[] args) { | |||
| String ip = "172.23.12.231"; | |||
| int port = 37777; | |||
| String username = "admin"; | |||
| String password = "admin123"; | |||
| Scanner scanner = new Scanner(System.in); | |||
| String defaultConfig = "ip:%s,port:%d,username:%s,password:%s,需要修改吗?(y/n)"; | |||
| defaultConfig = String.format(defaultConfig, ip, port, username, password); | |||
| System.out.println(defaultConfig); | |||
| String answer = ""; | |||
| do { | |||
| answer = scanner.nextLine(); | |||
| if ("y".equalsIgnoreCase(answer) || "yes".equalsIgnoreCase(answer)) { | |||
| System.out.println("please input ip"); | |||
| ip = scanner.nextLine().trim(); | |||
| System.out.println("please input port:"); | |||
| port = Integer.parseInt(scanner.nextLine()); | |||
| System.out.println("please input username:"); | |||
| username = scanner.nextLine().trim(); | |||
| System.out.println("please input password:"); | |||
| password = scanner.nextLine().trim(); | |||
| break; | |||
| } else if ("n".equalsIgnoreCase(answer) || "no".equalsIgnoreCase(answer)) { | |||
| break; | |||
| } | |||
| System.out.println("please input the right word.y/yes/n/no,try again."); | |||
| } while (!(answer.equalsIgnoreCase("y") | |||
| || answer.equalsIgnoreCase("yes") | |||
| || answer.equalsIgnoreCase("no") | |||
| || answer.equalsIgnoreCase("n"))); | |||
| RealPlayByDataTypeDemo demo = new RealPlayByDataTypeDemo(); | |||
| // sdk初始化 | |||
| demo.init(); | |||
| demo.addItem(new CaseMenu.Item(demo, "转码flv", "attachFlv")); | |||
| demo.addItem(new CaseMenu.Item(demo, "私有流", "attachDav")); | |||
| demo.addItem(new CaseMenu.Item(demo, "停止拉流", "detach")); | |||
| // 登录设备 | |||
| if (demo.login(ip, port, username, password)) { | |||
| // 登录成功后 | |||
| demo.run(); | |||
| } | |||
| // 登出设备 | |||
| demo.logout(); | |||
| // 测试结束,释放sdk资源 | |||
| demo.clean(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,51 @@ | |||
| package com.netsdk.demo.callback; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.sun.jna.Pointer; | |||
| /** | |||
| * @author 47081 | |||
| * @version 1.0 | |||
| * @description 数据回调函数 | |||
| * @date 2021/3/9 | |||
| */ | |||
| public class RealPlayByDataTypeCallback implements NetSDKLib.fRealDataCallBackEx2 { | |||
| private static volatile RealPlayByDataTypeCallback instance; | |||
| private RealPlayByDataTypeCallback() {} | |||
| public static RealPlayByDataTypeCallback getInstance() { | |||
| if (instance == null) { | |||
| synchronized (RealPlayByDataTypeCallback.class) { | |||
| if (instance == null) { | |||
| instance = new RealPlayByDataTypeCallback(); | |||
| } | |||
| } | |||
| } | |||
| return instance; | |||
| } | |||
| @Override | |||
| public void invoke( | |||
| NetSDKLib.LLong lRealHandle, | |||
| int dwDataType, | |||
| Pointer pBuffer, | |||
| int dwBufSize, | |||
| NetSDKLib.LLong param, | |||
| Pointer dwUser) { | |||
| // 依据dwDataType进行码流类型判断 | |||
| // 私有流或mp4,出来的码流均为私有流 | |||
| if (dwDataType == 0 || dwDataType == 1003) { | |||
| // 私有流 | |||
| } else { | |||
| // 转码码流 | |||
| int type = dwDataType - 1000; | |||
| /** | |||
| * EM_REAL_DATA_TYPE_PRIVATE(0, "私有码流"), EM_REAL_DATA_TYPE_GBPS(1, "国标PS码流"), | |||
| * EM_REAL_DATA_TYPE_TS(2, "TS码流"), EM_REAL_DATA_TYPE_MP4(3, "MP4文件"), | |||
| * EM_REAL_DATA_TYPE_H264(4, "裸H264码流"), EM_REAL_DATA_TYPE_FLV_STREAM(5, "流式FLV"); | |||
| */ | |||
| } | |||
| System.out.println("dwDataType: " + dwDataType); | |||
| } | |||
| } | |||
| @@ -0,0 +1,450 @@ | |||
| package com.netsdk.demo.frame; | |||
| import java.awt.*; | |||
| import java.awt.event.*; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.*; | |||
| import javax.swing.*; | |||
| import javax.swing.table.*; | |||
| import com.sun.jna.NativeLong; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.FunctionList; | |||
| import com.netsdk.common.LoginPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.AlarmListenModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.ToolKits; | |||
| /** | |||
| * Alarm Listen Demo | |||
| */ | |||
| class AlarmListenFrame extends JFrame{ | |||
| private static final long serialVersionUID = 1L; | |||
| // device disconnect callback instance | |||
| private DisConnect disConnect = new DisConnect(); | |||
| // device reconnect callback instance | |||
| private static HaveReConnect haveReConnect = new HaveReConnect(); | |||
| // alarm listen frame (this) | |||
| private static JFrame frame = new JFrame(); | |||
| private java.awt.Component target = this; | |||
| // alarm event info list | |||
| Vector<AlarmEventInfo> data = new Vector<AlarmEventInfo>(); | |||
| public AlarmListenFrame() { | |||
| setTitle(Res.string().getAlarmListen()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(800, 530); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| LoginModule.init(disConnect, haveReConnect); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| loginPanel = new LoginPanel(); | |||
| alarmListenPanel = new AlarmListenPanel(); | |||
| showAlarmPanel = new ShowAlarmEventPanel(); | |||
| JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, loginPanel, alarmListenPanel); | |||
| splitPane.setDividerSize(0); | |||
| add(splitPane, BorderLayout.NORTH); | |||
| add(showAlarmPanel, BorderLayout.CENTER); | |||
| loginPanel.addLoginBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(loginPanel.checkLoginText()) { | |||
| if(login()) { | |||
| frame = ToolKits.getFrame(e); | |||
| frame.setTitle(Res.string().getAlarmListen() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| loginPanel.addLogoutBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| frame.setTitle(Res.string().getAlarmListen()); | |||
| logout(); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| AlarmListenModule.stopListen(); | |||
| LoginModule.logout(); | |||
| LoginModule.cleanup(); | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /////////////////function/////////////////// | |||
| // device disconnect callback class | |||
| // set it's instance by call CLIENT_Init, when device disconnect sdk will call it. | |||
| private class DisConnect implements NetSDKLib.fDisConnect { | |||
| public DisConnect() { } | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getAlarmListen() + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // device reconnect(success) callback class | |||
| // set it's instance by call CLIENT_SetAutoReconnect, when device reconnect success sdk will call it. | |||
| private static class HaveReConnect implements NetSDKLib.fHaveReConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getAlarmListen() + " : " + Res.string().getOnline()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| public boolean login() { | |||
| if(LoginModule.login(loginPanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginPanel.portTextArea.getText()), | |||
| loginPanel.nameTextArea.getText(), | |||
| new String(loginPanel.passwordTextArea.getPassword()))) { | |||
| loginPanel.setButtonEnable(true); | |||
| alarmListenPanel.setButtonEnable(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| public void logout() { | |||
| AlarmListenModule.stopListen(); | |||
| LoginModule.logout(); | |||
| loginPanel.setButtonEnable(false); | |||
| alarmListenPanel.initButtonEnable(); | |||
| showAlarmPanel.clean(); | |||
| } | |||
| public Vector<String> convertAlarmEventInfo(AlarmEventInfo alarmEventInfo) { | |||
| Vector<String> vector = new Vector<String>(); | |||
| vector.add(String.valueOf(alarmEventInfo.id)); | |||
| vector.add(formatDate(alarmEventInfo.date)); | |||
| vector.add(String.valueOf(alarmEventInfo.chn)); | |||
| String status = null; | |||
| if (alarmEventInfo.status == AlarmStatus.ALARM_START) { | |||
| status = Res.string().getStart(); | |||
| }else { | |||
| status = Res.string().getStop(); | |||
| } | |||
| vector.add(alarmMessageMap.get(alarmEventInfo.type) + status); | |||
| return vector; | |||
| } | |||
| private String formatDate(Date date) { | |||
| final SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
| return simpleDate.format(date); | |||
| } | |||
| private fAlarmDataCB cbMessage = new fAlarmDataCB(); | |||
| // alarm listen data callback | |||
| private class fAlarmDataCB implements NetSDKLib.fMessCallBack{ | |||
| private final EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); | |||
| @Override | |||
| public boolean invoke(int lCommand, LLong lLoginID, | |||
| Pointer pStuEvent, int dwBufLen, String strDeviceIP, | |||
| NativeLong nDevicePort, Pointer dwUser) { | |||
| switch (lCommand) { | |||
| case NetSDKLib.NET_ALARM_ALARM_EX: | |||
| case NetSDKLib.NET_MOTION_ALARM_EX: | |||
| case NetSDKLib.NET_VIDEOLOST_ALARM_EX: | |||
| case NetSDKLib.NET_SHELTER_ALARM_EX: | |||
| case NetSDKLib.NET_DISKFULL_ALARM_EX: | |||
| case NetSDKLib.NET_DISKERROR_ALARM_EX: { | |||
| byte []alarm = new byte[dwBufLen]; | |||
| pStuEvent.read(0, alarm, 0, dwBufLen); | |||
| for (int i = 0; i < dwBufLen; i++) { | |||
| if (alarm[i] == 1) { | |||
| AlarmEventInfo alarmEventInfo = new AlarmEventInfo(i, lCommand, AlarmStatus.ALARM_START); | |||
| if (!data.contains(alarmEventInfo)) { | |||
| data.add(alarmEventInfo); | |||
| eventQueue.postEvent(new AlarmListenEvent(target, alarmEventInfo)); | |||
| } | |||
| }else { | |||
| AlarmEventInfo alarmEventInfo = new AlarmEventInfo(i, lCommand, AlarmStatus.ALARM_STOP); | |||
| if (data.remove(alarmEventInfo)) { | |||
| eventQueue.postEvent(new AlarmListenEvent(target, alarmEventInfo)); | |||
| } | |||
| } | |||
| } | |||
| break; | |||
| } | |||
| default: | |||
| break; | |||
| } | |||
| return true; | |||
| } | |||
| } | |||
| // alarm listen event | |||
| class AlarmListenEvent extends AWTEvent { | |||
| private static final long serialVersionUID = 1L; | |||
| public static final int EVENT_ID = AWTEvent.RESERVED_ID_MAX + 1; | |||
| private AlarmEventInfo alarmEventInfo; | |||
| public AlarmListenEvent(Object target, | |||
| AlarmEventInfo alarmEventInfo) { | |||
| super(target,EVENT_ID); | |||
| this.alarmEventInfo = alarmEventInfo; | |||
| ++AlarmEventInfo.index; | |||
| this.alarmEventInfo.id = AlarmEventInfo.index; | |||
| } | |||
| public AlarmEventInfo getAlarmEventInfo() { | |||
| return alarmEventInfo; | |||
| } | |||
| } | |||
| @Override | |||
| protected void processEvent( AWTEvent event) { | |||
| if ( event instanceof AlarmListenEvent) { | |||
| AlarmEventInfo alarmEventInfo = ((AlarmListenEvent)event).getAlarmEventInfo(); | |||
| showAlarmPanel.insert(alarmEventInfo); | |||
| } else { | |||
| super.processEvent(event); | |||
| } | |||
| } | |||
| // alarm listen control panel | |||
| private class AlarmListenPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public AlarmListenPanel() { | |||
| BorderEx.set(this, Res.string().getAlarmListen(), 2); | |||
| setLayout(new FlowLayout()); | |||
| btnStartListen = new JButton(Res.string().getStartListen()); | |||
| btnStopListen = new JButton(Res.string().getStopListen()); | |||
| btnStartListen.setPreferredSize(new Dimension(150, 20)); | |||
| btnStopListen.setPreferredSize(new Dimension(150, 20)); | |||
| add(btnStartListen); | |||
| add(new JLabel(" ")); | |||
| add(btnStopListen); | |||
| initButtonEnable(); | |||
| btnStartListen.addActionListener(new ActionListener(){ | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if (AlarmListenModule.startListen(cbMessage)) { | |||
| setButtonEnable(false); | |||
| }else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getAlarmListenFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| btnStopListen.addActionListener(new ActionListener(){ | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if (AlarmListenModule.stopListen()) { | |||
| showAlarmPanel.clean(); | |||
| setButtonEnable(true); | |||
| }else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| public void setButtonEnable(boolean b) { | |||
| btnStartListen.setEnabled(b); | |||
| btnStopListen.setEnabled(!b); | |||
| } | |||
| public void initButtonEnable() { | |||
| btnStartListen.setEnabled(false); | |||
| btnStopListen.setEnabled(false); | |||
| } | |||
| private JButton btnStartListen; | |||
| private JButton btnStopListen; | |||
| } | |||
| // alarm listen event show panel | |||
| private class ShowAlarmEventPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| private final static int MIN_SHOW_LINES = 20; | |||
| private final static int MAX_SHOW_LINES = 100; | |||
| private int currentRowNums = 0; | |||
| public ShowAlarmEventPanel() { | |||
| BorderEx.set(this, Res.string().getShowAlarmEvent(), 2); | |||
| setLayout(new BorderLayout()); | |||
| Vector<String> columnNames = new Vector<String>(); | |||
| columnNames.add(Res.string().getIndex()); // index | |||
| columnNames.add(Res.string().getEventTime()); // event time | |||
| columnNames.add(Res.string().getChannel()); // channel | |||
| columnNames.add(Res.string().getAlarmMessage()); // alarm message | |||
| tableModel = new DefaultTableModel(null, columnNames); | |||
| table = new JTable(tableModel) { | |||
| private static final long serialVersionUID = 1L; | |||
| public boolean isCellEditable(int rowIndex, int columnIndex) { | |||
| return false; | |||
| } | |||
| }; | |||
| tableModel.setRowCount(MIN_SHOW_LINES); // set min show lines | |||
| table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | |||
| table.getColumnModel().getColumn(0).setPreferredWidth(90); | |||
| table.getColumnModel().getColumn(1).setPreferredWidth(200); | |||
| table.getColumnModel().getColumn(2).setPreferredWidth(80); | |||
| table.getColumnModel().getColumn(3).setPreferredWidth(400); | |||
| table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); | |||
| table.setAutoscrolls(false); | |||
| table.getTableHeader().setReorderingAllowed(false); | |||
| // table.getTableHeader().setResizingAllowed(false); | |||
| JScrollPane scrollPane = new JScrollPane(table); | |||
| scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); | |||
| scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); | |||
| add(scrollPane, BorderLayout.CENTER); | |||
| } | |||
| public void insert(AlarmEventInfo alarmEventInfo) { | |||
| tableModel.insertRow(0,convertAlarmEventInfo(alarmEventInfo)); | |||
| if (currentRowNums < MAX_SHOW_LINES) { | |||
| ++currentRowNums; | |||
| } | |||
| if (currentRowNums <= MIN_SHOW_LINES) { | |||
| tableModel.setRowCount(MIN_SHOW_LINES); | |||
| }else if (currentRowNums == MAX_SHOW_LINES) { | |||
| tableModel.setRowCount(MAX_SHOW_LINES); | |||
| } | |||
| table.updateUI(); | |||
| } | |||
| public void clean() { | |||
| currentRowNums = 0; | |||
| data.clear(); | |||
| AlarmEventInfo.index=0; | |||
| tableModel.setRowCount(0); | |||
| tableModel.setRowCount(MIN_SHOW_LINES); | |||
| table.updateUI(); | |||
| } | |||
| private JTable table = null; | |||
| private DefaultTableModel tableModel = null; | |||
| } | |||
| private static HashMap<Integer, String> alarmMessageMap = new HashMap<Integer, String>() { | |||
| private static final long serialVersionUID = 1L; | |||
| { | |||
| put(NetSDKLib.NET_ALARM_ALARM_EX, Res.string().getExternalAlarm()); | |||
| put(NetSDKLib.NET_MOTION_ALARM_EX, Res.string().getMotionAlarm()); | |||
| put(NetSDKLib.NET_VIDEOLOST_ALARM_EX, Res.string().getVideoLostAlarm()); | |||
| put(NetSDKLib.NET_SHELTER_ALARM_EX, Res.string().getShelterAlarm()); | |||
| put(NetSDKLib.NET_DISKFULL_ALARM_EX, Res.string().getDiskFullAlarm()); | |||
| put(NetSDKLib.NET_DISKERROR_ALARM_EX, Res.string().getDiskErrorAlarm()); | |||
| } | |||
| }; | |||
| private LoginPanel loginPanel; | |||
| private AlarmListenPanel alarmListenPanel; | |||
| private ShowAlarmEventPanel showAlarmPanel; | |||
| enum AlarmStatus { | |||
| ALARM_START, ALARM_STOP | |||
| } | |||
| // struct of alarm event | |||
| static class AlarmEventInfo { | |||
| public static long index = 0; | |||
| public long id; | |||
| public int chn; | |||
| public int type; | |||
| public Date date; | |||
| public AlarmStatus status; | |||
| public AlarmEventInfo(int chn, int type, AlarmStatus status) { | |||
| this.chn = chn; | |||
| this.type = type; | |||
| this.status = status; | |||
| this.date = new Date(); | |||
| } | |||
| @Override | |||
| public boolean equals(Object o) { | |||
| if (this == o) return true; | |||
| if (o == null || getClass() != o.getClass()) return false; | |||
| AlarmEventInfo showInfo = (AlarmEventInfo) o; | |||
| return chn == showInfo.chn && type == showInfo.type; | |||
| } | |||
| } | |||
| } | |||
| public class AlarmListen { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| AlarmListenFrame demo = new AlarmListenFrame(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }; | |||
| @@ -0,0 +1,208 @@ | |||
| package com.netsdk.demo.frame.Attendance; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.util.Timer; | |||
| import java.util.TimerTask; | |||
| import java.util.concurrent.locks.ReentrantLock; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.SwingUtilities; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.AlarmListenModule; | |||
| import com.netsdk.demo.module.AttendanceModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.ALARM_CAPTURE_FINGER_PRINT_INFO; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.NetSDKLib.fMessCallBack; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.sun.jna.NativeLong; | |||
| import com.sun.jna.Pointer; | |||
| /** | |||
| * 添加信息信息 | |||
| */ | |||
| public class AddFingerPrintDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private static final int CHANNEL_ID = 0; // 门禁序号 | |||
| private static final String READER_ID = "1"; // 读卡器ID | |||
| private static final long TIMER_DELAY = 30000; // 定时器超时时间 | |||
| private String userID = null; | |||
| private byte []collectionData = null; | |||
| private Timer timer = new Timer(); // 信息采集定时器 | |||
| private ReentrantLock lock = new ReentrantLock(); | |||
| public AddFingerPrintDialog(String userId) { | |||
| setTitle(Res.string().getAddFingerPrint()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(300, 180); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
| //////////采集面板 ///////////////// | |||
| JPanel collectionPanel = new JPanel(); | |||
| BorderEx.set(collectionPanel, Res.string().getcFingerPrintCollection(), 4); | |||
| collectionPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 35, 25)); | |||
| collectionBtn = new JButton(Res.string().getStartCollection()); | |||
| collectionBtn.setPreferredSize(new Dimension(150, 20)); | |||
| promptLabel = new JLabel(); | |||
| promptLabel.setPreferredSize(new Dimension(150, 20)); | |||
| promptLabel.setHorizontalAlignment(JLabel.CENTER); | |||
| collectionPanel.add(collectionBtn); | |||
| collectionPanel.add(promptLabel); | |||
| //////////功能面板 ///////////////// | |||
| JPanel functionPanel = new JPanel(); | |||
| addBtn = new JButton(Res.string().getAdd()); | |||
| cancelBtn = new JButton(Res.string().getCancel()); | |||
| addBtn.setPreferredSize(new Dimension(100, 20)); | |||
| cancelBtn.setPreferredSize(new Dimension(100, 20)); | |||
| functionPanel.add(addBtn); | |||
| functionPanel.add(cancelBtn); | |||
| add(collectionPanel, BorderLayout.CENTER); | |||
| add(functionPanel, BorderLayout.SOUTH); | |||
| addBtn.setEnabled(false); | |||
| userID = userId; | |||
| cbMessage = new fCollectionDataCB(); | |||
| collectionBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| collectionFinger(); | |||
| } | |||
| }); | |||
| addBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if (AttendanceModule.insertFingerByUserId(userID, collectionData)) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed() , Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| dispose(); | |||
| } | |||
| }); | |||
| cancelBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| AlarmListenModule.stopListen(); | |||
| timer.cancel(); | |||
| dispose(); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| AlarmListenModule.stopListen(); | |||
| timer.cancel(); | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| public void collectionFinger() { | |||
| if (!AlarmListenModule.startListen(cbMessage)) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCollectionFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| collectionData = null; | |||
| if (!AttendanceModule.collectionFinger(CHANNEL_ID, READER_ID)) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCollectionFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| promptLabel.setText(Res.string().getInCollection()); | |||
| collectionBtn.setEnabled(false); | |||
| } | |||
| }); | |||
| timer.schedule(new TimerTask() { | |||
| public void run() { | |||
| lock.lock(); | |||
| if (collectionData == null) { | |||
| AlarmListenModule.stopListen(); | |||
| promptLabel.setText(Res.string().getCollectionFailed()); | |||
| collectionBtn.setEnabled(true); | |||
| } | |||
| lock.unlock(); | |||
| } | |||
| }, TIMER_DELAY); | |||
| } | |||
| /** | |||
| * 信息采集监听回调 | |||
| **/ | |||
| private class fCollectionDataCB implements fMessCallBack{ | |||
| @Override | |||
| public boolean invoke(int lCommand, LLong lLoginID, | |||
| Pointer pStuEvent, int dwBufLen, String strDeviceIP, | |||
| NativeLong nDevicePort, Pointer dwUser) { | |||
| if (lCommand == NetSDKLib.NET_ALARM_FINGER_PRINT) { | |||
| lock.lock(); | |||
| if (collectionData == null) { | |||
| timer.cancel(); | |||
| ALARM_CAPTURE_FINGER_PRINT_INFO msg = new ALARM_CAPTURE_FINGER_PRINT_INFO(); | |||
| ToolKits.GetPointerData(pStuEvent, msg); | |||
| collectionData = new byte[msg.nPacketLen * msg.nPacketNum]; | |||
| msg.szFingerPrintInfo.read(0, collectionData, 0, msg.nPacketLen * msg.nPacketNum); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| AlarmListenModule.stopListen(); | |||
| promptLabel.setText(Res.string().getcCompleteCollection()); | |||
| addBtn.setEnabled(true); | |||
| } | |||
| }); | |||
| } | |||
| lock.unlock(); | |||
| } | |||
| return true; | |||
| } | |||
| } | |||
| private fMessCallBack cbMessage; // 信息采集回调 | |||
| private JLabel promptLabel; // 提示信息 | |||
| private JButton collectionBtn; // 采集按钮 | |||
| private JButton addBtn; // 添加按钮 | |||
| private JButton cancelBtn; // 取消按钮 | |||
| } | |||
| @@ -0,0 +1,166 @@ | |||
| package com.netsdk.demo.frame.Attendance; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JSplitPane; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.UIManager; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.FunctionList; | |||
| import com.netsdk.common.LoginPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.AttendanceModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.ToolKits; | |||
| /** | |||
| * 考勤机Demo:包含门禁事件订阅、人员操作、信息操作 | |||
| */ | |||
| class AttendanceFrame extends JFrame{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| // 设备断线通知回调 | |||
| private DisConnect disConnect = new DisConnect(); | |||
| // 获取界面窗口 | |||
| private static JFrame frame = new JFrame(); | |||
| public AttendanceFrame(){ | |||
| setTitle(Res.string().getAttendance()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(800, 555); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| LoginModule.init(disConnect, null); // 打开工程,初始化 | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| loginPanel = new LoginPanel(); | |||
| showPanel = new AttendanceShowPanel(); | |||
| operatePanel = new AttendanceFunctionOperatePanel(showPanel); | |||
| JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, loginPanel, operatePanel); | |||
| splitPane.setDividerSize(0); | |||
| splitPane.setBorder(null); | |||
| add(splitPane, BorderLayout.NORTH); | |||
| add(showPanel, BorderLayout.CENTER); | |||
| loginPanel.addLoginBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(loginPanel.checkLoginText()) { | |||
| if(login()) { | |||
| frame = ToolKits.getFrame(e); | |||
| frame.setTitle(Res.string().getAttendance() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| loginPanel.addLogoutBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| logout(); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| AttendanceModule.stopRealLoadPicture(); | |||
| LoginModule.logout(); | |||
| LoginModule.cleanup(); // 关闭工程,释放资源 | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| // 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数 | |||
| private class DisConnect implements NetSDKLib.fDisConnect { | |||
| public DisConnect() { } | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| // 断线提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| JOptionPane.showMessageDialog(null, Res.string().getDisConnect(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| logout(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 登录 | |||
| public boolean login() { | |||
| if(LoginModule.login(loginPanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginPanel.portTextArea.getText()), | |||
| loginPanel.nameTextArea.getText(), | |||
| new String(loginPanel.passwordTextArea.getPassword()))) { | |||
| loginPanel.setButtonEnable(true); | |||
| operatePanel.setButtonEnable(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| // 登出 | |||
| public void logout() { | |||
| AttendanceModule.stopRealLoadPicture(); | |||
| LoginModule.logout(); | |||
| frame.setTitle(Res.string().getAttendance()); | |||
| loginPanel.setButtonEnable(false); | |||
| operatePanel.setButtonEnable(false); | |||
| showPanel.clearup(); | |||
| } | |||
| private LoginPanel loginPanel; // 登陆面板 | |||
| private AttendanceFunctionOperatePanel operatePanel; // 操作面板 | |||
| private AttendanceShowPanel showPanel; // 显示面板 | |||
| } | |||
| public class Attendance { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| AttendanceFrame demo = new AttendanceFrame(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| @@ -0,0 +1,324 @@ | |||
| package com.netsdk.demo.frame.Attendance; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JSplitPane; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.SwingWorker; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.frame.Attendance.AttendanceShowPanel.UserInfoShowPanel; | |||
| import com.netsdk.demo.module.AttendanceModule; | |||
| import com.netsdk.demo.module.AttendanceModule.OPERATE_TYPE; | |||
| import com.netsdk.demo.module.AttendanceModule.UserData; | |||
| /** | |||
| * 考勤机操作面板 | |||
| */ | |||
| public class AttendanceFunctionOperatePanel extends JPanel{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public static boolean bLogout = false; | |||
| public AttendanceShowPanel showPanel; // 显示面板 | |||
| private AttendanceFunctionOperatePanel target = this; // 为了传值 | |||
| public AttendanceFunctionOperatePanel(AttendanceShowPanel showPanel) { | |||
| setLayout(new BorderLayout()); | |||
| setPreferredSize(new Dimension(800, 120)); | |||
| listener = new UserOperateActionListener(); | |||
| userPanel = new FunctionOperatePanel(); | |||
| subscribePanel = new SubscribePanel(showPanel.eventShowPanel); | |||
| JSplitPane splitPane = new JSplitPane(); | |||
| splitPane.setDividerSize(0); | |||
| splitPane.setBorder(null); | |||
| splitPane.add(userPanel, JSplitPane.LEFT); | |||
| splitPane.add(subscribePanel, JSplitPane.RIGHT); | |||
| add(splitPane, BorderLayout.CENTER); | |||
| this.showPanel = showPanel; | |||
| this.showPanel.userShowPanel.prePageBtn.addActionListener(listener); | |||
| this.showPanel.userShowPanel.nextPageBtn.addActionListener(listener); | |||
| } | |||
| public void setButtonEnable(boolean b) { | |||
| bLogout=!b; | |||
| userPanel.setButtonEnable(b); | |||
| subscribePanel.setButtonEnable(b); | |||
| } | |||
| public void setSearchEnable(boolean b) { | |||
| showPanel.userShowPanel.setButtonEnable(b); | |||
| userPanel.searchPersonBtn.setEnabled(b); | |||
| } | |||
| public void insertData(UserData[] arrUserData) { | |||
| showPanel.userShowPanel.insertData(arrUserData); | |||
| } | |||
| public void insertData(UserData userData) { | |||
| showPanel.userShowPanel.insertData(userData); | |||
| } | |||
| /** | |||
| * 总的功能操作面板 | |||
| */ | |||
| public class FunctionOperatePanel extends JPanel{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public FunctionOperatePanel() { | |||
| // BorderEx.set(this, Res.string().getOperateByUser(), 1); | |||
| setLayout(new BorderLayout()); | |||
| setPreferredSize(new Dimension(600, 60)); | |||
| ////////// 查询条件 ///////////////// | |||
| JLabel userIdLabel = new JLabel(Res.string().getUserId(), JLabel.CENTER); | |||
| userIdTextField = new JTextField(); | |||
| userIdLabel.setPreferredSize(new Dimension(80, 20)); | |||
| userIdTextField.setPreferredSize(new Dimension(110, 20)); | |||
| ////////// 功能面板 ///////////////// | |||
| // 用户功能面板 | |||
| JPanel userFunctionPanel = new JPanel(); | |||
| userFunctionPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); | |||
| BorderEx.set(userFunctionPanel, Res.string().getUserOperate(), 1); | |||
| searchPersonBtn = new JButton(Res.string().getSearch()); | |||
| addPersonBtn = new JButton(Res.string().getAdd()); | |||
| modifyPersonBtn = new JButton(Res.string().getModify()); | |||
| deletePersonBtn = new JButton(Res.string().getDelete()); | |||
| searchPersonBtn.setPreferredSize(new Dimension(90, 20)); | |||
| addPersonBtn.setPreferredSize(new Dimension(90, 20)); | |||
| modifyPersonBtn.setPreferredSize(new Dimension(90, 20)); | |||
| deletePersonBtn.setPreferredSize(new Dimension(90, 20)); | |||
| userFunctionPanel.add(userIdLabel); | |||
| userFunctionPanel.add(userIdTextField); | |||
| userFunctionPanel.add(searchPersonBtn); | |||
| userFunctionPanel.add(addPersonBtn); | |||
| userFunctionPanel.add(modifyPersonBtn); | |||
| userFunctionPanel.add(deletePersonBtn); | |||
| // 信息功能面板 | |||
| JPanel fingerPrintFunctionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); | |||
| BorderEx.set(fingerPrintFunctionPanel, Res.string().getFingerPrintOperate(), 1); | |||
| operateByUserIdBtn = new JButton(Res.string().getOperateByUserId()); | |||
| operateByFingerPrintIdBtn = new JButton(Res.string().getOperateByFingerPrintId()); | |||
| operateByUserIdBtn.setPreferredSize(new Dimension(260, 20)); | |||
| operateByFingerPrintIdBtn.setPreferredSize(new Dimension(260, 20)); | |||
| fingerPrintFunctionPanel.add(operateByUserIdBtn); | |||
| fingerPrintFunctionPanel.add(operateByFingerPrintIdBtn); | |||
| JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); | |||
| splitPane.setDividerSize(0); | |||
| splitPane.setBorder(null); | |||
| splitPane.add(userFunctionPanel, JSplitPane.TOP); | |||
| splitPane.add(fingerPrintFunctionPanel, JSplitPane.BOTTOM); | |||
| add(splitPane, BorderLayout.CENTER); | |||
| searchPersonBtn.addActionListener(listener); | |||
| addPersonBtn.addActionListener(listener); | |||
| modifyPersonBtn.addActionListener(listener); | |||
| deletePersonBtn.addActionListener(listener); | |||
| operateByUserIdBtn.addActionListener(listener); | |||
| operateByFingerPrintIdBtn.addActionListener(listener); | |||
| setButtonEnable(false); | |||
| } | |||
| public void setButtonEnable(boolean b) { | |||
| searchPersonBtn.setEnabled(b); | |||
| addPersonBtn.setEnabled(b); | |||
| modifyPersonBtn.setEnabled(b); | |||
| deletePersonBtn.setEnabled(b); | |||
| operateByUserIdBtn.setEnabled(b); | |||
| operateByFingerPrintIdBtn.setEnabled(b); | |||
| } | |||
| public void searchPerson(OPERATE_TYPE type) { // flush 为 true 时 强制刷新 | |||
| if (type == OPERATE_TYPE.SEARCH_USER && !userIdTextField.getText().isEmpty()) { | |||
| UserData userData = AttendanceModule.getUser(userIdTextField.getText()); | |||
| if (userData == null) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| showPanel.userShowPanel.insertData(userData); | |||
| }else { | |||
| setSearchEnable(false); | |||
| new SearchPersonSwingWorker(type, target).execute(); | |||
| } | |||
| } | |||
| private JTextField userIdTextField; | |||
| public JButton searchPersonBtn; | |||
| private JButton addPersonBtn; | |||
| private JButton modifyPersonBtn; | |||
| private JButton deletePersonBtn; | |||
| private JButton operateByUserIdBtn; | |||
| private JButton operateByFingerPrintIdBtn; | |||
| } | |||
| /** | |||
| * 按键监听实现类 | |||
| */ | |||
| private class UserOperateActionListener implements ActionListener { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| OPERATE_TYPE emType = getOperateType(arg0.getSource()); | |||
| switch(emType) { | |||
| case SEARCH_USER: | |||
| case PRE_SEARCH_USER: | |||
| case NEXT_SEARCH_USER: | |||
| SwingUtilities.invokeLater(new SearchRunnable(emType)); | |||
| break; | |||
| case ADD_USER: | |||
| new AttendanceOperateShareDialog(emType, null, "").setVisible(true); | |||
| break; | |||
| case MODIFIY_USER: | |||
| case DELETE_USER: | |||
| case FINGERPRINT_OPEARTE_BY_USERID: | |||
| UserData userData = showPanel.userShowPanel.GetSelectedItem(); | |||
| if(userData == null) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectPerson(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if (emType == OPERATE_TYPE.FINGERPRINT_OPEARTE_BY_USERID) { | |||
| new OperateByUserIdDialog(userData).setVisible(true); | |||
| }else { | |||
| new AttendanceOperateShareDialog(emType, userData).setVisible(true); | |||
| } | |||
| break; | |||
| case FINGERPRINT_OPEARTE_BY_ID: | |||
| new OperateByFingerPrintIdDialog().setVisible(true); | |||
| default: | |||
| break; | |||
| } | |||
| } | |||
| private OPERATE_TYPE getOperateType(Object btn) { | |||
| OPERATE_TYPE type = OPERATE_TYPE.UNKNOWN; | |||
| if (btn == userPanel.searchPersonBtn) { // 查找人员 | |||
| type = OPERATE_TYPE.SEARCH_USER; | |||
| }else if (btn == showPanel.userShowPanel.prePageBtn) { // 上一页查找人员 | |||
| type = OPERATE_TYPE.PRE_SEARCH_USER; | |||
| }else if (btn == showPanel.userShowPanel.nextPageBtn) { // 下一页查找人员 | |||
| type = OPERATE_TYPE.NEXT_SEARCH_USER; | |||
| }else if (btn == userPanel.addPersonBtn) { // 添加人员 | |||
| type = OPERATE_TYPE.ADD_USER; | |||
| }else if (btn == userPanel.modifyPersonBtn) { // 修改人员 | |||
| type = OPERATE_TYPE.MODIFIY_USER; | |||
| }else if (btn == userPanel.deletePersonBtn) { // 删除人员 | |||
| type = OPERATE_TYPE.DELETE_USER; | |||
| }else if (btn == userPanel.operateByUserIdBtn) { // 通过用户ID操作信息 | |||
| type = OPERATE_TYPE.FINGERPRINT_OPEARTE_BY_USERID; | |||
| }else if (btn == userPanel.operateByFingerPrintIdBtn) { // 通过信息ID操作信息 | |||
| type = OPERATE_TYPE.FINGERPRINT_OPEARTE_BY_ID; | |||
| }else { | |||
| System.err.println("Unknown Event: " + btn); | |||
| } | |||
| return type; | |||
| } | |||
| } | |||
| public class SearchRunnable implements Runnable { | |||
| private OPERATE_TYPE searchType; | |||
| public SearchRunnable(OPERATE_TYPE searchType) { | |||
| this.searchType = searchType; | |||
| } | |||
| @Override | |||
| public void run() { | |||
| userPanel.searchPerson(searchType); | |||
| } | |||
| } | |||
| /** | |||
| * 人员搜索工作线程(完成异步搜索) | |||
| */ | |||
| public class SearchPersonSwingWorker extends SwingWorker<UserData[], Object> { | |||
| private AttendanceFunctionOperatePanel operatePanel; | |||
| private int offset = 0; | |||
| private OPERATE_TYPE type; | |||
| public SearchPersonSwingWorker(OPERATE_TYPE type, AttendanceFunctionOperatePanel operatePanel) { | |||
| this.operatePanel = operatePanel; | |||
| this.type = type; | |||
| } | |||
| protected UserData[] doInBackground() throws Exception { | |||
| switch(type) { | |||
| case SEARCH_USER: | |||
| offset = 0; | |||
| break; | |||
| case PRE_SEARCH_USER: | |||
| offset = UserInfoShowPanel.QUERY_SHOW_COUNT * ((AttendanceShowPanel.userIndex-1)/UserInfoShowPanel.QUERY_SHOW_COUNT - 1); | |||
| break; | |||
| case NEXT_SEARCH_USER: | |||
| offset = AttendanceShowPanel.userIndex; | |||
| break; | |||
| default: | |||
| break; | |||
| } | |||
| UserData[] arrUserData = AttendanceModule.findUser(offset, UserInfoShowPanel.QUERY_SHOW_COUNT); | |||
| return arrUserData; | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| if (bLogout) { | |||
| return; | |||
| } | |||
| try { | |||
| UserData[] arrUserData = get(); | |||
| if (arrUserData == null) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if (type == OPERATE_TYPE.SEARCH_USER || | |||
| type == OPERATE_TYPE.PRE_SEARCH_USER) { // 更新userIndex | |||
| AttendanceShowPanel.userIndex = offset; | |||
| } | |||
| operatePanel.insertData(arrUserData); | |||
| } catch (Exception e) { | |||
| // e.printStackTrace(); | |||
| }finally { | |||
| operatePanel.setSearchEnable(true); | |||
| } | |||
| } | |||
| } | |||
| private UserOperateActionListener listener; | |||
| public FunctionOperatePanel userPanel; | |||
| public SubscribePanel subscribePanel; | |||
| } | |||
| @@ -0,0 +1,265 @@ | |||
| package com.netsdk.demo.frame.Attendance; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JTextField; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.AttendanceModule; | |||
| import com.netsdk.demo.module.AttendanceModule.OPERATE_TYPE; | |||
| import com.netsdk.demo.module.AttendanceModule.UserData; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| /** | |||
| * 考勤机操作对话框 | |||
| */ | |||
| public class AttendanceOperateShareDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private OPERATE_TYPE emType = OPERATE_TYPE.UNKNOWN; // 操作类型 | |||
| private boolean bSuccess = false; // 接口调用结果 | |||
| public AttendanceOperateShareDialog(OPERATE_TYPE emType, UserData userData) { | |||
| this(emType, userData, ""); | |||
| } | |||
| public AttendanceOperateShareDialog(OPERATE_TYPE emType, String fingerPrintId) { | |||
| this(emType, null, fingerPrintId); | |||
| } | |||
| public AttendanceOperateShareDialog(OPERATE_TYPE emType, UserData userData, String fingerPrintId) { | |||
| setTitle(Res.string().getPersonOperate()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(300, 200); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
| //////////人员信息面板 ///////////////// | |||
| JPanel personInfoPanel = new JPanel(); | |||
| BorderEx.set(personInfoPanel, "", 4); | |||
| Dimension dimLable = new Dimension(80, 20); | |||
| JLabel userIdLabel = new JLabel(Res.string().getUserId()); | |||
| JLabel userNameLabel = new JLabel(Res.string().getUserName(true)); | |||
| JLabel cardNoLabel = new JLabel(Res.string().getCardNo()); | |||
| JLabel fingerPrintIdLabel = new JLabel(Res.string().getFingerPrintId()); | |||
| userIdLabel.setPreferredSize(dimLable); | |||
| userNameLabel.setPreferredSize(dimLable); | |||
| cardNoLabel.setPreferredSize(dimLable); | |||
| fingerPrintIdLabel.setPreferredSize(new Dimension(85, 20)); | |||
| Dimension dimValue = new Dimension(150, 20); | |||
| userIdTextField = new JTextField(); | |||
| userNameTextField = new JTextField(); | |||
| cardNoTextField = new JTextField(); | |||
| fingerPrintIdTextField = new JTextField(); | |||
| userIdTextField.setPreferredSize(dimValue); | |||
| userNameTextField.setPreferredSize(dimValue); | |||
| cardNoTextField.setPreferredSize(dimValue); | |||
| fingerPrintIdTextField.setPreferredSize(dimValue); | |||
| // 数据处理 | |||
| if (userData != null) { | |||
| if (userData.userId != null) { | |||
| userIdTextField.setText(userData.userId); | |||
| } | |||
| if (userData.userName != null) { | |||
| userNameTextField.setText(userData.userName); | |||
| } | |||
| if (userData.cardNo != null) { | |||
| cardNoTextField.setText(userData.cardNo); | |||
| } | |||
| } | |||
| if (!fingerPrintId.isEmpty()) { | |||
| fingerPrintIdTextField.setText(fingerPrintId); | |||
| } | |||
| if (emType == OPERATE_TYPE.DELETE_FINGERPRINT_BY_ID) { // 根据信息ID删除用户 | |||
| JPanel fingerPrintPanel = new JPanel(); | |||
| fingerPrintPanel.add(fingerPrintIdLabel); | |||
| fingerPrintPanel.add(fingerPrintIdTextField); | |||
| personInfoPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 40)); | |||
| personInfoPanel.add(fingerPrintPanel); | |||
| }else { | |||
| personInfoPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 10)); | |||
| personInfoPanel.add(userIdLabel); | |||
| personInfoPanel.add(userIdTextField); | |||
| personInfoPanel.add(userNameLabel); | |||
| personInfoPanel.add(userNameTextField); | |||
| personInfoPanel.add(cardNoLabel); | |||
| personInfoPanel.add(cardNoTextField); | |||
| if (emType == OPERATE_TYPE.DELETE_FINGERPRINT_BY_USERID | |||
| || emType == OPERATE_TYPE.DELETE_USER) { | |||
| JLabel promptLabel = new JLabel(" " + Res.string().getDeleteFingerPrintPrompt() + " "); | |||
| promptLabel.setEnabled(false); | |||
| personInfoPanel.add(promptLabel); | |||
| } | |||
| } | |||
| //////////功能面板 ///////////////// | |||
| JPanel functionPanel = new JPanel(); | |||
| confirmBtn = new JButton(Res.string().getConfirm()); | |||
| cancelBtn = new JButton(Res.string().getCancel()); | |||
| confirmBtn.setPreferredSize(new Dimension(100, 20)); | |||
| cancelBtn.setPreferredSize(new Dimension(100, 20)); | |||
| functionPanel.add(confirmBtn); | |||
| functionPanel.add(cancelBtn); | |||
| add(personInfoPanel, BorderLayout.CENTER); | |||
| add(functionPanel, BorderLayout.SOUTH); | |||
| operateListener = new UserOperateListener(); | |||
| confirmBtn.addActionListener(operateListener); | |||
| cancelBtn.addActionListener(operateListener); | |||
| this.emType = emType; | |||
| switch(emType) { | |||
| case ADD_USER: | |||
| setTitle(Res.string().getAddPerson()); | |||
| confirmBtn.setText(Res.string().getAdd()); | |||
| break; | |||
| case MODIFIY_USER: | |||
| setTitle(Res.string().getModifyPerson()); | |||
| confirmBtn.setText(Res.string().getModify()); | |||
| userIdTextField.setEnabled(false); | |||
| break; | |||
| case DELETE_USER: | |||
| setTitle(Res.string().getDelPerson()); | |||
| confirmBtn.setText(Res.string().getDelete()); | |||
| userIdTextField.setEnabled(false); | |||
| userNameTextField.setEnabled(false); | |||
| cardNoTextField.setEnabled(false); | |||
| break; | |||
| case DELETE_FINGERPRINT_BY_USERID: | |||
| case DELETE_FINGERPRINT_BY_ID: | |||
| setTitle(Res.string().getDeleteFingerPrint()); | |||
| confirmBtn.setText(Res.string().getDelete()); | |||
| userIdTextField.setEnabled(false); | |||
| userNameTextField.setEnabled(false); | |||
| cardNoTextField.setEnabled(false); | |||
| fingerPrintIdTextField.setEditable(false); | |||
| default: | |||
| break; | |||
| } | |||
| } | |||
| public boolean checkDataValidity() { | |||
| if (emType == OPERATE_TYPE.ADD_USER) { | |||
| if (userIdTextField.getText().isEmpty()) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getUserId(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| try { | |||
| if (userIdTextField.getText().getBytes("UTF-8").length > NetSDKLib.MAX_COMMON_STRING_32-1) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getUserIdExceedLength(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| }catch (Exception e){ | |||
| } | |||
| } | |||
| try { | |||
| if (userNameTextField.getText().getBytes("UTF-8").length > NetSDKLib.MAX_ATTENDANCE_USERNAME_LEN-1) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getUserNameExceedLength(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| if (cardNoTextField.getText().getBytes("UTF-8").length > NetSDKLib.MAX_COMMON_STRING_32-1) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCardNoExceedLength(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| }catch (Exception e){ | |||
| } | |||
| return true; | |||
| } | |||
| public UserData getUserData() { | |||
| UserData userData = new UserData(); | |||
| userData.cardNo = userIdTextField.getText(); | |||
| userData.userName = userNameTextField.getText(); | |||
| userData.cardNo = cardNoTextField.getText(); | |||
| return userData; | |||
| } | |||
| private class UserOperateListener implements ActionListener { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| if (arg0.getSource() == cancelBtn) { | |||
| dispose(); | |||
| }else if (arg0.getSource() == confirmBtn) { | |||
| switch(emType) { | |||
| case ADD_USER: | |||
| if (!checkDataValidity()) { | |||
| return; | |||
| } | |||
| bSuccess = AttendanceModule.addUser(userIdTextField.getText(), userNameTextField.getText(), cardNoTextField.getText()); | |||
| break; | |||
| case MODIFIY_USER: | |||
| if (!checkDataValidity()) { | |||
| return; | |||
| } | |||
| bSuccess = AttendanceModule.modifyUser(userIdTextField.getText(), userNameTextField.getText(), cardNoTextField.getText()); | |||
| break; | |||
| case DELETE_USER: | |||
| bSuccess = AttendanceModule.deleteUser(userIdTextField.getText()); | |||
| break; | |||
| case DELETE_FINGERPRINT_BY_USERID: | |||
| bSuccess = AttendanceModule.removeFingerByUserId(userIdTextField.getText()); | |||
| break; | |||
| case DELETE_FINGERPRINT_BY_ID: | |||
| bSuccess = AttendanceModule.removeFingerRecord(Integer.parseInt(fingerPrintIdTextField.getText())); | |||
| break; | |||
| default: | |||
| System.err.println("Can't Deal Operate Type: " + emType); | |||
| break; | |||
| } | |||
| if(bSuccess) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| dispose(); | |||
| }else { | |||
| System.err.println("Unknown Event: " + arg0.getSource()); | |||
| } | |||
| } | |||
| } | |||
| private UserOperateListener operateListener; // 按键监听 | |||
| private JTextField userIdTextField; // 用户ID | |||
| private JTextField userNameTextField; // 用户名 | |||
| private JTextField cardNoTextField; // 卡号 | |||
| private JTextField fingerPrintIdTextField; // 信息ID | |||
| private JButton confirmBtn; // 确认(根据emType类型变化) | |||
| private JButton cancelBtn; // 取消 | |||
| } | |||
| @@ -0,0 +1,370 @@ | |||
| package com.netsdk.demo.frame.Attendance; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.util.HashMap; | |||
| import java.util.Vector; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JSplitPane; | |||
| import javax.swing.JTable; | |||
| import javax.swing.ListSelectionModel; | |||
| import javax.swing.UIManager; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.common.Res.LanguageType; | |||
| import com.netsdk.demo.module.AttendanceModule.AccessEventInfo; | |||
| import com.netsdk.demo.module.AttendanceModule.UserData; | |||
| import com.netsdk.lib.NetSDKLib.NET_ACCESS_DOOROPEN_METHOD; | |||
| public class AttendanceShowPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public static int userIndex = 0; | |||
| public static int eventIndex = 0; | |||
| public AttendanceShowPanel() { | |||
| setLayout(new BorderLayout()); | |||
| userShowPanel = new UserInfoShowPanel(); | |||
| eventShowPanel = new EventInfoShowPanel(); | |||
| JSplitPane splitPane = new JSplitPane(); | |||
| splitPane.setDividerSize(0); | |||
| splitPane.setBorder(null); | |||
| splitPane.add(userShowPanel, JSplitPane.LEFT); | |||
| splitPane.add(eventShowPanel, JSplitPane.RIGHT); | |||
| add(splitPane); | |||
| } | |||
| public void clearup() { | |||
| userShowPanel.clearData(); | |||
| eventShowPanel.clearEvent(); | |||
| } | |||
| /** | |||
| * 用户信息显示界面 | |||
| * */ | |||
| public class UserInfoShowPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public static final int INDEX = 0; | |||
| public static final int USER_ID = 1; | |||
| public static final int USER_NAME = 2; | |||
| public static final int CARD_NO = 3; | |||
| public static final int FINGERPRINT_ID = 4; | |||
| public static final int FINGERPRINT_DATA = 5; | |||
| public final static int QUERY_SHOW_COUNT = 15; // 查询人数 | |||
| private int realRows = 0; // 实际显示个数 | |||
| public UserInfoShowPanel() { | |||
| BorderEx.set(this, Res.string().getUserList(), 1); | |||
| setLayout(new BorderLayout()); | |||
| setPreferredSize(new Dimension(395, 400)); | |||
| Vector<String> columnNames = new Vector<String>(); | |||
| columnNames.add(Res.string().getIndex()); // 序号 | |||
| columnNames.add(Res.string().getUserId()); // 用户编号 | |||
| columnNames.add(Res.string().getUserName()); // 用户名 | |||
| columnNames.add(Res.string().getCardNo()); // 卡号 | |||
| tableModel = new DefaultTableModel(null, columnNames); | |||
| table = new JTable(tableModel) { | |||
| private static final long serialVersionUID = 1L; | |||
| public boolean isCellEditable(int rowIndex, int columnIndex) { // 不可编辑 | |||
| return false; | |||
| } | |||
| }; | |||
| tableModel.setRowCount(QUERY_SHOW_COUNT); // 设置最小显示行 | |||
| table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行 | |||
| table.getColumnModel().getColumn(INDEX).setPreferredWidth(80); | |||
| table.getColumnModel().getColumn(USER_ID).setPreferredWidth(150); | |||
| table.getColumnModel().getColumn(USER_NAME).setPreferredWidth(150); | |||
| table.getColumnModel().getColumn(CARD_NO).setPreferredWidth(150); | |||
| ((DefaultTableCellRenderer) | |||
| table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(JLabel.CENTER); | |||
| table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); | |||
| JScrollPane scrollPane = new JScrollPane(table); | |||
| scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); | |||
| scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |||
| JPanel functionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); | |||
| prePageBtn = new JButton(Res.string().getPreviousPage()); | |||
| nextPageBtn = new JButton(Res.string().getNextPage()); | |||
| prePageBtn.setPreferredSize(new Dimension(120, 20)); | |||
| nextPageBtn.setPreferredSize(new Dimension(120, 20)); | |||
| prePageBtn.setEnabled(false); | |||
| nextPageBtn.setEnabled(false); | |||
| functionPanel.add(prePageBtn); | |||
| functionPanel.add(new JLabel(" ")); | |||
| functionPanel.add(nextPageBtn); | |||
| add(scrollPane, BorderLayout.CENTER); | |||
| add(functionPanel, BorderLayout.SOUTH); | |||
| } | |||
| public int getRows(){ | |||
| return realRows; | |||
| } | |||
| public UserData GetSelectedItem() { | |||
| int currentRow = table.getSelectedRow(); //获得所选的单行 | |||
| if(currentRow < 0 || currentRow + 1 > realRows) { | |||
| return null; | |||
| } | |||
| UserData userData = new UserData(); | |||
| userData.userId = (String) tableModel.getValueAt(currentRow, 1); | |||
| userData.userName = (String) tableModel.getValueAt(currentRow, 2); | |||
| userData.cardNo = (String) tableModel.getValueAt(currentRow, 3); | |||
| return userData; | |||
| } | |||
| public void updateSelectedItem(UserData userData) { | |||
| int currentRow = table.getSelectedRow(); //获得所选的单行 | |||
| if(currentRow < 0 || currentRow + 1 > realRows) { | |||
| return; | |||
| } | |||
| // tableModel.setValueAt(userData.userId, currentRow, 1); | |||
| tableModel.setValueAt(userData.userName, currentRow, 2); | |||
| tableModel.setValueAt(userData.cardNo, currentRow, 3); | |||
| table.updateUI(); | |||
| } | |||
| public void insertData(UserData[] arrUserData) { | |||
| if (arrUserData == null) { | |||
| return; | |||
| } | |||
| realRows = 0; | |||
| tableModel.setRowCount(0); | |||
| for (UserData userData : arrUserData) { | |||
| insertUserData(userData); | |||
| } | |||
| tableModel.setRowCount(QUERY_SHOW_COUNT); | |||
| table.updateUI(); | |||
| setButtonEnable(true); | |||
| } | |||
| public void setButtonEnable(boolean b) { | |||
| if (b) { | |||
| if (UserData.nTotalUser - userIndex > 0) { | |||
| nextPageBtn.setEnabled(true); | |||
| }else { | |||
| nextPageBtn.setEnabled(false); | |||
| } | |||
| if (userIndex - QUERY_SHOW_COUNT > 0) { | |||
| prePageBtn.setEnabled(true); | |||
| }else { | |||
| prePageBtn.setEnabled(false); | |||
| } | |||
| }else { | |||
| prePageBtn.setEnabled(false); | |||
| nextPageBtn.setEnabled(false); | |||
| } | |||
| } | |||
| public void insertData(UserData userData) { | |||
| if (userData == null) { | |||
| return; | |||
| } | |||
| clearData(); | |||
| tableModel.setRowCount(0); | |||
| insertUserData(userData); | |||
| tableModel.setRowCount(QUERY_SHOW_COUNT); | |||
| table.updateUI(); | |||
| setButtonEnable(false); | |||
| } | |||
| private void insertUserData(UserData userData) { | |||
| ++userIndex; | |||
| ++realRows; | |||
| Vector<String> vector = new Vector<String>(); | |||
| vector.add(String.valueOf(userIndex)); | |||
| vector.add(userData.userId); | |||
| vector.add(userData.userName); | |||
| vector.add(userData.cardNo); | |||
| tableModel.addRow(vector); | |||
| } | |||
| public void clearData() { | |||
| realRows = 0; | |||
| userIndex = 0; | |||
| tableModel.setRowCount(0); | |||
| tableModel.setRowCount(QUERY_SHOW_COUNT); | |||
| table.updateUI(); | |||
| prePageBtn.setEnabled(false); | |||
| nextPageBtn.setEnabled(false); | |||
| } | |||
| private JTable table = null; | |||
| private DefaultTableModel tableModel = null; | |||
| public JButton prePageBtn; | |||
| public JButton nextPageBtn; | |||
| } | |||
| /** | |||
| * 门禁事件显示界面 | |||
| * */ | |||
| public class EventInfoShowPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private static final int INDEX = 0; | |||
| private static final int USER_ID = 1; | |||
| private static final int CARD_NO = 2; | |||
| private static final int EVENT_TIME = 3; | |||
| private static final int DOOR_OPEN_METHOD = 4; | |||
| private final static int MIN_SHOW_LINES = 17; | |||
| private final static int MAX_SHOW_LINES = 50; | |||
| public EventInfoShowPanel() { | |||
| BorderEx.set(this, Res.string().getEventInfo(), 1); | |||
| setLayout(new BorderLayout()); | |||
| setPreferredSize(new Dimension(395, 400)); | |||
| Vector<String> columnNames = new Vector<String>(); | |||
| columnNames.add(Res.string().getIndex()); // 序号 | |||
| columnNames.add(Res.string().getUserId()); // 用户编号 | |||
| columnNames.add(Res.string().getCardNo()); // 卡号 | |||
| columnNames.add(Res.string().getEventTime()); // 事件时间 | |||
| columnNames.add(Res.string().getDoorOpenMethod()); // 开门方式 | |||
| tableModel = new DefaultTableModel(null, columnNames); | |||
| table = new JTable(tableModel) { | |||
| private static final long serialVersionUID = 1L; | |||
| public boolean isCellEditable(int rowIndex, int columnIndex) { | |||
| return false; | |||
| } | |||
| }; | |||
| tableModel.setRowCount(MIN_SHOW_LINES); // 设置最小显示行 | |||
| table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行 | |||
| table.getColumnModel().getColumn(INDEX).setPreferredWidth(80); | |||
| table.getColumnModel().getColumn(USER_ID).setPreferredWidth(150); | |||
| table.getColumnModel().getColumn(CARD_NO).setPreferredWidth(150); | |||
| table.getColumnModel().getColumn(EVENT_TIME).setPreferredWidth(150); | |||
| table.getColumnModel().getColumn(DOOR_OPEN_METHOD).setPreferredWidth(120); | |||
| ((DefaultTableCellRenderer) | |||
| table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(JLabel.CENTER); | |||
| table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); | |||
| JScrollPane scrollPane = new JScrollPane(table); | |||
| scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); | |||
| scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |||
| add(scrollPane, BorderLayout.CENTER); | |||
| } | |||
| public void clearEvent() { | |||
| eventIndex = 0; | |||
| tableModel.setRowCount(0); | |||
| tableModel.setRowCount(MIN_SHOW_LINES); | |||
| table.updateUI(); | |||
| } | |||
| public void insertEvent(AccessEventInfo accessEventInfo) { | |||
| if (accessEventInfo == null) { | |||
| return; | |||
| } | |||
| ++eventIndex; | |||
| tableModel.insertRow(0, convertEventData(accessEventInfo)); | |||
| if (eventIndex <= MIN_SHOW_LINES) { | |||
| tableModel.setRowCount(MIN_SHOW_LINES); | |||
| }else if (eventIndex >= MAX_SHOW_LINES){ | |||
| tableModel.setRowCount(MAX_SHOW_LINES); | |||
| } | |||
| table.updateUI(); | |||
| } | |||
| private Vector<String> convertEventData(AccessEventInfo accessEventInfo) { | |||
| Vector<String> vector = new Vector<String>(); | |||
| vector.add(String.valueOf(eventIndex)); | |||
| vector.add(accessEventInfo.userId); | |||
| vector.add(accessEventInfo.cardNo); | |||
| vector.add(accessEventInfo.eventTime.replace("/", "-")); | |||
| String openDoor = openDoorMethodMap.get(accessEventInfo.openDoorMethod); | |||
| if (openDoor == null) { | |||
| openDoor = Res.string().getUnKnow(); | |||
| } | |||
| vector.add(openDoor); | |||
| return vector; | |||
| } | |||
| private JTable table = null; | |||
| private DefaultTableModel tableModel = null; | |||
| } | |||
| private static HashMap<Integer, String> openDoorMethodMap = new HashMap<Integer, String>() { | |||
| private static final long serialVersionUID = 1L; | |||
| { | |||
| put(NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_FINGERPRINT, Res.string().getFingerPrint()); | |||
| put(NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_CARD, Res.string().getCard()); | |||
| } | |||
| }; | |||
| public UserInfoShowPanel userShowPanel; | |||
| public EventInfoShowPanel eventShowPanel; | |||
| public static void main(String[] args) { | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| Res.string().switchLanguage(LanguageType.English); | |||
| AttendanceShowPanel demo = new AttendanceShowPanel(); | |||
| JFrame frame = new JFrame(); | |||
| frame.setSize(800, 560); | |||
| frame.add(demo); | |||
| System.out.println("AttendanceShowPanel Test"); | |||
| frame.setVisible(true); | |||
| } | |||
| } | |||
| @@ -0,0 +1,209 @@ | |||
| package com.netsdk.demo.frame.Attendance; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.KeyEvent; | |||
| import java.awt.event.KeyListener; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JTextArea; | |||
| import javax.swing.JTextField; | |||
| import com.netsdk.common.Base64; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.AttendanceModule; | |||
| import com.netsdk.demo.module.AttendanceModule.OPERATE_TYPE; | |||
| import com.netsdk.demo.module.AttendanceModule.UserData; | |||
| /** | |||
| * 通过信息ID操作信息对话框 | |||
| */ | |||
| public class OperateByFingerPrintIdDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public OperateByFingerPrintIdDialog() { | |||
| setTitle(Res.string().getOperateByFingerPrintId()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(600, 500); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
| ////////// 查询条件 ///////////////// | |||
| JLabel fingerPrintIdLabel = new JLabel(Res.string().getFingerPrintId(), JLabel.CENTER); | |||
| fingerPrintIdTextField = new JTextField(); | |||
| fingerPrintIdLabel.setPreferredSize(new Dimension(85, 20)); | |||
| fingerPrintIdTextField.setPreferredSize(new Dimension(100, 20)); | |||
| ////////// 信息功能 ///////////////// | |||
| searchFingerPrintBtn = new JButton(Res.string().getSearchFingerPrint()); | |||
| deleteFingerPrintBtn = new JButton(Res.string().getDeleteFingerPrint()); | |||
| searchFingerPrintBtn.setPreferredSize(new Dimension(140, 20)); | |||
| deleteFingerPrintBtn.setPreferredSize(new Dimension(140, 20)); | |||
| JPanel functionPanel = new JPanel(); | |||
| BorderEx.set(functionPanel, Res.string().getOperateByFingerPrintId(), 1); | |||
| functionPanel.add(fingerPrintIdLabel); | |||
| functionPanel.add(fingerPrintIdTextField); | |||
| functionPanel.add(searchFingerPrintBtn); | |||
| functionPanel.add(deleteFingerPrintBtn); | |||
| //////////信息信息 ///////////////// | |||
| JPanel fingerPrintPanel = new JPanel(); | |||
| BorderEx.set(fingerPrintPanel, Res.string().getFingerPrintInfo(), 1); | |||
| fingerPrintPanel.setLayout(null); | |||
| JLabel userIdLabel = new JLabel(Res.string().getUserId()); | |||
| userId = new JLabel(); | |||
| JLabel fingerPrintDataLabel = new JLabel(Res.string().getFingerPrintData()); | |||
| fingerPrintData = new JTextArea(); | |||
| fingerPrintData.setBackground(null); | |||
| fingerPrintData.setEditable(false); | |||
| fingerPrintData.setLineWrap(true); | |||
| JScrollPane scrollPane = new JScrollPane(fingerPrintData); | |||
| userIdLabel.setBounds(30, 30, 90, 20); | |||
| userId.setBounds(150, 30, 300, 20); | |||
| fingerPrintDataLabel.setBounds(30, 60, 150, 20); | |||
| fingerPrintData.setBounds(30, 80, 600, 20); | |||
| scrollPane.setBounds(30, 80, 550, 300); | |||
| scrollPane.setBorder(null); | |||
| fingerPrintPanel.add(userIdLabel); | |||
| fingerPrintPanel.add(userId); | |||
| fingerPrintPanel.add(fingerPrintDataLabel); | |||
| fingerPrintPanel.add(scrollPane); | |||
| add(functionPanel, BorderLayout.NORTH); | |||
| add(fingerPrintPanel, BorderLayout.CENTER); | |||
| fingerPrintIdTextField.addKeyListener(new KeyListener() { | |||
| public void keyTyped(KeyEvent e) { | |||
| int key = e.getKeyChar(); | |||
| if (key < 48 || key > 57) { | |||
| e.consume(); | |||
| } | |||
| } | |||
| public void keyPressed(KeyEvent e) {} | |||
| public void keyReleased(KeyEvent e) {} | |||
| }); | |||
| listener = new FingerPrintIdOperateActionListener(); | |||
| searchFingerPrintBtn.addActionListener(listener); | |||
| deleteFingerPrintBtn.addActionListener(listener); | |||
| } | |||
| public String getFingerPrintId() { | |||
| if (fingerPrintIdTextField.getText().isEmpty()) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInput()+Res.string().getFingerPrintId(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return null; | |||
| } | |||
| try { | |||
| Integer.parseInt(fingerPrintIdTextField.getText()); | |||
| }catch (NumberFormatException e){ | |||
| JOptionPane.showMessageDialog(null, Res.string().getFingerPrintIdIllegal(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return null; | |||
| } | |||
| return fingerPrintIdTextField.getText(); | |||
| } | |||
| public void searchFingerPrint() { | |||
| clearFingerPrintInfo(); | |||
| String fingerPrintId = getFingerPrintId(); | |||
| if (fingerPrintId == null) { | |||
| return; | |||
| } | |||
| UserData userData = AttendanceModule.getFingerRecord(Integer.parseInt(fingerPrintId)); | |||
| if (userData == null) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if (userData.szFingerPrintInfo[0].length == 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFingerPrintIdNotExist(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| dealFingerPrintInfo(userData); | |||
| } | |||
| public void dealFingerPrintInfo(UserData userData) { | |||
| userId.setText(userData.userId); | |||
| fingerPrintData.setText(formatFingerPrintData(userData.szFingerPrintInfo[0])); | |||
| } | |||
| private String formatFingerPrintData(byte[] fingerPrintData) { | |||
| String formatData = Base64.getEncoder().encodeToString(fingerPrintData); | |||
| return formatData; | |||
| } | |||
| public void clearFingerPrintInfo() { | |||
| userId.setText(""); | |||
| fingerPrintData.setText(""); | |||
| } | |||
| /** | |||
| * 按键监听实现类 | |||
| */ | |||
| private class FingerPrintIdOperateActionListener implements ActionListener { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| OPERATE_TYPE emType = getOperateType(arg0.getSource()); | |||
| switch(emType) { | |||
| case SEARCH_FINGERPRINT_BY_ID: | |||
| searchFingerPrint(); | |||
| break; | |||
| case DELETE_FINGERPRINT_BY_ID: | |||
| String fingerPrintId = getFingerPrintId(); | |||
| if (fingerPrintId == null) { | |||
| return; | |||
| } | |||
| new AttendanceOperateShareDialog(emType, fingerPrintId).setVisible(true); | |||
| break; | |||
| default: | |||
| break; | |||
| } | |||
| } | |||
| private OPERATE_TYPE getOperateType(Object btn) { | |||
| OPERATE_TYPE type = OPERATE_TYPE.UNKNOWN; | |||
| if (btn == searchFingerPrintBtn) { // 查找信息 | |||
| type = OPERATE_TYPE.SEARCH_FINGERPRINT_BY_ID; | |||
| }else if (btn == deleteFingerPrintBtn) { // 删除信息 | |||
| type = OPERATE_TYPE.DELETE_FINGERPRINT_BY_ID; | |||
| }else { | |||
| System.err.println("Unknown Event: " + btn); | |||
| } | |||
| return type; | |||
| } | |||
| } | |||
| private JTextField fingerPrintIdTextField; | |||
| public JButton searchFingerPrintBtn; | |||
| private JButton deleteFingerPrintBtn; | |||
| private JLabel userId; | |||
| private JTextArea fingerPrintData; | |||
| private FingerPrintIdOperateActionListener listener; | |||
| } | |||
| @@ -0,0 +1,281 @@ | |||
| package com.netsdk.demo.frame.Attendance; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.util.Vector; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JSplitPane; | |||
| import javax.swing.JTable; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.ListSelectionModel; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import com.netsdk.common.Base64; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.AttendanceModule; | |||
| import com.netsdk.demo.module.AttendanceModule.OPERATE_TYPE; | |||
| import com.netsdk.demo.module.AttendanceModule.UserData; | |||
| public class OperateByUserIdDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private UserData userData; | |||
| public OperateByUserIdDialog(UserData userData) { | |||
| setTitle(Res.string().getOperateByUserId()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(570, 383); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
| ////////// 用户信息 (不可改变)///////////////// | |||
| JPanel userInfoPanel = new JPanel(); | |||
| userInfoPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); | |||
| BorderEx.set(userInfoPanel, Res.string().getUserInfo(), 2); | |||
| JLabel userIdLabel = new JLabel(Res.string().getUserId(), JLabel.CENTER); | |||
| JTextField userIdTextField = new JTextField(userData.userId); | |||
| JLabel userNameLabel = new JLabel(Res.string().getUserName(true), JLabel.CENTER); | |||
| JTextField userNameTextField = new JTextField(userData.userName); | |||
| JLabel cardNoLabel = new JLabel(Res.string().getCardNo(), JLabel.CENTER); | |||
| JTextField cardNoTextField = new JTextField(userData.cardNo); | |||
| userIdTextField.setEnabled(false); | |||
| userNameTextField.setEnabled(false); | |||
| cardNoTextField.setEnabled(false); | |||
| Dimension dimLable = new Dimension(55, 20); | |||
| userIdLabel.setPreferredSize(dimLable); | |||
| userNameLabel.setPreferredSize(dimLable); | |||
| cardNoLabel.setPreferredSize(dimLable); | |||
| Dimension dimValue = new Dimension(100, 20); | |||
| userIdTextField.setPreferredSize(dimValue); | |||
| userNameTextField.setPreferredSize(dimValue); | |||
| cardNoTextField.setPreferredSize(dimValue); | |||
| userInfoPanel.add(userIdLabel); | |||
| userInfoPanel.add(userIdTextField); | |||
| userInfoPanel.add(userNameLabel); | |||
| userInfoPanel.add(userNameTextField); | |||
| userInfoPanel.add(cardNoLabel); | |||
| userInfoPanel.add(cardNoTextField); | |||
| ////////// 信息功能 ///////////////// | |||
| JPanel functionPanel = new JPanel(); | |||
| BorderEx.set(functionPanel, Res.string().getOperateByUserId(), 2); | |||
| searchFingerPrintBtn = new JButton(Res.string().getSearchFingerPrint()); | |||
| addFingerPrintBtn = new JButton(Res.string().getAddFingerPrint()); | |||
| deleteFingerPrintBtn = new JButton(Res.string().getDeleteFingerPrint()); | |||
| searchFingerPrintBtn.setPreferredSize(new Dimension(150, 20)); | |||
| addFingerPrintBtn.setPreferredSize(new Dimension(150, 20)); | |||
| deleteFingerPrintBtn.setPreferredSize(new Dimension(150, 20)); | |||
| functionPanel.add(searchFingerPrintBtn); | |||
| functionPanel.add(addFingerPrintBtn); | |||
| functionPanel.add(deleteFingerPrintBtn); | |||
| //////////布局 ///////////////// | |||
| JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); | |||
| splitPane.setDividerSize(0); | |||
| splitPane.setBorder(null); | |||
| splitPane.add(userInfoPanel, JSplitPane.TOP); | |||
| splitPane.add(functionPanel, JSplitPane.BOTTOM); | |||
| add(splitPane, BorderLayout.NORTH); | |||
| fingerPrintShowPanel = new FingerPrintShowPanel(); | |||
| add(fingerPrintShowPanel, BorderLayout.CENTER); | |||
| listener = new UserIdOperateActionListener(); | |||
| searchFingerPrintBtn.addActionListener(listener); | |||
| addFingerPrintBtn.addActionListener(listener); | |||
| deleteFingerPrintBtn.addActionListener(listener); | |||
| this.userData = userData; | |||
| } | |||
| public void searchFingerPrint() { | |||
| clearTable(); | |||
| boolean bSuccess = AttendanceModule.getFingerByUserId(userData.userId, userData); | |||
| if (bSuccess){ | |||
| fingerPrintShowPanel.insertData(userData); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| public void clearTable() { | |||
| fingerPrintShowPanel.clearData(); | |||
| } | |||
| public void addFingerPrint(int fingerPrintId, byte[] fingerPrintData) { | |||
| fingerPrintShowPanel.insertData(fingerPrintId, fingerPrintData); | |||
| } | |||
| /** | |||
| * 按键监听实现类 | |||
| */ | |||
| private class UserIdOperateActionListener implements ActionListener { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| OPERATE_TYPE emType = getOperateType(arg0.getSource()); | |||
| switch(emType) { | |||
| case SEARCH_FINGERPRINT_BY_USERID: | |||
| searchFingerPrint(); | |||
| break; | |||
| case ADD_FINGERPRINT: | |||
| new AddFingerPrintDialog(userData.userId).setVisible(true); | |||
| break; | |||
| case DELETE_FINGERPRINT_BY_USERID: | |||
| new AttendanceOperateShareDialog(emType, userData).setVisible(true); | |||
| break; | |||
| default: | |||
| break; | |||
| } | |||
| } | |||
| private OPERATE_TYPE getOperateType(Object btn) { | |||
| OPERATE_TYPE type = OPERATE_TYPE.UNKNOWN; | |||
| if (btn == searchFingerPrintBtn) { // 查找信息 | |||
| type = OPERATE_TYPE.SEARCH_FINGERPRINT_BY_USERID; | |||
| }else if (btn == addFingerPrintBtn) { // 添加信息 | |||
| type = OPERATE_TYPE.ADD_FINGERPRINT; | |||
| }else if (btn == deleteFingerPrintBtn) { // 删除信息(用户ID) | |||
| type = OPERATE_TYPE.DELETE_FINGERPRINT_BY_USERID; | |||
| }else { | |||
| System.err.println("Unknown Event: " + btn); | |||
| } | |||
| return type; | |||
| } | |||
| } | |||
| /** | |||
| * 信息信息显示界面 | |||
| * */ | |||
| public class FingerPrintShowPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public static final int INDEX = 0; | |||
| public static final int USER_ID = 1; | |||
| public static final int FINGERPRINT_ID = 2; | |||
| public static final int FINGERPRINT_DATA = 3; | |||
| public final static int MAX_FINGERPRINT_NUM = 10; // 最大信息个数, 也做为显示个数 | |||
| private int realRows = 0; // 实际显示个数 | |||
| public FingerPrintShowPanel() { | |||
| BorderEx.set(this, Res.string().getFingerPrintInfo(), 1); | |||
| setLayout(new BorderLayout()); | |||
| setPreferredSize(new Dimension(550, 375)); | |||
| Vector<String> columnNames = new Vector<String>(); | |||
| columnNames.add(Res.string().getIndex()); // 序号 | |||
| columnNames.add(Res.string().getUserId()); // 用户编号 | |||
| columnNames.add(Res.string().getFingerPrintId()); // 信息ID | |||
| columnNames.add(Res.string().getFingerPrintData()); // 信息 | |||
| tableModel = new DefaultTableModel(null, columnNames); | |||
| table = new JTable(tableModel) { | |||
| private static final long serialVersionUID = 1L; | |||
| public boolean isCellEditable(int rowIndex, int columnIndex) { // 不可编辑 | |||
| return false; | |||
| } | |||
| }; | |||
| tableModel.setRowCount(MAX_FINGERPRINT_NUM); // 设置最小显示行 | |||
| table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行(其实无意义) | |||
| table.getColumnModel().getColumn(INDEX).setPreferredWidth(80); | |||
| table.getColumnModel().getColumn(USER_ID).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(FINGERPRINT_ID).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(FINGERPRINT_DATA).setPreferredWidth(8888); | |||
| ((DefaultTableCellRenderer) | |||
| table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(JLabel.CENTER); | |||
| table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); | |||
| JScrollPane scrollPane = new JScrollPane(table); | |||
| scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); | |||
| scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |||
| add(scrollPane, BorderLayout.CENTER); | |||
| } | |||
| public void insertData(UserData userData) { | |||
| if (userData.nFingerPrintIDs == null) { | |||
| return; | |||
| } | |||
| clearData(); | |||
| tableModel.setRowCount(0); | |||
| for (int i = 0; i < userData.nFingerPrintIDs.length; ++i) { | |||
| insertFingerPrintData(userData.nFingerPrintIDs[i], userData.szFingerPrintInfo[i]); | |||
| } | |||
| tableModel.setRowCount(MAX_FINGERPRINT_NUM); | |||
| table.updateUI(); | |||
| } | |||
| public void insertData(int fingerPrintId, byte[] fingerPrintData) { | |||
| tableModel.setRowCount(realRows); | |||
| insertFingerPrintData(fingerPrintId, fingerPrintData); | |||
| tableModel.setRowCount(MAX_FINGERPRINT_NUM); | |||
| table.updateUI(); | |||
| } | |||
| private void insertFingerPrintData(int fingerPrintId, byte[] fingerPrintData) { | |||
| ++realRows; | |||
| Vector<String> vector = new Vector<String>(); | |||
| vector.add(String.valueOf(realRows)); | |||
| vector.add(userData.userId); | |||
| vector.add(String.valueOf(fingerPrintId)); | |||
| vector.add(formatFingerPrintData(fingerPrintData)); | |||
| tableModel.addRow(vector); | |||
| } | |||
| private String formatFingerPrintData(byte[] fingerPrintData) { | |||
| String formatData = Base64.getEncoder().encodeToString(fingerPrintData); | |||
| return formatData; | |||
| } | |||
| public void clearData() { | |||
| realRows = 0; | |||
| tableModel.setRowCount(0); | |||
| tableModel.setRowCount(MAX_FINGERPRINT_NUM); | |||
| table.updateUI(); | |||
| } | |||
| private JTable table = null; | |||
| private DefaultTableModel tableModel = null; | |||
| } | |||
| public JButton searchFingerPrintBtn; | |||
| private JButton addFingerPrintBtn; | |||
| private JButton deleteFingerPrintBtn; | |||
| private UserIdOperateActionListener listener; | |||
| private FingerPrintShowPanel fingerPrintShowPanel; | |||
| } | |||
| @@ -0,0 +1,153 @@ | |||
| package com.netsdk.demo.frame.Attendance; | |||
| import java.awt.AWTEvent; | |||
| import java.awt.Dimension; | |||
| import java.awt.EventQueue; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.Toolkit; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.frame.Attendance.AttendanceShowPanel.EventInfoShowPanel; | |||
| import com.netsdk.demo.module.AttendanceModule; | |||
| import com.netsdk.demo.module.AttendanceModule.AccessEventInfo; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| /** | |||
| * 订阅面板 | |||
| */ | |||
| public class SubscribePanel extends JPanel{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private java.awt.Component target = this; // 目标 | |||
| private boolean bSubscribe = false; // 订阅标志 | |||
| private EventInfoShowPanel eventShowPanel; // 事件显示界面 | |||
| public SubscribePanel(EventInfoShowPanel eventPanel) { | |||
| BorderEx.set(this, Res.string().getSubscribe(), 1); | |||
| setLayout(new FlowLayout(FlowLayout.CENTER, 5, 30)); | |||
| setPreferredSize(new Dimension(180, 80)); | |||
| eventShowPanel = eventPanel; | |||
| callback = new fAnalyzerDataCB(); | |||
| subscribeBtn = new JButton(Res.string().getSubscribe()); | |||
| subscribeBtn.setPreferredSize(new Dimension(150, 20)); | |||
| add(subscribeBtn); | |||
| subscribeBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if (bSubscribe) { | |||
| AttendanceModule.stopRealLoadPicture(); | |||
| eventShowPanel.clearEvent(); | |||
| setSubscribeStatus(false); | |||
| }else { | |||
| if (AttendanceModule.realLoadPicture(callback)) { | |||
| setSubscribeStatus(true); | |||
| }else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSubscribeFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| subscribeBtn.setEnabled(false); | |||
| } | |||
| public void setButtonEnable(boolean b) { | |||
| setSubscribeStatus(false); | |||
| subscribeBtn.setEnabled(b); | |||
| } | |||
| public void setSubscribeStatus(boolean b) { | |||
| bSubscribe = b; | |||
| if (bSubscribe) { | |||
| subscribeBtn.setText(Res.string().getUnSubscribe()); | |||
| }else { | |||
| subscribeBtn.setText(Res.string().getSubscribe()); | |||
| } | |||
| } | |||
| /** | |||
| * 智能报警事件回调 | |||
| **/ | |||
| public class fAnalyzerDataCB implements fAnalyzerDataCallBack { | |||
| public final EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); | |||
| @Override | |||
| public int invoke(LLong lAnalyzerHandle, int dwAlarmType, | |||
| Pointer pAlarmInfo, Pointer pBuffer, int dwBufSize, | |||
| Pointer dwUser, int nSequence, Pointer reserved) { | |||
| if(pAlarmInfo == null) { | |||
| return 0; | |||
| } | |||
| switch(dwAlarmType) { | |||
| case NetSDKLib.EVENT_IVS_ACCESS_CTL: // 门禁事件 | |||
| DEV_EVENT_ACCESS_CTL_INFO event = new DEV_EVENT_ACCESS_CTL_INFO(); | |||
| ToolKits.GetPointerData(pAlarmInfo, event); | |||
| AccessEventInfo accessEvent = new AccessEventInfo(); | |||
| accessEvent.userId = new String(event.szUserID).trim(); | |||
| accessEvent.cardNo = new String(event.szCardNo).trim(); | |||
| accessEvent.eventTime = event.UTC.toStringTime(); | |||
| accessEvent.openDoorMethod = event.emOpenMethod; | |||
| if (eventQueue != null) { | |||
| eventQueue.postEvent(new AccessEvent(target, accessEvent)); | |||
| } | |||
| break; | |||
| default: | |||
| break; | |||
| } | |||
| return 0; | |||
| } | |||
| } | |||
| /** | |||
| * 门禁事件 | |||
| **/ | |||
| class AccessEvent extends AWTEvent { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public static final int EVENT_ID = AWTEvent.RESERVED_ID_MAX + 1; | |||
| private AccessEventInfo accessEvent; | |||
| public AccessEvent(Object target, AccessEventInfo accessEvent) { | |||
| super(target, EVENT_ID); | |||
| this.accessEvent = accessEvent; | |||
| } | |||
| public AccessEventInfo getAccessEventInfo() { | |||
| return this.accessEvent; | |||
| } | |||
| } | |||
| @Override | |||
| protected void processEvent( AWTEvent event) { | |||
| if ( event instanceof AccessEvent) { | |||
| AccessEventInfo accessEventInfo = ((AccessEvent)event).getAccessEventInfo(); | |||
| eventShowPanel.insertEvent(accessEventInfo); | |||
| } else { | |||
| super.processEvent(event); | |||
| } | |||
| } | |||
| private JButton subscribeBtn; // 订阅按钮 | |||
| private fAnalyzerDataCallBack callback; // 事件回调 | |||
| } | |||
| @@ -0,0 +1,134 @@ | |||
| package com.netsdk.demo.frame.AutoRegister; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JPasswordField; | |||
| import javax.swing.JTextField; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.DeviceManagerListener; | |||
| import com.netsdk.common.Res; | |||
| /** | |||
| * 在树上添加设备 | |||
| */ | |||
| public class AddDeviceDialog extends JDialog{ | |||
| private static final long serialVersionUID = 1L; | |||
| private DeviceManagerListener listener; | |||
| public void addDeviceManagerListener(DeviceManagerListener listener) { | |||
| this.listener = listener; | |||
| } | |||
| public AddDeviceDialog(){ | |||
| setTitle(Res.string().getAddDevice()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(220, 180); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| AddDevicePanel addDevicePanel = new AddDevicePanel(); | |||
| add(addDevicePanel, BorderLayout.CENTER); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e){ | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| /* | |||
| * 添加设备面板 | |||
| */ | |||
| private class AddDevicePanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public AddDevicePanel() { | |||
| BorderEx.set(this, "", 2); | |||
| setLayout(new FlowLayout()); | |||
| JLabel deviceIdLabel = new JLabel(Res.string().getDeviceID(), JLabel.CENTER); | |||
| JLabel usernameLabel = new JLabel(Res.string().getUserName(), JLabel.CENTER); | |||
| JLabel passwordLabel = new JLabel(Res.string().getPassword(), JLabel.CENTER); | |||
| deviceIdLabel.setPreferredSize(new Dimension(60, 21)); | |||
| usernameLabel.setPreferredSize(new Dimension(60, 21)); | |||
| passwordLabel.setPreferredSize(new Dimension(60, 21)); | |||
| deviceIdTextField = new JTextField(); | |||
| usernameTextField = new JTextField(); | |||
| passwordPasswordField = new JPasswordField(); | |||
| deviceIdTextField.setPreferredSize(new Dimension(120, 20)); | |||
| usernameTextField.setPreferredSize(new Dimension(120, 20)); | |||
| passwordPasswordField.setPreferredSize(new Dimension(120, 20)); | |||
| JButton addDeviceBtn = new JButton(Res.string().getAdd()); | |||
| JButton cancelBtn = new JButton(Res.string().getCancel()); | |||
| addDeviceBtn.setPreferredSize(new Dimension(90, 21)); | |||
| cancelBtn.setPreferredSize(new Dimension(90, 21)); | |||
| add(deviceIdLabel); | |||
| add(deviceIdTextField); | |||
| add(usernameLabel); | |||
| add(usernameTextField); | |||
| add(passwordLabel); | |||
| add(passwordPasswordField); | |||
| add(addDeviceBtn); | |||
| add(cancelBtn); | |||
| // 添加 | |||
| addDeviceBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| if(deviceIdTextField.getText().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getDeviceID(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(usernameTextField.getText().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getUserName(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if((new String(passwordPasswordField.getPassword()).trim()).equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getPassword(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| dispose(); | |||
| listener.onDeviceManager(deviceIdTextField.getText(), | |||
| usernameTextField.getText(), | |||
| new String(passwordPasswordField.getPassword()).trim()); | |||
| } | |||
| }); | |||
| // 取消,关闭 | |||
| cancelBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| private JTextField deviceIdTextField; | |||
| private JTextField usernameTextField; | |||
| private JPasswordField passwordPasswordField; | |||
| } | |||
| @@ -0,0 +1,341 @@ | |||
| package com.netsdk.demo.frame.AutoRegister; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.concurrent.ExecutorService; | |||
| import java.util.concurrent.Executors; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JCheckBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JTextField; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.LoginPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.AutoRegisterModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.CFG_DVRIP_INFO; | |||
| /** | |||
| * 主动注册网络配置 | |||
| */ | |||
| public class DeviceConfigDialog extends JDialog{ | |||
| private static final long serialVersionUID = 1L; | |||
| private CFG_DVRIP_INFO info = null; | |||
| private ExecutorService executorService = Executors.newSingleThreadExecutor(); | |||
| public DeviceConfigDialog(){ | |||
| setTitle(Res.string().getDeviceConfig()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(300, 380); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| loginDevicePanel = new LoginDevicePanel(); | |||
| ConfigDevicePanel configDevicePanel = new ConfigDevicePanel(); | |||
| add(loginDevicePanel, BorderLayout.NORTH); | |||
| add(configDevicePanel, BorderLayout.CENTER); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e){ | |||
| if(!executorService.isShutdown()) { | |||
| executorService.shutdown(); | |||
| } | |||
| LoginModule.logout(); | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| /* | |||
| * 登陆设备面板 | |||
| */ | |||
| private class LoginDevicePanel extends LoginPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public LoginDevicePanel() { | |||
| BorderEx.set(this, Res.string().getLogin(), 2); | |||
| setLayout(new FlowLayout()); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.height = 180; | |||
| setPreferredSize(dimension); | |||
| ipLabel.setPreferredSize(new Dimension(100, 21)); | |||
| portLabel.setPreferredSize(new Dimension(100, 21)); | |||
| nameLabel.setPreferredSize(new Dimension(100, 21)); | |||
| passwordLabel.setPreferredSize(new Dimension(100, 21)); | |||
| ipLabel.setHorizontalAlignment(JLabel.CENTER); | |||
| portLabel.setHorizontalAlignment(JLabel.CENTER); | |||
| nameLabel.setHorizontalAlignment(JLabel.CENTER); | |||
| passwordLabel.setHorizontalAlignment(JLabel.CENTER); | |||
| ipTextArea.setPreferredSize(new Dimension(140, 21)); | |||
| portTextArea.setPreferredSize(new Dimension(140, 21)); | |||
| nameTextArea.setPreferredSize(new Dimension(140, 21)); | |||
| passwordTextArea.setPreferredSize(new Dimension(140, 21)); | |||
| loginBtn.setPreferredSize(new Dimension(120, 21)); | |||
| logoutBtn.setPreferredSize(new Dimension(120, 21)); | |||
| add(ipLabel); | |||
| add(ipTextArea); | |||
| add(portLabel); | |||
| add(portTextArea); | |||
| add(nameLabel); | |||
| add(nameTextArea); | |||
| add(passwordLabel); | |||
| add(passwordTextArea); | |||
| add(loginBtn); | |||
| add(logoutBtn); | |||
| // 登陆 | |||
| loginBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| login(); | |||
| } | |||
| }); | |||
| // 登出 | |||
| logoutBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| logout(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /* | |||
| * 配置设备面板 | |||
| */ | |||
| private class ConfigDevicePanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public ConfigDevicePanel() { | |||
| BorderEx.set(this, Res.string().getDeviceConfig(), 2); | |||
| setLayout(new FlowLayout()); | |||
| enableCheckBox = new JCheckBox(Res.string().getEnable()); | |||
| JLabel nullLabel = new JLabel(); | |||
| JLabel autoRegisterIpLabel = new JLabel(Res.string().getRegisterAddress(), JLabel.CENTER); | |||
| JLabel autoRegisterPortLabel = new JLabel(Res.string().getRegisterPort(), JLabel.CENTER); | |||
| JLabel deviceIdLabel = new JLabel(Res.string().getDeviceID(), JLabel.CENTER); | |||
| enableCheckBox.setPreferredSize(new Dimension(80, 21)); | |||
| nullLabel.setPreferredSize(new Dimension(120, 21)); | |||
| autoRegisterIpLabel.setPreferredSize(new Dimension(100, 21)); | |||
| autoRegisterPortLabel.setPreferredSize(new Dimension(100, 21)); | |||
| deviceIdLabel.setPreferredSize(new Dimension(100, 21)); | |||
| autoRegisterIpTextField = new JTextField(); | |||
| autoRegisterPortTextField = new JTextField(); | |||
| deviceIdTextField = new JTextField(); | |||
| autoRegisterIpTextField.setPreferredSize(new Dimension(140, 21)); | |||
| autoRegisterPortTextField.setPreferredSize(new Dimension(140, 21)); | |||
| deviceIdTextField.setPreferredSize(new Dimension(140, 21)); | |||
| getBtn = new JButton(Res.string().getGet()); | |||
| setBtn = new JButton(Res.string().getSet()); | |||
| getBtn.setPreferredSize(new Dimension(120, 21)); | |||
| setBtn.setPreferredSize(new Dimension(120, 21)); | |||
| add(enableCheckBox); | |||
| add(nullLabel); | |||
| add(autoRegisterIpLabel); | |||
| add(autoRegisterIpTextField); | |||
| add(autoRegisterPortLabel); | |||
| add(autoRegisterPortTextField); | |||
| add(deviceIdLabel); | |||
| add(deviceIdTextField); | |||
| add(getBtn); | |||
| add(setBtn); | |||
| enableCheckBox.setSelected(true); | |||
| enableCheckBox.setEnabled(false); | |||
| getBtn.setEnabled(false); | |||
| setBtn.setEnabled(false); | |||
| autoRegisterIpTextField.setEnabled(false); | |||
| autoRegisterPortTextField.setEnabled(false); | |||
| deviceIdTextField.setEnabled(false); | |||
| // 获取 | |||
| getBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| executorService.execute(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| getBtn.setEnabled(false); | |||
| } | |||
| }); | |||
| executorService.execute(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| getConfig(); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| // 设置 | |||
| setBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| executorService.execute(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| setBtn.setEnabled(false); | |||
| } | |||
| }); | |||
| executorService.execute(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| setConfig(); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 登陆 | |||
| private void login() { | |||
| if(loginDevicePanel.checkLoginText()) { | |||
| if(LoginModule.login(loginDevicePanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginDevicePanel.portTextArea.getText()), | |||
| loginDevicePanel.nameTextArea.getText(), | |||
| new String(loginDevicePanel.passwordTextArea.getPassword()))) { | |||
| loginDevicePanel.setButtonEnable(true); | |||
| enableCheckBox.setEnabled(true); | |||
| getBtn.setEnabled(true); | |||
| setBtn.setEnabled(true); | |||
| autoRegisterIpTextField.setEnabled(true); | |||
| autoRegisterPortTextField.setEnabled(true); | |||
| deviceIdTextField.setEnabled(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| } | |||
| // 登出 | |||
| private void logout() { | |||
| LoginModule.logout(); | |||
| loginDevicePanel.setButtonEnable(false); | |||
| enableCheckBox.setEnabled(false); | |||
| getBtn.setEnabled(false); | |||
| setBtn.setEnabled(false); | |||
| autoRegisterIpTextField.setEnabled(false); | |||
| autoRegisterPortTextField.setEnabled(false); | |||
| deviceIdTextField.setEnabled(false); | |||
| autoRegisterIpTextField.setText(""); | |||
| autoRegisterPortTextField.setText(""); | |||
| deviceIdTextField.setText(""); | |||
| } | |||
| // 获取 | |||
| private void getConfig() { | |||
| info = AutoRegisterModule.getDVRIPConfig(LoginModule.m_hLoginHandle); | |||
| if(info == null) { | |||
| autoRegisterIpTextField.setText(""); | |||
| autoRegisterPortTextField.setText(""); | |||
| deviceIdTextField.setText(""); | |||
| JOptionPane.showMessageDialog(null, Res.string().getGet() + Res.string().getFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } else { | |||
| if(info.stuRegisters[0].bEnable == 1) { | |||
| enableCheckBox.setSelected(true); | |||
| } else { | |||
| enableCheckBox.setSelected(false); | |||
| } | |||
| autoRegisterIpTextField.setText(new String(info.stuRegisters[0].stuServers[0].szAddress).trim()); | |||
| autoRegisterPortTextField.setText(String.valueOf(info.stuRegisters[0].stuServers[0].nPort)); | |||
| try { | |||
| deviceIdTextField.setText(new String(info.stuRegisters[0].szDeviceID, "GBK").trim()); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } | |||
| getBtn.setEnabled(true); | |||
| } | |||
| /** | |||
| * 设置(在获取的基础上配置) | |||
| */ | |||
| private void setConfig() { | |||
| info = AutoRegisterModule.getDVRIPConfig(LoginModule.m_hLoginHandle); | |||
| if(autoRegisterIpTextField.getText().equals("")) { | |||
| setBtn.setEnabled(true); | |||
| JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getRegisterAddress(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(autoRegisterPortTextField.getText().equals("")) { | |||
| setBtn.setEnabled(true); | |||
| JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getRegisterPort(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(deviceIdTextField.getText().equals("")) { | |||
| setBtn.setEnabled(true); | |||
| JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getDeviceID(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| // win下,中文需要转换为GBK | |||
| byte[] deviceId = null; | |||
| try { | |||
| deviceId = deviceIdTextField.getText().getBytes("GBK"); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| System.out.println("登录句柄"+LoginModule.m_hLoginHandle + "是否启用" + enableCheckBox.isSelected() + "ip" + autoRegisterIpTextField.getText() + "端口" + autoRegisterPortTextField.getText() + "设备id" + new String(deviceId)); | |||
| if(AutoRegisterModule.setDVRIPConfig(LoginModule.m_hLoginHandle, | |||
| enableCheckBox.isSelected(), | |||
| autoRegisterIpTextField.getText(), | |||
| Integer.parseInt(autoRegisterPortTextField.getText()), | |||
| deviceId, | |||
| info)) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSet() + Res.string().getFailed() + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| setBtn.setEnabled(true); | |||
| } | |||
| private LoginDevicePanel loginDevicePanel; | |||
| private JTextField autoRegisterIpTextField; | |||
| private JTextField autoRegisterPortTextField; | |||
| private JTextField deviceIdTextField; | |||
| private JCheckBox enableCheckBox; | |||
| private JButton getBtn; | |||
| private JButton setBtn; | |||
| } | |||
| @@ -0,0 +1,146 @@ | |||
| package com.netsdk.demo.frame.AutoRegister; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JPasswordField; | |||
| import javax.swing.JTextField; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.DeviceManagerListener; | |||
| import com.netsdk.common.Res; | |||
| /** | |||
| * 在树上修改设备 | |||
| */ | |||
| public class ModifyDeviceDialog extends JDialog{ | |||
| private static final long serialVersionUID = 1L; | |||
| private DeviceManagerListener listener; | |||
| public void addDeviceManagerListener(DeviceManagerListener listener) { | |||
| this.listener = listener; | |||
| } | |||
| private String deviceId = ""; | |||
| private String username = ""; | |||
| private String password = ""; | |||
| public ModifyDeviceDialog(String deviceId, String username, String password){ | |||
| setTitle(Res.string().getModifyDevice()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(220, 180); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| this.deviceId = deviceId; | |||
| this.username = username; | |||
| this.password = password; | |||
| ModifyDevicePanel addDevicePanel = new ModifyDevicePanel(); | |||
| add(addDevicePanel, BorderLayout.CENTER); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e){ | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| /* | |||
| * 修改设备面板 | |||
| */ | |||
| private class ModifyDevicePanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public ModifyDevicePanel() { | |||
| BorderEx.set(this, "", 2); | |||
| setLayout(new FlowLayout()); | |||
| JLabel deviceIdLabel = new JLabel(Res.string().getDeviceID(), JLabel.CENTER); | |||
| JLabel usernameLabel = new JLabel(Res.string().getUserName(), JLabel.CENTER); | |||
| JLabel passwordLabel = new JLabel(Res.string().getPassword(), JLabel.CENTER); | |||
| deviceIdLabel.setPreferredSize(new Dimension(60, 21)); | |||
| usernameLabel.setPreferredSize(new Dimension(60, 21)); | |||
| passwordLabel.setPreferredSize(new Dimension(60, 21)); | |||
| deviceIdTextField = new JTextField(); | |||
| usernameTextField = new JTextField(); | |||
| passwordPasswordField = new JPasswordField(); | |||
| deviceIdTextField.setPreferredSize(new Dimension(120, 20)); | |||
| usernameTextField.setPreferredSize(new Dimension(120, 20)); | |||
| passwordPasswordField.setPreferredSize(new Dimension(120, 20)); | |||
| JButton modifyDeviceBtn = new JButton(Res.string().getModify()); | |||
| JButton cancelBtn = new JButton(Res.string().getCancel()); | |||
| modifyDeviceBtn.setPreferredSize(new Dimension(90, 21)); | |||
| cancelBtn.setPreferredSize(new Dimension(90, 21)); | |||
| add(deviceIdLabel); | |||
| add(deviceIdTextField); | |||
| add(usernameLabel); | |||
| add(usernameTextField); | |||
| add(passwordLabel); | |||
| add(passwordPasswordField); | |||
| add(modifyDeviceBtn); | |||
| add(cancelBtn); | |||
| deviceIdTextField.setText(deviceId); | |||
| usernameTextField.setText(username); | |||
| passwordPasswordField.setText(password); | |||
| // 修改 | |||
| modifyDeviceBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| if(deviceIdTextField.getText().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getDeviceID(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(usernameTextField.getText().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getUserName(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if((new String(passwordPasswordField.getPassword()).trim()).equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getPassword(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| dispose(); | |||
| listener.onDeviceManager(deviceIdTextField.getText(), | |||
| usernameTextField.getText(), | |||
| new String(passwordPasswordField.getPassword()).trim()); | |||
| } | |||
| }); | |||
| // 取消,关闭 | |||
| cancelBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| private JTextField deviceIdTextField; | |||
| private JTextField usernameTextField; | |||
| private JPasswordField passwordPasswordField; | |||
| } | |||
| @@ -0,0 +1,475 @@ | |||
| package com.netsdk.demo.frame; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Color; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.GridLayout; | |||
| import java.awt.Panel; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.awt.image.BufferedImage; | |||
| import java.io.ByteArrayInputStream; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.util.Vector; | |||
| import javax.imageio.ImageIO; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.UIManager; | |||
| import javax.swing.border.EmptyBorder; | |||
| import com.netsdk.common.*; | |||
| import com.netsdk.demo.module.*; | |||
| import com.netsdk.lib.*; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.sun.jna.CallbackThreadInitializer; | |||
| import com.sun.jna.Native; | |||
| import com.sun.jna.Pointer; | |||
| /** | |||
| * Capture Picture Demo | |||
| */ | |||
| class CapturePictureFrame extends JFrame{ | |||
| private static final long serialVersionUID = 1L; | |||
| // device channel list | |||
| private Vector<String> chnlist = new Vector<String>(); | |||
| // This field indicates whether the device is playing | |||
| private boolean bRealPlay = false; | |||
| // This field indicates whether the device is timing capture | |||
| private boolean bTimerCapture = false; | |||
| // device disconnect callback instance | |||
| private static DisConnect disConnect = new DisConnect(); | |||
| // device reconnect callback instance | |||
| private static HaveReConnect haveReConnect = new HaveReConnect(); | |||
| // realplay handle | |||
| public static LLong m_hPlayHandle = new LLong(0); | |||
| // capture picture frame (this) | |||
| private static JFrame frame = new JFrame(); | |||
| public CapturePictureFrame() { | |||
| setTitle(Res.string().getCapturePicture()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(800, 560); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| LoginModule.init(disConnect, haveReConnect); // init sdk | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| loginPanel = new LoginPanel(); | |||
| realPanel = new RealPanel(); | |||
| picPanel = new PICPanel(); | |||
| add(loginPanel, BorderLayout.NORTH); | |||
| add(realPanel, BorderLayout.CENTER); | |||
| add(picPanel, BorderLayout.EAST); | |||
| loginPanel.addLoginBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(loginPanel.checkLoginText()) { | |||
| if(login()) { | |||
| frame = ToolKits.getFrame(e); | |||
| frame.setTitle(Res.string().getCapturePicture() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| loginPanel.addLogoutBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| frame.setTitle(Res.string().getCapturePicture()); | |||
| logout(); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandle); | |||
| LoginModule.logout(); | |||
| LoginModule.cleanup(); | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /////////////////function/////////////////// | |||
| // device disconnect callback class | |||
| // set it's instance by call CLIENT_Init, when device disconnect sdk will call it. | |||
| private static class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getCapturePicture() + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // device reconnect(success) callback class | |||
| // set it's instance by call CLIENT_SetAutoReconnect, when device reconnect success sdk will call it. | |||
| private static class HaveReConnect implements NetSDKLib.fHaveReConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getCapturePicture() + " : " + Res.string().getOnline()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| public boolean login() { | |||
| Native.setCallbackThreadInitializer(m_CaptureReceiveCB, | |||
| new CallbackThreadInitializer(false, false, "snapPicture callback thread")); | |||
| if(LoginModule.login(loginPanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginPanel.portTextArea.getText()), | |||
| loginPanel.nameTextArea.getText(), | |||
| new String(loginPanel.passwordTextArea.getPassword()))) { | |||
| loginPanel.setButtonEnable(true); | |||
| setButtonEnable(true); | |||
| for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) { | |||
| chnlist.add(Res.string().getChannel() + " " + String.valueOf(i)); | |||
| } | |||
| chnComboBox.setModel(new DefaultComboBoxModel(chnlist)); | |||
| CapturePictureModule.setSnapRevCallBack(m_CaptureReceiveCB); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| public void logout() { | |||
| if (bTimerCapture) { | |||
| CapturePictureModule.stopCapturePicture(chnComboBox.getSelectedIndex()); | |||
| } | |||
| RealPlayModule.stopRealPlay(m_hPlayHandle); | |||
| LoginModule.logout(); | |||
| loginPanel.setButtonEnable(false); | |||
| setButtonEnable(false); | |||
| realPlayWindow.repaint(); | |||
| pictureShowWindow.setOpaque(true); | |||
| pictureShowWindow.repaint(); | |||
| bRealPlay = false; | |||
| realplayBtn.setText(Res.string().getStartRealPlay()); | |||
| for(int i = 0; i < LoginModule.m_stDeviceInfo.byChanNum; i++) { | |||
| chnlist.clear(); | |||
| } | |||
| chnComboBox.setModel(new DefaultComboBoxModel()); | |||
| bTimerCapture = false; | |||
| timerCaptureBtn.setText(Res.string().getTimerCapture()); | |||
| } | |||
| /* | |||
| * realplay show and control panel | |||
| */ | |||
| private class RealPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public RealPanel() { | |||
| BorderEx.set(this, Res.string().getRealplay(), 2); | |||
| setLayout(new BorderLayout()); | |||
| channelPanel = new Panel(); | |||
| realplayPanel = new JPanel(); | |||
| add(channelPanel, BorderLayout.SOUTH); | |||
| add(realplayPanel, BorderLayout.CENTER); | |||
| /************ realplay panel **************/ | |||
| realplayPanel.setLayout(new BorderLayout()); | |||
| realplayPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| realPlayWindow = new Panel(); | |||
| realPlayWindow.setBackground(Color.GRAY); | |||
| realplayPanel.add(realPlayWindow, BorderLayout.CENTER); | |||
| /************ channel and stream panel **************/ | |||
| chnlabel = new JLabel(Res.string().getChannel()); | |||
| chnComboBox = new JComboBox(); | |||
| streamLabel = new JLabel(Res.string().getStreamType()); | |||
| String[] stream = {Res.string().getMasterStream(), Res.string().getSubStream()}; | |||
| streamComboBox = new JComboBox(stream); | |||
| realplayBtn = new JButton(Res.string().getStartRealPlay()); | |||
| channelPanel.setLayout(new FlowLayout()); | |||
| channelPanel.add(chnlabel); | |||
| channelPanel.add(chnComboBox); | |||
| channelPanel.add(streamLabel); | |||
| channelPanel.add(streamComboBox); | |||
| channelPanel.add(realplayBtn); | |||
| chnComboBox.setPreferredSize(new Dimension(90, 20)); | |||
| streamComboBox.setPreferredSize(new Dimension(90, 20)); | |||
| realplayBtn.setPreferredSize(new Dimension(120, 20)); | |||
| realPlayWindow.setEnabled(false); | |||
| chnComboBox.setEnabled(false); | |||
| streamComboBox.setEnabled(false); | |||
| realplayBtn.setEnabled(false); | |||
| realplayBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| realplay(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| public void realplay() { | |||
| if(!bRealPlay) { | |||
| m_hPlayHandle = RealPlayModule.startRealPlay(chnComboBox.getSelectedIndex(), | |||
| streamComboBox.getSelectedIndex()==0? 0:3, | |||
| realPlayWindow); | |||
| if(m_hPlayHandle.longValue() != 0) { | |||
| realPlayWindow.repaint(); | |||
| bRealPlay = true; | |||
| chnComboBox.setEnabled(false); | |||
| streamComboBox.setEnabled(false); | |||
| realplayBtn.setText(Res.string().getStopRealPlay()); | |||
| } | |||
| } else { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandle); | |||
| realPlayWindow.repaint(); | |||
| bRealPlay = false; | |||
| chnComboBox.setEnabled(true && !bTimerCapture); | |||
| streamComboBox.setEnabled(true); | |||
| realplayBtn.setText(Res.string().getStartRealPlay()); | |||
| } | |||
| } | |||
| /* | |||
| * capture picture panel | |||
| */ | |||
| private class PICPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public PICPanel() { | |||
| setPreferredSize(new Dimension(350, 600)); | |||
| BorderEx.set(this, Res.string().getCapturePicture(), 2); | |||
| setLayout(new BorderLayout()); | |||
| pictureShowPanel = new JPanel(); | |||
| capturePanel = new JPanel(); | |||
| add(pictureShowPanel, BorderLayout.CENTER); | |||
| add(capturePanel, BorderLayout.SOUTH); | |||
| /************** capture picture button ************/ | |||
| capturePanel.setLayout(new GridLayout(3, 1)); | |||
| localCaptureBtn = new JButton(Res.string().getLocalCapture()); | |||
| remoteCaptureBtn = new JButton(Res.string().getRemoteCapture()); | |||
| timerCaptureBtn = new JButton(Res.string().getTimerCapture()); | |||
| localCaptureBtn.setPreferredSize(new Dimension(150, 20)); | |||
| remoteCaptureBtn.setPreferredSize(new Dimension(150, 20)); | |||
| timerCaptureBtn.setPreferredSize(new Dimension(150, 20)); | |||
| capturePanel.add(localCaptureBtn); | |||
| capturePanel.add(remoteCaptureBtn); | |||
| capturePanel.add(timerCaptureBtn); | |||
| localCaptureBtn.setEnabled(false); | |||
| remoteCaptureBtn.setEnabled(false); | |||
| timerCaptureBtn.setEnabled(false); | |||
| /************** picture show panel ************/ | |||
| pictureShowPanel.setLayout(new BorderLayout()); | |||
| pictureShowPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| pictureShowWindow = new PaintPanel(); | |||
| pictureShowPanel.add(pictureShowWindow, BorderLayout.CENTER); | |||
| localCaptureBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| if (!bRealPlay) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getNeedStartRealPlay(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| String strFileName = SavePath.getSavePath().getSaveCapturePath(); | |||
| System.out.println("strFileName = " + strFileName); | |||
| if(!CapturePictureModule.localCapturePicture(m_hPlayHandle, strFileName)) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| BufferedImage bufferedImage = null; | |||
| try { | |||
| bufferedImage = ImageIO.read(new File(strFileName)); | |||
| if(bufferedImage == null) { | |||
| return; | |||
| } | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| pictureShowWindow.setOpaque(false); | |||
| pictureShowWindow.setImage(bufferedImage); | |||
| pictureShowWindow.repaint(); | |||
| } | |||
| }); | |||
| remoteCaptureBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| if(!CapturePictureModule.remoteCapturePicture(chnComboBox.getSelectedIndex())) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| timerCaptureBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| if (!bTimerCapture) { | |||
| if(!CapturePictureModule.timerCapturePicture(chnComboBox.getSelectedIndex())) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| }else{ | |||
| bTimerCapture = true; | |||
| timerCaptureBtn.setText(Res.string().getStopCapture()); | |||
| chnComboBox.setEnabled(false); | |||
| remoteCaptureBtn.setEnabled(false); | |||
| } | |||
| }else { | |||
| if(!CapturePictureModule.stopCapturePicture(chnComboBox.getSelectedIndex())) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| }else{ | |||
| bTimerCapture = false; | |||
| timerCaptureBtn.setText(Res.string().getTimerCapture()); | |||
| chnComboBox.setEnabled(true && !bRealPlay); | |||
| remoteCaptureBtn.setEnabled(true); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| public fCaptureReceiveCB m_CaptureReceiveCB = new fCaptureReceiveCB(); | |||
| public class fCaptureReceiveCB implements NetSDKLib.fSnapRev{ | |||
| BufferedImage bufferedImage = null; | |||
| public void invoke( LLong lLoginID, Pointer pBuf, int RevLen, int EncodeType, int CmdSerial, Pointer dwUser) { | |||
| if(pBuf != null && RevLen > 0) { | |||
| String strFileName = SavePath.getSavePath().getSaveCapturePath(); | |||
| System.out.println("strFileName = " + strFileName); | |||
| byte[] buf = pBuf.getByteArray(0, RevLen); | |||
| ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf); | |||
| try { | |||
| bufferedImage = ImageIO.read(byteArrInput); | |||
| if(bufferedImage == null) { | |||
| return; | |||
| } | |||
| ImageIO.write(bufferedImage, "jpg", new File(strFileName)); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // show picture | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| pictureShowWindow.setOpaque(false); | |||
| pictureShowWindow.setImage(bufferedImage); | |||
| pictureShowWindow.repaint(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| } | |||
| private void setButtonEnable(boolean bln) { | |||
| localCaptureBtn.setEnabled(bln); | |||
| remoteCaptureBtn.setEnabled(bln); | |||
| timerCaptureBtn.setEnabled(bln); | |||
| realPlayWindow.setEnabled(bln); | |||
| chnComboBox.setEnabled(bln); | |||
| streamComboBox.setEnabled(bln); | |||
| realplayBtn.setEnabled(bln); | |||
| } | |||
| private LoginPanel loginPanel; | |||
| private RealPanel realPanel; | |||
| private JPanel realplayPanel; | |||
| private Panel realPlayWindow; | |||
| private Panel channelPanel; | |||
| private JLabel chnlabel; | |||
| private JComboBox chnComboBox; | |||
| private JLabel streamLabel; | |||
| private JComboBox streamComboBox; | |||
| private JButton realplayBtn; | |||
| private PICPanel picPanel; | |||
| private JPanel pictureShowPanel; | |||
| private JPanel capturePanel; | |||
| private PaintPanel pictureShowWindow; | |||
| private JButton localCaptureBtn; | |||
| private JButton remoteCaptureBtn; | |||
| private JButton timerCaptureBtn; | |||
| } | |||
| public class CapturePicture { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| CapturePictureFrame demo = new CapturePictureFrame(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }; | |||
| @@ -0,0 +1,406 @@ | |||
| package com.netsdk.demo.frame; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.GridLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.ItemEvent; | |||
| import java.awt.event.ItemListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JCheckBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JSplitPane; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.UIManager; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.DateChooserJButton; | |||
| import com.netsdk.common.FunctionList; | |||
| import com.netsdk.common.LoginPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.DeviceControlModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.ToolKits; | |||
| /** | |||
| * Device Control Demo | |||
| */ | |||
| class DeviceControlFrame extends JFrame { | |||
| private static final long serialVersionUID = 1L; | |||
| // device disconnect callback instance | |||
| private DisConnect disConnect = new DisConnect(); | |||
| // device control frame (this) | |||
| private static JFrame frame = new JFrame(); | |||
| public DeviceControlFrame() { | |||
| setTitle(Res.string().getDeviceControl()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(550, 350); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| LoginModule.init(disConnect, null); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| loginPanel = new DeviceControlLoginPanel(); | |||
| deviceCtlPanel = new DeviceControlPanel(); | |||
| add(loginPanel, BorderLayout.NORTH); | |||
| add(deviceCtlPanel, BorderLayout.CENTER); | |||
| loginPanel.addLoginBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(loginPanel.checkLoginText()) { | |||
| if(login()) { | |||
| frame = ToolKits.getFrame(e); | |||
| frame.setTitle(Res.string().getDeviceControl() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| loginPanel.addLogoutBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| frame.setTitle(Res.string().getDeviceControl()); | |||
| logout(); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| LoginModule.logout(); | |||
| LoginModule.cleanup(); | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /////////////////function/////////////////// | |||
| // device disconnect callback class | |||
| // set it's instance by call CLIENT_Init, when device disconnect sdk will call it. | |||
| private class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| JOptionPane.showMessageDialog(null, Res.string().getDisConnect(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| frame.setTitle(Res.string().getDeviceControl()); | |||
| logout(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| public boolean login() { | |||
| if(LoginModule.login(loginPanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginPanel.portTextArea.getText()), | |||
| loginPanel.nameTextArea.getText(), | |||
| new String(loginPanel.passwordTextArea.getPassword()))) { | |||
| loginPanel.setButtonEnable(true); | |||
| deviceCtlPanel.setButtonEnabled(true); | |||
| }else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| public void logout() { | |||
| LoginModule.logout(); | |||
| loginPanel.setButtonEnable(false); | |||
| deviceCtlPanel.resetButtonEnabled(); | |||
| } | |||
| private class DeviceControlPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public DeviceControlPanel() { | |||
| BorderEx.set(this, Res.string().getDeviceControl(), 2); | |||
| setLayout(new BorderLayout()); | |||
| setPreferredSize(new Dimension(350, 220)); | |||
| setResizable(false); | |||
| JLabel nullLable = new JLabel(); | |||
| currentTimeCheckBox = new JCheckBox(Res.string().getCurrentTime()); | |||
| getDateChooser = new DateChooserJButton(); | |||
| setDateChooser = new DateChooserJButton(2000, 2037); | |||
| rebootBtn = new JButton(Res.string().getReboot()); | |||
| getTimeBtn = new JButton(Res.string().getGetTime()); | |||
| setTimeBtn = new JButton(Res.string().getSetTime()); | |||
| nullLable.setPreferredSize(currentTimeCheckBox.getPreferredSize()); | |||
| getDateChooser.setPreferredSize(new Dimension(150, 20)); | |||
| setDateChooser.setPreferredSize(new Dimension(150, 20)); | |||
| rebootBtn.setPreferredSize(new Dimension(100, 20)); | |||
| getTimeBtn.setPreferredSize(new Dimension(100, 20)); | |||
| setTimeBtn.setPreferredSize(new Dimension(100, 20)); | |||
| JPanel rebootPanel = new JPanel(); | |||
| BorderEx.set(rebootPanel, Res.string().getDeviceReboot(), 2); | |||
| rebootPanel.add(rebootBtn); | |||
| JPanel timePanel = new JPanel(new GridLayout(2,1)); | |||
| BorderEx.set(timePanel, Res.string().getSyncTime(), 2); | |||
| JPanel getPanel = new JPanel(); | |||
| JPanel setPanel = new JPanel(); | |||
| getPanel.add(nullLable); | |||
| getPanel.add(getDateChooser); | |||
| getPanel.add(getTimeBtn); | |||
| setPanel.add(currentTimeCheckBox); | |||
| setPanel.add(setDateChooser); | |||
| setPanel.add(setTimeBtn); | |||
| timePanel.add(getPanel); | |||
| timePanel.add(setPanel); | |||
| JSplitPane splitPane = new JSplitPane(); | |||
| splitPane.setDividerSize(0); | |||
| splitPane.setBorder(null); | |||
| splitPane.add(rebootPanel, JSplitPane.LEFT); | |||
| splitPane.add(timePanel, JSplitPane.RIGHT); | |||
| add(splitPane); | |||
| getDateChooser.setEnabled(false); | |||
| setButtonEnabled(false); | |||
| rebootBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| OptionDialog optionDialog = new OptionDialog(); | |||
| optionDialog.setVisible(true); | |||
| } | |||
| }); | |||
| getTimeBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| String date = DeviceControlModule.getTime(); | |||
| if (date == null) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| }else { | |||
| getDateChooser.setText(date); | |||
| } | |||
| } | |||
| }); | |||
| setTimeBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| String date = null; | |||
| if (!currentTimeCheckBox.isSelected()) { | |||
| date = setDateChooser.getText(); | |||
| } | |||
| if (!DeviceControlModule.setTime(date)) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getOperateSuccess(), Res.string().getPromptMessage(), JOptionPane.PLAIN_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| currentTimeCheckBox.addItemListener(new ItemListener() { | |||
| @Override | |||
| public void itemStateChanged(ItemEvent e) { | |||
| JCheckBox jcb = (JCheckBox)e.getItem(); | |||
| if (jcb.isSelected()) { | |||
| setDateChooser.setEnabled(false); | |||
| }else { | |||
| setDateChooser.setEnabled(true); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| public void setButtonEnabled(boolean b) { | |||
| currentTimeCheckBox.setEnabled(b); | |||
| setDateChooser.setEnabled(b); | |||
| rebootBtn.setEnabled(b); | |||
| getTimeBtn.setEnabled(b); | |||
| setTimeBtn.setEnabled(b); | |||
| } | |||
| public void resetButtonEnabled() { | |||
| currentTimeCheckBox.setSelected(false); | |||
| setButtonEnabled(false); | |||
| } | |||
| private class OptionDialog extends JDialog { | |||
| private static final long serialVersionUID = 1L; | |||
| public OptionDialog() { | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
| pack(); | |||
| setSize(250, 100); | |||
| setLocationRelativeTo(null); | |||
| setModal(true); | |||
| setTitle(Res.string().getDeviceReboot()); | |||
| JLabel messageLable = new JLabel(Res.string().getRebootTips()); | |||
| confirmBtn = new JButton(Res.string().getConfirm()); | |||
| cancelBtn = new JButton(Res.string().getCancel()); | |||
| JPanel messagePanel = new JPanel(); | |||
| messagePanel.add(messageLable); | |||
| JPanel btnPanel = new JPanel(); | |||
| btnPanel.add(cancelBtn); | |||
| btnPanel.add(confirmBtn); | |||
| add(messagePanel, BorderLayout.NORTH); | |||
| add(btnPanel, BorderLayout.CENTER); | |||
| addListener(); | |||
| } | |||
| private void addListener() { | |||
| confirmBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| cancelBtn.setEnabled(false); | |||
| if (!DeviceControlModule.reboot()) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getOperateSuccess(), Res.string().getPromptMessage(), JOptionPane.PLAIN_MESSAGE); | |||
| } | |||
| dispose(); | |||
| } | |||
| }); | |||
| cancelBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| private JButton confirmBtn; | |||
| private JButton cancelBtn; | |||
| } | |||
| private JButton rebootBtn; | |||
| private DateChooserJButton getDateChooser; | |||
| private JButton getTimeBtn; | |||
| private JCheckBox currentTimeCheckBox; | |||
| private DateChooserJButton setDateChooser; | |||
| private JButton setTimeBtn; | |||
| } | |||
| private class DeviceControlLoginPanel extends LoginPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public DeviceControlLoginPanel() { | |||
| setLayout(new GridLayout(3, 1)); | |||
| removeAll(); | |||
| JPanel ipPanel = new JPanel(); | |||
| JPanel userPanel = new JPanel(); | |||
| JPanel btnPanel = new JPanel(); | |||
| resetSize(); | |||
| ipPanel.add(ipLabel); | |||
| ipPanel.add(ipTextArea); | |||
| ipPanel.add(portLabel); | |||
| ipPanel.add(portTextArea); | |||
| userPanel.add(nameLabel); | |||
| userPanel.add(nameTextArea); | |||
| userPanel.add(passwordLabel); | |||
| userPanel.add(passwordTextArea); | |||
| btnPanel.add(loginBtn); | |||
| btnPanel.add(new JLabel(" ")); | |||
| btnPanel.add(logoutBtn); | |||
| add(ipPanel); | |||
| add(userPanel); | |||
| add(btnPanel); | |||
| } | |||
| private void resetSize() { | |||
| ipLabel.setPreferredSize(new Dimension(70, 25)); | |||
| portLabel.setPreferredSize(new Dimension(70, 25)); | |||
| nameLabel.setText(Res.string().getUserName()); | |||
| nameLabel.setPreferredSize(new Dimension(70, 25)); | |||
| passwordLabel.setPreferredSize(new Dimension(70, 25)); | |||
| loginBtn.setPreferredSize(new Dimension(100, 20)); | |||
| logoutBtn.setPreferredSize(new Dimension(100, 20)); | |||
| ipTextArea.setPreferredSize(new Dimension(100, 20)); | |||
| portTextArea.setPreferredSize(new Dimension(100, 20)); | |||
| nameTextArea.setPreferredSize(new Dimension(100, 20)); | |||
| passwordTextArea.setPreferredSize(new Dimension(100, 20)); | |||
| } | |||
| } | |||
| private DeviceControlLoginPanel loginPanel; | |||
| private DeviceControlPanel deviceCtlPanel; | |||
| } | |||
| public class DeviceControl { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| DeviceControlFrame demo = new DeviceControlFrame(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }; | |||
| @@ -0,0 +1,889 @@ | |||
| package com.netsdk.demo.frame; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.GridLayout; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.util.Vector; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JProgressBar; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JTable; | |||
| import javax.swing.ListSelectionModel; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.UIManager; | |||
| import javax.swing.border.EmptyBorder; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import com.netsdk.common.*; | |||
| import com.netsdk.demo.module.DownLoadRecordModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.*; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.sun.jna.CallbackThreadInitializer; | |||
| import com.sun.jna.Native; | |||
| import com.sun.jna.Pointer; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| /* | |||
| * 下载录像Demo | |||
| */ | |||
| class DownLoadRecordFrame extends JFrame{ | |||
| private static final long serialVersionUID = 1L; | |||
| private Vector<String> chnlist = new Vector<String>(); | |||
| private DefaultTableModel model; | |||
| private LLong m_hDownLoadByTimeHandle = new LLong(0); // 按时间下载句柄 | |||
| private LLong m_hDownLoadByFileHandle = new LLong(0); // 按文件下载句柄 | |||
| private boolean b_downloadByTime = false; | |||
| private boolean b_downloadByFile = false; | |||
| private IntByReference nFindCount = new IntByReference(0); | |||
| // 设备断线通知回调 | |||
| private DisConnect disConnect = new DisConnect(); | |||
| // 网络连接恢复 | |||
| private static HaveReConnect haveReConnect = new HaveReConnect(); | |||
| // 开始时间 | |||
| private NetSDKLib.NET_TIME stTimeStart = new NetSDKLib.NET_TIME(); | |||
| // 结束时间 | |||
| private NetSDKLib.NET_TIME stTimeEnd = new NetSDKLib.NET_TIME(); | |||
| // 录像文件信息 | |||
| private NetSDKLib.NET_RECORDFILE_INFO[] stFileInfo = (NetSDKLib.NET_RECORDFILE_INFO[])new NetSDKLib.NET_RECORDFILE_INFO().toArray(2000); | |||
| Object[][] data = null; | |||
| // 获取界面窗口 | |||
| private static JFrame frame = new JFrame(); | |||
| public DownLoadRecordFrame() { | |||
| setTitle(Res.string().getDownloadRecord()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(800, 560); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| loginPanel = new LoginPanel(); | |||
| downloadRecordPanel = new DownLoadRecordPanel(); | |||
| add(loginPanel, BorderLayout.NORTH); | |||
| add(downloadRecordPanel, BorderLayout.CENTER); | |||
| loginPanel.addLoginBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(loginPanel.checkLoginText()) { | |||
| if(login()) { | |||
| frame = ToolKits.getFrame(e); | |||
| frame.setTitle(Res.string().getDownloadRecord() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| loginPanel.addLogoutBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| frame.setTitle(Res.string().getDownloadRecord()); | |||
| logout(); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| DownLoadRecordModule.stopDownLoadRecordFile(m_hDownLoadByFileHandle); | |||
| DownLoadRecordModule.stopDownLoadRecordFile(m_hDownLoadByTimeHandle); | |||
| LoginModule.logout(); | |||
| LoginModule.cleanup(); // 关闭工程,释放资源 | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /////////////////面板////////////////// | |||
| // 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数 | |||
| private class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| // 断线提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getDownloadRecord() + " : " + Res.string().getDisConnectReconnecting()); | |||
| setButtonEnable(true); | |||
| b_downloadByFile = false; | |||
| downloadByFileBtn.setText(Res.string().getDownload()); | |||
| b_downloadByTime = false; | |||
| downloadByTimeBtn.setText(Res.string().getDownload()); | |||
| DownLoadRecordModule.stopDownLoadRecordFile(m_hDownLoadByFileHandle); | |||
| DownLoadRecordModule.stopDownLoadRecordFile(m_hDownLoadByTimeHandle); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 网络连接恢复,设备重连成功回调 | |||
| // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 | |||
| private static class HaveReConnect implements NetSDKLib.fHaveReConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| // 重连提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getDownloadRecord() + " : " + Res.string().getOnline()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 登录 | |||
| public boolean login() { | |||
| Native.setCallbackThreadInitializer(m_DownLoadPosByFile, | |||
| new CallbackThreadInitializer(false, false, "downloadbyfile callback thread")); | |||
| Native.setCallbackThreadInitializer(m_DownLoadPosByTime, | |||
| new CallbackThreadInitializer(false, false, "downloadbytime callback thread")); | |||
| if(LoginModule.login(loginPanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginPanel.portTextArea.getText()), | |||
| loginPanel.nameTextArea.getText(), | |||
| new String(loginPanel.passwordTextArea.getPassword()))) { | |||
| loginPanel.setButtonEnable(true); | |||
| setButtonEnable(true); | |||
| for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) { | |||
| chnlist.add(Res.string().getChannel() + " " + String.valueOf(i)); | |||
| } | |||
| // 默认设置主辅码流 | |||
| DownLoadRecordModule.setStreamType(streamComboBoxByFile.getSelectedIndex()); | |||
| // 登陆成功,将通道添加到控件 | |||
| chnComboBoxByFile.setModel(new DefaultComboBoxModel(chnlist)); | |||
| chnComboBoxByTime.setModel(new DefaultComboBoxModel(chnlist)); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| //登出 | |||
| public void logout() { | |||
| LoginModule.logout(); | |||
| loginPanel.setButtonEnable(false); | |||
| setButtonEnable(false); | |||
| // 列表清空 | |||
| data = new Object[14][5]; | |||
| table.setModel(new DefaultTableModel(data, Res.string().getDownloadTableName())); | |||
| table.getColumnModel().getColumn(0).setPreferredWidth(23); | |||
| table.getColumnModel().getColumn(1).setPreferredWidth(28); | |||
| table.getColumnModel().getColumn(2).setPreferredWidth(50); | |||
| for(int i = 0; i < LoginModule.m_stDeviceInfo.byChanNum; i++) { | |||
| chnlist.clear(); | |||
| } | |||
| chnComboBoxByFile.setModel(new DefaultComboBoxModel()); | |||
| chnComboBoxByTime.setModel(new DefaultComboBoxModel()); | |||
| b_downloadByFile = false; | |||
| downloadByFileBtn.setText(Res.string().getDownload()); | |||
| b_downloadByTime = false; | |||
| downloadByTimeBtn.setText(Res.string().getDownload()); | |||
| } | |||
| /* | |||
| * 下载录像面板 | |||
| */ | |||
| private class DownLoadRecordPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public DownLoadRecordPanel() { | |||
| BorderEx.set(this, Res.string().getDownloadRecord(), 2); | |||
| setLayout(new GridLayout(1, 2)); | |||
| downloadByTimePanel = new DownLoadByTimePanel(); // 按时间下载 | |||
| downloadByFilePanel = new DownLoadByFilePanel(); // 按文件下载 | |||
| add(downloadByTimePanel); | |||
| add(downloadByFilePanel); | |||
| } | |||
| } | |||
| /* | |||
| * 按文件下载面板 | |||
| */ | |||
| private class DownLoadByFilePanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public DownLoadByFilePanel() { | |||
| BorderEx.set(this, Res.string().getDownloadByFile(), 2); | |||
| setLayout(new BorderLayout()); | |||
| downloadByFileSetPanel = new JPanel(); // 设置 | |||
| queryPanel = new JPanel(); // 查询 | |||
| downByFilePanel = new JPanel(); // 下载 | |||
| add(downloadByFileSetPanel, BorderLayout.NORTH); | |||
| add(queryPanel, BorderLayout.CENTER); | |||
| add(downByFilePanel, BorderLayout.SOUTH); | |||
| /******** 设置面板***********/ | |||
| JPanel startTimeByFile = new JPanel(); | |||
| JPanel endTimeByFile = new JPanel(); | |||
| JPanel chnByFile = new JPanel(); | |||
| JPanel streamByFile = new JPanel(); | |||
| downloadByFileSetPanel.setLayout(new GridLayout(2, 2)); | |||
| downloadByFileSetPanel.add(startTimeByFile); | |||
| downloadByFileSetPanel.add(endTimeByFile); | |||
| downloadByFileSetPanel.add(chnByFile); | |||
| downloadByFileSetPanel.add(streamByFile); | |||
| // 开始时间设置 | |||
| startTimeByFile.setBorder(new EmptyBorder(5, 5, 5, 20)); | |||
| startTimeByFile.setLayout(new GridLayout(2, 1)); | |||
| JLabel startLabel = new JLabel(Res.string().getStartTime()); | |||
| dateChooserStartByFile = new DateChooserJButton(); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.height = 20; | |||
| dateChooserStartByFile.setPreferredSize(dimension); | |||
| startTimeByFile.add(startLabel); | |||
| startTimeByFile.add(dateChooserStartByFile); | |||
| // 结束时间设置 | |||
| endTimeByFile.setBorder(new EmptyBorder(5, 20, 5, 5)); | |||
| endTimeByFile.setLayout(new GridLayout(2, 1)); | |||
| JLabel endLabel = new JLabel(Res.string().getEndTime()); | |||
| dateChooserEndByFile = new DateChooserJButton(); | |||
| dateChooserEndByFile.setPreferredSize(dimension); | |||
| endTimeByFile.add(endLabel); | |||
| endTimeByFile.add(dateChooserEndByFile); | |||
| // 通道设置 | |||
| chnByFile.setBorder(new EmptyBorder(5, 10, 0, 5)); | |||
| chnByFile.setLayout(new FlowLayout()); | |||
| chnlabel = new JLabel(Res.string().getChannel()); | |||
| chnComboBoxByFile = new JComboBox(); | |||
| chnComboBoxByFile.setPreferredSize(new Dimension(115, 20)); | |||
| chnByFile.add(chnlabel); | |||
| chnByFile.add(chnComboBoxByFile); | |||
| // 码流设置 | |||
| streamByFile.setBorder(new EmptyBorder(5, 10, 0, 5)); | |||
| streamByFile.setLayout(new FlowLayout()); | |||
| streamLabel = new JLabel(Res.string().getStreamType()); | |||
| String[] stream = {Res.string().getMasterAndSub(), Res.string().getMasterStream(), Res.string().getSubStream()}; | |||
| streamComboBoxByFile = new JComboBox(stream); | |||
| streamComboBoxByFile.setModel(new DefaultComboBoxModel(stream)); | |||
| streamComboBoxByFile.setPreferredSize(new Dimension(115, 20)); | |||
| streamByFile.add(streamLabel); | |||
| streamByFile.add(streamComboBoxByFile); | |||
| /******** 查询面板***********/ | |||
| queryPanel.setLayout(new BorderLayout()); | |||
| queryPanel.setBorder(new EmptyBorder(0, 5, 5, 5)); | |||
| data = new Object[14][5]; | |||
| defaultmodel = new DefaultTableModel(data, Res.string().getDownloadTableName()); | |||
| table = new JTable(defaultmodel){ | |||
| private static final long serialVersionUID = 1L; | |||
| @Override | |||
| public boolean isCellEditable(int row, int column) { | |||
| return false; | |||
| } | |||
| }; | |||
| table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行 | |||
| table.getColumnModel().getColumn(0).setPreferredWidth(20); | |||
| table.getColumnModel().getColumn(1).setPreferredWidth(20); | |||
| table.getColumnModel().getColumn(2).setPreferredWidth(50); | |||
| DefaultTableCellRenderer dCellRenderer = new DefaultTableCellRenderer(); | |||
| dCellRenderer.setHorizontalAlignment(JLabel.CENTER); | |||
| table.setDefaultRenderer(Object.class, dCellRenderer); | |||
| queryPanel.add(new JScrollPane(table), BorderLayout.CENTER); | |||
| /******** 下载面板***********/ | |||
| downByFilePanel.setLayout(new BorderLayout()); | |||
| downByFilePanel.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| JPanel btnPanel1 = new JPanel(); | |||
| downloadByFileProgressBar = new JProgressBar(0, 100); | |||
| downloadByFileProgressBar.setPreferredSize(new Dimension(100, 20)); | |||
| downloadByFileProgressBar.setStringPainted(true); | |||
| downByFilePanel.add(btnPanel1, BorderLayout.CENTER); | |||
| downByFilePanel.add(downloadByFileProgressBar, BorderLayout.SOUTH); | |||
| // 查询、下载按钮 | |||
| queryRecordBtn = new JButton(Res.string().getQuery()); | |||
| downloadByFileBtn = new JButton(Res.string().getDownload()); | |||
| queryRecordBtn.setPreferredSize(new Dimension(175, 20)); | |||
| downloadByFileBtn.setPreferredSize(new Dimension(175, 20)); | |||
| btnPanel1.setLayout(new FlowLayout()); | |||
| btnPanel1.add(queryRecordBtn); | |||
| btnPanel1.add(downloadByFileBtn); | |||
| queryRecordBtn.setEnabled(false); | |||
| downloadByFileBtn.setEnabled(false); | |||
| downloadByFileProgressBar.setEnabled(false); | |||
| chnComboBoxByFile.setEnabled(false); | |||
| streamComboBoxByFile.setEnabled(false); | |||
| dateChooserStartByFile.setEnabled(false); | |||
| dateChooserEndByFile.setEnabled(false); | |||
| streamComboBoxByFile.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| DownLoadRecordModule.setStreamType(streamComboBoxByFile.getSelectedIndex()); | |||
| } | |||
| }); | |||
| queryRecordBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| int i = 1; // 列表序号 | |||
| int time = 0; | |||
| System.out.println(dateChooserStartByFile.getText() + "\n" + dateChooserEndByFile.getText()); | |||
| // 开始时间 | |||
| String[] dateStartByFile = dateChooserStartByFile.getText().split(" "); | |||
| String[] dateStart1 = dateStartByFile[0].split("-"); | |||
| String[] dateStart2 = dateStartByFile[1].split(":"); | |||
| stTimeStart.dwYear = Integer.parseInt(dateStart1[0]); | |||
| stTimeStart.dwMonth = Integer.parseInt(dateStart1[1]); | |||
| stTimeStart.dwDay = Integer.parseInt(dateStart1[2]); | |||
| stTimeStart.dwHour = Integer.parseInt(dateStart2[0]); | |||
| stTimeStart.dwMinute = Integer.parseInt(dateStart2[1]); | |||
| stTimeStart.dwSecond = Integer.parseInt(dateStart2[2]); | |||
| // 结束时间 | |||
| String[] dateEndByFile = dateChooserEndByFile.getText().split(" "); | |||
| String[] dateEnd1 = dateEndByFile[0].split("-"); | |||
| String[] dateEnd2 = dateEndByFile[1].split(":"); | |||
| stTimeEnd.dwYear = Integer.parseInt(dateEnd1[0]); | |||
| stTimeEnd.dwMonth = Integer.parseInt(dateEnd1[1]); | |||
| stTimeEnd.dwDay = Integer.parseInt(dateEnd1[2]); | |||
| stTimeEnd.dwHour = Integer.parseInt(dateEnd2[0]); | |||
| stTimeEnd.dwMinute = Integer.parseInt(dateEnd2[1]); | |||
| stTimeEnd.dwSecond = Integer.parseInt(dateEnd2[2]); | |||
| if(stTimeStart.dwYear != stTimeEnd.dwYear | |||
| || stTimeStart.dwMonth != stTimeEnd.dwMonth | |||
| || (stTimeEnd.dwDay - stTimeStart.dwDay > 1)) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectTimeAgain(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(stTimeEnd.dwDay - stTimeStart.dwDay == 1) { | |||
| time = (24 + stTimeEnd.dwHour)*60*60 + stTimeEnd.dwMinute*60 + stTimeEnd.dwSecond - | |||
| stTimeStart.dwHour*60*60 - stTimeStart.dwMinute*60 - stTimeStart.dwSecond; | |||
| } else { | |||
| time = stTimeEnd.dwHour*60*60 + stTimeEnd.dwMinute*60 + stTimeEnd.dwSecond - | |||
| stTimeStart.dwHour*60*60 - stTimeStart.dwMinute*60 - stTimeStart.dwSecond; | |||
| } | |||
| if(time > 6 * 60 * 60 | |||
| || time <= 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectTimeAgain(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(!DownLoadRecordModule.queryRecordFile(chnComboBoxByFile.getSelectedIndex(), | |||
| stTimeStart, | |||
| stTimeEnd, | |||
| stFileInfo, | |||
| nFindCount)) { | |||
| // 列表清空 | |||
| data = new Object[14][5]; | |||
| table.setModel(new DefaultTableModel(data, Res.string().getDownloadTableName())); | |||
| table.getColumnModel().getColumn(0).setPreferredWidth(23); | |||
| table.getColumnModel().getColumn(1).setPreferredWidth(28); | |||
| table.getColumnModel().getColumn(2).setPreferredWidth(50); | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } else { | |||
| System.out.println(nFindCount.getValue()); | |||
| int count = 0; | |||
| if(nFindCount.getValue() > 14) { | |||
| count = nFindCount.getValue(); | |||
| } else { | |||
| count = 14; | |||
| } | |||
| data = new Object[count][5]; | |||
| table.setModel(new DefaultTableModel(data, Res.string().getDownloadTableName())); | |||
| table.getColumnModel().getColumn(0).setPreferredWidth(23); | |||
| table.getColumnModel().getColumn(1).setPreferredWidth(28); | |||
| table.getColumnModel().getColumn(2).setPreferredWidth(50); | |||
| if(nFindCount.getValue() == 0) { | |||
| return; | |||
| } | |||
| model = (DefaultTableModel)table.getModel(); | |||
| for(int j = 0; j < nFindCount.getValue(); j++) { | |||
| model.setValueAt(String.valueOf(i), j, 0); | |||
| model.setValueAt(String.valueOf(stFileInfo[j].ch + 1), j, 1); // 设备返回的通道加1 | |||
| model.setValueAt(Res.string().getRecordTypeStr(stFileInfo[j].nRecordFileType), j, 2); | |||
| model.setValueAt(stFileInfo[j].starttime.toStringTime(), j, 3); | |||
| model.setValueAt(stFileInfo[j].endtime.toStringTime(), j, 4); | |||
| i++; | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| downloadByFileBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| int row = -1; | |||
| row = table.getSelectedRow(); //获得所选的单行 | |||
| if(model == null) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getQueryRecord(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(row < 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectRowWithData(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| for(int m = 1; m < 5; m++) { | |||
| if(model.getValueAt(row, m) == null || String.valueOf(model.getValueAt(row, m)).trim().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectRowWithData(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| } | |||
| // 开始时间 | |||
| String[] dateStart = String.valueOf(model.getValueAt(row, 3)).split(" "); | |||
| String[] dateStartByFile1 = dateStart[0].split("/"); | |||
| String[] dateStartByFile2 = dateStart[1].split(":"); | |||
| stTimeStart.dwYear = Integer.parseInt(dateStartByFile1[0]); | |||
| stTimeStart.dwMonth = Integer.parseInt(dateStartByFile1[1]); | |||
| stTimeStart.dwDay = Integer.parseInt(dateStartByFile1[2]); | |||
| stTimeStart.dwHour = Integer.parseInt(dateStartByFile2[0]); | |||
| stTimeStart.dwMinute = Integer.parseInt(dateStartByFile2[1]); | |||
| stTimeStart.dwSecond = Integer.parseInt(dateStartByFile2[2]); | |||
| // 结束时间 | |||
| String[] dateEnd = String.valueOf(model.getValueAt(row, 4)).split(" "); | |||
| String[] dateEndByFile1 = dateEnd[0].split("/"); | |||
| String[] dateEndByFile2 = dateEnd[1].split(":"); | |||
| stTimeEnd.dwYear = Integer.parseInt(dateEndByFile1[0]); | |||
| stTimeEnd.dwMonth = Integer.parseInt(dateEndByFile1[1]); | |||
| stTimeEnd.dwDay = Integer.parseInt(dateEndByFile1[2]); | |||
| stTimeEnd.dwHour = Integer.parseInt(dateEndByFile2[0]); | |||
| stTimeEnd.dwMinute = Integer.parseInt(dateEndByFile2[1]); | |||
| stTimeEnd.dwSecond = Integer.parseInt(dateEndByFile2[2]); | |||
| if(!b_downloadByFile) { | |||
| System.out.println("ByFile" + String.valueOf(model.getValueAt(row, 3)) + "\n" + String.valueOf(model.getValueAt(row, 4))); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| downloadByFileProgressBar.setValue(0); | |||
| } | |||
| }); | |||
| m_hDownLoadByFileHandle = DownLoadRecordModule.downloadRecordFile(Integer.parseInt(String.valueOf(model.getValueAt(row, 1))) - 1, | |||
| Res.string().getRecordTypeInt(String.valueOf(model.getValueAt(row, 2))), | |||
| stTimeStart, | |||
| stTimeEnd, | |||
| SavePath.getSavePath().getSaveRecordFilePath(), | |||
| m_DownLoadPosByFile); | |||
| if(m_hDownLoadByFileHandle.longValue() != 0) { | |||
| b_downloadByFile = true; | |||
| downloadByFileBtn.setText(Res.string().getStopDownload()); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } else { | |||
| DownLoadRecordModule.stopDownLoadRecordFile(m_hDownLoadByFileHandle); | |||
| b_downloadByFile = false; | |||
| downloadByFileBtn.setText(Res.string().getDownload()); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| downloadByFileProgressBar.setValue(0); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /* | |||
| * 按时间下载面板 | |||
| */ | |||
| private class DownLoadByTimePanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public DownLoadByTimePanel() { | |||
| BorderEx.set(this, Res.string().getDownloadByTime(), 2); | |||
| setLayout(new BorderLayout()); | |||
| downloadByTimeSetPanel = new JPanel(); // 设置 | |||
| downByTimePanel = new JPanel(); // 下载 | |||
| add(downloadByTimeSetPanel, BorderLayout.NORTH); | |||
| add(downByTimePanel, BorderLayout.CENTER); | |||
| /******** 设置面板***********/ | |||
| JPanel startTimeByTime = new JPanel(); | |||
| JPanel endTimeByTime = new JPanel(); | |||
| JPanel chnByTime = new JPanel(); | |||
| JPanel streamByTime = new JPanel(); | |||
| downloadByTimeSetPanel.setLayout(new GridLayout(2, 2)); | |||
| downloadByTimeSetPanel.add(startTimeByTime); | |||
| downloadByTimeSetPanel.add(endTimeByTime); | |||
| downloadByTimeSetPanel.add(chnByTime); | |||
| downloadByTimeSetPanel.add(streamByTime); | |||
| // 开始时间设置 | |||
| startTimeByTime.setBorder(new EmptyBorder(5, 5, 5, 20)); | |||
| startTimeByTime.setLayout(new GridLayout(2, 1)); | |||
| JLabel startLabel = new JLabel(Res.string().getStartTime()); | |||
| dateChooserStartByTime = new DateChooserJButton(); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.height = 20; | |||
| dateChooserStartByTime.setPreferredSize(dimension); | |||
| startTimeByTime.add(startLabel); | |||
| startTimeByTime.add(dateChooserStartByTime); | |||
| // 结束时间设置 | |||
| endTimeByTime.setBorder(new EmptyBorder(5, 20, 5, 5)); | |||
| endTimeByTime.setLayout(new GridLayout(2, 1)); | |||
| JLabel endLabel = new JLabel(Res.string().getEndTime()); | |||
| dateChooserEndByTime = new DateChooserJButton(); | |||
| dateChooserEndByTime.setPreferredSize(dimension); | |||
| endTimeByTime.add(endLabel); | |||
| endTimeByTime.add(dateChooserEndByTime); | |||
| // 通道设置 | |||
| chnByTime.setBorder(new EmptyBorder(5, 10, 0, 5)); | |||
| chnByTime.setLayout(new FlowLayout()); | |||
| chnlabel = new JLabel(Res.string().getChannel()); | |||
| chnComboBoxByTime = new JComboBox(); | |||
| chnComboBoxByTime.setPreferredSize(new Dimension(115, 20)); | |||
| chnByTime.add(chnlabel); | |||
| chnByTime.add(chnComboBoxByTime); | |||
| // 码流设置 | |||
| streamByTime.setBorder(new EmptyBorder(5, 10, 0, 5)); | |||
| streamByTime.setLayout(new FlowLayout()); | |||
| streamLabel = new JLabel(Res.string().getStreamType()); | |||
| String[] stream = {Res.string().getMasterAndSub(), Res.string().getMasterStream(), Res.string().getSubStream()}; | |||
| streamComboBoxByTime = new JComboBox(); | |||
| streamComboBoxByTime.setModel(new DefaultComboBoxModel(stream)); | |||
| streamComboBoxByTime.setPreferredSize(new Dimension(115, 20)); | |||
| streamByTime.add(streamLabel); | |||
| streamByTime.add(streamComboBoxByTime); | |||
| /******** 下载面板***********/ | |||
| downByTimePanel.setLayout(new FlowLayout()); | |||
| downByTimePanel.setBorder(new EmptyBorder(0, 5, 0, 5)); | |||
| JPanel btnPanel2 = new JPanel(); | |||
| downloadByTimeProgressBar = new JProgressBar(0, 100); | |||
| downloadByTimeProgressBar.setPreferredSize(new Dimension(355, 20)); | |||
| downloadByTimeProgressBar.setStringPainted(true); | |||
| downByTimePanel.add(btnPanel2); | |||
| downByTimePanel.add(downloadByTimeProgressBar); | |||
| // 下载按钮 | |||
| downloadByTimeBtn = new JButton(Res.string().getDownload()); | |||
| JLabel nullLabel = new JLabel(); | |||
| nullLabel.setPreferredSize(new Dimension(180, 20)); | |||
| downloadByTimeBtn.setPreferredSize(new Dimension(170, 20)); | |||
| btnPanel2.setLayout(new FlowLayout()); | |||
| btnPanel2.add(downloadByTimeBtn); | |||
| btnPanel2.add(nullLabel); | |||
| downloadByTimeBtn.setEnabled(false); | |||
| downloadByTimeProgressBar.setEnabled(false); | |||
| chnComboBoxByTime.setEnabled(false); | |||
| streamComboBoxByTime.setEnabled(false); | |||
| dateChooserStartByTime.setEnabled(false); | |||
| dateChooserEndByTime.setEnabled(false); | |||
| streamComboBoxByTime.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| DownLoadRecordModule.setStreamType(streamComboBoxByTime.getSelectedIndex()); | |||
| } | |||
| }); | |||
| downloadByTimeBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| int time = 0; | |||
| // 开始时间 | |||
| String[] dateStartByTime = dateChooserStartByTime.getText().split(" "); | |||
| String[] dateStart1 = dateStartByTime[0].split("-"); | |||
| String[] dateStart2 = dateStartByTime[1].split(":"); | |||
| stTimeStart.dwYear = Integer.parseInt(dateStart1[0]); | |||
| stTimeStart.dwMonth = Integer.parseInt(dateStart1[1]); | |||
| stTimeStart.dwDay = Integer.parseInt(dateStart1[2]); | |||
| stTimeStart.dwHour = Integer.parseInt(dateStart2[0]); | |||
| stTimeStart.dwMinute = Integer.parseInt(dateStart2[1]); | |||
| stTimeStart.dwSecond = Integer.parseInt(dateStart2[2]); | |||
| // 结束时间 | |||
| String[] dateEndByTime = dateChooserEndByTime.getText().split(" "); | |||
| String[] dateEnd1 = dateEndByTime[0].split("-"); | |||
| String[] dateEnd2 = dateEndByTime[1].split(":"); | |||
| stTimeEnd.dwYear = Integer.parseInt(dateEnd1[0]); | |||
| stTimeEnd.dwMonth = Integer.parseInt(dateEnd1[1]); | |||
| stTimeEnd.dwDay = Integer.parseInt(dateEnd1[2]); | |||
| stTimeEnd.dwHour = Integer.parseInt(dateEnd2[0]); | |||
| stTimeEnd.dwMinute = Integer.parseInt(dateEnd2[1]); | |||
| stTimeEnd.dwSecond = Integer.parseInt(dateEnd2[2]); | |||
| if(stTimeStart.dwYear != stTimeEnd.dwYear | |||
| || stTimeStart.dwMonth != stTimeEnd.dwMonth | |||
| || (stTimeEnd.dwDay - stTimeStart.dwDay) > 1) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectTimeAgain(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(stTimeEnd.dwDay - stTimeStart.dwDay == 1) { | |||
| time = (24 + stTimeEnd.dwHour)*60*60 + stTimeEnd.dwMinute*60 + stTimeEnd.dwSecond - | |||
| stTimeStart.dwHour*60*60 - stTimeStart.dwMinute*60 - stTimeStart.dwSecond; | |||
| } else { | |||
| time = stTimeEnd.dwHour*60*60 + stTimeEnd.dwMinute*60 + stTimeEnd.dwSecond - | |||
| stTimeStart.dwHour*60*60 - stTimeStart.dwMinute*60 - stTimeStart.dwSecond; | |||
| } | |||
| System.out.println("time :" + time); | |||
| if(time > 6 * 60 * 60 | |||
| || time <= 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectTimeAgain(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(!b_downloadByTime) { | |||
| System.out.println("ByTime" + dateChooserStartByTime.getText() + "\n" + dateChooserEndByTime.getText()); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| downloadByTimeProgressBar.setValue(0); | |||
| } | |||
| }); | |||
| m_hDownLoadByTimeHandle = DownLoadRecordModule.downloadRecordFile(chnComboBoxByTime.getSelectedIndex(), | |||
| 0, | |||
| stTimeStart, | |||
| stTimeEnd, | |||
| SavePath.getSavePath().getSaveRecordFilePath(), | |||
| m_DownLoadPosByTime); | |||
| if(m_hDownLoadByTimeHandle.longValue() != 0) { | |||
| b_downloadByTime = true; | |||
| downloadByTimeBtn.setText(Res.string().getStopDownload()); | |||
| chnComboBoxByTime.setEnabled(false); | |||
| streamComboBoxByTime.setEnabled(false); | |||
| dateChooserStartByTime.setEnabled(false); | |||
| dateChooserEndByTime.setEnabled(false); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } else { | |||
| DownLoadRecordModule.stopDownLoadRecordFile(m_hDownLoadByTimeHandle); | |||
| b_downloadByTime = false; | |||
| downloadByTimeBtn.setText(Res.string().getDownload()); | |||
| chnComboBoxByTime.setEnabled(true); | |||
| streamComboBoxByTime.setEnabled(true); | |||
| dateChooserStartByTime.setEnabled(true); | |||
| dateChooserEndByTime.setEnabled(true); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| downloadByTimeProgressBar.setValue(0); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /* | |||
| * 按文件下载回调 | |||
| */ | |||
| private DownLoadPosCallBackByFile m_DownLoadPosByFile = new DownLoadPosCallBackByFile(); // 录像下载进度 | |||
| class DownLoadPosCallBackByFile implements NetSDKLib.fTimeDownLoadPosCallBack{ | |||
| public void invoke(LLong lLoginID, final int dwTotalSize, final int dwDownLoadSize, int index, NetSDKLib.NET_RECORDFILE_INFO.ByValue recordfileinfo, Pointer dwUser) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| // System.out.println("ByFile " + dwDownLoadSize + " / " + dwTotalSize); | |||
| downloadByFileProgressBar.setValue(dwDownLoadSize*100 / dwTotalSize); | |||
| if(dwDownLoadSize == -1) { | |||
| downloadByFileProgressBar.setValue(100); | |||
| DownLoadRecordModule.stopDownLoadRecordFile(m_hDownLoadByFileHandle); | |||
| b_downloadByFile = false; | |||
| downloadByFileBtn.setText(Res.string().getDownload()); | |||
| JOptionPane.showMessageDialog(null, Res.string().getDownloadCompleted(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /* | |||
| * 按时间下载回调 | |||
| */ | |||
| private DownLoadPosCallBackByTime m_DownLoadPosByTime = new DownLoadPosCallBackByTime(); // 录像下载进度 | |||
| class DownLoadPosCallBackByTime implements NetSDKLib.fTimeDownLoadPosCallBack{ | |||
| public void invoke(LLong lLoginID, final int dwTotalSize, final int dwDownLoadSize, int index, NetSDKLib.NET_RECORDFILE_INFO.ByValue recordfileinfo, Pointer dwUser) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| // System.out.println("ByTime " + dwDownLoadSize + " / " + dwTotalSize); | |||
| downloadByTimeProgressBar.setValue(dwDownLoadSize*100 / dwTotalSize); | |||
| if(dwDownLoadSize == -1) { | |||
| downloadByTimeProgressBar.setValue(100); | |||
| DownLoadRecordModule.stopDownLoadRecordFile(m_hDownLoadByTimeHandle); | |||
| b_downloadByTime = false; | |||
| downloadByTimeBtn.setText(Res.string().getDownload()); | |||
| chnComboBoxByTime.setEnabled(true); | |||
| streamComboBoxByTime.setEnabled(true); | |||
| dateChooserStartByTime.setEnabled(true); | |||
| dateChooserEndByTime.setEnabled(true); | |||
| JOptionPane.showMessageDialog(null, Res.string().getDownloadCompleted(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| private void setButtonEnable(boolean bln) { | |||
| queryRecordBtn.setEnabled(bln); | |||
| downloadByFileBtn.setEnabled(bln); | |||
| downloadByFileProgressBar.setValue(0); | |||
| downloadByFileProgressBar.setEnabled(bln); | |||
| downloadByTimeBtn.setEnabled(bln); | |||
| downloadByTimeProgressBar.setValue(0); | |||
| downloadByTimeProgressBar.setEnabled(bln); | |||
| chnComboBoxByFile.setEnabled(bln); | |||
| streamComboBoxByFile.setEnabled(bln); | |||
| chnComboBoxByTime.setEnabled(bln); | |||
| streamComboBoxByTime.setEnabled(bln); | |||
| dateChooserStartByFile.setEnabled(bln); | |||
| dateChooserEndByFile.setEnabled(bln); | |||
| dateChooserStartByTime.setEnabled(bln); | |||
| dateChooserEndByTime.setEnabled(bln); | |||
| } | |||
| //登录组件 | |||
| private LoginPanel loginPanel; | |||
| // 下载 | |||
| private DownLoadRecordPanel downloadRecordPanel; | |||
| // 按文件下载 | |||
| private DownLoadByTimePanel downloadByTimePanel; | |||
| private JPanel downloadByFileSetPanel; | |||
| private JPanel queryPanel; | |||
| private JPanel downByFilePanel; | |||
| private JButton queryRecordBtn; | |||
| private JButton downloadByFileBtn; | |||
| private JProgressBar downloadByFileProgressBar; | |||
| private JButton downloadByTimeBtn; | |||
| private JProgressBar downloadByTimeProgressBar; | |||
| private JTable table; | |||
| private DefaultTableModel defaultmodel; | |||
| private JLabel chnlabel; | |||
| private JComboBox chnComboBoxByFile; | |||
| private JComboBox chnComboBoxByTime; | |||
| private JLabel streamLabel; | |||
| private JComboBox streamComboBoxByFile; | |||
| private JComboBox streamComboBoxByTime; | |||
| private DateChooserJButton dateChooserStartByFile; | |||
| private DateChooserJButton dateChooserEndByFile; | |||
| // 按文件下载 | |||
| private DownLoadByFilePanel downloadByFilePanel; | |||
| private JPanel downloadByTimeSetPanel; | |||
| private JPanel downByTimePanel; | |||
| private DateChooserJButton dateChooserStartByTime; | |||
| private DateChooserJButton dateChooserEndByTime; | |||
| } | |||
| public class DownLoadRecord { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| DownLoadRecordFrame demo = new DownLoadRecordFrame(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }; | |||
| @@ -0,0 +1,254 @@ | |||
| package com.netsdk.demo.frame.FaceRecognition; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.IOException; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JCheckBox; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.event.ChangeEvent; | |||
| import javax.swing.event.ChangeListener; | |||
| import com.sun.jna.Memory; | |||
| import com.netsdk.common.*; | |||
| import com.netsdk.demo.module.FaceRecognitionModule; | |||
| import com.netsdk.lib.ToolKits; | |||
| public class AddPersonDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private Memory memory = null; | |||
| private String groupId = ""; | |||
| private String groupName = ""; | |||
| private WindowCloseListener listener; | |||
| public void addWindowCloseListener(WindowCloseListener listener) { | |||
| this.listener = listener; | |||
| } | |||
| /** | |||
| * @param groupId 人脸库ID | |||
| * @param groupName 人脸库名称 | |||
| */ | |||
| public AddPersonDialog(String groupId, String groupName){ | |||
| setTitle(Res.string().getAddPerson()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(520, 400); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| this.groupId = groupId; | |||
| this.groupName = groupName; | |||
| FaceServerAddPanel faceServerAddPanel = new FaceServerAddPanel(); | |||
| add(faceServerAddPanel, BorderLayout.CENTER); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e){ | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| public class FaceServerAddPanel extends JPanel{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public FaceServerAddPanel() { | |||
| BorderEx.set(this, "", 4); | |||
| setLayout(new BorderLayout()); | |||
| JPanel imagePanel = new JPanel(); | |||
| JPanel personInfoPanel = new JPanel(); | |||
| Dimension dimension = this.getPreferredSize(); | |||
| dimension.height = 400; | |||
| dimension.width = 250; | |||
| personInfoPanel.setPreferredSize(dimension); | |||
| add(imagePanel, BorderLayout.CENTER); | |||
| add(personInfoPanel, BorderLayout.WEST); | |||
| /////////// 添加的人脸图片面板 ////////////////// | |||
| imagePanel.setLayout(new BorderLayout()); | |||
| addImagePanel = new PaintPanel(); // 添加的人员信息图片显示 | |||
| selectImageBtn = new JButton(Res.string().getSelectPicture()); | |||
| imagePanel.add(addImagePanel, BorderLayout.CENTER); | |||
| imagePanel.add(selectImageBtn, BorderLayout.SOUTH); | |||
| ////////// 添加的人脸信息面板 ///////////////// | |||
| personInfoPanel.setLayout(new FlowLayout()); | |||
| JLabel goroupIdLabel = new JLabel(Res.string().getFaceGroupId(), JLabel.CENTER); | |||
| JLabel goroupNameLabel = new JLabel(Res.string().getFaceGroupName(), JLabel.CENTER); | |||
| JLabel nameLabel = new JLabel(Res.string().getName(), JLabel.CENTER); | |||
| JLabel sexLabel = new JLabel(Res.string().getSex(), JLabel.CENTER); | |||
| JLabel birthdayLabel = new JLabel(Res.string().getBirthday(), JLabel.CENTER); | |||
| JLabel idTypeLabel = new JLabel(Res.string().getIdType(), JLabel.CENTER); | |||
| JLabel idLabel = new JLabel(Res.string().getIdNo(), JLabel.CENTER); | |||
| Dimension dimension2 = new Dimension(); | |||
| dimension2.width = 80; | |||
| dimension2.height = 20; | |||
| goroupIdLabel.setPreferredSize(dimension2); | |||
| goroupNameLabel.setPreferredSize(dimension2); | |||
| nameLabel.setPreferredSize(dimension2); | |||
| sexLabel.setPreferredSize(dimension2); | |||
| idTypeLabel.setPreferredSize(dimension2); | |||
| idLabel.setPreferredSize(dimension2); | |||
| birthdayLabel.setPreferredSize(dimension2); | |||
| goroupIdTextField = new JTextField(); | |||
| goroupNameTextField = new JTextField(); | |||
| nameTextField = new JTextField(); | |||
| sexComboBox = new JComboBox(Res.string().getSexStrings()); | |||
| birthdayBtn = new DateChooserJButtonEx(); | |||
| idTypeComboBox = new JComboBox(Res.string().getIdStrings()); | |||
| idTextField = new JTextField(); | |||
| birthdayCheckBox = new JCheckBox(); | |||
| addBtn = new JButton(Res.string().getAdd()); | |||
| cancelBtn = new JButton(Res.string().getCancel()); | |||
| birthdayBtn.setStartYear(1900); | |||
| Dimension dimension3 = new Dimension(); | |||
| dimension3.width = 150; | |||
| dimension3.height = 20; | |||
| sexComboBox.setPreferredSize(dimension3); | |||
| idTypeComboBox.setPreferredSize(dimension3); | |||
| goroupIdTextField.setPreferredSize(dimension3); | |||
| goroupNameTextField.setPreferredSize(dimension3); | |||
| nameTextField.setPreferredSize(dimension3); | |||
| idTextField.setPreferredSize(dimension3); | |||
| birthdayBtn.setPreferredSize(new Dimension(130, 20)); | |||
| birthdayCheckBox.setPreferredSize(new Dimension(20, 20)); | |||
| addBtn.setPreferredSize(new Dimension(120, 20)); | |||
| cancelBtn.setPreferredSize(new Dimension(120, 20)); | |||
| goroupIdTextField.setEditable(false); | |||
| goroupNameTextField.setEditable(false); | |||
| birthdayCheckBox.setSelected(true); | |||
| goroupIdTextField.setText(groupId); | |||
| goroupNameTextField.setText(groupName); | |||
| personInfoPanel.add(goroupIdLabel); | |||
| personInfoPanel.add(goroupIdTextField); | |||
| personInfoPanel.add(goroupNameLabel); | |||
| personInfoPanel.add(goroupNameTextField); | |||
| personInfoPanel.add(nameLabel); | |||
| personInfoPanel.add(nameTextField); | |||
| personInfoPanel.add(sexLabel); | |||
| personInfoPanel.add(sexComboBox); | |||
| personInfoPanel.add(idTypeLabel); | |||
| personInfoPanel.add(idTypeComboBox); | |||
| personInfoPanel.add(idLabel); | |||
| personInfoPanel.add(idTextField); | |||
| personInfoPanel.add(birthdayLabel); | |||
| personInfoPanel.add(birthdayBtn); | |||
| personInfoPanel.add(birthdayCheckBox); | |||
| personInfoPanel.add(addBtn); | |||
| personInfoPanel.add(cancelBtn); | |||
| birthdayCheckBox.addChangeListener(new ChangeListener() { | |||
| @Override | |||
| public void stateChanged(ChangeEvent arg0) { | |||
| if(birthdayCheckBox.isSelected()) { | |||
| birthdayBtn.setEnabled(true); | |||
| } else { | |||
| birthdayBtn.setEnabled(false); | |||
| } | |||
| } | |||
| }); | |||
| // 选择图片,获取图片的信息 | |||
| selectImageBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| String picPath = ""; | |||
| // 选择图片,获取图片路径,并在界面显示 | |||
| picPath = ToolKits.openPictureFile(addImagePanel); | |||
| if(!picPath.equals("")) { | |||
| try { | |||
| memory = ToolKits.readPictureFile(picPath); | |||
| } catch (IOException e) { | |||
| // TODO Auto-generated catch block | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| // 添加人员信息 | |||
| addBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| boolean bRet = FaceRecognitionModule.addPerson(goroupIdTextField.getText(), | |||
| memory, | |||
| nameTextField.getText(), | |||
| sexComboBox.getSelectedIndex(), | |||
| birthdayCheckBox.isSelected(), birthdayBtn.getText().toString(), | |||
| idTypeComboBox.getSelectedIndex(), idTextField.getText()); | |||
| if(bRet) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| dispose(); | |||
| listener.windowClosing(); | |||
| } | |||
| }); | |||
| // 取消,关闭 | |||
| cancelBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 添加人员信息窗口的组件 | |||
| private PaintPanel addImagePanel; | |||
| private JButton selectImageBtn; | |||
| private JTextField goroupIdTextField; | |||
| private JTextField goroupNameTextField; | |||
| private JTextField nameTextField; | |||
| private JComboBox sexComboBox; | |||
| private DateChooserJButtonEx birthdayBtn; | |||
| private JComboBox idTypeComboBox; | |||
| private JTextField idTextField; | |||
| private JButton addBtn; | |||
| private JButton cancelBtn; | |||
| private JCheckBox birthdayCheckBox; | |||
| } | |||
| @@ -0,0 +1,350 @@ | |||
| package com.netsdk.demo.frame.FaceRecognition; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.GridLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.util.ArrayList; | |||
| import java.util.HashMap; | |||
| import java.util.Vector; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JTable; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import com.netsdk.common.*; | |||
| import com.netsdk.demo.module.FaceRecognitionModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.NET_FACERECONGNITION_GROUP_INFO; | |||
| public class DispositionOperateDialog extends JDialog { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| // 通道列表 | |||
| private Vector<String> chnlist = new Vector<String>(); | |||
| // 通道个数 | |||
| private int nChn = LoginModule.m_stDeviceInfo.byChanNum; | |||
| // 通道列表, 用于布控 | |||
| private ArrayList< Integer> arrayList = new ArrayList<Integer>(); | |||
| // key:通道 value:相似度, 用于撤控 | |||
| private HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>(); | |||
| String groupId = ""; | |||
| String groupName = ""; | |||
| public DispositionOperateDialog(String groupId, String groupName) { | |||
| setTitle(Res.string().getDisposition() + "/" + Res.string().getDelDisposition()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(450, 400); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| for(int i = 1; i < nChn + 1; i++) { | |||
| chnlist.add(Res.string().getChannel() + " " + String.valueOf(i)); | |||
| } | |||
| this.groupId = groupId; | |||
| this.groupName = groupName; | |||
| DispositionListPanel dispositionListPanel = new DispositionListPanel(); | |||
| DispositionInfoPanel dispositionInfoPanel = new DispositionInfoPanel(); | |||
| add(dispositionListPanel, BorderLayout.CENTER); | |||
| add(dispositionInfoPanel, BorderLayout.NORTH); | |||
| findChnAndSimilary(); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| /* | |||
| * 布控显示列表 | |||
| */ | |||
| private class DispositionListPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public DispositionListPanel() { | |||
| BorderEx.set(this, "", 2); | |||
| setLayout(new BorderLayout()); | |||
| JPanel panel = new JPanel(); | |||
| JPanel panel2 = new JPanel(); | |||
| JPanel panel3 = new JPanel(); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.width = 145; | |||
| panel.setPreferredSize(dimension); | |||
| panel.setLayout(new BorderLayout()); | |||
| panel.add(panel2, BorderLayout.NORTH); | |||
| panel.add(panel3, BorderLayout.SOUTH); | |||
| addBtn = new JButton(Res.string().getAdd()); | |||
| refreshBtn = new JButton(Res.string().getFresh()); | |||
| panel2.setLayout(new GridLayout(2, 1)); | |||
| panel2.add(addBtn); | |||
| panel2.add(refreshBtn); | |||
| dispositionBtn = new JButton(Res.string().getDisposition()); | |||
| delDispositionBtn = new JButton(Res.string().getDelDisposition()); | |||
| panel3.setLayout(new GridLayout(2, 1)); | |||
| panel3.add(dispositionBtn); | |||
| panel3.add(delDispositionBtn); | |||
| data = new Object[512][2]; | |||
| defaultTableModel = new DefaultTableModel(data, Res.string().getDispositionTable()); | |||
| table = new JTable(defaultTableModel){ // 列表不可编辑 | |||
| private static final long serialVersionUID = 1L; | |||
| @Override | |||
| public boolean isCellEditable(int row, int column) { | |||
| return false; | |||
| } | |||
| }; | |||
| DefaultTableCellRenderer dCellRenderer = new DefaultTableCellRenderer(); | |||
| dCellRenderer.setHorizontalAlignment(JLabel.CENTER); | |||
| table.setDefaultRenderer(Object.class, dCellRenderer); | |||
| add(new JScrollPane(table), BorderLayout.CENTER); | |||
| add(panel, BorderLayout.EAST); | |||
| // 添加通道和相似度到列表 | |||
| addBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| boolean isExit = false; | |||
| String chn = String.valueOf(chnComboBox.getSelectedIndex() + 1); | |||
| String similary = similaryTextField.getText(); | |||
| if(similaryTextField.getText().equals("") | |||
| || Integer.parseInt(similaryTextField.getText()) > 100) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSimilarityRange(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| // 如果存在了通道号,列表修改相应的相似度 | |||
| for(int i = 0; i < nChn; i++) { | |||
| if(chn.equals(String.valueOf(defaultTableModel.getValueAt(i, 0)).trim())) { | |||
| defaultTableModel.setValueAt(similary, i, 1); | |||
| isExit = true; | |||
| break; | |||
| } | |||
| } | |||
| if(isExit) { | |||
| return; | |||
| } | |||
| // 如果不存在通道号,按顺序添加人列表 | |||
| for(int i = 0; i < nChn; i++) { | |||
| if(String.valueOf(defaultTableModel.getValueAt(i, 0)).trim().equals("") | |||
| || defaultTableModel.getValueAt(i, 0) == null) { | |||
| defaultTableModel.setValueAt(chn, i, 0); | |||
| defaultTableModel.setValueAt(similary, i, 1); | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| // 刷新已布控的通道和相似度信息 | |||
| refreshBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| findChnAndSimilary(); | |||
| } | |||
| }); | |||
| // 布控 | |||
| dispositionBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| hashMap.clear(); | |||
| // 获取列表里的数据 | |||
| for(int i = 0; i < nChn; i++) { | |||
| // 判断通道号是否为空 | |||
| if(!String.valueOf(defaultTableModel.getValueAt(i, 0)).trim().equals("") | |||
| && defaultTableModel.getValueAt(i, 0) != null) { | |||
| // 判断相似度是否为空 | |||
| if(!String.valueOf(defaultTableModel.getValueAt(i, 1)).trim().equals("") | |||
| && defaultTableModel.getValueAt(i, 1) != null) { | |||
| hashMap.put(Integer.parseInt(String.valueOf(defaultTableModel.getValueAt(i, 0)).trim()), | |||
| Integer.parseInt(String.valueOf(defaultTableModel.getValueAt(i, 1)).trim())); | |||
| } else { | |||
| hashMap.put(Integer.parseInt(String.valueOf(defaultTableModel.getValueAt(i, 0)).trim()), 0); | |||
| } | |||
| } | |||
| } | |||
| System.out.println("size:" + hashMap.size()); | |||
| if(hashMap.size() == 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getAddDispositionInfo(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(!FaceRecognitionModule.putDisposition(goroupIdTextField.getText(), hashMap)) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } | |||
| // 刷新列表 | |||
| findChnAndSimilary(); | |||
| } | |||
| }); | |||
| delDispositionBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| arrayList.clear(); | |||
| // 获取所有选中行数 | |||
| int[] rows = null; | |||
| rows = table.getSelectedRows(); | |||
| if(rows == null) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectDelDispositionInfo(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| // 获取所有选中,非空的通道号 | |||
| for(int i = 0; i < rows.length; i++) { | |||
| if(!String.valueOf(defaultTableModel.getValueAt(rows[i], 0)).trim().equals("") | |||
| && defaultTableModel.getValueAt(rows[i], 0) != null) { | |||
| arrayList.add(Integer.parseInt(String.valueOf(defaultTableModel.getValueAt(rows[i], 0)).trim())); | |||
| } | |||
| } | |||
| if(arrayList.size() == 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectDelDispositionInfo(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(!FaceRecognitionModule.delDisposition(goroupIdTextField.getText(), arrayList)) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } | |||
| // 刷新列表 | |||
| findChnAndSimilary(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /* | |||
| * 布控信息 | |||
| */ | |||
| private class DispositionInfoPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public DispositionInfoPanel() { | |||
| BorderEx.set(this, "", 2); | |||
| setLayout(new FlowLayout()); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.height = 80; | |||
| setPreferredSize(dimension); | |||
| JLabel goroupIdLabel = new JLabel(Res.string().getFaceGroupId(), JLabel.CENTER); | |||
| JLabel goroupNameLabel = new JLabel(Res.string().getFaceGroupName(), JLabel.CENTER); | |||
| JLabel chnLabel = new JLabel(Res.string().getChannel(), JLabel.CENTER); | |||
| JLabel similaryLabel = new JLabel(Res.string().getSimilarity(), JLabel.CENTER); | |||
| goroupIdTextField = new JTextField(); | |||
| goroupNameTextField = new JTextField(); | |||
| chnComboBox = new JComboBox(chnlist); | |||
| similaryTextField = new JTextField(); | |||
| Dimension dimension1 = new Dimension(); | |||
| dimension1.width = 80; | |||
| dimension1.height = 20; | |||
| goroupIdLabel.setPreferredSize(dimension1); | |||
| goroupNameLabel.setPreferredSize(dimension1); | |||
| chnLabel.setPreferredSize(dimension1); | |||
| similaryLabel.setPreferredSize(dimension1); | |||
| goroupIdTextField.setPreferredSize(new Dimension(120, 20)); | |||
| goroupNameTextField.setPreferredSize(new Dimension(120, 20)); | |||
| chnComboBox.setPreferredSize(new Dimension(120, 20)); | |||
| similaryTextField.setPreferredSize(new Dimension(120, 20)); | |||
| add(goroupIdLabel); | |||
| add(goroupIdTextField); | |||
| add(goroupNameLabel); | |||
| add(goroupNameTextField); | |||
| add(chnLabel); | |||
| add(chnComboBox); | |||
| add(similaryLabel); | |||
| add(similaryTextField); | |||
| ToolKits.limitTextFieldLength(similaryTextField, 3); | |||
| goroupIdTextField.setEditable(false); | |||
| goroupNameTextField.setEditable(false); | |||
| goroupIdTextField.setText(groupId); | |||
| goroupNameTextField.setText(groupName); | |||
| } | |||
| } | |||
| // 查找人脸库的布控通道以及对应的相似度 | |||
| private void findChnAndSimilary() { | |||
| // 清空列表 | |||
| defaultTableModel.setRowCount(0); | |||
| defaultTableModel.setRowCount(512); | |||
| // 查询布控信息 | |||
| NET_FACERECONGNITION_GROUP_INFO[] groupInfos = FaceRecognitionModule.findGroupInfo(goroupIdTextField.getText()); | |||
| if(groupInfos == null) { | |||
| return; | |||
| } | |||
| for(int i = 0; i < groupInfos[0].nRetChnCount; i++) { | |||
| defaultTableModel.setValueAt(String.valueOf(groupInfos[0].nChannel[i] + 1), i, 0); | |||
| defaultTableModel.setValueAt(String.valueOf(groupInfos[0].nSimilarity[i]), i, 1); | |||
| } | |||
| } | |||
| private Object[][] data; | |||
| private DefaultTableModel defaultTableModel; | |||
| private JTable table; | |||
| private JButton addBtn; | |||
| private JButton refreshBtn; | |||
| private JButton dispositionBtn; | |||
| private JButton delDispositionBtn; | |||
| private JTextField goroupIdTextField; | |||
| private JTextField goroupNameTextField; | |||
| private JComboBox chnComboBox; | |||
| private JTextField similaryTextField; | |||
| } | |||
| @@ -0,0 +1,138 @@ | |||
| package com.netsdk.demo.frame.FaceRecognition; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.HeadlessException; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.File; | |||
| import java.util.concurrent.ExecutionException; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.SwingWorker; | |||
| import com.netsdk.common.PaintPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.FaceRecognitionModule; | |||
| import com.netsdk.lib.ToolKits; | |||
| public class DownloadPictureDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public DownloadPictureDialog() { | |||
| setTitle(Res.string().getDownLoadPicture()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(380, 500); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| JLabel picPathLabel = new JLabel(Res.string().getPicturePath()+":", JLabel.CENTER); | |||
| picPathTextField = new JTextField(); | |||
| downloadBth = new JButton(Res.string().getDownLoadPicture()); | |||
| picPathTextField.setPreferredSize(new Dimension(180, 20)); | |||
| downloadBth.setPreferredSize(new Dimension(80, 20)); | |||
| paintPanel = new PaintPanel(); | |||
| paintPanel.setPreferredSize(new Dimension(360, 450)); | |||
| setLayout(new FlowLayout()); | |||
| add(picPathLabel); | |||
| add(picPathTextField); | |||
| add(downloadBth); | |||
| add(paintPanel); | |||
| downloadBth.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| paintPanel.setOpaque(true); | |||
| paintPanel.repaint(); | |||
| downloadBth.setEnabled(false); | |||
| } | |||
| }); | |||
| downloadPicture(); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| private void downloadPicture() { | |||
| new SwingWorker<Boolean, Integer>() { | |||
| String szFileName = ""; // 要下载的图片路径 | |||
| String pszFileDst = ""; // 保存图片的路径 | |||
| @Override | |||
| protected Boolean doInBackground() { | |||
| if(picPathTextField.getText().isEmpty()) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getEnterPicturePath(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| szFileName = picPathTextField.getText(); | |||
| pszFileDst = "./person.jpg"; | |||
| File file = new File(pszFileDst); | |||
| if(file.exists()) { | |||
| file.delete(); | |||
| } | |||
| if(!FaceRecognitionModule.downloadPersonPic(szFileName, pszFileDst)) { | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| if(picPathTextField.getText().isEmpty()) { | |||
| return; | |||
| } | |||
| try { | |||
| if(get()) { | |||
| // 下载成功后,面板上显示下载的图片 | |||
| ToolKits.openPictureFile(pszFileDst, paintPanel); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } catch (HeadlessException e) { | |||
| e.printStackTrace(); | |||
| } catch (InterruptedException e) { | |||
| e.printStackTrace(); | |||
| } catch (ExecutionException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| downloadBth.setEnabled(true); | |||
| } | |||
| }.execute(); | |||
| } | |||
| private JTextField picPathTextField; | |||
| private PaintPanel paintPanel; | |||
| private JButton downloadBth; | |||
| } | |||
| @@ -0,0 +1,245 @@ | |||
| package com.netsdk.demo.frame.FaceRecognition; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.util.Vector; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JTextArea; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.SwingWorker; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.DateChooserJButton; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.FaceRecognitionModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib.MEDIAFILE_FACERECOGNITION_INFO; | |||
| /** | |||
| * 查找人脸事件的信息记录 | |||
| */ | |||
| public class FindFaceEventRecordDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private Vector<String> chnList = new Vector<String>(); | |||
| public FindFaceEventRecordDialog(){ | |||
| setTitle("查找人脸事件的信息记录"); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(750, 430); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| FaceEventRecordPanel faceRecordPanel = new FaceEventRecordPanel(); | |||
| add(faceRecordPanel, BorderLayout.CENTER); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e){ | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| public class FaceEventRecordPanel extends JPanel{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public FaceEventRecordPanel() { | |||
| BorderEx.set(this, "", 4); | |||
| setLayout(new BorderLayout()); | |||
| JPanel panel1 = new JPanel(); | |||
| JPanel panel2 = new JPanel(); | |||
| add(panel1, BorderLayout.NORTH); | |||
| add(panel2, BorderLayout.CENTER); | |||
| // | |||
| JLabel chnlabel = new JLabel(Res.string().getChannel()); | |||
| chnComboBox = new JComboBox(); | |||
| for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) { | |||
| chnList.add(Res.string().getChannel() + " " + String.valueOf(i)); | |||
| } | |||
| // 登陆成功,将通道添加到控件 | |||
| chnComboBox.setModel(new DefaultComboBoxModel(chnList)); | |||
| chnComboBox.setPreferredSize(new Dimension(80, 20)); | |||
| JLabel startLabel = new JLabel(Res.string().getStartTime()); | |||
| startTimeBtn = new DateChooserJButton("2018-10-30 11:11:11"); | |||
| JLabel endLabel = new JLabel(Res.string().getEndTime()); | |||
| endTimeBtn = new DateChooserJButton(); | |||
| searchBtn = new JButton(Res.string().getSearch()); | |||
| searchBtn.setPreferredSize(new Dimension(70, 20)); | |||
| JButton downloadBth = new JButton("下载查询到的图片"); | |||
| downloadBth.setPreferredSize(new Dimension(140, 20)); | |||
| msgTextArea = new JTextArea(); | |||
| Dimension dimension1 = new Dimension(); | |||
| dimension1.width = 130; | |||
| dimension1.height = 20; | |||
| startTimeBtn.setPreferredSize(dimension1); | |||
| endTimeBtn.setPreferredSize(dimension1); | |||
| panel1.setLayout(new FlowLayout()); | |||
| panel1.add(chnlabel); | |||
| panel1.add(chnComboBox); | |||
| panel1.add(startLabel); | |||
| panel1.add(startTimeBtn); | |||
| panel1.add(endLabel); | |||
| panel1.add(endTimeBtn); | |||
| panel1.add(searchBtn); | |||
| panel1.add(downloadBth); | |||
| panel2.setLayout(new BorderLayout()); | |||
| panel2.add(new JScrollPane(msgTextArea), BorderLayout.CENTER); | |||
| searchBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| searchBtn.setEnabled(false); | |||
| } | |||
| }); | |||
| findEventInfo(); | |||
| } | |||
| }); | |||
| downloadBth.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| DownloadPictureDialog dialog = new DownloadPictureDialog(); | |||
| dialog.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| private JComboBox chnComboBox; | |||
| private DateChooserJButton startTimeBtn; | |||
| private DateChooserJButton endTimeBtn; | |||
| private JTextArea msgTextArea; | |||
| private JButton searchBtn; | |||
| public void findEventInfo() { | |||
| new SwingWorker<Boolean, StringBuffer>() { | |||
| @Override | |||
| protected Boolean doInBackground() { | |||
| int count = 0; // 循环查询了几次 | |||
| int index = 0; // index + 1 为查询到的总个数 | |||
| int nFindCount = 10; // 每次查询的个数 | |||
| StringBuffer message = null; | |||
| msgTextArea.setText(""); | |||
| // 获取查询句柄 | |||
| if(!FaceRecognitionModule.findFile(chnComboBox.getSelectedIndex(), startTimeBtn.getText(), endTimeBtn.getText())) { | |||
| message = new StringBuffer(); | |||
| message.append("未查询到相关信息"); | |||
| publish(message); | |||
| return false; | |||
| } | |||
| // 查询具体信息, 循环查询, nFindCount为每次查询的个数 | |||
| while(true) { | |||
| MEDIAFILE_FACERECOGNITION_INFO[] msg = FaceRecognitionModule.findNextFile(nFindCount); | |||
| if(msg == null) { | |||
| message = new StringBuffer(); | |||
| message.append("查询结束!"); | |||
| publish(message); | |||
| break; | |||
| } | |||
| for(int i = 0; i < msg.length; i++) { | |||
| index = i + count * nFindCount + 1; | |||
| // 清空 | |||
| message = new StringBuffer(); | |||
| message.append("[" + index + "]通道号 :" + msg[i].nChannelId + "\n"); | |||
| message.append("[" + index + "]报警发生时间 :" + msg[i].stTime.toStringTime() + "\n"); | |||
| message.append("[" + index + "]全景图 :" + new String(msg[i].stGlobalScenePic.szFilePath).trim() + "\n"); | |||
| message.append("[" + index + "]人脸图路径 :" + new String(msg[i].stObjectPic.szFilePath).trim() + "\n"); | |||
| message.append("[" + index + "]匹配到的候选对象数量 :" + msg[i].nCandidateNum + "\n"); | |||
| for(int j = 0; j < msg[i].nCandidateNum; j++) { | |||
| for(int k = 0; k < msg[i].stuCandidatesPic[j].nFileCount; k++) { | |||
| message.append("[" + index + "]对比图路径 :" + new String(msg[i].stuCandidatesPic[j].stFiles[k].szFilePath).trim() + "\n"); | |||
| } | |||
| } | |||
| message.append("[" + index + "]匹配到的候选对象数量 :" + msg[i].nCandidateExNum + "\n"); | |||
| // 对比信息 | |||
| for(int j = 0; j < msg[i].nCandidateExNum; j++) { | |||
| message.append("[" + index + "]人员唯一标识符 :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szUID).trim() + "\n"); | |||
| // 以下参数,设备有些功能没有解析,如果想要知道 对比图的人员信息,可以根据上面获取的 szUID,来查询人员信息。 | |||
| // findFaceRecognitionDB() 此示例的方法是根据 GroupId来查询的,这里的查询,GroupId不填,根据 szUID 来查询 | |||
| message.append("[" + index + "]姓名 :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szPersonName).trim() + "\n"); | |||
| message.append("[" + index + "]相似度 :" + msg[i].stuCandidatesEx[j].bySimilarity + "\n"); | |||
| message.append("[" + index + "]年龄 :" + msg[i].stuCandidatesEx[j].stPersonInfo.byAge + "\n"); | |||
| message.append("[" + index + "]人脸库名称 :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szGroupName).trim() + "\n"); | |||
| message.append("[" + index + "]人脸库ID :" + new String(msg[i].stuCandidatesEx[j].stPersonInfo.szGroupID).trim() + "\n"); | |||
| } | |||
| message.append("\n"); | |||
| publish(message); | |||
| } | |||
| if (msg.length < nFindCount) { | |||
| message = new StringBuffer(); | |||
| message.append("查询结束!"); | |||
| publish(message); | |||
| break; | |||
| } else { | |||
| count ++; | |||
| } | |||
| } | |||
| // 关闭查询接口 | |||
| FaceRecognitionModule.findCloseFile(); | |||
| return true; | |||
| } | |||
| @Override | |||
| protected void process(java.util.List<StringBuffer> chunks) { | |||
| for(StringBuffer data : chunks) { | |||
| msgTextArea.append(data.toString()); | |||
| msgTextArea.updateUI(); | |||
| } | |||
| super.process(chunks); | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| searchBtn.setEnabled(true); | |||
| } | |||
| }.execute(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,334 @@ | |||
| package com.netsdk.demo.frame.FaceRecognition; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.GridLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.UnsupportedEncodingException; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JTable; | |||
| import javax.swing.ListSelectionModel; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.FaceRecognitionModule; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| import com.netsdk.lib.ToolKits; | |||
| public class GroupOperateDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| // 人脸库名称 | |||
| private String inputGroupName = ""; | |||
| // 布控界面 | |||
| public DispositionOperateDialog dispositionOperateDialog = null; | |||
| // 人员操作界面 | |||
| public PersonOperateDialog personOperateDialog = null; | |||
| public GroupOperateDialog() { | |||
| setTitle(Res.string().getGroupOperate()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(650, 360); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| GroupListPanel GroupPanel = new GroupListPanel(); | |||
| GroupOperatePanel GroupOperatePanel = new GroupOperatePanel(); | |||
| add(GroupPanel, BorderLayout.CENTER); | |||
| add(GroupOperatePanel, BorderLayout.EAST); | |||
| findGroupInfo(); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| /* | |||
| * 人脸库显示列表 | |||
| */ | |||
| private class GroupListPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public GroupListPanel() { | |||
| BorderEx.set(this, "", 2); | |||
| setLayout(new BorderLayout()); | |||
| data = new Object[20][3]; | |||
| defaultTableModel = new DefaultTableModel(data, Res.string().getGroupTable()); | |||
| table = new JTable(defaultTableModel) { // 列表不可编辑 | |||
| private static final long serialVersionUID = 1L; | |||
| @Override | |||
| public boolean isCellEditable(int row, int column) { | |||
| return false; | |||
| } | |||
| }; | |||
| table.getColumnModel().getColumn(0).setPreferredWidth(80); | |||
| table.getColumnModel().getColumn(1).setPreferredWidth(280); | |||
| table.getColumnModel().getColumn(2).setPreferredWidth(100); | |||
| table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行 | |||
| DefaultTableCellRenderer dCellRenderer = new DefaultTableCellRenderer(); | |||
| dCellRenderer.setHorizontalAlignment(JLabel.CENTER); | |||
| table.setDefaultRenderer(Object.class, dCellRenderer); | |||
| add(new JScrollPane(table), BorderLayout.CENTER); | |||
| } | |||
| } | |||
| /* | |||
| * 人脸库操作 | |||
| */ | |||
| private class GroupOperatePanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public GroupOperatePanel() { | |||
| BorderEx.set(this, "", 2); | |||
| setLayout(new BorderLayout()); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.width = 230; | |||
| setPreferredSize(dimension); | |||
| JPanel GroupPanel = new JPanel(); | |||
| JPanel panel = new JPanel(); | |||
| add(GroupPanel, BorderLayout.CENTER); | |||
| add(panel, BorderLayout.SOUTH); | |||
| /*JButton searchByPicBtn = new JButton(Res.string().getSearchByPic());*/ | |||
| JButton personOperateBtn = new JButton(Res.string().getPersonOperate()); | |||
| panel.setPreferredSize(new Dimension(230, 45)); | |||
| panel.setLayout(new GridLayout(2, 1)); | |||
| /*panel.add(searchByPicBtn);*/ | |||
| panel.add(personOperateBtn); | |||
| /* | |||
| * 人脸库增删改, 布控、撤控 | |||
| */ | |||
| JButton refreshBtn = new JButton(Res.string().getFresh()); | |||
| JButton addGroupBtn = new JButton(Res.string().getAddGroup()); | |||
| JButton modifyGroupBtn = new JButton(Res.string().getModifyGroup()); | |||
| JButton deleteGroupBtn = new JButton(Res.string().getDelGroup()); | |||
| JButton dispositionBtn = new JButton(Res.string().getDisposition() + "/" + Res.string().getDelDisposition()); | |||
| GroupPanel.setLayout(new GridLayout(12, 1)); | |||
| GroupPanel.add(refreshBtn); | |||
| GroupPanel.add(addGroupBtn); | |||
| GroupPanel.add(modifyGroupBtn); | |||
| GroupPanel.add(deleteGroupBtn); | |||
| GroupPanel.add(dispositionBtn); | |||
| // 刷新人脸库列表 | |||
| refreshBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| findGroupInfo(); | |||
| } | |||
| }); | |||
| // 添加人脸库 | |||
| addGroupBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| inputGroupName = JOptionPane.showInputDialog(GroupOperateDialog.this, | |||
| Res.string().getInputGroupName(), ""); | |||
| if(inputGroupName == null) { // 取消或者关闭按钮 | |||
| return; | |||
| } | |||
| if(FaceRecognitionModule.addGroup(inputGroupName)) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| // 更新人脸库列表 | |||
| findGroupInfo(); | |||
| } | |||
| }); | |||
| // 修改人脸库 | |||
| modifyGroupBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| int row = -1; | |||
| row = table.getSelectedRow(); //获得所选的单行 | |||
| if(row < 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(defaultTableModel.getValueAt(row, 0) == null || String.valueOf(defaultTableModel.getValueAt(row, 0)).trim().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| inputGroupName = JOptionPane.showInputDialog(GroupOperateDialog.this, | |||
| Res.string().getInputGroupName(), String.valueOf(defaultTableModel.getValueAt(row, 1)).trim()); | |||
| if(inputGroupName == null) { // 取消或者关闭按钮 | |||
| return; | |||
| } | |||
| if(FaceRecognitionModule.modifyGroup(inputGroupName, String.valueOf(defaultTableModel.getValueAt(row, 0)).trim())) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| // 更新人脸库列表 | |||
| findGroupInfo(); | |||
| } | |||
| }); | |||
| // 删除人脸库 | |||
| deleteGroupBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| int row = -1; | |||
| row = table.getSelectedRow(); //获得所选的单行 | |||
| if(row < 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(defaultTableModel.getValueAt(row, 0) == null || String.valueOf(defaultTableModel.getValueAt(row, 0)).trim().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(!FaceRecognitionModule.deleteGroup(String.valueOf(defaultTableModel.getValueAt(row, 0)).trim())) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } | |||
| // 更新人脸库列表 | |||
| findGroupInfo(); | |||
| } | |||
| }); | |||
| // 布控/撤控 | |||
| dispositionBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| int row = -1; | |||
| row = table.getSelectedRow(); //获得所选的单行 | |||
| if(row < 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(defaultTableModel.getValueAt(row, 0) == null || String.valueOf(defaultTableModel.getValueAt(row, 0)).trim().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| dispositionOperateDialog = new DispositionOperateDialog(String.valueOf(defaultTableModel.getValueAt(row, 0)).trim(), | |||
| String.valueOf(defaultTableModel.getValueAt(row, 1)).trim()); | |||
| dispositionOperateDialog.setVisible(true); | |||
| } | |||
| }); | |||
| /*// 以图搜图 | |||
| searchByPicBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SearchByPicDialog dialog = new SearchByPicDialog(); | |||
| dialog.setVisible(true); | |||
| } | |||
| });*/ | |||
| // 人员操作 | |||
| personOperateBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| int row = -1; | |||
| row = table.getSelectedRow(); //获得所选的单行 | |||
| if(row < 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(defaultTableModel.getValueAt(row, 0) == null || String.valueOf(defaultTableModel.getValueAt(row, 0)).trim().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| personOperateDialog = new PersonOperateDialog(String.valueOf(defaultTableModel.getValueAt(row, 0)).trim(), | |||
| String.valueOf(defaultTableModel.getValueAt(row, 1)).trim()); | |||
| personOperateDialog.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /* | |||
| * 查找所有人脸库 | |||
| */ | |||
| private void findGroupInfo() { | |||
| // 清空列表 | |||
| for(int i = 0; i < 20; i++) { | |||
| for(int j = 0; j < 3; j++) { | |||
| defaultTableModel.setValueAt("", i, j); | |||
| } | |||
| } | |||
| // 查询人脸库 | |||
| NET_FACERECONGNITION_GROUP_INFO[] groupInfoArr = FaceRecognitionModule.findGroupInfo(""); | |||
| if(groupInfoArr != null) { | |||
| for(int i = 0; i < groupInfoArr.length; i++) { | |||
| defaultTableModel.setValueAt(new String(groupInfoArr[i].szGroupId).trim(), i, 0); | |||
| try { | |||
| defaultTableModel.setValueAt(new String(groupInfoArr[i].szGroupName, "GBK").trim(), i, 1); | |||
| } catch (UnsupportedEncodingException e1) { | |||
| e1.printStackTrace(); | |||
| } | |||
| defaultTableModel.setValueAt(String.valueOf(groupInfoArr[i].nGroupSize).trim(), i, 2); | |||
| } | |||
| } | |||
| } | |||
| private Object[][] data; | |||
| private DefaultTableModel defaultTableModel; | |||
| private JTable table; | |||
| } | |||
| @@ -0,0 +1,529 @@ | |||
| package com.netsdk.demo.frame.FaceRecognition; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.SwingUtilities; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.DateChooserJButtonEx; | |||
| import com.netsdk.common.FunctionList; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.DotmatrixScreenModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.NetSDKLib.NET_CTRL_SET_PARK_INFO; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.ButtonGroup; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JRadioButton; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.awt.event.ActionEvent; | |||
| import javax.swing.JPasswordField; | |||
| import javax.swing.border.TitledBorder; | |||
| import javax.swing.UIManager; | |||
| import java.awt.Color; | |||
| /** | |||
| * | |||
| * @author 119178 | |||
| * 点阵屏下发demo | |||
| */ | |||
| public class LatticeScreen { | |||
| // 设备断线通知回调 | |||
| private DisConnect disConnect = new DisConnect(); | |||
| // 网络连接恢复 | |||
| private HaveReConnect haveReConnect = new HaveReConnect(); | |||
| private JFrame frame; | |||
| private JTextField textField; | |||
| private JTextField textField_1; | |||
| private JTextField textField_2; | |||
| private JTextField textField_4; | |||
| private JTextField textField_5; | |||
| private JTextField textField_6; | |||
| private JTextField textField_7; | |||
| private JTextField textField_8; | |||
| private JTextField textField_9; | |||
| private JComboBox comboBox; | |||
| private JComboBox comboBox_1; | |||
| private JRadioButton rdbtnNewRadioButton; | |||
| private JRadioButton rdbtnNewRadioButton_1; | |||
| private DateChooserJButtonEx startTime; | |||
| private DateChooserJButtonEx EndTime; | |||
| private JPasswordField passwordField; | |||
| private JButton btnNewButton ; | |||
| private JButton btnNewButton_1 ; | |||
| private JButton btnNewButton_2 ; | |||
| private JTextField textField_3; | |||
| private JTextField textField_10; | |||
| private JTextField textField_11; | |||
| /** | |||
| * Launch the application. | |||
| */ | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| LatticeScreen demo = new LatticeScreen(); | |||
| demo.frame.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| /** | |||
| * Create the application. | |||
| */ | |||
| public LatticeScreen() { | |||
| LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 | |||
| initialize(); | |||
| // 注册窗体清出事件 | |||
| frame.addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| LoginModule.logout(); // 退出 | |||
| LoginModule.cleanup(); // 关闭工程,释放资源 | |||
| frame.dispose(); | |||
| // 返回主菜单 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /////////////////面板/////////////////// | |||
| // 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数 | |||
| private class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| // 断线提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getFaceRecognition() + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 网络连接恢复,设备重连成功回调 | |||
| // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 | |||
| private class HaveReConnect implements NetSDKLib.fHaveReConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| // 重连提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getFaceRecognition() + " : " + Res.string().getOnline()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /** | |||
| * Initialize the contents of the frame. | |||
| */ | |||
| private void initialize() { | |||
| frame = new JFrame(); | |||
| frame.setTitle(Res.string().getmatrixScreen()); | |||
| frame.setBounds(200, 200, 807, 578); | |||
| //frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); | |||
| frame.getContentPane().setLayout(null); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| final JPanel panel1 = new JPanel(); | |||
| panel1.setBounds(10, 10, 100, 50); | |||
| JPanel panel = new JPanel(); | |||
| panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), Res.string().getLogin(), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); | |||
| panel.setBounds(10, 10, 771, 40); | |||
| frame.getContentPane().add(panel); | |||
| panel.setLayout(null); | |||
| JLabel lblNewLabel = new JLabel(Res.string().getDeviceIp()+":"); | |||
| lblNewLabel.setBounds(26, 14, 54, 15); | |||
| panel.add(lblNewLabel); | |||
| textField = new JTextField("172.24.31.178"); | |||
| textField.setBounds(82, 11, 76, 21); | |||
| panel.add(textField); | |||
| textField.setColumns(10); | |||
| JLabel lblNewLabel_1 = new JLabel(Res.string().getPort()+":"); | |||
| lblNewLabel_1.setBounds(168, 14, 47, 15); | |||
| panel.add(lblNewLabel_1); | |||
| textField_1 = new JTextField("37777"); | |||
| textField_1.setBounds(217, 11, 76, 21); | |||
| panel.add(textField_1); | |||
| textField_1.setColumns(10); | |||
| JLabel lblNewLabel_2 = new JLabel(Res.string().getUserName()+":"); | |||
| lblNewLabel_2.setBounds(302, 14, 47, 15); | |||
| panel.add(lblNewLabel_2); | |||
| textField_2 = new JTextField("admin"); | |||
| textField_2.setBounds(351, 11, 76, 21); | |||
| panel.add(textField_2); | |||
| textField_2.setColumns(10); | |||
| JLabel lblNewLabel_3 = new JLabel(Res.string().getPassword()+":"); | |||
| lblNewLabel_3.setBounds(435, 14, 38, 15); | |||
| panel.add(lblNewLabel_3); | |||
| passwordField = new JPasswordField("admin123"); | |||
| passwordField.setBounds(476, 11, 89, 21); | |||
| panel.add(passwordField); | |||
| btnNewButton = new JButton(Res.string().getLogin()); | |||
| btnNewButton.addActionListener(new ActionListener() { | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(LoginModule.login(textField.getText(), | |||
| Integer.parseInt(textField_1.getText()), | |||
| textField_2.getText(), | |||
| new String(passwordField.getPassword()))) { | |||
| btnNewButton.setEnabled(false); | |||
| btnNewButton_1.setEnabled(true); | |||
| btnNewButton_2.setEnabled(true); | |||
| textField.setEnabled(true);; | |||
| textField_1.setEditable(true);; | |||
| textField_2.setEnabled(true); | |||
| textField_3.setEnabled(true); | |||
| textField_4.setEnabled(true); | |||
| textField_5.setEnabled(true); | |||
| textField_6.setEnabled(true); | |||
| textField_7.setEnabled(true); | |||
| textField_8.setEnabled(true); | |||
| textField_9.setEnabled(true); | |||
| textField_10.setEnabled(true); | |||
| textField_11.setEnabled(true); | |||
| comboBox.setEnabled(true); | |||
| comboBox_1.setEnabled(true); | |||
| rdbtnNewRadioButton.setEnabled(true); | |||
| rdbtnNewRadioButton_1.setEnabled(true); | |||
| startTime.setEnabled(true); | |||
| EndTime.setEnabled(true); | |||
| passwordField.setEnabled(true); | |||
| }else{ | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| btnNewButton.setBounds(584, 10, 76, 23); | |||
| panel.add(btnNewButton); | |||
| btnNewButton.setEnabled(true); | |||
| btnNewButton_1 = new JButton(Res.string().getLogout()); | |||
| btnNewButton_1.addActionListener(new ActionListener() { | |||
| public void actionPerformed(ActionEvent e) { | |||
| LoginModule.logout(); | |||
| btnNewButton.setEnabled(true); | |||
| btnNewButton_1.setEnabled(false); | |||
| btnNewButton_2.setEnabled(false); | |||
| textField.setEnabled(false);; | |||
| textField_1.setEditable(false);; | |||
| textField_2.setEnabled(false); | |||
| textField_3.setEnabled(false); | |||
| textField_4.setEnabled(false); | |||
| textField_5.setEnabled(false); | |||
| textField_6.setEnabled(false); | |||
| textField_7.setEnabled(false); | |||
| textField_8.setEnabled(false); | |||
| textField_9.setEnabled(false); | |||
| textField_10.setEnabled(false); | |||
| textField_11.setEnabled(false); | |||
| comboBox.setEnabled(false); | |||
| comboBox_1.setEditable(false); | |||
| rdbtnNewRadioButton.setEnabled(false); | |||
| rdbtnNewRadioButton_1.setEnabled(false); | |||
| startTime.setEnabled(true); | |||
| EndTime.setEnabled(true); | |||
| passwordField.setEnabled(true); | |||
| } | |||
| }); | |||
| btnNewButton_1.setBounds(678, 10, 76, 23); | |||
| panel.add(btnNewButton_1); | |||
| btnNewButton_1.setEnabled(false); | |||
| JPanel panel_1 = new JPanel(); | |||
| panel_1.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null)); | |||
| panel_1.setBounds(10, 56, 771, 474); | |||
| frame.getContentPane().add(panel_1); | |||
| panel_1.setLayout(null); | |||
| JLabel lblNewLabel_4 = new JLabel(Res.string().getPassingState()+":"); | |||
| lblNewLabel_4.setBounds(71, 26, 95, 21); | |||
| panel_1.add(lblNewLabel_4); | |||
| comboBox = new JComboBox(); | |||
| comboBox.setEnabled(false); | |||
| comboBox.setModel(new DefaultComboBoxModel(new String[] {Res.string().getPassingCar(), Res.string().getNoCar()})); | |||
| comboBox.setBounds(176, 26, 131, 21); | |||
| panel_1.add(comboBox); | |||
| JLabel lblNewLabel_5 = new JLabel(Res.string().getInTime()+":"); | |||
| lblNewLabel_5.setBounds(391, 29, 102, 15); | |||
| panel_1.add(lblNewLabel_5); | |||
| startTime=new DateChooserJButtonEx(); | |||
| startTime.setEnabled(false); | |||
| startTime.setBounds(503, 26, 131, 21); | |||
| panel_1.add(startTime); | |||
| JLabel lblNewLabel_6 = new JLabel(Res.string().getOutTime()+":"); | |||
| lblNewLabel_6.setBounds(391, 84, 102, 15); | |||
| panel_1.add(lblNewLabel_6); | |||
| EndTime=new DateChooserJButtonEx(); | |||
| EndTime.setEnabled(false); | |||
| EndTime.setBounds(503, 81, 131, 21); | |||
| panel_1.add(EndTime); | |||
| JLabel lblNewLabel_7 = new JLabel(Res.string().getPlateNumber()+":"); | |||
| lblNewLabel_7.setBounds(71, 84, 95, 15); | |||
| panel_1.add(lblNewLabel_7); | |||
| textField_4 = new JTextField(); | |||
| textField_4.setEnabled(false); | |||
| textField_4.setBounds(176, 81, 131, 21); | |||
| panel_1.add(textField_4); | |||
| textField_4.setColumns(10); | |||
| JLabel lblNewLabel_8 = new JLabel(Res.string().getCarOwner()+":"); | |||
| lblNewLabel_8.setBounds(77, 142, 89, 15); | |||
| panel_1.add(lblNewLabel_8); | |||
| textField_5 = new JTextField(); | |||
| textField_5.setEnabled(false); | |||
| textField_5.setBounds(176, 139, 131, 21); | |||
| panel_1.add(textField_5); | |||
| textField_5.setColumns(10); | |||
| JLabel lblNewLabel_9 = new JLabel(Res.string().getParkingTime()+":"); | |||
| lblNewLabel_9.setBounds(391, 133, 102, 15); | |||
| panel_1.add(lblNewLabel_9); | |||
| textField_6 = new JTextField(); | |||
| textField_6.setEnabled(false); | |||
| textField_6.setBounds(503, 130, 131, 21); | |||
| panel_1.add(textField_6); | |||
| textField_6.setColumns(10); | |||
| JLabel lblNewLabel_10 = new JLabel(Res.string().getUserType()+":"); | |||
| lblNewLabel_10.setBounds(71, 198, 95, 15); | |||
| panel_1.add(lblNewLabel_10); | |||
| comboBox_1 = new JComboBox(); | |||
| comboBox_1.setEnabled(false); | |||
| comboBox_1.setModel(new DefaultComboBoxModel(new String[] {Res.string().getMonthlyCardUser() | |||
| ,Res.string().getAnnualCardUser(), Res.string().getLongTermUser(), Res.string().getTemporaryUser()})); | |||
| comboBox_1.setBounds(176, 195, 131, 21); | |||
| panel_1.add(comboBox_1); | |||
| JLabel lblNewLabel_11 = new JLabel(Res.string().getParkingCharge()); | |||
| lblNewLabel_11.setBounds(391, 178, 102, 15); | |||
| panel_1.add(lblNewLabel_11); | |||
| textField_7 = new JTextField(); | |||
| textField_7.setEnabled(false); | |||
| textField_7.setBounds(503, 175, 131, 21); | |||
| panel_1.add(textField_7); | |||
| textField_7.setColumns(10); | |||
| JLabel lblNewLabel_12 = new JLabel(Res.string().getDaysDue()); | |||
| lblNewLabel_12.setBounds(71, 253, 95, 15); | |||
| panel_1.add(lblNewLabel_12); | |||
| textField_8 = new JTextField(); | |||
| textField_8.setEnabled(false); | |||
| textField_8.setBounds(176, 250, 131, 21); | |||
| panel_1.add(textField_8); | |||
| textField_8.setColumns(10); | |||
| JLabel lblNewLabel_13 = new JLabel(Res.string().getRemainingParkingSpaces()); | |||
| lblNewLabel_13.setBounds(391, 215, 102, 15); | |||
| panel_1.add(lblNewLabel_13); | |||
| textField_9 = new JTextField(); | |||
| textField_9.setEnabled(false); | |||
| textField_9.setBounds(503, 212, 131, 21); | |||
| panel_1.add(textField_9); | |||
| textField_9.setColumns(10); | |||
| rdbtnNewRadioButton = new JRadioButton(Res.string().getVehiclesNotAllowedToPass()); | |||
| rdbtnNewRadioButton.setEnabled(false); | |||
| rdbtnNewRadioButton.setBounds(367, 249, 155, 23); | |||
| panel_1.add(rdbtnNewRadioButton); | |||
| rdbtnNewRadioButton_1 = new JRadioButton(Res.string().getAllowedVehiclesToPass()); | |||
| rdbtnNewRadioButton_1.setEnabled(false); | |||
| rdbtnNewRadioButton_1.setBounds(524, 249, 162, 23); | |||
| panel_1.add(rdbtnNewRadioButton_1); | |||
| ButtonGroup group=new ButtonGroup(); | |||
| group.add(rdbtnNewRadioButton); | |||
| group.add(rdbtnNewRadioButton_1); | |||
| btnNewButton_2 = new JButton(Res.string().getSetUp()); | |||
| btnNewButton_2.addActionListener(new ActionListener() { | |||
| public void actionPerformed(ActionEvent e) { | |||
| int emType=NetSDKLib.CtrlType.CTRLTYPE_CTRL_SET_PARK_INFO; | |||
| NET_CTRL_SET_PARK_INFO msg=new NET_CTRL_SET_PARK_INFO(); | |||
| msg.szPlateNumber=textField_4.getText().getBytes(); | |||
| if(!textField_6.getText().equals("")) { | |||
| msg.nParkTime=Integer.parseInt(textField_6.getText()); | |||
| }else { | |||
| msg.nParkTime=0; | |||
| } | |||
| msg.szMasterofCar=textField_5.getText().getBytes(); | |||
| if(comboBox_1.getSelectedItem().equals(Res.string().getMonthlyCardUser())) { | |||
| msg.szUserType="monthlyCardUser".getBytes(); | |||
| } | |||
| else if(comboBox_1.getSelectedItem().equals(Res.string().getAnnualCardUser())){ | |||
| msg.szUserType="yearlyCardUser".getBytes(); | |||
| } | |||
| else if(comboBox_1.getSelectedItem().equals(Res.string().getLongTermUser())){ | |||
| msg.szUserType="longTimeUser".getBytes(); | |||
| } | |||
| else if(comboBox_1.getSelectedItem().equals(Res.string().getTemporaryUser())){ | |||
| msg.szUserType="casualUser".getBytes(); | |||
| } | |||
| if(!textField_8.getText().equals("")) { | |||
| msg.nRemainDay=Integer.parseInt(textField_8.getText()); | |||
| }else { | |||
| msg.nRemainDay=0; | |||
| } | |||
| if(rdbtnNewRadioButton.isSelected()) { | |||
| msg.nPassEnable=0; | |||
| }else if(rdbtnNewRadioButton_1.isSelected()){ | |||
| msg.nPassEnable=1; | |||
| } | |||
| String InTime=startTime.getText().toString();// 车辆入场时间 | |||
| String[] InTimes = InTime.split("-"); | |||
| msg.stuInTime.dwYear = (short)Integer.parseInt(InTimes[0]); | |||
| msg.stuInTime.dwMonth = (byte)Integer.parseInt(InTimes[1]); | |||
| msg.stuInTime.dwDay = (byte)Integer.parseInt(InTimes[2]); | |||
| String OutTime=EndTime.getText().toString();// 车辆出场时间 | |||
| String[] OutTimes = OutTime.split("-"); | |||
| msg.stuOutTime.dwYear = (short)Integer.parseInt(OutTimes[0]); | |||
| msg.stuOutTime.dwMonth = (byte)Integer.parseInt(OutTimes[1]); | |||
| msg.stuOutTime.dwDay = (byte)Integer.parseInt(OutTimes[2]); | |||
| //msg.stuInTime.setTime(2019, 7, 9, 10, 45, 0); // 车辆入场时间 | |||
| //msg.stuOutTime.setTime(2019, 7, 9, 10, 52, 0); // 车辆出场时间 | |||
| try { | |||
| msg.szParkCharge=textField_7.getText().getBytes("GBK"); | |||
| } catch (UnsupportedEncodingException e2) { | |||
| // TODO Auto-generated catch block | |||
| e2.printStackTrace(); | |||
| } | |||
| if(!textField_9.getText().equals("")) { | |||
| msg.nRemainSpace=Integer.parseInt(textField_9.getText()); | |||
| }else { | |||
| msg.nRemainSpace=0; | |||
| } | |||
| /* | |||
| * if(rdbtnNewRadioButton.isSelected()) { msg.nPassEnable=1; }else | |||
| * if(rdbtnNewRadioButton_1.isSelected()){ msg.nPassEnable=0; } | |||
| */ | |||
| if(comboBox.getSelectedItem().equals(Res.string().getPassingCar())) { | |||
| msg.emCarStatus=1; | |||
| } | |||
| else if(comboBox.getSelectedItem().equals(Res.string().getNoCar())){ | |||
| msg.emCarStatus=2; | |||
| } | |||
| try { | |||
| msg.szSubUserType=textField_3.getText().getBytes("GBK"); | |||
| } catch (UnsupportedEncodingException e1) { | |||
| // TODO Auto-generated catch block | |||
| e1.printStackTrace(); | |||
| } | |||
| try { | |||
| msg.szRemarks=textField_10.getText().getBytes("GBK"); | |||
| } catch (UnsupportedEncodingException e1) { | |||
| // TODO Auto-generated catch block | |||
| e1.printStackTrace(); | |||
| } | |||
| try { | |||
| msg.szCustom=textField_11.getText().getBytes("GBK"); | |||
| } catch (UnsupportedEncodingException e1) { | |||
| // TODO Auto-generated catch block | |||
| e1.printStackTrace(); | |||
| } | |||
| msg.write(); | |||
| boolean ret=DotmatrixScreenModule.setDotmatrixScreen(emType, msg); | |||
| if(ret) { | |||
| JOptionPane.showMessageDialog(panel1, Res.string().getSetUpSuccess()); | |||
| }else { | |||
| JOptionPane.showMessageDialog(panel1, Res.string().getSetUpFailed()); | |||
| } | |||
| } | |||
| }); | |||
| btnNewButton_2.setBounds(618, 441, 93, 23); | |||
| panel_1.add(btnNewButton_2); | |||
| btnNewButton_2.setEnabled(false); | |||
| JLabel label = new JLabel(Res.string().getCostomUserInfo()+":"); | |||
| label.setBounds(58, 309, 119, 21); | |||
| panel_1.add(label); | |||
| JLabel label_1 = new JLabel(Res.string().getRemarksInfo()+":"); | |||
| label_1.setBounds(58, 350, 97, 21); | |||
| panel_1.add(label_1); | |||
| JLabel label_2 = new JLabel(Res.string().getCostomInfo()+":"); | |||
| label_2.setBounds(60, 394, 95, 21); | |||
| panel_1.add(label_2); | |||
| textField_3 = new JTextField(); | |||
| textField_3.setEnabled(false); | |||
| textField_3.setColumns(10); | |||
| textField_3.setBounds(187, 306, 460, 28); | |||
| panel_1.add(textField_3); | |||
| textField_10 = new JTextField(); | |||
| textField_10.setEnabled(false); | |||
| textField_10.setColumns(10); | |||
| textField_10.setBounds(187, 347, 460, 28); | |||
| panel_1.add(textField_10); | |||
| textField_11 = new JTextField(); | |||
| textField_11.setEnabled(false); | |||
| textField_11.setColumns(10); | |||
| textField_11.setBounds(187, 391, 460, 28); | |||
| panel_1.add(textField_11); | |||
| } | |||
| } | |||
| @@ -0,0 +1,326 @@ | |||
| package com.netsdk.demo.frame.FaceRecognition; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.UnsupportedEncodingException; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JCheckBox; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.event.ChangeEvent; | |||
| import javax.swing.event.ChangeListener; | |||
| import com.sun.jna.Memory; | |||
| import com.netsdk.common.*; | |||
| import com.netsdk.demo.module.FaceRecognitionModule; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| import com.netsdk.lib.ToolKits; | |||
| public class ModifyPersonDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private String groupId = ""; | |||
| private String groupName = ""; | |||
| private String uid = ""; | |||
| private String pszFileDst = ""; | |||
| private Memory memory = null; | |||
| private CANDIDATE_INFOEX stuCandidate = null; | |||
| private WindowCloseListener listener; | |||
| public void addWindowCloseListener(WindowCloseListener listener) { | |||
| this.listener = listener; | |||
| } | |||
| /** | |||
| * @param groupId 人脸库ID | |||
| * @param groupName 人脸库名称 | |||
| * @param uid 人员标识符 | |||
| * @param pszFileDst 下载到本地的图片路径 | |||
| * @param memory 图片数据 | |||
| * @param stuCandidate 人员信息 | |||
| */ | |||
| public ModifyPersonDialog(String groupId, | |||
| String groupName, | |||
| String uid, | |||
| String pszFileDst, | |||
| Memory memory, | |||
| CANDIDATE_INFOEX stuCandidate){ | |||
| setTitle(Res.string().getModifyPerson()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(520, 400); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| this.groupId = groupId; | |||
| this.groupName = groupName; | |||
| this.uid = uid; | |||
| this.pszFileDst = pszFileDst; | |||
| this.memory = memory; | |||
| this.stuCandidate = stuCandidate; | |||
| FaceServerAddPanel faceServerAddPanel = new FaceServerAddPanel(); | |||
| add(faceServerAddPanel, BorderLayout.CENTER); | |||
| showPersonInfo(); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e){ | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| public class FaceServerAddPanel extends JPanel{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public FaceServerAddPanel() { | |||
| BorderEx.set(this, "", 4); | |||
| setLayout(new BorderLayout()); | |||
| JPanel imagePanel = new JPanel(); | |||
| JPanel personInfoPanel = new JPanel(); | |||
| Dimension dimension = this.getPreferredSize(); | |||
| dimension.height = 400; | |||
| dimension.width = 250; | |||
| personInfoPanel.setPreferredSize(dimension); | |||
| add(imagePanel, BorderLayout.CENTER); | |||
| add(personInfoPanel, BorderLayout.WEST); | |||
| /////////// 添加的人脸图片面板 ////////////////// | |||
| imagePanel.setLayout(new BorderLayout()); | |||
| addImagePanel = new PaintPanel(); // 添加的人员信息图片显示 | |||
| selectImageBtn = new JButton(Res.string().getSelectPicture()); | |||
| imagePanel.add(addImagePanel, BorderLayout.CENTER); | |||
| imagePanel.add(selectImageBtn, BorderLayout.SOUTH); | |||
| ////////// 添加的人脸信息面板 ///////////////// | |||
| personInfoPanel.setLayout(new FlowLayout()); | |||
| JLabel goroupIdLabel = new JLabel(Res.string().getFaceGroupId(), JLabel.CENTER); | |||
| JLabel goroupNameLabel = new JLabel(Res.string().getFaceGroupName(), JLabel.CENTER); | |||
| JLabel uidLabel = new JLabel(Res.string().getUid(), JLabel.CENTER); | |||
| JLabel nameLabel = new JLabel(Res.string().getName(), JLabel.CENTER); | |||
| JLabel sexLabel = new JLabel(Res.string().getSex(), JLabel.CENTER); | |||
| JLabel birthdayLabel = new JLabel(Res.string().getBirthday(), JLabel.CENTER); | |||
| JLabel idTypeLabel = new JLabel(Res.string().getIdType(), JLabel.CENTER); | |||
| JLabel idLabel = new JLabel(Res.string().getIdNo(), JLabel.CENTER); | |||
| Dimension dimension2 = new Dimension(); | |||
| dimension2.width = 80; | |||
| dimension2.height = 20; | |||
| uidLabel.setPreferredSize(dimension2); | |||
| goroupIdLabel.setPreferredSize(dimension2); | |||
| goroupNameLabel.setPreferredSize(dimension2); | |||
| nameLabel.setPreferredSize(dimension2); | |||
| sexLabel.setPreferredSize(dimension2); | |||
| birthdayLabel.setPreferredSize(dimension2); | |||
| idTypeLabel.setPreferredSize(dimension2); | |||
| idLabel.setPreferredSize(dimension2); | |||
| goroupIdTextField = new JTextField(); | |||
| goroupNameTextField = new JTextField(); | |||
| uidTextField = new JTextField(); | |||
| nameTextField = new JTextField(); | |||
| sexComboBox = new JComboBox(Res.string().getSexStrings()); | |||
| birthdayBtn = new DateChooserJButtonEx(""); | |||
| idTypeComboBox = new JComboBox(Res.string().getIdStrings()); | |||
| idTextField = new JTextField(); | |||
| birthdayCheckBox = new JCheckBox(); | |||
| modifyBtn = new JButton(Res.string().getModify()); | |||
| cancelBtn = new JButton(Res.string().getCancel()); | |||
| birthdayBtn.setStartYear(1900); | |||
| Dimension dimension3 = new Dimension(); | |||
| dimension3.width = 150; | |||
| dimension3.height = 20; | |||
| sexComboBox.setPreferredSize(dimension3); | |||
| idTypeComboBox.setPreferredSize(dimension3); | |||
| goroupIdTextField.setPreferredSize(dimension3); | |||
| goroupNameTextField.setPreferredSize(dimension3); | |||
| uidTextField.setPreferredSize(dimension3); | |||
| nameTextField.setPreferredSize(dimension3); | |||
| idTextField.setPreferredSize(dimension3); | |||
| birthdayBtn.setPreferredSize(new Dimension(130, 20)); | |||
| birthdayCheckBox.setPreferredSize(new Dimension(20, 20)); | |||
| modifyBtn.setPreferredSize(new Dimension(120, 20)); | |||
| cancelBtn.setPreferredSize(new Dimension(120, 20)); | |||
| goroupIdTextField.setEditable(false); | |||
| goroupNameTextField.setEditable(false); | |||
| uidTextField.setEditable(false); | |||
| birthdayCheckBox.setSelected(true); | |||
| goroupIdTextField.setText(groupId); | |||
| goroupNameTextField.setText(groupName); | |||
| uidTextField.setText(uid); | |||
| personInfoPanel.add(goroupIdLabel); | |||
| personInfoPanel.add(goroupIdTextField); | |||
| personInfoPanel.add(goroupNameLabel); | |||
| personInfoPanel.add(goroupNameTextField); | |||
| personInfoPanel.add(uidLabel); | |||
| personInfoPanel.add(uidTextField); | |||
| personInfoPanel.add(nameLabel); | |||
| personInfoPanel.add(nameTextField); | |||
| personInfoPanel.add(sexLabel); | |||
| personInfoPanel.add(sexComboBox); | |||
| personInfoPanel.add(idTypeLabel); | |||
| personInfoPanel.add(idTypeComboBox); | |||
| personInfoPanel.add(idLabel); | |||
| personInfoPanel.add(idTextField); | |||
| personInfoPanel.add(birthdayLabel); | |||
| personInfoPanel.add(birthdayBtn); | |||
| personInfoPanel.add(birthdayCheckBox); | |||
| personInfoPanel.add(modifyBtn); | |||
| personInfoPanel.add(cancelBtn); | |||
| birthdayCheckBox.addChangeListener(new ChangeListener() { | |||
| @Override | |||
| public void stateChanged(ChangeEvent arg0) { | |||
| if(birthdayCheckBox.isSelected()) { | |||
| birthdayBtn.setEnabled(true); | |||
| } else { | |||
| birthdayBtn.setEnabled(false); | |||
| } | |||
| } | |||
| }); | |||
| // 选择图片,获取图片的信息 | |||
| selectImageBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| String picPath = ""; | |||
| // 选择图片,获取图片路径,并在界面显示 | |||
| picPath = ToolKits.openPictureFile(addImagePanel); | |||
| if(!picPath.equals("")) { | |||
| memory = null; | |||
| try { | |||
| memory = ToolKits.readPictureFile(picPath); | |||
| } catch (IOException e) { | |||
| // TODO Auto-generated catch block | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| // 修改人员信息 | |||
| modifyBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| boolean bRet = FaceRecognitionModule.modifyPerson(groupId, uid, | |||
| memory, | |||
| nameTextField.getText(), | |||
| sexComboBox.getSelectedIndex(), | |||
| birthdayCheckBox.isSelected(), birthdayBtn.getText().toString(), | |||
| idTypeComboBox.getSelectedIndex(), idTextField.getText()); | |||
| if(bRet) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| dispose(); | |||
| listener.windowClosing(); | |||
| } | |||
| }); | |||
| // 取消,关闭 | |||
| cancelBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| private void showPersonInfo() { | |||
| File file = null; | |||
| if(!pszFileDst.equals("")) { | |||
| file = ToolKits.openPictureFile(pszFileDst, addImagePanel); | |||
| } | |||
| if(file != null) { | |||
| file.delete(); | |||
| } | |||
| try { | |||
| nameTextField.setText(new String(stuCandidate.stPersonInfo.szPersonName, "GBK").trim()); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| sexComboBox.setSelectedIndex(stuCandidate.stPersonInfo.bySex & 0xff); | |||
| idTypeComboBox.setSelectedIndex(stuCandidate.stPersonInfo.byIDType & 0xff); | |||
| idTextField.setText(new String(stuCandidate.stPersonInfo.szID).trim()); | |||
| if(stuCandidate.stPersonInfo == null) { | |||
| birthdayCheckBox.setSelected(false); | |||
| birthdayBtn.setText(birthdayBtn.getDate().toString()); | |||
| } else { | |||
| if(String.valueOf((int)stuCandidate.stPersonInfo.wYear).equals("0000") | |||
| || String.valueOf((int)stuCandidate.stPersonInfo.wYear).equals("0") | |||
| || String.valueOf( stuCandidate.stPersonInfo.byMonth & 0xff).equals("0") | |||
| || String.valueOf( stuCandidate.stPersonInfo.byMonth & 0xff).equals("00") | |||
| || String.valueOf(stuCandidate.stPersonInfo.byDay & 0xff).equals("0") | |||
| || String.valueOf(stuCandidate.stPersonInfo.byDay & 0xff).equals("00")) { | |||
| birthdayCheckBox.setSelected(false); | |||
| birthdayBtn.setText(birthdayBtn.getDate().toString()); | |||
| } else { | |||
| birthdayCheckBox.setSelected(true); | |||
| birthdayBtn.setText(String.valueOf((int)stuCandidate.stPersonInfo.wYear) + "-" + | |||
| String.valueOf( stuCandidate.stPersonInfo.byMonth & 0xff) + "-" + | |||
| String.valueOf(stuCandidate.stPersonInfo.byDay & 0xff)); | |||
| } | |||
| } | |||
| } | |||
| // 添加人员信息窗口的组件 | |||
| public PaintPanel addImagePanel; | |||
| private JButton selectImageBtn; | |||
| private JTextField goroupIdTextField; | |||
| private JTextField goroupNameTextField; | |||
| private JTextField uidTextField; | |||
| public JTextField nameTextField; | |||
| public JComboBox sexComboBox; | |||
| public DateChooserJButtonEx birthdayBtn; | |||
| public JComboBox idTypeComboBox; | |||
| public JTextField idTextField; | |||
| private JButton modifyBtn; | |||
| private JButton cancelBtn; | |||
| public JCheckBox birthdayCheckBox; | |||
| } | |||
| @@ -0,0 +1,856 @@ | |||
| package com.netsdk.demo.frame.FaceRecognition; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.GridLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.IOException; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.HashMap; | |||
| import java.util.concurrent.ExecutionException; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JCheckBox; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JTable; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.ListSelectionModel; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.SwingWorker; | |||
| import javax.swing.event.ChangeEvent; | |||
| import javax.swing.event.ChangeListener; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import com.sun.jna.Memory; | |||
| import com.netsdk.common.*; | |||
| import com.netsdk.demo.module.FaceRecognitionModule; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| public class PersonOperateDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private String groupId = ""; | |||
| private String groupName = ""; | |||
| // 添加人员界面 | |||
| public AddPersonDialog addPersonDialog = null; | |||
| // 修改人员界面 | |||
| public ModifyPersonDialog modifyPersonDialog = null; | |||
| // 查询起始索引 | |||
| private int nBeginNum = 0; | |||
| // 页数 | |||
| private int nPagesNumber = 0; | |||
| // 查询人员总数 | |||
| private int nTotalCount = 0; | |||
| private HashMap<String, CANDIDATE_INFOEX> cadidateHashMap = new HashMap<String, CANDIDATE_INFOEX>(); | |||
| public PersonOperateDialog(String groupId, String groupName) { | |||
| setTitle(Res.string().getPersonOperate()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(680, 520); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| this.groupId = groupId; | |||
| this.groupName = groupName; | |||
| PersonInfoPanel personInfoPanel = new PersonInfoPanel(); | |||
| PersonInfoListPanel personInfoListPanel = new PersonInfoListPanel(); | |||
| add(personInfoPanel, BorderLayout.NORTH); | |||
| add(personInfoListPanel, BorderLayout.CENTER); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| nBeginNum = 0; | |||
| nPagesNumber = 0; | |||
| nTotalCount = 0; | |||
| cadidateHashMap.clear(); | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| /* | |||
| * 查找条件信息 | |||
| */ | |||
| private class SearchInfoPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public SearchInfoPanel() { | |||
| BorderEx.set(this, Res.string().getFindCondition(), 1); | |||
| setLayout(new FlowLayout()); | |||
| JLabel goroupIdLabel = new JLabel(Res.string().getFaceGroupId(), JLabel.CENTER); | |||
| JLabel goroupNameLabel = new JLabel(Res.string().getFaceGroupName(), JLabel.CENTER); | |||
| JLabel nameLabel = new JLabel(Res.string().getName(), JLabel.CENTER); | |||
| JLabel sexLabel = new JLabel(Res.string().getSex(), JLabel.CENTER); | |||
| JLabel IdTypeLabel = new JLabel(Res.string().getIdType(), JLabel.CENTER); | |||
| JLabel IdLabel = new JLabel(Res.string().getIdNo(), JLabel.CENTER); | |||
| JLabel birthdayLabel = new JLabel(Res.string().getBirthday(), JLabel.CENTER); | |||
| JLabel lineLabel = new JLabel("-", JLabel.CENTER); | |||
| startBirthdayCheckBox = new JCheckBox(); | |||
| endBirthdayCheckBox = new JCheckBox(); | |||
| JLabel nullLabel = new JLabel(); | |||
| Dimension dimension1 = new Dimension(); | |||
| dimension1.height = 20; | |||
| dimension1.width = 80; | |||
| goroupIdLabel.setPreferredSize(dimension1); | |||
| goroupNameLabel.setPreferredSize(dimension1); | |||
| nameLabel.setPreferredSize(dimension1); | |||
| sexLabel.setPreferredSize(dimension1); | |||
| IdTypeLabel.setPreferredSize(dimension1); | |||
| IdLabel.setPreferredSize(dimension1); | |||
| birthdayLabel.setPreferredSize(dimension1); | |||
| lineLabel.setPreferredSize(new Dimension(50, 20)); | |||
| nullLabel.setPreferredSize(new Dimension(180, 20)); | |||
| goroupIdTextField = new JTextField(); | |||
| goroupNameTextField = new JTextField(); | |||
| nameTextField = new JTextField(); | |||
| sexComboBox = new JComboBox(Res.string().getSexStringsFind()); | |||
| idTypeComboBox = new JComboBox(Res.string().getIdStringsFind()); | |||
| idTextField = new JTextField(); | |||
| startTimeBtn = new DateChooserJButtonEx("2018-07-01"); | |||
| endTimeBtn = new DateChooserJButtonEx(); | |||
| startTimeBtn.setStartYear(1900); | |||
| endTimeBtn.setStartYear(1900); | |||
| Dimension dimension2 = new Dimension(); | |||
| dimension2.height = 20; | |||
| goroupIdTextField.setPreferredSize(dimension2); | |||
| goroupNameTextField.setPreferredSize(dimension2); | |||
| nameTextField.setPreferredSize(dimension2); | |||
| idTextField.setPreferredSize(dimension2); | |||
| goroupIdTextField.setPreferredSize(new Dimension(120, 20)); | |||
| goroupNameTextField.setPreferredSize(new Dimension(120, 20)); | |||
| nameTextField.setPreferredSize(new Dimension(120, 20)); | |||
| idTextField.setPreferredSize(new Dimension(120, 20)); | |||
| sexComboBox.setPreferredSize(new Dimension(120, 20)); | |||
| startTimeBtn.setPreferredSize(new Dimension(125, 20)); | |||
| endTimeBtn.setPreferredSize(new Dimension(125, 20)); | |||
| idTypeComboBox.setPreferredSize(new Dimension(120, 20)); | |||
| startBirthdayCheckBox.setPreferredSize(new Dimension(20, 20)); | |||
| endBirthdayCheckBox.setPreferredSize(new Dimension(20, 20)); | |||
| add(goroupIdLabel); | |||
| add(goroupIdTextField); | |||
| add(goroupNameLabel); | |||
| add(goroupNameTextField); | |||
| add(nameLabel); | |||
| add(nameTextField); | |||
| add(sexLabel); | |||
| add(sexComboBox); | |||
| add(IdTypeLabel); | |||
| add(idTypeComboBox); | |||
| add(IdLabel); | |||
| add(idTextField); | |||
| add(birthdayLabel); | |||
| add(startTimeBtn); | |||
| add(startBirthdayCheckBox); | |||
| add(lineLabel); | |||
| add(endTimeBtn); | |||
| add(endBirthdayCheckBox); | |||
| add(nullLabel); | |||
| goroupIdTextField.setEditable(false); | |||
| goroupNameTextField.setEditable(false); | |||
| startBirthdayCheckBox.setSelected(false); | |||
| endBirthdayCheckBox.setSelected(false); | |||
| startTimeBtn.setEnabled(false); | |||
| endTimeBtn.setEnabled(false); | |||
| } | |||
| } | |||
| /* | |||
| * 人员信息以及操作面板 | |||
| */ | |||
| private class PersonInfoPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public PersonInfoPanel() { | |||
| BorderEx.set(this, "", 2); | |||
| setLayout(new BorderLayout()); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.height = 150; | |||
| setPreferredSize(dimension); | |||
| SearchInfoPanel searchInfoPanel = new SearchInfoPanel(); | |||
| JPanel operatePanel = new JPanel(); | |||
| add(searchInfoPanel, BorderLayout.CENTER); | |||
| add(operatePanel, BorderLayout.SOUTH); | |||
| /* | |||
| * 操作 | |||
| */ | |||
| searchPersonBtn = new JButton(Res.string().getFindPerson()); | |||
| JButton addPersonBtn = new JButton(Res.string().getAddPerson()); | |||
| JButton modifyPersonBtn = new JButton(Res.string().getModifyPerson()); | |||
| JButton deletePersonBtn = new JButton(Res.string().getDelPerson()); | |||
| operatePanel.setLayout(new GridLayout(1, 4)); | |||
| operatePanel.add(searchPersonBtn); | |||
| operatePanel.add(addPersonBtn); | |||
| operatePanel.add(modifyPersonBtn); | |||
| operatePanel.add(deletePersonBtn); | |||
| goroupIdTextField.setText(groupId); | |||
| goroupNameTextField.setText(groupName); | |||
| startBirthdayCheckBox.addChangeListener(new ChangeListener() { | |||
| @Override | |||
| public void stateChanged(ChangeEvent arg0) { | |||
| if(startBirthdayCheckBox.isSelected()) { | |||
| startTimeBtn.setEnabled(true); | |||
| } else { | |||
| startTimeBtn.setEnabled(false); | |||
| } | |||
| } | |||
| }); | |||
| endBirthdayCheckBox.addChangeListener(new ChangeListener() { | |||
| @Override | |||
| public void stateChanged(ChangeEvent arg0) { | |||
| if(endBirthdayCheckBox.isSelected()) { | |||
| endTimeBtn.setEnabled(true); | |||
| } else { | |||
| endTimeBtn.setEnabled(false); | |||
| } | |||
| } | |||
| }); | |||
| // 查找人员 | |||
| searchPersonBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| searchPersonBtn.setEnabled(false); | |||
| } | |||
| }); | |||
| new SwingWorker<CANDIDATE_INFOEX[], String>() { | |||
| @Override | |||
| protected CANDIDATE_INFOEX[] doInBackground() { | |||
| nTotalCount = 0; | |||
| nBeginNum = 0; | |||
| cleanList(); | |||
| cadidateHashMap.clear(); | |||
| nTotalCount = FaceRecognitionModule.startFindPerson(goroupIdTextField.getText(), | |||
| startBirthdayCheckBox.isSelected(), startTimeBtn.getText().toString(), | |||
| endBirthdayCheckBox.isSelected(), endTimeBtn.getText().toString(), | |||
| nameTextField.getText(), sexComboBox.getSelectedIndex(), | |||
| idTypeComboBox.getSelectedIndex(), idTextField.getText()); | |||
| if(nTotalCount <= 0) { | |||
| searchPersonBtn.setEnabled(true); | |||
| previousPageBtn.setEnabled(false); | |||
| lastPageBtn.setEnabled(false); | |||
| numTextField.setText(""); | |||
| return null; | |||
| } | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = FaceRecognitionModule.doFindPerson(nBeginNum, 17); | |||
| return stuCandidatesEx; | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| try { | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = get(); | |||
| findPersonInfo(stuCandidatesEx); | |||
| } catch (InterruptedException e) { | |||
| e.printStackTrace(); | |||
| } catch (ExecutionException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| }.execute(); | |||
| } | |||
| }); | |||
| // 添加人员 | |||
| addPersonBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| addPersonDialog = new AddPersonDialog(groupId, groupName); | |||
| addPersonDialog.addWindowCloseListener(new WindowCloseListener() { | |||
| @Override | |||
| public void windowClosing() { | |||
| new SwingWorker<CANDIDATE_INFOEX[], String>() { | |||
| @Override | |||
| protected CANDIDATE_INFOEX[] doInBackground() { | |||
| nTotalCount = 0; | |||
| nBeginNum = 0; | |||
| cleanList(); | |||
| cadidateHashMap.clear(); | |||
| nTotalCount = FaceRecognitionModule.startFindPerson(goroupIdTextField.getText(), | |||
| startBirthdayCheckBox.isSelected(), startTimeBtn.getText().toString(), | |||
| endBirthdayCheckBox.isSelected(), endTimeBtn.getText().toString(), | |||
| nameTextField.getText(), sexComboBox.getSelectedIndex(), | |||
| idTypeComboBox.getSelectedIndex(), idTextField.getText()); | |||
| if(nTotalCount <= 0) { | |||
| searchPersonBtn.setEnabled(true); | |||
| previousPageBtn.setEnabled(false); | |||
| lastPageBtn.setEnabled(false); | |||
| numTextField.setText(""); | |||
| return null; | |||
| } | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = FaceRecognitionModule.doFindPerson(nBeginNum, 17); | |||
| return stuCandidatesEx; | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| try { | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = get(); | |||
| findPersonInfo(stuCandidatesEx); | |||
| } catch (InterruptedException e) { | |||
| e.printStackTrace(); | |||
| } catch (ExecutionException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| }.execute(); | |||
| } | |||
| }); | |||
| addPersonDialog.setVisible(true); | |||
| } | |||
| }); | |||
| // 修改人员 | |||
| modifyPersonBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| int row = -1; | |||
| row = table.getSelectedRow(); //获得所选的单行 | |||
| if(row < 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectPerson(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(defaultTableModel.getValueAt(row, 0) == null || String.valueOf(defaultTableModel.getValueAt(row, 0)).trim().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectPerson(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| // 人员信息 | |||
| CANDIDATE_INFOEX stuCandidate = cadidateHashMap.get(String.valueOf(defaultTableModel.getValueAt(row, 0)).trim()); | |||
| // URL地址 | |||
| String szFilePath = stuCandidate.stPersonInfo.szFacePicInfo[0].pszFilePath.getString(0); | |||
| // 存放图片的本地路径 | |||
| String pszFileDst = "./person.jpg"; | |||
| // 下载图片, 下载到本地, 图片路径 "./person.jpg" | |||
| boolean bRet = FaceRecognitionModule.downloadPersonPic(szFilePath, pszFileDst); | |||
| Memory memory = null; | |||
| if(bRet) { | |||
| try { | |||
| memory = ToolKits.readPictureFile(pszFileDst); | |||
| } catch (IOException e) { | |||
| // TODO Auto-generated catch block | |||
| e.printStackTrace(); | |||
| } | |||
| } else { | |||
| pszFileDst = ""; | |||
| } | |||
| // 人员标识符 | |||
| String uid = String.valueOf(defaultTableModel.getValueAt(row, 0)).trim(); | |||
| modifyPersonDialog = new ModifyPersonDialog(groupId, groupName, uid, pszFileDst, memory, stuCandidate); | |||
| modifyPersonDialog.addWindowCloseListener(new WindowCloseListener() { | |||
| @Override | |||
| public void windowClosing() { | |||
| new SwingWorker<CANDIDATE_INFOEX[], String>() { | |||
| @Override | |||
| protected CANDIDATE_INFOEX[] doInBackground() { | |||
| nTotalCount = 0; | |||
| nBeginNum = 0; | |||
| cleanList(); | |||
| cadidateHashMap.clear(); | |||
| nTotalCount = FaceRecognitionModule.startFindPerson(goroupIdTextField.getText(), | |||
| startBirthdayCheckBox.isSelected(), startTimeBtn.getText().toString(), | |||
| endBirthdayCheckBox.isSelected(), endTimeBtn.getText().toString(), | |||
| nameTextField.getText(), sexComboBox.getSelectedIndex(), | |||
| idTypeComboBox.getSelectedIndex(), idTextField.getText()); | |||
| if(nTotalCount <= 0) { | |||
| searchPersonBtn.setEnabled(true); | |||
| previousPageBtn.setEnabled(false); | |||
| lastPageBtn.setEnabled(false); | |||
| numTextField.setText(""); | |||
| return null; | |||
| } | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = FaceRecognitionModule.doFindPerson(nBeginNum, 17); | |||
| return stuCandidatesEx; | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| try { | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = get(); | |||
| findPersonInfo(stuCandidatesEx); | |||
| } catch (InterruptedException e) { | |||
| e.printStackTrace(); | |||
| } catch (ExecutionException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| }.execute(); | |||
| } | |||
| }); | |||
| modifyPersonDialog.setVisible(true); | |||
| } | |||
| }); | |||
| // 删除人员 | |||
| deletePersonBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| int row = -1; | |||
| row = table.getSelectedRow(); //获得所选的单行 | |||
| if(row < 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectPerson(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(defaultTableModel.getValueAt(row, 0) == null || String.valueOf(defaultTableModel.getValueAt(row, 0)).trim().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectPerson(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(!FaceRecognitionModule.delPerson(goroupIdTextField.getText(), String.valueOf(defaultTableModel.getValueAt(row, 0)).trim())) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } | |||
| new SwingWorker<CANDIDATE_INFOEX[], String>() { | |||
| @Override | |||
| protected CANDIDATE_INFOEX[] doInBackground() { | |||
| nTotalCount = 0; | |||
| nBeginNum = 0; | |||
| cleanList(); | |||
| cadidateHashMap.clear(); | |||
| nTotalCount = FaceRecognitionModule.startFindPerson(goroupIdTextField.getText(), | |||
| startBirthdayCheckBox.isSelected(), startTimeBtn.getText().toString(), | |||
| endBirthdayCheckBox.isSelected(), endTimeBtn.getText().toString(), | |||
| nameTextField.getText(), sexComboBox.getSelectedIndex(), | |||
| idTypeComboBox.getSelectedIndex(), idTextField.getText()); | |||
| if(nTotalCount <= 0) { | |||
| searchPersonBtn.setEnabled(true); | |||
| previousPageBtn.setEnabled(false); | |||
| lastPageBtn.setEnabled(false); | |||
| numTextField.setText(""); | |||
| return null; | |||
| } | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = FaceRecognitionModule.doFindPerson(nBeginNum, 17); | |||
| return stuCandidatesEx; | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| try { | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = get(); | |||
| findPersonInfo(stuCandidatesEx); | |||
| } catch (InterruptedException e) { | |||
| e.printStackTrace(); | |||
| } catch (ExecutionException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| }.execute(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /* | |||
| * 人员信息显示列表 | |||
| */ | |||
| private class PersonInfoListPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public PersonInfoListPanel() { | |||
| BorderEx.set(this, "", 2); | |||
| setLayout(new BorderLayout()); | |||
| data = new Object[17][6]; | |||
| defaultTableModel = new DefaultTableModel(data, Res.string().getPersonTable()); | |||
| table = new JTable(defaultTableModel) { // 列表不可编辑 | |||
| private static final long serialVersionUID = 1L; | |||
| @Override | |||
| public boolean isCellEditable(int row, int column) { | |||
| return false; | |||
| } | |||
| }; | |||
| table.getColumnModel().getColumn(0).setPreferredWidth(120); | |||
| table.getColumnModel().getColumn(1).setPreferredWidth(150); | |||
| table.getColumnModel().getColumn(2).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(3).setPreferredWidth(200); | |||
| table.getColumnModel().getColumn(4).setPreferredWidth(150); | |||
| table.getColumnModel().getColumn(5).setPreferredWidth(250); | |||
| table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行 | |||
| DefaultTableCellRenderer dCellRenderer = new DefaultTableCellRenderer(); | |||
| dCellRenderer.setHorizontalAlignment(JLabel.CENTER); | |||
| table.setDefaultRenderer(Object.class, dCellRenderer); | |||
| JPanel panel = new JPanel(); | |||
| previousPageBtn = new JButton(Res.string().getPreviousPage()); | |||
| lastPageBtn = new JButton(Res.string().getLastPage()); | |||
| JLabel numLabel = new JLabel(Res.string().getPagesNumber(), JLabel.CENTER); | |||
| numTextField = new JTextField(); | |||
| numTextField.setHorizontalAlignment(JTextField.CENTER); | |||
| numTextField.setPreferredSize(new Dimension(80, 20)); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.height = 25; | |||
| panel.setPreferredSize(dimension); | |||
| numLabel.setPreferredSize(new Dimension(80, 20)); | |||
| numTextField.setPreferredSize(new Dimension(120, 20)); | |||
| previousPageBtn.setPreferredSize(new Dimension(120, 20)); | |||
| lastPageBtn.setPreferredSize(new Dimension(120, 20)); | |||
| panel.setLayout(new FlowLayout()); | |||
| panel.add(previousPageBtn); | |||
| panel.add(numLabel); | |||
| panel.add(numTextField); | |||
| panel.add(lastPageBtn); | |||
| previousPageBtn.setEnabled(false); | |||
| lastPageBtn.setEnabled(false); | |||
| numTextField.setEnabled(false); | |||
| add(new JScrollPane(table), BorderLayout.CENTER); | |||
| add(panel, BorderLayout.SOUTH); | |||
| // 前一页 | |||
| previousPageBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| previousPageBtn.setEnabled(false); | |||
| } | |||
| }); | |||
| new SwingWorker<CANDIDATE_INFOEX[], String>() { | |||
| @Override | |||
| protected CANDIDATE_INFOEX[] doInBackground() { | |||
| nBeginNum -= 17; | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = FaceRecognitionModule.doFindPerson(nBeginNum, 17); | |||
| return stuCandidatesEx; | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| try { | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = get(); | |||
| findPreviousPage(stuCandidatesEx); | |||
| } catch (InterruptedException e) { | |||
| e.printStackTrace(); | |||
| } catch (ExecutionException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| }.execute(); | |||
| } | |||
| }); | |||
| // 下一页 | |||
| lastPageBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| lastPageBtn.setEnabled(false); | |||
| } | |||
| }); | |||
| new SwingWorker<CANDIDATE_INFOEX[], String>() { | |||
| @Override | |||
| protected CANDIDATE_INFOEX[] doInBackground() { | |||
| nBeginNum += 17; | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = FaceRecognitionModule.doFindPerson(nBeginNum, 17); | |||
| return stuCandidatesEx; | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| try { | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = get(); | |||
| findLastPage(stuCandidatesEx); | |||
| } catch (InterruptedException e) { | |||
| e.printStackTrace(); | |||
| } catch (ExecutionException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| }.execute(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /* | |||
| * 查找前17个 | |||
| */ | |||
| public void findPersonInfo(CANDIDATE_INFOEX[] stuCandidatesEx) { | |||
| if(stuCandidatesEx != null) { | |||
| searchPersonBtn.setEnabled(true); | |||
| previousPageBtn.setEnabled(false); | |||
| nPagesNumber = 1; | |||
| numTextField.setText(String.valueOf(nPagesNumber)); | |||
| for(int i = 0; i < stuCandidatesEx.length; i++) { | |||
| if(!cadidateHashMap.containsKey(new String(stuCandidatesEx[i].stPersonInfo.szUID).trim())) { | |||
| cadidateHashMap.put(new String(stuCandidatesEx[i].stPersonInfo.szUID).trim(), stuCandidatesEx[i]); | |||
| } | |||
| // UID | |||
| defaultTableModel.setValueAt(new String(stuCandidatesEx[i].stPersonInfo.szUID).trim(), i, 0); | |||
| // 姓名 | |||
| try { | |||
| defaultTableModel.setValueAt(new String(stuCandidatesEx[i].stPersonInfo.szPersonName, "GBK").trim(), i, 1); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 性别 | |||
| defaultTableModel.setValueAt(Res.string().getSex(stuCandidatesEx[i].stPersonInfo.bySex & 0xff), i, 2); | |||
| // 生日 | |||
| defaultTableModel.setValueAt(String.valueOf((int)stuCandidatesEx[i].stPersonInfo.wYear) + "-" + | |||
| String.valueOf( stuCandidatesEx[i].stPersonInfo.byMonth & 0xff) + "-" + | |||
| String.valueOf(stuCandidatesEx[i].stPersonInfo.byDay & 0xff), i, 3); | |||
| // 证件类型 | |||
| defaultTableModel.setValueAt(Res.string().getIdType(stuCandidatesEx[i].stPersonInfo.byIDType & 0xff), i, 4); | |||
| // 证件号 | |||
| try { | |||
| defaultTableModel.setValueAt(new String(stuCandidatesEx[i].stPersonInfo.szID, "GBK").trim(), i, 5); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| if(nTotalCount > nBeginNum + stuCandidatesEx.length) { | |||
| lastPageBtn.setEnabled(true); | |||
| } | |||
| } else { | |||
| searchPersonBtn.setEnabled(true); | |||
| previousPageBtn.setEnabled(false); | |||
| lastPageBtn.setEnabled(false); | |||
| numTextField.setText(""); | |||
| } | |||
| } | |||
| /* | |||
| * 上一页查找 | |||
| */ | |||
| private void findPreviousPage(CANDIDATE_INFOEX[] stuCandidatesEx) { | |||
| if(stuCandidatesEx != null) { | |||
| nPagesNumber -= 1; | |||
| numTextField.setText(String.valueOf(nPagesNumber)); | |||
| cadidateHashMap.clear(); | |||
| cleanList(); | |||
| lastPageBtn.setEnabled(true); | |||
| for(int i = 0; i < stuCandidatesEx.length; i++) { | |||
| if(!cadidateHashMap.containsKey(new String(stuCandidatesEx[i].stPersonInfo.szUID).trim())) { | |||
| cadidateHashMap.put(new String(stuCandidatesEx[i].stPersonInfo.szUID).trim(), stuCandidatesEx[i]); | |||
| } | |||
| // UID | |||
| defaultTableModel.setValueAt(new String(stuCandidatesEx[i].stPersonInfo.szUID).trim(), i, 0); | |||
| // 姓名 | |||
| try { | |||
| defaultTableModel.setValueAt(new String(stuCandidatesEx[i].stPersonInfo.szPersonName, "GBK").trim(), i, 1); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 性别 | |||
| defaultTableModel.setValueAt(Res.string().getSex(stuCandidatesEx[i].stPersonInfo.bySex & 0xff), i, 2); | |||
| // 生日 | |||
| defaultTableModel.setValueAt(String.valueOf((int)stuCandidatesEx[i].stPersonInfo.wYear) + "-" + | |||
| String.valueOf( stuCandidatesEx[i].stPersonInfo.byMonth & 0xff) + "-" + | |||
| String.valueOf(stuCandidatesEx[i].stPersonInfo.byDay & 0xff), i, 3); | |||
| // 证件类型 | |||
| defaultTableModel.setValueAt(Res.string().getIdType(stuCandidatesEx[i].stPersonInfo.byIDType & 0xff), i, 4); | |||
| // 证件号 | |||
| try { | |||
| defaultTableModel.setValueAt(new String(stuCandidatesEx[i].stPersonInfo.szID, "GBK").trim(), i, 5); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| if(nBeginNum >= 17) { | |||
| previousPageBtn.setEnabled(true); | |||
| } else { | |||
| previousPageBtn.setEnabled(false); | |||
| } | |||
| } else{ | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| previousPageBtn.setEnabled(true); | |||
| nBeginNum += 17; | |||
| } | |||
| } | |||
| /* | |||
| * 下一页查找 | |||
| */ | |||
| private void findLastPage(CANDIDATE_INFOEX[] stuCandidatesEx) { | |||
| if(stuCandidatesEx != null) { | |||
| nPagesNumber += 1; | |||
| numTextField.setText(String.valueOf(nPagesNumber)); | |||
| cadidateHashMap.clear(); | |||
| cleanList(); | |||
| previousPageBtn.setEnabled(true); | |||
| for(int i = 0; i < stuCandidatesEx.length; i++) { | |||
| if(!cadidateHashMap.containsKey(new String(stuCandidatesEx[i].stPersonInfo.szUID).trim())) { | |||
| cadidateHashMap.put(new String(stuCandidatesEx[i].stPersonInfo.szUID).trim(), stuCandidatesEx[i]); | |||
| } | |||
| // UID | |||
| defaultTableModel.setValueAt(new String(stuCandidatesEx[i].stPersonInfo.szUID).trim(), i, 0); | |||
| // 姓名 | |||
| try { | |||
| defaultTableModel.setValueAt(new String(stuCandidatesEx[i].stPersonInfo.szPersonName, "GBK").trim(), i, 1); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 性别 | |||
| defaultTableModel.setValueAt(Res.string().getSex(stuCandidatesEx[i].stPersonInfo.bySex & 0xff), i, 2); | |||
| // 生日 | |||
| defaultTableModel.setValueAt(String.valueOf((int)stuCandidatesEx[i].stPersonInfo.wYear) + "-" + | |||
| String.valueOf( stuCandidatesEx[i].stPersonInfo.byMonth & 0xff) + "-" + | |||
| String.valueOf(stuCandidatesEx[i].stPersonInfo.byDay & 0xff), i, 3); | |||
| // 证件类型 | |||
| defaultTableModel.setValueAt(Res.string().getIdType(stuCandidatesEx[i].stPersonInfo.byIDType & 0xff), i, 4); | |||
| // 证件号 | |||
| try { | |||
| defaultTableModel.setValueAt(new String(stuCandidatesEx[i].stPersonInfo.szID, "GBK").trim(), i, 5); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| if(nTotalCount > nBeginNum + stuCandidatesEx.length) { | |||
| lastPageBtn.setEnabled(true); | |||
| } else { | |||
| lastPageBtn.setEnabled(false); | |||
| } | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| lastPageBtn.setEnabled(true); | |||
| nBeginNum -= 17; | |||
| } | |||
| } | |||
| /* | |||
| * 清空列表 | |||
| */ | |||
| private void cleanList() { | |||
| for(int i = 0; i < 17; i++) { | |||
| for(int j = 0; j < 6; j++) { | |||
| defaultTableModel.setValueAt("", i, j); | |||
| } | |||
| } | |||
| } | |||
| private Object[][] data; | |||
| private DefaultTableModel defaultTableModel; | |||
| private JTable table; | |||
| private JButton previousPageBtn; | |||
| private JButton lastPageBtn; | |||
| private JTextField goroupIdTextField; | |||
| private JTextField goroupNameTextField; | |||
| private JTextField nameTextField; | |||
| private JComboBox sexComboBox; | |||
| private JComboBox idTypeComboBox; | |||
| private JTextField idTextField; | |||
| private JCheckBox startBirthdayCheckBox; | |||
| private JCheckBox endBirthdayCheckBox; | |||
| private DateChooserJButtonEx startTimeBtn; | |||
| private DateChooserJButtonEx endTimeBtn; | |||
| private JTextField numTextField; | |||
| private JButton searchPersonBtn; | |||
| } | |||
| @@ -0,0 +1,596 @@ | |||
| package com.netsdk.demo.frame.FaceRecognition; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.EventQueue; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.IOException; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.Vector; | |||
| import java.util.concurrent.ExecutionException; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JCheckBox; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JProgressBar; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JTextArea; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.SwingWorker; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.DateChooserJButtonEx; | |||
| import com.netsdk.common.PaintPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.demo.module.SearchByPictureModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| public class SearchByPicDialog extends JDialog { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private Vector<String> chnList = new Vector<String>(); | |||
| private Memory memory = null; | |||
| private static volatile int nProgress = 0; // 设备处理进度 | |||
| private static volatile int nCount = 0; | |||
| public SearchByPicDialog() { | |||
| setTitle(Res.string().getSearchByPic()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(780, 550); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| JPanel panel = new JPanel(); | |||
| progressBar = new JProgressBar(0, 100); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.height = 18; | |||
| progressBar.setPreferredSize(dimension); | |||
| progressBar.setStringPainted(true); | |||
| add(panel, BorderLayout.CENTER); | |||
| add(progressBar, BorderLayout.SOUTH); | |||
| //////// | |||
| panel.setLayout(new BorderLayout()); | |||
| SearchPicConditionPanel searchPicConditionPanel = new SearchPicConditionPanel(); | |||
| searchPicInfoTextArea = new JTextArea(); | |||
| Dimension dimension1 = new Dimension(); | |||
| dimension1.width = 220; | |||
| searchPicConditionPanel.setPreferredSize(dimension1); | |||
| panel.add(searchPicConditionPanel, BorderLayout.WEST); | |||
| panel.add(new JScrollPane(searchPicInfoTextArea), BorderLayout.CENTER); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| private class SearchPicConditionPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public SearchPicConditionPanel() { | |||
| setLayout(new BorderLayout()); | |||
| JPanel panelNorth = new JPanel(); | |||
| JPanel panelSouth = new JPanel(); | |||
| add(panelNorth, BorderLayout.NORTH); | |||
| add(panelSouth, BorderLayout.SOUTH); | |||
| //////// | |||
| searchPicPanel = new PaintPanel(); | |||
| JButton selectPicBtn = new JButton(Res.string().getSelectPicture()); | |||
| JButton downloadBtn = new JButton(Res.string().getDownloadQueryPicture()); | |||
| searchPicPanel.setPreferredSize(new Dimension(210, 270)); | |||
| selectPicBtn.setPreferredSize(new Dimension(210, 20)); | |||
| downloadBtn.setPreferredSize(new Dimension(210, 20)); | |||
| panelNorth.setLayout(new FlowLayout()); | |||
| panelNorth.setPreferredSize(new Dimension(210, 330)); | |||
| panelNorth.add(searchPicPanel); | |||
| panelNorth.add(selectPicBtn); | |||
| panelNorth.add(downloadBtn); | |||
| ///// | |||
| faceCheckBox = new JCheckBox(Res.string().getFaceLibrary()); | |||
| historyCheckBox = new JCheckBox(Res.string().getHistoryLibrary()); | |||
| faceCheckBox.setPreferredSize(new Dimension(100, 20)); | |||
| historyCheckBox.setPreferredSize(new Dimension(100, 20)); | |||
| startTimeLabel = new JLabel(Res.string().getStartTime(), JLabel.CENTER); | |||
| endTimeLabel = new JLabel(Res.string().getEndTime(), JLabel.CENTER); | |||
| chnLabel = new JLabel(Res.string().getChannel(), JLabel.CENTER); | |||
| JLabel similaryLabel = new JLabel(Res.string().getSimilarity(), JLabel.CENTER); | |||
| Dimension dimension1 = new Dimension(); | |||
| dimension1.width = 80; | |||
| dimension1.height = 20; | |||
| startTimeLabel.setPreferredSize(dimension1); | |||
| endTimeLabel.setPreferredSize(dimension1); | |||
| chnLabel.setPreferredSize(dimension1); | |||
| similaryLabel.setPreferredSize(dimension1); | |||
| startTimeBtn = new DateChooserJButtonEx("2018-11-07"); | |||
| endTimeBtn = new DateChooserJButtonEx(); | |||
| chnComboBox = new JComboBox(); | |||
| for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) { | |||
| chnList.add(Res.string().getChannel() + " " + String.valueOf(i)); | |||
| } | |||
| // 登陆成功,将通道添加到控件 | |||
| chnComboBox.setModel(new DefaultComboBoxModel(chnList)); | |||
| similaryTextField = new JTextField("60", JTextField.CENTER); | |||
| Dimension dimension2 = new Dimension(); | |||
| dimension2.width = 120; | |||
| dimension2.height = 20; | |||
| startTimeBtn.setPreferredSize(dimension2); | |||
| endTimeBtn.setPreferredSize(dimension2); | |||
| chnComboBox.setPreferredSize(dimension2); | |||
| similaryTextField.setPreferredSize(dimension2); | |||
| searchPicBtn = new JButton(Res.string().getSearch()); | |||
| searchPicBtn.setPreferredSize(new Dimension(210, 20)); | |||
| panelSouth.setLayout(new FlowLayout()); | |||
| panelSouth.setPreferredSize(new Dimension(210, 160)); | |||
| panelSouth.add(faceCheckBox); | |||
| panelSouth.add(historyCheckBox); | |||
| panelSouth.add(startTimeLabel); | |||
| panelSouth.add(startTimeBtn); | |||
| panelSouth.add(endTimeLabel); | |||
| panelSouth.add(endTimeBtn); | |||
| panelSouth.add(chnLabel); | |||
| panelSouth.add(chnComboBox); | |||
| panelSouth.add(similaryLabel); | |||
| panelSouth.add(similaryTextField); | |||
| panelSouth.add(searchPicBtn); | |||
| historyCheckBox.setSelected(true); | |||
| faceCheckBox.setSelected(false); | |||
| // 选择图片,获取图片的信息 | |||
| selectPicBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| String picPath = ""; | |||
| // 选择图片,获取图片路径,并在界面显示 | |||
| picPath = ToolKits.openPictureFile(searchPicPanel); | |||
| if(!picPath.equals("")) { | |||
| try { | |||
| memory = ToolKits.readPictureFile(picPath); | |||
| } catch (IOException e) { | |||
| // TODO Auto-generated catch block | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| downloadBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| DownloadPictureDialog dialog = new DownloadPictureDialog(); | |||
| dialog.setVisible(true); | |||
| } | |||
| }); | |||
| searchPicBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| searchPicBtn.setEnabled(false); | |||
| progressBar.setValue(0); | |||
| searchPicInfoTextArea.setText(""); | |||
| } | |||
| }); | |||
| searchByPicture(); | |||
| } | |||
| }); | |||
| faceCheckBox.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| if(faceCheckBox.isSelected()) { | |||
| historyCheckBox.setSelected(false); | |||
| chnLabel.setVisible(false); | |||
| chnComboBox.setVisible(false); | |||
| startTimeLabel.setVisible(false); | |||
| endTimeLabel.setVisible(false); | |||
| startTimeBtn.setVisible(false); | |||
| endTimeBtn.setVisible(false); | |||
| } else { | |||
| historyCheckBox.setSelected(true); | |||
| chnLabel.setVisible(true); | |||
| chnComboBox.setVisible(true); | |||
| startTimeLabel.setVisible(true); | |||
| endTimeLabel.setVisible(true); | |||
| startTimeBtn.setVisible(true); | |||
| endTimeBtn.setVisible(true); | |||
| } | |||
| } | |||
| }); | |||
| historyCheckBox.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| if(historyCheckBox.isSelected()) { | |||
| faceCheckBox.setSelected(false); | |||
| chnLabel.setVisible(true); | |||
| chnComboBox.setVisible(true); | |||
| startTimeLabel.setVisible(true); | |||
| endTimeLabel.setVisible(true); | |||
| startTimeBtn.setVisible(true); | |||
| endTimeBtn.setVisible(true); | |||
| } else { | |||
| faceCheckBox.setSelected(true); | |||
| chnLabel.setVisible(false); | |||
| chnComboBox.setVisible(false); | |||
| startTimeLabel.setVisible(false); | |||
| endTimeLabel.setVisible(false); | |||
| startTimeBtn.setVisible(false); | |||
| endTimeBtn.setVisible(false); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| private void searchByPicture() { | |||
| new SwingWorker<Boolean, StringBuffer>() { | |||
| int nTotalCount = 0; // 查询到的总个数 | |||
| @Override | |||
| protected Boolean doInBackground() { | |||
| int beginNum = 0; // 偏移量 | |||
| int nCount = 0; // 循环查询了几次 | |||
| int index = 0; // index + 1 为查询到的总个数 | |||
| int nFindCount = 10; // 每次查询的个数 | |||
| StringBuffer message = null; | |||
| if(memory == null) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getChooseFacePic(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| // 获取查询句柄 | |||
| nTotalCount = SearchByPictureModule.startFindPerson(memory, | |||
| startTimeBtn.getText(), | |||
| endTimeBtn.getText(), | |||
| historyCheckBox.isSelected(), | |||
| chnComboBox.getSelectedIndex(), | |||
| similaryTextField.getText()); | |||
| if(nTotalCount == 0) { // 查询失败 | |||
| // 查询失败,关闭查询 | |||
| SearchByPictureModule.doFindClosePerson(); | |||
| return false; | |||
| } else if(nTotalCount == -1) { // 设备正在处理,通过订阅来查询处理进度 | |||
| nProgress = 0; | |||
| nCount = 0; | |||
| SearchByPictureModule.attachFaceFindState(fFaceFindStateCb.getInstance()); | |||
| } else { | |||
| while(true) { | |||
| CANDIDATE_INFOEX[] caInfoexs = SearchByPictureModule.doFindNextPerson(beginNum, nFindCount); | |||
| if(caInfoexs == null) { | |||
| break; | |||
| } | |||
| for(int i = 0; i < caInfoexs.length; i++) { | |||
| index = i + nFindCount * nCount + 1; | |||
| // 清空 | |||
| message = new StringBuffer(); | |||
| if(historyCheckBox.isSelected()) { // 历史库显示 | |||
| message.append("[" + index + "]"+Res.string().getTime()+":" + caInfoexs[i].stTime.toStringTimeEx() + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getUid()+":" + new String(caInfoexs[i].stPersonInfo.szUID).trim() + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getSex()+":" + Res.string().getSex(caInfoexs[i].stPersonInfo.bySex) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getAge()+":" + caInfoexs[i].stPersonInfo.byAge + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getColor()+":" + Res.string().getColor(0) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getEye()+":" + Res.string().getEyeState(caInfoexs[i].stPersonInfo.emEye) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getMouth()+":" + Res.string().getMouthState(caInfoexs[i].stPersonInfo.emMouth) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getMask()+":" + Res.string().getMaskState(caInfoexs[i].stPersonInfo.emMask) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getBeard()+":" + Res.string().getBeardState(caInfoexs[i].stPersonInfo.emBeard) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getGlasses()+":" + Res.string().getGlasses(caInfoexs[i].stPersonInfo.byGlasses) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getSimilarity()+":" + caInfoexs[i].bySimilarity + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getPicturePath()+":" + caInfoexs[i].stPersonInfo.szFacePicInfo[0].pszFilePath.getString(0) + "\n"); | |||
| } else { // 人脸库显示 | |||
| message.append("[" + index + "]"+Res.string().getFaceLibraryID()+":" + new String(caInfoexs[i].stPersonInfo.szGroupID).trim() + "\n"); | |||
| try { | |||
| message.append("[" + index + "]"+Res.string().getFaceLibraryName()+":" + new String(caInfoexs[i].stPersonInfo.szGroupName, "GBK").trim() + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getName()+":" + new String(caInfoexs[i].stPersonInfo.szPersonName, "GBK").trim() + "\n"); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| message.append("[" + index + "]"+Res.string().getUid()+":" + new String(caInfoexs[i].stPersonInfo.szUID).trim() + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getBirthday()+":" + (caInfoexs[i].stPersonInfo.wYear) + "-" + | |||
| (0xff & caInfoexs[i].stPersonInfo.byMonth) + "-" + | |||
| (0xff & caInfoexs[i].stPersonInfo.byDay) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getSex()+":" + Res.string().getSex(caInfoexs[i].stPersonInfo.bySex) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getCardType()+":" + Res.string().getIdType(caInfoexs[i].stPersonInfo.byIDType) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getCardNum()+":" + new String(caInfoexs[i].stPersonInfo.szID).trim() + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getSimilarity()+":" + caInfoexs[i].bySimilarity + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getPicturePath()+":" + caInfoexs[i].stPersonInfo.szFacePicInfo[0].pszFilePath.getString(0) + "\n"); | |||
| } | |||
| message.append("\n"); | |||
| publish(message); | |||
| } | |||
| if(caInfoexs.length < nFindCount) { | |||
| System.out.printf("No More Record, Find End!\n"); | |||
| break; | |||
| } else { | |||
| beginNum += nFindCount; | |||
| nCount++; | |||
| } | |||
| } | |||
| // 关闭查询 | |||
| SearchByPictureModule.doFindClosePerson(); | |||
| } | |||
| return true; | |||
| } | |||
| @Override | |||
| protected void process(java.util.List<StringBuffer> chunks) { | |||
| for(StringBuffer data : chunks) { | |||
| searchPicInfoTextArea.append(data.toString()); | |||
| searchPicInfoTextArea.updateUI(); | |||
| } | |||
| super.process(chunks); | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| if(nTotalCount == 0) { // 查询总个数失败 | |||
| searchPicBtn.setEnabled(true); | |||
| progressBar.setValue(100); | |||
| searchPicInfoTextArea.append("未查询到相关信息... \n"); | |||
| searchPicInfoTextArea.updateUI(); | |||
| } else if(nTotalCount == -1){ // 设备在处理中 | |||
| searchPicInfoTextArea.append(Res.string().getLoading()+"... \n"); | |||
| searchPicInfoTextArea.updateUI(); | |||
| } else { | |||
| try { | |||
| if(get()) { // 其他情况,查询信息结束 | |||
| searchPicBtn.setEnabled(true); | |||
| progressBar.setValue(100); | |||
| searchPicInfoTextArea.append("查询结束... \n"); | |||
| searchPicInfoTextArea.updateUI(); | |||
| } | |||
| } catch (InterruptedException e) { | |||
| e.printStackTrace(); | |||
| } catch (ExecutionException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| }.execute(); | |||
| } | |||
| /** | |||
| * 订阅人脸回调函数 | |||
| */ | |||
| private static class fFaceFindStateCb implements NetSDKLib.fFaceFindState { | |||
| private fFaceFindStateCb() {} | |||
| private static class fFaceFindStateCbHolder { | |||
| private static final fFaceFindStateCb instance = new fFaceFindStateCb(); | |||
| } | |||
| public static fFaceFindStateCb getInstance() { | |||
| return fFaceFindStateCbHolder.instance; | |||
| } | |||
| @Override | |||
| public void invoke(LLong lLoginID, LLong lAttachHandle, | |||
| Pointer pstStates, int nStateNum, Pointer dwUser) { | |||
| if(nStateNum < 1) { | |||
| return; | |||
| } | |||
| NET_CB_FACE_FIND_STATE[] msg = new NET_CB_FACE_FIND_STATE[nStateNum]; | |||
| for(int i = 0; i < nStateNum; i++) { | |||
| msg[i] = new NET_CB_FACE_FIND_STATE(); | |||
| } | |||
| ToolKits.GetPointerDataToStructArr(pstStates, msg); | |||
| for(int i = 0; i < nStateNum; i++) { | |||
| if(SearchByPictureModule.nToken == msg[i].nToken) { | |||
| nProgress = msg[i].nProgress; | |||
| nCount = msg[i].nCurrentCount; // 返回的总个数 | |||
| // 刷新设备处理进度 | |||
| // UI线程 | |||
| EventQueue.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| progressBar.setValue(nProgress); | |||
| if(nProgress == 100) { // 进度等于100,设备处理完毕,开始查询 | |||
| // 异步线程处理 | |||
| new SearchPictureWoker(nCount).execute(); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 用于订阅人脸状态后的查询 | |||
| * 以图搜图与查询人员信息的接口是一样的,只是逻辑不一样,doFindNextPerson接口时,都是指定每次查询的个数,最大20,然后根据偏移量循环查询 | |||
| * SwingWorker为异步线程,回调属于子线程,不能做耗时操作和刷新UI | |||
| */ | |||
| private static class SearchPictureWoker extends SwingWorker<Boolean, StringBuffer> { | |||
| private int nTotalCount; // 查询到的总个数 | |||
| public SearchPictureWoker(int nTotalCount) { | |||
| this.nTotalCount = nTotalCount; | |||
| } | |||
| @Override | |||
| protected Boolean doInBackground() { | |||
| int beginNum = 0; // 偏移量 | |||
| int nCount = 0; // 循环查询了几次 | |||
| int index = 0; // index + 1 为查询到的总个数 | |||
| int nFindCount = 10; // 每次查询的个数 | |||
| StringBuffer message = null; | |||
| // 进度达到100%,关闭订阅 | |||
| SearchByPictureModule.detachFaceFindState(); | |||
| System.out.println("nTotalCount = " + nTotalCount); | |||
| if(nTotalCount == 0) { | |||
| // 关闭查询 | |||
| SearchByPictureModule.doFindClosePerson(); | |||
| return false; | |||
| } | |||
| while(true) { | |||
| CANDIDATE_INFOEX[] caInfoexs = SearchByPictureModule.doFindNextPerson(beginNum, nFindCount); | |||
| if(caInfoexs == null) { | |||
| break; | |||
| } | |||
| for(int i = 0; i < caInfoexs.length; i++) { | |||
| index = i + nFindCount * nCount + 1; | |||
| // 清空 | |||
| message = new StringBuffer(); | |||
| if(historyCheckBox.isSelected()) { // 历史库显示 | |||
| message.append("[" + index + "]"+Res.string().getTime()+":" + caInfoexs[i].stTime.toStringTimeEx() + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getUid()+":" + new String(caInfoexs[i].stPersonInfo.szUID).trim() + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getSex()+":" + Res.string().getSex(caInfoexs[i].stPersonInfo.bySex) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getAge()+":" + caInfoexs[i].stPersonInfo.byAge + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getColor()+":" + Res.string().getColor(0) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getEye()+":" + Res.string().getEyeState(caInfoexs[i].stPersonInfo.emEye) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getMouth()+":" + Res.string().getMouthState(caInfoexs[i].stPersonInfo.emMouth) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getMask()+":" + Res.string().getMaskState(caInfoexs[i].stPersonInfo.emMask) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getBeard()+":" + Res.string().getBeardState(caInfoexs[i].stPersonInfo.emBeard) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getGlasses()+":" + Res.string().getGlasses(caInfoexs[i].stPersonInfo.byGlasses) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getSimilarity()+":" + caInfoexs[i].bySimilarity + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getPicturePath()+":" + caInfoexs[i].stPersonInfo.szFacePicInfo[0].pszFilePath.getString(0) + "\n"); | |||
| } else { // 人脸库显示 | |||
| message.append("[" + index + "]"+Res.string().getFaceLibraryID()+":" + new String(caInfoexs[i].stPersonInfo.szGroupID).trim() + "\n"); | |||
| try { | |||
| message.append("[" + index + "]"+Res.string().getFaceLibraryName()+":" + new String(caInfoexs[i].stPersonInfo.szGroupName, "GBK").trim() + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getName()+":" + new String(caInfoexs[i].stPersonInfo.szPersonName, "GBK").trim() + "\n"); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| message.append("[" + index + "]"+Res.string().getUid()+":" + new String(caInfoexs[i].stPersonInfo.szUID).trim() + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getBirthday()+":" + (caInfoexs[i].stPersonInfo.wYear) + "-" + | |||
| (0xff & caInfoexs[i].stPersonInfo.byMonth) + "-" + | |||
| (0xff & caInfoexs[i].stPersonInfo.byDay) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getSex()+":" + Res.string().getSex(caInfoexs[i].stPersonInfo.bySex) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getCardType()+":" + Res.string().getIdType(caInfoexs[i].stPersonInfo.byIDType) + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getCardNum()+":" + new String(caInfoexs[i].stPersonInfo.szID).trim() + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getSimilarity()+":" + caInfoexs[i].bySimilarity + "\n"); | |||
| message.append("[" + index + "]"+Res.string().getPicturePath()+":" + caInfoexs[i].stPersonInfo.szFacePicInfo[0].pszFilePath.getString(0) + "\n"); | |||
| } | |||
| message.append("\n"); | |||
| publish(message); | |||
| } | |||
| if(caInfoexs.length < nFindCount) { | |||
| System.out.printf("No More Record, Find End!\n"); | |||
| break; | |||
| } else { | |||
| beginNum += nFindCount; | |||
| nCount++; | |||
| } | |||
| } | |||
| // 关闭查询 | |||
| SearchByPictureModule.doFindClosePerson(); | |||
| return true; | |||
| } | |||
| @Override | |||
| protected void process(java.util.List<StringBuffer> chunks) { | |||
| for(StringBuffer data : chunks) { | |||
| searchPicInfoTextArea.append(data.toString()); | |||
| searchPicInfoTextArea.updateUI(); | |||
| } | |||
| super.process(chunks); | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| searchPicBtn.setEnabled(true); | |||
| searchPicInfoTextArea.append(Res.string().getEndSearch()+"... \n"); | |||
| searchPicInfoTextArea.updateUI(); | |||
| } | |||
| } | |||
| private static JTextArea searchPicInfoTextArea; | |||
| private static JProgressBar progressBar; | |||
| private static JButton searchPicBtn; | |||
| private PaintPanel searchPicPanel; | |||
| private JComboBox chnComboBox; | |||
| private JTextField similaryTextField; | |||
| private DateChooserJButtonEx startTimeBtn; | |||
| private DateChooserJButtonEx endTimeBtn; | |||
| private JLabel chnLabel; | |||
| private JLabel startTimeLabel; | |||
| private JLabel endTimeLabel; | |||
| private JCheckBox faceCheckBox; | |||
| private static JCheckBox historyCheckBox; | |||
| } | |||
| @@ -0,0 +1,332 @@ | |||
| package com.netsdk.demo.frame.Gate; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.IOException; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JCheckBox; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JPasswordField; | |||
| import javax.swing.JTextField; | |||
| import com.sun.jna.Memory; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.DateChooserJButton; | |||
| import com.netsdk.common.PaintPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.GateModule; | |||
| import com.netsdk.lib.ToolKits; | |||
| public class AddCardDialog extends JDialog{ | |||
| private static final long serialVersionUID = 1L; | |||
| private Memory memory = null; | |||
| private String picPath = ""; | |||
| public AddCardDialog(){ | |||
| setTitle(Res.string().getAdd() + Res.string().getCardInfo()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(520, 390); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| CardInfoPanel cardInfoPanel = new CardInfoPanel(); | |||
| ImagePanel imagePanel = new ImagePanel(); | |||
| add(cardInfoPanel, BorderLayout.CENTER); | |||
| add(imagePanel, BorderLayout.EAST); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e){ | |||
| clear(); | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| /** | |||
| * 卡信息 | |||
| */ | |||
| private class CardInfoPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public CardInfoPanel() { | |||
| BorderEx.set(this, Res.string().getCardInfo(), 4); | |||
| setLayout(new FlowLayout()); | |||
| JLabel cardNoLabel = new JLabel(Res.string().getCardNo() + ":", JLabel.CENTER); | |||
| JLabel userIdLabel = new JLabel(Res.string().getUserId() + ":", JLabel.CENTER); | |||
| JLabel cardNameLabel = new JLabel(Res.string().getCardName() + ":", JLabel.CENTER); | |||
| JLabel cardPasswdLabel = new JLabel(Res.string().getCardPassword() + ":", JLabel.CENTER); | |||
| JLabel cardStatusLabel = new JLabel(Res.string().getCardStatus() + ":", JLabel.CENTER); | |||
| JLabel cardTypeLabel = new JLabel(Res.string().getCardType() + ":", JLabel.CENTER); | |||
| JLabel useTimesLabel = new JLabel(Res.string().getUseTimes() + ":", JLabel.CENTER); | |||
| JLabel validPeriodLabel = new JLabel(Res.string().getValidPeriod() + ":", JLabel.CENTER); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.width = 85; | |||
| dimension.height = 20; | |||
| cardNoLabel.setPreferredSize(dimension); | |||
| userIdLabel.setPreferredSize(dimension); | |||
| cardNameLabel.setPreferredSize(dimension); | |||
| cardPasswdLabel.setPreferredSize(dimension); | |||
| cardStatusLabel.setPreferredSize(dimension); | |||
| cardTypeLabel.setPreferredSize(dimension); | |||
| useTimesLabel.setPreferredSize(dimension); | |||
| validPeriodLabel.setPreferredSize(dimension); | |||
| cardNoTextField = new JTextField(); | |||
| userIdTextField = new JTextField(); | |||
| cardNameTextField = new JTextField(); | |||
| cardPasswdField = new JPasswordField(); | |||
| cardStatusComboBox = new JComboBox(Res.string().getCardStatusList()); | |||
| cardTypeComboBox = new JComboBox(Res.string().getCardTypeList()); | |||
| useTimesTextField = new JTextField("0"); | |||
| firstEnterCheckBox = new JCheckBox(Res.string().getIsFirstEnter()); | |||
| enableCheckBox = new JCheckBox(Res.string().getEnable()); | |||
| enableCheckBox.setSelected(true); | |||
| enableCheckBox.setVisible(false); | |||
| startTimeBtn = new DateChooserJButton(); | |||
| endTimeBtn = new DateChooserJButton(); | |||
| cardNoTextField.setPreferredSize(new Dimension(145, 20)); | |||
| userIdTextField.setPreferredSize(new Dimension(145, 20)); | |||
| cardNameTextField.setPreferredSize(new Dimension(145, 20)); | |||
| cardPasswdField.setPreferredSize(new Dimension(145, 20)); | |||
| useTimesTextField.setPreferredSize(new Dimension(145, 20)); | |||
| cardStatusComboBox.setPreferredSize(new Dimension(145, 20)); | |||
| cardTypeComboBox.setPreferredSize(new Dimension(145, 20)); | |||
| startTimeBtn.setPreferredSize(new Dimension(145, 20)); | |||
| endTimeBtn.setPreferredSize(new Dimension(145, 20)); | |||
| firstEnterCheckBox.setPreferredSize(new Dimension(170, 20)); | |||
| enableCheckBox.setPreferredSize(new Dimension(70, 20)); | |||
| JLabel nullLabel1 = new JLabel(); | |||
| JLabel nullLabel2 = new JLabel(); | |||
| JLabel nullLabel3 = new JLabel(); | |||
| nullLabel1.setPreferredSize(new Dimension(5, 20)); | |||
| nullLabel2.setPreferredSize(new Dimension(30, 20)); | |||
| nullLabel3.setPreferredSize(new Dimension(85, 20)); | |||
| addBtn = new JButton(Res.string().getAdd()); | |||
| cancelBtn = new JButton(Res.string().getCancel()); | |||
| JLabel nullLabel4 = new JLabel(); | |||
| nullLabel4.setPreferredSize(new Dimension(250, 20)); | |||
| addBtn.setPreferredSize(new Dimension(110, 20)); | |||
| cancelBtn.setPreferredSize(new Dimension(110, 20)); | |||
| add(cardNoLabel); | |||
| add(cardNoTextField); | |||
| add(userIdLabel); | |||
| add(userIdTextField); | |||
| add(cardNameLabel); | |||
| add(cardNameTextField); | |||
| add(cardPasswdLabel); | |||
| add(cardPasswdField); | |||
| add(cardStatusLabel); | |||
| add(cardStatusComboBox); | |||
| add(cardTypeLabel); | |||
| add(cardTypeComboBox); | |||
| add(useTimesLabel); | |||
| add(useTimesTextField); | |||
| add(nullLabel1); | |||
| add(firstEnterCheckBox); | |||
| add(nullLabel2); | |||
| add(enableCheckBox); | |||
| add(validPeriodLabel); | |||
| add(startTimeBtn); | |||
| add(nullLabel3); | |||
| add(endTimeBtn); | |||
| add(nullLabel4); | |||
| add(addBtn); | |||
| add(cancelBtn); | |||
| // 添加 | |||
| addBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| // if(cardNoTextField.getText().isEmpty()) { | |||
| // JOptionPane.showMessageDialog(null, Res.string().getInputCardNo(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| // return; | |||
| // } | |||
| if(userIdTextField.getText().isEmpty()) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInputUserId(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(memory == null) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectPicture(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| try { | |||
| if (cardNoTextField.getText().getBytes("UTF-8").length > 31) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCardNoExceedLength() + "(31)", Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if (userIdTextField.getText().getBytes("UTF-8").length > 31) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getUserIdExceedLength() + "(31)", Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if (cardNameTextField.getText().getBytes("UTF-8").length > 63) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCardNameExceedLength() + "(63)", Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if (new String(cardPasswdField.getPassword()).getBytes("UTF-8").length > 63) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCardPasswdExceedLength() + "(63)", Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| } catch (Exception e1) { | |||
| e1.printStackTrace(); | |||
| } | |||
| // 先添加卡,卡添加成功后,再添加图片 | |||
| int useTimes = 0; | |||
| if(useTimesTextField.getText().isEmpty()) { | |||
| useTimes = 0; | |||
| } else { | |||
| useTimes = Integer.parseInt(useTimesTextField.getText()); | |||
| } | |||
| boolean bCardFlags = GateModule.insertCard(cardNoTextField.getText(), userIdTextField.getText(), cardNameTextField.getText(), | |||
| new String(cardPasswdField.getPassword()), Res.string().getCardStatusInt(cardStatusComboBox.getSelectedIndex()), | |||
| Res.string().getCardTypeInt(cardTypeComboBox.getSelectedIndex()), useTimes, | |||
| firstEnterCheckBox.isSelected() ? 1:0, enableCheckBox.isSelected() ? 1:0, startTimeBtn.getText(), endTimeBtn.getText()); | |||
| String cardError = ""; | |||
| if(!bCardFlags) { | |||
| cardError = ToolKits.getErrorCodeShow(); | |||
| } | |||
| boolean bFaceFalgs = GateModule.addFaceInfo(userIdTextField.getText(), memory); | |||
| String faceError = ""; | |||
| if(!bFaceFalgs) { | |||
| faceError = ToolKits.getErrorCodeShow(); | |||
| } | |||
| // 添加卡信息和人脸成功 | |||
| if(bCardFlags && bFaceFalgs) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceedAddCardAndPerson(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| dispose(); | |||
| } | |||
| // 添加卡信息和人脸失败 | |||
| if(!bCardFlags && !bFaceFalgs) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailedAddCard() + " : " + cardError, | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| // 添加卡信息成功,添加人脸失败 | |||
| if(bCardFlags && !bFaceFalgs) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceedAddCardButFailedAddPerson() + " : " + faceError, Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| // 卡信息已存在,添加人脸成功 | |||
| if(!bCardFlags && bFaceFalgs) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCardExistedSucceedAddPerson(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| // 取消 | |||
| cancelBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| clear(); | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /** | |||
| * 选择图片 | |||
| */ | |||
| private class ImagePanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public ImagePanel() { | |||
| BorderEx.set(this, Res.string().getPersonPicture(), 4); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.width = 250; | |||
| setPreferredSize(dimension); | |||
| setLayout(new BorderLayout()); | |||
| addImagePanel = new PaintPanel(); // 添加的人员信息图片显示 | |||
| selectImageBtn = new JButton(Res.string().getSelectPicture()); | |||
| add(addImagePanel, BorderLayout.CENTER); | |||
| add(selectImageBtn, BorderLayout.SOUTH); | |||
| // 选择图片,获取图片的信息 | |||
| selectImageBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| // 选择图片,获取图片路径,并在界面显示 | |||
| picPath = ToolKits.openPictureFile(addImagePanel); | |||
| if(!picPath.isEmpty()) { | |||
| try { | |||
| memory = ToolKits.readPictureFile(picPath); | |||
| } catch (IOException e) { | |||
| // TODO Auto-generated catch block | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| private void clear() { | |||
| memory = null; | |||
| picPath = ""; | |||
| } | |||
| private PaintPanel addImagePanel; | |||
| private JButton selectImageBtn; | |||
| private JTextField cardNoTextField; | |||
| private JTextField userIdTextField; | |||
| private JTextField cardNameTextField; | |||
| private JPasswordField cardPasswdField; | |||
| private JComboBox cardStatusComboBox; | |||
| private JComboBox cardTypeComboBox; | |||
| private JTextField useTimesTextField; | |||
| private JCheckBox firstEnterCheckBox; | |||
| private JCheckBox enableCheckBox; | |||
| private DateChooserJButton startTimeBtn; | |||
| private DateChooserJButton endTimeBtn; | |||
| private JButton addBtn; | |||
| private JButton cancelBtn; | |||
| } | |||
| @@ -0,0 +1,399 @@ | |||
| package com.netsdk.demo.frame.Gate; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.Panel; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.Vector; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JTable; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.SwingWorker; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.GateModule; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| public class CardManegerDialog extends JDialog{ | |||
| private static final long serialVersionUID = 1L; | |||
| private int count = 0; // 查询了几次 | |||
| private int index = 0; // 查询的卡信息索引 | |||
| private int nFindCount = 10; // 每次查询的次数 | |||
| public CardManegerDialog(){ | |||
| setTitle(Res.string().getCardManager()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(700, 390); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| CardListPanel cardListPanel = new CardListPanel(); | |||
| CardOperatePanel cardOperatePanel = new CardOperatePanel(); | |||
| add(cardListPanel, BorderLayout.CENTER); | |||
| add(cardOperatePanel, BorderLayout.EAST); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e){ | |||
| dispose(); | |||
| } | |||
| }); | |||
| setOnClickListener(); | |||
| } | |||
| /** | |||
| * 卡信息列表 | |||
| */ | |||
| private class CardListPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public CardListPanel() { | |||
| BorderEx.set(this, Res.string().getCardInfo(), 2); | |||
| setLayout(new BorderLayout()); | |||
| defaultModel = new DefaultTableModel(null, Res.string().getCardTable()); | |||
| table = new JTable(defaultModel) { // 列表不可编辑 | |||
| private static final long serialVersionUID = 1L; | |||
| @Override | |||
| public boolean isCellEditable(int row, int column) { | |||
| return false; | |||
| } | |||
| }; | |||
| defaultModel.setRowCount(18); | |||
| table.getColumnModel().getColumn(0).setPreferredWidth(80); | |||
| table.getColumnModel().getColumn(1).setPreferredWidth(120); | |||
| table.getColumnModel().getColumn(2).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(3).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(4).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(5).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(6).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(7).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(8).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(9).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(10).setPreferredWidth(100); | |||
| table.getColumnModel().getColumn(11).setPreferredWidth(150); | |||
| table.getColumnModel().getColumn(12).setPreferredWidth(150); | |||
| // 列表显示居中 | |||
| DefaultTableCellRenderer dCellRenderer = new DefaultTableCellRenderer(); | |||
| dCellRenderer.setHorizontalAlignment(JLabel.CENTER); | |||
| table.setDefaultRenderer(Object.class, dCellRenderer); | |||
| ((DefaultTableCellRenderer)table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(JLabel.CENTER); | |||
| table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); | |||
| JScrollPane scrollPane = new JScrollPane(table); | |||
| add(scrollPane, BorderLayout.CENTER); | |||
| } | |||
| } | |||
| /** | |||
| * 卡操作 | |||
| */ | |||
| private class CardOperatePanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public CardOperatePanel() { | |||
| BorderEx.set(this, Res.string().getCardOperate(), 2); | |||
| setLayout(new BorderLayout()); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.width = 210; | |||
| setPreferredSize(dimension); | |||
| Panel panel1 = new Panel(); | |||
| Panel panel2 = new Panel(); | |||
| add(panel1, BorderLayout.NORTH); | |||
| add(panel2, BorderLayout.CENTER); | |||
| // | |||
| JLabel cardNoLabel = new JLabel(Res.string().getCardNo() + ":", JLabel.CENTER); | |||
| cardNoTextField = new JTextField(""); | |||
| cardNoLabel.setPreferredSize(new Dimension(50, 20)); | |||
| cardNoTextField.setPreferredSize(new Dimension(120, 20)); | |||
| cardNoTextField.setHorizontalAlignment(JTextField.CENTER); | |||
| panel1.setLayout(new FlowLayout()); | |||
| panel1.add(cardNoLabel); | |||
| panel1.add(cardNoTextField); | |||
| // | |||
| searchBtn = new JButton(Res.string().getSearch()); | |||
| addBtn = new JButton(Res.string().getAdd()); | |||
| modifyBtn = new JButton(Res.string().getModify()); | |||
| deleteBtn = new JButton(Res.string().getDelete()); | |||
| clearBtn = new JButton(Res.string().getClear()); | |||
| searchBtn.setPreferredSize(new Dimension(180, 21)); | |||
| addBtn.setPreferredSize(new Dimension(180, 21)); | |||
| modifyBtn.setPreferredSize(new Dimension(180, 21)); | |||
| deleteBtn.setPreferredSize(new Dimension(180, 21)); | |||
| clearBtn.setPreferredSize(new Dimension(180, 21)); | |||
| JLabel nullLabel = new JLabel(); | |||
| nullLabel.setPreferredSize(new Dimension(180, 30)); | |||
| panel2.setLayout(new FlowLayout()); | |||
| panel2.add(nullLabel); | |||
| panel2.add(searchBtn); | |||
| panel2.add(addBtn); | |||
| panel2.add(modifyBtn); | |||
| panel2.add(deleteBtn); | |||
| panel2.add(clearBtn); | |||
| } | |||
| } | |||
| private void setOnClickListener() { | |||
| searchBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| try { | |||
| if (cardNoTextField.getText().getBytes("UTF-8").length > 31) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCardNoExceedLength() + "(31)", Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| } catch (Exception e1) { | |||
| e1.printStackTrace(); | |||
| } | |||
| searchBtn.setEnabled(false); | |||
| defaultModel.setRowCount(0); | |||
| defaultModel.setRowCount(18); | |||
| } | |||
| }); | |||
| findCardInfo(); | |||
| } | |||
| }); | |||
| addBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| AddCardDialog dialog = new AddCardDialog(); | |||
| dialog.setVisible(true); | |||
| } | |||
| }); | |||
| modifyBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| int row = -1; | |||
| row = table.getSelectedRow(); //获得所选的单行 | |||
| if(row < 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectCard(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(defaultModel.getValueAt(row, 3) == null || String.valueOf(defaultModel.getValueAt(row, 3)).trim().isEmpty()) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectCard(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| @SuppressWarnings("unchecked") | |||
| Vector<String> vector = (Vector<String>) defaultModel.getDataVector().get(row); | |||
| ModifyCardDialog dialog = new ModifyCardDialog(vector); | |||
| dialog.setVisible(true); | |||
| } | |||
| }); | |||
| deleteBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| int row = -1; | |||
| row = table.getSelectedRow(); //获得所选的单行 | |||
| if(row < 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectCard(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if(defaultModel.getValueAt(row, 3) == null || String.valueOf(defaultModel.getValueAt(row, 3)).trim().isEmpty()) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectCard(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| Vector<String> v = (Vector<String>)defaultModel.getDataVector().get(row); | |||
| String recordNo = v.get(3).toString(); // 记录集编号 | |||
| String userId = v.get(4).toString(); // 用户ID | |||
| // 删除人脸和卡信息 | |||
| if(!GateModule.deleteFaceInfo(userId) || | |||
| !GateModule.deleteCard(Integer.parseInt(recordNo))) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| defaultModel.removeRow(row); | |||
| table.updateUI(); | |||
| } | |||
| } | |||
| }); | |||
| clearBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| int result = JOptionPane.showConfirmDialog(null, Res.string().getWantClearAllInfo(), Res.string().getPromptMessage(), JOptionPane.YES_NO_OPTION); | |||
| if(result == 0) { // 0-是, 1-否 | |||
| // 清空人脸和卡信息 | |||
| if(!GateModule.clearFaceInfo() || | |||
| !GateModule.clearCard()) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| defaultModel.setRowCount(0); | |||
| defaultModel.setRowCount(18); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| /** | |||
| * 查询卡的信息 | |||
| */ | |||
| public void findCardInfo() { | |||
| new SwingWorker<Boolean, CardData>() { | |||
| @Override | |||
| protected Boolean doInBackground() { | |||
| count = 0; | |||
| index = 0; | |||
| nFindCount = 10; | |||
| // 卡号: 为空,查询所有的卡信息 | |||
| // 获取查询句柄 | |||
| if(!GateModule.findCard(cardNoTextField.getText(),"")) { | |||
| return false; | |||
| } | |||
| // 查询具体信息 | |||
| while(true) { | |||
| NET_RECORDSET_ACCESS_CTL_CARD[] pstRecord = GateModule.findNextCard(nFindCount); | |||
| if(pstRecord == null) { | |||
| break; | |||
| } | |||
| for(int i = 0; i < pstRecord.length; i++) { | |||
| index = i + count * nFindCount; | |||
| try { | |||
| Vector<String> vector = new Vector<String>(); | |||
| vector.add(String.valueOf(index + 1)); // 序号 | |||
| vector.add(new String(pstRecord[i].szCardNo).trim()); // 卡号 | |||
| vector.add(new String(pstRecord[i].szCardName, "GBK").trim()); // 卡名 | |||
| vector.add(String.valueOf(pstRecord[i].nRecNo)); // 记录集编号 | |||
| vector.add(new String(pstRecord[i].szUserID).trim()); // 用户ID | |||
| vector.add(new String(pstRecord[i].szPsw).trim()); // 卡密码 | |||
| vector.add(Res.string().getCardStatus(pstRecord[i].emStatus)); // 卡状态 | |||
| vector.add(Res.string().getCardType(pstRecord[i].emType)); // 卡类型 | |||
| vector.add(String.valueOf(pstRecord[i].nUserTime)); // 使用次数 | |||
| vector.add(pstRecord[i].bFirstEnter == 1 ? Res.string().getFirstEnter() : Res.string().getNoFirstEnter()); // 是否首卡 | |||
| vector.add(pstRecord[i].bIsValid == 1? Res.string().getValid() : Res.string().getInValid()); // 是否有效 | |||
| vector.add(pstRecord[i].stuValidStartTime.toStringTimeEx()); // 有效开始时间 | |||
| vector.add(pstRecord[i].stuValidEndTime.toStringTimeEx()); // 有效结束时间 | |||
| CardData data = new CardData(); | |||
| data.setIndex(index); | |||
| data.setVector(vector); | |||
| publish(data); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| if (pstRecord.length < nFindCount) { | |||
| break; | |||
| } else { | |||
| count ++; | |||
| } | |||
| } | |||
| // 关闭查询接口 | |||
| GateModule.findCardClose(); | |||
| return true; | |||
| } | |||
| @Override | |||
| protected void process(java.util.List<CardData> chunks) { | |||
| for(CardData data : chunks) { | |||
| defaultModel.insertRow(data.getIndex(), data.getVector()); | |||
| if(data.getIndex() < 18) { | |||
| defaultModel.setRowCount(18); | |||
| } else { | |||
| defaultModel.setRowCount(data.getIndex() + 1); | |||
| } | |||
| table.updateUI(); | |||
| } | |||
| super.process(chunks); | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| searchBtn.setEnabled(true); | |||
| } | |||
| }.execute(); | |||
| } | |||
| class CardData { | |||
| private int nIndex = 0; | |||
| private Vector<String> vector = null; | |||
| public int getIndex() { | |||
| return nIndex; | |||
| } | |||
| public void setIndex(int index) { | |||
| this.nIndex = index; | |||
| } | |||
| public Vector<String> getVector() { | |||
| return vector; | |||
| } | |||
| public void setVector(Vector<String> vector) { | |||
| this.vector = vector; | |||
| } | |||
| } | |||
| /// | |||
| private DefaultTableModel defaultModel; | |||
| private JTable table; | |||
| private JTextField cardNoTextField; | |||
| private JButton searchBtn; | |||
| private JButton addBtn; | |||
| private JButton modifyBtn; | |||
| private JButton deleteBtn; | |||
| private JButton clearBtn; | |||
| } | |||
| @@ -0,0 +1,611 @@ | |||
| package com.netsdk.demo.frame.Gate; | |||
| import java.awt.AWTEvent; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.EventQueue; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.Toolkit; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.awt.image.BufferedImage; | |||
| import java.io.ByteArrayInputStream; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.Vector; | |||
| import javax.imageio.ImageIO; | |||
| import javax.swing.BorderFactory; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.UIManager; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.FunctionList; | |||
| import com.netsdk.common.LoginPanel; | |||
| import com.netsdk.common.PaintPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.GateModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.sun.jna.Pointer; | |||
| class GateFrame extends JFrame { | |||
| private static final long serialVersionUID = 1L; | |||
| // 获取界面窗口 | |||
| private static JFrame frame = new JFrame(); | |||
| // 设备断线通知回调 | |||
| private static DisConnect disConnect = new DisConnect(); | |||
| // 网络连接恢复 | |||
| private static HaveReConnect haveReConnect = new HaveReConnect(); | |||
| // 订阅句柄 | |||
| public static LLong m_hAttachHandle = new LLong(0); | |||
| private Vector<String> chnList = new Vector<String>(); | |||
| private AnalyzerDataCB analyzerCallback = new AnalyzerDataCB(); | |||
| private java.awt.Component target = this; | |||
| private boolean isAttach = false; | |||
| public GateFrame() { | |||
| setTitle(Res.string().getGate()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(800, 400); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| loginPanel = new LoginPanel(); | |||
| GatePanel gatePanel = new GatePanel(); | |||
| add(loginPanel, BorderLayout.NORTH); | |||
| add(gatePanel, BorderLayout.CENTER); | |||
| loginPanel.addLoginBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(loginPanel.checkLoginText()) { | |||
| if(login()) { | |||
| frame = ToolKits.getFrame(e); | |||
| frame.setTitle(Res.string().getGate() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| loginPanel.addLogoutBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| frame.setTitle(Res.string().getGate()); | |||
| logout(); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| GateModule.stopRealLoadPic(m_hAttachHandle); | |||
| LoginModule.logout(); | |||
| LoginModule.cleanup(); // 关闭工程,释放资源 | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /////////////////面板/////////////////// | |||
| // 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数 | |||
| private static class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| // 断线提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getGate() + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 网络连接恢复,设备重连成功回调 | |||
| // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 | |||
| private static class HaveReConnect implements NetSDKLib.fHaveReConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| // 重连提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getGate() + " : " + Res.string().getOnline()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 登录 | |||
| public boolean login() { | |||
| if(LoginModule.login(loginPanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginPanel.portTextArea.getText()), | |||
| loginPanel.nameTextArea.getText(), | |||
| new String(loginPanel.passwordTextArea.getPassword()))) { | |||
| for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) { | |||
| chnList.add(Res.string().getChannel() + " " + String.valueOf(i)); | |||
| } | |||
| // 登陆成功,将通道添加到控件 | |||
| chnComboBox.setModel(new DefaultComboBoxModel(chnList)); | |||
| loginPanel.setButtonEnable(true); | |||
| setEnable(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| // 登出 | |||
| public void logout() { | |||
| GateModule.stopRealLoadPic(m_hAttachHandle); | |||
| LoginModule.logout(); | |||
| loginPanel.setButtonEnable(false); | |||
| for(int i = 0; i < LoginModule.m_stDeviceInfo.byChanNum; i++) { | |||
| chnList.clear(); | |||
| } | |||
| chnComboBox.setModel(new DefaultComboBoxModel()); | |||
| setEnable(false); | |||
| detachBtn.setEnabled(false); | |||
| isAttach = false; | |||
| clearPanel(); | |||
| } | |||
| /** | |||
| * 闸机界面面板 | |||
| */ | |||
| private class GatePanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public GatePanel() { | |||
| BorderEx.set(this, "", 4); | |||
| setLayout(new BorderLayout()); | |||
| JPanel gateOperatePanel = new JPanel(); | |||
| JPanel gateShowPanel = new JPanel(); | |||
| add(gateOperatePanel, BorderLayout.WEST); | |||
| add(gateShowPanel, BorderLayout.CENTER); | |||
| /** | |||
| * 闸机操作面板 | |||
| */ | |||
| gateOperatePanel.setLayout(new BorderLayout()); | |||
| gateOperatePanel.setPreferredSize(new Dimension(250, 70)); | |||
| JPanel channelPanel = new JPanel(); | |||
| JPanel operatePanel = new JPanel(); | |||
| gateOperatePanel.add(channelPanel, BorderLayout.NORTH); | |||
| gateOperatePanel.add(operatePanel, BorderLayout.CENTER); | |||
| // 通道面板 | |||
| channelPanel.setBorder(BorderFactory.createTitledBorder("")); | |||
| channelPanel.setPreferredSize(new Dimension(220, 70)); | |||
| channelPanel.setLayout(new FlowLayout()); | |||
| JLabel channelLabel = new JLabel(Res.string().getChannel()); | |||
| chnComboBox = new JComboBox(); | |||
| chnComboBox.setPreferredSize(new Dimension(100, 20)); | |||
| channelPanel.add(channelLabel); | |||
| channelPanel.add(chnComboBox); | |||
| // 按钮面板 | |||
| operatePanel.setBorder(BorderFactory.createTitledBorder(Res.string().getOperate())); | |||
| operatePanel.setLayout(new FlowLayout()); | |||
| attachBtn = new JButton(Res.string().getAttach()); | |||
| detachBtn = new JButton(Res.string().getDetach()); | |||
| cardOperateBtn = new JButton(Res.string().getCardOperate()); | |||
| JLabel nullJLabel = new JLabel(""); | |||
| nullJLabel.setPreferredSize(new Dimension(205, 40)); | |||
| attachBtn.setPreferredSize(new Dimension(100, 20)); | |||
| detachBtn.setPreferredSize(new Dimension(100, 20)); | |||
| cardOperateBtn.setPreferredSize(new Dimension(205, 20)); | |||
| operatePanel.add(attachBtn); | |||
| operatePanel.add(detachBtn); | |||
| operatePanel.add(nullJLabel); | |||
| operatePanel.add(cardOperateBtn); | |||
| setEnable(false); | |||
| detachBtn.setEnabled(false); | |||
| /** | |||
| * 闸机订阅展示面板 | |||
| */ | |||
| gateShowPanel.setBorder(BorderFactory.createTitledBorder("")); | |||
| gateShowPanel.setLayout(new BorderLayout()); | |||
| personPaintPanel = new PaintPanel(); | |||
| JPanel cardInfoPanel = new JPanel(); | |||
| personPaintPanel.setPreferredSize(new Dimension(250, 70)); | |||
| gateShowPanel.add(personPaintPanel, BorderLayout.WEST); | |||
| gateShowPanel.add(cardInfoPanel, BorderLayout.CENTER); | |||
| // | |||
| cardInfoPanel.setLayout(new FlowLayout()); | |||
| JLabel timeLable = new JLabel(Res.string().getTime() + ":", JLabel.CENTER); | |||
| JLabel openStatusLable = new JLabel(Res.string().getOpenStatus() + ":", JLabel.CENTER); | |||
| JLabel openMethodLable = new JLabel(Res.string().getOpenMethod() + ":", JLabel.CENTER); | |||
| JLabel cardNameLable = new JLabel(Res.string().getCardName() + ":", JLabel.CENTER); | |||
| JLabel cardNoLable = new JLabel(Res.string().getCardNo() + ":", JLabel.CENTER); | |||
| JLabel userIdLable = new JLabel(Res.string().getUserId() + ":", JLabel.CENTER); | |||
| JLabel tempLable = new JLabel(Res.string().getTemp() + ":", JLabel.CENTER); | |||
| JLabel maskstutasLable = new JLabel(Res.string().getMaskstutas() + ":", JLabel.CENTER); | |||
| timeLable.setPreferredSize(new Dimension(80, 20)); | |||
| openStatusLable.setPreferredSize(new Dimension(80, 20)); | |||
| openMethodLable.setPreferredSize(new Dimension(80, 20)); | |||
| cardNameLable.setPreferredSize(new Dimension(80, 20)); | |||
| cardNoLable.setPreferredSize(new Dimension(80, 20)); | |||
| userIdLable.setPreferredSize(new Dimension(80, 20)); | |||
| tempLable.setPreferredSize(new Dimension(80, 20)); | |||
| maskstutasLable.setPreferredSize(new Dimension(80, 20)); | |||
| timeTextField = new JTextField(""); | |||
| openStatusTextField = new JTextField(""); | |||
| openMethodTextField = new JTextField(""); | |||
| cardNameTextField = new JTextField(""); | |||
| cardNoTextField = new JTextField(""); | |||
| userIdTextField = new JTextField(""); | |||
| tempTextField = new JTextField(""); | |||
| maskStatusTextField = new JTextField(""); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.width = 150; | |||
| dimension.height = 20; | |||
| timeTextField.setPreferredSize(dimension); | |||
| openStatusTextField.setPreferredSize(dimension); | |||
| openMethodTextField.setPreferredSize(dimension); | |||
| cardNameTextField.setPreferredSize(dimension); | |||
| cardNoTextField.setPreferredSize(dimension); | |||
| userIdTextField.setPreferredSize(dimension); | |||
| tempTextField.setPreferredSize(dimension); | |||
| maskStatusTextField.setPreferredSize(dimension); | |||
| timeTextField.setHorizontalAlignment(JTextField.CENTER); | |||
| openStatusTextField.setHorizontalAlignment(JTextField.CENTER); | |||
| openMethodTextField.setHorizontalAlignment(JTextField.CENTER); | |||
| cardNameTextField.setHorizontalAlignment(JTextField.CENTER); | |||
| cardNoTextField.setHorizontalAlignment(JTextField.CENTER); | |||
| userIdTextField.setHorizontalAlignment(JTextField.CENTER); | |||
| tempTextField.setHorizontalAlignment(JTextField.CENTER); | |||
| maskStatusTextField.setHorizontalAlignment(JTextField.CENTER); | |||
| timeTextField.setEditable(false); | |||
| openStatusTextField.setEditable(false); | |||
| openMethodTextField.setEditable(false); | |||
| cardNameTextField.setEditable(false); | |||
| cardNoTextField.setEditable(false); | |||
| userIdTextField.setEditable(false); | |||
| tempTextField.setEditable(false); | |||
| maskStatusTextField.setEditable(false); | |||
| cardInfoPanel.add(timeLable); | |||
| cardInfoPanel.add(timeTextField); | |||
| cardInfoPanel.add(openStatusLable); | |||
| cardInfoPanel.add(openStatusTextField); | |||
| cardInfoPanel.add(openMethodLable); | |||
| cardInfoPanel.add(openMethodTextField); | |||
| cardInfoPanel.add(cardNameLable); | |||
| cardInfoPanel.add(cardNameTextField); | |||
| cardInfoPanel.add(cardNoLable); | |||
| cardInfoPanel.add(cardNoTextField); | |||
| cardInfoPanel.add(userIdLable); | |||
| cardInfoPanel.add(userIdTextField); | |||
| cardInfoPanel.add(tempLable); | |||
| cardInfoPanel.add(tempTextField); | |||
| cardInfoPanel.add(maskstutasLable); | |||
| cardInfoPanel.add(maskStatusTextField); | |||
| setOnClickListener(); | |||
| } | |||
| } | |||
| // 监听 | |||
| private void setOnClickListener() { | |||
| // 订阅 | |||
| attachBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| m_hAttachHandle = GateModule.realLoadPic(chnComboBox.getSelectedIndex(), analyzerCallback); | |||
| if(m_hAttachHandle.longValue() != 0) { | |||
| isAttach = true; | |||
| attachBtn.setEnabled(false); | |||
| detachBtn.setEnabled(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| // 取消订阅 | |||
| detachBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| GateModule.stopRealLoadPic(m_hAttachHandle); | |||
| synchronized (this) { | |||
| isAttach = false; | |||
| } | |||
| attachBtn.setEnabled(true); | |||
| detachBtn.setEnabled(false); | |||
| clearPanel(); | |||
| } | |||
| }); | |||
| // 卡操作 | |||
| cardOperateBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| CardManegerDialog dialog = new CardManegerDialog(); | |||
| dialog.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| private void setEnable(boolean bln) { | |||
| chnComboBox.setEnabled(bln); | |||
| attachBtn.setEnabled(bln); | |||
| cardOperateBtn.setEnabled(bln); | |||
| } | |||
| private void clearPanel() { | |||
| personPaintPanel.setOpaque(true); | |||
| personPaintPanel.repaint(); | |||
| timeTextField.setText(""); | |||
| openStatusTextField.setText(""); | |||
| openMethodTextField.setText(""); | |||
| cardNameTextField.setText(""); | |||
| cardNoTextField.setText(""); | |||
| userIdTextField.setText(""); | |||
| tempTextField.setText(""); | |||
| maskStatusTextField.setText(""); | |||
| } | |||
| private class AnalyzerDataCB implements NetSDKLib.fAnalyzerDataCallBack { | |||
| private BufferedImage gateBufferedImage = null; | |||
| public int invoke(LLong lAnalyzerHandle, int dwAlarmType, | |||
| Pointer pAlarmInfo, Pointer pBuffer, int dwBufSize, | |||
| Pointer dwUser, int nSequence, Pointer reserved) | |||
| { | |||
| if (lAnalyzerHandle.longValue() == 0 || pAlarmInfo == null) { | |||
| return -1; | |||
| } | |||
| File path = new File("./GateSnapPicture/"); | |||
| if (!path.exists()) { | |||
| path.mkdir(); | |||
| } | |||
| ///< 门禁事件 | |||
| if(dwAlarmType == NetSDKLib.EVENT_IVS_ACCESS_CTL) { | |||
| DEV_EVENT_ACCESS_CTL_INFO msg = new DEV_EVENT_ACCESS_CTL_INFO(); | |||
| ToolKits.GetPointerData(pAlarmInfo, msg); | |||
| // 保存图片,获取图片缓存 | |||
| String snapPicPath = path + "\\" + System.currentTimeMillis() + "GateSnapPicture.jpg"; // 保存图片地址 | |||
| byte[] buffer = pBuffer.getByteArray(0, dwBufSize); | |||
| ByteArrayInputStream byteArrInputGlobal = new ByteArrayInputStream(buffer); | |||
| try { | |||
| gateBufferedImage = ImageIO.read(byteArrInputGlobal); | |||
| if(gateBufferedImage != null) { | |||
| ImageIO.write(gateBufferedImage, "jpg", new File(snapPicPath)); | |||
| } | |||
| } catch (IOException e2) { | |||
| e2.printStackTrace(); | |||
| } | |||
| // 图片以及门禁信息界面显示 | |||
| EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); | |||
| if (eventQueue != null) { | |||
| eventQueue.postEvent( new AccessEvent(target, | |||
| gateBufferedImage, | |||
| msg)); | |||
| } | |||
| } | |||
| return 0; | |||
| } | |||
| } | |||
| class AccessEvent extends AWTEvent { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public static final int EVENT_ID = AWTEvent.RESERVED_ID_MAX + 1; | |||
| private BufferedImage gateBufferedImage = null; | |||
| private DEV_EVENT_ACCESS_CTL_INFO msg = null; | |||
| public AccessEvent(Object target, | |||
| BufferedImage gateBufferedImage, | |||
| DEV_EVENT_ACCESS_CTL_INFO msg) { | |||
| super(target, EVENT_ID); | |||
| this.gateBufferedImage = gateBufferedImage; | |||
| this.msg = msg; | |||
| } | |||
| public BufferedImage getGateBufferedImage() { | |||
| return gateBufferedImage; | |||
| } | |||
| public DEV_EVENT_ACCESS_CTL_INFO getAccessInfo() { | |||
| return msg; | |||
| } | |||
| } | |||
| @Override | |||
| protected void processEvent(AWTEvent event) { | |||
| if (event instanceof AccessEvent) { // 门禁事件处理 | |||
| AccessEvent ev = (AccessEvent) event; | |||
| BufferedImage gateBufferedImage = ev.getGateBufferedImage(); | |||
| DEV_EVENT_ACCESS_CTL_INFO msg = ev.getAccessInfo(); | |||
| if(!isAttach) { | |||
| return; | |||
| } | |||
| // 图片显示 | |||
| if(gateBufferedImage != null) { | |||
| personPaintPanel.setImage(gateBufferedImage); | |||
| personPaintPanel.setOpaque(false); | |||
| personPaintPanel.repaint(); | |||
| } else { | |||
| personPaintPanel.setOpaque(true); | |||
| personPaintPanel.repaint(); | |||
| } | |||
| // 时间 | |||
| if(msg.UTC == null || msg.UTC.toString().isEmpty()) { | |||
| timeTextField.setText(""); | |||
| } else { | |||
| msg.UTC.setTime(msg.UTC.dwYear, msg.UTC.dwMonth, msg.UTC.dwDay, msg.UTC.dwHour+8, msg.UTC.dwMinute, msg.UTC.dwSecond); | |||
| timeTextField.setText(msg.UTC.toString()); | |||
| } | |||
| // 开门状态 | |||
| if(msg.bStatus == 1) { | |||
| openStatusTextField.setText(Res.string().getSucceed()); | |||
| } else { | |||
| openStatusTextField.setText(Res.string().getFailed()); | |||
| } | |||
| // 开门方式 | |||
| openMethodTextField.setText(Res.string().getOpenMethods(msg.emOpenMethod)); | |||
| // 卡名 | |||
| try { | |||
| cardNameTextField.setText(new String(msg.szCardName, "GBK").trim()); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 卡号 | |||
| cardNoTextField.setText(new String(msg.szCardNo).trim()); | |||
| // 用户ID | |||
| userIdTextField.setText(new String(msg.szUserID).trim()); | |||
| // 口罩状态 | |||
| maskStatusTextField.setText(Res.string().getMaskStatus(msg.emMask)); | |||
| //温度 | |||
| if(msg.stuManTemperatureInfo.emTemperatureUnit==0) { | |||
| tempTextField.setText(String.valueOf(msg.stuManTemperatureInfo.fCurrentTemperature+"℃")); | |||
| }else if(msg.stuManTemperatureInfo.emTemperatureUnit==1){ | |||
| tempTextField.setText(String.valueOf(msg.stuManTemperatureInfo.fCurrentTemperature+"℉")); | |||
| }else if(msg.stuManTemperatureInfo.emTemperatureUnit==2) { | |||
| tempTextField.setText(String.valueOf(msg.stuManTemperatureInfo.fCurrentTemperature+"K")); | |||
| } | |||
| } else { | |||
| super.processEvent(event); | |||
| } | |||
| } | |||
| /* | |||
| * 登录控件 | |||
| */ | |||
| private LoginPanel loginPanel; | |||
| private JComboBox chnComboBox; | |||
| private JButton attachBtn; | |||
| private JButton detachBtn; | |||
| private JButton cardOperateBtn; | |||
| private PaintPanel personPaintPanel; | |||
| private JTextField timeTextField; | |||
| private JTextField openStatusTextField; | |||
| private JTextField openMethodTextField; | |||
| private JTextField cardNameTextField; | |||
| private JTextField cardNoTextField; | |||
| private JTextField userIdTextField; | |||
| private JTextField tempTextField; | |||
| private JTextField maskStatusTextField; | |||
| } | |||
| public class Gate { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| GateFrame demo = new GateFrame(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| @@ -0,0 +1,341 @@ | |||
| package com.netsdk.demo.frame.Gate; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.IOException; | |||
| import java.util.Vector; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JCheckBox; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JPasswordField; | |||
| import javax.swing.JTextField; | |||
| import com.sun.jna.Memory; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.DateChooserJButton; | |||
| import com.netsdk.common.PaintPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.GateModule; | |||
| import com.netsdk.lib.ToolKits; | |||
| public class ModifyCardDialog extends JDialog{ | |||
| private static final long serialVersionUID = 1L; | |||
| private Memory memory = null; | |||
| private Vector<String> vector = null; | |||
| private String picPath = ""; | |||
| public ModifyCardDialog(Vector<String> v){ | |||
| setTitle(Res.string().getModify() + Res.string().getCardInfo()); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(520, 390); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 | |||
| CardInfoPanel cardInfoPanel = new CardInfoPanel(); | |||
| ImagePanel imagePanel = new ImagePanel(); | |||
| add(cardInfoPanel, BorderLayout.CENTER); | |||
| add(imagePanel, BorderLayout.EAST); | |||
| this.vector = v; | |||
| showCardInfo(); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e){ | |||
| clear(); | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| /** | |||
| * 卡信息 | |||
| */ | |||
| private class CardInfoPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public CardInfoPanel() { | |||
| BorderEx.set(this, Res.string().getCardInfo(), 4); | |||
| JLabel cardNoLabel = new JLabel(Res.string().getCardNo() + ":", JLabel.CENTER); | |||
| JLabel userIdLabel = new JLabel(Res.string().getUserId() + ":", JLabel.CENTER); | |||
| JLabel cardNameLabel = new JLabel(Res.string().getCardName() + ":", JLabel.CENTER); | |||
| JLabel cardPasswdLabel = new JLabel(Res.string().getCardPassword() + ":", JLabel.CENTER); | |||
| JLabel cardStatusLabel = new JLabel(Res.string().getCardStatus() + ":", JLabel.CENTER); | |||
| JLabel cardTypeLabel = new JLabel(Res.string().getCardType() + ":", JLabel.CENTER); | |||
| JLabel useTimesLabel = new JLabel(Res.string().getUseTimes() + ":", JLabel.CENTER); | |||
| JLabel validPeriodLabel = new JLabel(Res.string().getValidPeriod() + ":", JLabel.CENTER); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.width = 85; | |||
| dimension.height = 20; | |||
| cardNoLabel.setPreferredSize(dimension); | |||
| userIdLabel.setPreferredSize(dimension); | |||
| cardNameLabel.setPreferredSize(dimension); | |||
| cardPasswdLabel.setPreferredSize(dimension); | |||
| cardStatusLabel.setPreferredSize(dimension); | |||
| cardTypeLabel.setPreferredSize(dimension); | |||
| useTimesLabel.setPreferredSize(dimension); | |||
| validPeriodLabel.setPreferredSize(dimension); | |||
| cardNoTextField = new JTextField(); | |||
| userIdTextField = new JTextField(); | |||
| cardNameTextField = new JTextField(); | |||
| cardPasswdField = new JPasswordField(); | |||
| cardStatusComboBox = new JComboBox(Res.string().getCardStatusList()); | |||
| cardTypeComboBox = new JComboBox(Res.string().getCardTypeList()); | |||
| useTimesTextField = new JTextField(); | |||
| firstEnterCheckBox = new JCheckBox(Res.string().getIsFirstEnter()); | |||
| enableCheckBox = new JCheckBox(Res.string().getEnable()); | |||
| enableCheckBox.setSelected(true); | |||
| enableCheckBox.setVisible(false); | |||
| startTimeBtn = new DateChooserJButton(); | |||
| endTimeBtn = new DateChooserJButton(); | |||
| cardNoTextField.setPreferredSize(new Dimension(145, 20)); | |||
| userIdTextField.setPreferredSize(new Dimension(145, 20)); | |||
| cardNameTextField.setPreferredSize(new Dimension(145, 20)); | |||
| cardPasswdField.setPreferredSize(new Dimension(145, 20)); | |||
| useTimesTextField.setPreferredSize(new Dimension(145, 20)); | |||
| cardStatusComboBox.setPreferredSize(new Dimension(145, 20)); | |||
| cardTypeComboBox.setPreferredSize(new Dimension(145, 20)); | |||
| startTimeBtn.setPreferredSize(new Dimension(145, 20)); | |||
| endTimeBtn.setPreferredSize(new Dimension(145, 20)); | |||
| firstEnterCheckBox.setPreferredSize(new Dimension(170, 20)); | |||
| enableCheckBox.setPreferredSize(new Dimension(70, 20)); | |||
| JLabel nullLabel1 = new JLabel(); | |||
| JLabel nullLabel2 = new JLabel(); | |||
| JLabel nullLabel3 = new JLabel(); | |||
| nullLabel1.setPreferredSize(new Dimension(5, 20)); | |||
| nullLabel2.setPreferredSize(new Dimension(30, 20)); | |||
| nullLabel3.setPreferredSize(new Dimension(85, 20)); | |||
| cardNoTextField.setEditable(false); | |||
| userIdTextField.setEditable(false); | |||
| modifyBtn = new JButton(Res.string().getModify()); | |||
| cancelBtn = new JButton(Res.string().getCancel()); | |||
| JLabel nullLabel4 = new JLabel(); | |||
| nullLabel4.setPreferredSize(new Dimension(250, 20)); | |||
| modifyBtn.setPreferredSize(new Dimension(110, 20)); | |||
| cancelBtn.setPreferredSize(new Dimension(110, 20)); | |||
| add(cardNoLabel); | |||
| add(cardNoTextField); | |||
| add(userIdLabel); | |||
| add(userIdTextField); | |||
| add(cardNameLabel); | |||
| add(cardNameTextField); | |||
| add(cardPasswdLabel); | |||
| add(cardPasswdField); | |||
| add(cardStatusLabel); | |||
| add(cardStatusComboBox); | |||
| add(cardTypeLabel); | |||
| add(cardTypeComboBox); | |||
| add(useTimesLabel); | |||
| add(useTimesTextField); | |||
| add(nullLabel1); | |||
| add(firstEnterCheckBox); | |||
| add(nullLabel2); | |||
| add(enableCheckBox); | |||
| add(validPeriodLabel); | |||
| add(startTimeBtn); | |||
| add(nullLabel3); | |||
| add(endTimeBtn); | |||
| add(nullLabel4); | |||
| add(modifyBtn); | |||
| add(cancelBtn); | |||
| // 修改 | |||
| modifyBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| try { | |||
| if (cardNameTextField.getText().getBytes("UTF-8").length > 63) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCardNameExceedLength() + "(63)", Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if (new String(cardPasswdField.getPassword()).getBytes("UTF-8").length > 63) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCardPasswdExceedLength() + "(63)", Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| } catch (Exception e1) { | |||
| e1.printStackTrace(); | |||
| } | |||
| int useTimes = 0; | |||
| if(useTimesTextField.getText().isEmpty()) { | |||
| useTimes = 0; | |||
| } else { | |||
| useTimes = Integer.parseInt(useTimesTextField.getText()); | |||
| } | |||
| if(GateModule.modifyCard(Integer.parseInt(vector.get(3).toString()), cardNoTextField.getText(), | |||
| userIdTextField.getText(), cardNameTextField.getText(), | |||
| new String(cardPasswdField.getPassword()), | |||
| Res.string().getCardStatusInt(cardStatusComboBox.getSelectedIndex()), | |||
| Res.string().getCardTypeInt(cardTypeComboBox.getSelectedIndex()), | |||
| useTimes, firstEnterCheckBox.isSelected() ? 1:0, | |||
| enableCheckBox.isSelected() ? 1:0, startTimeBtn.getText(), endTimeBtn.getText())) { | |||
| if(memory == null) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceedModifyCard(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| dispose(); | |||
| } else { | |||
| if(GateModule.modifyFaceInfo(userIdTextField.getText(), memory)) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceedModifyCardAndPerson(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); | |||
| dispose(); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSucceedModifyCardButFailedModifyPerson() + " : " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailedModifyCard() + " : " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| // 取消 | |||
| cancelBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| clear(); | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /** | |||
| * 选择图片 | |||
| */ | |||
| private class ImagePanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public ImagePanel() { | |||
| BorderEx.set(this, Res.string().getPersonPicture(), 4); | |||
| Dimension dimension = new Dimension(); | |||
| dimension.width = 250; | |||
| setPreferredSize(dimension); | |||
| setLayout(new BorderLayout()); | |||
| addImagePanel = new PaintPanel(); // 添加的人员信息图片显示 | |||
| selectImageBtn = new JButton(Res.string().getSelectPicture()); | |||
| add(addImagePanel, BorderLayout.CENTER); | |||
| add(selectImageBtn, BorderLayout.SOUTH); | |||
| // 选择图片,获取图片的信息 | |||
| selectImageBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| // 选择图片,获取图片路径,并在界面显示 | |||
| picPath = ToolKits.openPictureFile(addImagePanel); | |||
| if(!picPath.isEmpty()) { | |||
| try { | |||
| memory = ToolKits.readPictureFile(picPath); | |||
| } catch (IOException e) { | |||
| // TODO Auto-generated catch block | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /** | |||
| * 界面显示要修改的卡信息 | |||
| */ | |||
| private void showCardInfo() { | |||
| // 卡号 | |||
| cardNoTextField.setText(vector.get(1).toString()); | |||
| // 卡名 | |||
| cardNameTextField.setText(vector.get(2).toString()); | |||
| // 用户ID | |||
| userIdTextField.setText(vector.get(4).toString()); | |||
| // 卡密码 | |||
| cardPasswdField.setText(vector.get(5).toString()); | |||
| // 卡状态 | |||
| cardStatusComboBox.setSelectedIndex(Res.string().getCardStatusChomBoxIndex(vector.get(6).toString())); | |||
| // 卡类型 | |||
| cardTypeComboBox.setSelectedIndex(Res.string().getCardTypeChomBoxIndex(vector.get(7).toString())); | |||
| // 使用次数 | |||
| useTimesTextField.setText(vector.get(8).toString()); | |||
| // 是否首卡 | |||
| if(vector.get(9).toString().equals(Res.string().getFirstEnter())) { | |||
| firstEnterCheckBox.setSelected(true); | |||
| } else { | |||
| firstEnterCheckBox.setSelected(false); | |||
| } | |||
| // 是否有效 | |||
| if(vector.get(10).toString().equals(Res.string().getValid())) { | |||
| enableCheckBox.setSelected(true); | |||
| } else { | |||
| enableCheckBox.setSelected(false); | |||
| } | |||
| // 有效开始时间 | |||
| startTimeBtn.setText(vector.get(11).toString()); | |||
| // 有效结束时间 | |||
| endTimeBtn.setText(vector.get(12).toString()); | |||
| } | |||
| private void clear() { | |||
| memory = null; | |||
| vector = null; | |||
| picPath = ""; | |||
| } | |||
| private PaintPanel addImagePanel; | |||
| private JButton selectImageBtn; | |||
| private JTextField cardNoTextField; | |||
| private JTextField userIdTextField; | |||
| private JTextField cardNameTextField; | |||
| private JPasswordField cardPasswdField; | |||
| private JComboBox cardStatusComboBox; | |||
| private JComboBox cardTypeComboBox; | |||
| private JTextField useTimesTextField; | |||
| private JCheckBox firstEnterCheckBox; | |||
| private JCheckBox enableCheckBox; | |||
| private DateChooserJButton startTimeBtn; | |||
| private DateChooserJButton endTimeBtn; | |||
| private JButton modifyBtn; | |||
| private JButton cancelBtn; | |||
| } | |||
| @@ -0,0 +1,711 @@ | |||
| package com.netsdk.demo.frame; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.*; | |||
| import com.netsdk.demo.module.*; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import javax.swing.*; | |||
| import javax.swing.border.EmptyBorder; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import java.awt.*; | |||
| import java.awt.event.*; | |||
| import java.util.*; | |||
| import java.util.List; | |||
| import java.util.concurrent.ExecutorService; | |||
| import java.util.concurrent.Executors; | |||
| /** | |||
| * 人数统计事件 demo | |||
| */ | |||
| class HumanNumberStatisticFrame extends JFrame { | |||
| private static final long serialVersionUID = 1L; | |||
| /* | |||
| * 界面、SDK初始化及登录 | |||
| */ | |||
| public HumanNumberStatisticFrame() { | |||
| setTitle(Res.string().getHumanNumberStatistic()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(1080, 560); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| LoginModule.init(disConnectCB, haveReConnectCB); // 打开工程,SDK初始化,注册断线和重连回调函数 | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| loginPanel = new LoginPanel(); | |||
| humanStatisticPanel = new HumanStatisticPanel(); | |||
| add(loginPanel, BorderLayout.NORTH); | |||
| add(humanStatisticPanel, BorderLayout.CENTER); | |||
| // 调用按钮登录事件 | |||
| loginPanel.addLoginBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if (loginPanel.checkLoginText()) { | |||
| if (login()) { | |||
| mainFrame = ToolKits.getFrame(e); | |||
| mainFrame.setTitle(Res.string().getHumanNumberStatistic() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| // 调用按钮登出事件 | |||
| loginPanel.addLogoutBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| mainFrame.setTitle(Res.string().getHumanNumberStatistic()); | |||
| logout(); | |||
| } | |||
| }); | |||
| // 注册窗体清出事件 | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandle); // 退出句柄 | |||
| FaceRecognitionModule.renderPrivateData(m_hPlayHandle, 0); // 关闭规则框 | |||
| VideoStateSummaryModule.detachAllVideoStatSummary(); // 退订事件 | |||
| LoginModule.logout(); // 退出 | |||
| LoginModule.cleanup(); // 关闭工程,释放资源 | |||
| dispose(); | |||
| // 返回主菜单 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /////////////////////////////// 登录相关 ////////////////////////////////////// | |||
| ////////////////////////////////////////////////////////////////////////////// | |||
| // 设备断线通知回调 | |||
| private static DisConnectCallBack disConnectCB = new DisConnectCallBack(); | |||
| // 网络连接恢复 | |||
| private static HaveReConnectCallBack haveReConnectCB = new HaveReConnectCallBack(); | |||
| private Vector<String> chnList = new Vector<String>(); | |||
| // 预览句柄 | |||
| public static NetSDKLib.LLong m_hPlayHandle = new NetSDKLib.LLong(0); | |||
| // 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数 | |||
| private static class DisConnectCallBack implements NetSDKLib.fDisConnect { | |||
| public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnectCallBack!\n", pchDVRIP, nDVRPort); | |||
| // 断线提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| mainFrame.setTitle(Res.string().getHumanNumberStatistic() + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 网络连接恢复,设备重连成功回调 | |||
| // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 | |||
| private static class HaveReConnectCallBack implements NetSDKLib.fHaveReConnect { | |||
| public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| // 重连提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| mainFrame.setTitle(Res.string().getHumanNumberStatistic() + " : " + Res.string().getOnline()); | |||
| } | |||
| }); | |||
| // 断线后需要重新订阅 | |||
| ExecutorService service = Executors.newSingleThreadExecutor(); | |||
| service.execute(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| if (b_RealPlay) { // 如果断前正在预览 | |||
| stopRealPlay(); // 退出预览 | |||
| realPlay(); // 重新开启预览 | |||
| } | |||
| if (b_Attachment) { // 如果断前正在订阅 | |||
| // 重订阅事件 | |||
| VideoStateSummaryModule.reAttachAllVideoStatSummary(humanNumberStatisticCB); | |||
| setAttachBtnTextEnable(); | |||
| } | |||
| } | |||
| }); | |||
| service.shutdown(); | |||
| } | |||
| } | |||
| // 登录 | |||
| public boolean login() { | |||
| if (LoginModule.login(loginPanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginPanel.portTextArea.getText()), | |||
| loginPanel.nameTextArea.getText(), | |||
| new String(loginPanel.passwordTextArea.getPassword()))) { | |||
| loginPanel.setButtonEnable(true); | |||
| setButtonEnable(true); | |||
| final int chanNum = LoginModule.m_stDeviceInfo.byChanNum; | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| // 更新列表长度 | |||
| int listSize = Math.max(chanNum, 32); | |||
| groupListPanel.remove(scrollPane); | |||
| groupListPanel.creatGroupInfoPanel(listSize); | |||
| // 登陆成功,将通道添加到控件 | |||
| for (int i = 0; i < chanNum; i++) { | |||
| chnList.add(Res.string().getChannel() + " " + String.valueOf(i + 1)); | |||
| SummaryInfo summaryInfo = new SummaryInfo(); | |||
| summaryInfo.nChannelID = i; | |||
| EventDisplay.dataList.add(summaryInfo); | |||
| } | |||
| chnComboBox.setModel(new DefaultComboBoxModel(chnList)); | |||
| setEnableAllInnerComponent(controlPanel, true); | |||
| EventDisplay.setEventInfo(groupInfoTable, EventDisplay.dataList); | |||
| } | |||
| }); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| // 登出 | |||
| public void logout() { | |||
| VideoStateSummaryModule.detachAllVideoStatSummary(); // 退订阅 | |||
| stopRealPlay(); //退出播放 | |||
| LoginModule.logout(); // 退出登录 | |||
| chnList.clear(); // 清除通道号列表 | |||
| EventDisplay.clearEventInfoList(); // 清除事件列表数据 | |||
| chnComboBox.setModel(new DefaultComboBoxModel()); | |||
| loginPanel.setButtonEnable(false); | |||
| setAttachBtnTextDisable(); | |||
| setEnableAllInnerComponent(controlPanel, false); | |||
| } | |||
| /////////////////////////////// 人数统计事件 //////////////////////////////// | |||
| //////////////////////////////////////////////////////////////////////////// | |||
| private static boolean b_RealPlay = false; | |||
| private static boolean b_Attachment = false; | |||
| /* | |||
| * 一级面板:人数统计控制面板 | |||
| */ | |||
| private class HumanStatisticPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public HumanStatisticPanel() { | |||
| setLayout(new BorderLayout()); | |||
| Dimension dim = getPreferredSize(); | |||
| dim.width = 320; | |||
| setPreferredSize(dim); | |||
| humanStatisticAttachPanel = new HumanStatisticControlPanel(); // 人数统计控制面板 | |||
| realPanel = new RealPanel(); // 实时显示面啊 | |||
| groupListPanel = new GroupListPanel(); // 事件展示面板 | |||
| add(humanStatisticAttachPanel, BorderLayout.NORTH); | |||
| add(realPanel, BorderLayout.EAST); | |||
| add(groupListPanel, BorderLayout.CENTER); | |||
| } | |||
| } | |||
| /* | |||
| * 二级面板: 控制面板 通道、码流设置,事件订阅 | |||
| */ | |||
| private class HumanStatisticControlPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public HumanStatisticControlPanel() { | |||
| BorderEx.set(this, Res.string().getHumanNumberStatisticAttach(), 2); | |||
| setLayout(new FlowLayout()); | |||
| /* 预览控制面板 */ | |||
| controlPanel = new Panel(); | |||
| add(controlPanel); | |||
| chnLabel = new JLabel(Res.string().getChannel()); | |||
| chnComboBox = new JComboBox(); | |||
| streamLabel = new JLabel(Res.string().getStreamType()); | |||
| String[] stream = {Res.string().getMasterStream(), Res.string().getSubStream()}; | |||
| streamComboBox = new JComboBox(stream); | |||
| realPlayBtn = new JButton(Res.string().getStartRealPlay()); | |||
| attachBtn = new JButton(Res.string().getAttach()); | |||
| clearBtn = new JButton(Res.string().getHumanNumberStatisticEventClearOSD()); | |||
| controlPanel.setLayout(new FlowLayout()); | |||
| controlPanel.add(chnLabel); | |||
| controlPanel.add(chnComboBox); | |||
| controlPanel.add(streamLabel); | |||
| controlPanel.add(streamComboBox); | |||
| controlPanel.add(realPlayBtn); | |||
| controlPanel.add(attachBtn); | |||
| controlPanel.add(clearBtn); | |||
| chnComboBox.setPreferredSize(new Dimension(90, 20)); | |||
| streamComboBox.setPreferredSize(new Dimension(120, 20)); | |||
| realPlayBtn.setPreferredSize(new Dimension(120, 20)); | |||
| attachBtn.setPreferredSize(new Dimension(120, 20)); | |||
| clearBtn.setPreferredSize(new Dimension(120, 20)); | |||
| chnComboBox.setEnabled(false); | |||
| streamComboBox.setEnabled(false); | |||
| realPlayBtn.setEnabled(false); | |||
| attachBtn.setEnabled(false); | |||
| clearBtn.setEnabled(false); | |||
| realPlayBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| realPlay(); | |||
| } | |||
| }); | |||
| attachBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| int channel = chnComboBox.getSelectedIndex(); | |||
| if (!VideoStateSummaryModule.channelAttached(channel)) { | |||
| if (VideoStateSummaryModule.attachVideoStatSummary(channel, humanNumberStatisticCB)) { | |||
| setAttachBtnTextEnable(); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } else { | |||
| if (VideoStateSummaryModule.detachVideoStatSummary(channel)) { | |||
| setAttachBtnTextDisable(); | |||
| SummaryInfo info = new SummaryInfo(); | |||
| info.nChannelID = channel; | |||
| EventDisplay.dataList.add(channel, info); | |||
| EventDisplay.dataList.remove(channel + 1); | |||
| EventDisplay.setEventInfo(groupInfoTable, EventDisplay.dataList); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| // 添加下拉框事件监听器 | |||
| chnComboBox.addItemListener(new ItemListener() { | |||
| @Override | |||
| public void itemStateChanged(ItemEvent e) { | |||
| if (e.getStateChange() == ItemEvent.SELECTED) { | |||
| int channel = chnComboBox.getSelectedIndex(); | |||
| if (VideoStateSummaryModule.channelAttached(channel)) { | |||
| setAttachBtnTextEnable(); | |||
| } else { | |||
| setAttachBtnTextDisable(); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| clearBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| clearSummaryInfo(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| private static void setRealPlayBtnTextEnable() { | |||
| b_RealPlay = true; | |||
| realPlayBtn.setText(Res.string().getStopRealPlay()); | |||
| } | |||
| private static void setRealPlayBtnTextDisable() { | |||
| b_RealPlay = false; | |||
| realPlayBtn.setText(Res.string().getStartRealPlay()); | |||
| } | |||
| private static void setAttachBtnTextEnable() { | |||
| b_Attachment = VideoStateSummaryModule.getM_hAttachMap().size() > 0; | |||
| attachBtn.setText(Res.string().getDetach()); | |||
| } | |||
| private static void setAttachBtnTextDisable() { | |||
| b_Attachment = VideoStateSummaryModule.getM_hAttachMap().size() > 0; | |||
| attachBtn.setText(Res.string().getAttach()); | |||
| } | |||
| private static void setButtonEnable(boolean bln) { | |||
| realPlayWindow.setEnabled(bln); | |||
| chnComboBox.setEnabled(bln); | |||
| streamComboBox.setEnabled(bln); | |||
| realPlayBtn.setEnabled(bln); | |||
| attachBtn.setEnabled(bln); | |||
| clearBtn.setEnabled(bln); | |||
| } | |||
| // 启用/禁用 Container 内所有组件 | |||
| public static void setEnableAllInnerComponent(Component container, boolean enable) { | |||
| for (Component component : getComponents(container)) { | |||
| component.setEnabled(enable); | |||
| } | |||
| } | |||
| // 获取 Swing Container 内所有的非 Container 组件 | |||
| public static Component[] getComponents(Component container) { | |||
| ArrayList<Component> list = null; | |||
| try { | |||
| list = new ArrayList<Component>(Arrays.asList( | |||
| ((Container) container).getComponents())); | |||
| for (int index = 0; index < list.size(); index++) { | |||
| list.addAll(Arrays.asList(getComponents(list.get(index)))); | |||
| } | |||
| } catch (ClassCastException e) { | |||
| list = new ArrayList<Component>(); | |||
| } | |||
| return list.toArray(new Component[0]); | |||
| } | |||
| private void clearSummaryInfo() { | |||
| VideoStateSummaryModule.clearVideoStateSummary(chnComboBox.getSelectedIndex()); | |||
| } | |||
| /* | |||
| * 二级面板:预览面板 | |||
| */ | |||
| private class RealPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public RealPanel() { | |||
| BorderEx.set(this, Res.string().getRealplay(), 2); | |||
| Dimension dim = this.getPreferredSize(); | |||
| dim.width = 420; | |||
| this.setPreferredSize(dim); | |||
| this.setLayout(new BorderLayout()); | |||
| realPlayPanel = new JPanel(); | |||
| add(realPlayPanel, BorderLayout.CENTER); | |||
| /************ 预览面板 **************/ | |||
| realPlayPanel.setLayout(new BorderLayout()); | |||
| realPlayPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| realPlayWindow = new Panel(); | |||
| realPlayWindow.setBackground(Color.GRAY); | |||
| realPlayWindow.setSize(480, 480); | |||
| realPlayPanel.add(realPlayWindow, BorderLayout.CENTER); | |||
| } | |||
| } | |||
| // 预览 | |||
| public static void realPlay() { | |||
| if (!b_RealPlay) { | |||
| m_hPlayHandle = RealPlayModule.startRealPlay( | |||
| chnComboBox.getSelectedIndex(), | |||
| streamComboBox.getSelectedIndex() == 0 ? 0 : 3, | |||
| realPlayWindow); | |||
| if (m_hPlayHandle.longValue() != 0) { // 正常状态下句柄不为空 | |||
| FaceRecognitionModule.renderPrivateData(m_hPlayHandle, 1); // 开启规则框 | |||
| realPlayWindow.repaint(); | |||
| chnComboBox.setEnabled(false); | |||
| streamComboBox.setEnabled(false); | |||
| setRealPlayBtnTextEnable(); | |||
| } | |||
| } else { | |||
| stopRealPlay(); | |||
| } | |||
| } | |||
| public static void stopRealPlay() { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandle); // 为空则说明失败,退出拉流 | |||
| FaceRecognitionModule.renderPrivateData(m_hPlayHandle, 0); // 关闭规则框 | |||
| realPlayWindow.repaint(); | |||
| chnComboBox.setEnabled(true); | |||
| streamComboBox.setEnabled(true); | |||
| setRealPlayBtnTextDisable(); | |||
| } | |||
| // 搜索数据列表 | |||
| public class GroupListPanel extends JPanel { | |||
| private Object[][] statisticData = null; // 人脸库列表 | |||
| private final String[] groupName = { | |||
| Res.string().getHumanNumberStatisticEventChannel(), | |||
| Res.string().getHumanNumberStatisticEventTime(), | |||
| Res.string().getHumanNumberStatisticEventHourIn(), | |||
| Res.string().getHumanNumberStatisticEventTodayIn(), | |||
| Res.string().getHumanNumberStatisticEventTotalIn(), | |||
| Res.string().getHumanNumberStatisticEventHourOut(), | |||
| Res.string().getHumanNumberStatisticEventTodayOut(), | |||
| Res.string().getHumanNumberStatisticEventTotalOut() | |||
| }; | |||
| private DefaultTableModel groupInfoModel; | |||
| public GroupListPanel() { | |||
| BorderEx.set(this, Res.string().getHumanNumberStatisticEventTitle(), 2); | |||
| setLayout(new BorderLayout()); | |||
| statisticData = new Object[32][9]; | |||
| creatGroupInfoPanel(32); | |||
| } | |||
| private void creatGroupInfoPanel(int listSize) { | |||
| statisticData = new Object[listSize][9]; // 人脸库列表集合修改 | |||
| groupInfoModel = new DefaultTableModel(statisticData, groupName); | |||
| groupInfoTable = new JTable(groupInfoModel) { | |||
| @Override // 不可编辑 | |||
| public boolean isCellEditable(int row, int column) { | |||
| return false; | |||
| } | |||
| }; | |||
| groupInfoTable.getColumnModel().getColumn(0).setPreferredWidth(10); | |||
| groupInfoTable.getColumnModel().getColumn(1).setPreferredWidth(80); | |||
| groupInfoTable.getColumnModel().getColumn(2).setPreferredWidth(10); | |||
| groupInfoTable.getColumnModel().getColumn(3).setPreferredWidth(10); | |||
| groupInfoTable.getColumnModel().getColumn(4).setPreferredWidth(10); | |||
| groupInfoTable.getColumnModel().getColumn(5).setPreferredWidth(10); | |||
| groupInfoTable.getColumnModel().getColumn(6).setPreferredWidth(10); | |||
| groupInfoTable.getColumnModel().getColumn(7).setPreferredWidth(10); | |||
| groupInfoTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行 | |||
| // 列表显示居中 | |||
| DefaultTableCellRenderer dCellRenderer = new DefaultTableCellRenderer(); | |||
| dCellRenderer.setHorizontalAlignment(JLabel.CENTER); | |||
| groupInfoTable.setDefaultRenderer(Object.class, dCellRenderer); | |||
| scrollPane = new JScrollPane(groupInfoTable); | |||
| this.add(scrollPane, BorderLayout.CENTER); | |||
| } | |||
| } | |||
| // 人数统计回调事件 | |||
| public static fHumanNumberStatisticCallBack humanNumberStatisticCB = fHumanNumberStatisticCallBack.getInstance(); | |||
| public static class fHumanNumberStatisticCallBack implements NetSDKLib.fVideoStatSumCallBack { | |||
| private static fHumanNumberStatisticCallBack instance = new fHumanNumberStatisticCallBack(); | |||
| public static fHumanNumberStatisticCallBack getInstance() { | |||
| return instance; | |||
| } | |||
| private EventTaskCommonQueue eventTaskQueue = new EventTaskCommonQueue(); | |||
| public fHumanNumberStatisticCallBack() { | |||
| eventTaskQueue.init(); | |||
| } | |||
| public void invoke(NetSDKLib.LLong lAttachHandle, NetSDKLib.NET_VIDEOSTAT_SUMMARY stVideoState, int dwBufLen, Pointer dwUser) { | |||
| SummaryInfo summaryInfo = new SummaryInfo( | |||
| stVideoState.nChannelID, stVideoState.stuTime.toStringTime(), | |||
| stVideoState.stuEnteredSubtotal.nToday, | |||
| stVideoState.stuEnteredSubtotal.nHour, | |||
| stVideoState.stuEnteredSubtotal.nTotal, | |||
| stVideoState.stuExitedSubtotal.nToday, | |||
| stVideoState.stuExitedSubtotal.nHour, | |||
| stVideoState.stuExitedSubtotal.nTotal); | |||
| System.out.printf("Channel[%d] GetTime[%s]\n" + | |||
| "People In Information[Total[%d] Hour[%d] Today[%d]]\n" + | |||
| "People Out Information[Total[%d] Hour[%d] Today[%d]]\n", | |||
| summaryInfo.nChannelID, summaryInfo.eventTime, | |||
| summaryInfo.enteredTotal, summaryInfo.enteredHour, summaryInfo.enteredToday, | |||
| summaryInfo.exitedTotal, summaryInfo.exitedHour, summaryInfo.exitedToday); | |||
| eventTaskQueue.addEvent(new EventDisplay(summaryInfo)); | |||
| } | |||
| } | |||
| private static class SummaryInfo { | |||
| public int nChannelID; | |||
| public String eventTime; | |||
| public int enteredToday; | |||
| public int enteredHour; | |||
| public int enteredTotal; | |||
| public int exitedToday; | |||
| public int exitedHour; | |||
| public int exitedTotal; | |||
| public SummaryInfo() { | |||
| } | |||
| public SummaryInfo(int nChannelID, String eventTime, | |||
| int enteredToday, int enteredHour, | |||
| int enteredTotal, int exitedToday, | |||
| int exitedHour, int exitedTotal) { | |||
| this.nChannelID = nChannelID; | |||
| this.eventTime = eventTime; | |||
| this.enteredToday = enteredToday; | |||
| this.enteredHour = enteredHour; | |||
| this.enteredTotal = enteredTotal; | |||
| this.exitedToday = exitedToday; | |||
| this.exitedHour = exitedHour; | |||
| this.exitedTotal = exitedTotal; | |||
| } | |||
| } | |||
| private static class EventDisplay implements EventTaskHandler { | |||
| private static List<SummaryInfo> dataList = new LinkedList<SummaryInfo>(); | |||
| private int getMaxSize() { | |||
| int channelNum = LoginModule.m_stDeviceInfo.byChanNum; | |||
| return Math.max(channelNum, 32); | |||
| } | |||
| private static final Object lockObj = new Object(); | |||
| private final SummaryInfo summaryInfo; | |||
| public EventDisplay(SummaryInfo Info) { | |||
| this.summaryInfo = Info; | |||
| } | |||
| @Override | |||
| public void eventTaskProcess() { | |||
| InsertOrUpdateEventInfo(summaryInfo); | |||
| } | |||
| private void InsertOrUpdateEventInfo(SummaryInfo summaryInfo) { | |||
| synchronized (lockObj) { | |||
| dataList.add(summaryInfo.nChannelID, summaryInfo); | |||
| dataList.remove(summaryInfo.nChannelID + 1); | |||
| if (dataList.size() > getMaxSize()) { | |||
| dataList.remove(getMaxSize()); | |||
| } | |||
| setEventInfo(groupInfoTable, dataList); | |||
| } | |||
| } | |||
| private static void setEventInfo(JTable groupInfoTable, List<SummaryInfo> dataList) { | |||
| clearTableModel(groupInfoTable); | |||
| for (int i = 0; i < dataList.size(); i++) { | |||
| groupInfoTable.setValueAt(dataList.get(i).nChannelID + 1, i, 0); | |||
| groupInfoTable.setValueAt(dataList.get(i).eventTime, i, 1); | |||
| groupInfoTable.setValueAt(dataList.get(i).enteredHour, i, 2); | |||
| groupInfoTable.setValueAt(dataList.get(i).enteredToday, i, 3); | |||
| groupInfoTable.setValueAt(dataList.get(i).enteredTotal, i, 4); | |||
| groupInfoTable.setValueAt(dataList.get(i).exitedHour, i, 5); | |||
| groupInfoTable.setValueAt(dataList.get(i).exitedToday, i, 6); | |||
| groupInfoTable.setValueAt(dataList.get(i).exitedTotal, i, 7); | |||
| } | |||
| } | |||
| // 清空 DefaultTableModel | |||
| public static void clearTableModel(JTable jTableModel) { | |||
| int rowCount = jTableModel.getRowCount(); | |||
| int columnCount = jTableModel.getColumnCount(); | |||
| //清空DefaultTableModel中的内容 | |||
| for (int i = 0; i < rowCount; i++)//表格中的行数 | |||
| { | |||
| for (int j = 0; j < columnCount; j++) {//表格中的列数 | |||
| jTableModel.setValueAt(" ", i, j);//逐个清空 | |||
| } | |||
| } | |||
| } | |||
| private static void clearEventInfoList() { | |||
| synchronized (lockObj) { | |||
| dataList.clear(); | |||
| setEventInfo(groupInfoTable, dataList); | |||
| } | |||
| } | |||
| } | |||
| /////////////////////////////// 界面控件定义 //////////////////////////////// | |||
| //////////////////////////////////////////////////////////////////////////// | |||
| /********************************************************************** | |||
| * 主界面窗口(mainFrame): mainFrame | |||
| * 1) 登录(login): loginPanel | |||
| * 2) 人数事件统计(humanStatistic): humanStatisticPanel | |||
| * (1) 控制面板(HumanStatisticAttach): HumanStatisticControlPanel | |||
| * (2) 预览(realPlay): realPanel | |||
| * (3) 事件信息展示面板(eventInfo): groupListPanel | |||
| **********************************************************************/ | |||
| ///////////////////// 主面板 ///////////////////// | |||
| private static JFrame mainFrame = new JFrame(); | |||
| ///////////////////// 一级面板 ///////////////////// | |||
| /* 登录面板 */ | |||
| private LoginPanel loginPanel; | |||
| /* 人数统计面板 */ | |||
| private HumanStatisticPanel humanStatisticPanel; | |||
| ///////////////////// 二级面板 ///////////////////// | |||
| /* 人数统计面板 */ | |||
| private HumanStatisticControlPanel humanStatisticAttachPanel; | |||
| private Panel controlPanel; | |||
| private JLabel chnLabel; | |||
| private static JComboBox chnComboBox; | |||
| private JLabel streamLabel; | |||
| private static JComboBox streamComboBox; | |||
| private static JButton realPlayBtn; | |||
| private static JButton attachBtn; | |||
| private static JButton clearBtn; | |||
| /* 实时预览面板 */ | |||
| private RealPanel realPanel; | |||
| private JPanel realPlayPanel; | |||
| private static Panel realPlayWindow; | |||
| /* 事件数据展示面板 */ | |||
| private static JTable groupInfoTable; | |||
| private GroupListPanel groupListPanel; | |||
| private JScrollPane scrollPane; | |||
| } | |||
| public class HumanNumberStatistic { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| HumanNumberStatisticFrame demo = new HumanNumberStatisticFrame(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| @@ -0,0 +1,23 @@ | |||
| package com.netsdk.demo.frame; | |||
| import javax.swing.SwingUtilities; | |||
| import com.netsdk.common.SwitchLanguage; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| public class Main { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| if(NetSDKLib.NETSDK_INSTANCE != null | |||
| && NetSDKLib.CONFIG_INSTANCE != null) { | |||
| System.setProperty("java.awt.im.style", "on-the-spot"); // 去除中文输入弹出框 | |||
| SwitchLanguage demo = new SwitchLanguage(); | |||
| demo.setVisible(true); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| @@ -0,0 +1,956 @@ | |||
| package com.netsdk.demo.frame; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Color; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.GridLayout; | |||
| import java.awt.Panel; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.MouseEvent; | |||
| import java.awt.event.MouseListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.awt.image.BufferedImage; | |||
| import java.io.ByteArrayInputStream; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.util.Vector; | |||
| import javax.imageio.ImageIO; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.UIManager; | |||
| import javax.swing.border.EmptyBorder; | |||
| import com.netsdk.common.*; | |||
| import com.netsdk.demo.module.*; | |||
| import com.netsdk.lib.*; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.sun.jna.CallbackThreadInitializer; | |||
| import com.sun.jna.Native; | |||
| import com.sun.jna.Pointer; | |||
| /** | |||
| * 实时预览Demo | |||
| */ | |||
| class PTZControlFrame extends JFrame{ | |||
| private static final long serialVersionUID = 1L; | |||
| private Vector<String> chnlist = new Vector<String>(); | |||
| private boolean b_realplay = false; | |||
| // 设备断线通知回调 | |||
| private static DisConnect disConnect = new DisConnect(); | |||
| // 网络连接恢复 | |||
| private static HaveReConnect haveReConnect = new HaveReConnect(); | |||
| // 预览句柄 | |||
| public static LLong m_hPlayHandle = new LLong(0); | |||
| // 获取界面窗口 | |||
| private static JFrame frame = new JFrame(); | |||
| public PTZControlFrame() { | |||
| setTitle(Res.string().getPTZ()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(800, 560); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| loginPanel = new LoginPanel(); | |||
| realPanel = new RealPanel(); | |||
| ptz_picPanel = new PTZ_PICPanel(); | |||
| add(loginPanel, BorderLayout.NORTH); | |||
| add(realPanel, BorderLayout.CENTER); | |||
| add(ptz_picPanel, BorderLayout.EAST); | |||
| loginPanel.addLoginBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(loginPanel.checkLoginText()) { | |||
| if(login()) { | |||
| frame = ToolKits.getFrame(e); | |||
| frame.setTitle(Res.string().getPTZ() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| loginPanel.addLogoutBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| frame.setTitle(Res.string().getPTZ()); | |||
| logout(); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandle); | |||
| LoginModule.logout(); | |||
| LoginModule.cleanup(); // 关闭工程,释放资源 | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /////////////////面板/////////////////// | |||
| // 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数 | |||
| private static class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| // 断线提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getPTZ() + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 网络连接恢复,设备重连成功回调 | |||
| // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 | |||
| private static class HaveReConnect implements NetSDKLib.fHaveReConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| // 重连提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getPTZ() + " : " + Res.string().getOnline()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 登录 | |||
| public boolean login() { | |||
| Native.setCallbackThreadInitializer(m_SnapReceiveCB, | |||
| new CallbackThreadInitializer(false, false, "snapPicture callback thread")); | |||
| if(LoginModule.login(loginPanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginPanel.portTextArea.getText()), | |||
| loginPanel.nameTextArea.getText(), | |||
| new String(loginPanel.passwordTextArea.getPassword()))) { | |||
| loginPanel.setButtonEnable(true); | |||
| setButtonEnable(true); | |||
| for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) { | |||
| chnlist.add(Res.string().getChannel() + " " + String.valueOf(i)); | |||
| } | |||
| // 登陆成功,将通道添加到控件 | |||
| chnComboBox.setModel(new DefaultComboBoxModel(chnlist)); | |||
| CapturePictureModule.setSnapRevCallBack(m_SnapReceiveCB); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| // 登出 | |||
| public void logout() { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandle); | |||
| LoginModule.logout(); | |||
| loginPanel.setButtonEnable(false); | |||
| setButtonEnable(false); | |||
| realPlayWindow.repaint(); | |||
| pictureShowWindow.setOpaque(true); | |||
| pictureShowWindow.repaint(); | |||
| b_realplay = false; | |||
| realplayBtn.setText(Res.string().getStartRealPlay()); | |||
| for(int i = 0; i < LoginModule.m_stDeviceInfo.byChanNum; i++) { | |||
| chnlist.clear(); | |||
| } | |||
| chnComboBox.setModel(new DefaultComboBoxModel()); | |||
| } | |||
| /* | |||
| * 预览界面通道、码流设置 以及抓图面板 | |||
| */ | |||
| private class RealPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public RealPanel() { | |||
| BorderEx.set(this, Res.string().getRealplay(), 2); | |||
| setLayout(new BorderLayout()); | |||
| channelPanel = new Panel(); | |||
| realplayPanel = new JPanel(); | |||
| add(channelPanel, BorderLayout.SOUTH); | |||
| add(realplayPanel, BorderLayout.CENTER); | |||
| /************ 预览面板 **************/ | |||
| realplayPanel.setLayout(new BorderLayout()); | |||
| realplayPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| realPlayWindow = new Panel(); | |||
| realPlayWindow.setBackground(Color.GRAY); | |||
| realplayPanel.add(realPlayWindow, BorderLayout.CENTER); | |||
| /************ 通道、码流面板 **************/ | |||
| chnlabel = new JLabel(Res.string().getChannel()); | |||
| chnComboBox = new JComboBox(); | |||
| streamLabel = new JLabel(Res.string().getStreamType()); | |||
| String[] stream = {Res.string().getMasterStream(), Res.string().getSubStream()}; | |||
| streamComboBox = new JComboBox(stream); | |||
| realplayBtn = new JButton(Res.string().getStartRealPlay()); | |||
| channelPanel.setLayout(new FlowLayout()); | |||
| channelPanel.add(chnlabel); | |||
| channelPanel.add(chnComboBox); | |||
| channelPanel.add(streamLabel); | |||
| channelPanel.add(streamComboBox); | |||
| channelPanel.add(realplayBtn); | |||
| chnComboBox.setPreferredSize(new Dimension(90, 20)); | |||
| streamComboBox.setPreferredSize(new Dimension(90, 20)); | |||
| realplayBtn.setPreferredSize(new Dimension(120, 20)); | |||
| realPlayWindow.setEnabled(false); | |||
| chnComboBox.setEnabled(false); | |||
| streamComboBox.setEnabled(false); | |||
| realplayBtn.setEnabled(false); | |||
| realplayBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| realplay(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 预览 | |||
| public void realplay() { | |||
| if(!b_realplay) { | |||
| m_hPlayHandle = RealPlayModule.startRealPlay(chnComboBox.getSelectedIndex(), | |||
| streamComboBox.getSelectedIndex()==0? 0:3, | |||
| realPlayWindow); | |||
| if(m_hPlayHandle.longValue() != 0) { | |||
| realPlayWindow.repaint(); | |||
| b_realplay = true; | |||
| chnComboBox.setEnabled(false); | |||
| streamComboBox.setEnabled(false); | |||
| realplayBtn.setText(Res.string().getStopRealPlay()); | |||
| } | |||
| } else { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandle); | |||
| realPlayWindow.repaint(); | |||
| b_realplay = false; | |||
| chnComboBox.setEnabled(true); | |||
| streamComboBox.setEnabled(true); | |||
| realplayBtn.setText(Res.string().getStartRealPlay()); | |||
| } | |||
| } | |||
| /* | |||
| * 抓图显示与云台控制面板 | |||
| */ | |||
| private class PTZ_PICPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public PTZ_PICPanel() { | |||
| setLayout(new BorderLayout()); | |||
| Dimension dim = getPreferredSize(); | |||
| dim.width = 320; | |||
| setPreferredSize(dim); | |||
| picPanel = new PICPanel(); // 图片显示面板 | |||
| ptzPanel = new PTZPanel(); // 云台面板 | |||
| add(picPanel, BorderLayout.CENTER); | |||
| add(ptzPanel, BorderLayout.SOUTH); | |||
| } | |||
| } | |||
| /* | |||
| * 抓图显示面板 | |||
| */ | |||
| private class PICPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public PICPanel() { | |||
| BorderEx.set(this, Res.string().getCapturePicture(), 2); | |||
| setLayout(new BorderLayout()); | |||
| pictureShowPanel = new JPanel(); | |||
| snapPanel = new JPanel(); | |||
| add(pictureShowPanel, BorderLayout.CENTER); | |||
| add(snapPanel, BorderLayout.SOUTH); | |||
| /************** 抓图按钮 ************/ | |||
| snapPanel.setLayout(new BorderLayout()); | |||
| snapPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| snapBtn = new JButton(Res.string().getRemoteCapture()); | |||
| snapBtn.setPreferredSize(new Dimension(40, 23)); | |||
| snapPanel.add(snapBtn, BorderLayout.CENTER); | |||
| snapBtn.setEnabled(false); | |||
| /************** 图片显示 ************/ | |||
| pictureShowPanel.setLayout(new BorderLayout()); | |||
| pictureShowPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| pictureShowWindow = new PaintPanel(); | |||
| pictureShowPanel.add(pictureShowWindow, BorderLayout.CENTER); | |||
| snapBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| if(!CapturePictureModule.remoteCapturePicture(chnComboBox.getSelectedIndex())) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /* | |||
| * 云台控制面板 | |||
| */ | |||
| private class PTZPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public PTZPanel() { | |||
| BorderEx.set(this, Res.string().getPTZControl(), 2); | |||
| setPreferredSize(new Dimension(40, 205)); | |||
| setLayout(new GridLayout(2, 1)); | |||
| directionPanel = new JPanel(); | |||
| JPanel panel1 = new JPanel(); | |||
| JPanel panel2 = new JPanel(); | |||
| ptzCtrlPanel = new JPanel(); | |||
| add(directionPanel); | |||
| add(ptzCtrlPanel); | |||
| directionPanel.setLayout(new BorderLayout()); | |||
| directionPanel.add(panel1, BorderLayout.NORTH); | |||
| directionPanel.add(panel2, BorderLayout.CENTER); | |||
| /*************** 云台方向 **************/ | |||
| panel1.setLayout(new BorderLayout()); | |||
| panel1.setBorder(new EmptyBorder(0, 5, 0, 5)); | |||
| panel2.setLayout(new GridLayout(3, 3)); | |||
| panel2.setBorder(new EmptyBorder(0, 5, 0, 5)); | |||
| leftUpBtn = new JButton(Res.string().getLeftUp()); | |||
| upBtn = new JButton(Res.string().getUp()); | |||
| rightUpBtn = new JButton(Res.string().getRightUp()); | |||
| leftBtn = new JButton(Res.string().getLeft()); | |||
| rightBtn = new JButton(Res.string().getRight()); | |||
| leftDownBtn = new JButton(Res.string().getLeftDown()); | |||
| downBtn = new JButton(Res.string().getDown()); | |||
| rightDownBtn = new JButton(Res.string().getRightDown()); | |||
| operateJLabel = new JLabel("", JLabel.CENTER); | |||
| String[] speed = {Res.string().getSpeed() + " 1", | |||
| Res.string().getSpeed() + " 2", | |||
| Res.string().getSpeed() + " 3", | |||
| Res.string().getSpeed() + " 4", | |||
| Res.string().getSpeed() + " 5", | |||
| Res.string().getSpeed() + " 6", | |||
| Res.string().getSpeed() + " 7", | |||
| Res.string().getSpeed() + " 8"}; | |||
| speedComboBox = new JComboBox(speed); | |||
| speedComboBox.setSelectedIndex(4); | |||
| speedComboBox.setPreferredSize(new Dimension(40, 21)); | |||
| panel1.add(speedComboBox, BorderLayout.CENTER); | |||
| panel2.add(leftUpBtn); | |||
| panel2.add(upBtn); | |||
| panel2.add(rightUpBtn); | |||
| panel2.add(leftBtn); | |||
| panel2.add(operateJLabel); | |||
| panel2.add(rightBtn); | |||
| panel2.add(leftDownBtn); | |||
| panel2.add(downBtn); | |||
| panel2.add(rightDownBtn); | |||
| leftUpBtn.setEnabled(false); | |||
| upBtn.setEnabled(false); | |||
| rightUpBtn.setEnabled(false); | |||
| leftBtn.setEnabled(false); | |||
| rightBtn.setEnabled(false); | |||
| leftDownBtn.setEnabled(false); | |||
| downBtn.setEnabled(false); | |||
| rightDownBtn.setEnabled(false); | |||
| speedComboBox.setEnabled(false); | |||
| /*************** 变焦、变倍、光圈 **************/ | |||
| ptzCtrlPanel.setLayout(new GridLayout(3, 2)); | |||
| ptzCtrlPanel.setBorder(new EmptyBorder(15, 5, 5, 5)); | |||
| zoomAddBtn = new JButton(Res.string().getZoomAdd()); | |||
| zoomDecBtn = new JButton(Res.string().getZoomDec()); | |||
| focusAddBtn = new JButton(Res.string().getFocusAdd()); | |||
| focusDecBtn = new JButton(Res.string().getFocusDec()); | |||
| irisAddBtn = new JButton(Res.string().getIrisAdd()); | |||
| irisDecBtn = new JButton(Res.string().getIrisDec()); | |||
| ptzCtrlPanel.add(zoomAddBtn); | |||
| ptzCtrlPanel.add(zoomDecBtn); | |||
| ptzCtrlPanel.add(focusAddBtn); | |||
| ptzCtrlPanel.add(focusDecBtn); | |||
| ptzCtrlPanel.add(irisAddBtn); | |||
| ptzCtrlPanel.add(irisDecBtn); | |||
| zoomAddBtn.setEnabled(false); | |||
| zoomDecBtn.setEnabled(false); | |||
| focusAddBtn.setEnabled(false); | |||
| focusDecBtn.setEnabled(false); | |||
| irisAddBtn.setEnabled(false); | |||
| irisDecBtn.setEnabled(false); | |||
| // 向上 | |||
| upBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlUpStart(chnComboBox.getSelectedIndex(), | |||
| 0, | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlUpEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 向下 | |||
| downBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlDownStart(chnComboBox.getSelectedIndex(), | |||
| 0, | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlDownEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 向左 | |||
| leftBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlLeftStart(chnComboBox.getSelectedIndex(), | |||
| 0, | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlLeftEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 向右 | |||
| rightBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlRightStart(chnComboBox.getSelectedIndex(), | |||
| 0, | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlRightEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 向左上 | |||
| leftUpBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlLeftUpStart(chnComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlLeftUpEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 向右上 | |||
| rightUpBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlRightUpStart(chnComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlRightUpEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 向左下 | |||
| leftDownBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlLeftDownStart(chnComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlLeftDownEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 向右下 | |||
| rightDownBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlRightDownStart(chnComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlRightDownEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 变倍+ | |||
| zoomAddBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlZoomAddStart(chnComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlZoomAddEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 变倍- | |||
| zoomDecBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlZoomDecStart(chnComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlZoomDecEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 变焦+ | |||
| focusAddBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlFocusAddStart(chnComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlFocusAddEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 变焦- | |||
| focusDecBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlFocusDecStart(chnComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlFocusDecEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 光圈+ | |||
| irisAddBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlIrisAddStart(chnComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlIrisAddEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| // 光圈- | |||
| irisDecBtn.addMouseListener(new MouseListener() { | |||
| @Override | |||
| public void mouseExited(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseEntered(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| } | |||
| @Override | |||
| public void mousePressed(MouseEvent e) { | |||
| if(PtzControlModule.ptzControlIrisDecStart(chnComboBox.getSelectedIndex(), | |||
| speedComboBox.getSelectedIndex())) { | |||
| operateJLabel.setText(Res.string().getSucceed()); | |||
| } else { | |||
| operateJLabel.setText(Res.string().getFailed()); | |||
| } | |||
| } | |||
| @Override | |||
| public void mouseReleased(MouseEvent e) { | |||
| PtzControlModule.ptzControlIrisDecEnd(chnComboBox.getSelectedIndex()); | |||
| operateJLabel.setText(""); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| public fSnapReceiveCB m_SnapReceiveCB = new fSnapReceiveCB(); | |||
| public class fSnapReceiveCB implements NetSDKLib.fSnapRev{ | |||
| BufferedImage bufferedImage = null; | |||
| public void invoke( LLong lLoginID, Pointer pBuf, int RevLen, int EncodeType, int CmdSerial, Pointer dwUser) { | |||
| if(pBuf != null && RevLen > 0) { | |||
| String strFileName = SavePath.getSavePath().getSaveCapturePath(); | |||
| System.out.println("strFileName = " + strFileName); | |||
| byte[] buf = pBuf.getByteArray(0, RevLen); | |||
| ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf); | |||
| try { | |||
| bufferedImage = ImageIO.read(byteArrInput); | |||
| if(bufferedImage == null) { | |||
| return; | |||
| } | |||
| ImageIO.write(bufferedImage, "jpg", new File(strFileName)); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 界面显示抓图 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| pictureShowWindow.setOpaque(false); | |||
| pictureShowWindow.setImage(bufferedImage); | |||
| pictureShowWindow.repaint(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| } | |||
| private void setButtonEnable(boolean bln) { | |||
| snapBtn.setEnabled(bln); | |||
| leftUpBtn.setEnabled(bln); | |||
| upBtn.setEnabled(bln); | |||
| rightUpBtn.setEnabled(bln); | |||
| leftBtn.setEnabled(bln); | |||
| rightBtn.setEnabled(bln); | |||
| leftDownBtn.setEnabled(bln); | |||
| downBtn.setEnabled(bln); | |||
| rightDownBtn.setEnabled(bln); | |||
| zoomAddBtn.setEnabled(bln); | |||
| zoomDecBtn.setEnabled(bln); | |||
| focusAddBtn.setEnabled(bln); | |||
| focusDecBtn.setEnabled(bln); | |||
| irisAddBtn.setEnabled(bln); | |||
| irisDecBtn.setEnabled(bln); | |||
| speedComboBox.setEnabled(bln); | |||
| realPlayWindow.setEnabled(bln); | |||
| chnComboBox.setEnabled(bln); | |||
| streamComboBox.setEnabled(bln); | |||
| realplayBtn.setEnabled(bln); | |||
| } | |||
| /* | |||
| * 登录 | |||
| */ | |||
| private LoginPanel loginPanel; | |||
| /* | |||
| * 预览 | |||
| */ | |||
| private RealPanel realPanel; | |||
| private JPanel realplayPanel; | |||
| private Panel realPlayWindow; | |||
| private Panel channelPanel; | |||
| private JLabel chnlabel; | |||
| private JComboBox chnComboBox; | |||
| private JLabel streamLabel; | |||
| private JComboBox streamComboBox; | |||
| private JButton realplayBtn; | |||
| private JButton snapBtn; | |||
| /* | |||
| * 抓图与云台 | |||
| */ | |||
| private PTZ_PICPanel ptz_picPanel; | |||
| private PICPanel picPanel; | |||
| private JPanel pictureShowPanel; | |||
| private JPanel snapPanel; | |||
| private PaintPanel pictureShowWindow; | |||
| /* | |||
| * 云台 | |||
| */ | |||
| private PTZPanel ptzPanel; | |||
| private JPanel directionPanel; | |||
| private JPanel ptzCtrlPanel; | |||
| private JButton leftUpBtn; | |||
| private JButton upBtn; | |||
| private JButton rightUpBtn; | |||
| private JButton leftBtn; | |||
| private JButton rightBtn; | |||
| private JButton leftDownBtn; | |||
| private JButton downBtn; | |||
| private JButton rightDownBtn; | |||
| private JComboBox speedComboBox; | |||
| private JLabel operateJLabel; | |||
| private JButton zoomAddBtn; | |||
| private JButton zoomDecBtn; | |||
| private JButton focusAddBtn; | |||
| private JButton focusDecBtn; | |||
| private JButton irisAddBtn; | |||
| private JButton irisDecBtn; | |||
| } | |||
| public class PTZControl { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| PTZControlFrame demo = new PTZControlFrame(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| @@ -0,0 +1,420 @@ | |||
| package com.netsdk.demo.frame; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Color; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.GridLayout; | |||
| import java.awt.Panel; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.util.Vector; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.UIManager; | |||
| import javax.swing.border.EmptyBorder; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.*; | |||
| import com.netsdk.demo.module.*; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.ToolKits; | |||
| class RealPlayFrame extends JFrame{ | |||
| private static final long serialVersionUID = 1L; | |||
| private Vector<String> chnlist = new Vector<String>(); | |||
| private boolean isrealplayOne = false; | |||
| private boolean isrealplayTwo = false; | |||
| // 设备断线通知回调 | |||
| private static DisConnect disConnect = new DisConnect(); | |||
| // 网络连接恢复 | |||
| private static HaveReConnect haveReConnect = new HaveReConnect(); | |||
| // 预览句柄 | |||
| public static LLong m_hPlayHandleOne = new LLong(0); | |||
| public static LLong m_hPlayHandleTwo = new LLong(0); | |||
| // 获取界面窗口 | |||
| private static JFrame frame = new JFrame(); | |||
| public RealPlayFrame() { | |||
| setTitle(Res.string().getRealplay()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(800, 560); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| loginPanel = new LoginPanel(); | |||
| realPanel = new JPanel(); | |||
| add(loginPanel, BorderLayout.NORTH); | |||
| add(realPanel, BorderLayout.CENTER); | |||
| // 预览面板 | |||
| realPanelOne = new RealPanelOne(); | |||
| realPanelTwo = new RealPanelTwo(); | |||
| realPanel.setLayout(new GridLayout(1, 2)); | |||
| realPanel.add(realPanelOne); | |||
| realPanel.add(realPanelTwo); | |||
| loginPanel.addLoginBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(loginPanel.checkLoginText()) { | |||
| if(login()) { | |||
| frame = ToolKits.getFrame(e); | |||
| frame.setTitle(Res.string().getRealplay() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| loginPanel.addLogoutBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| frame.setTitle(Res.string().getRealplay()); | |||
| logout(); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleOne); | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleTwo); | |||
| LoginModule.logout(); | |||
| LoginModule.cleanup(); // 关闭工程,释放资源 | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /////////////////面板/////////////////// | |||
| // 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数 | |||
| private static class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| // 断线提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getRealplay() + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 网络连接恢复,设备重连成功回调 | |||
| // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 | |||
| private static class HaveReConnect implements NetSDKLib.fHaveReConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| // 重连提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getRealplay() + " : " + Res.string().getOnline()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 登录 | |||
| public boolean login() { | |||
| if(LoginModule.login(loginPanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginPanel.portTextArea.getText()), | |||
| loginPanel.nameTextArea.getText(), | |||
| new String(loginPanel.passwordTextArea.getPassword()))) { | |||
| loginPanel.setButtonEnable(true); | |||
| setButtonEnable(true); | |||
| for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) { | |||
| chnlist.add(Res.string().getChannel() + " " + String.valueOf(i)); | |||
| } | |||
| // 登陆成功,将通道添加到控件 | |||
| chnComboBoxOne.setModel(new DefaultComboBoxModel(chnlist)); | |||
| chnComboBoxTwo.setModel(new DefaultComboBoxModel(chnlist)); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| // 登出 | |||
| public void logout() { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleOne); | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleTwo); | |||
| LoginModule.logout(); | |||
| loginPanel.setButtonEnable(false); | |||
| setButtonEnable(false); | |||
| realPlayWindowOne.repaint(); | |||
| realPlayWindowTwo.repaint(); | |||
| isrealplayOne = false; | |||
| realplayBtnOne.setText(Res.string().getStartRealPlay()); | |||
| isrealplayTwo = false; | |||
| realplayBtnTwo.setText(Res.string().getStartRealPlay()); | |||
| for(int i = 0; i < LoginModule.m_stDeviceInfo.byChanNum; i++) { | |||
| chnlist.clear(); | |||
| } | |||
| chnComboBoxOne.setModel(new DefaultComboBoxModel()); | |||
| chnComboBoxTwo.setModel(new DefaultComboBoxModel()); | |||
| } | |||
| /* | |||
| * 预览界面通道、码流设置 以及抓图面板 | |||
| */ | |||
| private class RealPanelOne extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public RealPanelOne() { | |||
| BorderEx.set(this, Res.string().getRealplay(), 2); | |||
| setLayout(new BorderLayout()); | |||
| channelPanelOne = new Panel(); | |||
| realplayPanelOne = new JPanel(); | |||
| add(channelPanelOne, BorderLayout.NORTH); | |||
| add(realplayPanelOne, BorderLayout.CENTER); | |||
| /************ 预览面板 **************/ | |||
| realplayPanelOne.setLayout(new BorderLayout()); | |||
| realplayPanelOne.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| realPlayWindowOne = new Panel(); | |||
| realPlayWindowOne.setBackground(Color.GRAY); | |||
| realplayPanelOne.add(realPlayWindowOne, BorderLayout.CENTER); | |||
| /************ 通道、码流面板 **************/ | |||
| chnlabelOne = new JLabel(Res.string().getChn()); | |||
| chnComboBoxOne = new JComboBox(); | |||
| streamLabelOne = new JLabel(Res.string().getStreamType()); | |||
| String[] stream = {Res.string().getMasterStream(), Res.string().getSubStream()}; | |||
| streamComboBoxOne = new JComboBox(stream); | |||
| realplayBtnOne = new JButton(Res.string().getStartRealPlay()); | |||
| channelPanelOne.setLayout(new FlowLayout()); | |||
| channelPanelOne.add(chnlabelOne); | |||
| channelPanelOne.add(chnComboBoxOne); | |||
| channelPanelOne.add(streamLabelOne); | |||
| channelPanelOne.add(streamComboBoxOne); | |||
| channelPanelOne.add(realplayBtnOne); | |||
| chnComboBoxOne.setPreferredSize(new Dimension(80, 20)); | |||
| streamComboBoxOne.setPreferredSize(new Dimension(95, 20)); | |||
| realplayBtnOne.setPreferredSize(new Dimension(115, 20)); | |||
| realPlayWindowOne.setEnabled(false); | |||
| chnComboBoxOne.setEnabled(false); | |||
| streamComboBoxOne.setEnabled(false); | |||
| realplayBtnOne.setEnabled(false); | |||
| realplayBtnOne.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| realplayOne(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 预览 | |||
| public void realplayOne() { | |||
| if(!isrealplayOne) { | |||
| m_hPlayHandleOne = RealPlayModule.startRealPlay(chnComboBoxOne.getSelectedIndex(), | |||
| streamComboBoxOne.getSelectedIndex()==0? 0:3, | |||
| realPlayWindowOne); | |||
| if(m_hPlayHandleOne.longValue() != 0) { | |||
| realPlayWindowOne.repaint(); | |||
| isrealplayOne = true; | |||
| chnComboBoxOne.setEnabled(false); | |||
| streamComboBoxOne.setEnabled(false); | |||
| realplayBtnOne.setText(Res.string().getStopRealPlay()); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } else { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleOne); | |||
| realPlayWindowOne.repaint(); | |||
| isrealplayOne = false; | |||
| chnComboBoxOne.setEnabled(true); | |||
| streamComboBoxOne.setEnabled(true); | |||
| realplayBtnOne.setText(Res.string().getStartRealPlay()); | |||
| } | |||
| } | |||
| private class RealPanelTwo extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public RealPanelTwo() { | |||
| BorderEx.set(this, Res.string().getRealplay(), 2); | |||
| setLayout(new BorderLayout()); | |||
| channelPanelTwo = new Panel(); | |||
| realplayPanelTwo = new JPanel(); | |||
| add(channelPanelTwo, BorderLayout.NORTH); | |||
| add(realplayPanelTwo, BorderLayout.CENTER); | |||
| /************ 预览面板 **************/ | |||
| realplayPanelTwo.setLayout(new BorderLayout()); | |||
| realplayPanelTwo.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| realPlayWindowTwo = new Panel(); | |||
| realPlayWindowTwo.setBackground(Color.GRAY); | |||
| realplayPanelTwo.add(realPlayWindowTwo, BorderLayout.CENTER); | |||
| /************ 通道、码流面板 **************/ | |||
| chnlabelTwo = new JLabel(Res.string().getChn()); | |||
| chnComboBoxTwo = new JComboBox(); | |||
| streamLabelTwo = new JLabel(Res.string().getStreamType()); | |||
| String[] stream = {Res.string().getMasterStream(), Res.string().getSubStream()}; | |||
| streamComboBoxTwo = new JComboBox(stream); | |||
| realplayBtnTwo = new JButton(Res.string().getStartRealPlay()); | |||
| channelPanelTwo.setLayout(new FlowLayout()); | |||
| channelPanelTwo.add(chnlabelTwo); | |||
| channelPanelTwo.add(chnComboBoxTwo); | |||
| channelPanelTwo.add(streamLabelTwo); | |||
| channelPanelTwo.add(streamComboBoxTwo); | |||
| channelPanelTwo.add(realplayBtnTwo); | |||
| chnComboBoxTwo.setPreferredSize(new Dimension(80, 20)); | |||
| streamComboBoxTwo.setPreferredSize(new Dimension(95, 20)); | |||
| realplayBtnTwo.setPreferredSize(new Dimension(115, 20)); | |||
| realPlayWindowTwo.setEnabled(false); | |||
| chnComboBoxTwo.setEnabled(false); | |||
| streamComboBoxTwo.setEnabled(false); | |||
| realplayBtnTwo.setEnabled(false); | |||
| realplayBtnTwo.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| realplayTwo(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 预览 | |||
| public void realplayTwo() { | |||
| if(!isrealplayTwo) { | |||
| m_hPlayHandleTwo = RealPlayModule.startRealPlay(chnComboBoxTwo.getSelectedIndex(), | |||
| streamComboBoxTwo.getSelectedIndex()==0? 0:3, | |||
| realPlayWindowTwo); | |||
| if(m_hPlayHandleTwo.longValue() != 0) { | |||
| realPlayWindowTwo.repaint(); | |||
| isrealplayTwo = true; | |||
| chnComboBoxTwo.setEnabled(false); | |||
| streamComboBoxTwo.setEnabled(false); | |||
| realplayBtnTwo.setText(Res.string().getStopRealPlay()); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } else { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleTwo); | |||
| realPlayWindowTwo.repaint(); | |||
| isrealplayTwo = false; | |||
| chnComboBoxTwo.setEnabled(true); | |||
| streamComboBoxTwo.setEnabled(true); | |||
| realplayBtnTwo.setText(Res.string().getStartRealPlay()); | |||
| } | |||
| } | |||
| private void setButtonEnable(boolean bln) { | |||
| realPlayWindowOne.setEnabled(bln); | |||
| chnComboBoxOne.setEnabled(bln); | |||
| streamComboBoxOne.setEnabled(bln); | |||
| realplayBtnOne.setEnabled(bln); | |||
| realPlayWindowTwo.setEnabled(bln); | |||
| chnComboBoxTwo.setEnabled(bln); | |||
| streamComboBoxTwo.setEnabled(bln); | |||
| realplayBtnTwo.setEnabled(bln); | |||
| } | |||
| /* | |||
| * 登录 | |||
| */ | |||
| private LoginPanel loginPanel; | |||
| private JPanel realPanel; | |||
| /* | |||
| * 预览 | |||
| */ | |||
| private RealPanelOne realPanelOne; | |||
| private JPanel realplayPanelOne; | |||
| private Panel realPlayWindowOne; | |||
| private Panel channelPanelOne; | |||
| private JLabel chnlabelOne; | |||
| private JComboBox chnComboBoxOne; | |||
| private JLabel streamLabelOne; | |||
| private JComboBox streamComboBoxOne; | |||
| private JButton realplayBtnOne; | |||
| // | |||
| private RealPanelTwo realPanelTwo; | |||
| private JPanel realplayPanelTwo; | |||
| private Panel realPlayWindowTwo; | |||
| private Panel channelPanelTwo; | |||
| private JLabel chnlabelTwo; | |||
| private JComboBox chnComboBoxTwo; | |||
| private JLabel streamLabelTwo; | |||
| private JComboBox streamComboBoxTwo; | |||
| private JButton realplayBtnTwo; | |||
| } | |||
| public class RealPlay { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| RealPlayFrame demo = new RealPlayFrame(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| @@ -0,0 +1,223 @@ | |||
| package com.netsdk.demo.frame; | |||
| import java.io.File; | |||
| import com.netsdk.common.CaseMenu; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.NetSDKLib.NET_DEVICEINFO_Ex; | |||
| import java.util.Scanner; | |||
| import com.sun.jna.Pointer; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| public class RealplayEx { | |||
| public static final NetSDKLib netSdk = NetSDKLib.NETSDK_INSTANCE; | |||
| // 登陆句柄 | |||
| private LLong loginHandle = new LLong(0); | |||
| // 预览预览句柄 | |||
| private static LLong lRealHandle = new LLong(0); | |||
| // 设备信息扩展 | |||
| private NET_DEVICEINFO_Ex deviceInfo = new NET_DEVICEINFO_Ex(); | |||
| //private NET_TIME m_startTime = new NET_TIME(); // 开始时间 | |||
| //private NET_TIME m_stopTime = new NET_TIME(); // 结束时间 | |||
| public void InitTest(){ | |||
| // 初始化SDK库 | |||
| netSdk.CLIENT_Init(DisConnectCallBack.getInstance(), null); | |||
| // 设置断线重连成功回调函数 | |||
| netSdk.CLIENT_SetAutoReconnect(HaveReConnectCallBack.getInstance(), null); | |||
| //打开日志,可选 | |||
| NetSDKLib.LOG_SET_PRINT_INFO setLog = new NetSDKLib.LOG_SET_PRINT_INFO(); | |||
| String logPath = new File(".").getAbsoluteFile().getParent() + File.separator + "sdk_log" + File.separator + "sdk.log"; | |||
| setLog.bSetFilePath = 1; | |||
| System.arraycopy(logPath.getBytes(), 0, setLog.szLogFilePath, 0, logPath.getBytes().length); | |||
| setLog.bSetPrintStrategy = 1; | |||
| setLog.nPrintStrategy = 0; | |||
| if (!netSdk.CLIENT_LogOpen(setLog)){ | |||
| System.err.println("Open SDK Log Failed!!!"); | |||
| } | |||
| } | |||
| public void Login(String m_strIp,int m_nPort,String m_strUser,String m_strPassword ){ | |||
| // 登陆设备 | |||
| int nSpecCap = NetSDKLib.EM_LOGIN_SPAC_CAP_TYPE.EM_LOGIN_SPEC_CAP_TCP; // TCP登入 | |||
| IntByReference nError = new IntByReference(0); | |||
| loginHandle = netSdk.CLIENT_LoginEx2(m_strIp, m_nPort, m_strUser, | |||
| m_strPassword ,nSpecCap, null, deviceInfo, nError); | |||
| if (loginHandle.longValue() != 0) { | |||
| System.out.printf("Login Device[%s] Success!\n", m_strIp); | |||
| } | |||
| else { | |||
| System.err.printf("Login Device[%s] Fail.Error[0x%x]\n", m_strIp, netSdk.CLIENT_GetLastError()); | |||
| LoginOut(); | |||
| } | |||
| } | |||
| public void realplay(){ | |||
| lRealHandle= netSdk.CLIENT_RealPlayEx(loginHandle, 0, null, 0); | |||
| if(lRealHandle.longValue()!=0){ | |||
| System.out.println("realplay success"); | |||
| netSdk.CLIENT_SetRealDataCallBackEx(lRealHandle, CbfRealDataCallBackEx.getInstance(),null, 31); | |||
| } | |||
| } | |||
| public void StopRealPlay(){ | |||
| if(netSdk.CLIENT_StopRealPlayEx(lRealHandle)){ | |||
| System.out.println("StopRealPlay success"); | |||
| } | |||
| } | |||
| public void LoginOut(){ | |||
| System.out.println("End Test"); | |||
| if( loginHandle.longValue() != 0) | |||
| { | |||
| netSdk.CLIENT_Logout(loginHandle); | |||
| } | |||
| System.out.println("See You..."); | |||
| netSdk.CLIENT_Cleanup(); | |||
| System.exit(0); | |||
| } | |||
| public void RunTest(){ | |||
| CaseMenu menu=new CaseMenu(); | |||
| menu.addItem((new CaseMenu.Item(this , "realplay" , "realplay"))); | |||
| menu.addItem((new CaseMenu.Item(this , "StopRealPlay" , "StopRealPlay"))); | |||
| menu.run(); | |||
| } | |||
| /** | |||
| * 设备断线回调 | |||
| */ | |||
| private static class DisConnectCallBack implements NetSDKLib.fDisConnect { | |||
| private DisConnectCallBack() { | |||
| } | |||
| private static class CallBackHolder { | |||
| private static DisConnectCallBack instance = new DisConnectCallBack(); | |||
| } | |||
| public static DisConnectCallBack getInstance() { | |||
| return CallBackHolder.instance; | |||
| } | |||
| public void invoke(NetSDKLib.LLong lLoginID, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| } | |||
| } | |||
| /** | |||
| * 设备重连回调 | |||
| */ | |||
| private static class HaveReConnectCallBack implements NetSDKLib.fHaveReConnect { | |||
| private HaveReConnectCallBack() { | |||
| } | |||
| private static class CallBackHolder { | |||
| private static HaveReConnectCallBack instance = new HaveReConnectCallBack(); | |||
| } | |||
| public static HaveReConnectCallBack getInstance() { | |||
| return CallBackHolder.instance; | |||
| } | |||
| public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| } | |||
| } | |||
| /** | |||
| * 实时预览数据回调函数--扩展(pBuffer内存由SDK内部申请释放) | |||
| */ | |||
| private static class CbfRealDataCallBackEx implements NetSDKLib.fRealDataCallBackEx { | |||
| private CbfRealDataCallBackEx() { | |||
| } | |||
| private static class CallBackHolder { | |||
| private static CbfRealDataCallBackEx instance = new CbfRealDataCallBackEx(); | |||
| } | |||
| public static CbfRealDataCallBackEx getInstance() { | |||
| return CallBackHolder.instance; | |||
| } | |||
| @Override | |||
| public void invoke(LLong lRealHandle, int dwDataType, Pointer pBuffer, | |||
| int dwBufSize, int param, Pointer dwUser) { | |||
| int bInput=0; | |||
| if(0 != lRealHandle.longValue()) | |||
| { | |||
| switch(dwDataType) { | |||
| case 0: | |||
| System.out.println("码流大小为" + dwBufSize + "\n" + "码流类型为原始音视频混合数据"); | |||
| break; | |||
| case 1: | |||
| //标准视频数据 | |||
| break; | |||
| case 2: | |||
| //yuv 数据 | |||
| break; | |||
| case 3: | |||
| //pcm 音频数据 | |||
| break; | |||
| case 4: | |||
| //原始音频数据 | |||
| break; | |||
| default: | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| public static void main(String []args){ | |||
| RealplayEx XM=new RealplayEx(); | |||
| String ip = "172.23.12.231"; | |||
| int port = 37777; | |||
| String username = "admin"; | |||
| String password = "admin123"; | |||
| Scanner scanner = new Scanner(System.in); | |||
| String defaultConfig = "ip:%s,port:%d,username:%s,password:%s,需要修改吗?(y/n)"; | |||
| defaultConfig = String.format(defaultConfig, ip, port, username, password); | |||
| System.out.println(defaultConfig); | |||
| String answer = ""; | |||
| do { | |||
| answer = scanner.nextLine(); | |||
| if ("y".equalsIgnoreCase(answer) || "yes".equalsIgnoreCase(answer)) { | |||
| System.out.println("please input ip"); | |||
| ip = scanner.nextLine().trim(); | |||
| System.out.println("please input port:"); | |||
| port = Integer.parseInt(scanner.nextLine()); | |||
| System.out.println("please input username:"); | |||
| username = scanner.nextLine().trim(); | |||
| System.out.println("please input password:"); | |||
| password = scanner.nextLine().trim(); | |||
| break; | |||
| } else if ("n".equalsIgnoreCase(answer) || "no".equalsIgnoreCase(answer)) { | |||
| break; | |||
| } | |||
| System.out.println("please input the right word.y/yes/n/no,try again."); | |||
| } while (!(answer.equalsIgnoreCase("y") | |||
| || answer.equalsIgnoreCase("yes") | |||
| || answer.equalsIgnoreCase("no") | |||
| || answer.equalsIgnoreCase("n"))); | |||
| XM.InitTest(); | |||
| XM.Login(ip,port,username,password); | |||
| XM.RunTest(); | |||
| XM.LoginOut(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,342 @@ | |||
| package com.netsdk.demo.frame; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.GridLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.ItemEvent; | |||
| import java.awt.event.ItemListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.util.Vector; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.UIManager; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.FunctionList; | |||
| import com.netsdk.common.LoginPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.demo.module.TalkModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.ToolKits; | |||
| /** | |||
| * Talk Demo | |||
| */ | |||
| class TalkFrame extends JFrame { | |||
| private static final long serialVersionUID = 1L; | |||
| // device channel list | |||
| private Vector<String> chnlist = new Vector<String>(); | |||
| // device disconnect callback instance | |||
| private static DisConnect disConnect = new DisConnect(); | |||
| // talk frame (this) | |||
| private static JFrame frame = new JFrame(); | |||
| public TalkFrame() { | |||
| setTitle(Res.string().getTalk()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(400, 450); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| LoginModule.init(disConnect, null); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| loginPanel = new TalkLoginPanel(); | |||
| talkPanel = new TalkPanel(); | |||
| add(loginPanel, BorderLayout.CENTER); | |||
| add(talkPanel, BorderLayout.SOUTH); | |||
| loginPanel.addLoginBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(loginPanel.checkLoginText()) { | |||
| if(login()) { | |||
| frame = ToolKits.getFrame(e); | |||
| frame.setTitle(Res.string().getTalk() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| loginPanel.addLogoutBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| frame.setTitle(Res.string().getTalk()); | |||
| logout(); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| TalkModule.stopTalk(); | |||
| LoginModule.logout(); | |||
| LoginModule.cleanup(); | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /////////////////function/////////////////// | |||
| // device disconnect callback class | |||
| // set it's instance by call CLIENT_Init, when device disconnect sdk will call it. | |||
| private static class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getTalk() + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| public boolean login() { | |||
| if(LoginModule.login(loginPanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginPanel.portTextArea.getText()), | |||
| loginPanel.nameTextArea.getText(), | |||
| new String(loginPanel.passwordTextArea.getPassword()))) { | |||
| loginPanel.setButtonEnable(true); | |||
| for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) { | |||
| chnlist.add(Res.string().getChannel() + " " + String.valueOf(i)); | |||
| } | |||
| talkPanel.talkEnable(); | |||
| }else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| public void logout() { | |||
| TalkModule.stopTalk(); | |||
| LoginModule.logout(); | |||
| loginPanel.setButtonEnable(false); | |||
| chnlist.clear(); | |||
| talkPanel.initTalkEnable(); | |||
| } | |||
| private class TalkPanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public TalkPanel() { | |||
| BorderEx.set(this, Res.string().getTalk(), 2); | |||
| setLayout(new GridLayout(3, 1)); | |||
| setPreferredSize(new Dimension(350, 220)); | |||
| transmitPanel = new JPanel(); | |||
| chnPanel = new JPanel(); | |||
| talkBtnPanel = new JPanel(); | |||
| transmitLabel = new JLabel(Res.string().getTransmitType()); | |||
| transmitLabel.setPreferredSize(new Dimension(100, 25)); | |||
| transmitComboBox = new JComboBox(); | |||
| transmitComboBox.setPreferredSize(new Dimension(150, 25)); | |||
| transmitPanel.add(transmitLabel); | |||
| transmitPanel.add(transmitComboBox); | |||
| chnlabel = new JLabel(Res.string().getTransmitChannel()); | |||
| chnlabel.setPreferredSize(new Dimension(100, 25)); | |||
| chnComboBox = new JComboBox(); | |||
| chnComboBox.setPreferredSize(new Dimension(150, 25)); | |||
| chnPanel.add(chnlabel); | |||
| chnPanel.add(chnComboBox); | |||
| startTalkBtn = new JButton(Res.string().getStartTalk()); | |||
| startTalkBtn.setPreferredSize(new Dimension(100, 20)); | |||
| JLabel nullLabel = new JLabel(" "); | |||
| stopTalkBtn = new JButton(Res.string().getStopTalk()); | |||
| stopTalkBtn.setPreferredSize(new Dimension(100, 20)); | |||
| talkBtnPanel.add(startTalkBtn); | |||
| talkBtnPanel.add(nullLabel); | |||
| talkBtnPanel.add(stopTalkBtn); | |||
| add(transmitPanel); | |||
| add(chnPanel); | |||
| add(talkBtnPanel); | |||
| initTalkEnable(); | |||
| startTalkBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(TalkModule.startTalk(transmitComboBox.getSelectedIndex(), | |||
| chnComboBox.getSelectedIndex())) { | |||
| setButtonEnable(false); | |||
| }else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getTalkFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| }); | |||
| stopTalkBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| TalkModule.stopTalk(); | |||
| setButtonEnable(true); | |||
| } | |||
| }); | |||
| transmitComboBox.addItemListener(new ItemListener() { | |||
| @Override | |||
| public void itemStateChanged(ItemEvent e) { | |||
| if (e.getStateChange() == ItemEvent.SELECTED) { | |||
| if (transmitComboBox.getSelectedIndex() == 1) { | |||
| chnComboBox.setModel(new DefaultComboBoxModel(chnlist)); | |||
| chnComboBox.setEnabled(true); | |||
| }else { | |||
| chnComboBox.setModel(new DefaultComboBoxModel()); | |||
| chnComboBox.setEnabled(false); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| public void talkEnable() { | |||
| String[] transmit = {Res.string().getLocalTransmitType(), Res.string().getRemoteTransmitType()}; | |||
| transmitComboBox.setModel(new DefaultComboBoxModel(transmit)); | |||
| setButtonEnable(true); | |||
| } | |||
| public void initTalkEnable() { | |||
| chnComboBox.setModel(new DefaultComboBoxModel()); | |||
| transmitComboBox.setModel(new DefaultComboBoxModel()); | |||
| chnComboBox.setEnabled(false); | |||
| transmitComboBox.setEnabled(false); | |||
| startTalkBtn.setEnabled(false); | |||
| stopTalkBtn.setEnabled(false); | |||
| } | |||
| private void setButtonEnable(boolean bln) { | |||
| transmitComboBox.setEnabled(bln); | |||
| if (bln && transmitComboBox.getSelectedIndex() == 1) { | |||
| chnComboBox.setEnabled(true); | |||
| }else { | |||
| chnComboBox.setEnabled(false); | |||
| } | |||
| startTalkBtn.setEnabled(bln); | |||
| stopTalkBtn.setEnabled(!bln); | |||
| } | |||
| private JPanel transmitPanel; | |||
| private JPanel chnPanel; | |||
| private JPanel talkBtnPanel; | |||
| private JLabel transmitLabel; | |||
| private JComboBox transmitComboBox; | |||
| private JLabel chnlabel; | |||
| private JComboBox chnComboBox; | |||
| private JButton startTalkBtn; | |||
| private JButton stopTalkBtn; | |||
| } | |||
| private class TalkLoginPanel extends LoginPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public TalkLoginPanel() { | |||
| setLayout(new GridLayout(3, 1)); | |||
| removeAll(); | |||
| JPanel ipPanel = new JPanel(); | |||
| JPanel userPanel = new JPanel(); | |||
| JPanel btnPanel = new JPanel(); | |||
| JLabel nullLabel = new JLabel(" "); | |||
| JLabel nullLabel1 = new JLabel(" "); | |||
| resetSize(); | |||
| ipPanel.add(ipLabel); | |||
| ipPanel.add(ipTextArea); | |||
| ipPanel.add(portLabel); | |||
| ipPanel.add(portTextArea); | |||
| userPanel.add(nameLabel); | |||
| userPanel.add(nameTextArea); | |||
| userPanel.add(passwordLabel); | |||
| userPanel.add(passwordTextArea); | |||
| btnPanel.add(nullLabel); | |||
| btnPanel.add(loginBtn); | |||
| btnPanel.add(nullLabel1); | |||
| btnPanel.add(logoutBtn); | |||
| add(ipPanel); | |||
| add(userPanel); | |||
| add(btnPanel); | |||
| } | |||
| private void resetSize() { | |||
| ipLabel.setPreferredSize(new Dimension(70, 20)); | |||
| portLabel.setPreferredSize(new Dimension(70, 20)); | |||
| nameLabel.setText(Res.string().getUserName()); | |||
| nameLabel.setPreferredSize(new Dimension(70, 20)); | |||
| passwordLabel.setPreferredSize(new Dimension(70, 20)); | |||
| ipTextArea.setPreferredSize(new Dimension(90, 20)); | |||
| portTextArea.setPreferredSize(new Dimension(90, 20)); | |||
| nameTextArea.setPreferredSize(new Dimension(90, 20)); | |||
| passwordTextArea.setPreferredSize(new Dimension(90, 20)); | |||
| } | |||
| } | |||
| private TalkLoginPanel loginPanel; | |||
| private TalkPanel talkPanel; | |||
| } | |||
| public class Talk { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| TalkFrame demo = new TalkFrame(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }; | |||
| @@ -0,0 +1,349 @@ | |||
| package com.netsdk.demo.frame.ThermalCamera; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.IOException; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.concurrent.locks.ReentrantLock; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.SwingUtilities; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.Native; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.ThermalCameraModule; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| /** | |||
| * 热图信息对话框 | |||
| */ | |||
| public class HeatMapDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private JDialog target = this; | |||
| private ReentrantLock lock = new ReentrantLock(); | |||
| private NET_RADIOMETRY_DATA gData = new NET_RADIOMETRY_DATA(); | |||
| public HeatMapDialog() { | |||
| setTitle(Res.string().getShowInfo("HEATMAP")); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(400, 440); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
| /////////////////////////////// | |||
| operatePanel = new OperatePanel(); | |||
| showPanel = new HeatMapShowPanel(); | |||
| add(showPanel, BorderLayout.CENTER); | |||
| add(operatePanel, BorderLayout.NORTH); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e){ | |||
| try { | |||
| ThermalCameraModule.radiometryDetach(); | |||
| }finally { | |||
| dispose(); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| /** | |||
| * 订阅回调 | |||
| */ | |||
| private RadiometryAttachCB cbNotify = new RadiometryAttachCB(); | |||
| private class RadiometryAttachCB implements fRadiometryAttachCB { | |||
| @Override | |||
| public void invoke(LLong lAttachHandle, final NET_RADIOMETRY_DATA pBuf, | |||
| int nBufLen, Pointer dwUser) { | |||
| copyRadiometryData(pBuf); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| target.setTitle(Res.string().getShowInfo("HEATMAP")); | |||
| operatePanel.saveBtn.setEnabled(true); | |||
| showPanel.updateData(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| private void copyRadiometryData(NET_RADIOMETRY_DATA data) { | |||
| lock.lock(); | |||
| gData.stMetaData = data.stMetaData; | |||
| gData.dwBufSize = data.dwBufSize; | |||
| gData.pbDataBuf = new Memory(data.dwBufSize); | |||
| gData.pbDataBuf.write(0, data.pbDataBuf.getByteArray(0, data.dwBufSize), 0, data.dwBufSize); | |||
| lock.unlock(); | |||
| } | |||
| /** | |||
| * 操作界面 | |||
| * */ | |||
| public class OperatePanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public OperatePanel() { | |||
| BorderEx.set(this, Res.string().getShowInfo("HEATMAP_OPERATE"), 1); | |||
| setLayout(new FlowLayout(FlowLayout.LEFT, 5, 10)); | |||
| attachBtn = new JButton(Res.string().getShowInfo("RADIOMETRY_ATTACH")); | |||
| fetchBtn = new JButton(Res.string().getShowInfo("RADIOMETRY_FETCH")); | |||
| saveBtn = new JButton(Res.string().getShowInfo("SAVE_HEATMAP")); | |||
| Dimension btnDimension = new Dimension(120, 20); | |||
| attachBtn.setPreferredSize(btnDimension); | |||
| fetchBtn.setPreferredSize(btnDimension); | |||
| saveBtn.setPreferredSize(btnDimension); | |||
| fetchBtn.setEnabled(false); | |||
| saveBtn.setEnabled(false); | |||
| add(attachBtn); | |||
| add(fetchBtn); | |||
| add(saveBtn); | |||
| attachBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| attach(); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| fetchBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| fetch(); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| saveBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| try { | |||
| save(); | |||
| } catch (IOException e) { | |||
| // TODO Auto-generated catch block | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| public void attach() { | |||
| freeMemory(); | |||
| target.setTitle(Res.string().getShowInfo("HEATMAP")); | |||
| if (ThermalCameraModule.isAttaching()) { | |||
| ThermalCameraModule.radiometryDetach(); | |||
| fetchBtn.setEnabled(false); | |||
| saveBtn.setEnabled(false); | |||
| attachBtn.setText(Res.string().getShowInfo("RADIOMETRY_ATTACH")); | |||
| }else { | |||
| if (ThermalCameraModule.radiometryAttach(ThermalCameraFrame.THERMAL_CHANNEL, cbNotify)) { | |||
| attachBtn.setText(Res.string().getShowInfo("RADIOMETRY_DETACH")); | |||
| showPanel.clearData(); | |||
| fetchBtn.setEnabled(true); | |||
| }else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| } | |||
| public void fetch() { | |||
| freeMemory(); | |||
| saveBtn.setEnabled(false); | |||
| int nStatus = ThermalCameraModule.radiometryFetch(ThermalCameraFrame.THERMAL_CHANNEL); | |||
| if (nStatus != -1) { | |||
| showPanel.clearData(); | |||
| String[] arrStatus = Res.string().getTemperStatusList(); | |||
| if (nStatus >= 1 && nStatus <= arrStatus.length) { | |||
| target.setTitle(Res.string().getShowInfo("HEATMAP") + " : " + arrStatus[nStatus-1]); | |||
| } | |||
| }else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| public void save() throws IOException { | |||
| lock.lock(); | |||
| boolean bSaved = ThermalCameraModule.saveData(gData); | |||
| lock.unlock(); | |||
| if (bSaved) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getShowInfo("HEATMAP_SAVE_SUCCESS"), Res.string().getPromptMessage(), JOptionPane.PLAIN_MESSAGE); | |||
| }else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| public void freeMemory() { | |||
| lock.lock(); | |||
| if (gData.pbDataBuf != null) { | |||
| Native.free(Pointer.nativeValue(gData.pbDataBuf)); | |||
| Pointer.nativeValue(gData.pbDataBuf, 0); | |||
| } | |||
| lock.unlock(); | |||
| } | |||
| private JButton attachBtn; | |||
| private JButton fetchBtn; | |||
| private JButton saveBtn; | |||
| } | |||
| /** | |||
| * 查询显示界面 | |||
| * */ | |||
| public class HeatMapShowPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public HeatMapShowPanel() { | |||
| BorderEx.set(this, Res.string().getShowInfo("HEATMAP_METADATA_INFO"), 1); | |||
| setLayout(new FlowLayout(FlowLayout.CENTER, 15, 25)); | |||
| JLabel heightLabel = new JLabel(Res.string().getShowInfo("HEIGHT"), JLabel.LEFT); | |||
| heightTextField = new JTextField(); | |||
| JLabel widthLabel = new JLabel(Res.string().getShowInfo("WIDTH"), JLabel.LEFT); | |||
| widthTextField = new JTextField(); | |||
| JLabel channelLabel = new JLabel(Res.string().getShowInfo("CHANNEL"), JLabel.LEFT); | |||
| channelTextField = new JTextField(); | |||
| JLabel timeLabel = new JLabel(Res.string().getShowInfo("TIME"), JLabel.LEFT); | |||
| timeTextField = new JTextField(); | |||
| JLabel lengthLabel = new JLabel(Res.string().getShowInfo("LENGTH"), JLabel.LEFT); | |||
| lengthTextField = new JTextField(); | |||
| JLabel sensorTypeLabel = new JLabel(Res.string().getShowInfo("SENSOR_TYPE"), JLabel.LEFT); | |||
| sensorTypeTextField = new JTextField(); | |||
| Dimension lableDimension = new Dimension(100, 20); | |||
| Dimension textFieldDimension = new Dimension(140, 20); | |||
| heightLabel.setPreferredSize(lableDimension); | |||
| widthLabel.setPreferredSize(lableDimension); | |||
| channelLabel.setPreferredSize(lableDimension); | |||
| timeLabel.setPreferredSize(lableDimension); | |||
| lengthLabel.setPreferredSize(lableDimension); | |||
| sensorTypeLabel.setPreferredSize(lableDimension); | |||
| heightTextField.setPreferredSize(textFieldDimension); | |||
| widthTextField.setPreferredSize(textFieldDimension); | |||
| channelTextField.setPreferredSize(textFieldDimension); | |||
| timeTextField.setPreferredSize(textFieldDimension); | |||
| lengthTextField.setPreferredSize(textFieldDimension); | |||
| sensorTypeTextField.setPreferredSize(textFieldDimension); | |||
| heightTextField.setEditable(false); | |||
| widthTextField.setEditable(false); | |||
| channelTextField.setEditable(false); | |||
| timeTextField.setEditable(false); | |||
| lengthTextField.setEditable(false); | |||
| sensorTypeTextField.setEditable(false); | |||
| add(heightLabel); | |||
| add(heightTextField); | |||
| add(widthLabel); | |||
| add(widthTextField); | |||
| add(channelLabel); | |||
| add(channelTextField); | |||
| add(timeLabel); | |||
| add(timeTextField); | |||
| add(lengthLabel); | |||
| add(lengthTextField); | |||
| add(sensorTypeLabel); | |||
| add(sensorTypeTextField); | |||
| } | |||
| public void updateData() { | |||
| String[] data = new String[6]; | |||
| lock.lock(); | |||
| data[0] = String.valueOf(gData.stMetaData.nHeight); | |||
| data[1] = String.valueOf(gData.stMetaData.nWidth); | |||
| data[2] = String.valueOf(gData.stMetaData.nChannel+1); | |||
| data[3] = gData.stMetaData.stTime.toStringTimeEx(); | |||
| data[4] = String.valueOf(gData.stMetaData.nLength); | |||
| try { | |||
| data[5] = new String(gData.stMetaData.szSensorType, "GBK").trim(); | |||
| } catch (UnsupportedEncodingException e) { | |||
| data[5] = new String(gData.stMetaData.szSensorType).trim(); | |||
| } | |||
| lock.unlock(); | |||
| setData(data); | |||
| } | |||
| public void clearData() { | |||
| setData(new String[6]); | |||
| } | |||
| private void setData(String[] data) { | |||
| if (data.length != 6) { | |||
| System.err.printf("data length %d != 6", data.length); | |||
| return; | |||
| } | |||
| heightTextField.setText(data[0]); | |||
| widthTextField.setText(data[1]); | |||
| channelTextField.setText(data[2]); | |||
| timeTextField.setText(data[3]); | |||
| lengthTextField.setText(data[4]); | |||
| sensorTypeTextField.setText(data[5]); | |||
| } | |||
| private JTextField heightTextField; | |||
| private JTextField widthTextField; | |||
| private JTextField channelTextField; | |||
| private JTextField timeTextField; | |||
| private JTextField lengthTextField; | |||
| private JTextField sensorTypeTextField; | |||
| } | |||
| private OperatePanel operatePanel; | |||
| private HeatMapShowPanel showPanel; | |||
| } | |||
| @@ -0,0 +1,301 @@ | |||
| package com.netsdk.demo.frame.ThermalCamera; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.KeyEvent; | |||
| import java.awt.event.KeyListener; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JSplitPane; | |||
| import javax.swing.JTextField; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.ThermalCameraModule; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.NET_RADIOMETRYINFO; | |||
| /** | |||
| * 查询测温项对话框 | |||
| */ | |||
| public class ItemQueryDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public ItemQueryDialog() { | |||
| setTitle(Res.string().getShowInfo("ITEM_TEMPER")); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(365, 460); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
| /////////////////////////////// | |||
| queryPanel = new QueryPanel(); | |||
| showPanel = new QueryShowPanel(); | |||
| add(queryPanel, BorderLayout.NORTH); | |||
| add(showPanel, BorderLayout.CENTER); | |||
| } | |||
| /** | |||
| * 查询测温项界面 | |||
| * */ | |||
| public class QueryPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public QueryPanel() { | |||
| BorderEx.set(this, Res.string().getShowInfo("QUERY_CONDITION"), 1); | |||
| setLayout(new BorderLayout()); | |||
| JLabel presetIdLabel = new JLabel(Res.string().getShowInfo("PRESET_ID"), JLabel.CENTER); | |||
| presetIdTextField = new JTextField("1"); | |||
| JLabel ruleIdLabel = new JLabel(Res.string().getShowInfo("RULE_ID"), JLabel.CENTER); | |||
| ruleIdTextField = new JTextField("1"); | |||
| JLabel meterTypeLabel = new JLabel(Res.string().getShowInfo("METER_TYPE"), JLabel.CENTER); | |||
| meterTypeComboBox = new JComboBox(); | |||
| meterTypeComboBox.setModel(new DefaultComboBoxModel(Res.string().getMeterTypeList())); | |||
| queryBtn = new JButton(Res.string().getShowInfo("QUERY")); | |||
| Dimension lableDimension = new Dimension(85, 20); | |||
| Dimension textFieldDimension = new Dimension(80, 20); | |||
| Dimension btnDimension = new Dimension(100, 20); | |||
| presetIdLabel.setPreferredSize(lableDimension); | |||
| presetIdTextField.setPreferredSize(textFieldDimension); | |||
| ruleIdLabel.setPreferredSize(lableDimension); | |||
| ruleIdTextField.setPreferredSize(textFieldDimension); | |||
| meterTypeLabel.setPreferredSize(lableDimension); | |||
| meterTypeComboBox.setPreferredSize(textFieldDimension); | |||
| JLabel label = new JLabel(); | |||
| label.setPreferredSize(new Dimension(40, 20)); | |||
| queryBtn.setPreferredSize(btnDimension); | |||
| JPanel topPanel = new JPanel(); | |||
| topPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 10)); | |||
| topPanel.add(presetIdLabel); | |||
| topPanel.add(presetIdTextField); | |||
| topPanel.add(ruleIdLabel); | |||
| topPanel.add(ruleIdTextField); | |||
| JPanel bottomPanel = new JPanel(); | |||
| bottomPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 10)); | |||
| bottomPanel.add(meterTypeLabel); | |||
| bottomPanel.add(meterTypeComboBox); | |||
| bottomPanel.add(label); | |||
| bottomPanel.add(queryBtn); | |||
| JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); | |||
| splitPane.setDividerSize(0); | |||
| splitPane.setBorder(null); | |||
| splitPane.add(topPanel, JSplitPane.TOP); | |||
| splitPane.add(bottomPanel, JSplitPane.BOTTOM); | |||
| add(splitPane, BorderLayout.CENTER); | |||
| listener = new NumberKeyListener(); | |||
| presetIdTextField.addKeyListener(listener); | |||
| ruleIdTextField.addKeyListener(listener); | |||
| queryBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| queryItemInfo(); | |||
| } | |||
| }); | |||
| } | |||
| public void queryItemInfo() { | |||
| try { | |||
| showPanel.clearData(); | |||
| int nPresetId = Integer.parseInt(presetIdTextField.getText()); | |||
| int nRuleId = Integer.parseInt(ruleIdTextField.getText()); | |||
| int nMeterType = meterTypeComboBox.getSelectedIndex() + 1; | |||
| NET_RADIOMETRYINFO stItemInfo = | |||
| ThermalCameraModule.queryItemTemper(ThermalCameraFrame.THERMAL_CHANNEL, nPresetId, nRuleId, nMeterType); | |||
| if (stItemInfo == null) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| showPanel.updateData(stItemInfo); | |||
| }catch(NumberFormatException e) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getShowInfo("INPUT_ILLEGAL"), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| private NumberKeyListener listener; | |||
| private JTextField presetIdTextField; | |||
| private JTextField ruleIdTextField; | |||
| private JComboBox meterTypeComboBox; | |||
| private JButton queryBtn; | |||
| } | |||
| /** | |||
| * 查询显示界面 | |||
| * */ | |||
| public class QueryShowPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public QueryShowPanel() { | |||
| BorderEx.set(this, Res.string().getShowInfo("QUERY_RESULT"), 1); | |||
| setLayout(new FlowLayout(FlowLayout.CENTER, 5, 25)); | |||
| JLabel meterTypeLabel = new JLabel(Res.string().getShowInfo("METER_TYPE"), JLabel.LEFT); | |||
| meterTypeTextField = new JTextField(); | |||
| JLabel temperUnitLabel = new JLabel(Res.string().getShowInfo("TEMPER_UNIT"), JLabel.LEFT); | |||
| temperUnitTextField = new JTextField(); | |||
| JLabel temperAverLabel = new JLabel(Res.string().getShowInfo("TEMPER_AVER"), JLabel.LEFT); | |||
| temperAverTextField = new JTextField(); | |||
| JLabel temperMaxLabel = new JLabel(Res.string().getShowInfo("TEMPER_MAX"), JLabel.LEFT); | |||
| temperMaxTextField = new JTextField(); | |||
| JLabel temperMinLabel = new JLabel(Res.string().getShowInfo("TEMPER_MIN"), JLabel.LEFT); | |||
| temperMinTextField = new JTextField(); | |||
| JLabel temperMidLabel = new JLabel(Res.string().getShowInfo("TEMPER_MID"), JLabel.LEFT); | |||
| temperMidTextField = new JTextField(); | |||
| JLabel temperStdLabel = new JLabel(Res.string().getShowInfo("TEMPER_STD"), JLabel.LEFT); | |||
| temperStdTextField = new JTextField(); | |||
| Dimension lableDimension = new Dimension(120, 20); | |||
| Dimension textFieldDimension = new Dimension(130, 20); | |||
| meterTypeLabel.setPreferredSize(lableDimension); | |||
| temperUnitLabel.setPreferredSize(lableDimension); | |||
| temperAverLabel.setPreferredSize(lableDimension); | |||
| temperMaxLabel.setPreferredSize(lableDimension); | |||
| temperMinLabel.setPreferredSize(lableDimension); | |||
| temperMidLabel.setPreferredSize(lableDimension); | |||
| temperStdLabel.setPreferredSize(lableDimension); | |||
| meterTypeTextField.setPreferredSize(textFieldDimension); | |||
| temperUnitTextField.setPreferredSize(textFieldDimension); | |||
| temperAverTextField.setPreferredSize(textFieldDimension); | |||
| temperMaxTextField.setPreferredSize(textFieldDimension); | |||
| temperMinTextField.setPreferredSize(textFieldDimension); | |||
| temperMidTextField.setPreferredSize(textFieldDimension); | |||
| temperStdTextField.setPreferredSize(textFieldDimension); | |||
| meterTypeTextField.setEditable(false); | |||
| temperUnitTextField.setEditable(false); | |||
| temperAverTextField.setEditable(false); | |||
| temperMaxTextField.setEditable(false); | |||
| temperMinTextField.setEditable(false); | |||
| temperMidTextField.setEditable(false); | |||
| temperStdTextField.setEditable(false); | |||
| add(meterTypeLabel); | |||
| add(meterTypeTextField); | |||
| add(temperUnitLabel); | |||
| add(temperUnitTextField); | |||
| add(temperMaxLabel); | |||
| add(temperMaxTextField); | |||
| add(temperMinLabel); | |||
| add(temperMinTextField); | |||
| add(temperMidLabel); | |||
| add(temperMidTextField); | |||
| add(temperStdLabel); | |||
| add(temperStdTextField); | |||
| } | |||
| public void updateData(NET_RADIOMETRYINFO stItemInfo) { | |||
| String[] data = new String[7]; | |||
| String [] arrMeterType = Res.string().getMeterTypeList(); | |||
| if (stItemInfo.nMeterType >= 1 && | |||
| stItemInfo.nMeterType <= arrMeterType.length) { | |||
| data[0] = arrMeterType[stItemInfo.nMeterType-1]; | |||
| }else { | |||
| data[0] = Res.string().getShowInfo("UNKNOWN"); | |||
| } | |||
| String [] arrTemperUnit = Res.string().getTemperUnitList(); | |||
| if (stItemInfo.nTemperUnit >= 1 && | |||
| stItemInfo.nTemperUnit <= arrTemperUnit.length) { | |||
| data[1] = arrTemperUnit[stItemInfo.nTemperUnit-1]; | |||
| }else { | |||
| data[1] = Res.string().getShowInfo("UNKNOWN"); | |||
| } | |||
| data[2] = String.valueOf(stItemInfo.fTemperAver); | |||
| data[3] = String.valueOf(stItemInfo.fTemperMax); | |||
| data[4] = String.valueOf(stItemInfo.fTemperMin); | |||
| data[5] = String.valueOf(stItemInfo.fTemperMid); | |||
| data[6] = String.valueOf(stItemInfo.fTemperStd); | |||
| setData(data); | |||
| } | |||
| public void clearData() { | |||
| setData(new String[7]); | |||
| } | |||
| private void setData(String[] data) { | |||
| if (data.length != 7) { | |||
| System.err.printf("data length %d != 7", data.length); | |||
| return; | |||
| } | |||
| meterTypeTextField.setText(data[0]); | |||
| temperUnitTextField.setText(data[1]); | |||
| temperAverTextField.setText(data[2]); | |||
| temperMaxTextField.setText(data[3]); | |||
| temperMinTextField.setText(data[4]); | |||
| temperMidTextField.setText(data[5]); | |||
| temperStdTextField.setText(data[6]); | |||
| } | |||
| private JTextField meterTypeTextField; | |||
| private JTextField temperUnitTextField; | |||
| private JTextField temperAverTextField; | |||
| private JTextField temperMaxTextField; | |||
| private JTextField temperMinTextField; | |||
| private JTextField temperMidTextField; | |||
| private JTextField temperStdTextField; | |||
| } | |||
| class NumberKeyListener implements KeyListener { | |||
| public void keyTyped(KeyEvent e) { | |||
| int key = e.getKeyChar(); | |||
| if (key < 48 || key > 57) { | |||
| e.consume(); | |||
| } | |||
| } | |||
| public void keyPressed(KeyEvent e) {} | |||
| public void keyReleased(KeyEvent e) {} | |||
| } | |||
| private QueryPanel queryPanel; | |||
| private QueryShowPanel showPanel; | |||
| } | |||
| @@ -0,0 +1,233 @@ | |||
| package com.netsdk.demo.frame.ThermalCamera; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.KeyEvent; | |||
| import java.awt.event.KeyListener; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JTextField; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.ThermalCameraModule; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.NET_RADIOMETRYINFO; | |||
| /** | |||
| * 查询测温点对话框 | |||
| */ | |||
| public class PointQueryDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public PointQueryDialog() { | |||
| setTitle(Res.string().getShowInfo("POINT_TEMPER")); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(350, 300); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
| /////////////////////////////// | |||
| queryPanel = new QueryPanel(); | |||
| showPanel = new QueryShowPanel(); | |||
| add(queryPanel, BorderLayout.NORTH); | |||
| add(showPanel, BorderLayout.CENTER); | |||
| } | |||
| /** | |||
| * 查询界面 | |||
| * */ | |||
| public class QueryPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public QueryPanel() { | |||
| BorderEx.set(this, Res.string().getShowInfo("QUERY_CONDITION"), 1); | |||
| setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10)); | |||
| JLabel XLabel = new JLabel(Res.string().getShowInfo("X"), JLabel.CENTER); | |||
| XTextField = new JTextField("0"); | |||
| JLabel YLabel = new JLabel(Res.string().getShowInfo("Y"), JLabel.CENTER); | |||
| YTextField = new JTextField("0"); | |||
| queryBtn = new JButton(Res.string().getShowInfo("QUERY")); | |||
| Dimension lableDimension = new Dimension(10, 20); | |||
| Dimension textFieldDimension = new Dimension(70, 20); | |||
| Dimension btnDimension = new Dimension(100, 20); | |||
| XLabel.setPreferredSize(lableDimension); | |||
| XTextField.setPreferredSize(textFieldDimension); | |||
| YLabel.setPreferredSize(lableDimension); | |||
| YTextField.setPreferredSize(textFieldDimension); | |||
| queryBtn.setPreferredSize(btnDimension); | |||
| add(XLabel); | |||
| add(XTextField); | |||
| add(YLabel); | |||
| add(YTextField); | |||
| add(queryBtn); | |||
| listener = new NumberKeyListener(); | |||
| XTextField.addKeyListener(listener); | |||
| YTextField.addKeyListener(listener); | |||
| queryBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| queryPointInfo(); | |||
| } | |||
| }); | |||
| } | |||
| private void queryPointInfo() { | |||
| try { | |||
| showPanel.clearData(); | |||
| short x = Short.parseShort(XTextField.getText()); | |||
| short y = Short.parseShort(YTextField.getText()); | |||
| NET_RADIOMETRYINFO pointInfo = | |||
| ThermalCameraModule.queryPointTemper(ThermalCameraFrame.THERMAL_CHANNEL, x, y); | |||
| if (pointInfo == null) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| showPanel.updateData(pointInfo); | |||
| }catch(NumberFormatException e) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getShowInfo("COORDINATE_ILLEGAL"), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| private NumberKeyListener listener; | |||
| private JTextField XTextField; | |||
| private JTextField YTextField; | |||
| private JButton queryBtn; | |||
| } | |||
| /** | |||
| * 查询显示界面 | |||
| * */ | |||
| public class QueryShowPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public QueryShowPanel() { | |||
| BorderEx.set(this, Res.string().getShowInfo("QUERY_RESULT"), 1); | |||
| setLayout(new FlowLayout(FlowLayout.CENTER, 5, 30)); | |||
| JLabel meterTypeLabel = new JLabel(Res.string().getShowInfo("METER_TYPE"), JLabel.LEFT); | |||
| meterTypeTextField = new JTextField(); | |||
| JLabel temperUnitLabel = new JLabel(Res.string().getShowInfo("TEMPER_UNIT"), JLabel.LEFT); | |||
| temperUnitTextField = new JTextField(); | |||
| JLabel temperLabel = new JLabel(Res.string().getShowInfo("TEMPER"), JLabel.LEFT); | |||
| temperTextField = new JTextField(); | |||
| Dimension lableDimension = new Dimension(100, 20); | |||
| Dimension textFieldDimension = new Dimension(130, 20); | |||
| meterTypeLabel.setPreferredSize(lableDimension); | |||
| temperUnitLabel.setPreferredSize(lableDimension); | |||
| temperLabel.setPreferredSize(lableDimension); | |||
| meterTypeTextField.setPreferredSize(textFieldDimension); | |||
| temperUnitTextField.setPreferredSize(textFieldDimension); | |||
| temperTextField.setPreferredSize(textFieldDimension); | |||
| meterTypeTextField.setEditable(false); | |||
| temperUnitTextField.setEditable(false); | |||
| temperTextField.setEditable(false); | |||
| add(meterTypeLabel); | |||
| add(meterTypeTextField); | |||
| add(temperUnitLabel); | |||
| add(temperUnitTextField); | |||
| add(temperLabel); | |||
| add(temperTextField); | |||
| } | |||
| public void updateData(NET_RADIOMETRYINFO stPointInfo) { | |||
| String[] data = new String[3]; | |||
| String [] arrMeterType = Res.string().getMeterTypeList(); | |||
| if (stPointInfo.nMeterType >= 1 && | |||
| stPointInfo.nMeterType <= arrMeterType.length) { | |||
| data[0] = arrMeterType[stPointInfo.nMeterType-1]; | |||
| }else { | |||
| data[0] = Res.string().getShowInfo("UNKNOWN"); | |||
| } | |||
| String [] arrTemperUnit = Res.string().getTemperUnitList(); | |||
| if (stPointInfo.nTemperUnit >= 1 && | |||
| stPointInfo.nTemperUnit <= arrTemperUnit.length) { | |||
| data[1] = arrTemperUnit[stPointInfo.nTemperUnit-1]; | |||
| }else { | |||
| data[1] = Res.string().getShowInfo("UNKNOWN"); | |||
| } | |||
| data[2] = String.valueOf(stPointInfo.fTemperAver); | |||
| setData(data); | |||
| } | |||
| public void clearData() { | |||
| setData(new String[3]); | |||
| } | |||
| private void setData(String[] data) { | |||
| if (data.length != 3) { | |||
| System.err.printf("data length %d != 3", data.length); | |||
| return; | |||
| } | |||
| meterTypeTextField.setText(data[0]); | |||
| temperUnitTextField.setText(data[1]); | |||
| temperTextField.setText(data[2]); | |||
| } | |||
| private JTextField meterTypeTextField; | |||
| private JTextField temperUnitTextField; | |||
| private JTextField temperTextField; | |||
| } | |||
| class NumberKeyListener implements KeyListener { | |||
| public void keyTyped(KeyEvent e) { | |||
| int key = e.getKeyChar(); | |||
| if (key < 48 || key > 57) { | |||
| e.consume(); | |||
| } | |||
| } | |||
| public void keyPressed(KeyEvent e) {} | |||
| public void keyReleased(KeyEvent e) {} | |||
| } | |||
| private QueryPanel queryPanel; | |||
| private QueryShowPanel showPanel; | |||
| } | |||
| @@ -0,0 +1,558 @@ | |||
| package com.netsdk.demo.frame.ThermalCamera; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.GridLayout; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.Enumeration; | |||
| import java.util.Vector; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JSplitPane; | |||
| import javax.swing.JTable; | |||
| import javax.swing.ListSelectionModel; | |||
| import javax.swing.SwingConstants; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.SwingWorker; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import javax.swing.table.TableColumn; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.DateChooserJButton; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.ThermalCameraModule; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| import com.netsdk.lib.ToolKits; | |||
| public class TemperQueryDialog extends JDialog{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| private NET_IN_RADIOMETRY_STARTFIND stuStartFind = new NET_IN_RADIOMETRY_STARTFIND(); | |||
| public TemperQueryDialog() { | |||
| setTitle(Res.string().getShowInfo("TEMPER_INFO")); | |||
| setLayout(new BorderLayout()); | |||
| setModal(true); | |||
| pack(); | |||
| setSize(800, 550); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
| /////////////////////////////// | |||
| queryPanel = new QueryPanel(); | |||
| showPanel = new QueryShowPanel(); | |||
| add(queryPanel, BorderLayout.NORTH); | |||
| add(showPanel, BorderLayout.CENTER); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e){ | |||
| try { | |||
| ThermalCameraModule.stopFind(); | |||
| }finally { | |||
| dispose(); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| public void setSearchEnable(boolean b) { | |||
| showPanel.setButtonEnable(b); | |||
| queryPanel.setButtonEnable(b); | |||
| } | |||
| public void queryHistoryInfo(final QUERY_TYPE type) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| setSearchEnable(false); | |||
| if (type == QUERY_TYPE.FIRST_PAGE_QUERY) { | |||
| showPanel.clearData(); | |||
| } | |||
| } | |||
| }); | |||
| new QuerySwingWorker(type).execute(); | |||
| } | |||
| /** | |||
| * 查询界面 | |||
| * */ | |||
| public class QueryPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public QueryPanel() { | |||
| BorderEx.set(this, Res.string().getShowInfo("QUERY_CONDITION"), 1); | |||
| setLayout(new BorderLayout()); | |||
| JLabel startTimeLabel = new JLabel(Res.string().getShowInfo("START_TIME"), JLabel.LEFT); | |||
| startTimeBtn = new DateChooserJButton(); | |||
| JLabel endTimeLabel = new JLabel(Res.string().getShowInfo("END_TIME"), JLabel.LEFT); | |||
| endTimeBtn = new DateChooserJButton(); | |||
| JLabel meterTypeLabel = new JLabel(Res.string().getShowInfo("METER_TYPE"), JLabel.LEFT); | |||
| meterTypeComboBox = new JComboBox(); | |||
| meterTypeComboBox.setModel(new DefaultComboBoxModel(Res.string().getMeterTypeList())); | |||
| JLabel periodLabel = new JLabel(Res.string().getShowInfo("SAVE_PERIOD"), JLabel.LEFT); | |||
| periodComboBox = new JComboBox(); | |||
| periodComboBox.setModel(new DefaultComboBoxModel(Res.string().getPeriodList())); | |||
| queryBtn = new JButton(Res.string().getShowInfo("QUERY")); | |||
| Dimension lableDimension = new Dimension(85, 20); | |||
| Dimension btnDimension = new Dimension(125, 20); | |||
| startTimeLabel.setPreferredSize(lableDimension); | |||
| startTimeBtn.setPreferredSize(btnDimension); | |||
| endTimeLabel.setPreferredSize(lableDimension); | |||
| endTimeBtn.setPreferredSize(btnDimension); | |||
| meterTypeLabel.setPreferredSize(lableDimension); | |||
| meterTypeComboBox.setPreferredSize(btnDimension); | |||
| periodLabel.setPreferredSize(lableDimension); | |||
| periodComboBox.setPreferredSize(btnDimension); | |||
| queryBtn.setPreferredSize(btnDimension); | |||
| JPanel startTimePanel = new JPanel(); | |||
| startTimePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); | |||
| startTimePanel.add(startTimeLabel); | |||
| startTimePanel.add(startTimeBtn); | |||
| JPanel endTimePanel = new JPanel(); | |||
| endTimePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); | |||
| endTimePanel.add(endTimeLabel); | |||
| endTimePanel.add(endTimeBtn); | |||
| JPanel topPanel = new JPanel(); | |||
| topPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 2)); | |||
| topPanel.add(startTimePanel); | |||
| topPanel.add(endTimePanel); | |||
| JPanel meterTypePanel = new JPanel(); | |||
| meterTypePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); | |||
| meterTypePanel.add(meterTypeLabel); | |||
| meterTypePanel.add(meterTypeComboBox); | |||
| JPanel periodPanel = new JPanel(); | |||
| periodPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); | |||
| periodPanel.add(periodLabel); | |||
| periodPanel.add(periodComboBox); | |||
| JPanel bottomPanel = new JPanel(); | |||
| bottomPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 2)); | |||
| bottomPanel.add(meterTypePanel); | |||
| bottomPanel.add(periodPanel); | |||
| JPanel leftPanel = new JPanel(new GridLayout(2,1)); | |||
| BorderEx.set(leftPanel, "", 1); | |||
| leftPanel.add(topPanel); | |||
| leftPanel.add(bottomPanel); | |||
| JPanel rightPanel = new JPanel(); | |||
| rightPanel.setLayout(null); | |||
| BorderEx.set(rightPanel, "", 1); | |||
| queryBtn.setBounds(50, 30, 125, 20); | |||
| rightPanel.add(queryBtn); | |||
| JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); | |||
| pane.setDividerSize(0); | |||
| pane.setBorder(null); | |||
| add(pane, BorderLayout.CENTER); | |||
| queryBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| setStuStartFind(); | |||
| queryHistoryInfo(QUERY_TYPE.FIRST_PAGE_QUERY); | |||
| } | |||
| }); | |||
| } | |||
| private void setStuStartFind() { | |||
| setTime(stuStartFind.stStartTime, startTimeBtn.getText()); | |||
| setTime(stuStartFind.stEndTime, endTimeBtn.getText()); | |||
| stuStartFind.nMeterType = meterTypeComboBox.getSelectedIndex() + 1; | |||
| stuStartFind.nChannel = ThermalCameraFrame.THERMAL_CHANNEL; | |||
| int[] arrPeriod = {5, 10, 15, 30}; | |||
| stuStartFind.emPeriod = arrPeriod[periodComboBox.getSelectedIndex()]; | |||
| } | |||
| private void setTime(NET_TIME netTime, String date) { | |||
| String[] dateTime = date.split(" "); | |||
| String[] arrDate = dateTime[0].split("-"); | |||
| String[] arrTime = dateTime[1].split(":"); | |||
| netTime.dwYear = Integer.parseInt(arrDate[0]); | |||
| netTime.dwMonth = Integer.parseInt(arrDate[1]); | |||
| netTime.dwDay = Integer.parseInt(arrDate[2]); | |||
| netTime.dwHour = Integer.parseInt(arrTime[0]); | |||
| netTime.dwMinute = Integer.parseInt(arrTime[1]); | |||
| netTime.dwSecond = Integer.parseInt(arrTime[2]); | |||
| } | |||
| public void setButtonEnable(boolean b) { | |||
| queryBtn.setEnabled(b); | |||
| } | |||
| private DateChooserJButton startTimeBtn; | |||
| private DateChooserJButton endTimeBtn; | |||
| private JComboBox meterTypeComboBox; | |||
| private JComboBox periodComboBox; | |||
| private JButton queryBtn; | |||
| } | |||
| /** | |||
| * 热成像查询结果信息显示界面 | |||
| * */ | |||
| public class QueryShowPanel extends JPanel { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public static final int INDEX = 0; | |||
| public static final int RECORD_TIME = 1; | |||
| public static final int PRESET_ID = 2; | |||
| public static final int RULE_ID = 3; | |||
| public static final int ITEM_NAME = 4; | |||
| public static final int CHANNEL = 5; | |||
| public static final int COORDINATE = 6; | |||
| public static final int METER_TYPE = 7; | |||
| public static final int TEMPER_UNIT = 8; | |||
| public static final int TEMPER_AVER = 9; | |||
| public static final int TEMPER_MAX = 10; | |||
| public static final int TEMPER_MIN = 11; | |||
| public static final int TEMPER_MID = 12; | |||
| public static final int TEMPER_STD = 13; | |||
| public final static int QUERY_SHOW_COUNT = 20; // 查询个数 | |||
| private int currentIndex = 0; // 实际显示个数 | |||
| private String [] arrMeterType = Res.string().getMeterTypeList(); | |||
| private String [] arrTemperUnit = Res.string().getTemperUnitList(); // 减少次数 | |||
| public QueryShowPanel() { | |||
| BorderEx.set(this, Res.string().getShowInfo("QUERY_LIST"), 1); | |||
| setLayout(new BorderLayout()); | |||
| String[] columnNames = { | |||
| Res.string().getShowInfo("INDEX"), Res.string().getShowInfo("RECORD_TIME"), | |||
| Res.string().getShowInfo("PRESET_ID"), Res.string().getShowInfo("RULE_ID"), | |||
| Res.string().getShowInfo("ITEM_NAME"), Res.string().getShowInfo("CHANNEL"), | |||
| Res.string().getShowInfo("COORDINATE"), Res.string().getShowInfo("METER_TYPE"), | |||
| Res.string().getShowInfo("TEMPER_UNIT"), Res.string().getShowInfo("TEMPER_AVER"), | |||
| Res.string().getShowInfo("TEMPER_MAX"), Res.string().getShowInfo("TEMPER_MIN"), | |||
| Res.string().getShowInfo("TEMPER_MID"), Res.string().getShowInfo("TEMPER_STD") | |||
| }; | |||
| tableModel = new DefaultTableModel(null, columnNames); | |||
| table = new JTable(tableModel) { | |||
| private static final long serialVersionUID = 1L; | |||
| public boolean isCellEditable(int rowIndex, int columnIndex) { // 不可编辑 | |||
| return false; | |||
| } | |||
| }; | |||
| tableModel.setRowCount(QUERY_SHOW_COUNT); // 设置最小显示行 | |||
| table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行 | |||
| Enumeration<TableColumn> columns = table.getColumnModel().getColumns(); | |||
| while (columns.hasMoreElements()) { | |||
| columns.nextElement().setPreferredWidth(140); | |||
| } | |||
| table.getColumnModel().getColumn(RECORD_TIME).setPreferredWidth(140); | |||
| table.getColumnModel().getColumn(ITEM_NAME).setPreferredWidth(180); | |||
| ((DefaultTableCellRenderer) | |||
| table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(SwingConstants.CENTER); | |||
| DefaultTableCellRenderer tcr = new DefaultTableCellRenderer(); | |||
| tcr.setHorizontalAlignment(SwingConstants.CENTER); | |||
| table.setDefaultRenderer(Object.class, tcr); | |||
| table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); | |||
| JScrollPane scrollPane = new JScrollPane(table); | |||
| scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); | |||
| scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |||
| JPanel functionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 120, 5)); | |||
| prePageBtn = new JButton(Res.string().getPreviousPage()); | |||
| nextPageBtn = new JButton(Res.string().getNextPage()); | |||
| prePageBtn.setPreferredSize(new Dimension(120, 20)); | |||
| nextPageBtn.setPreferredSize(new Dimension(120, 20)); | |||
| setButtonEnable(false); | |||
| // functionPanel.add(prePageBtn); | |||
| functionPanel.add(nextPageBtn); | |||
| add(scrollPane, BorderLayout.CENTER); | |||
| add(functionPanel, BorderLayout.SOUTH); | |||
| prePageBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| queryHistoryInfo(QUERY_TYPE.PRE_PAGE_QUERY); | |||
| } | |||
| }); | |||
| nextPageBtn.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| queryHistoryInfo(QUERY_TYPE.NEXT_PAGE_QUERY); | |||
| } | |||
| }); | |||
| } | |||
| public void setButtonEnable(boolean b) { | |||
| prePageBtn.setEnabled(false); | |||
| nextPageBtn.setEnabled(false); | |||
| if (b) { | |||
| if (currentIndex < ThermalCameraModule.getTotalCount()) { | |||
| nextPageBtn.setEnabled(true); | |||
| } | |||
| if (currentIndex > QUERY_SHOW_COUNT) { | |||
| prePageBtn.setEnabled(true); | |||
| } | |||
| } | |||
| } | |||
| public int getIndex() { | |||
| return currentIndex; | |||
| } | |||
| public void setIndex(int index) { | |||
| currentIndex = index; | |||
| } | |||
| public void insertData(NET_OUT_RADIOMETRY_DOFIND stuDoFind) { | |||
| if (stuDoFind == null) { | |||
| return; | |||
| } | |||
| tableModel.setRowCount(0); | |||
| for (int i = 0; i < stuDoFind.nFound; ++i) { | |||
| insertData(stuDoFind.stInfo[i]); | |||
| } | |||
| tableModel.setRowCount(QUERY_SHOW_COUNT); | |||
| table.updateUI(); | |||
| } | |||
| private void insertData(NET_RADIOMETRY_QUERY data) { | |||
| ++currentIndex; | |||
| Vector<String> vector = new Vector<String>(); | |||
| vector.add(String.valueOf(currentIndex)); | |||
| vector.add(data.stTime.toStringTimeEx()); | |||
| vector.add(String.valueOf(data.nPresetId)); | |||
| vector.add(String.valueOf(data.nRuleId)); | |||
| try { | |||
| vector.add(new String(data.szName, "GBK").trim()); | |||
| } catch (UnsupportedEncodingException e) { | |||
| vector.add(new String(data.szName).trim()); | |||
| } | |||
| vector.add(String.valueOf(data.nChannel)); | |||
| if (data.stTemperInfo.nMeterType == NET_RADIOMETRY_METERTYPE.NET_RADIOMETRY_METERTYPE_SPOT) { | |||
| vector.add("(" + data.stCoordinates[0].nx + "," + data.stCoordinates[0].ny + ")"); | |||
| }else if(data.stTemperInfo.nMeterType == NET_RADIOMETRY_METERTYPE.NET_RADIOMETRY_METERTYPE_LINE){ | |||
| vector.add("(" + data.stCoordinates[0].nx + "," + data.stCoordinates[0].ny + "),(" + data.stCoordinates[1].nx + "," + data.stCoordinates[1].ny + ")"); | |||
| }else{ | |||
| switch(data.nCoordinateNum){ | |||
| case 3: | |||
| vector.add("(" + data.stCoordinates[0].nx + "," + data.stCoordinates[0].ny + ")," | |||
| + "(" + data.stCoordinates[1].nx + "," + data.stCoordinates[1].ny + ")," | |||
| + "(" + data.stCoordinates[2].nx + "," + data.stCoordinates[2].ny + ")"); | |||
| break; | |||
| case 4: | |||
| vector.add("(" + data.stCoordinates[0].nx + "," + data.stCoordinates[0].ny + ")," | |||
| + "(" + data.stCoordinates[1].nx + "," + data.stCoordinates[1].ny + ")," | |||
| + "(" + data.stCoordinates[2].nx + "," + data.stCoordinates[2].ny + ")," | |||
| + "(" + data.stCoordinates[3].nx + "," + data.stCoordinates[3].ny + ")"); | |||
| break; | |||
| case 5: | |||
| vector.add("(" + data.stCoordinates[0].nx + "," + data.stCoordinates[0].ny + ")," | |||
| + "(" + data.stCoordinates[1].nx + "," + data.stCoordinates[1].ny + ")," | |||
| + "(" + data.stCoordinates[2].nx + "," + data.stCoordinates[2].ny + ")," | |||
| + "(" + data.stCoordinates[3].nx + "," + data.stCoordinates[3].ny + ")," | |||
| + "(" + data.stCoordinates[4].nx + "," + data.stCoordinates[4].ny + ")"); | |||
| break; | |||
| case 6: | |||
| vector.add("(" + data.stCoordinates[0].nx + "," + data.stCoordinates[0].ny + ")," | |||
| + "(" + data.stCoordinates[1].nx + "," + data.stCoordinates[1].ny + ")," | |||
| + "(" + data.stCoordinates[2].nx + "," + data.stCoordinates[2].ny + ")," | |||
| + "(" + data.stCoordinates[3].nx + "," + data.stCoordinates[3].ny + ")," | |||
| + "(" + data.stCoordinates[4].nx + "," + data.stCoordinates[4].ny + ")," | |||
| + "(" + data.stCoordinates[5].nx + "," + data.stCoordinates[5].ny + "),"); | |||
| break; | |||
| case 7: | |||
| vector.add("(" + data.stCoordinates[0].nx + "," + data.stCoordinates[0].ny + ")," | |||
| + "(" + data.stCoordinates[1].nx + "," + data.stCoordinates[1].ny + ")," | |||
| + "(" + data.stCoordinates[2].nx + "," + data.stCoordinates[2].ny + ")," | |||
| + "(" + data.stCoordinates[3].nx + "," + data.stCoordinates[3].ny + ")," | |||
| + "(" + data.stCoordinates[4].nx + "," + data.stCoordinates[4].ny + ")," | |||
| + "(" + data.stCoordinates[5].nx + "," + data.stCoordinates[5].ny + ")," | |||
| + "(" + data.stCoordinates[6].nx + "," + data.stCoordinates[6].ny + ")"); | |||
| break; | |||
| case 8: | |||
| vector.add("(" + data.stCoordinates[0].nx + "," + data.stCoordinates[0].ny + ")," | |||
| + "(" + data.stCoordinates[1].nx + "," + data.stCoordinates[1].ny + ")," | |||
| + "(" + data.stCoordinates[2].nx + "," + data.stCoordinates[2].ny + ")," | |||
| + "(" + data.stCoordinates[3].nx + "," + data.stCoordinates[3].ny + ")," | |||
| + "(" + data.stCoordinates[4].nx + "," + data.stCoordinates[4].ny + ")," | |||
| + "(" + data.stCoordinates[5].nx + "," + data.stCoordinates[5].ny + ")," | |||
| + "(" + data.stCoordinates[6].nx + "," + data.stCoordinates[6].ny + ")," | |||
| + "(" + data.stCoordinates[7].nx + "," + data.stCoordinates[7].ny + ")"); | |||
| break; | |||
| } | |||
| } | |||
| if (data.stTemperInfo.nMeterType >= 1 && | |||
| data.stTemperInfo.nMeterType <= arrMeterType.length) { | |||
| vector.add(arrMeterType[data.stTemperInfo.nMeterType-1]); | |||
| }else { | |||
| vector.add(Res.string().getShowInfo("UNKNOWN")); | |||
| } | |||
| if (data.stTemperInfo.nTemperUnit >= 1 && | |||
| data.stTemperInfo.nTemperUnit <= arrTemperUnit.length) { | |||
| vector.add(arrTemperUnit[data.stTemperInfo.nTemperUnit-1]); | |||
| }else { | |||
| vector.add(Res.string().getShowInfo("UNKNOWN")); | |||
| } | |||
| vector.add(String.valueOf(data.stTemperInfo.fTemperAver)); | |||
| vector.add(String.valueOf(data.stTemperInfo.fTemperMax)); | |||
| vector.add(String.valueOf(data.stTemperInfo.fTemperMin)); | |||
| vector.add(String.valueOf(data.stTemperInfo.fTemperMid)); | |||
| vector.add(String.valueOf(data.stTemperInfo.fTemperStd)); | |||
| tableModel.addRow(vector); | |||
| } | |||
| public void clearData() { | |||
| currentIndex = 0; | |||
| tableModel.setRowCount(0); | |||
| tableModel.setRowCount(QUERY_SHOW_COUNT); | |||
| table.updateUI(); | |||
| setButtonEnable(false); | |||
| } | |||
| private JTable table = null; | |||
| private DefaultTableModel tableModel = null; | |||
| public JButton prePageBtn; | |||
| public JButton nextPageBtn; | |||
| } | |||
| /** | |||
| * 查询类型 | |||
| * */ | |||
| public enum QUERY_TYPE { | |||
| UNKNOWN, // 未知 | |||
| FIRST_PAGE_QUERY, // 第一页 | |||
| PRE_PAGE_QUERY, // 上一页 | |||
| NEXT_PAGE_QUERY // 下一页 | |||
| }; | |||
| /** | |||
| * 查找工作线程(完成异步搜索) | |||
| */ | |||
| public class QuerySwingWorker extends SwingWorker<NET_OUT_RADIOMETRY_DOFIND, Object> { | |||
| private QUERY_TYPE type; | |||
| private int offset = 0; | |||
| public QuerySwingWorker(QUERY_TYPE type) { | |||
| this.type = type; | |||
| } | |||
| protected NET_OUT_RADIOMETRY_DOFIND doInBackground() { | |||
| int currentIndex = showPanel.getIndex(); | |||
| try { | |||
| switch(type) { | |||
| case FIRST_PAGE_QUERY: | |||
| ThermalCameraModule.stopFind(); | |||
| if (!ThermalCameraModule.startFind(stuStartFind)) { | |||
| return null; | |||
| } | |||
| offset = 0; | |||
| break; | |||
| case PRE_PAGE_QUERY: | |||
| offset = ((currentIndex-1)/QueryShowPanel.QUERY_SHOW_COUNT-1) * QueryShowPanel.QUERY_SHOW_COUNT; | |||
| break; | |||
| case NEXT_PAGE_QUERY: | |||
| offset = currentIndex; | |||
| break; | |||
| default: | |||
| break; | |||
| } | |||
| NET_OUT_RADIOMETRY_DOFIND stuDoFind = ThermalCameraModule.doFind(offset, QueryShowPanel.QUERY_SHOW_COUNT); | |||
| return stuDoFind; | |||
| }catch (Exception e) { | |||
| System.out.println(" -------- doInBackground Exception -------- "); | |||
| } | |||
| return null; | |||
| } | |||
| @Override | |||
| protected void done() { | |||
| try { | |||
| NET_OUT_RADIOMETRY_DOFIND stuDoFind = get(); | |||
| if (stuDoFind == null) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| // System.out.println("offset " + offset + " nFound " + stuDoFind.nFound + " Total " + ThermalCameraModule.getTotalCount()); | |||
| if (stuDoFind.nFound == 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailed(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| showPanel.setIndex(offset); | |||
| showPanel.insertData(stuDoFind); | |||
| } catch (Exception e) { | |||
| // e.printStackTrace(); | |||
| }finally { | |||
| setSearchEnable(true); | |||
| } | |||
| } | |||
| } | |||
| private QueryPanel queryPanel; | |||
| private QueryShowPanel showPanel; | |||
| } | |||
| @@ -0,0 +1,567 @@ | |||
| package com.netsdk.demo.frame.ThermalCamera; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Color; | |||
| import java.awt.Dimension; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.GridLayout; | |||
| import java.awt.Panel; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import java.util.Vector; | |||
| import javax.swing.DefaultComboBoxModel; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JComboBox; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JSplitPane; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.UIManager; | |||
| import javax.swing.border.EmptyBorder; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.BorderEx; | |||
| import com.netsdk.common.FunctionList; | |||
| import com.netsdk.common.LoginPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.demo.module.RealPlayModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.ToolKits; | |||
| /** | |||
| * 热成像 | |||
| */ | |||
| class ThermalCameraFrame extends JFrame { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 1L; | |||
| public static int THERMAL_CHANNEL = 1; // thermal channel | |||
| private Vector<String> chnlist = new Vector<String>(); | |||
| private boolean isrealplayOne = false; | |||
| private boolean isrealplayTwo = false; | |||
| // 设备断线通知回调 | |||
| private static DisConnect disConnect = new DisConnect(); | |||
| // 网络连接恢复 | |||
| private static HaveReConnect haveReConnect = new HaveReConnect(); | |||
| // 预览句柄 | |||
| public static LLong m_hPlayHandleOne = new LLong(0); | |||
| public static LLong m_hPlayHandleTwo = new LLong(0); | |||
| // 获取界面窗口 | |||
| private static JFrame frame = new JFrame(); | |||
| public ThermalCameraFrame() { | |||
| setTitle(Res.string().getThermalCamera()); | |||
| setLayout(new BorderLayout()); | |||
| pack(); | |||
| setSize(800, 560); | |||
| setResizable(false); | |||
| setLocationRelativeTo(null); | |||
| LoginModule.init(disConnect, haveReConnect); // 打开工程,初始化 | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| loginPanel = new LoginPanel(); | |||
| operatePanel = new ThermalOperatePanel(); | |||
| realPanelOne = new RealPanelOne(); | |||
| realPanelTwo = new RealPanelTwo(); | |||
| JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, loginPanel, operatePanel); | |||
| splitPane.setDividerSize(0); | |||
| splitPane.setBorder(null); | |||
| JPanel realPanel = new JPanel();; | |||
| realPanel.setLayout(new GridLayout(1, 2)); | |||
| realPanel.add(realPanelOne); | |||
| realPanel.add(realPanelTwo); | |||
| add(splitPane, BorderLayout.NORTH); | |||
| add(realPanel, BorderLayout.CENTER); | |||
| loginPanel.addLoginBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| if(loginPanel.checkLoginText()) { | |||
| if(login()) { | |||
| frame = ToolKits.getFrame(e); | |||
| frame.setTitle(Res.string().getShowInfo("THERMAL_CAMERA") + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| loginPanel.addLogoutBtnActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| frame.setTitle(Res.string().getShowInfo("THERMAL_CAMERA")); | |||
| logout(); | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| public void windowClosing(WindowEvent e) { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleOne); | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleTwo); | |||
| LoginModule.logout(); | |||
| LoginModule.cleanup(); // 关闭工程,释放资源 | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /////////////////面板/////////////////// | |||
| // 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数 | |||
| private static class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| // 断线提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getShowInfo("THERMAL_CAMERA") + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 网络连接恢复,设备重连成功回调 | |||
| // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 | |||
| private static class HaveReConnect implements NetSDKLib.fHaveReConnect { | |||
| public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| // 重连提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getShowInfo("THERMAL_CAMERA") + " : " + Res.string().getOnline()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 登录 | |||
| public boolean login() { | |||
| if(LoginModule.login(loginPanel.ipTextArea.getText(), | |||
| Integer.parseInt(loginPanel.portTextArea.getText()), | |||
| loginPanel.nameTextArea.getText(), | |||
| new String(loginPanel.passwordTextArea.getPassword()))) { | |||
| for(int i = 1; i < LoginModule.m_stDeviceInfo.byChanNum + 1; i++) { | |||
| chnlist.add(Res.string().getChannel() + " " + String.valueOf(i)); | |||
| } | |||
| setEnable(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| // 登出 | |||
| public void logout() { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleOne); | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleTwo); | |||
| LoginModule.logout(); | |||
| setEnable(false); | |||
| chnlist.clear(); | |||
| } | |||
| public void setEnable(boolean b) { | |||
| loginPanel.setButtonEnable(b); | |||
| realPanelOne.setRealPlayEnable(b); | |||
| realPanelTwo.setRealPlayEnable(b); | |||
| operatePanel.setOperateEnabled(b); | |||
| isrealplayOne = false; | |||
| isrealplayTwo = false; | |||
| } | |||
| /* | |||
| * 热成像操作面板 | |||
| */ | |||
| private class ThermalOperatePanel extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public ThermalOperatePanel() { | |||
| BorderEx.set(this, Res.string().getShowInfo("THERMAL_OPERATE"), 2); | |||
| setLayout(new FlowLayout(FlowLayout.CENTER, 15, 5)); | |||
| JLabel chnlabel = new JLabel(Res.string().getChn()); | |||
| chnComboBox = new JComboBox(); | |||
| pointQueryBtn = new JButton(Res.string().getShowInfo("POINT_QUERY")); | |||
| itemQueryBtn = new JButton(Res.string().getShowInfo("ITEM_QUERY")); | |||
| historyQueryBtn = new JButton(Res.string().getShowInfo("TEMPER_QUERY")); | |||
| heatMapBtn = new JButton(Res.string().getShowInfo("HEATMAP")); | |||
| Dimension btnDimension = new Dimension(140, 20); | |||
| pointQueryBtn.setPreferredSize(btnDimension); | |||
| itemQueryBtn.setPreferredSize(btnDimension); | |||
| historyQueryBtn.setPreferredSize(btnDimension); | |||
| heatMapBtn.setPreferredSize(btnDimension); | |||
| chnComboBox.setPreferredSize(new Dimension(80, 20)); | |||
| JPanel chnPanel = new JPanel(); | |||
| chnPanel.add(chnlabel); | |||
| chnPanel.add(chnComboBox); | |||
| add(chnPanel); | |||
| add(pointQueryBtn); | |||
| add(pointQueryBtn); | |||
| add(itemQueryBtn); | |||
| add(historyQueryBtn); | |||
| add(heatMapBtn); | |||
| setOperateEnabled(false); | |||
| listener = new ThermalOperateActionListener(); | |||
| pointQueryBtn.addActionListener(listener); | |||
| itemQueryBtn.addActionListener(listener); | |||
| historyQueryBtn.addActionListener(listener); | |||
| heatMapBtn.addActionListener(listener); | |||
| } | |||
| public void setOperateEnabled(boolean b) { | |||
| pointQueryBtn.setEnabled(b); | |||
| itemQueryBtn.setEnabled(b); | |||
| historyQueryBtn.setEnabled(b); | |||
| heatMapBtn.setEnabled(b); | |||
| chnComboBox.setEnabled(b); | |||
| if (b) { | |||
| chnComboBox.setModel(new DefaultComboBoxModel(chnlist)); | |||
| if (chnlist.size() > THERMAL_CHANNEL) { | |||
| chnComboBox.setSelectedIndex(THERMAL_CHANNEL); | |||
| } | |||
| }else { | |||
| chnComboBox.setModel(new DefaultComboBoxModel()); | |||
| } | |||
| } | |||
| private JComboBox chnComboBox; | |||
| private ThermalOperateActionListener listener; | |||
| private JButton pointQueryBtn; | |||
| private JButton itemQueryBtn; | |||
| private JButton historyQueryBtn; | |||
| private JButton heatMapBtn; | |||
| } | |||
| private enum ThermalOperate {UNKNOWN, POINT_QUERY, ITEM_QUERY, TEMPER_QUERY, HEATMAP} | |||
| /** | |||
| * 按键监听实现类 | |||
| */ | |||
| private class ThermalOperateActionListener implements ActionListener { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| THERMAL_CHANNEL = operatePanel.chnComboBox.getSelectedIndex(); | |||
| ThermalOperate emType = getOperateType(arg0.getSource()); | |||
| switch(emType) { | |||
| case POINT_QUERY: | |||
| new PointQueryDialog().setVisible(true); | |||
| break; | |||
| case ITEM_QUERY: | |||
| new ItemQueryDialog().setVisible(true); | |||
| break; | |||
| case TEMPER_QUERY: | |||
| new TemperQueryDialog().setVisible(true); | |||
| break; | |||
| case HEATMAP: | |||
| new HeatMapDialog().setVisible(true); | |||
| break; | |||
| default: | |||
| break; | |||
| } | |||
| } | |||
| private ThermalOperate getOperateType(Object btn) { | |||
| ThermalOperate type = ThermalOperate.UNKNOWN; | |||
| if (btn == operatePanel.pointQueryBtn) { | |||
| type = ThermalOperate.POINT_QUERY; | |||
| }else if (btn == operatePanel.itemQueryBtn) { | |||
| type = ThermalOperate.ITEM_QUERY; | |||
| }else if (btn == operatePanel.historyQueryBtn) { | |||
| type = ThermalOperate.TEMPER_QUERY; | |||
| }else if (btn == operatePanel.heatMapBtn) { | |||
| type = ThermalOperate.HEATMAP; | |||
| }else{ | |||
| System.err.println("Unknown Event: " + btn); | |||
| } | |||
| return type; | |||
| } | |||
| } | |||
| /* | |||
| * 预览界面通道、码流设置 以及抓图面板 | |||
| */ | |||
| private class RealPanelOne extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public RealPanelOne() { | |||
| BorderEx.set(this, Res.string().getRealplay(), 2); | |||
| setLayout(new BorderLayout()); | |||
| channelPanelOne = new Panel(); | |||
| realplayPanelOne = new JPanel(); | |||
| add(channelPanelOne, BorderLayout.NORTH); | |||
| add(realplayPanelOne, BorderLayout.CENTER); | |||
| /************ 预览面板 **************/ | |||
| realplayPanelOne.setLayout(new BorderLayout()); | |||
| realplayPanelOne.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| realPlayWindowOne = new Panel(); | |||
| realPlayWindowOne.setBackground(Color.GRAY); | |||
| realplayPanelOne.add(realPlayWindowOne, BorderLayout.CENTER); | |||
| /************ 通道、码流面板 **************/ | |||
| chnlabelOne = new JLabel(Res.string().getChn()); | |||
| chnComboBoxOne = new JComboBox(); | |||
| streamLabelOne = new JLabel(Res.string().getStreamType()); | |||
| String[] stream = {Res.string().getMasterStream(), Res.string().getSubStream()}; | |||
| streamComboBoxOne = new JComboBox(stream); | |||
| realplayBtnOne = new JButton(Res.string().getStartRealPlay()); | |||
| channelPanelOne.setLayout(new FlowLayout()); | |||
| channelPanelOne.add(chnlabelOne); | |||
| channelPanelOne.add(chnComboBoxOne); | |||
| channelPanelOne.add(streamLabelOne); | |||
| channelPanelOne.add(streamComboBoxOne); | |||
| channelPanelOne.add(realplayBtnOne); | |||
| chnComboBoxOne.setPreferredSize(new Dimension(80, 20)); | |||
| streamComboBoxOne.setPreferredSize(new Dimension(95, 20)); | |||
| realplayBtnOne.setPreferredSize(new Dimension(115, 20)); | |||
| realPlayWindowOne.setEnabled(false); | |||
| chnComboBoxOne.setEnabled(false); | |||
| streamComboBoxOne.setEnabled(false); | |||
| realplayBtnOne.setEnabled(false); | |||
| realplayBtnOne.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| realPlay(); | |||
| } | |||
| }); | |||
| } | |||
| public void setRealPlayEnable(boolean bln) { | |||
| realPlayWindowOne.setEnabled(bln); | |||
| chnComboBoxOne.setEnabled(bln); | |||
| streamComboBoxOne.setEnabled(bln); | |||
| realplayBtnOne.setEnabled(bln); | |||
| if (bln) { | |||
| chnComboBoxOne.setModel(new DefaultComboBoxModel(chnlist)); | |||
| }else { | |||
| realPlayWindowOne.repaint(); | |||
| realplayBtnOne.setText(Res.string().getStartRealPlay()); | |||
| chnComboBoxOne.setModel(new DefaultComboBoxModel()); | |||
| } | |||
| } | |||
| private void realPlay() { | |||
| if(!isrealplayOne) { | |||
| m_hPlayHandleOne = RealPlayModule.startRealPlay(chnComboBoxOne.getSelectedIndex(), | |||
| streamComboBoxOne.getSelectedIndex()==0? 0:3, | |||
| realPlayWindowOne); | |||
| if(m_hPlayHandleOne.longValue() != 0) { | |||
| changePlayStatus(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } else { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleOne); | |||
| changePlayStatus(false); | |||
| } | |||
| } | |||
| private void changePlayStatus(boolean b) { | |||
| realPlayWindowOne.repaint(); | |||
| isrealplayOne = b; | |||
| chnComboBoxOne.setEnabled(!b); | |||
| streamComboBoxOne.setEnabled(!b); | |||
| if (b) { | |||
| realplayBtnOne.setText(Res.string().getStopRealPlay()); | |||
| } else { | |||
| m_hPlayHandleOne.setValue(0); | |||
| realplayBtnOne.setText(Res.string().getStartRealPlay()); | |||
| } | |||
| } | |||
| private JPanel realplayPanelOne; | |||
| private Panel realPlayWindowOne; | |||
| private Panel channelPanelOne; | |||
| private JLabel chnlabelOne; | |||
| private JComboBox chnComboBoxOne; | |||
| private JLabel streamLabelOne; | |||
| private JComboBox streamComboBoxOne; | |||
| private JButton realplayBtnOne; | |||
| } | |||
| private class RealPanelTwo extends JPanel { | |||
| private static final long serialVersionUID = 1L; | |||
| public RealPanelTwo() { | |||
| BorderEx.set(this, Res.string().getRealplay(), 2); | |||
| setLayout(new BorderLayout()); | |||
| channelPanelTwo = new Panel(); | |||
| realplayPanelTwo = new JPanel(); | |||
| add(channelPanelTwo, BorderLayout.NORTH); | |||
| add(realplayPanelTwo, BorderLayout.CENTER); | |||
| /************ 预览面板 **************/ | |||
| realplayPanelTwo.setLayout(new BorderLayout()); | |||
| realplayPanelTwo.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| realPlayWindowTwo = new Panel(); | |||
| realPlayWindowTwo.setBackground(Color.GRAY); | |||
| realplayPanelTwo.add(realPlayWindowTwo, BorderLayout.CENTER); | |||
| /************ 通道、码流面板 **************/ | |||
| chnlabelTwo = new JLabel(Res.string().getChn()); | |||
| chnComboBoxTwo = new JComboBox(); | |||
| streamLabelTwo = new JLabel(Res.string().getStreamType()); | |||
| String[] stream = {Res.string().getMasterStream(), Res.string().getSubStream()}; | |||
| streamComboBoxTwo = new JComboBox(stream); | |||
| realplayBtnTwo = new JButton(Res.string().getStartRealPlay()); | |||
| channelPanelTwo.setLayout(new FlowLayout()); | |||
| channelPanelTwo.add(chnlabelTwo); | |||
| channelPanelTwo.add(chnComboBoxTwo); | |||
| channelPanelTwo.add(streamLabelTwo); | |||
| channelPanelTwo.add(streamComboBoxTwo); | |||
| channelPanelTwo.add(realplayBtnTwo); | |||
| chnComboBoxTwo.setPreferredSize(new Dimension(80, 20)); | |||
| streamComboBoxTwo.setPreferredSize(new Dimension(95, 20)); | |||
| realplayBtnTwo.setPreferredSize(new Dimension(115, 20)); | |||
| realPlayWindowTwo.setEnabled(false); | |||
| chnComboBoxTwo.setEnabled(false); | |||
| streamComboBoxTwo.setEnabled(false); | |||
| realplayBtnTwo.setEnabled(false); | |||
| realplayBtnTwo.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| realPlay(); | |||
| } | |||
| }); | |||
| } | |||
| public void setRealPlayEnable(boolean bln) { | |||
| realPlayWindowTwo.setEnabled(bln); | |||
| chnComboBoxTwo.setEnabled(bln); | |||
| streamComboBoxTwo.setEnabled(bln); | |||
| realplayBtnTwo.setEnabled(bln); | |||
| if (bln) { | |||
| chnComboBoxTwo.setModel(new DefaultComboBoxModel(chnlist)); | |||
| if (chnlist.size() > THERMAL_CHANNEL) { | |||
| chnComboBoxTwo.setSelectedIndex(THERMAL_CHANNEL); | |||
| } | |||
| }else { | |||
| realPlayWindowTwo.repaint(); | |||
| realplayBtnTwo.setText(Res.string().getStartRealPlay()); | |||
| chnComboBoxTwo.setModel(new DefaultComboBoxModel()); | |||
| } | |||
| } | |||
| private void realPlay() { | |||
| if(!isrealplayTwo) { | |||
| m_hPlayHandleTwo = RealPlayModule.startRealPlay(chnComboBoxTwo.getSelectedIndex(), | |||
| streamComboBoxTwo.getSelectedIndex()==0? 0:3, | |||
| realPlayWindowTwo); | |||
| if(m_hPlayHandleTwo.longValue() != 0) { | |||
| changePlayStatus(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } else { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandleTwo); | |||
| changePlayStatus(false); | |||
| } | |||
| } | |||
| private void changePlayStatus(boolean b) { | |||
| realPlayWindowTwo.repaint(); | |||
| isrealplayTwo = b; | |||
| chnComboBoxTwo.setEnabled(!b); | |||
| streamComboBoxTwo.setEnabled(!b); | |||
| if (b) { | |||
| realplayBtnTwo.setText(Res.string().getStopRealPlay()); | |||
| } else { | |||
| m_hPlayHandleTwo.setValue(0); | |||
| realplayBtnTwo.setText(Res.string().getStartRealPlay()); | |||
| } | |||
| } | |||
| private JPanel realplayPanelTwo; | |||
| private Panel realPlayWindowTwo; | |||
| private Panel channelPanelTwo; | |||
| private JLabel chnlabelTwo; | |||
| private JComboBox chnComboBoxTwo; | |||
| private JLabel streamLabelTwo; | |||
| private JComboBox streamComboBoxTwo; | |||
| private JButton realplayBtnTwo; | |||
| } | |||
| private LoginPanel loginPanel; | |||
| private ThermalOperatePanel operatePanel; | |||
| private RealPanelOne realPanelOne; | |||
| private RealPanelTwo realPanelTwo; | |||
| } | |||
| public class ThermalCamera { | |||
| public static void main(String[] args) { | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| // Res.string().switchLanguage(LanguageType.English); | |||
| ThermalCameraFrame demo = new ThermalCameraFrame(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| @@ -0,0 +1,67 @@ | |||
| package com.netsdk.demo.frame.scada; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.Utils; | |||
| import com.sun.jna.Pointer; | |||
| import javax.swing.*; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.nio.charset.Charset; | |||
| /** | |||
| * className:SCADAAlarmAttachInfoCallBack | |||
| * description:动环主机:智能事件回调函数 订阅监测点报警信息回调 | |||
| * author:251589 | |||
| * createTime:2021/4/10 16:54 | |||
| * | |||
| * @version v1.0 | |||
| */ | |||
| public class SCADAAlarmAttachInfoCallBack implements NetSDKLib.fSCADAAlarmAttachInfoCallBack { | |||
| // 多平台 编码 | |||
| private final Charset encode = Charset.forName(Utils.getPlatformEncode()); | |||
| private static SCADAAlarmAttachInfoCallBack INSTANCE; | |||
| private JTable table; | |||
| @Override | |||
| public void invoke(NetSDKLib.LLong lAttachHandle, | |||
| NetSDKLib.NET_SCADA_NOTIFY_POINT_ALARM_INFO_LIST pInfo, int nBufLen, | |||
| Pointer dwUser) { | |||
| System.out.println("————————————————————【订阅监测点报警信息回调】————————————————————"); | |||
| //更新列表 | |||
| if (table != null) { | |||
| DefaultTableModel model = (DefaultTableModel) table.getModel(); | |||
| for (int i = 0; i < pInfo.nList; i++) { | |||
| System.out.println(" 设备ID:" + new String(pInfo.stuList[i].szDevID).trim()); | |||
| System.out.println(" 点位ID:" + new String(pInfo.stuList[i].szPointID).trim()); | |||
| String alarmDesc = new String(pInfo.stuList[i].szAlarmDesc, encode).trim(); | |||
| System.out.println(" 报警描述:" + alarmDesc); | |||
| System.out.println(" 报警标志:" + (pInfo.stuList[i].bAlarmFlag == 1)); | |||
| System.out.println(" 报警时间:" + pInfo.stuList[i].stuAlarmTime.toStringTime()); | |||
| System.out.println(" 报警级别(0~6):" + pInfo.stuList[i].nAlarmLevel); | |||
| System.out.println(" 报警编号(同一个告警的开始和结束的编号是相同的):" + pInfo.stuList[i].nSerialNo); | |||
| model.addRow(new Object[]{new String(pInfo.stuList[i].szDevID).trim(), new String(pInfo.stuList[i].szPointID).trim(), alarmDesc, pInfo.stuList[i].stuAlarmTime.toStringTime(), pInfo.stuList[i].nAlarmLevel}); | |||
| } | |||
| } | |||
| System.out.println("————————————————————【订阅监测点报警信息回调】————————————————————"); | |||
| } | |||
| private SCADAAlarmAttachInfoCallBack(JTable table) { | |||
| this.table = table; | |||
| } | |||
| public static SCADAAlarmAttachInfoCallBack getINSTANCE(JTable table) { | |||
| if (INSTANCE == null) { | |||
| INSTANCE = new SCADAAlarmAttachInfoCallBack(table); | |||
| } | |||
| if (table != null) { | |||
| INSTANCE.table = table; | |||
| } | |||
| return INSTANCE; | |||
| } | |||
| } | |||
| @@ -0,0 +1,42 @@ | |||
| package com.netsdk.demo.frame.scada; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import static com.netsdk.demo.module.LoginModule.m_hLoginHandle; | |||
| /** | |||
| * className:SCADAAttachModule | |||
| * description: | |||
| * author:251589 | |||
| * createTime:2021/5/7 20:16 | |||
| * | |||
| * @version v1.0 | |||
| */ | |||
| public class SCADAAttachModule { | |||
| // 订阅实时信息句柄 | |||
| public static NetSDKLib.LLong attachInfoHandle = new NetSDKLib.LLong(0); | |||
| // 订阅报警句柄 | |||
| public static NetSDKLib.LLong alarmAttachInfoHandle = new NetSDKLib.LLong(0); | |||
| public static boolean attachInfo(NetSDKLib.fSCADAAttachInfoCallBack callBack){ | |||
| // 入参 | |||
| NetSDKLib.NET_IN_SCADA_ATTACH_INFO stIn = new NetSDKLib.NET_IN_SCADA_ATTACH_INFO(); | |||
| stIn.cbCallBack = callBack; | |||
| // 出参 | |||
| NetSDKLib.NET_OUT_SCADA_ATTACH_INFO stOut = new NetSDKLib.NET_OUT_SCADA_ATTACH_INFO(); | |||
| attachInfoHandle = LoginModule.netsdk.CLIENT_SCADAAttachInfo(m_hLoginHandle, stIn, stOut, 3000); | |||
| if (attachInfoHandle.longValue() != 0){ | |||
| System.out.println("AttachInfo succeed!"); | |||
| } else { | |||
| System.err.println("AttachInfo failed!"); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| } | |||
| @@ -0,0 +1,898 @@ | |||
| package com.netsdk.demo.frame.scada; | |||
| import com.netsdk.common.FunctionList; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.frame.vto.DefaultDisConnect; | |||
| import com.netsdk.demo.frame.vto.DefaultHaveReconnect; | |||
| import com.netsdk.demo.frame.vto.OperateManager; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.Utils; | |||
| import com.netsdk.lib.structure.NET_ATTRIBUTE_INFO; | |||
| import com.netsdk.lib.structure.NET_GET_CONDITION_INFO; | |||
| import com.netsdk.lib.structure.NET_IN_SCADA_GET_ATTRIBUTE_INFO; | |||
| import com.netsdk.lib.structure.NET_OUT_SCADA_GET_ATTRIBUTE_INFO; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.NativeLong; | |||
| import com.sun.jna.Pointer; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| import javax.swing.*; | |||
| import javax.swing.border.EmptyBorder; | |||
| import javax.swing.border.TitledBorder; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import java.awt.*; | |||
| import java.awt.event.*; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.nio.charset.Charset; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import java.util.Vector; | |||
| import static com.netsdk.demo.module.LoginModule.m_hLoginHandle; | |||
| public class SCADADemo extends JFrame { | |||
| private static final long serialVersionUID = 1L; | |||
| private JPanel contentPane; | |||
| private JTextField ipTextField; | |||
| private JTextField portTextField; | |||
| private JTextField userNameTextField; | |||
| private JPasswordField passwordField; | |||
| private JButton btnLogin; // 登录 | |||
| private JButton btnLogout; // 登出 | |||
| private JButton btnGetDeviceList; // 获取设备列表 | |||
| private JButton btnAlarmAttachInfo; // 遥信,订阅报警 | |||
| private JButton btnAttachInfo; // 遥测,订阅信息 | |||
| private JButton btnAlarmAttachInfoStop; // 遥信,取消订阅报警 | |||
| private JButton btnAttachInfoStop; // 遥测,取消订阅信息 | |||
| private JButton btnStartListen; // 停止监听 | |||
| private JButton btnStopListen; // 停止监听 | |||
| private JTable devicesTable; // 设备列表 | |||
| private JTable pointListTable; // 设备点位列表 | |||
| private JTable alarmAttachInfoTable; | |||
| private JScrollPane deviceScrollPane; | |||
| private JButton btnGetSCADAAttribute; // 获取点位信息 | |||
| private boolean isListen = false; | |||
| ///////////////////// 主面板 ///////////////////// | |||
| private static JFrame mainFrame = new JFrame(); | |||
| private OperateManager manager = new OperateManager(); | |||
| /** | |||
| * Launch the application. | |||
| */ | |||
| public static void main(String[] args) { | |||
| EventQueue.invokeLater(new Runnable() { | |||
| public void run() { | |||
| try { | |||
| SCADADemo frame = new SCADADemo(); | |||
| frame.setVisible(true); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| /** | |||
| * enable button | |||
| * | |||
| * @param enable | |||
| */ | |||
| public void setButtonEnable(boolean enable) { | |||
| btnLogin.setEnabled(enable); | |||
| btnLogout.setEnabled(enable); | |||
| btnGetDeviceList.setEnabled(enable); | |||
| btnAlarmAttachInfo.setEnabled(enable); | |||
| btnAttachInfo.setEnabled(enable); | |||
| btnGetSCADAAttribute.setEnabled(enable); | |||
| btnStartListen.setEnabled(enable); | |||
| } | |||
| private boolean isAlarmAttachInfo = false; | |||
| private boolean isAttachInfo = false; | |||
| /** | |||
| * 登录 | |||
| */ | |||
| public boolean login() { | |||
| if (LoginModule.login(ipTextField.getText(), Integer.parseInt(portTextField.getText()), | |||
| userNameTextField.getText(), new String(passwordField.getPassword()))) { | |||
| setButtonEnable(true); // login succeed,enable related button | |||
| btnLogin.setEnabled(false); | |||
| // 监听按钮使能 | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 登出 | |||
| */ | |||
| public void logout() { | |||
| if (LoginModule.logout()) { | |||
| setButtonEnable(false); // 所有按钮置灰 | |||
| btnLogin.setEnabled(true); | |||
| if (isListen) { | |||
| stopListen(); | |||
| isListen = false; | |||
| } | |||
| if (isAlarmAttachInfo) { | |||
| scadaDetachInfo(); | |||
| isAlarmAttachInfo = false; | |||
| } | |||
| if (isAttachInfo) { | |||
| scadaAlarmDetachInfo(); | |||
| isAttachInfo = false; | |||
| } | |||
| //清空表格 | |||
| //普通事件table清空数据 | |||
| ((DefaultTableModel) alarmTable.getModel()).setRowCount(0); | |||
| // 设备列表table清空数据 | |||
| ((DefaultTableModel) devicesDataTable.getModel()).setRowCount(0); | |||
| // 监测点位实时信息table清空数据 | |||
| ((DefaultTableModel) attachInfoDataTable.getModel()).setRowCount(0); | |||
| // 监测点位报警table清空数据 | |||
| ((DefaultTableModel) alarmAttachInfoDataTable.getModel()).setRowCount(0); | |||
| // 点位信息table清空数据 | |||
| ((DefaultTableModel) attributeDataTable.getModel()).setRowCount(0); | |||
| } | |||
| } | |||
| /** | |||
| * 获取当前主机接入的外部设备ID | |||
| */ | |||
| Vector<String> deviceIds = new Vector<String>(); | |||
| // 多平台 编码 | |||
| private final static Charset encode = Charset.forName(Utils.getPlatformEncode()); | |||
| public boolean getDeviceIdList() { | |||
| deviceIds.clear(); | |||
| // model.setColumnCount(0); | |||
| int nCount = 64; // | |||
| NetSDKLib.NET_SCADA_DEVICE_ID_INFO[] stuDeviceIDList = new NetSDKLib.NET_SCADA_DEVICE_ID_INFO[nCount]; | |||
| for (int i = 0; i < stuDeviceIDList.length; ++i) { | |||
| stuDeviceIDList[i] = new NetSDKLib.NET_SCADA_DEVICE_ID_INFO(); | |||
| } | |||
| NetSDKLib.NET_SCADA_DEVICE_LIST stuSCADADeviceInfo = new NetSDKLib.NET_SCADA_DEVICE_LIST(); | |||
| stuSCADADeviceInfo.nMax = nCount; | |||
| int nSize = stuDeviceIDList[0].size() * nCount; | |||
| stuSCADADeviceInfo.pstuDeviceIDInfo = new Memory(nSize); // 监测设备信息 | |||
| stuSCADADeviceInfo.pstuDeviceIDInfo.clear(nSize); | |||
| ToolKits.SetStructArrToPointerData(stuDeviceIDList, stuSCADADeviceInfo.pstuDeviceIDInfo); | |||
| if (queryDevState(NetSDKLib.NET_DEVSTATE_SCADA_DEVICE_LIST, stuSCADADeviceInfo)) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| if (stuSCADADeviceInfo.nRet == 0) { | |||
| System.out.println("当前主机接入的外部设备ID有效个数为0."); // 外部设备没有有效ID | |||
| return false; | |||
| } | |||
| // 从 Pointer 提取数据 | |||
| ToolKits.GetPointerDataToStructArr(stuSCADADeviceInfo.pstuDeviceIDInfo, stuDeviceIDList); | |||
| // 打印数据并更新设备ID | |||
| System.out.println("获取当前主机接入的外部设备ID的有效个数:" + stuSCADADeviceInfo.nRet); | |||
| if (null != devicesDataTable) { | |||
| DefaultTableModel model = (DefaultTableModel) devicesDataTable.getModel(); | |||
| model.getDataVector().clear();// 清空所有数据 | |||
| for (int i = 0; i < stuSCADADeviceInfo.nRet; ++i) { | |||
| String deviceID = ""; | |||
| String deviceName = ""; | |||
| deviceName = new String(stuDeviceIDList[i].szDevName, encode).trim(); | |||
| deviceID = new String(stuDeviceIDList[i].szDeviceID, encode).trim(); | |||
| System.out.printf("外部设备[%d] 设备id[%s] 设备名称[%s]\n", i, | |||
| new String(stuDeviceIDList[i].szDeviceID, encode).trim(), deviceName); | |||
| deviceIds.add(deviceID); | |||
| model.addRow(new Object[]{deviceID, deviceName}); | |||
| } | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 查询设备状态 | |||
| */ | |||
| public boolean queryDevState(int nType, NetSDKLib.SdkStructure stuInfo) { | |||
| IntByReference intRetLen = new IntByReference(); | |||
| stuInfo.write(); | |||
| if (!LoginModule.netsdk.CLIENT_QueryDevState(m_hLoginHandle, nType, stuInfo.getPointer(), stuInfo.size(), intRetLen, 3000)) { | |||
| return true; | |||
| } | |||
| stuInfo.read(); | |||
| return false; | |||
| } | |||
| /** | |||
| * 订阅监测点位报警 | |||
| */ | |||
| public void scadaAlarmAttachInfo() { | |||
| if (!isAlarmAttachInfo) { | |||
| // 入参 | |||
| NetSDKLib.NET_IN_SCADA_ALARM_ATTACH_INFO stIn = new NetSDKLib.NET_IN_SCADA_ALARM_ATTACH_INFO(); | |||
| stIn.cbCallBack = SCADAAlarmAttachInfoCallBack.getINSTANCE(alarmAttachInfoDataTable); | |||
| // 出参 | |||
| NetSDKLib.NET_OUT_SCADA_ALARM_ATTACH_INFO stOut = new NetSDKLib.NET_OUT_SCADA_ALARM_ATTACH_INFO(); | |||
| alarmAttachInfoHandle = LoginModule.netsdk.CLIENT_SCADAAlarmAttachInfo(m_hLoginHandle, stIn, stOut, 3000); | |||
| if (alarmAttachInfoHandle.longValue() != 0) { | |||
| contentPane.repaint(); | |||
| isAlarmAttachInfo = true; | |||
| btnAlarmAttachInfo.setText(Res.string().getCancel()); // 取消 | |||
| } | |||
| } else { | |||
| scadaAlarmDetachInfo(); | |||
| } | |||
| } | |||
| /** | |||
| * 取消订阅监测点位报警信息 | |||
| */ | |||
| public void scadaAlarmDetachInfo() { | |||
| if (alarmAttachInfoHandle.longValue() != 0) { | |||
| LoginModule.netsdk.CLIENT_SCADAAlarmDetachInfo(alarmAttachInfoHandle); | |||
| contentPane.repaint(); | |||
| isAlarmAttachInfo = false; | |||
| alarmAttachInfoHandle.setValue(0); | |||
| alarmAttachInfoDataModel.getDataVector().clear(); | |||
| btnAlarmAttachInfo.setText(Res.string().getSCADAAttach()); // 订阅 | |||
| } | |||
| } | |||
| private NetSDKLib.LLong attachInfoHandle = new NetSDKLib.LLong(0); // 监测点位信息,订阅句柄 | |||
| private NetSDKLib.LLong alarmAttachInfoHandle = new NetSDKLib.LLong(0); // 监测点位报警,订阅句柄 | |||
| /** | |||
| * 普通报警监听回调 | |||
| */ | |||
| private static class MessCallback implements NetSDKLib.fMessCallBack { | |||
| private static MessCallback INSTANCE; | |||
| private JTable table; | |||
| private MessCallback(JTable table) { | |||
| this.table = table; | |||
| } | |||
| public static MessCallback getInstance(JTable table) { | |||
| if (INSTANCE == null) { | |||
| INSTANCE = new MessCallback(table); | |||
| } | |||
| if (table != null) { | |||
| INSTANCE.table = table; | |||
| } | |||
| return INSTANCE; | |||
| } | |||
| @Override | |||
| public boolean invoke(int lCommand, NetSDKLib.LLong lLoginID, Pointer pStuEvent, | |||
| int dwBufLen, String strDeviceIP, NativeLong nDevicePort, | |||
| Pointer dwUser) { | |||
| switch (lCommand) { | |||
| case NetSDKLib.NET_ALARM_SCADA_DEV_ALARM: { // 12706 检测采集设备报警事件 "SCADADevAlarm" | |||
| NetSDKLib.ALARM_SCADA_DEV_INFO msg = new NetSDKLib.ALARM_SCADA_DEV_INFO(); | |||
| ToolKits.GetPointerData(pStuEvent, msg); | |||
| String deviceId = new String(msg.szDevID,encode).trim(); | |||
| System.out.println("[检测采集设备报警事件] nChannel :" + msg.nChannel); | |||
| System.out.println("设备ID :" + deviceId); | |||
| String description = new String(msg.szDesc, encode).trim(); | |||
| String deviceName = new String(msg.szDevName,encode).trim(); | |||
| System.out.println( " nAction :" + msg.nAction + | |||
| " nAlarmFlag :" + msg.nAlarmFlag + "\n" + "故障设备名称" + deviceName | |||
| + "\n" + "描述" + description + "时间" + msg.stuTime); | |||
| if (table != null) { | |||
| // NetSDKLib.ALARM_SCADA_DEV_INFO msg = new NetSDKLib.ALARM_SCADA_DEV_INFO(); | |||
| // ToolKits.GetPointerData(pStuEvent, msg); | |||
| DefaultTableModel model = (DefaultTableModel) table.getModel(); | |||
| model.addRow(new Object[]{deviceId, deviceName, msg.nChannel, description}); | |||
| } | |||
| break; | |||
| } | |||
| default: | |||
| System.out.println("What's lCommand: " + lCommand); | |||
| break; | |||
| } | |||
| return true; | |||
| } | |||
| } | |||
| /** | |||
| * 订阅监测点位实时信息 | |||
| */ | |||
| public void scadaAttachInfo() { | |||
| if (!isBtnAttachInfo) { | |||
| // 入参 | |||
| NetSDKLib.NET_IN_SCADA_ATTACH_INFO stIn = new NetSDKLib.NET_IN_SCADA_ATTACH_INFO(); | |||
| stIn.cbCallBack = SCADAAttachInfoCallBack.getInstance(attachInfoDataTable); | |||
| // 出参 | |||
| System.err.println("登录句柄: " + m_hLoginHandle); | |||
| NetSDKLib.NET_OUT_SCADA_ATTACH_INFO stOut = new NetSDKLib.NET_OUT_SCADA_ATTACH_INFO(); | |||
| attachInfoHandle = LoginModule.netsdk.CLIENT_SCADAAttachInfo(m_hLoginHandle, stIn, stOut, 3000); | |||
| if (attachInfoHandle.longValue() != 0) { | |||
| contentPane.repaint(); | |||
| isBtnAttachInfo = true; | |||
| btnAttachInfo.setText(Res.string().getCancel()); // 取消 | |||
| System.out.println("CLIENT_SCADAAttachInfo: 订阅监测点位实时信息成功!"); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } else { | |||
| scadaDetachInfo(); | |||
| } | |||
| } | |||
| /** | |||
| * 获取设备点位信息 | |||
| */ | |||
| public void getDeviceAttribute() throws UnsupportedEncodingException { | |||
| Map<Integer, String> num2PointType = new HashMap<Integer, String>(6); | |||
| num2PointType.put(0, "UNKNOWN"); | |||
| num2PointType.put(1, "ALL"); | |||
| num2PointType.put(2, "YC"); | |||
| num2PointType.put(3, "YX"); | |||
| num2PointType.put(4, "YT"); | |||
| num2PointType.put(5, "YK"); | |||
| DefaultTableModel model = (DefaultTableModel) attributeDataTable.getModel(); | |||
| model.getDataVector().clear(); // 清空所有数据 | |||
| for (int i = 0; i < deviceIds.size(); i++) { | |||
| String deviceId = deviceIds.get(i); | |||
| int nMaxAttributeInfoNum = 20; | |||
| NET_IN_SCADA_GET_ATTRIBUTE_INFO inParam = new NET_IN_SCADA_GET_ATTRIBUTE_INFO(); // 获取设备点位信息 入参 | |||
| NET_OUT_SCADA_GET_ATTRIBUTE_INFO outParam = new NET_OUT_SCADA_GET_ATTRIBUTE_INFO(); // 获取设备点位信息 出参 | |||
| NET_GET_CONDITION_INFO conditionInfo = new NET_GET_CONDITION_INFO(); // 获取条件 | |||
| conditionInfo.szDeviceID = deviceIds.get(i).getBytes(); | |||
| conditionInfo.bIsSendID = 1; | |||
| outParam.nMaxAttributeInfoNum = nMaxAttributeInfoNum; | |||
| NET_ATTRIBUTE_INFO attributeInfo = new NET_ATTRIBUTE_INFO(); // 设备点位信息(内存由用户申请) | |||
| outParam.pstuAttributeInfo = new Memory(nMaxAttributeInfoNum * attributeInfo.size()); | |||
| inParam.stuCondition = conditionInfo; | |||
| inParam.write(); | |||
| outParam.write(); | |||
| boolean ret = LoginModule.netsdk.CLIENT_SCADAGetAttributeInfo(m_hLoginHandle, inParam.getPointer(), outParam.getPointer(), 3000); | |||
| inParam.read(); | |||
| outParam.read(); | |||
| if (ret) { | |||
| System.out.println("SCADAGetAttributeInfo succeed!"); | |||
| outParam.read(); | |||
| int retAttributeInfoNum = outParam.nRetAttributeInfoNum; | |||
| System.out.println(outParam); | |||
| NET_ATTRIBUTE_INFO infos[] = new NET_ATTRIBUTE_INFO[retAttributeInfoNum]; | |||
| for (int j = 0; j < retAttributeInfoNum; j++) { | |||
| infos[j] = new NET_ATTRIBUTE_INFO(); | |||
| } | |||
| System.err.println("infos 大小: " + infos.length); | |||
| ToolKits.GetPointerDataToStructArr(outParam.pstuAttributeInfo, infos); | |||
| for (int n = 0; n < retAttributeInfoNum; n++) { | |||
| NET_ATTRIBUTE_INFO out = new NET_ATTRIBUTE_INFO(); | |||
| out = infos[n]; | |||
| model.addRow(new Object[]{deviceId, new String(out.szSignalName, encode).trim(), out.nDelay, out.bIsValid, num2PointType.get(out.emPointType)}); | |||
| System.out.println("设备ID:" + deviceId | |||
| + "\n" + "点位类型: " + num2PointType.get(out.emPointType) | |||
| + "\n" + "点位名称: " + new String(out.szSignalName, encode).trim() | |||
| + "\n" + "时延: " + out.nDelay); | |||
| } | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 取消订阅监测点位实时信息 | |||
| */ | |||
| public void scadaDetachInfo() { | |||
| if (attachInfoHandle.longValue() != 0) { | |||
| LoginModule.netsdk.CLIENT_SCADADetachInfo(attachInfoHandle); | |||
| //attachInfoHandle.setValue(0); | |||
| contentPane.repaint(); | |||
| isBtnAttachInfo = false; | |||
| attachInfoDataModel.getDataVector().clear(); | |||
| btnAttachInfo.setText(Res.string().getSCADAAttach()); // 订阅 | |||
| System.out.println("CLIENT_SCADADetachInfo: 取消订阅监测点位实时信息成功!"); | |||
| } | |||
| } | |||
| /** | |||
| * 订阅报警信息 | |||
| */ | |||
| public void startListenEx() { | |||
| if (!isListen) { | |||
| LoginModule.netsdk.CLIENT_SetDVRMessCallBack(MessCallback.getInstance(alarmTable), null); // set alarm listen callback | |||
| boolean b = LoginModule.netsdk.CLIENT_StartListenEx(m_hLoginHandle); | |||
| if (b) { | |||
| isListen = true; | |||
| contentPane.repaint(); | |||
| btnStartListen.setText(Res.string().getCancel()); | |||
| //btnStopListen.setEnabled(true); | |||
| System.out.println("CLIENT_StartListenEx success."); | |||
| } | |||
| } else { | |||
| stopListen(); | |||
| } | |||
| } | |||
| public JTable tableInit(Object[][] data, String[] columnName) { | |||
| JTable table; | |||
| DefaultTableModel model; | |||
| model = new DefaultTableModel(data, columnName); | |||
| table = new JTable(model) { | |||
| @Override // 不可编辑 | |||
| public boolean isCellEditable(int row, int column) { | |||
| return false; | |||
| } | |||
| }; | |||
| table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行 | |||
| // 列表显示居中 | |||
| DefaultTableCellRenderer dCellRenderer = new DefaultTableCellRenderer(); | |||
| dCellRenderer.setHorizontalAlignment(JLabel.CENTER); | |||
| table.setDefaultRenderer(Object.class, dCellRenderer); | |||
| return table; | |||
| } | |||
| /** | |||
| * 停止监听 | |||
| */ | |||
| public void stopListen() { | |||
| if (isListen) { | |||
| if (LoginModule.netsdk.CLIENT_StopListen(m_hLoginHandle)) { | |||
| isListen = false; | |||
| contentPane.repaint(); | |||
| alarmModel.getDataVector().clear(); | |||
| btnStartListen.setText(Res.string().getStart()); | |||
| } | |||
| } | |||
| } | |||
| // 获取界面窗口 | |||
| private static JFrame frame = new JFrame(); | |||
| /** | |||
| * Create Frame | |||
| */ | |||
| public SCADADemo() { | |||
| setTitle(Res.string().getSCADA()); | |||
| setBounds(100, 100, 920, 750); | |||
| contentPane = new JPanel(); | |||
| contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| setContentPane(contentPane); | |||
| contentPane.setLayout(null); | |||
| setResizable(true); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| LoginModule.init(DefaultDisConnect.GetInstance(), DefaultHaveReconnect.getINSTANCE()); | |||
| JPanel panel = new JPanel(); | |||
| panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), Res.string().getLogin(), | |||
| TitledBorder.LEFT, TitledBorder.TOP, null, new Color(0, 0, 0))); | |||
| panel.setBounds(0, 0, 905, 46); | |||
| contentPane.add(panel); | |||
| panel.setLayout(null); | |||
| JLabel ipLabel = new JLabel(Res.string().getIp()); | |||
| ipLabel.setBounds(10, 15, 44, 21); | |||
| panel.add(ipLabel); | |||
| ipTextField = new JTextField(); | |||
| ipTextField.setText("172.3.0.223"); // 172.24.31.185 172.3.4.104 172.3.4.101 | |||
| ipTextField.setBounds(64, 15, 89, 21); | |||
| panel.add(ipTextField); | |||
| ipTextField.setColumns(10); | |||
| JLabel portLabel = new JLabel(Res.string().getPort()); | |||
| portLabel.setBounds(174, 15, 44, 21); | |||
| panel.add(portLabel); | |||
| portTextField = new JTextField(); | |||
| portTextField.setText("37777"); | |||
| portTextField.setColumns(10); | |||
| portTextField.setBounds(228, 15, 66, 21); | |||
| panel.add(portTextField); | |||
| JLabel lblName = new JLabel(Res.string().getUserName()); | |||
| lblName.setBounds(316, 15, 66, 21); | |||
| panel.add(lblName); | |||
| userNameTextField = new JTextField(); | |||
| userNameTextField.setText("admin"); | |||
| userNameTextField.setColumns(10); | |||
| userNameTextField.setBounds(383, 15, 87, 21); | |||
| panel.add(userNameTextField); | |||
| JLabel lblPassword = new JLabel(Res.string().getPassword()); | |||
| lblPassword.setBounds(492, 15, 66, 21); | |||
| panel.add(lblPassword); | |||
| passwordField = new JPasswordField(); | |||
| passwordField.setBounds(568, 15, 112, 21); | |||
| passwordField.setText("admin123"); | |||
| panel.add(passwordField); | |||
| btnLogin = new JButton(Res.string().getLogin()); | |||
| btnLogin.setBounds(684, 14, 99, 23); | |||
| panel.add(btnLogin); | |||
| btnLogin.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| login(); | |||
| } | |||
| }); | |||
| btnLogout = new JButton(Res.string().getLogout()); | |||
| btnLogout.setBounds(785, 14, 110, 23); | |||
| panel.add(btnLogout); | |||
| btnLogout.setEnabled(false); | |||
| btnLogout.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| logout(); | |||
| LoginModule.cleanup(); // 关闭工程,释放资源 | |||
| dispose(); | |||
| // 返回主菜单 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| // 设备列表 | |||
| JPanel devicesPanel = new JPanel(); | |||
| devicesPanel.setBorder(new TitledBorder(null, Res.string().getSCADADeviceList(), TitledBorder.LEFT, TitledBorder.TOP, null, new Color(0, 0, 0))); | |||
| devicesPanel.setBounds(0, 50, 450, 260); | |||
| contentPane.add(devicesPanel); | |||
| devicesPanel.setLayout(new BorderLayout(0, 0)); | |||
| btnGetDeviceList = new JButton(Res.string().getListBtn()); | |||
| btnGetDeviceList.setBounds(260, 315, 100, 29); | |||
| contentPane.add(btnGetDeviceList); | |||
| btnGetDeviceList.addMouseListener( | |||
| new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| getDeviceIdList(); | |||
| } | |||
| }); | |||
| devicesData = new Object[0][3]; | |||
| devicesDataTable = tableInit(devicesData, devicesDataTitle); | |||
| devicesDataModel = (DefaultTableModel) devicesDataTable.getModel(); | |||
| JScrollPane deviceScrollPane = new JScrollPane(devicesDataTable); | |||
| deviceScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |||
| devicesPanel.add(deviceScrollPane, BorderLayout.CENTER); | |||
| // 点位信息 | |||
| JPanel pointListPanel = new JPanel(); | |||
| pointListPanel.setBorder(new TitledBorder(null, Res.string().getSCADAPointList(), TitledBorder.LEFT, TitledBorder.TOP, null, new Color(0, 0, 0))); | |||
| pointListPanel.setBounds(0, 350, 450, 260); | |||
| contentPane.add(pointListPanel); | |||
| pointListPanel.setLayout(new BorderLayout(0, 0)); | |||
| btnGetSCADAAttribute = new JButton(Res.string().getListBtn()); | |||
| btnGetSCADAAttribute.setBounds(260, 615, 100, 29); | |||
| contentPane.add(btnGetSCADAAttribute); | |||
| btnGetSCADAAttribute.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| try { | |||
| getDeviceAttribute(); | |||
| } catch (UnsupportedEncodingException unsupportedEncodingException) { | |||
| unsupportedEncodingException.printStackTrace(); | |||
| } | |||
| } | |||
| }); | |||
| attributeData = new Object[0][3]; | |||
| attributeDataTable = tableInit(attributeData, attributeDataTitle); | |||
| attributeDataModel = (DefaultTableModel) attributeDataTable.getModel(); | |||
| JScrollPane attributeDataScrollPane = new JScrollPane(attributeDataTable); | |||
| attributeDataScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |||
| pointListPanel.add(attributeDataScrollPane, BorderLayout.CENTER); | |||
| // 遥测 | |||
| JPanel attachAlarmPanel = new JPanel(); | |||
| attachAlarmPanel.setBorder(new TitledBorder(null, Res.string().getSCADAAlarmAttachInfo(), TitledBorder.LEFT, TitledBorder.TOP, null, new Color(0, 0, 0))); | |||
| attachAlarmPanel.setBounds(450, 50, 450, 170); | |||
| contentPane.add(attachAlarmPanel); | |||
| attachAlarmPanel.setLayout(new BorderLayout(0, 0)); | |||
| btnAlarmAttachInfo = new JButton(Res.string().getSCADAAttach()); | |||
| btnAlarmAttachInfo.setBounds(450, 225, 100, 29); | |||
| contentPane.add(btnAlarmAttachInfo); | |||
| btnAlarmAttachInfo.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| scadaAlarmAttachInfo(); | |||
| } | |||
| }); | |||
| alarmAttachInfoData = new Object[0][3]; | |||
| alarmAttachInfoDataTable = tableInit(alarmAttachInfoData, alarmAttachInfoDataTitle); | |||
| alarmAttachInfoDataModel = (DefaultTableModel) alarmAttachInfoDataTable.getModel(); | |||
| JScrollPane alarmAttachInfoDataScrollPane = new JScrollPane(alarmAttachInfoDataTable); | |||
| alarmAttachInfoDataScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |||
| attachAlarmPanel.add(alarmAttachInfoDataScrollPane, BorderLayout.CENTER); | |||
| // 普通报警 | |||
| JPanel attachPanel = new JPanel(); | |||
| attachPanel.setBorder(new TitledBorder(null, Res.string().getSCADAAttach(), TitledBorder.LEFT, TitledBorder.TOP, null, new Color(0, 0, 0))); | |||
| attachPanel.setBounds(450, 270, 450, 170); | |||
| contentPane.add(attachPanel); | |||
| attachPanel.setLayout(new BorderLayout(0, 0)); | |||
| btnStartListen = new JButton(Res.string().getSCADAAttach()); | |||
| btnStartListen.setBounds(450, 445, 100, 29); | |||
| contentPane.add(btnStartListen); | |||
| btnStartListen.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| startListenEx(); | |||
| } | |||
| }); | |||
| // btnStartListen.addMouseListener(new MouseAdapter() { | |||
| // @Override | |||
| // public void mouseClicked(MouseEvent e) { | |||
| // super.mouseClicked(e); | |||
| // isBtnStartListen = !isBtnStartListen; | |||
| // if (isBtnStartListen) { | |||
| // startListenEx(); | |||
| // btnStartListen.setText(Res.string().getCancel()); | |||
| // } else { | |||
| // stopListen(); | |||
| // btnStartListen.setText(Res.string().getSCADAAttach()); | |||
| // } | |||
| // contentPane.add(btnStartListen); | |||
| // contentPane.setOpaque(true); | |||
| // contentPane.repaint(); | |||
| // } | |||
| // }); | |||
| alarmData = new Object[0][3]; | |||
| alarmTable = tableInit(alarmData, alarmTableTitle); | |||
| alarmModel = (DefaultTableModel) alarmTable.getModel(); | |||
| JScrollPane scrollPane = new JScrollPane(alarmTable); | |||
| scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |||
| attachPanel.add(scrollPane, BorderLayout.CENTER); | |||
| // 遥信 订阅监测点位实时信息 | |||
| boolean isBtnGetDeviceList = false; | |||
| JPanel attachInfoPanel = new JPanel(); | |||
| attachInfoPanel.setBorder(new TitledBorder(null, Res.string().getSCADAAttachInfo(), TitledBorder.LEFT, TitledBorder.TOP, null, new Color(0, 0, 0))); | |||
| attachInfoPanel.setBounds(450, 480, 450, 170); | |||
| contentPane.add(attachInfoPanel); | |||
| attachInfoPanel.setLayout(new BorderLayout(0, 0)); | |||
| btnAttachInfo = new JButton(Res.string().getSCADAAttach()); // 订阅 | |||
| btnAttachInfo.setBounds(450, 655, 100, 29); | |||
| contentPane.add(btnAttachInfo); | |||
| btnAttachInfo.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| scadaAttachInfo(); | |||
| } | |||
| }); | |||
| // btnAttachInfo.addMouseListener(new MouseAdapter() { | |||
| // @Override | |||
| // public void mouseClicked(MouseEvent e) { | |||
| // super.mouseClicked(e); | |||
| // scadaAttachInfo(); | |||
| // } | |||
| // }); | |||
| attachInfoData = new Object[0][3]; | |||
| attachInfoDataTable = tableInit(attachInfoData, attachInfoDataTitle); | |||
| attachInfoDataModel = (DefaultTableModel) attachInfoDataTable.getModel(); | |||
| JScrollPane attachInfoDataScrollPane = new JScrollPane(attachInfoDataTable); | |||
| attachInfoDataScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |||
| attachInfoPanel.add(attachInfoDataScrollPane, BorderLayout.CENTER); | |||
| setButtonEnable(false); | |||
| btnLogin.setEnabled(true); | |||
| addWindowListener(new WindowAdapter() { | |||
| @Override | |||
| public void windowClosing(WindowEvent e) { | |||
| if (LoginModule.m_hLoginHandle.longValue() != 0) { | |||
| logout(); | |||
| } | |||
| LoginModule.cleanup(); | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| private boolean isBtnGetDeviceList = false; | |||
| private boolean isBtnStartListen = false; | |||
| private boolean isBtnAlarmAttachInfo = false; | |||
| private boolean isBtnAttachInfo = false; | |||
| private boolean isBtnPointList = false; | |||
| // 普通订阅数据表 | |||
| private Object[][] alarmData; | |||
| private JTable alarmTable; | |||
| private final String[] alarmTableTitle = {Res.string().getDeviceID(), Res.string().getDeviceName(), Res.string().getChannel(), Res.string().getAlarmDescribe()}; | |||
| private DefaultTableModel alarmModel; | |||
| // 设备列表 | |||
| private Object[][] devicesData; | |||
| private JTable devicesDataTable; | |||
| private final String[] devicesDataTitle = {Res.string().getDeviceID(), Res.string().getDeviceName()}; | |||
| private DefaultTableModel devicesDataModel; | |||
| // 报警列表 | |||
| private Object[][] alarmAttachInfoData; | |||
| private JTable alarmAttachInfoDataTable; | |||
| private final String[] alarmAttachInfoDataTitle = {Res.string().getDeviceID(), Res.string().getPointID(), Res.string().getAlarmDescribe(), Res.string().getCollectTime(), Res.string().getAlarmLevel()}; | |||
| private DefaultTableModel alarmAttachInfoDataModel; | |||
| // 实时信息列表 | |||
| private Object[][] attachInfoData; | |||
| private JTable attachInfoDataTable; | |||
| private final String[] attachInfoDataTitle = {Res.string().getDeviceName(), Res.string().getCollectTime(), Res.string().getPointID()}; | |||
| private DefaultTableModel attachInfoDataModel; | |||
| // 点位信息列表 | |||
| private Object[][] attributeData; | |||
| private JTable attributeDataTable; | |||
| private final String[] attributeDataTitle = {Res.string().getDeviceID(), Res.string().getPointName(), Res.string().getAlarmDelay(), Res.string().getIfValidSignalPoint(), Res.string().getAlarmType()}; | |||
| private DefaultTableModel attributeDataModel; | |||
| // 设备断线通知回调 | |||
| private DisConnect disConnectCallback = new DisConnect(); | |||
| /////////////////面板/////////////////// | |||
| // 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数 | |||
| private static class DisConnect implements NetSDKLib.fDisConnect { | |||
| public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort); | |||
| // 断线提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| frame.setTitle(Res.string().getSCADA() + " : " + Res.string().getDisConnectReconnecting()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // // 网络连接恢复,设备重连成功回调 | |||
| // // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 | |||
| // private static class HaveReConnect implements NetSDKLib.fHaveReConnect { | |||
| // public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| // System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| // | |||
| // // 重连提示 | |||
| // SwingUtilities.invokeLater(new Runnable() { | |||
| // public void run() { | |||
| // frame.setTitle(Res.string().getPowerEnvironmentMonitor() + " : " + Res.string().getOnline()); | |||
| // } | |||
| // }); | |||
| // } | |||
| // } | |||
| /** | |||
| * 订阅监测点位信息回调 | |||
| */ | |||
| private static class SCADAAttachInfoCallBack implements NetSDKLib.fSCADAAttachInfoCallBack { | |||
| private JTable attachInfoTable; | |||
| private static SCADAAttachInfoCallBack INSTANCE; | |||
| private SCADAAttachInfoCallBack(JTable attachInfoTable) { | |||
| this.attachInfoTable = attachInfoTable; | |||
| } | |||
| public static final SCADAAttachInfoCallBack getInstance(JTable table) { | |||
| if (INSTANCE == null) { | |||
| INSTANCE = new SCADAAttachInfoCallBack(table); | |||
| } | |||
| if (table != null) { | |||
| INSTANCE.attachInfoTable = table; | |||
| } | |||
| return INSTANCE; | |||
| } | |||
| @Override | |||
| public void invoke(NetSDKLib.LLong lLoginID, NetSDKLib.LLong lAttachHandle, | |||
| NetSDKLib.NET_SCADA_NOTIFY_POINT_INFO_LIST pInfo, int nBufLen, Pointer dwUser) { | |||
| System.out.println("————————————————————【订阅监测点位信息回调】————————————————————"); | |||
| // for (int i = 0; i < pInfo.nList; i++) { | |||
| // System.out.println(" 设备名称:" + new String(pInfo.stuList[i].szDevName).trim()); | |||
| // System.out.println(" 点位名(与点位表的取值一致):" + new String(pInfo.stuList[i].szPointName).trim()); | |||
| // System.out.println(" 现场监控单元ID:" + new String(pInfo.stuList[i].szFSUID).trim()); | |||
| // System.out.println(" 点位ID:" + new String(pInfo.stuList[i].szID).trim()); | |||
| // System.out.println(" 探测器ID:" + new String(pInfo.stuList[i].szSensorID).trim()); | |||
| // System.out.println(" 点位类型:" + pInfo.stuList[i].emPointType); | |||
| // System.out.println(" 采集时间 : " + pInfo.stuList[i].stuCollectTime.toStringTime()); | |||
| // } | |||
| //更新列表 | |||
| if (attachInfoTable != null) { | |||
| DefaultTableModel model = (DefaultTableModel) attachInfoTable.getModel(); | |||
| for (int i = 0; i < pInfo.nList; i++) { | |||
| String deviceName = new String(pInfo.stuList[i].szDevName, encode).trim(); | |||
| String time = pInfo.stuList[i].stuCollectTime.toStringTime(); | |||
| System.out.println(" 设备名称:" + deviceName); | |||
| System.out.println(" 采集时间:" + time); | |||
| System.out.println(" 点位ID:" + new String(pInfo.stuList[i].szID).trim()); | |||
| model.addRow(new Object[]{deviceName, time, new String(pInfo.stuList[i].szID).trim()}); | |||
| } | |||
| } | |||
| System.out.println("————————————————————【订阅监测点位信息回调】————————————————————"); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,425 @@ | |||
| package com.netsdk.demo.frame.vto; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.*; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JDialog; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JPasswordField; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.UIManager; | |||
| import javax.swing.UnsupportedLookAndFeelException; | |||
| import javax.swing.border.EmptyBorder; | |||
| import javax.swing.border.TitledBorder; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.Base64; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| public class CollectionFingerPrint extends JDialog { | |||
| private final JPanel contentPanel = new JPanel(); | |||
| private JTextField ipTextField; | |||
| private JTextField portTextField; | |||
| private JTextField usernameTextField; | |||
| private JPasswordField passwordField; | |||
| private JLabel collectionResult; | |||
| private JButton btnLogin; | |||
| private JButton btnLogout; | |||
| private JButton btnCollection; | |||
| private byte[] packageData; | |||
| private int packageLen; | |||
| private boolean bcollectionResult = false; | |||
| private boolean isListen; | |||
| public byte[] getPackageData() { | |||
| return packageData; | |||
| } | |||
| public void setPackageData(byte[] packageData) { | |||
| this.packageData = packageData; | |||
| } | |||
| public void setLabelResult(byte[] packageData) { | |||
| collectionResult.setText(Base64.getEncoder().encodeToString(packageData)); | |||
| } | |||
| public int getPackageLen() { | |||
| return packageLen; | |||
| } | |||
| public void setPackageLen(int packageLen) { | |||
| this.packageLen = packageLen; | |||
| } | |||
| public boolean isCollectionResult() { | |||
| return bcollectionResult; | |||
| } | |||
| public void setCollectionResult(boolean bcollectionResult) { | |||
| this.bcollectionResult = bcollectionResult; | |||
| //显示结果 | |||
| collectionResult.setText(this.bcollectionResult ? "success" : "failed"); | |||
| } | |||
| public void stopListen() { | |||
| //获取到信息,停止监听 | |||
| if (loginHandler != null && loginHandler.longValue() != 0) { | |||
| stopListen(loginHandler); | |||
| } | |||
| //获取按钮使能 | |||
| btnCollection.setEnabled(true); | |||
| //设置监听状态 | |||
| isListen = false; | |||
| } | |||
| private NetSDKLib.LLong loginHandler; | |||
| private NetSDKLib.NET_DEVICEINFO_Ex deviceinfoEx = new NetSDKLib.NET_DEVICEINFO_Ex(); | |||
| /** | |||
| * Launch the application. | |||
| */ | |||
| public static void main(String[] args) { | |||
| try { | |||
| CollectionFingerPrint dialog = new CollectionFingerPrint(); | |||
| dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); | |||
| dialog.setVisible(true); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| /** | |||
| * Create the dialog. | |||
| */ | |||
| public CollectionFingerPrint() { | |||
| setBounds(100, 100, 304, 397); | |||
| setTitle(Res.string().getVTOOperateCollectionFingerPrintTitle()); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (ClassNotFoundException e) { | |||
| e.printStackTrace(); | |||
| } catch (InstantiationException e) { | |||
| e.printStackTrace(); | |||
| } catch (IllegalAccessException e) { | |||
| e.printStackTrace(); | |||
| } catch (UnsupportedLookAndFeelException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| getContentPane().setLayout(new BorderLayout()); | |||
| contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| getContentPane().add(contentPanel, BorderLayout.CENTER); | |||
| contentPanel.setLayout(null); | |||
| { | |||
| JPanel panel = new JPanel(); | |||
| panel.setBorder(new TitledBorder(null, Res.string().getLogin(), TitledBorder.LEADING, | |||
| TitledBorder.TOP, null, null)); | |||
| panel.setBounds(10, 10, 268, 167); | |||
| contentPanel.add(panel); | |||
| panel.setLayout(null); | |||
| { | |||
| JLabel lblNewLabel = new JLabel(Res.string().getIp()); | |||
| lblNewLabel.setBounds(10, 23, 66, 15); | |||
| panel.add(lblNewLabel); | |||
| } | |||
| { | |||
| ipTextField = new JTextField(); | |||
| ipTextField.setText("172.23.32.61"); | |||
| ipTextField.setBounds(103, 20, 155, 21); | |||
| panel.add(ipTextField); | |||
| ipTextField.setColumns(10); | |||
| } | |||
| { | |||
| JLabel lblPort = new JLabel(Res.string().getPort()); | |||
| lblPort.setBounds(10, 48, 83, 15); | |||
| panel.add(lblPort); | |||
| } | |||
| { | |||
| portTextField = new JTextField(); | |||
| portTextField.setText("37777"); | |||
| portTextField.setColumns(10); | |||
| portTextField.setBounds(103, 45, 155, 21); | |||
| panel.add(portTextField); | |||
| } | |||
| { | |||
| JLabel lblName = new JLabel(Res.string().getUserName()); | |||
| lblName.setBounds(10, 73, 83, 15); | |||
| panel.add(lblName); | |||
| } | |||
| { | |||
| usernameTextField = new JTextField(); | |||
| usernameTextField.setText("admin"); | |||
| usernameTextField.setColumns(10); | |||
| usernameTextField.setBounds(103, 70, 155, 21); | |||
| panel.add(usernameTextField); | |||
| } | |||
| { | |||
| JLabel lblPassword = new JLabel(Res.string().getPassword()); | |||
| lblPassword.setBounds(10, 98, 90, 15); | |||
| panel.add(lblPassword); | |||
| } | |||
| passwordField = new JPasswordField(); | |||
| passwordField.setBounds(103, 95, 155, 18); | |||
| passwordField.setText("admin123"); | |||
| panel.add(passwordField); | |||
| { | |||
| btnLogin = new JButton(Res.string().getLogin()); | |||
| btnLogin.setBounds(7, 134, 111, 23); | |||
| panel.add(btnLogin); | |||
| btnLogin.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| if (login()) { | |||
| btnCollection.setEnabled(true); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| { | |||
| btnLogout = new JButton(Res.string().getLogout()); | |||
| btnLogout.setBounds(153, 134, 105, 23); | |||
| panel.add(btnLogout); | |||
| btnLogout.setEnabled(false); | |||
| btnLogout.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| logout(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| { | |||
| JPanel panel = new JPanel(); | |||
| panel.setBorder(new TitledBorder(null, Res.string().getOperate(), TitledBorder.LEADING, TitledBorder.TOP, | |||
| null, null)); | |||
| panel.setBounds(10, 187, 268, 129); | |||
| contentPanel.add(panel); | |||
| panel.setLayout(null); | |||
| { | |||
| btnCollection = new JButton(Res.string().getStartCollection()); | |||
| btnCollection.setBounds(10, 26, 227, 41); | |||
| panel.add(btnCollection); | |||
| collectionResult = new JLabel(Res.string().getCollectionResult()); | |||
| collectionResult.setBounds(10, 77, 227, 26); | |||
| panel.add(collectionResult); | |||
| btnCollection.setEnabled(false); | |||
| final CollectionFingerPrint print = this; | |||
| btnCollection.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| isListen = startListen(loginHandler, VTOMessageCallBack.getINSTANCE(null, print)); | |||
| if (isListen) { | |||
| //下发采集信息指令 | |||
| if (!collectionFinger()) { | |||
| stopListen(loginHandler); | |||
| } else { | |||
| // 使其失效 | |||
| btnCollection.setEnabled(false); | |||
| } | |||
| new Thread(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| try { | |||
| Thread.sleep(20000); | |||
| //等待二十秒,如果没有获取到信息,则停止获取 | |||
| if (isListen) { | |||
| stopListen(); | |||
| } | |||
| } catch (InterruptedException interruptedException) { | |||
| interruptedException.printStackTrace(); | |||
| } | |||
| } | |||
| }).start(); | |||
| } | |||
| } | |||
| }); | |||
| addWindowListener(new WindowAdapter() { | |||
| @Override | |||
| public void windowClosed(WindowEvent e) { | |||
| super.windowClosed(e); | |||
| //已经登录 | |||
| if (loginHandler != null && loginHandler.longValue() != 0) { | |||
| if (isListen) { | |||
| //停止监听 | |||
| stopListen(loginHandler); | |||
| } | |||
| //登出 | |||
| logout(); | |||
| } | |||
| //按钮复位 | |||
| btnLogin.setEnabled(true); | |||
| btnLogout.setEnabled(false); | |||
| btnCollection.setEnabled(false); | |||
| //清除信息数据 | |||
| bcollectionResult=false; | |||
| packageData=null; | |||
| //清除label显示 | |||
| collectionResult.setText(Res.string().getCollectionResult()); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| { | |||
| JPanel buttonPane = new JPanel(); | |||
| buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); | |||
| getContentPane().add(buttonPane, BorderLayout.SOUTH); | |||
| { | |||
| JButton okButton = new JButton("OK"); | |||
| okButton.setActionCommand("OK"); | |||
| buttonPane.add(okButton); | |||
| getRootPane().setDefaultButton(okButton); | |||
| okButton.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent e) { | |||
| setVisible(false); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 登录 | |||
| */ | |||
| public boolean login() { | |||
| if (login(ipTextField.getText(), Integer.parseInt(portTextField.getText()), usernameTextField.getText(), | |||
| new String(passwordField.getPassword()))) { | |||
| btnLogin.setEnabled(false); | |||
| btnLogout.setEnabled(true); | |||
| btnCollection.setEnabled(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG Login Device \else 登录设备 \endif | |||
| */ | |||
| public boolean login(String m_strIp, int m_nPort, String m_strUser, String m_strPassword) { | |||
| // IntByReference nError = new IntByReference(0); | |||
| // 入参 | |||
| NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY pstInParam = new NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY(); | |||
| pstInParam.nPort = m_nPort; | |||
| pstInParam.szIP = m_strIp.getBytes(); | |||
| pstInParam.szPassword = m_strPassword.getBytes(); | |||
| pstInParam.szUserName = m_strUser.getBytes(); | |||
| // 出参 | |||
| NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY pstOutParam = new NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY(); | |||
| pstOutParam.stuDeviceInfo = deviceinfoEx; | |||
| loginHandler = LoginModule.netsdk.CLIENT_LoginWithHighLevelSecurity(pstInParam, pstOutParam); | |||
| if (loginHandler.longValue() == 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } else { | |||
| System.out.println("Login Success [ " + m_strIp + " ]"); | |||
| } | |||
| return loginHandler.longValue() == 0 ? false : true; | |||
| } | |||
| public long getLoginHandler() { | |||
| if (loginHandler != null) { | |||
| return loginHandler.longValue(); | |||
| } | |||
| return 0; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG Logout Device \else 登出设备 \endif | |||
| */ | |||
| public boolean logout() { | |||
| if (loginHandler.longValue() == 0) { | |||
| return false; | |||
| } | |||
| boolean bRet = LoginModule.netsdk.CLIENT_Logout(loginHandler); | |||
| if (bRet) { | |||
| loginHandler.setValue(0); | |||
| btnLogin.setEnabled(true); | |||
| btnLogout.setEnabled(false); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 下发采集信息指令 | |||
| * | |||
| * @return | |||
| */ | |||
| public boolean collectionFinger() { | |||
| NetSDKLib.NET_CTRL_CAPTURE_FINGER_PRINT capture = new NetSDKLib.NET_CTRL_CAPTURE_FINGER_PRINT(); | |||
| capture.nChannelID = 0; | |||
| System.arraycopy("1".getBytes(), 0, capture.szReaderID, 0, "1".getBytes().length); | |||
| Pointer pointer = new Memory(capture.size()); | |||
| ToolKits.SetStructDataToPointer(capture, pointer, 0); | |||
| boolean ret = LoginModule.netsdk.CLIENT_ControlDevice(loginHandler, NetSDKLib.CtrlType.CTRLTYPE_CTRL_CAPTURE_FINGER_PRINT, pointer, 100000); | |||
| if (!ret) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| public boolean startListen(NetSDKLib.LLong loginHandler, NetSDKLib.fMessCallBack cbMessage) { | |||
| LoginModule.netsdk.CLIENT_SetDVRMessCallBack(cbMessage, null); // set alarm listen callback | |||
| if (!LoginModule.netsdk.CLIENT_StartListenEx(loginHandler)) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } else { | |||
| System.out.println("CLIENT_StartListenEx success."); | |||
| } | |||
| return true; | |||
| } | |||
| public boolean stopListen(NetSDKLib.LLong loginHandler) { | |||
| if (!LoginModule.netsdk.CLIENT_StopListen(loginHandler)) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getStopListenFailed()+","+ ToolKits.getErrorCodeShow(), | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } else { | |||
| System.out.println("CLIENT_StopListen success."); | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 清除获取信息的状态 | |||
| */ | |||
| public void clearStatus() { | |||
| this.setPackageData(null); | |||
| this.setCollectionResult(false); | |||
| this.setPackageLen(0); | |||
| } | |||
| } | |||
| @@ -0,0 +1,34 @@ | |||
| package com.netsdk.demo.frame.vto; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.NetSDKLib.fDisConnect; | |||
| /** | |||
| * 设备断线回调函数,空实现。 建议回调函数使用单例模式 | |||
| * | |||
| * @author 47081 | |||
| * | |||
| */ | |||
| public class DefaultDisConnect implements fDisConnect { | |||
| private static DefaultDisConnect INSTANCE; | |||
| private DefaultDisConnect() { | |||
| // TODO Auto-generated constructor stub | |||
| } | |||
| public static DefaultDisConnect GetInstance() { | |||
| if (INSTANCE == null) { | |||
| INSTANCE = new DefaultDisConnect(); | |||
| } | |||
| return INSTANCE; | |||
| } | |||
| @Override | |||
| public void invoke(LLong lLoginID, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| // TODO Auto-generated method stub | |||
| System.out.printf("Device[%s] Port[%d] DisConnectCallBack!\n", pchDVRIP, nDVRPort); | |||
| } | |||
| } | |||
| @@ -0,0 +1,50 @@ | |||
| package com.netsdk.demo.frame.vto; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.SwingUtilities; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.NetSDKLib.fHaveReConnect; | |||
| /** | |||
| * 网络连接恢复,设备重连成功回调 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数 | |||
| * | |||
| * @author 47081 | |||
| * | |||
| */ | |||
| public class DefaultHaveReconnect implements fHaveReConnect { | |||
| private static DefaultHaveReconnect INSTANCE; | |||
| private JFrame frame; | |||
| public void setFrame(JFrame frame) { | |||
| this.frame = frame; | |||
| } | |||
| private DefaultHaveReconnect() { | |||
| // TODO Auto-generated constructor stub | |||
| } | |||
| public static DefaultHaveReconnect getINSTANCE() { | |||
| if (INSTANCE == null) { | |||
| INSTANCE = new DefaultHaveReconnect(); | |||
| } | |||
| return INSTANCE; | |||
| } | |||
| @Override | |||
| public void invoke(LLong lLoginID, String pchDVRIP, int nDVRPort, Pointer dwUser) { | |||
| System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort); | |||
| // 重连提示 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| if (frame != null) { | |||
| frame.setTitle(Res.string().getPTZ() + " : " + Res.string().getOnline()); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| @@ -0,0 +1,559 @@ | |||
| package com.netsdk.demo.frame.vto; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.Base64; | |||
| import com.netsdk.common.PaintPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Color; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.event.*; | |||
| import java.io.IOException; | |||
| import javax.swing.*; | |||
| import javax.swing.border.EmptyBorder; | |||
| import javax.swing.border.TitledBorder; | |||
| import javax.swing.event.ChangeEvent; | |||
| import javax.swing.event.ChangeListener; | |||
| import static com.netsdk.lib.NetSDKLib.CtrlType.*; | |||
| public class OperateInfo extends JDialog { | |||
| private final JPanel contentPanel = new JPanel(); | |||
| private JTextField cardNoTextField; | |||
| private JTextField roomNoTextField; | |||
| private CollectionFingerPrint fingerPrint = new CollectionFingerPrint(); | |||
| private PaintPanel paintPanel; | |||
| private Memory memory; | |||
| private JCheckBox needFingerCheckBox; | |||
| private boolean bListen = false; | |||
| /** | |||
| * 窗口使用的类型: | |||
| * 0:新增卡信息 | |||
| * 1:修改卡信息 | |||
| */ | |||
| private int infoType; | |||
| private String userId; | |||
| private String cardNo; | |||
| private String fingerPrintData; | |||
| public void setCardNoTextFieldEditEnable(boolean enable) { | |||
| this.cardNoTextField.setEditable(enable); | |||
| } | |||
| public void setRoomNoTextFieldEditEnable(boolean enable){ | |||
| this.roomNoTextField.setEditable(enable); | |||
| } | |||
| public void syncData(String userId, String cardNo, String fingerPrintData) { | |||
| this.userId = userId; | |||
| this.cardNo = cardNo; | |||
| this.fingerPrintData = fingerPrintData; | |||
| if (fingerPrintData == null || fingerPrintData.trim().equals("")) { | |||
| needFingerCheckBox.setSelected(false); | |||
| } else { | |||
| needFingerCheckBox.setSelected(true); | |||
| } | |||
| cardNoTextField.setText(cardNo); | |||
| roomNoTextField.setText(userId); | |||
| } | |||
| public int getInfoType() { | |||
| return infoType; | |||
| } | |||
| public void setInfoType(int infoType) { | |||
| this.infoType = infoType; | |||
| } | |||
| public void receiveData(int infoType, String userId, String cardNo, String fingerPrintData) { | |||
| this.infoType = infoType; | |||
| //新增卡 | |||
| if (infoType == 0) { | |||
| this.userId = ""; | |||
| this.cardNo = ""; | |||
| this.fingerPrintData = ""; | |||
| } else if (infoType == 1) { | |||
| //修改卡 | |||
| this.userId = userId; | |||
| this.cardNo = cardNo; | |||
| this.fingerPrintData = fingerPrintData; | |||
| } | |||
| this.cardNoTextField.setText(this.cardNo); | |||
| this.roomNoTextField.setText(this.userId); | |||
| if (!this.fingerPrintData.trim().equals("")) { | |||
| needFingerCheckBox.setSelected(true); | |||
| } else { | |||
| needFingerCheckBox.setSelected(false); | |||
| } | |||
| } | |||
| /** | |||
| * Launch the application. | |||
| */ | |||
| public static void main(String[] args) { | |||
| try { | |||
| OperateInfo dialog = new OperateInfo(); | |||
| dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); | |||
| dialog.setVisible(true); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| /** | |||
| * Create the dialog. | |||
| */ | |||
| public OperateInfo() { | |||
| setTitle(Res.string().getVTOOperateInfoTitle()); | |||
| setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (ClassNotFoundException e) { | |||
| e.printStackTrace(); | |||
| } catch (InstantiationException e) { | |||
| e.printStackTrace(); | |||
| } catch (IllegalAccessException e) { | |||
| e.printStackTrace(); | |||
| } catch (UnsupportedLookAndFeelException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| setBounds(100, 100, 476, 294); | |||
| getContentPane().setLayout(new BorderLayout()); | |||
| contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| getContentPane().add(contentPanel, BorderLayout.CENTER); | |||
| contentPanel.setLayout(null); | |||
| { | |||
| JPanel panel = new JPanel(); | |||
| panel.setBorder(new TitledBorder(null, Res.string().getCardInfo(), TitledBorder.LEFT, TitledBorder.TOP, | |||
| null, null)); | |||
| panel.setBounds(0, 0, 285, 87); | |||
| contentPanel.add(panel); | |||
| panel.setLayout(null); | |||
| { | |||
| JLabel lblNewLabel = new JLabel(Res.string().getCardNo()); | |||
| lblNewLabel.setBounds(10, 22, 89, 15); | |||
| panel.add(lblNewLabel); | |||
| } | |||
| { | |||
| cardNoTextField = new JTextField(); | |||
| cardNoTextField.setBounds(111, 19, 164, 21); | |||
| panel.add(cardNoTextField); | |||
| cardNoTextField.setColumns(10); | |||
| } | |||
| { | |||
| JLabel lblNewLabel_1 = new JLabel(Res.string().getVTOOperateManagerRoomNo()); | |||
| lblNewLabel_1.setBounds(10, 62, 96, 15); | |||
| panel.add(lblNewLabel_1); | |||
| } | |||
| { | |||
| roomNoTextField = new JTextField(); | |||
| roomNoTextField.setColumns(10); | |||
| roomNoTextField.setBounds(111, 59, 164, 21); | |||
| panel.add(roomNoTextField); | |||
| } | |||
| } | |||
| needFingerCheckBox = new JCheckBox(Res.string().getNeedFingerPrint()); | |||
| needFingerCheckBox.setSelected(true); | |||
| needFingerCheckBox.setBounds(6, 106, 190, 23); | |||
| contentPanel.add(needFingerCheckBox); | |||
| JPanel panel = new JPanel(); | |||
| panel.setBorder(new TitledBorder(null, Res.string().getFingerPrint(), TitledBorder.LEFT, | |||
| TitledBorder.TOP, null, null)); | |||
| panel.setBounds(0, 135, 285, 84); | |||
| contentPanel.add(panel); | |||
| panel.setLayout(null); | |||
| JLabel lblNewLabel_2 = new JLabel(Res.string().getFingerPrint()); | |||
| lblNewLabel_2.setBounds(10, 35, 109, 28); | |||
| panel.add(lblNewLabel_2); | |||
| final JButton btnGetFinger = new JButton(Res.string().getGet()); | |||
| btnGetFinger.setBounds(129, 38, 93, 23); | |||
| panel.add(btnGetFinger); | |||
| btnGetFinger.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| if (fingerPrint == null) { | |||
| fingerPrint = new CollectionFingerPrint(); | |||
| fingerPrint.setVisible(true); | |||
| fingerPrint.setFocusable(true); | |||
| } else { | |||
| //清除信息数据 | |||
| fingerPrint.dispose(); | |||
| //显示信息对话框 | |||
| fingerPrint.setVisible(true); | |||
| } | |||
| } | |||
| }); | |||
| needFingerCheckBox.addChangeListener(new ChangeListener() { | |||
| @Override | |||
| public void stateChanged(ChangeEvent e) { | |||
| //获取事件源 | |||
| JCheckBox checkBox = (JCheckBox) e.getSource(); | |||
| //选中 | |||
| if (checkBox.isSelected()) { | |||
| btnGetFinger.setEnabled(true); | |||
| } else { | |||
| btnGetFinger.setEnabled(false); | |||
| } | |||
| } | |||
| }); | |||
| { | |||
| paintPanel = new PaintPanel(); | |||
| paintPanel.setBackground(Color.GRAY); | |||
| paintPanel.setBorder(new TitledBorder(null, Res.string().getFaceInfo(), TitledBorder.LEADING, | |||
| TitledBorder.TOP, null, null)); | |||
| paintPanel.setBounds(295, 10, 155, 209); | |||
| contentPanel.add(paintPanel); | |||
| paintPanel.setLayout(null); | |||
| { | |||
| JButton open = new JButton(Res.string().getOpen()); | |||
| open.setBounds(26, 90, 93, 23); | |||
| paintPanel.add(open); | |||
| // 选择图片,获取图片的信息 | |||
| open.addActionListener(new ActionListener() { | |||
| @Override | |||
| public void actionPerformed(ActionEvent arg0) { | |||
| String picPath = ""; | |||
| // 选择图片,获取图片路径,并在界面显示 | |||
| picPath = ToolKits.openPictureFile(paintPanel); | |||
| if (!picPath.equals("")) { | |||
| try { | |||
| memory = ToolKits.readPictureFile(picPath); | |||
| } catch (IOException e) { | |||
| // TODO Auto-generated catch block | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| { | |||
| JPanel buttonPane = new JPanel(); | |||
| buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); | |||
| getContentPane().add(buttonPane, BorderLayout.SOUTH); | |||
| { | |||
| JButton okButton = new JButton("OK"); | |||
| okButton.setActionCommand("OK"); | |||
| buttonPane.add(okButton); | |||
| getRootPane().setDefaultButton(okButton); | |||
| okButton.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| //获取到信息 | |||
| if (fingerPrint.isCollectionResult()) { | |||
| fingerPrintData = Base64.getEncoder().encodeToString(fingerPrint.getPackageData()).trim(); | |||
| } | |||
| if (infoType == 0) { | |||
| //新增卡信息 | |||
| if (!checkCardNo(cardNoTextField.getText().trim().getBytes(), true)) { | |||
| //卡号已存在 | |||
| return; | |||
| } | |||
| //添加失败,直接返回,不隐藏窗口 | |||
| if (!addCard(cardNoTextField.getText().trim().getBytes(), roomNoTextField.getText().getBytes(), needFingerCheckBox.isSelected() ? 1 : 0, fingerPrintData)) { | |||
| return; | |||
| } | |||
| } else if (infoType == 1) { | |||
| //修改卡信息 | |||
| if (!checkCardNo(cardNoTextField.getText().trim().getBytes(), false)) { | |||
| //卡号不存在,不能修改 | |||
| return; | |||
| } | |||
| //修改失败,则直接返回,不隐藏界面 | |||
| if (!modifyCard(cardNoTextField.getText().trim().getBytes(), roomNoTextField.getText().trim().getBytes(), needFingerCheckBox.isSelected() ? 1 : 0, fingerPrintData)) { | |||
| return; | |||
| } | |||
| } | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| { | |||
| JButton cancelButton = new JButton("Cancel"); | |||
| cancelButton.setActionCommand("Cancel"); | |||
| buttonPane.add(cancelButton); | |||
| cancelButton.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| dispose(); | |||
| } | |||
| }); | |||
| } | |||
| addWindowListener(new WindowAdapter() { | |||
| @Override | |||
| public void windowClosed(WindowEvent e) { | |||
| super.windowClosed(e); | |||
| //清除信息状态 | |||
| if (fingerPrint.isCollectionResult()) { | |||
| fingerPrint.clearStatus(); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| /** | |||
| * 检查下卡号是否存在 | |||
| * true:不存在 | |||
| * false:存在 | |||
| * | |||
| * @param type true:卡存在即弹窗 | |||
| * @return | |||
| */ | |||
| public boolean checkCardNo(byte[] cardNo, boolean type) { | |||
| if (cardNo.length == 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInputCardNo(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| //check whether the card number already exists查询一下卡号是否已经存在 | |||
| NetSDKLib.NET_IN_FIND_RECORD_PARAM inParam = new NetSDKLib.NET_IN_FIND_RECORD_PARAM(); | |||
| inParam.emType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; | |||
| //查询条件 | |||
| NetSDKLib.FIND_RECORD_ACCESSCTLCARD_CONDITION condition = new NetSDKLib.FIND_RECORD_ACCESSCTLCARD_CONDITION(); | |||
| //卡号查询有效 | |||
| condition.abCardNo = 1; | |||
| if (cardNo.length > condition.szCardNo.length - 1) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCardNoExceedLength(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| System.arraycopy(cardNo, 0, condition.szCardNo, 0, cardNo.length); | |||
| inParam.pQueryCondition = new Memory(condition.size()); | |||
| ToolKits.SetStructDataToPointer(condition, inParam.pQueryCondition, 0); | |||
| NetSDKLib.NET_OUT_FIND_RECORD_PARAM outParam = new NetSDKLib.NET_OUT_FIND_RECORD_PARAM(); | |||
| boolean startFind = LoginModule.netsdk.CLIENT_FindRecord(LoginModule.m_hLoginHandle, inParam, outParam, 5000); | |||
| if (!startFind) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getQueryCardExistFailed(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| //查询卡号是否已存在 | |||
| int max = 1; | |||
| NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM inNextParam = new NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM(); | |||
| inNextParam.lFindeHandle = outParam.lFindeHandle; | |||
| inNextParam.nFileCount = max; | |||
| NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM outNextParam = new NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM(); | |||
| outNextParam.nMaxRecordNum = max; | |||
| NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD[] card = new NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD[1]; | |||
| card[0] = new NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD(); | |||
| outNextParam.pRecordList = new Memory(card[0].size() * max); | |||
| ToolKits.SetStructArrToPointerData(card, outNextParam.pRecordList); | |||
| LoginModule.netsdk.CLIENT_FindNextRecord(inNextParam, outNextParam, 5000); | |||
| if (outNextParam.nRetRecordNum != 0 && type) { | |||
| //卡号已存在 | |||
| JOptionPane.showMessageDialog(null, Res.string().getFindCardExist(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| //停止查询 | |||
| LoginModule.netsdk.CLIENT_FindRecordClose(outParam.lFindeHandle); | |||
| return false; | |||
| } | |||
| //停止查询 | |||
| LoginModule.netsdk.CLIENT_FindRecordClose(outParam.lFindeHandle); | |||
| return true; | |||
| } | |||
| /** | |||
| * 新增卡 | |||
| */ | |||
| public boolean addCard(byte[] cardNo, byte[] userID, int enableFinger, String fingerPrintData) { | |||
| if (cardNo.length == 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInputCardNo(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| if (userID.length == 0) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getInputRoomNo(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| if (memory == null) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getChooseFacePic(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD card = new NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD(); | |||
| if (cardNo.length > card.szCardNo.length - 1) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getCardNoExceedLength(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| if (userID.length > card.szUserID.length - 1) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getRoomNoExceedLength(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| System.arraycopy(cardNo, 0, card.szCardNo, 0, cardNo.length); | |||
| System.arraycopy(userID, 0, card.szUserID, 0, userID.length); | |||
| card.nDoorNum = 1; | |||
| card.sznDoors[0] = 0; | |||
| if (enableFinger == 1) { | |||
| //信息不存在 | |||
| if (fingerPrintData == null || fingerPrintData.trim().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFingerPrintIdNotExist(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| //base64 string to bytes | |||
| byte[] bytes = Base64.getDecoder().decode(fingerPrintData); | |||
| //增加信息 | |||
| card.bEnableExtended = 1; | |||
| card.stuFingerPrintInfoEx.nCount = 1; | |||
| card.stuFingerPrintInfoEx.nLength = bytes.length; | |||
| card.stuFingerPrintInfoEx.nPacketLen = bytes.length; | |||
| card.stuFingerPrintInfoEx.pPacketData = new Memory(bytes.length); | |||
| card.stuFingerPrintInfoEx.pPacketData.clear(bytes.length); | |||
| card.stuFingerPrintInfoEx.pPacketData.write(0, bytes, 0, bytes.length); | |||
| } else { | |||
| card.bEnableExtended = 0; | |||
| } | |||
| NetSDKLib.NET_CTRL_RECORDSET_INSERT_PARAM inParam = new NetSDKLib.NET_CTRL_RECORDSET_INSERT_PARAM(); | |||
| inParam.stuCtrlRecordSetInfo.emType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; | |||
| inParam.stuCtrlRecordSetInfo.nBufLen = card.size(); | |||
| inParam.stuCtrlRecordSetInfo.pBuf = new Memory(card.size()); | |||
| ToolKits.SetStructDataToPointer(card, inParam.stuCtrlRecordSetInfo.pBuf, 0); | |||
| Pointer pointer = new Memory(inParam.size()); | |||
| ToolKits.SetStructDataToPointer(inParam, pointer, 0); | |||
| // 插入信息必须用 CTRLTYPE_CTRL_RECORDSET_INSERTEX,不能用 CTRLTYPE_CTRL_RECORDSET_INSERT | |||
| boolean res = LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, CTRLTYPE_CTRL_RECORDSET_INSERTEX, pointer, 5000); | |||
| if (!res) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return res; | |||
| } | |||
| ToolKits.GetPointerData(pointer, inParam); | |||
| if (memory != null) { | |||
| //增加人脸图片 | |||
| NetSDKLib.NET_IN_ADD_FACE_INFO inAddFaceInfo = new NetSDKLib.NET_IN_ADD_FACE_INFO(); | |||
| System.arraycopy(userID, 0, inAddFaceInfo.szUserID, 0, userID.length); | |||
| inAddFaceInfo.stuFaceInfo.nFacePhoto = 1; | |||
| inAddFaceInfo.stuFaceInfo.nFacePhotoLen[0] = (int) memory.size(); | |||
| inAddFaceInfo.stuFaceInfo.pszFacePhotoArr[0].pszFacePhoto = new Memory(memory.size()); | |||
| inAddFaceInfo.stuFaceInfo.pszFacePhotoArr[0].pszFacePhoto.write(0, memory.getByteArray(0, (int) memory.size()), 0, (int) memory.size()); | |||
| inAddFaceInfo.stuFaceInfo.nRoom = 1; | |||
| System.arraycopy(userID, 0, inAddFaceInfo.stuFaceInfo.szRoomNoArr[0].szRoomNo, 0, userID.length); | |||
| NetSDKLib.NET_OUT_ADD_FACE_INFO outAddFaceInfo = new NetSDKLib.NET_OUT_ADD_FACE_INFO(); | |||
| Pointer outFaceParam = new Memory(outAddFaceInfo.size()); | |||
| ToolKits.SetStructDataToPointer(outAddFaceInfo, outFaceParam, 0); | |||
| Pointer inFace = new Memory(inAddFaceInfo.size()); | |||
| ToolKits.SetStructDataToPointer(inAddFaceInfo, inFace, 0); | |||
| boolean result = LoginModule.netsdk.CLIENT_FaceInfoOpreate(LoginModule.m_hLoginHandle, NetSDKLib.EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_ADD, | |||
| inFace, outFaceParam, 10000); | |||
| if (!result) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 修改卡信息 | |||
| * | |||
| * @param cardNo 卡号 | |||
| * @param userID 房间号 | |||
| * @param enableFinger 是否使用信息 | |||
| * @param fingerPrintData 信息数据,Base64编码字符串 | |||
| */ | |||
| public boolean modifyCard(byte[] cardNo, byte[] userID, int enableFinger, String fingerPrintData) { | |||
| //modify card | |||
| NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD card = new NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD(); | |||
| NetSDKLib.NET_CTRL_RECORDSET_PARAM inParam = new NetSDKLib.NET_CTRL_RECORDSET_PARAM(); | |||
| inParam.emType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; | |||
| card.nDoorNum = 1; | |||
| card.sznDoors[0] = 0; | |||
| System.arraycopy(cardNo, 0, card.szCardNo, 0, cardNo.length); | |||
| System.arraycopy(userID, 0, card.szUserID, 0, userID.length); | |||
| if (enableFinger == 1) { | |||
| //信息不存在,输入信息 | |||
| if (fingerPrintData == null || fingerPrintData.trim().equals("")) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFingerPrintIdNotExist(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| byte[] data = Base64.getDecoder().decode(fingerPrintData); | |||
| //modify finger print | |||
| card.bEnableExtended = 1; | |||
| card.stuFingerPrintInfoEx.nCount = 1; | |||
| card.stuFingerPrintInfoEx.nLength = data.length; | |||
| card.stuFingerPrintInfoEx.nPacketLen = data.length; | |||
| card.stuFingerPrintInfoEx.pPacketData = new Memory(data.length); | |||
| card.stuFingerPrintInfoEx.pPacketData.clear(data.length); | |||
| card.stuFingerPrintInfoEx.pPacketData.write(0, data, 0, data.length); | |||
| } else { | |||
| card.bEnableExtended = 0; | |||
| } | |||
| inParam.pBuf = new Memory(card.size()); | |||
| ToolKits.SetStructDataToPointer(card, inParam.pBuf, 0); | |||
| Pointer pointer = new Memory(inParam.size()); | |||
| ToolKits.SetStructDataToPointer(inParam, pointer, 0); | |||
| boolean res = LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, CTRLTYPE_CTRL_RECORDSET_UPDATEEX, pointer, 10000); | |||
| if (!res) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailedModifyCard() + ", " + ToolKits.getErrorCodeShow(), | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return res; | |||
| } | |||
| //modify face | |||
| if (memory != null) { | |||
| NetSDKLib.NET_IN_UPDATE_FACE_INFO inUpdateFaceInfo = new NetSDKLib.NET_IN_UPDATE_FACE_INFO(); | |||
| System.arraycopy(userID, 0, inUpdateFaceInfo.szUserID, 0, userID.length); | |||
| inUpdateFaceInfo.stuFaceInfo.nFacePhoto = 1; | |||
| inUpdateFaceInfo.stuFaceInfo.nFacePhotoLen[0] = (int) memory.size(); | |||
| //inUpdateFaceInfo.stuFaceInfo.pszFacePhotoArr[0].pszFacePhoto=memory; | |||
| inUpdateFaceInfo.stuFaceInfo.pszFacePhotoArr[0].pszFacePhoto = new Memory(memory.size()); | |||
| inUpdateFaceInfo.stuFaceInfo.pszFacePhotoArr[0].pszFacePhoto.write(0, memory.getByteArray(0, (int) memory.size()), 0, (int) memory.size()); | |||
| inUpdateFaceInfo.stuFaceInfo.nRoom = 1; | |||
| System.arraycopy(userID, 0, inUpdateFaceInfo.stuFaceInfo.szRoomNoArr[0].szRoomNo, 0, userID.length); | |||
| NetSDKLib.NET_OUT_UPDATE_FACE_INFO outUpdateFaceInfo = new NetSDKLib.NET_OUT_UPDATE_FACE_INFO(); | |||
| Pointer inUpdateParam = new Memory(inUpdateFaceInfo.size()); | |||
| ToolKits.SetStructDataToPointer(inUpdateFaceInfo, inUpdateParam, 0); | |||
| Pointer outUpdateParam = new Memory(outUpdateFaceInfo.size()); | |||
| ToolKits.SetStructDataToPointer(outUpdateFaceInfo, outUpdateParam, 0); | |||
| boolean result = LoginModule.netsdk.CLIENT_FaceInfoOpreate(LoginModule.m_hLoginHandle, NetSDKLib.EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_UPDATE, inUpdateParam, outUpdateParam, 5000); | |||
| if (!result) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getFailedModifyCard() +","+ ToolKits.getErrorCodeShow(), | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return result; | |||
| } | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 清除人脸图片 | |||
| */ | |||
| public void clearImage() { | |||
| paintPanel.setOpaque(false); | |||
| paintPanel.setImage(null); | |||
| paintPanel.repaint(); | |||
| memory = null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,518 @@ | |||
| package com.netsdk.demo.frame.vto; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.EventQueue; | |||
| import java.awt.event.MouseAdapter; | |||
| import java.awt.event.MouseEvent; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import javax.swing.*; | |||
| import javax.swing.border.EmptyBorder; | |||
| import javax.swing.border.TitledBorder; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.Pointer; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| import com.netsdk.common.Base64; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import static com.netsdk.lib.NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; | |||
| import static com.netsdk.lib.NetSDKLib.NET_DEVSTATE_DEV_RECORDSET_EX; | |||
| public class OperateManager extends JDialog { | |||
| private NetSDKLib.LLong lFindHandle; | |||
| private JPanel contentPane; | |||
| private OperateInfo info; | |||
| private JTextField textField; | |||
| private JTable table; | |||
| private Object[][] data; | |||
| private String[] tableTitle = { | |||
| Res.string().getVTOOperateManagerRecNo(), | |||
| Res.string().getVTOOperateManagerRoomNo(), | |||
| Res.string().getVTOOperateManagerCardNo(), | |||
| Res.string().getVTOOperateManagerFingerPrintData() | |||
| }; | |||
| /** | |||
| * Launch the application. | |||
| */ | |||
| public static void main(String[] args) { | |||
| EventQueue.invokeLater(new Runnable() { | |||
| public void run() { | |||
| try { | |||
| OperateManager dialogManager = new OperateManager(); | |||
| dialogManager.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); | |||
| dialogManager.setVisible(true); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| /** | |||
| * Create the frame. | |||
| */ | |||
| public OperateManager() { | |||
| setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); | |||
| setTitle(Res.string().getVTOOperateManagerTitle()); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (ClassNotFoundException e) { | |||
| e.printStackTrace(); | |||
| } catch (InstantiationException e) { | |||
| e.printStackTrace(); | |||
| } catch (IllegalAccessException e) { | |||
| e.printStackTrace(); | |||
| } catch (UnsupportedLookAndFeelException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| setBounds(100, 100, 547, 414); | |||
| contentPane = new JPanel(); | |||
| contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| setContentPane(contentPane); | |||
| contentPane.setLayout(null); | |||
| JPanel panel = new JPanel(); | |||
| panel.setBorder(new TitledBorder(null, Res.string().getCardInfo(), TitledBorder.LEFT, | |||
| TitledBorder.TOP, null, null)); | |||
| panel.setBounds(0, 10, 328, 356); | |||
| contentPane.add(panel); | |||
| panel.setLayout(new BorderLayout(0, 0)); | |||
| JScrollPane scrollPane = new JScrollPane(); | |||
| panel.add(scrollPane, BorderLayout.CENTER); | |||
| data = new Object[0][5]; | |||
| table = tableInit(data, tableTitle); | |||
| scrollPane.setViewportView(table); | |||
| JLabel lblNewLabel = new JLabel(Res.string().getVTORealLoadCardNo()); | |||
| lblNewLabel.setBounds(338, 24, 95, 20); | |||
| contentPane.add(lblNewLabel); | |||
| textField = new JTextField(); | |||
| textField.setBounds(338, 54, 136, 21); | |||
| contentPane.add(textField); | |||
| textField.setColumns(10); | |||
| JButton btnSearch = new JButton(Res.string().getSearch()); | |||
| btnSearch.setBounds(338, 85, 136, 23); | |||
| contentPane.add(btnSearch); | |||
| btnSearch.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| search(); | |||
| } | |||
| }); | |||
| JButton btnAdd = new JButton(Res.string().getAdd()); | |||
| btnAdd.setBounds(338, 138, 136, 23); | |||
| contentPane.add(btnAdd); | |||
| btnAdd.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| if (info == null) { | |||
| info = new OperateInfo(); | |||
| info.addWindowListener(new WindowAdapter() { | |||
| @Override | |||
| public void windowClosed(WindowEvent e) { | |||
| super.windowClosed(e); | |||
| search(); | |||
| } | |||
| }); | |||
| } | |||
| info.setVisible(true); | |||
| //设置卡号可编辑 | |||
| info.setCardNoTextFieldEditEnable(true); | |||
| //设置房间号可编辑 | |||
| info.setRoomNoTextFieldEditEnable(true); | |||
| info.setFocusable(true); | |||
| //新增卡 | |||
| info.receiveData(0, "", "", ""); | |||
| info.clearImage(); | |||
| } | |||
| }); | |||
| JButton btnModify = new JButton(Res.string().getModify()); | |||
| btnModify.setBounds(338, 193, 136, 23); | |||
| contentPane.add(btnModify); | |||
| btnModify.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| //modify(); | |||
| if (table.getSelectedRowCount() != 1) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getSelectCard(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| if (table.getSelectedRowCount() == 1) { | |||
| if (info == null) { | |||
| info = new OperateInfo(); | |||
| info.addWindowListener(new WindowAdapter() { | |||
| @Override | |||
| public void windowClosed(WindowEvent e) { | |||
| super.windowClosed(e); | |||
| search(); | |||
| } | |||
| }); | |||
| } | |||
| info.setVisible(true); | |||
| //设置卡号不可编辑 | |||
| info.setCardNoTextFieldEditEnable(false); | |||
| //设置房间号不可编辑 | |||
| info.setRoomNoTextFieldEditEnable(false); | |||
| info.setFocusable(true); | |||
| //修改卡信息 | |||
| /** | |||
| * 设置info的数据 | |||
| */ | |||
| info.receiveData(1, ((String) table.getModel().getValueAt(table.getSelectedRow(), 1)).trim(), | |||
| ((String) table.getModel().getValueAt(table.getSelectedRow(), 2)).trim(), | |||
| ((String) table.getModel().getValueAt(table.getSelectedRow(), 3)).trim()); | |||
| //清除人脸缓存数据 | |||
| info.clearImage(); | |||
| info.setVisible(true); | |||
| info.setFocusable(true); | |||
| } | |||
| } | |||
| }); | |||
| JButton btnDelete = new JButton(Res.string().getDelete()); | |||
| btnDelete.setBounds(338, 245, 136, 23); | |||
| contentPane.add(btnDelete); | |||
| btnDelete.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| delete(); | |||
| //更新卡数据显示 | |||
| search(); | |||
| } | |||
| }); | |||
| JButton btnClear = new JButton(Res.string().getClear()); | |||
| btnClear.setBounds(338, 303, 136, 23); | |||
| contentPane.add(btnClear); | |||
| btnClear.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| clear(); | |||
| //更新卡数据显示 | |||
| search(); | |||
| } | |||
| }); | |||
| } | |||
| /** | |||
| * 表格初始化 | |||
| * | |||
| * @param data 表格数据 | |||
| * @param columnName 表头名称 | |||
| * @return | |||
| */ | |||
| public JTable tableInit(Object[][] data, String[] columnName) { | |||
| JTable table; | |||
| DefaultTableModel model; | |||
| model = new DefaultTableModel(data, columnName); | |||
| table = new JTable(model) { | |||
| @Override // 不可编辑 | |||
| public boolean isCellEditable(int row, int column) { | |||
| return false; | |||
| } | |||
| }; | |||
| model = (DefaultTableModel) table.getModel(); | |||
| /*DefaultTableCellHeaderRenderer titleRender = new DefaultTableCellHeaderRenderer(); | |||
| titleRender.setHorizontalAlignment(JLabel.CENTER); | |||
| table.getTableHeader().setDefaultRenderer(titleRender);*/ | |||
| table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行 | |||
| // 列表显示居中 | |||
| DefaultTableCellRenderer dCellRenderer = new DefaultTableCellRenderer(); | |||
| dCellRenderer.setHorizontalAlignment(JLabel.CENTER); | |||
| table.setDefaultRenderer(Object.class, dCellRenderer); | |||
| return table; | |||
| } | |||
| /** | |||
| * 查询卡数据 | |||
| */ | |||
| public void search() { | |||
| if (lFindHandle != null && lFindHandle.longValue() != 0) { | |||
| LoginModule.netsdk.CLIENT_FindRecordClose(lFindHandle); | |||
| lFindHandle = null; | |||
| } | |||
| //清除table数据 | |||
| DefaultTableModel model = (DefaultTableModel) table.getModel(); | |||
| model.setRowCount(0); | |||
| //开始查询记录 | |||
| NetSDKLib.NET_IN_FIND_RECORD_PARAM inParam = new NetSDKLib.NET_IN_FIND_RECORD_PARAM(); | |||
| NetSDKLib.NET_OUT_FIND_RECORD_PARAM outParam = new NetSDKLib.NET_OUT_FIND_RECORD_PARAM(); | |||
| //门禁卡 | |||
| inParam.emType = NET_RECORD_ACCESSCTLCARD; | |||
| NetSDKLib.FIND_RECORD_ACCESSCTLCARD_CONDITION condition = new NetSDKLib.FIND_RECORD_ACCESSCTLCARD_CONDITION(); | |||
| if (textField.getText() != null && !textField.getText().equals("")) { | |||
| //卡号非空,为条件查询 | |||
| condition.abCardNo = 1; | |||
| String cardNo = textField.getText(); | |||
| System.arraycopy(cardNo.getBytes(), 0, condition.szCardNo, 0, cardNo.getBytes().length); | |||
| inParam.pQueryCondition = new Memory(condition.size()); | |||
| ToolKits.SetStructDataToPointer(condition, inParam.pQueryCondition, 0); | |||
| } | |||
| boolean bRet = LoginModule.netsdk.CLIENT_FindRecord(LoginModule.m_hLoginHandle, inParam, outParam, 10000); | |||
| if (!bRet) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| lFindHandle = outParam.lFindeHandle; | |||
| //Query查询所有数据 | |||
| queryData(); | |||
| //结束查询 | |||
| boolean success = LoginModule.netsdk.CLIENT_FindRecordClose(lFindHandle); | |||
| if (!success) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| /** | |||
| * 循环遍历获取卡数据 | |||
| */ | |||
| public void queryData() { | |||
| DefaultTableModel model = (DefaultTableModel) table.getModel(); | |||
| while (true) { | |||
| int max = 20; | |||
| //query the next batch of data 查询下一组数据 | |||
| NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM inParam = new NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM(); | |||
| NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM outParam = new NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM(); | |||
| NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD[] cards = new NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD[max]; | |||
| for (int i = 0; i < max; i++) { | |||
| cards[i] = new NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD(); | |||
| } | |||
| outParam.pRecordList = new Memory(cards[0].size() * max); | |||
| outParam.nMaxRecordNum = max; | |||
| inParam.lFindeHandle = lFindHandle; | |||
| inParam.nFileCount = max; | |||
| ToolKits.SetStructArrToPointerData(cards, outParam.pRecordList); | |||
| boolean result = LoginModule.netsdk.CLIENT_FindNextRecord(inParam, outParam, 10000); | |||
| //获取数据 | |||
| ToolKits.GetPointerDataToStructArr(outParam.pRecordList, cards); | |||
| NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD card; | |||
| for (int i = 0; i < outParam.nRetRecordNum; i++) { | |||
| //获取到卡数据 | |||
| card = cards[i]; | |||
| //有信息信息,则获取信息数据 | |||
| String fingerPrint = ""; | |||
| card.bEnableExtended = 1; | |||
| card.stuFingerPrintInfoEx.nPacketLen = 2048; | |||
| card.stuFingerPrintInfoEx.pPacketData = new Memory(2048); | |||
| //获取信息信息 | |||
| fingerPrint = getFingerPrint(card); | |||
| //更新table数据显示 | |||
| model.addRow(new Object[]{card.nRecNo, new String(card.szUserID).trim(), new String(card.szCardNo).trim(), fingerPrint.trim()}); | |||
| } | |||
| //当前查询数与最大查询数不同,则查询结束 | |||
| if (outParam.nRetRecordNum != outParam.nMaxRecordNum || (outParam.nRetRecordNum == 0 && outParam.nMaxRecordNum == 0)) { | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 获取信息数据信息 | |||
| * | |||
| * @param card | |||
| * @return | |||
| */ | |||
| public String getFingerPrint(NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARD card) { | |||
| NetSDKLib.NET_CTRL_RECORDSET_PARAM inp = new NetSDKLib.NET_CTRL_RECORDSET_PARAM(); | |||
| inp.emType = NET_RECORD_ACCESSCTLCARD; | |||
| inp.pBuf = new Memory(card.size()); | |||
| ToolKits.SetStructDataToPointer(card, inp.pBuf, 0); | |||
| inp.nBufLen = card.size(); | |||
| Pointer pointer = new Memory(inp.size()); | |||
| ToolKits.SetStructDataToPointer(inp, pointer, 0); | |||
| boolean re = LoginModule.netsdk.CLIENT_QueryDevState(LoginModule.m_hLoginHandle, NET_DEVSTATE_DEV_RECORDSET_EX, pointer, inp.size(), new IntByReference(0), 5000); | |||
| if (re) { | |||
| //提取信息数据 | |||
| ToolKits.GetPointerDataToStruct(pointer, 0, inp); | |||
| //获取门禁卡信息 | |||
| ToolKits.GetPointerData(inp.pBuf, card); | |||
| byte[] fpData = new byte[card.stuFingerPrintInfoEx.nRealPacketLen]; | |||
| card.stuFingerPrintInfoEx.pPacketData.read(0, fpData, 0, fpData.length); | |||
| //转成base64编码 | |||
| return Base64.getEncoder().encodeToString(fpData); | |||
| } else { | |||
| /*JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE);*/ | |||
| System.out.println("Get Finger print data error.there is no data"); | |||
| } | |||
| return ""; | |||
| } | |||
| /** | |||
| * 删除卡相关信息 | |||
| */ | |||
| public void delete() { | |||
| if (table.getSelectedRowCount() != 1) { | |||
| JOptionPane.showMessageDialog(null, "please select a card", Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| int nRecNo = (Integer) table.getModel().getValueAt(table.getSelectedRow(), 0); | |||
| //删除卡 | |||
| if (!deleteCard(nRecNo)) { | |||
| return; | |||
| } | |||
| //删除人脸 | |||
| if (!deleteFaceInfo((String) table.getModel().getValueAt(table.getSelectedRow(), 1))) { | |||
| return; | |||
| } | |||
| } | |||
| /** | |||
| * 删除卡信息 | |||
| * | |||
| * @param recNo | |||
| * @return | |||
| */ | |||
| public boolean deleteCard(int recNo) { | |||
| NetSDKLib.NET_CTRL_RECORDSET_PARAM remove = new NetSDKLib.NET_CTRL_RECORDSET_PARAM(); | |||
| remove.emType = NET_RECORD_ACCESSCTLCARD; | |||
| remove.pBuf = new IntByReference(recNo).getPointer(); | |||
| remove.write(); | |||
| boolean result = LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, | |||
| NetSDKLib.CtrlType.CTRLTYPE_CTRL_RECORDSET_REMOVE, remove.getPointer(), 5000); | |||
| remove.read(); | |||
| if (!result) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * 删除人脸(单个删除) | |||
| * | |||
| * @param userId 用户ID | |||
| */ | |||
| public boolean deleteFaceInfo(String userId) { | |||
| int emType = NetSDKLib.EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_REMOVE; | |||
| /** | |||
| * 入参 | |||
| */ | |||
| NetSDKLib.NET_IN_REMOVE_FACE_INFO inRemove = new NetSDKLib.NET_IN_REMOVE_FACE_INFO(); | |||
| // 用户ID | |||
| System.arraycopy(userId.getBytes(), 0, inRemove.szUserID, 0, userId.getBytes().length); | |||
| /** | |||
| * 出参 | |||
| */ | |||
| NetSDKLib.NET_OUT_REMOVE_FACE_INFO outRemove = new NetSDKLib.NET_OUT_REMOVE_FACE_INFO(); | |||
| inRemove.write(); | |||
| outRemove.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_FaceInfoOpreate(LoginModule.m_hLoginHandle, emType, inRemove.getPointer(), outRemove.getPointer(), 5000); | |||
| inRemove.read(); | |||
| outRemove.read(); | |||
| if (!bRet) { | |||
| JOptionPane.showMessageDialog(null, Res.string().getRemoveCardFaceFailed() + "," + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 清除数据 | |||
| */ | |||
| public void clear() { | |||
| //清空人脸数据 | |||
| if (!clearFace()) { | |||
| return; | |||
| } | |||
| //清空卡信息 | |||
| if (clearCard()) { | |||
| return; | |||
| } | |||
| //重新查询,更新界面 | |||
| search(); | |||
| } | |||
| /** | |||
| * 清除人脸(清除所有) | |||
| */ | |||
| private boolean clearFace() { | |||
| int emType = NetSDKLib.EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_CLEAR; | |||
| /** | |||
| * 入参 | |||
| */ | |||
| NetSDKLib.NET_IN_CLEAR_FACE_INFO inClear = new NetSDKLib.NET_IN_CLEAR_FACE_INFO(); | |||
| /** | |||
| * 出参 | |||
| */ | |||
| NetSDKLib.NET_OUT_REMOVE_FACE_INFO outClear = new NetSDKLib.NET_OUT_REMOVE_FACE_INFO(); | |||
| inClear.write(); | |||
| outClear.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_FaceInfoOpreate(LoginModule.m_hLoginHandle, emType, inClear.getPointer(), outClear.getPointer(), 5000); | |||
| inClear.read(); | |||
| outClear.read(); | |||
| if (!bRet) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 清除卡信息 | |||
| * | |||
| * @return | |||
| */ | |||
| private boolean clearCard() { | |||
| NetSDKLib.NET_CTRL_RECORDSET_PARAM clear = new NetSDKLib.NET_CTRL_RECORDSET_PARAM(); | |||
| clear.emType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; // 记录集信息类型 | |||
| clear.write(); | |||
| boolean result = LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, | |||
| NetSDKLib.CtrlType.CTRLTYPE_CTRL_RECORDSET_CLEAR, clear.getPointer(), 5000); | |||
| clear.read(); | |||
| if (!result) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| return result; | |||
| } | |||
| } | |||
| @@ -0,0 +1,129 @@ | |||
| package com.netsdk.demo.frame.vto; | |||
| import com.sun.jna.Callback; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.PaintPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.common.SavePath; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import javax.imageio.ImageIO; | |||
| import javax.swing.*; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import java.awt.image.BufferedImage; | |||
| import java.io.ByteArrayInputStream; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import static com.netsdk.lib.NetSDKLib.EVENT_IVS_ACCESS_CTL; | |||
| /** | |||
| * @author 47081 | |||
| * @version 1.0 | |||
| * @description vto智能分析的回调函数, 建议写成单例模式 | |||
| * 对应接口 {@link NetSDKLib#CLIENT_RealLoadPictureEx(NetSDKLib.LLong, int, int, int, Callback, Pointer, Pointer)} | |||
| * @date 2020/8/15 | |||
| */ | |||
| public class VTOAnalyzerCallBack implements NetSDKLib.fAnalyzerDataCallBack { | |||
| private static VTOAnalyzerCallBack INSTANCE; | |||
| private JTable table; | |||
| private PaintPanel paintPanel; | |||
| private BufferedImage bufferedImage; | |||
| private VTOAnalyzerCallBack(JTable table,PaintPanel panel) { | |||
| this.table = table; | |||
| this.paintPanel=panel; | |||
| } | |||
| public static VTOAnalyzerCallBack getINSTANCE(JTable table,PaintPanel paintPanel) { | |||
| if (INSTANCE == null) { | |||
| INSTANCE = new VTOAnalyzerCallBack(table,paintPanel); | |||
| } | |||
| return INSTANCE; | |||
| } | |||
| @Override | |||
| public int invoke(NetSDKLib.LLong lAnalyzerHandle, int dwAlarmType, Pointer pAlarmInfo, Pointer pBuffer, int dwBufSize, Pointer dwUser, int nSequence, Pointer reserved) { | |||
| //门禁事件 | |||
| if (dwAlarmType == EVENT_IVS_ACCESS_CTL) { | |||
| NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO info = new NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO(); | |||
| ToolKits.GetPointerDataToStruct(pAlarmInfo, 0, info); | |||
| //更新列表 | |||
| if(table!=null){ | |||
| DefaultTableModel model= (DefaultTableModel) table.getModel(); | |||
| NetSDKLib.NET_TIME_EX time=info.UTC; | |||
| if(info.UTC.dwYear==0&&info.UTC.dwMonth==0&&info.UTC.dwDay==0){ | |||
| time=info.stuFileInfo.stuFileTime; | |||
| } | |||
| model.addRow(new Object[]{new String(info.szUserID).trim(),new String(info.szCardNo).trim(),time.toString().trim(),getEventInfo(info).trim()}); | |||
| } | |||
| if(pBuffer != null && dwBufSize > 0) { | |||
| String strFileName = SavePath.getSavePath().getSaveCapturePath(); | |||
| byte[] buf = pBuffer.getByteArray(0, dwBufSize); | |||
| ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf); | |||
| try { | |||
| bufferedImage = ImageIO.read(byteArrInput); | |||
| if (bufferedImage == null) { | |||
| return 0; | |||
| } | |||
| ImageIO.write(bufferedImage, "jpg", new File(strFileName)); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 界面显示抓图 | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| paintPanel.setOpaque(false); | |||
| paintPanel.setImage(bufferedImage); | |||
| paintPanel.repaint(); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // return 1; | |||
| return 0; | |||
| } | |||
| /** | |||
| * 获取事件信息 | |||
| * @param info | |||
| * @return | |||
| */ | |||
| private String getEventInfo(NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO info){ | |||
| StringBuilder builder=new StringBuilder(); | |||
| builder.append(Res.string().getChannel()).append(info.nChannelID).append(",") | |||
| .append(Res.string().getOpenMethod()).append(openDoorMethod(info.emOpenMethod)).append(",") | |||
| .append(Res.string().getOpenStatus()).append(info.bStatus==1?Res.string().getSucceed():Res.string().getFailed()); | |||
| return builder.toString(); | |||
| } | |||
| /** | |||
| * 开门方式 | |||
| * @param emOpenMethod | |||
| * @return | |||
| */ | |||
| private String openDoorMethod(int emOpenMethod) { | |||
| String method; | |||
| switch (emOpenMethod) { | |||
| case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_CARD: | |||
| method = Res.string().getCard(); | |||
| break; | |||
| case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_FACE_RECOGNITION: | |||
| method = Res.string().getFaceRecognition(); | |||
| break; | |||
| case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_FINGERPRINT: | |||
| method = Res.string().getFingerPrint(); | |||
| break; | |||
| case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_REMOTE: | |||
| method = Res.string().getRemoteCapture(); | |||
| break; | |||
| default: | |||
| method = Res.string().getUnKnow(); | |||
| break; | |||
| } | |||
| return method; | |||
| } | |||
| } | |||
| @@ -0,0 +1,640 @@ | |||
| package com.netsdk.demo.frame.vto; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Color; | |||
| import java.awt.EventQueue; | |||
| import java.awt.Panel; | |||
| import java.awt.event.MouseAdapter; | |||
| import java.awt.event.MouseEvent; | |||
| import java.awt.event.WindowAdapter; | |||
| import java.awt.event.WindowEvent; | |||
| import javax.swing.JButton; | |||
| import javax.swing.JFrame; | |||
| import javax.swing.JLabel; | |||
| import javax.swing.JOptionPane; | |||
| import javax.swing.JPanel; | |||
| import javax.swing.JPasswordField; | |||
| import javax.swing.JScrollPane; | |||
| import javax.swing.JTabbedPane; | |||
| import javax.swing.JTable; | |||
| import javax.swing.JTextField; | |||
| import javax.swing.ListSelectionModel; | |||
| import javax.swing.ScrollPaneConstants; | |||
| import javax.swing.SwingUtilities; | |||
| import javax.swing.UIManager; | |||
| import javax.swing.border.EmptyBorder; | |||
| import javax.swing.border.TitledBorder; | |||
| import javax.swing.table.DefaultTableCellRenderer; | |||
| import javax.swing.table.DefaultTableModel; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.FunctionList; | |||
| import com.netsdk.common.PaintPanel; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.demo.module.AlarmListenModule; | |||
| import com.netsdk.demo.module.GateModule; | |||
| import com.netsdk.demo.module.LoginModule; | |||
| import com.netsdk.demo.module.RealPlayModule; | |||
| import com.netsdk.demo.module.TalkModule; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.CtrlType; | |||
| import com.netsdk.lib.NetSDKLib.EM_OPEN_DOOR_TYPE; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.NetSDKLib.NET_CTRL_ACCESS_OPEN; | |||
| import com.netsdk.lib.ToolKits; | |||
| public class VTODemo extends JFrame { | |||
| private static final long serialVersionUID = 1L; | |||
| private JPanel contentPane; | |||
| private JTextField ipTextField; | |||
| private JTextField portTextField; | |||
| private JTextField userNameTextField; | |||
| private JPasswordField passwordField; | |||
| private JTable alarmTable; | |||
| private Panel realPlay; | |||
| private PaintPanel imagePanel; | |||
| private JButton btnLogin; | |||
| private JButton btnLogout; | |||
| private JButton btnRealPlay; | |||
| private JButton btnStopplay; | |||
| private JButton btnTalk; | |||
| private JButton btnStoptalk; | |||
| private JButton btnOpendoor; | |||
| private JButton btnClosedoor; | |||
| private JButton btnOperate; | |||
| private JButton btnStartlisten; | |||
| private JButton btnStoplisten; | |||
| private JButton btnStartrealload; | |||
| private JButton btnStoprealload; | |||
| JTabbedPane tabbedPane; | |||
| private static boolean b_RealPlay = false; | |||
| private static boolean b_Attachment = false; | |||
| private boolean isListen = false; | |||
| ///////////////////// 主面板 ///////////////////// | |||
| private static JFrame mainFrame = new JFrame(); | |||
| private OperateManager manager = new OperateManager(); | |||
| private Object[][] alarmData; | |||
| private Object[][] realData; | |||
| private DefaultTableModel alarmModel; | |||
| private DefaultTableModel realModel; | |||
| private final String[] alarmTableTitle = {Res.string().getVTOAlarmEventRoomNo(), | |||
| Res.string().getVTOAlarmEventCardNo(), Res.string().getVTOAlarmEventTime(), | |||
| Res.string().getVTOAlarmEventOpenMethod(), Res.string().getVTOAlarmEventStatus()}; | |||
| private final String[] realTableTitle = {Res.string().getVTORealLoadRoomNO(), Res.string().getVTORealLoadCardNo(), | |||
| Res.string().getVTORealLoadTime(), Res.string().getVTORealLoadEventInfo()}; | |||
| /** | |||
| * Launch the application. | |||
| */ | |||
| public static void main(String[] args) { | |||
| EventQueue.invokeLater(new Runnable() { | |||
| public void run() { | |||
| try { | |||
| VTODemo frame = new VTODemo(); | |||
| frame.setVisible(true); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| }); | |||
| } | |||
| /** | |||
| * Create the frame. | |||
| */ | |||
| public VTODemo() { | |||
| // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |||
| setTitle(Res.string().getVTO()); | |||
| setBounds(100, 100, 920, 651); | |||
| contentPane = new JPanel(); | |||
| contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); | |||
| setContentPane(contentPane); | |||
| contentPane.setLayout(null); | |||
| try { | |||
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| LoginModule.init(DefaultDisConnect.GetInstance(), DefaultHaveReconnect.getINSTANCE()); | |||
| JPanel panel = new JPanel(); | |||
| panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), Res.string().getLogin(), | |||
| TitledBorder.LEFT, TitledBorder.TOP, null, new Color(0, 0, 0))); | |||
| panel.setBounds(0, 0, 905, 46); | |||
| contentPane.add(panel); | |||
| panel.setLayout(null); | |||
| JLabel ipLabel = new JLabel(Res.string().getIp()); | |||
| ipLabel.setBounds(10, 15, 44, 21); | |||
| panel.add(ipLabel); | |||
| ipTextField = new JTextField(); | |||
| ipTextField.setText("192.168.69.142"); | |||
| ipTextField.setBounds(64, 15, 89, 21); | |||
| panel.add(ipTextField); | |||
| ipTextField.setColumns(10); | |||
| JLabel portLabel = new JLabel(Res.string().getPort()); | |||
| portLabel.setBounds(174, 15, 44, 21); | |||
| panel.add(portLabel); | |||
| portTextField = new JTextField(); | |||
| portTextField.setText("37777"); | |||
| portTextField.setColumns(10); | |||
| portTextField.setBounds(228, 15, 66, 21); | |||
| panel.add(portTextField); | |||
| JLabel lblName = new JLabel(Res.string().getUserName()); | |||
| lblName.setBounds(316, 15, 66, 21); | |||
| panel.add(lblName); | |||
| userNameTextField = new JTextField(); | |||
| userNameTextField.setText("admin"); | |||
| userNameTextField.setColumns(10); | |||
| userNameTextField.setBounds(383, 15, 87, 21); | |||
| panel.add(userNameTextField); | |||
| JLabel lblPassword = new JLabel(Res.string().getPassword()); | |||
| lblPassword.setBounds(492, 15, 66, 21); | |||
| panel.add(lblPassword); | |||
| passwordField = new JPasswordField(); | |||
| passwordField.setBounds(568, 15, 112, 21); | |||
| passwordField.setText("yzx123456"); | |||
| panel.add(passwordField); | |||
| btnLogin = new JButton(Res.string().getLogin()); | |||
| btnLogin.setBounds(684, 14, 99, 23); | |||
| panel.add(btnLogin); | |||
| btnLogin.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| login(); | |||
| } | |||
| }); | |||
| btnLogout = new JButton(Res.string().getLogout()); | |||
| btnLogout.setBounds(785, 14, 110, 23); | |||
| panel.add(btnLogout); | |||
| btnLogout.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| logout(); | |||
| } | |||
| }); | |||
| JPanel previewPanel = new JPanel(); | |||
| previewPanel.setBorder( | |||
| new TitledBorder(null, Res.string().getRealplay(), TitledBorder.LEFT, TitledBorder.TOP, null, null)); | |||
| previewPanel.setBounds(10, 56, 409, 313); | |||
| contentPane.add(previewPanel); | |||
| previewPanel.setLayout(new BorderLayout(0, 0)); | |||
| realPlay = new Panel(); | |||
| realPlay.setBackground(Color.GRAY); | |||
| previewPanel.add(realPlay, BorderLayout.CENTER); | |||
| JPanel operatePanel = new JPanel(); | |||
| operatePanel.setBorder( | |||
| new TitledBorder(null, Res.string().getOperate(), TitledBorder.LEFT, TitledBorder.TOP, null, null)); | |||
| operatePanel.setBounds(429, 56, 452, 194); | |||
| contentPane.add(operatePanel); | |||
| operatePanel.setLayout(null); | |||
| btnRealPlay = new JButton(Res.string().getStartRealPlay()); | |||
| btnRealPlay.setBounds(37, 23, 162, 29); | |||
| operatePanel.add(btnRealPlay); | |||
| btnRealPlay.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| realPlay(); | |||
| } | |||
| }); | |||
| btnTalk = new JButton(Res.string().getStartTalk()); | |||
| btnTalk.setBounds(248, 23, 152, 29); | |||
| operatePanel.add(btnTalk); | |||
| btnTalk.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| talk(); | |||
| } | |||
| }); | |||
| btnStopplay = new JButton(Res.string().getStopRealPlay()); | |||
| btnStopplay.setBounds(37, 62, 162, 29); | |||
| operatePanel.add(btnStopplay); | |||
| btnStopplay.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| stopPlay(); | |||
| } | |||
| }); | |||
| btnStoptalk = new JButton(Res.string().getStopTalk()); | |||
| btnStoptalk.setBounds(248, 62, 152, 29); | |||
| operatePanel.add(btnStoptalk); | |||
| btnStoptalk.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| stopTalk(); | |||
| } | |||
| }); | |||
| btnOpendoor = new JButton(Res.string().getDoorOpen()); | |||
| btnOpendoor.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| openDoor(); | |||
| } | |||
| }); | |||
| btnOpendoor.setBounds(37, 110, 162, 29); | |||
| operatePanel.add(btnOpendoor); | |||
| btnClosedoor = new JButton(Res.string().getDoorClose()); | |||
| btnClosedoor.setBounds(37, 149, 162, 29); | |||
| operatePanel.add(btnClosedoor); | |||
| btnClosedoor.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| super.mouseClicked(e); | |||
| closeDoor(); | |||
| } | |||
| }); | |||
| btnOperate = new JButton(Res.string().getCardOperate()); | |||
| btnOperate.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| if (manager == null) { | |||
| manager = new OperateManager(); | |||
| } | |||
| manager.setVisible(true); | |||
| } | |||
| }); | |||
| btnOperate.setBounds(248, 125, 152, 29); | |||
| operatePanel.add(btnOperate); | |||
| JPanel eventOperate = new JPanel(); | |||
| eventOperate.setBorder(new TitledBorder(null, Res.string().getEventOperate(), TitledBorder.LEFT, | |||
| TitledBorder.TOP, null, null)); | |||
| eventOperate.setBounds(429, 260, 452, 104); | |||
| contentPane.add(eventOperate); | |||
| eventOperate.setLayout(null); | |||
| btnStartlisten = new JButton(Res.string().getStartListen()); | |||
| btnStartlisten.setBounds(35, 21, 178, 29); | |||
| eventOperate.add(btnStartlisten); | |||
| btnStartlisten.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| isListen = startListen(); | |||
| tabbedPane.setSelectedIndex(0); | |||
| } | |||
| }); | |||
| btnStoplisten = new JButton(Res.string().getStopListen()); | |||
| btnStoplisten.setBounds(35, 60, 178, 29); | |||
| eventOperate.add(btnStoplisten); | |||
| btnStoplisten.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| //table清空数据 | |||
| ((DefaultTableModel) alarmTable.getModel()).setRowCount(0); | |||
| stopListen(); | |||
| } | |||
| }); | |||
| btnStartrealload = new JButton(Res.string().getStartRealLoad()); | |||
| btnStartrealload.setBounds(234, 21, 195, 29); | |||
| eventOperate.add(btnStartrealload); | |||
| btnStartrealload.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| startRealLoad(); | |||
| tabbedPane.setSelectedIndex(1); | |||
| } | |||
| }); | |||
| btnStoprealload = new JButton(Res.string().getStopRealLoad()); | |||
| btnStoprealload.setBounds(234, 60, 195, 29); | |||
| eventOperate.add(btnStoprealload); | |||
| btnStoprealload.addMouseListener(new MouseAdapter() { | |||
| @Override | |||
| public void mouseClicked(MouseEvent e) { | |||
| //清空table数据 | |||
| ((DefaultTableModel) realLoadTable.getModel()).setRowCount(0); | |||
| stopRealLoad(); | |||
| //图片清空 | |||
| imagePanel.setImage(null); | |||
| imagePanel.repaint(); | |||
| } | |||
| }); | |||
| tabbedPane = new JTabbedPane(JTabbedPane.TOP); | |||
| tabbedPane.setBounds(10, 379, 871, 224); | |||
| contentPane.add(tabbedPane); | |||
| JPanel alarmPanel = new JPanel(); | |||
| alarmPanel.setBorder( | |||
| new TitledBorder(null, Res.string().getEventInfo(), TitledBorder.LEFT, TitledBorder.TOP, null, null)); | |||
| tabbedPane.addTab(Res.string().getAlarmEvent(), null, alarmPanel, null); | |||
| alarmPanel.setLayout(new BorderLayout(0, 0)); | |||
| alarmData = new Object[0][5]; | |||
| alarmTable = tableInit(alarmData, alarmTableTitle); | |||
| alarmModel = (DefaultTableModel) alarmTable.getModel(); | |||
| JScrollPane scrollPane = new JScrollPane(alarmTable); | |||
| scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |||
| alarmPanel.add(scrollPane, BorderLayout.CENTER); | |||
| JPanel realLoadPanel = new JPanel(); | |||
| realLoadPanel.setBorder(new TitledBorder(null, Res.string().getVTORealLoadEventInfo(), TitledBorder.LEFT, | |||
| TitledBorder.TOP, null, null)); | |||
| tabbedPane.addTab(Res.string().getRealLoadEvent(), null, realLoadPanel, null); | |||
| realLoadPanel.setLayout(null); | |||
| imagePanel = new PaintPanel(); | |||
| imagePanel.setBounds(671, 20, 185, 165); | |||
| realLoadPanel.add(imagePanel); | |||
| realData = new Object[0][4]; | |||
| realLoadTable = tableInit(realData, realTableTitle); | |||
| realModel = (DefaultTableModel) realLoadTable.getModel(); | |||
| realScrollPane = new JScrollPane(realLoadTable); | |||
| realScrollPane.setBounds(10, 20, 654, 165); | |||
| realScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |||
| realLoadPanel.add(realScrollPane); | |||
| btnEnable(false); | |||
| btnLogin.setEnabled(true); | |||
| addWindowListener(new WindowAdapter() { | |||
| @Override | |||
| public void windowClosing(WindowEvent e) { | |||
| if (LoginModule.m_hLoginHandle.longValue() != 0) { | |||
| logout(); | |||
| } | |||
| LoginModule.cleanup(); | |||
| dispose(); | |||
| SwingUtilities.invokeLater(new Runnable() { | |||
| public void run() { | |||
| FunctionList demo = new FunctionList(); | |||
| demo.setVisible(true); | |||
| } | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /** | |||
| * 按钮使能 | |||
| * | |||
| * @param enable | |||
| */ | |||
| public void btnEnable(boolean enable) { | |||
| btnLogin.setEnabled(enable); | |||
| btnLogout.setEnabled(enable); | |||
| btnRealPlay.setEnabled(enable); | |||
| btnStopplay.setEnabled(enable); | |||
| btnTalk.setEnabled(enable); | |||
| btnStoptalk.setEnabled(enable); | |||
| btnOpendoor.setEnabled(enable); | |||
| btnClosedoor.setEnabled(enable); | |||
| btnOperate.setEnabled(enable); | |||
| btnStartlisten.setEnabled(enable); | |||
| btnStoplisten.setEnabled(enable); | |||
| btnStartrealload.setEnabled(enable); | |||
| btnStoprealload.setEnabled(enable); | |||
| } | |||
| public JTable tableInit(Object[][] data, String[] columnName) { | |||
| JTable table; | |||
| DefaultTableModel model; | |||
| model = new DefaultTableModel(data, columnName); | |||
| table = new JTable(model) { | |||
| @Override // 不可编辑 | |||
| public boolean isCellEditable(int row, int column) { | |||
| return false; | |||
| } | |||
| }; | |||
| model = (DefaultTableModel) table.getModel(); | |||
| table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行 | |||
| // 列表显示居中 | |||
| DefaultTableCellRenderer dCellRenderer = new DefaultTableCellRenderer(); | |||
| dCellRenderer.setHorizontalAlignment(JLabel.CENTER); | |||
| table.setDefaultRenderer(Object.class, dCellRenderer); | |||
| return table; | |||
| } | |||
| /** | |||
| * 登录 | |||
| */ | |||
| public boolean login() { | |||
| if (LoginModule.login(ipTextField.getText(), Integer.parseInt(portTextField.getText()), | |||
| userNameTextField.getText(), new String(passwordField.getPassword()))) { | |||
| btnEnable(true); | |||
| btnLogin.setEnabled(false); | |||
| // 监听按钮使能 | |||
| btnRealPlay.setEnabled(true); | |||
| btnStopplay.setEnabled(false); | |||
| btnStartlisten.setEnabled(true); | |||
| btnStoplisten.setEnabled(false); | |||
| btnStartrealload.setEnabled(true); | |||
| btnStoprealload.setEnabled(false); | |||
| btnTalk.setEnabled(true); | |||
| btnStoptalk.setEnabled(false); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, Res.string().getLoginFailed() + ", " + ToolKits.getErrorCodeShow(), | |||
| Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 登出 | |||
| */ | |||
| public void logout() { | |||
| if (b_RealPlay) { | |||
| stopPlay(); | |||
| } | |||
| if (TalkModule.m_hTalkHandle != null) { | |||
| stopTalk(); | |||
| } | |||
| if (isListen) { | |||
| stopListen(); | |||
| isListen = false; | |||
| } | |||
| stopRealLoad(); | |||
| LoginModule.logout(); | |||
| btnEnable(false); | |||
| //清空两个表格 | |||
| //普通事件table清空数据 | |||
| ((DefaultTableModel) alarmTable.getModel()).setRowCount(0); | |||
| //智能事件table清空数据 | |||
| ((DefaultTableModel) realLoadTable.getModel()).setRowCount(0); | |||
| //图片清空 | |||
| imagePanel.setImage(null); | |||
| imagePanel.repaint(); | |||
| btnLogin.setEnabled(true); | |||
| } | |||
| private LLong m_hPlayHandle; | |||
| public void realPlay() { | |||
| if (!b_RealPlay) { | |||
| m_hPlayHandle = RealPlayModule.startRealPlay(0, 0, realPlay); | |||
| if (m_hPlayHandle.longValue() != 0) { | |||
| b_RealPlay = true; | |||
| btnRealPlay.setEnabled(false); | |||
| btnStopplay.setEnabled(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 停止实时预览 | |||
| */ | |||
| public void stopPlay() { | |||
| if (b_RealPlay) { | |||
| RealPlayModule.stopRealPlay(m_hPlayHandle); | |||
| realPlay.repaint(); | |||
| b_RealPlay = false; | |||
| btnRealPlay.setEnabled(true); | |||
| btnStopplay.setEnabled(false); | |||
| } | |||
| } | |||
| /** | |||
| * 对讲 | |||
| */ | |||
| public void talk() { | |||
| if (TalkModule.startTalk(0, 0)) { | |||
| btnTalk.setEnabled(false); | |||
| btnStoptalk.setEnabled(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| /** | |||
| * 停止对讲 | |||
| */ | |||
| public void stopTalk() { | |||
| TalkModule.stopTalk(); | |||
| btnTalk.setEnabled(true); | |||
| btnStoptalk.setEnabled(false); | |||
| } | |||
| /** | |||
| * 开门 | |||
| */ | |||
| public void openDoor() { | |||
| NET_CTRL_ACCESS_OPEN openInfo = new NET_CTRL_ACCESS_OPEN(); | |||
| openInfo.nChannelID = 0; | |||
| openInfo.emOpenDoorType = EM_OPEN_DOOR_TYPE.EM_OPEN_DOOR_TYPE_REMOTE; | |||
| Pointer pointer = new Memory(openInfo.size()); | |||
| ToolKits.SetStructDataToPointer(openInfo, pointer, 0); | |||
| boolean ret = LoginModule.netsdk.CLIENT_ControlDeviceEx(LoginModule.m_hLoginHandle, | |||
| CtrlType.CTRLTYPE_CTRL_ACCESS_OPEN, pointer, null, 10000); | |||
| if (!ret) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return; | |||
| } | |||
| } | |||
| /** | |||
| * 关门 | |||
| */ | |||
| public void closeDoor() { | |||
| final NetSDKLib.NET_CTRL_ACCESS_CLOSE close = new NetSDKLib.NET_CTRL_ACCESS_CLOSE(); | |||
| close.nChannelID = 0; // 对应的门编号 - 如何开全部的门 | |||
| close.write(); | |||
| Pointer pointer = new Memory(close.size()); | |||
| boolean result = LoginModule.netsdk.CLIENT_ControlDeviceEx(LoginModule.m_hLoginHandle, | |||
| NetSDKLib.CtrlType.CTRLTYPE_CTRL_ACCESS_CLOSE, close.getPointer(), null, 5000); | |||
| close.read(); | |||
| if (!result) { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| /** | |||
| * 监听事件 | |||
| */ | |||
| public boolean startListen() { | |||
| if (AlarmListenModule.startListen(VTOMessageCallBack.getINSTANCE(alarmTable, null))) { | |||
| btnStartlisten.setEnabled(false); | |||
| btnStoplisten.setEnabled(true); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 停止监听 | |||
| */ | |||
| public void stopListen() { | |||
| if (isListen) { | |||
| if (AlarmListenModule.stopListen()) { | |||
| isListen = false; | |||
| btnStartlisten.setEnabled(true); | |||
| btnStoplisten.setEnabled(false); | |||
| } else { | |||
| JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), | |||
| JOptionPane.ERROR_MESSAGE); | |||
| } | |||
| } | |||
| } | |||
| private LLong m_attachHandle; | |||
| private JTable realLoadTable; | |||
| private JScrollPane realScrollPane; | |||
| /** | |||
| * 智能事件监听 | |||
| */ | |||
| public void startRealLoad() { | |||
| m_attachHandle = GateModule.realLoadPic(0, VTOAnalyzerCallBack.getINSTANCE(realLoadTable, imagePanel)); | |||
| if (m_attachHandle != null && m_attachHandle.longValue() != 0) { | |||
| btnStartrealload.setEnabled(false); | |||
| btnStoprealload.setEnabled(true); | |||
| } | |||
| } | |||
| /** | |||
| * 停止智能事件监听 | |||
| */ | |||
| public void stopRealLoad() { | |||
| if (m_attachHandle != null && m_attachHandle.longValue() != 0) { | |||
| GateModule.stopRealLoadPic(m_attachHandle); | |||
| m_attachHandle.setValue(0); | |||
| btnStartrealload.setEnabled(true); | |||
| btnStoprealload.setEnabled(false); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,103 @@ | |||
| package com.netsdk.demo.frame.vto; | |||
| import com.sun.jna.NativeLong; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.common.Res; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import javax.swing.*; | |||
| import javax.swing.table.DefaultTableModel; | |||
| /** | |||
| * @author 47081 | |||
| * @version 1.0 | |||
| * @description vto监听事件的回调函数, 建议写成单例模式 | |||
| * @date 2020/8/15 | |||
| */ | |||
| public class VTOMessageCallBack implements NetSDKLib.fMessCallBack { | |||
| private static VTOMessageCallBack INSTANCE; | |||
| private JTable table; | |||
| private CollectionFingerPrint print; | |||
| private VTOMessageCallBack(JTable table) { | |||
| this.table = table; | |||
| } | |||
| public static VTOMessageCallBack getINSTANCE(JTable table, CollectionFingerPrint print) { | |||
| if (INSTANCE == null) { | |||
| INSTANCE = new VTOMessageCallBack(table); | |||
| } | |||
| if (table != null) { | |||
| INSTANCE.table = table; | |||
| } | |||
| if (print != null) { | |||
| INSTANCE.print = print; | |||
| } | |||
| return INSTANCE; | |||
| } | |||
| @Override | |||
| public boolean invoke(int lCommand, NetSDKLib.LLong lLoginID, Pointer pStuEvent, int dwBufLen, String strDeviceIP, NativeLong nDevicePort, Pointer dwUser) { | |||
| //门禁事件 | |||
| if (lCommand == NetSDKLib.NET_ALARM_ACCESS_CTL_EVENT) { | |||
| NetSDKLib.ALARM_ACCESS_CTL_EVENT_INFO info = new NetSDKLib.ALARM_ACCESS_CTL_EVENT_INFO(); | |||
| ToolKits.GetPointerDataToStruct(pStuEvent, 0, info); | |||
| //更新列表 | |||
| if (table != null) { | |||
| DefaultTableModel model = (DefaultTableModel) table.getModel(); | |||
| model.addRow(new Object[]{new String(info.szUserID).trim(), new String(info.szCardNo).trim(), info.stuTime.toStringTime(), openDoorMethod(info.emOpenMethod), info.bStatus == 1 ? Res.string().getSucceed() : Res.string().getFailed()}); | |||
| } | |||
| } | |||
| //信息事件 | |||
| if (lCommand == NetSDKLib.NET_ALARM_FINGER_PRINT) { | |||
| if (print != null) { | |||
| if (lLoginID.longValue() == print.getLoginHandler()) { | |||
| NetSDKLib.ALARM_CAPTURE_FINGER_PRINT_INFO info = new NetSDKLib.ALARM_CAPTURE_FINGER_PRINT_INFO(); | |||
| ToolKits.GetPointerDataToStruct(pStuEvent, 0, info); | |||
| print.setCollectionResult(info.bCollectResult == 1); | |||
| if (info.bCollectResult == 1) { | |||
| print.setPackageLen(info.nPacketLen * info.nPacketNum); | |||
| int length = info.nPacketLen * info.nPacketNum; | |||
| byte[] data = new byte[length]; | |||
| info.szFingerPrintInfo.read(0, data, 0, length); | |||
| print.setPackageData(data); | |||
| //显示结果 | |||
| print.setLabelResult(data); | |||
| } | |||
| print.stopListen(); | |||
| } | |||
| } | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 开门方式 | |||
| * | |||
| * @param emOpenMethod | |||
| * @return | |||
| */ | |||
| private String openDoorMethod(int emOpenMethod) { | |||
| String method; | |||
| switch (emOpenMethod) { | |||
| case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_CARD: | |||
| method = Res.string().getCard(); | |||
| break; | |||
| case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_FACE_RECOGNITION: | |||
| method = Res.string().getFaceRecognition(); | |||
| break; | |||
| case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_FINGERPRINT: | |||
| method = Res.string().getFingerPrint(); | |||
| break; | |||
| case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_REMOTE: | |||
| method = Res.string().getRemoteOpenDoor(); | |||
| break; | |||
| default: | |||
| method = Res.string().getUnKnow(); | |||
| break; | |||
| } | |||
| return method; | |||
| } | |||
| } | |||
| @@ -0,0 +1,75 @@ | |||
| package com.netsdk.demo.module; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.fMessCallBack; | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * alarm listen interface | |||
| * contains: start and stop alarm listen | |||
| * \else | |||
| * 报警接口实现 | |||
| * 包含 :向设备订阅报警和停止订阅报警 | |||
| * \endif | |||
| */ | |||
| public class AlarmListenModule { | |||
| private static boolean bListening = false; | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * start alarm listen | |||
| * \else | |||
| * 向设备订阅报警 | |||
| * \endif | |||
| */ | |||
| public static boolean startListen(fMessCallBack cbMessage) { | |||
| if (bListening) { | |||
| // System.out.println("Had Subscribe Alarm."); | |||
| return true; | |||
| } | |||
| LoginModule.netsdk.CLIENT_SetDVRMessCallBack(cbMessage, null); // set alarm listen callback | |||
| if (!LoginModule.netsdk.CLIENT_StartListenEx(LoginModule.m_hLoginHandle)) { | |||
| System.err.printf("CLIENT_StartListenEx Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } else { | |||
| System.out.println("CLIENT_StartListenEx success."); | |||
| } | |||
| bListening = true; | |||
| return true; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * stop alarm listen | |||
| * \else | |||
| * 停止订阅报警 | |||
| * \endif | |||
| */ | |||
| public static boolean stopListen() { | |||
| if (!bListening) { | |||
| return true; | |||
| } | |||
| if (!LoginModule.netsdk.CLIENT_StopListen(LoginModule.m_hLoginHandle)) { | |||
| System.err.printf("CLIENT_StopListen Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } else { | |||
| System.out.println("CLIENT_StopListen success."); | |||
| } | |||
| bListening = false; | |||
| return true; | |||
| } | |||
| } | |||
| @@ -0,0 +1,501 @@ | |||
| package com.netsdk.demo.module; | |||
| import java.io.UnsupportedEncodingException; | |||
| import com.sun.jna.Memory; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Attendance Interface | |||
| * contains:smart subscribe、CRUD of user&&fingerprint and collection fingerprint | |||
| * \else | |||
| * 考勤机接口实现 | |||
| * 包含: 智能订阅、考勤用户及信息的增删改查、信息采集 | |||
| * \endif | |||
| */ | |||
| public class AttendanceModule { | |||
| public static final int TIME_OUT = 3000; | |||
| public static final int nMaxFingerPrintSize = 2048; | |||
| public static LLong m_hAttachHandle = new LLong(0); | |||
| /** | |||
| * 智能订阅 | |||
| * @param callback 智能订阅回调函数 | |||
| */ | |||
| public static boolean realLoadPicture(fAnalyzerDataCallBack callback) { | |||
| int bNeedPicture = 0; // 不需要图片 | |||
| m_hAttachHandle = LoginModule.netsdk.CLIENT_RealLoadPictureEx(LoginModule.m_hLoginHandle, -1, | |||
| NetSDKLib.EVENT_IVS_ALL, bNeedPicture, callback, null, null); | |||
| if(m_hAttachHandle.longValue() == 0) { | |||
| System.err.printf("CLIENT_RealLoadPictureEx Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return m_hAttachHandle.longValue() != 0; | |||
| } | |||
| /** | |||
| * 停止智能订阅 | |||
| */ | |||
| public static void stopRealLoadPicture(){ | |||
| if (m_hAttachHandle.longValue() == 0) { | |||
| return; | |||
| } | |||
| LoginModule.netsdk.CLIENT_StopLoadPic(m_hAttachHandle); | |||
| m_hAttachHandle.setValue(0); | |||
| } | |||
| /** | |||
| * 考勤新增加用户 | |||
| * @param userId 用户ID | |||
| * @param userName 用户名 | |||
| * @param cardNo 卡号 | |||
| */ | |||
| public static boolean addUser(String userId, String userName, String cardNo) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_ATTENDANCE_ADDUSER stuIn = new NET_IN_ATTENDANCE_ADDUSER(); | |||
| stringToByteArray(userId, stuIn.stuUserInfo.szUserID); | |||
| stringToByteArray(userName, stuIn.stuUserInfo.szUserName); | |||
| stringToByteArray(cardNo, stuIn.stuUserInfo.szCardNo); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_ATTENDANCE_ADDUSER stuOut = new NET_OUT_ATTENDANCE_ADDUSER(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_Attendance_AddUser(LoginModule.m_hLoginHandle, stuIn, stuOut, TIME_OUT); | |||
| if (!bRet) { | |||
| System.err.printf("CLIENT_Attendance_AddUser Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 考勤删除用户 | |||
| * @param userId 用户ID | |||
| */ | |||
| public static boolean deleteUser(String userId) { | |||
| removeFingerByUserId(userId); // 先去删除信息 | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_ATTENDANCE_DELUSER stuIn = new NET_IN_ATTENDANCE_DELUSER(); | |||
| stringToByteArray(userId, stuIn.szUserID); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_ATTENDANCE_DELUSER stuOut = new NET_OUT_ATTENDANCE_DELUSER(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_Attendance_DelUser(LoginModule.m_hLoginHandle, stuIn, stuOut, TIME_OUT); | |||
| if (!bRet) { | |||
| System.err.printf("CLIENT_Attendance_DelUser Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 考勤修改用户 | |||
| * @param userId 用户ID | |||
| * @param userName 用户名 | |||
| * @param cardNo 卡号 | |||
| */ | |||
| public static boolean modifyUser(String userId, String userName, String cardNo) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_ATTENDANCE_ModifyUSER stuIn = new NET_IN_ATTENDANCE_ModifyUSER(); | |||
| stringToByteArray(userId, stuIn.stuUserInfo.szUserID); | |||
| stringToByteArray(userName, stuIn.stuUserInfo.szUserName); | |||
| stringToByteArray(cardNo, stuIn.stuUserInfo.szCardNo); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_ATTENDANCE_ModifyUSER stuOut = new NET_OUT_ATTENDANCE_ModifyUSER(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_Attendance_ModifyUser(LoginModule.m_hLoginHandle, stuIn, stuOut, TIME_OUT); | |||
| if (!bRet) { | |||
| System.err.printf("CLIENT_Attendance_ModifyUser Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 考勤机 查找用户 | |||
| * @param nOffset 查询偏移 | |||
| * @param nPagedQueryCount 查询个数 | |||
| * @return UserData[] 用户信息组 | |||
| */ | |||
| public static UserData[] findUser(int nOffset, int nPagedQueryCount) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_ATTENDANCE_FINDUSER stuIn = new NET_IN_ATTENDANCE_FINDUSER(); | |||
| stuIn.nOffset = nOffset; | |||
| stuIn.nPagedQueryCount = nPagedQueryCount; | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_ATTENDANCE_FINDUSER stuOut = new NET_OUT_ATTENDANCE_FINDUSER(); | |||
| NET_ATTENDANCE_USERINFO[] userInfo = new NET_ATTENDANCE_USERINFO[nPagedQueryCount]; | |||
| for(int i = 0; i < nPagedQueryCount; i++) { | |||
| userInfo[i] = new NET_ATTENDANCE_USERINFO(); | |||
| } | |||
| stuOut.nMaxUserCount = nPagedQueryCount; | |||
| stuOut.stuUserInfo = new Memory(userInfo[0].size() * stuOut.nMaxUserCount); | |||
| stuOut.stuUserInfo.clear(userInfo[0].size() * stuOut.nMaxUserCount); | |||
| ToolKits.SetStructArrToPointerData(userInfo, stuOut.stuUserInfo); // 将数组内存拷贝到Pointer | |||
| stuOut.nMaxPhotoDataLength = 128; | |||
| stuOut.pbyPhotoData = new Memory(stuOut.nMaxPhotoDataLength); // 申请内存 | |||
| boolean bRet = LoginModule.netsdk.CLIENT_Attendance_FindUser(LoginModule.m_hLoginHandle, stuIn, stuOut, TIME_OUT); | |||
| if (!bRet) { | |||
| System.err.printf("CLIENT_Attendance_FindUser Failed!" + ToolKits.getErrorCodePrint()); | |||
| return null; | |||
| } | |||
| ToolKits.GetPointerDataToStructArr(stuOut.stuUserInfo, userInfo); // 将 Pointer 的内容 输出到 数组 | |||
| UserData[] userData = new UserData[stuOut.nRetUserCount]; | |||
| for(int i = 0; i < stuOut.nRetUserCount; i++) { | |||
| userData[i] = new UserData(); | |||
| try { | |||
| userData[i].userId = new String(userInfo[i].szUserID, "GBK").trim(); | |||
| userData[i].userName = new String(userInfo[i].szUserName, "GBK").trim(); | |||
| userData[i].cardNo = new String(userInfo[i].szCardNo, "GBK").trim(); | |||
| }catch(Exception e) { // 如果转化失败就采用原始数据 | |||
| userData[i].userId = new String(userInfo[i].szUserID).trim(); | |||
| userData[i].userName = new String(userInfo[i].szUserName).trim(); | |||
| userData[i].cardNo = new String(userInfo[i].szCardNo).trim(); | |||
| } | |||
| // getFingerByUserId(userData[i].userId, userData[i]); // 获取信息信息 | |||
| } | |||
| UserData.nTotalUser = stuOut.nTotalUser; | |||
| return userData; | |||
| } | |||
| /** | |||
| * 考勤获取用户信息 | |||
| * @param userId 用户ID | |||
| * @return UserData 用户信息 | |||
| */ | |||
| public static UserData getUser(String userId) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_ATTENDANCE_GetUSER stuIn = new NET_IN_ATTENDANCE_GetUSER(); | |||
| stringToByteArray(userId, stuIn.szUserID); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_ATTENDANCE_GetUSER stuOut = new NET_OUT_ATTENDANCE_GetUSER(); | |||
| stuOut.nMaxLength = 128; | |||
| stuOut.pbyPhotoData = new Memory(stuOut.nMaxLength); // 申请内存 | |||
| stuOut.pbyPhotoData.clear(stuOut.nMaxLength); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_Attendance_GetUser(LoginModule.m_hLoginHandle, stuIn, stuOut, TIME_OUT); | |||
| if (!bRet) { | |||
| System.err.printf("CLIENT_Attendance_GetUser Failed!" + ToolKits.getErrorCodePrint()); | |||
| return null; | |||
| } | |||
| UserData userData = new UserData(); | |||
| try { | |||
| userData.userId = new String(stuOut.stuUserInfo.szUserID, "GBK").trim(); | |||
| userData.userName = new String(stuOut.stuUserInfo.szUserName, "GBK").trim(); | |||
| userData.cardNo = new String(stuOut.stuUserInfo.szCardNo, "GBK").trim(); | |||
| }catch(Exception e) { // 如果转化失败就采用原始数据 | |||
| userData.userId = new String(stuOut.stuUserInfo.szUserID).trim(); | |||
| userData.userName = new String(stuOut.stuUserInfo.szUserName).trim(); | |||
| userData.cardNo = new String(stuOut.stuUserInfo.szCardNo).trim(); | |||
| } | |||
| // getFingerByUserId(userId, userData); // 获取信息信息 | |||
| return userData; | |||
| } | |||
| /** | |||
| * 考勤机 通过用户ID插入信息数据 | |||
| * @param userId 用户ID | |||
| * @param szFingerPrintInfo 信息信息 | |||
| */ | |||
| public static boolean insertFingerByUserId(String userId, byte[] szFingerPrintInfo) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_FINGERPRINT_INSERT_BY_USERID stuIn = new NET_IN_FINGERPRINT_INSERT_BY_USERID(); | |||
| stringToByteArray(userId, stuIn.szUserID); | |||
| stuIn.nPacketCount = 1; | |||
| stuIn.nSinglePacketLen = szFingerPrintInfo.length; | |||
| stuIn.szFingerPrintInfo = new Memory(stuIn.nPacketCount * stuIn.nSinglePacketLen); // 申请内存 | |||
| stuIn.szFingerPrintInfo.clear(stuIn.nPacketCount * stuIn.nSinglePacketLen); | |||
| stuIn.szFingerPrintInfo.write(0, szFingerPrintInfo, 0, szFingerPrintInfo.length); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_FINGERPRINT_INSERT_BY_USERID stuOut = new NET_OUT_FINGERPRINT_INSERT_BY_USERID(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_Attendance_InsertFingerByUserID(LoginModule.m_hLoginHandle, stuIn, stuOut, TIME_OUT); | |||
| if (!bRet) { | |||
| System.err.printf("CLIENT_Attendance_InsertFingerByUserID Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 考勤机 删除单个用户下所有信息数据 | |||
| * @param userId 用户ID | |||
| */ | |||
| public static boolean removeFingerByUserId(String userId) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_CTRL_IN_FINGERPRINT_REMOVE_BY_USERID stuIn = new NET_CTRL_IN_FINGERPRINT_REMOVE_BY_USERID(); | |||
| stringToByteArray(userId, stuIn.szUserID); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_CTRL_OUT_FINGERPRINT_REMOVE_BY_USERID stuOut = new NET_CTRL_OUT_FINGERPRINT_REMOVE_BY_USERID(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_Attendance_RemoveFingerByUserID(LoginModule.m_hLoginHandle, stuIn, stuOut, TIME_OUT); | |||
| if (!bRet) { | |||
| System.err.printf("CLIENT_Attendance_RemoveFingerByUserID Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 考勤机 通过信息ID删除信息数据 | |||
| * @param nFingerPrintID 信息ID | |||
| */ | |||
| public static boolean removeFingerRecord(int nFingerPrintID) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_CTRL_IN_FINGERPRINT_REMOVE stuIn = new NET_CTRL_IN_FINGERPRINT_REMOVE(); | |||
| stuIn.nFingerPrintID = nFingerPrintID; | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_CTRL_OUT_FINGERPRINT_REMOVE stuOut = new NET_CTRL_OUT_FINGERPRINT_REMOVE(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_Attendance_RemoveFingerRecord(LoginModule.m_hLoginHandle, stuIn, stuOut, TIME_OUT); | |||
| if (!bRet) { | |||
| System.err.printf("CLIENT_Attendance_RemoveFingerRecord Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 考勤机 通过信息ID获取信息数据 | |||
| * @param nFingerPrintID 信息ID | |||
| * @return userData 用户数据 | |||
| */ | |||
| public static UserData getFingerRecord(int nFingerPrintID) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_CTRL_IN_FINGERPRINT_GET stuIn = new NET_CTRL_IN_FINGERPRINT_GET(); | |||
| stuIn.nFingerPrintID = nFingerPrintID; | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_CTRL_OUT_FINGERPRINT_GET stuOut = new NET_CTRL_OUT_FINGERPRINT_GET(); | |||
| stuOut.nMaxFingerDataLength = nMaxFingerPrintSize; | |||
| stuOut.szFingerPrintInfo = new Memory(stuOut.nMaxFingerDataLength); // 申请内存 | |||
| stuOut.szFingerPrintInfo.clear(stuOut.nMaxFingerDataLength); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_Attendance_GetFingerRecord(LoginModule.m_hLoginHandle, stuIn, stuOut, TIME_OUT); | |||
| if (!bRet) { | |||
| System.err.printf("CLIENT_Attendance_GetFingerRecord Failed!" + ToolKits.getErrorCodePrint()); | |||
| return null; | |||
| } | |||
| if (stuOut.nRetLength == 0) { | |||
| System.err.println("GetFingerRecord Failed nRetLength == 0!"); | |||
| } | |||
| UserData userData = new UserData(); | |||
| userData.userId = new String(stuOut.szUserID).trim(); | |||
| userData.nFingerPrintIDs = new int[1]; | |||
| userData.nFingerPrintIDs[0] = nFingerPrintID; | |||
| userData.szFingerPrintInfo = new byte[1][stuOut.nRetLength]; | |||
| stuOut.szFingerPrintInfo.read(0, userData.szFingerPrintInfo[0], 0, stuOut.nRetLength); | |||
| return userData; | |||
| } | |||
| /** | |||
| * 考勤机 通过用户ID查找该用户下的所有信息数据 | |||
| * @param userId 用户ID | |||
| * @param userData 用户数据 | |||
| */ | |||
| public static boolean getFingerByUserId(String userId, UserData userData) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_FINGERPRINT_GETBYUSER stuIn = new NET_IN_FINGERPRINT_GETBYUSER(); | |||
| stringToByteArray(userId, stuIn.szUserID); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_FINGERPRINT_GETBYUSER stuOut = new NET_OUT_FINGERPRINT_GETBYUSER(); | |||
| stuOut.nMaxFingerDataLength = NetSDKLib.NET_MAX_FINGER_PRINT * nMaxFingerPrintSize; | |||
| stuOut.pbyFingerData = new Memory(stuOut.nMaxFingerDataLength); // 申请内存 | |||
| stuOut.pbyFingerData.clear(stuOut.nMaxFingerDataLength); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_Attendance_GetFingerByUserID(LoginModule.m_hLoginHandle, stuIn, stuOut, TIME_OUT); | |||
| if (!bRet) { | |||
| System.err.printf("CLIENT_Attendance_GetFingerByUserID Failed!" + ToolKits.getErrorCodePrint()); | |||
| }else { | |||
| userData.nFingerPrintIDs = new int[stuOut.nRetFingerPrintCount]; | |||
| userData.szFingerPrintInfo = new byte[stuOut.nRetFingerPrintCount][stuOut.nSinglePacketLength]; | |||
| int offset = 0; | |||
| for (int i = 0; i < stuOut.nRetFingerPrintCount; ++i) { | |||
| userData.nFingerPrintIDs[i] = stuOut.nFingerPrintIDs[i]; | |||
| stuOut.pbyFingerData.read(offset, userData.szFingerPrintInfo[i], 0, stuOut.nSinglePacketLength); | |||
| offset += stuOut.nSinglePacketLength; | |||
| } | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 信息采集 | |||
| * @param nChannelID 门禁序号 | |||
| * @param szReaderID 读卡器ID | |||
| */ | |||
| public static boolean collectionFinger(int nChannelID, String szReaderID) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_CTRL_CAPTURE_FINGER_PRINT stuCollection = new NET_CTRL_CAPTURE_FINGER_PRINT(); | |||
| stuCollection.nChannelID = nChannelID; | |||
| stringToByteArray(szReaderID, stuCollection.szReaderID); | |||
| stuCollection.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_ControlDeviceEx(LoginModule.m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_CTRL_CAPTURE_FINGER_PRINT, stuCollection.getPointer(), null, 5000); | |||
| if (!bRet) { | |||
| System.err.printf("CLIENT_ControlDeviceEx CAPTURE_FINGER_PRINT Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 字符串转字符数组 | |||
| * @param src 源字符串 | |||
| * @param dst 目标字符数组 | |||
| */ | |||
| public static void stringToByteArray(String src, byte[] dst) { | |||
| if (src == null || src.isEmpty()) { | |||
| return; | |||
| } | |||
| for(int i = 0; i < dst.length; i++) { | |||
| dst[i] = 0; | |||
| } | |||
| byte []szSrc; | |||
| try { | |||
| szSrc = src.getBytes("GBK"); | |||
| } catch (UnsupportedEncodingException e) { | |||
| szSrc = src.getBytes(); | |||
| } | |||
| if (szSrc != null) { | |||
| int len = szSrc.length >= dst.length ? dst.length-1:szSrc.length; | |||
| System.arraycopy(szSrc, 0, dst, 0, len); | |||
| } | |||
| } | |||
| /** | |||
| * 用户信息 | |||
| * */ | |||
| public static class UserData { | |||
| public static int nTotalUser; // 用户总数 | |||
| public String userId; // 用户ID | |||
| public String userName; // 用户名 | |||
| public String cardNo; // 卡号 | |||
| public int[] nFingerPrintIDs; // 信息ID数组 | |||
| public byte[][] szFingerPrintInfo; // 信息数据数组 | |||
| } | |||
| /** | |||
| * 门禁事件信息 | |||
| * */ | |||
| public static class AccessEventInfo { | |||
| public String userId; // 用户ID | |||
| public String cardNo; // 卡号 | |||
| public String eventTime; // 事件发生时间 | |||
| public int openDoorMethod; // 开门方式 | |||
| } | |||
| /** | |||
| * 操作类型 | |||
| * */ | |||
| public enum OPERATE_TYPE { | |||
| UNKNOWN, // 未知 | |||
| SEARCH_USER, // 搜索用户(第一页) | |||
| PRE_SEARCH_USER, // 搜索用户(上一页) | |||
| NEXT_SEARCH_USER, // 搜索用户(下一页) | |||
| SEARCH_USER_BY_USERID, // 通过用户ID搜索用户 | |||
| ADD_USER, // 添加用户 | |||
| DELETE_USER, // 删除用户 | |||
| MODIFIY_USER, // 修改用户 | |||
| FINGERPRINT_OPEARTE_BY_USERID, // 通过用户ID操作信息 | |||
| FINGERPRINT_OPEARTE_BY_ID, // 通过信息ID操作信息 | |||
| SEARCH_FINGERPRINT_BY_USERID, // 通过用户ID搜索信息 | |||
| SEARCH_FINGERPRINT_BY_ID, // 通过信息ID搜索信息 | |||
| ADD_FINGERPRINT, // 添加信息 | |||
| DELETE_FINGERPRINT_BY_USERID, // 通过用户ID删除信息 | |||
| DELETE_FINGERPRINT_BY_ID // 通过信息ID删除信息 | |||
| }; | |||
| } | |||
| @@ -0,0 +1,346 @@ | |||
| package com.netsdk.demo.module; | |||
| import java.awt.Panel; | |||
| import com.netsdk.lib.NetSDKLib.CFG_DVRIP_INFO; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY; | |||
| import com.netsdk.lib.NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY; | |||
| import com.netsdk.lib.NetSDKLib.fServiceCallBack; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.sun.jna.Native; | |||
| import com.sun.jna.Pointer; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| public class AutoRegisterModule { | |||
| // 监听服务句柄 | |||
| public static LLong mServerHandler = new LLong(0); | |||
| // 设备信息 | |||
| public static NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex(); | |||
| // 语音对讲句柄 | |||
| public static LLong m_hTalkHandle = new LLong(0); | |||
| private static boolean m_bRecordStatus = false; | |||
| /** | |||
| * 开启服务 | |||
| * @param address 本地IP地址 | |||
| * @param port 本地端口, 可以任意 | |||
| * @param callback 回调函数 | |||
| */ | |||
| public static boolean startServer(String address, int port, fServiceCallBack callback) { | |||
| mServerHandler = LoginModule.netsdk.CLIENT_ListenServer(address, port, 1000, callback, null); | |||
| if (0 == mServerHandler.longValue()) { | |||
| System.err.println("Failed to start server." + ToolKits.getErrorCodePrint()); | |||
| } else { | |||
| System.out.printf("Start server, [Server address %s][Server port %d]\n", address, port); | |||
| } | |||
| return mServerHandler.longValue() != 0; | |||
| } | |||
| /** | |||
| * 结束服务 | |||
| */ | |||
| public static boolean stopServer() { | |||
| boolean bRet = false; | |||
| if(mServerHandler.longValue() != 0) { | |||
| bRet = LoginModule.netsdk.CLIENT_StopListenServer(mServerHandler); | |||
| mServerHandler.setValue(0); | |||
| System.out.println("Stop server!"); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 登录设备(主动注册登陆接口) | |||
| * @param m_strIp 设备IP | |||
| * @param m_nPort 设备端口号 | |||
| * @param m_strUser 设备用户名 | |||
| * @param m_strPassword 设备密码 | |||
| * @param deviceId 设备ID | |||
| * @return | |||
| */ | |||
| public static LLong login(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, String deviceIds) { | |||
| Pointer deviceId = ToolKits.GetGBKStringToPointer(deviceIds); | |||
| //IntByReference nError = new IntByReference(0); | |||
| //入参 | |||
| NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY pstInParam=new NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY(); | |||
| pstInParam.nPort=m_nPort; | |||
| pstInParam.szIP=m_strIp.getBytes(); | |||
| pstInParam.szPassword=m_strPassword.getBytes(); | |||
| pstInParam.szUserName=m_strUser.getBytes(); | |||
| pstInParam.emSpecCap = 2;// 主动注册方式 | |||
| pstInParam.pCapParam=deviceId; | |||
| //出参 | |||
| NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY pstOutParam=new NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY(); | |||
| pstOutParam.stuDeviceInfo=m_stDeviceInfo; | |||
| /*LLong m_hLoginHandle = LoginModule.netsdk.CLIENT_LoginEx2(m_strIp, m_nPort, m_strUser, m_strPassword, | |||
| tcpSpecCap, deviceId, m_stDeviceInfo, nError);*/ | |||
| LLong m_hLoginHandle=LoginModule.netsdk.CLIENT_LoginWithHighLevelSecurity(pstInParam, pstOutParam); | |||
| return m_hLoginHandle; | |||
| } | |||
| /** | |||
| * 登出设备 | |||
| * @param m_hLoginHandle 登陆句柄 | |||
| * @return | |||
| */ | |||
| public static boolean logout(LLong m_hLoginHandle) { | |||
| boolean bRet = false; | |||
| if(m_hLoginHandle.longValue() != 0) { | |||
| bRet = LoginModule.netsdk.CLIENT_Logout(m_hLoginHandle); | |||
| m_hLoginHandle.setValue(0); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 开始预览 | |||
| * @param m_hLoginHandle 登陆句柄 | |||
| * @param channel 通道号 | |||
| * @param stream 码流类型 | |||
| * @param realPlayWindow 拉流窗口 | |||
| * @return | |||
| */ | |||
| public static LLong startRealPlay(LLong m_hLoginHandle, int channel, int stream, Panel realPlayWindow) { | |||
| LLong m_hPlayHandle = LoginModule.netsdk.CLIENT_RealPlayEx(m_hLoginHandle, channel, Native.getComponentPointer(realPlayWindow), stream); | |||
| if(m_hPlayHandle.longValue() == 0) { | |||
| System.err.println("Failed to start realplay." + ToolKits.getErrorCodePrint()); | |||
| } else { | |||
| System.out.println("Success to start realplay"); | |||
| } | |||
| return m_hPlayHandle; | |||
| } | |||
| /** | |||
| * 停止预览 | |||
| * @param m_hPlayHandle 实时预览句柄 | |||
| * @return | |||
| */ | |||
| public static boolean stopRealPlay(LLong m_hPlayHandle) { | |||
| boolean bRet = false; | |||
| if(m_hPlayHandle.longValue() != 0) { | |||
| bRet = LoginModule.netsdk.CLIENT_StopRealPlayEx(m_hPlayHandle); | |||
| m_hPlayHandle.setValue(0); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 远程抓图 | |||
| * @param m_hLoginHandle 登陆句柄 | |||
| * @param chn 通道号 | |||
| * @return | |||
| */ | |||
| public static boolean snapPicture(LLong m_hLoginHandle, int chn) { | |||
| // 发送抓图命令给前端设备,抓图的信息 | |||
| NetSDKLib.SNAP_PARAMS msg = new NetSDKLib.SNAP_PARAMS(); | |||
| msg.Channel = chn; // 抓图通道 | |||
| msg.mode = 0; // 抓图模式 | |||
| msg.Quality = 3; // 画质 | |||
| msg.InterSnap = 0; // 定时抓图时间间隔 | |||
| msg.CmdSerial = 0; // 请求序列号,有效值范围 0~65535,超过范围会被截断为 | |||
| IntByReference reserved = new IntByReference(0); | |||
| if (!LoginModule.netsdk.CLIENT_SnapPictureEx(m_hLoginHandle, msg, reserved)) { | |||
| System.err.printf("SnapPictureEx Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } else { | |||
| System.out.println("SnapPictureEx success"); | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| *设置抓图回调函数, 图片主要在m_SnapReceiveCB中返回 | |||
| * @param m_SnapReceiveCB | |||
| */ | |||
| public static void setSnapRevCallBack(NetSDKLib.fSnapRev m_SnapReceiveCB){ | |||
| LoginModule.netsdk.CLIENT_SetSnapRevCallBack(m_SnapReceiveCB, null); | |||
| } | |||
| /** | |||
| * 获取网络协议 | |||
| * @param m_hLoginHandle 登录句柄 | |||
| * @return | |||
| */ | |||
| public static CFG_DVRIP_INFO getDVRIPConfig(LLong m_hLoginHandle) { | |||
| CFG_DVRIP_INFO msg = new CFG_DVRIP_INFO(); | |||
| if(!ToolKits.GetDevConfig(m_hLoginHandle, -1, NetSDKLib.CFG_CMD_DVRIP, msg)) { | |||
| return null; | |||
| } | |||
| return msg; | |||
| } | |||
| /** | |||
| * 网络协议配置 | |||
| * @param m_hLoginHandle 登陆句柄 | |||
| * @param enable 使能 | |||
| * @param address 服务器地址 | |||
| * @param nPort 服务器端口号 | |||
| * @param deviceId 设备ID | |||
| * @param info 获取到的网络协议配置 | |||
| * @return | |||
| */ | |||
| public static boolean setDVRIPConfig(LLong m_hLoginHandle, boolean enable, String address, int nPort, byte[] deviceId, CFG_DVRIP_INFO info) { | |||
| CFG_DVRIP_INFO msg = info; | |||
| // 主动注册配置个数 | |||
| msg.nRegistersNum = 1; | |||
| // 主动注册使能 | |||
| msg.stuRegisters[0].bEnable = enable? 1:0; | |||
| // 服务器个数 | |||
| msg.stuRegisters[0].nServersNum = 1; | |||
| // 服务器地址 | |||
| ToolKits.StringToByteArray(address, msg.stuRegisters[0].stuServers[0].szAddress); | |||
| // 服务器端口号 | |||
| msg.stuRegisters[0].stuServers[0].nPort = nPort; | |||
| // 设备ID | |||
| ToolKits.ByteArrayToByteArray(deviceId, msg.stuRegisters[0].szDeviceID); | |||
| return ToolKits.SetDevConfig(m_hLoginHandle, -1, NetSDKLib.CFG_CMD_DVRIP, msg); | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Start Talk | |||
| * \else | |||
| * 开始通话 | |||
| * \endif | |||
| */ | |||
| public static boolean startTalk(LLong m_hLoginHandle) { | |||
| // 设置语音对讲编码格式 | |||
| NetSDKLib.NETDEV_TALKDECODE_INFO talkEncode = new NetSDKLib.NETDEV_TALKDECODE_INFO(); | |||
| talkEncode.encodeType = NetSDKLib.NET_TALK_CODING_TYPE.NET_TALK_PCM; | |||
| talkEncode.dwSampleRate = 8000; | |||
| talkEncode.nAudioBit = 16; | |||
| talkEncode.nPacketPeriod = 25; | |||
| talkEncode.write(); | |||
| if(LoginModule.netsdk.CLIENT_SetDeviceMode(m_hLoginHandle, NetSDKLib.EM_USEDEV_MODE.NET_TALK_ENCODE_TYPE, talkEncode.getPointer())) { | |||
| System.out.println("Set Talk Encode Type Succeed!"); | |||
| } else { | |||
| System.err.println("Set Talk Encode Type Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| // 设置对讲模式 | |||
| NetSDKLib.NET_SPEAK_PARAM speak = new NetSDKLib.NET_SPEAK_PARAM(); | |||
| speak.nMode = 0; | |||
| speak.bEnableWait = false; | |||
| speak.nSpeakerChannel = 0; | |||
| speak.write(); | |||
| if (LoginModule.netsdk.CLIENT_SetDeviceMode(m_hLoginHandle, NetSDKLib.EM_USEDEV_MODE.NET_TALK_SPEAK_PARAM, speak.getPointer())) { | |||
| System.out.println("Set Talk Speak Mode Succeed!"); | |||
| } else { | |||
| System.err.println("Set Talk Speak Mode Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| // 设置语音对讲是否为转发模式 | |||
| NetSDKLib.NET_TALK_TRANSFER_PARAM talkTransfer = new NetSDKLib.NET_TALK_TRANSFER_PARAM(); | |||
| talkTransfer.bTransfer = 0; // 是否开启语音对讲转发模式, 1-true; 0-false | |||
| talkTransfer.write(); | |||
| if(LoginModule.netsdk.CLIENT_SetDeviceMode(m_hLoginHandle, NetSDKLib.EM_USEDEV_MODE.NET_TALK_TRANSFER_MODE, talkTransfer.getPointer())) { | |||
| System.out.println("Set Talk Transfer Mode Succeed!"); | |||
| } else { | |||
| System.err.println("Set Talk Transfer Mode Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| m_hTalkHandle = LoginModule.netsdk.CLIENT_StartTalkEx(m_hLoginHandle, AudioDataCB.getInstance(), null); | |||
| if(m_hTalkHandle.longValue() == 0) { | |||
| System.err.println("Start Talk Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } else { | |||
| System.out.println("Start Talk Success"); | |||
| if(LoginModule.netsdk.CLIENT_RecordStart()){ | |||
| System.out.println("Start Record Success"); | |||
| m_bRecordStatus = true; | |||
| } else { | |||
| System.err.println("Start Local Record Failed!" + ToolKits.getErrorCodePrint()); | |||
| stopTalk(m_hTalkHandle); | |||
| return false; | |||
| } | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Stop Talk | |||
| * \else | |||
| * 结束通话 | |||
| * \endif | |||
| */ | |||
| public static void stopTalk(LLong m_hTalkHandle) { | |||
| if(m_hTalkHandle.longValue() == 0) { | |||
| return; | |||
| } | |||
| if (m_bRecordStatus){ | |||
| LoginModule.netsdk.CLIENT_RecordStop(); | |||
| m_bRecordStatus = false; | |||
| } | |||
| if(!LoginModule.netsdk.CLIENT_StopTalkEx(m_hTalkHandle)) { | |||
| System.err.println("Stop Talk Failed!" + ToolKits.getErrorCodePrint()); | |||
| } else { | |||
| m_hTalkHandle.setValue(0); | |||
| } | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Audio Data Callback | |||
| * \else | |||
| * 语音对讲的数据回调 | |||
| * \endif | |||
| */ | |||
| private static class AudioDataCB implements NetSDKLib.pfAudioDataCallBack { | |||
| private AudioDataCB() {} | |||
| private static AudioDataCB audioCallBack = new AudioDataCB(); | |||
| public static AudioDataCB getInstance() { | |||
| return audioCallBack; | |||
| } | |||
| public void invoke(LLong lTalkHandle, Pointer pDataBuf, int dwBufSize, byte byAudioFlag, Pointer dwUser){ | |||
| if(lTalkHandle.longValue() != m_hTalkHandle.longValue()) { | |||
| return; | |||
| } | |||
| if (byAudioFlag == 0) { // 将收到的本地PC端检测到的声卡数据发送给设备端 | |||
| LLong lSendSize = LoginModule.netsdk.CLIENT_TalkSendData(m_hTalkHandle, pDataBuf, dwBufSize); | |||
| if(lSendSize.longValue() != (long)dwBufSize) { | |||
| System.err.println("send incomplete" + lSendSize.longValue() + ":" + dwBufSize); | |||
| } | |||
| }else if (byAudioFlag == 1) { // 将收到的设备端发送过来的语音数据传给SDK解码播放 | |||
| LoginModule.netsdk.CLIENT_AudioDecEx(m_hTalkHandle, pDataBuf, dwBufSize); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,107 @@ | |||
| package com.netsdk.demo.module; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Capture Picture Interface | |||
| * contains:local、remote、timer and stop capture picture | |||
| * \else | |||
| * 抓图接口实现 | |||
| * 包含: 本地、远程、定时和停止抓图 | |||
| * \endif | |||
| */ | |||
| public class CapturePictureModule { | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Local Capture Picture | |||
| * \else | |||
| * 本地抓图 | |||
| * \endif | |||
| */ | |||
| public static boolean localCapturePicture(LLong hPlayHandle, String picFileName) { | |||
| if (!LoginModule.netsdk.CLIENT_CapturePictureEx(hPlayHandle, picFileName, NetSDKLib.NET_CAPTURE_FORMATS.NET_CAPTURE_JPEG)) { | |||
| System.err.printf("CLIENT_CapturePicture Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } else { | |||
| System.out.println("CLIENT_CapturePicture success"); | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Remote Capture Picture | |||
| * \else | |||
| * 远程抓图 | |||
| * \endif | |||
| */ | |||
| public static boolean remoteCapturePicture(int chn) { | |||
| return snapPicture(chn, 0, 0); | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Timer Capture Picture | |||
| * \else | |||
| * 定时抓图 | |||
| * \endif | |||
| */ | |||
| public static boolean timerCapturePicture(int chn) { | |||
| return snapPicture(chn, 1, 2); | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Stop Timer Capture Picture | |||
| * \else | |||
| * 停止定时抓图 | |||
| * \endif | |||
| */ | |||
| public static boolean stopCapturePicture(int chn) { | |||
| return snapPicture(chn, -1, 0); | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Capture Picture (except local capture picture, others all call this interface) | |||
| * \else | |||
| * 抓图 (除本地抓图外, 其他全部调用此接口) | |||
| * \endif | |||
| */ | |||
| private static boolean snapPicture(int chn, int mode, int interval) { | |||
| // send caputre picture command to device | |||
| NetSDKLib.SNAP_PARAMS stuSnapParams = new NetSDKLib.SNAP_PARAMS(); | |||
| stuSnapParams.Channel = chn; // channel | |||
| stuSnapParams.mode = mode; // capture picture mode | |||
| stuSnapParams.Quality = 3; // picture quality | |||
| stuSnapParams.InterSnap = interval; // timer capture picture time interval | |||
| stuSnapParams.CmdSerial = 0; // request serial | |||
| IntByReference reserved = new IntByReference(0); | |||
| if (!LoginModule.netsdk.CLIENT_SnapPictureEx(LoginModule.m_hLoginHandle, stuSnapParams, reserved)) { | |||
| System.err.printf("CLIENT_SnapPictureEx Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } else { | |||
| System.out.println("CLIENT_SnapPictureEx success"); | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Set Capture Picture Callback | |||
| * \else | |||
| * 设置抓图回调函数 | |||
| * \endif | |||
| */ | |||
| public static void setSnapRevCallBack(NetSDKLib.fSnapRev cbSnapReceive){ | |||
| LoginModule.netsdk.CLIENT_SetSnapRevCallBack(cbSnapReceive, null); | |||
| } | |||
| } | |||
| @@ -0,0 +1,88 @@ | |||
| package com.netsdk.demo.module; | |||
| import java.text.SimpleDateFormat; | |||
| import com.netsdk.lib.NetSDKLib.CtrlType; | |||
| import com.netsdk.lib.NetSDKLib.NET_TIME; | |||
| import com.netsdk.lib.ToolKits; | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Device Control Interface | |||
| * contains:reboot device、setup device time and query device time | |||
| * \else | |||
| * 设备控制接口实现 | |||
| * 包含: 重启、时间同步、获取时间功能 | |||
| * \endif | |||
| */ | |||
| public class DeviceControlModule { | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Reboot Device | |||
| * \else | |||
| * 重启设备 | |||
| * \endif | |||
| */ | |||
| public static boolean reboot() { | |||
| if (!LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, CtrlType.CTRLTYPE_CTRL_REBOOT, null, 3000)) { | |||
| System.err.println("CLIENT_ControlDevice Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Setup Device Time | |||
| * \else | |||
| * 时间同步 | |||
| * \endif | |||
| */ | |||
| public static boolean setTime(String date) { | |||
| NET_TIME deviceTime = new NET_TIME(); | |||
| if (date == null) { | |||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
| date = dateFormat.format(new java.util.Date()); | |||
| } | |||
| String[] dateTime = date.split(" "); | |||
| String[] arrDate = dateTime[0].split("-"); | |||
| String[] arrTime = dateTime[1].split(":"); | |||
| deviceTime.dwYear = Integer.parseInt(arrDate[0]); | |||
| deviceTime.dwMonth = Integer.parseInt(arrDate[1]); | |||
| deviceTime.dwDay = Integer.parseInt(arrDate[2]); | |||
| deviceTime.dwHour = Integer.parseInt(arrTime[0]); | |||
| deviceTime.dwMinute = Integer.parseInt(arrTime[1]); | |||
| deviceTime.dwSecond = Integer.parseInt(arrTime[2]); | |||
| if (!LoginModule.netsdk.CLIENT_SetupDeviceTime(LoginModule.m_hLoginHandle, deviceTime)) { | |||
| System.err.println("CLIENT_SetupDeviceTime Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Get Device Current Time | |||
| * \else | |||
| * 获取设备当前时间 | |||
| * \endif | |||
| */ | |||
| public static String getTime() { | |||
| NET_TIME deviceTime = new NET_TIME(); | |||
| if (!LoginModule.netsdk.CLIENT_QueryDeviceTime(LoginModule.m_hLoginHandle, deviceTime, 3000)) { | |||
| System.err.println("CLIENT_QueryDeviceTime Failed!" + ToolKits.getErrorCodePrint()); | |||
| return null; | |||
| } | |||
| String date = deviceTime.toStringTime(); | |||
| date = date.replace("/", "-"); | |||
| return date; | |||
| } | |||
| } | |||
| @@ -0,0 +1,54 @@ | |||
| package com.netsdk.demo.module; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| /** | |||
| * 设备初始化接口实现 | |||
| */ | |||
| public class DeviceInitModule { | |||
| /* | |||
| * 设备初始化 | |||
| */ | |||
| public static boolean initDevAccount(String localIp,String szMac, String password, String cellPhone_mail, byte byPwdResetWay) { | |||
| /** | |||
| * 入参 | |||
| */ | |||
| NET_IN_INIT_DEVICE_ACCOUNT inInit = new NET_IN_INIT_DEVICE_ACCOUNT(); | |||
| // mac地址 | |||
| System.arraycopy(szMac.getBytes(), 0, inInit.szMac, 0, szMac.getBytes().length); | |||
| // 用户名 | |||
| String username = "admin"; | |||
| System.arraycopy(username.getBytes(), 0, inInit.szUserName, 0, username.getBytes().length); | |||
| // 密码,必须字母与数字结合,8位以上,否则设备不识别 | |||
| if(password.getBytes().length <= 127) { | |||
| System.arraycopy(password.getBytes(), 0, inInit.szPwd, 0, password.getBytes().length); | |||
| } else if(password.getBytes().length > 127){ | |||
| System.arraycopy(password.getBytes(), 0, inInit.szPwd, 0, 127); | |||
| } | |||
| // 设备支持的密码重置方式 | |||
| inInit.byPwdResetWay = byPwdResetWay; | |||
| // bit0-支持预置手机号 bit1-支持预置邮箱 | |||
| if((byPwdResetWay >> 1 & 0x01) == 0) { // 手机号 | |||
| System.arraycopy(cellPhone_mail.getBytes(), 0, inInit.szCellPhone, 0, cellPhone_mail.getBytes().length); | |||
| } else if((byPwdResetWay >> 1 & 0x01) == 1) { // 邮箱 | |||
| System.arraycopy(cellPhone_mail.getBytes(), 0, inInit.szMail, 0, cellPhone_mail.getBytes().length); | |||
| } | |||
| /** | |||
| * 出参 | |||
| */ | |||
| NET_OUT_INIT_DEVICE_ACCOUNT outInit = new NET_OUT_INIT_DEVICE_ACCOUNT(); | |||
| if(!LoginModule.netsdk.CLIENT_InitDevAccount(inInit, outInit, 5000, localIp)) { | |||
| System.err.println("初始化失败," + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| } | |||
| @@ -0,0 +1,72 @@ | |||
| package com.netsdk.demo.module; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.enumeration.DH_LOG_QUERY_TYPE; | |||
| import com.netsdk.lib.structure.DH_DEVICE_LOG_ITEM_EX; | |||
| import com.netsdk.lib.structure.NET_TIME; | |||
| import com.netsdk.lib.structure.QUERY_DEVICE_LOG_PARAM; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.Pointer; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| import java.nio.charset.Charset; | |||
| public class DeviceLogModule { | |||
| public static DH_DEVICE_LOG_ITEM_EX[] getSystemLog(NET_TIME startTime,NET_TIME endTime){ | |||
| //查询条件,作为入参 | |||
| QUERY_DEVICE_LOG_PARAM param=new QUERY_DEVICE_LOG_PARAM(); | |||
| //要查询的日志类型 | |||
| param.emLogType= DH_LOG_QUERY_TYPE.DHLOG_ALL.ordinal(); | |||
| //通道号 | |||
| param.nChannelID=0; | |||
| //开始查询的条数 | |||
| param.nStartNum=0; | |||
| //结束查询的条数,30-1+1=30,查询的条数是30条 | |||
| param.nEndNum=1024; | |||
| int logNum=param.nEndNum-param.nStartNum+1; | |||
| //日志数据结构体类型,写0 c层可能校验不通过,建议写1,使用DH_DEVICE_LOG_ITEM_EX作为日志数据的结构体, | |||
| // 因为c层对出参buffer长度的校验是以DH_DEVICE_LOG_ITEM_EX结构体长度来校验的 | |||
| // 而DH_DEVICE_LOG_ITEM_EX结构体的长度比DH_DEVICE_LOG_ITEM结构体要长得多 | |||
| param.nLogStuType=1; | |||
| //要查询的起始时间段 | |||
| param.stuStartTime= startTime; | |||
| //要查询的结束时间段 | |||
| param.stuEndTime= endTime; | |||
| //入参 | |||
| Pointer queryParam=new Memory(param.size()); | |||
| ToolKits.SetStructDataToPointer(param,queryParam,0); | |||
| //日志数据结构体 | |||
| DH_DEVICE_LOG_ITEM_EX logBuffer=new DH_DEVICE_LOG_ITEM_EX(); | |||
| int totalSize = logBuffer.size() * logNum; | |||
| //出参,分配内存 | |||
| Pointer pointer=new Memory(totalSize); | |||
| pointer.clear(totalSize); | |||
| //出参,查询到的日志条数 | |||
| IntByReference relogNum = new IntByReference(1); | |||
| boolean bSet=LoginModule.netsdk.CLIENT_QueryDeviceLog(LoginModule.m_hLoginHandle,queryParam,pointer,totalSize,relogNum,3000); | |||
| System.out.println("get system log is:"+bSet); | |||
| if(bSet){ | |||
| System.out.println("返回的log 条数:"+relogNum.getValue()); | |||
| if(relogNum.getValue()>0){ | |||
| DH_DEVICE_LOG_ITEM_EX[] arrays=(DH_DEVICE_LOG_ITEM_EX[])new DH_DEVICE_LOG_ITEM_EX().toArray(relogNum.getValue()); | |||
| ToolKits.GetPointerDataToStructArr(pointer,arrays); | |||
| for(DH_DEVICE_LOG_ITEM_EX item:arrays){ | |||
| String time=item.getDate(); | |||
| String operator=item.getOperator(Charset.forName("GBK")).trim(); | |||
| String operation=item.getOperation(Charset.forName("GBK")).trim(); | |||
| String log=item.getLog(Charset.forName("GBK")).trim(); | |||
| String detailLog=item.getDetailLog(Charset.forName("GBK")).trim(); | |||
| System.out.println(time+","+operator+","+operation+","+log+","+detailLog+",日志类型:"+item.nLogType); | |||
| } | |||
| return arrays; | |||
| } | |||
| }else{ | |||
| System.out.println("get log error: the error code is "+ToolKits.getErrorCodePrint()); | |||
| } | |||
| return null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,126 @@ | |||
| package com.netsdk.demo.module; | |||
| import java.net.Inet4Address; | |||
| import java.net.Inet6Address; | |||
| import java.net.InetAddress; | |||
| import java.net.NetworkInterface; | |||
| import java.net.SocketException; | |||
| import java.util.ArrayList; | |||
| import java.util.Enumeration; | |||
| import java.util.List; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.Pointer; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.enumeration.EM_SEND_SEARCH_TYPE; | |||
| import com.netsdk.lib.structure.NET_IN_STARTSERACH_DEVICE; | |||
| import com.netsdk.lib.structure.NET_OUT_STARTSERACH_DEVICE; | |||
| /** | |||
| * 设备搜索接口实现 | |||
| * 主要功能有 : 设备组播和广播搜索、设备IP单播搜索 | |||
| */ | |||
| public class DeviceSearchModule { | |||
| /** | |||
| * 设备组播和广播搜索 | |||
| * @throws SocketException | |||
| */ | |||
| public static LLong multiBroadcastDeviceSearch(fSearchDevicesCBEx cbSearchDevices,String szlocalIp) throws SocketException { | |||
| NET_IN_STARTSERACH_DEVICE pInparm = new NET_IN_STARTSERACH_DEVICE(); | |||
| pInparm.cbSearchDevices=cbSearchDevices; | |||
| System.arraycopy(szlocalIp.getBytes(), 0, pInparm.szLocalIp, 0, szlocalIp.getBytes().length); | |||
| pInparm.emSendType=EM_SEND_SEARCH_TYPE.EM_SEND_SEARCH_TYPE_MULTICAST_AND_BROADCAST.ordinal(); | |||
| Pointer pInBuf =new Memory(pInparm.size()); | |||
| ToolKits.SetStructDataToPointer(pInparm, pInBuf, 0); | |||
| NET_OUT_STARTSERACH_DEVICE pOutparm =new NET_OUT_STARTSERACH_DEVICE(); | |||
| Pointer pOutBuf =new Memory(pOutparm.size()); | |||
| ToolKits.SetStructDataToPointer(pOutparm, pOutBuf, 0); | |||
| return LoginModule.netsdk.CLIENT_StartSearchDevicesEx(pInBuf, pOutBuf); | |||
| } | |||
| /** | |||
| * 停止设备组播和广播搜索 | |||
| */ | |||
| public static void stopDeviceSearch(LLong m_DeviceSearchHandle) { | |||
| if(m_DeviceSearchHandle.longValue() == 0) { | |||
| return; | |||
| } | |||
| LoginModule.netsdk.CLIENT_StopSearchDevices(m_DeviceSearchHandle); | |||
| m_DeviceSearchHandle.setValue(0); | |||
| } | |||
| /** | |||
| * 设备IP单播搜索 | |||
| * @param startIP 起始IP | |||
| * @param nIpNum IP个数,最大 256 | |||
| * @throws SocketException | |||
| */ | |||
| public static boolean unicastDeviceSearch(String localIp,String startIP, int nIpNum, fSearchDevicesCB cbSearchDevices) throws SocketException { | |||
| String[] szIPStr = startIP.split("\\."); | |||
| DEVICE_IP_SEARCH_INFO deviceSearchInfo = new DEVICE_IP_SEARCH_INFO(); | |||
| deviceSearchInfo.nIpNum = nIpNum; | |||
| for(int i = 0; i < deviceSearchInfo.nIpNum; i++) { | |||
| System.arraycopy(getIp(szIPStr, i).getBytes(), 0, deviceSearchInfo.szIPArr[i].szIP, 0, getIp(szIPStr, i).getBytes().length); | |||
| } | |||
| if(LoginModule.netsdk.CLIENT_SearchDevicesByIPs(deviceSearchInfo, cbSearchDevices, null, localIp, 6000)) { | |||
| System.out.println("SearchDevicesByIPs Succeed!"); | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| public static String getIp(String[] ip, int num) { | |||
| String szIp = ""; | |||
| if(Integer.parseInt(ip[3]) >= 255) { | |||
| szIp = ip[0] + "." + ip[1] + "." + String.valueOf(Integer.parseInt(ip[2]) + 1) + "." + String.valueOf(Integer.parseInt(ip[3]) + num - 255); | |||
| } else { | |||
| szIp = ip[0] + "." + ip[1] + "." + ip[2] + "." + String.valueOf(Integer.parseInt(ip[3]) + num); | |||
| } | |||
| return szIp; | |||
| } | |||
| /** | |||
| * 获取多网卡IP | |||
| */ | |||
| public static List<String> getHostAddress() throws SocketException { | |||
| List<String> ipList = new ArrayList<String>(); | |||
| if(NetworkInterface.getNetworkInterfaces() == null) { | |||
| return ipList; | |||
| } | |||
| Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); | |||
| while (networkInterfaces.hasMoreElements()) { | |||
| NetworkInterface networkInterface = networkInterfaces.nextElement(); | |||
| Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); | |||
| while (inetAddresses.hasMoreElements()) { | |||
| InetAddress inetAddress = inetAddresses.nextElement(); | |||
| if (inetAddress.isLoopbackAddress()) {//回路地址,如127.0.0.1 | |||
| // System.out.println("loop addr:" + inetAddress); | |||
| } else if (inetAddress.isLinkLocalAddress()) {//169.254.x.x | |||
| // System.out.println("link addr:" + inetAddress); | |||
| } else if(inetAddress instanceof Inet4Address){ | |||
| //非链接和回路真实ip | |||
| String localname = inetAddress.getHostName(); | |||
| String localip = inetAddress.getHostAddress(); | |||
| ipList.add(localip); | |||
| } | |||
| } | |||
| } | |||
| return ipList; | |||
| } | |||
| } | |||
| @@ -0,0 +1,14 @@ | |||
| package com.netsdk.demo.module; | |||
| import com.netsdk.lib.NetSDKLib.NET_CTRL_SET_PARK_INFO; | |||
| public class DotmatrixScreenModule { | |||
| public static boolean setDotmatrixScreen(int emType, NET_CTRL_SET_PARK_INFO msg) { | |||
| boolean ret = LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, emType, msg.getPointer(), 3000); | |||
| return ret; | |||
| } | |||
| } | |||
| @@ -0,0 +1,81 @@ | |||
| package com.netsdk.demo.module; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| /** | |||
| * 下载录像接口实现 | |||
| * 主要有 : 查询录像、下载录像、设置码流类型功能 | |||
| */ | |||
| public class DownLoadRecordModule { | |||
| // 下载句柄 | |||
| public static LLong m_hDownLoadHandle = new LLong(0); | |||
| // 查找录像文件 | |||
| public static boolean queryRecordFile(int nChannelId, | |||
| NetSDKLib.NET_TIME stTimeStart, | |||
| NetSDKLib.NET_TIME stTimeEnd, | |||
| NetSDKLib.NET_RECORDFILE_INFO[] stFileInfo, | |||
| IntByReference nFindCount) { | |||
| // RecordFileType 录像类型 0:所有录像 1:外部报警 2:动态监测报警 3:所有报警 4:卡号查询 5:组合条件查询 | |||
| // 6:录像位置与偏移量长度 8:按卡号查询图片(目前仅HB-U和NVS特殊型号的设备支持) 9:查询图片(目前仅HB-U和NVS特殊型号的设备支持) | |||
| // 10:按字段查询 15:返回网络数据结构(金桥网吧) 16:查询所有透明串数据录像文件 | |||
| int nRecordFileType = 0; | |||
| boolean bRet = LoginModule.netsdk.CLIENT_QueryRecordFile(LoginModule.m_hLoginHandle, nChannelId, | |||
| nRecordFileType, stTimeStart, stTimeEnd, null, stFileInfo, | |||
| stFileInfo.length * stFileInfo[0].size(), nFindCount, 5000, false); | |||
| if(bRet) { | |||
| System.out.println("QueryRecordFile Succeed! \n" + "查询到的视频个数:" + nFindCount.getValue()); | |||
| } else { | |||
| System.err.println("QueryRecordFile Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 设置回放时的码流类型 | |||
| * @param m_streamType 码流类型 | |||
| */ | |||
| public static void setStreamType(int m_streamType) { | |||
| IntByReference steamType = new IntByReference(m_streamType);// 0-主辅码流,1-主码流,2-辅码流 | |||
| int emType = NetSDKLib.EM_USEDEV_MODE.NET_RECORD_STREAM_TYPE; | |||
| boolean bret = LoginModule.netsdk.CLIENT_SetDeviceMode(LoginModule.m_hLoginHandle, emType, steamType.getPointer()); | |||
| if (!bret) { | |||
| System.err.println("Set Stream Type Failed, Get last error." + ToolKits.getErrorCodePrint()); | |||
| } else { | |||
| System.out.println("Set Stream Type Succeed!"); | |||
| } | |||
| } | |||
| public static LLong downloadRecordFile(int nChannelId, | |||
| int nRecordFileType, | |||
| NetSDKLib.NET_TIME stTimeStart, | |||
| NetSDKLib.NET_TIME stTimeEnd, | |||
| String SavedFileName, | |||
| NetSDKLib.fTimeDownLoadPosCallBack cbTimeDownLoadPos) { | |||
| m_hDownLoadHandle = LoginModule.netsdk.CLIENT_DownloadByTimeEx(LoginModule.m_hLoginHandle, nChannelId, nRecordFileType, | |||
| stTimeStart, stTimeEnd, SavedFileName, | |||
| cbTimeDownLoadPos, null, null, null, null); | |||
| if(m_hDownLoadHandle.longValue() != 0) { | |||
| System.out.println("Downloading RecordFile!"); | |||
| } else { | |||
| System.err.println("Download RecordFile Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return m_hDownLoadHandle; | |||
| } | |||
| public static void stopDownLoadRecordFile(LLong m_hDownLoadHandle) { | |||
| if (m_hDownLoadHandle.longValue() == 0) { | |||
| return; | |||
| } | |||
| LoginModule.netsdk.CLIENT_StopDownload(m_hDownLoadHandle); | |||
| } | |||
| } | |||
| @@ -0,0 +1,880 @@ | |||
| package com.netsdk.demo.module; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.ArrayList; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import com.netsdk.lib.NativeString; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.Pointer; | |||
| /** | |||
| * IVSS 和 IPC-FR 人脸功能接口实现, IPC-FD只支持人脸检测事件 | |||
| */ | |||
| public class FaceRecognitionModule { | |||
| // 查找句柄 | |||
| private static LLong m_FindHandle = null; | |||
| // 查询密令 | |||
| public static int nToken = 0; | |||
| //////////////////////////////// 目标识别 和 人脸检测 事件 ///////////////////////////////////////////// | |||
| /** | |||
| * 目标识别事件和人脸检测事件订阅 | |||
| * @param channel 通道号 | |||
| * @param callback 回调函数 | |||
| * @return true:成功 false:失败 | |||
| */ | |||
| public static LLong realLoadPicture(int channel, fAnalyzerDataCallBack callback) { | |||
| int bNeedPicture = 1; // 是否需要图片 | |||
| LLong m_hAttachHandle = LoginModule.netsdk.CLIENT_RealLoadPictureEx(LoginModule.m_hLoginHandle, channel, | |||
| NetSDKLib.EVENT_IVS_ALL, bNeedPicture, callback, null, null); | |||
| if(m_hAttachHandle.longValue() == 0) { | |||
| System.err.println("CLIENT_RealLoadPictureEx Failed, Error:" + ToolKits.getErrorCodePrint()); | |||
| } else { | |||
| System.out.println("通道[" + channel + "]订阅成功!"); | |||
| } | |||
| return m_hAttachHandle; | |||
| } | |||
| /** | |||
| * 停止订阅 | |||
| * @param m_hAttachHandle 智能订阅句柄 | |||
| */ | |||
| public static void stopRealLoadPicture(LLong m_hAttachHandle) { | |||
| if(m_hAttachHandle.longValue() != 0) { | |||
| LoginModule.netsdk.CLIENT_StopLoadPic(m_hAttachHandle); | |||
| m_hAttachHandle.setValue(0); | |||
| } | |||
| } | |||
| /////////////////////////////////////// 人脸库的增、删、改、查 //////////////////////////////// | |||
| /** | |||
| * 查询人脸库 | |||
| * @param groupId 需要查找的人脸库ID; 为空表示查找所有的人脸库 | |||
| */ | |||
| public static NET_FACERECONGNITION_GROUP_INFO[] findGroupInfo(String groupId) { | |||
| NET_FACERECONGNITION_GROUP_INFO[] groupInfoRet = null; | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_FIND_GROUP_INFO stuIn = new NET_IN_FIND_GROUP_INFO(); | |||
| System.arraycopy(groupId.getBytes(), 0, stuIn.szGroupId, 0, groupId.getBytes().length); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| int max = 20; | |||
| NET_FACERECONGNITION_GROUP_INFO[] groupInfo = new NET_FACERECONGNITION_GROUP_INFO[max]; | |||
| for(int i = 0; i < max; i++) { | |||
| groupInfo[i] = new NET_FACERECONGNITION_GROUP_INFO(); | |||
| } | |||
| NET_OUT_FIND_GROUP_INFO stuOut = new NET_OUT_FIND_GROUP_INFO(); | |||
| stuOut.pGroupInfos = new Memory(groupInfo[0].size() * groupInfo.length); // Pointer初始化 | |||
| stuOut.pGroupInfos.clear(groupInfo[0].size() * groupInfo.length); | |||
| stuOut.nMaxGroupNum = groupInfo.length; | |||
| ToolKits.SetStructArrToPointerData(groupInfo, stuOut.pGroupInfos); // 将数组内存拷贝给Pointer | |||
| if(LoginModule.netsdk.CLIENT_FindGroupInfo(LoginModule.m_hLoginHandle, stuIn, stuOut, 4000)) { | |||
| // 将Pointer的值输出到 数组 NET_FACERECONGNITION_GROUP_INFO | |||
| ToolKits.GetPointerDataToStructArr(stuOut.pGroupInfos, groupInfo); | |||
| if(stuOut.nRetGroupNum > 0) { | |||
| // 根据设备返回的,将有效的人脸库信息返回 | |||
| groupInfoRet = new NET_FACERECONGNITION_GROUP_INFO[stuOut.nRetGroupNum]; | |||
| for(int i = 0; i < stuOut.nRetGroupNum; i++) { | |||
| groupInfoRet[i] = groupInfo[i]; | |||
| } | |||
| } | |||
| } else { | |||
| System.err.println("查询人员信息失败" + ToolKits.getErrorCodePrint()); | |||
| return null; | |||
| } | |||
| return groupInfoRet; | |||
| } | |||
| /** | |||
| * 添加人脸库 | |||
| * @param groupName 需要添加的人脸库名称 | |||
| */ | |||
| public static boolean addGroup(String groupName) { | |||
| NET_ADD_FACERECONGNITION_GROUP_INFO addGroupInfo = new NET_ADD_FACERECONGNITION_GROUP_INFO(); | |||
| // 人脸库名称 | |||
| try { | |||
| System.arraycopy(groupName.getBytes("GBK"), 0, addGroupInfo.stuGroupInfo.szGroupName, 0, groupName.getBytes("GBK").length); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_OPERATE_FACERECONGNITION_GROUP stuIn = new NET_IN_OPERATE_FACERECONGNITION_GROUP(); | |||
| stuIn.emOperateType = EM_OPERATE_FACERECONGNITION_GROUP_TYPE.NET_FACERECONGNITION_GROUP_ADD; // 添加人员组信息 | |||
| stuIn.pOPerateInfo = addGroupInfo.getPointer(); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_OPERATE_FACERECONGNITION_GROUP stuOut = new NET_OUT_OPERATE_FACERECONGNITION_GROUP(); | |||
| addGroupInfo.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_OperateFaceRecognitionGroup(LoginModule.m_hLoginHandle, stuIn, stuOut, 4000); | |||
| addGroupInfo.read(); | |||
| if(bRet) { | |||
| System.out.println("人员组ID : " + new String(stuOut.szGroupId).trim()); // 新增记录的人员组ID,唯一标识一组人员 | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 修改人脸库 | |||
| * @param groupName 修改后的人脸库名称 | |||
| * @param groupId 需要修改的人脸库ID | |||
| */ | |||
| public static boolean modifyGroup(String groupName, String groupId) { | |||
| NET_MODIFY_FACERECONGNITION_GROUP_INFO modifyGroupInfo = new NET_MODIFY_FACERECONGNITION_GROUP_INFO(); | |||
| // 人脸库名称 | |||
| try { | |||
| System.arraycopy(groupName.getBytes("GBK"), 0, modifyGroupInfo.stuGroupInfo.szGroupName, 0, groupName.getBytes("GBK").length); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 人脸库ID | |||
| System.arraycopy(groupId.getBytes(), 0, modifyGroupInfo.stuGroupInfo.szGroupId, 0, groupId.getBytes().length); | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_OPERATE_FACERECONGNITION_GROUP stuIn = new NET_IN_OPERATE_FACERECONGNITION_GROUP(); | |||
| stuIn.emOperateType = EM_OPERATE_FACERECONGNITION_GROUP_TYPE.NET_FACERECONGNITION_GROUP_MODIFY; // 修改人员组信息 | |||
| stuIn.pOPerateInfo = modifyGroupInfo.getPointer(); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_OPERATE_FACERECONGNITION_GROUP stuOut = new NET_OUT_OPERATE_FACERECONGNITION_GROUP(); | |||
| modifyGroupInfo.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_OperateFaceRecognitionGroup(LoginModule.m_hLoginHandle, stuIn, stuOut, 4000); | |||
| modifyGroupInfo.read(); | |||
| if(bRet) { | |||
| System.out.println("修改人脸库成功."); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 删除人脸库 | |||
| * @param groupId 需要删除的人脸库ID; 为空表示删除所有的人脸库 | |||
| */ | |||
| public static boolean deleteGroup(String groupId) { | |||
| NET_DELETE_FACERECONGNITION_GROUP_INFO deleteGroupInfo = new NET_DELETE_FACERECONGNITION_GROUP_INFO(); | |||
| // 人脸库ID | |||
| System.arraycopy(groupId.getBytes(), 0, deleteGroupInfo.szGroupId, 0, groupId.getBytes().length); | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_OPERATE_FACERECONGNITION_GROUP stuIn = new NET_IN_OPERATE_FACERECONGNITION_GROUP(); | |||
| stuIn.emOperateType = EM_OPERATE_FACERECONGNITION_GROUP_TYPE.NET_FACERECONGNITION_GROUP_DELETE; // 删除人员组信息 | |||
| stuIn.pOPerateInfo = deleteGroupInfo.getPointer(); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_OPERATE_FACERECONGNITION_GROUP stuOut = new NET_OUT_OPERATE_FACERECONGNITION_GROUP(); | |||
| deleteGroupInfo.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_OperateFaceRecognitionGroup(LoginModule.m_hLoginHandle, stuIn, stuOut, 4000); | |||
| deleteGroupInfo.read(); | |||
| if(bRet) { | |||
| System.out.println("删除人脸库成功."); | |||
| } | |||
| return bRet; | |||
| } | |||
| ///////////////////////////// 按人脸库布控、撤控 /////////////////////////////////////// | |||
| /** | |||
| * 以人脸库的角度进行布控 | |||
| * @param groupId 人脸库ID | |||
| * @param hashMap key:撤控通道 value:相似度 | |||
| */ | |||
| public static boolean putDisposition(String groupId, HashMap<Integer, Integer> hashMap) { | |||
| int i = 0; | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_FACE_RECOGNITION_PUT_DISPOSITION_INFO stuIn = new NET_IN_FACE_RECOGNITION_PUT_DISPOSITION_INFO(); | |||
| // 人脸库ID | |||
| System.arraycopy(groupId.getBytes(), 0, stuIn.szGroupId, 0, groupId.getBytes().length); | |||
| for(Map.Entry<Integer, Integer> entry : hashMap.entrySet()) { | |||
| stuIn.stuDispositionChnInfo[i].nChannelID = entry.getKey() - 1; | |||
| stuIn.stuDispositionChnInfo[i].nSimilary = entry.getValue(); | |||
| i++; | |||
| } | |||
| stuIn.nDispositionChnNum = hashMap.size(); // 布控视频通道个数 | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_FACE_RECOGNITION_PUT_DISPOSITION_INFO stuOut = new NET_OUT_FACE_RECOGNITION_PUT_DISPOSITION_INFO(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_FaceRecognitionPutDisposition(LoginModule.m_hLoginHandle, stuIn, stuOut, 4000); | |||
| if(bRet) { | |||
| System.out.println("通道布控结果个数:" + stuOut.nReportCnt); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 以人脸库的角度进行撤控 | |||
| * @param groupId 人脸库ID | |||
| * @param arrayList 撤控通道列表 | |||
| */ | |||
| public static boolean delDisposition(String groupId, ArrayList<Integer> arrayList) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_FACE_RECOGNITION_DEL_DISPOSITION_INFO stuIn = new NET_IN_FACE_RECOGNITION_DEL_DISPOSITION_INFO(); | |||
| // 人脸库ID | |||
| System.arraycopy(groupId.getBytes(), 0, stuIn.szGroupId, 0, groupId.getBytes().length); | |||
| // 撤控视频通道列表 | |||
| for(int i = 0; i < arrayList.size(); i++) { | |||
| stuIn.nDispositionChn[i] = arrayList.get(i) - 1; | |||
| } | |||
| // 撤控视频通道个数 | |||
| stuIn.nDispositionChnNum = arrayList.size(); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_FACE_RECOGNITION_DEL_DISPOSITION_INFO stuOut = new NET_OUT_FACE_RECOGNITION_DEL_DISPOSITION_INFO(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_FaceRecognitionDelDisposition(LoginModule.m_hLoginHandle, stuIn, stuOut, 4000); | |||
| if(bRet) { | |||
| System.out.println("通道撤控结果个数:" + stuOut.nReportCnt); | |||
| } | |||
| return bRet; | |||
| } | |||
| ///////////////////////////// 按通道布控、撤控 /////////////////////////////////////// | |||
| /** | |||
| * 获取布控在视频通道的组信息 | |||
| * @param channel 通道号 | |||
| */ | |||
| public static void GetGroupInfoForChannel(int channel) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_GET_GROUPINFO_FOR_CHANNEL stIn = new NET_IN_GET_GROUPINFO_FOR_CHANNEL(); | |||
| // 通道号 | |||
| stIn.nChannelID = channel; | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_GET_GROUPINFO_FOR_CHANNEL stOut = new NET_OUT_GET_GROUPINFO_FOR_CHANNEL(); | |||
| if(LoginModule.netsdk.CLIENT_GetGroupInfoForChannel(LoginModule.m_hLoginHandle, stIn, stOut, 4000)) { | |||
| for(int i = 0; i < stOut.nGroupIdNum; i++) { | |||
| System.out.println("人脸库ID:" + new String(stOut.szGroupIdArr[i].szGroupId).trim()); | |||
| System.out.println("相似度:" + stOut.nSimilary[i] + "\n"); | |||
| } | |||
| } else { | |||
| System.err.println("获取布控在视频通道的组信息失败, " + ToolKits.getErrorCodePrint()); | |||
| } | |||
| } | |||
| /** | |||
| * 布控通道人员组信息 | |||
| * @param channel | |||
| * @param groupIds 人脸库ID,长度等于相似度 | |||
| * @param similarys 相似度, 长度等于人脸库ID | |||
| */ | |||
| public static void SetGroupInfoForChannel(int channel, String[] groupIds, int[] similarys) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_SET_GROUPINFO_FOR_CHANNEL stIn = new NET_IN_SET_GROUPINFO_FOR_CHANNEL(); | |||
| // 通道号 | |||
| stIn.nChannelID = channel; | |||
| // 人脸库ID个数 | |||
| stIn.nGroupIdNum = groupIds.length; | |||
| // 相似度个数 | |||
| stIn.nSimilaryNum = similarys.length; | |||
| for(int i = 0; i < groupIds.length; i++) { | |||
| // 人脸库ID赋值,用数组拷贝 | |||
| System.arraycopy(groupIds[i].getBytes(), 0, stIn.szGroupIdArr[i].szGroupId, 0, groupIds[i].getBytes().length); | |||
| // 对应的人脸库的相似度 | |||
| stIn.nSimilary[i] = similarys[i]; | |||
| } | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_SET_GROUPINFO_FOR_CHANNEL stOut = new NET_OUT_SET_GROUPINFO_FOR_CHANNEL(); | |||
| if(LoginModule.netsdk.CLIENT_SetGroupInfoForChannel(LoginModule.m_hLoginHandle, stIn, stOut, 4000)) { | |||
| } | |||
| } | |||
| ///////////////////////////// 人员操作 //////////////////////////////////////////// | |||
| /** | |||
| * 按条件查询目标识别结果 | |||
| * @param groupId 人脸库ID | |||
| * @param isStartBirthday 查询条件是否下发开始生日 | |||
| * @param startTime 生日起始时间 | |||
| * @param isEndBirthday 查询条件是否下发结束生日 | |||
| * @param endTime 生日结束时间 | |||
| * @param personName 姓名 | |||
| * @param sex 性别 | |||
| * @param idType 证件类型 | |||
| * @param idNo 证件号 | |||
| * @return 查询到的所有人员个数 | |||
| */ | |||
| public static int startFindPerson(String groupId, | |||
| boolean isStartBirthday, | |||
| String startTime, | |||
| boolean isEndBirthday, | |||
| String endTime, | |||
| String personName, | |||
| int sex, | |||
| int idType, | |||
| String idNo) { | |||
| m_FindHandle = null; | |||
| nToken = 0; | |||
| int nTotalCount = 0; | |||
| /* | |||
| * 入参, IVVS设备,查询条件只有 stuInStartFind.stPerson 里的参数有效 | |||
| */ | |||
| NET_IN_STARTFIND_FACERECONGNITION stuIn = new NET_IN_STARTFIND_FACERECONGNITION(); | |||
| stuIn.bPersonExEnable = 1; // 人员信息查询条件是否有效, 并使用扩展结构体 | |||
| // 人脸库ID | |||
| System.arraycopy(groupId.getBytes(), 0, stuIn.stPersonInfoEx.szGroupID, 0, groupId.getBytes().length); | |||
| // 姓名 | |||
| try { | |||
| System.arraycopy(personName.getBytes("GBK"), 0, stuIn.stPersonInfoEx.szPersonName, 0, personName.getBytes("GBK").length); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 性别 | |||
| stuIn.stPersonInfoEx.bySex = (byte)sex; | |||
| // 证件类型 | |||
| stuIn.stPersonInfoEx.byIDType = (byte)idType; | |||
| // 证件号 | |||
| System.arraycopy(idNo.getBytes(), 0, stuIn.stPersonInfoEx.szID, 0, idNo.getBytes().length); | |||
| stuIn.stFilterInfo.nGroupIdNum = 1; | |||
| // 人脸库ID | |||
| System.arraycopy(groupId.getBytes(), 0, stuIn.stFilterInfo.szGroupIdArr[0].szGroupId, 0, groupId.getBytes().length); | |||
| // 待查询人脸类型 | |||
| stuIn.stFilterInfo.emFaceType = EM_FACERECOGNITION_FACE_TYPE.EM_FACERECOGNITION_FACE_TYPE_ALL; | |||
| // 开始生日 | |||
| if(isStartBirthday) { | |||
| String[] startTimeStr = startTime.split("-"); | |||
| stuIn.stFilterInfo.stBirthdayRangeStart.dwYear = Integer.parseInt(startTimeStr[0]); | |||
| stuIn.stFilterInfo.stBirthdayRangeStart.dwMonth = Integer.parseInt(startTimeStr[1]); | |||
| stuIn.stFilterInfo.stBirthdayRangeStart.dwDay = Integer.parseInt(startTimeStr[2]); | |||
| } | |||
| // 结束生日 | |||
| if(isEndBirthday) { | |||
| String[] endTimeStr = endTime.split("-"); | |||
| stuIn.stFilterInfo.stBirthdayRangeEnd.dwYear = Integer.parseInt(endTimeStr[0]); | |||
| stuIn.stFilterInfo.stBirthdayRangeEnd.dwMonth = Integer.parseInt(endTimeStr[1]); | |||
| stuIn.stFilterInfo.stBirthdayRangeEnd.dwDay = Integer.parseInt(endTimeStr[2]); | |||
| } | |||
| stuIn.stFilterInfo.nRangeNum = 1; | |||
| stuIn.stFilterInfo.szRange[0] = EM_FACE_DB_TYPE.NET_FACE_DB_TYPE_BLACKLIST; | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_STARTFIND_FACERECONGNITION stuOut = new NET_OUT_STARTFIND_FACERECONGNITION(); | |||
| stuIn.write(); | |||
| stuOut.write(); | |||
| if(LoginModule.netsdk.CLIENT_StartFindFaceRecognition(LoginModule.m_hLoginHandle, stuIn, stuOut, 4000)) { | |||
| m_FindHandle = stuOut.lFindHandle; | |||
| nTotalCount = stuOut.nTotalCount; | |||
| nToken = stuOut.nToken; | |||
| } else { | |||
| System.out.println("CLIENT_StartFindFaceRecognition Failed, Error:" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return nTotalCount; | |||
| } | |||
| /** | |||
| * 查找目标识别结果 | |||
| * @param beginNum 查询起始序号 | |||
| * @param nCount 当前想查询的记录条数 | |||
| * @return 返回的人员信息数组 | |||
| */ | |||
| public static CANDIDATE_INFOEX[] doFindPerson(int beginNum, int nCount) { | |||
| /* | |||
| *入参 | |||
| */ | |||
| NetSDKLib.NET_IN_DOFIND_FACERECONGNITION stuIn = new NetSDKLib.NET_IN_DOFIND_FACERECONGNITION(); | |||
| stuIn.lFindHandle = m_FindHandle; | |||
| stuIn.nCount = nCount; // 当前想查询的记录条数 | |||
| stuIn.nBeginNum = beginNum; // 查询起始序号 | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NetSDKLib.NET_OUT_DOFIND_FACERECONGNITION stuOut = new NetSDKLib.NET_OUT_DOFIND_FACERECONGNITION(); | |||
| stuOut.bUseCandidatesEx = 1; // 是否使用候选对象扩展结构体 | |||
| // 必须申请内存,每次查询几个,必须至少申请几个,最大申请20个 | |||
| for(int i = 0; i < nCount; i++) { | |||
| stuOut.stuCandidatesEx[i].stPersonInfo.szFacePicInfo[0].nFilePathLen = 256; | |||
| stuOut.stuCandidatesEx[i].stPersonInfo.szFacePicInfo[0].pszFilePath = new Memory(256); | |||
| } | |||
| stuIn.write(); | |||
| stuOut.write(); | |||
| if(LoginModule.netsdk.CLIENT_DoFindFaceRecognition(stuIn, stuOut, 4000)) { | |||
| stuIn.read(); | |||
| stuOut.read(); | |||
| if(stuOut.nCadidateExNum == 0) { | |||
| return null; | |||
| } | |||
| // 查询到的数据 | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = new CANDIDATE_INFOEX[stuOut.nCadidateExNum]; | |||
| for(int i = 0; i < stuOut.nCadidateExNum; i++) { | |||
| stuCandidatesEx[i] = new CANDIDATE_INFOEX(); | |||
| stuCandidatesEx[i] = stuOut.stuCandidatesEx[i]; | |||
| } | |||
| return stuCandidatesEx; | |||
| } else { | |||
| System.out.println("CLIENT_DoFindFaceRecognition Failed, Error:" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * 结束查询 | |||
| */ | |||
| public static boolean doFindPerson() { | |||
| boolean bRet = false; | |||
| if(m_FindHandle.longValue() != 0) { | |||
| bRet = LoginModule.netsdk.CLIENT_StopFindFaceRecognition(m_FindHandle); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 添加人员 | |||
| * @param groupId 人脸库ID | |||
| * @param memory 图片数据 | |||
| * @param personName 姓名 | |||
| * @param sex 性别 | |||
| * @param isBirthday 是否下发生日 | |||
| * @param birthday 生日 | |||
| * @param byIdType 证件类型 | |||
| * @param idNo 证件号 | |||
| * @return | |||
| */ | |||
| public static boolean addPerson(String groupId, | |||
| Memory memory, | |||
| String personName, | |||
| int sex, | |||
| boolean isBirthday, | |||
| String birthday, | |||
| int byIdType, | |||
| String idNo) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_OPERATE_FACERECONGNITIONDB stuIn = new NET_IN_OPERATE_FACERECONGNITIONDB(); | |||
| stuIn.emOperateType = NetSDKLib.EM_OPERATE_FACERECONGNITIONDB_TYPE.NET_FACERECONGNITIONDB_ADD; | |||
| ///////// 使用人员扩展信息 ////////// | |||
| stuIn.bUsePersonInfoEx = 1; | |||
| // 人脸库ID | |||
| System.arraycopy(groupId.getBytes(), 0, stuIn.stPersonInfoEx.szGroupID, 0, groupId.getBytes().length); | |||
| // 生日设置 | |||
| if(isBirthday) { | |||
| String[] birthdays = birthday.split("-"); | |||
| stuIn.stPersonInfoEx.wYear = (short)Integer.parseInt(birthdays[0]); | |||
| stuIn.stPersonInfoEx.byMonth = (byte)Integer.parseInt(birthdays[1]); | |||
| stuIn.stPersonInfoEx.byDay = (byte)Integer.parseInt(birthdays[2]); | |||
| } | |||
| // 性别,1-男,2-女,作为查询条件时,此参数填0,则表示此参数无效 | |||
| stuIn.stPersonInfoEx.bySex = (byte)sex; | |||
| // 人员名字 | |||
| try { | |||
| System.arraycopy(personName.getBytes("GBK"), 0, stuIn.stPersonInfoEx.szPersonName, 0, personName.getBytes("GBK").length); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 证件类型 | |||
| stuIn.stPersonInfoEx.byIDType = (byte)byIdType; | |||
| // 证件号 | |||
| System.arraycopy(idNo.getBytes(), 0, stuIn.stPersonInfoEx.szID, 0, idNo.getBytes().length); | |||
| // 图片张数、大小、缓存设置 | |||
| if(memory != null) { | |||
| stuIn.stPersonInfoEx.wFacePicNum = 1; // 图片张数 | |||
| stuIn.stPersonInfoEx.szFacePicInfo[0].dwFileLenth = (int)memory.size(); // 图片大小 | |||
| stuIn.stPersonInfoEx.szFacePicInfo[0].dwOffSet = 0; | |||
| stuIn.nBufferLen = (int)memory.size(); | |||
| stuIn.pBuffer = memory; | |||
| } | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_OPERATE_FACERECONGNITIONDB stuOut = new NET_OUT_OPERATE_FACERECONGNITIONDB() ; | |||
| stuIn.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_OperateFaceRecognitionDB(LoginModule.m_hLoginHandle, stuIn, stuOut, 3000); | |||
| stuIn.read(); | |||
| if(bRet) { | |||
| System.out.println("szUID : " + new String(stuOut.szUID).trim()); | |||
| } else { | |||
| System.err.println(ToolKits.getErrorCodePrint()); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 修改人员信息 | |||
| * @param groupId 人脸库ID | |||
| * @param uid 人员唯一标识符 | |||
| * @param memory 图片数据 | |||
| * @param personName 姓名 | |||
| * @param sex 性别 | |||
| * @param isBirthday 是否下发生日 | |||
| * @param birthday 生日 | |||
| * @param byIdType 证件类型 | |||
| * @param idNo 证件号 | |||
| * @return true:成功 , false:失败 | |||
| */ | |||
| public static boolean modifyPerson(String groupId, | |||
| String uid, | |||
| Memory memory, | |||
| String personName, | |||
| int sex, | |||
| boolean isBirthday, | |||
| String birthday, | |||
| int byIdType, | |||
| String idNo) { | |||
| // 入参 | |||
| NET_IN_OPERATE_FACERECONGNITIONDB stuIn = new NET_IN_OPERATE_FACERECONGNITIONDB(); | |||
| stuIn.emOperateType = NetSDKLib.EM_OPERATE_FACERECONGNITIONDB_TYPE.NET_FACERECONGNITIONDB_MODIFY; | |||
| ///////// 使用人员扩展信息 //////// | |||
| stuIn.bUsePersonInfoEx = 1; | |||
| // 人脸库ID | |||
| System.arraycopy(groupId.getBytes(), 0, stuIn.stPersonInfoEx.szGroupID, 0, groupId.getBytes().length); | |||
| // 人员唯一标识符 | |||
| System.arraycopy(uid.getBytes(), 0, stuIn.stPersonInfoEx.szUID, 0, uid.getBytes().length); | |||
| // 生日设置 | |||
| if(isBirthday) { | |||
| String[] birthdays = birthday.split("-"); | |||
| stuIn.stPersonInfoEx.wYear = (short)Integer.parseInt(birthdays[0]); | |||
| stuIn.stPersonInfoEx.byMonth = (byte)Integer.parseInt(birthdays[1]); | |||
| stuIn.stPersonInfoEx.byDay = (byte)Integer.parseInt(birthdays[2]); | |||
| } | |||
| // 性别,1-男,2-女,作为查询条件时,此参数填0,则表示此参数无效 | |||
| stuIn.stPersonInfoEx.bySex = (byte)sex; | |||
| // 人员名字 | |||
| try { | |||
| System.arraycopy(personName.getBytes("GBK"), 0, stuIn.stPersonInfoEx.szPersonName, 0, personName.getBytes("GBK").length); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 证件类型 | |||
| stuIn.stPersonInfoEx.byIDType = (byte)byIdType; | |||
| // 证件号 | |||
| System.arraycopy(idNo.getBytes(), 0, stuIn.stPersonInfoEx.szID, 0, idNo.getBytes().length); | |||
| // 图片张数、大小、缓存设置 | |||
| if(memory != null) { | |||
| stuIn.stPersonInfoEx.wFacePicNum = 1; // 图片张数 | |||
| stuIn.stPersonInfoEx.szFacePicInfo[0].dwFileLenth = (int)memory.size(); // 图片大小 | |||
| stuIn.stPersonInfoEx.szFacePicInfo[0].dwOffSet = 0; | |||
| stuIn.nBufferLen = (int)memory.size(); | |||
| stuIn.pBuffer = memory; | |||
| } | |||
| // 出参 | |||
| NET_OUT_OPERATE_FACERECONGNITIONDB stuOut = new NET_OUT_OPERATE_FACERECONGNITIONDB() ; | |||
| stuIn.write(); | |||
| if(!LoginModule.netsdk.CLIENT_OperateFaceRecognitionDB(LoginModule.m_hLoginHandle, stuIn, stuOut, 3000)) { | |||
| System.err.println("修改人员失败" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| stuIn.read(); | |||
| return true; | |||
| } | |||
| /** | |||
| * 删除人员信息 | |||
| * @param groupId 人脸库ID | |||
| * @param sUID 人员唯一标识符 | |||
| */ | |||
| public static boolean delPerson(String groupId, String sUID) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_OPERATE_FACERECONGNITIONDB stuIn = new NET_IN_OPERATE_FACERECONGNITIONDB(); | |||
| stuIn.emOperateType = NetSDKLib.EM_OPERATE_FACERECONGNITIONDB_TYPE.NET_FACERECONGNITIONDB_DELETE; | |||
| //////// 使用人员扩展信息 ////////// | |||
| stuIn.bUsePersonInfoEx = 1; | |||
| // GroupID 赋值 | |||
| System.arraycopy(groupId.getBytes(), 0, stuIn.stPersonInfoEx.szGroupID, 0, groupId.getBytes().length); | |||
| // UID赋值 | |||
| System.arraycopy(sUID.getBytes(), 0, stuIn.stPersonInfoEx.szUID, 0, sUID.getBytes().length); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_OPERATE_FACERECONGNITIONDB stuOut = new NET_OUT_OPERATE_FACERECONGNITIONDB() ; | |||
| boolean bRet = LoginModule.netsdk.CLIENT_OperateFaceRecognitionDB(LoginModule.m_hLoginHandle, stuIn, stuOut, 3000); | |||
| if(!bRet) { | |||
| System.err.println(LoginModule.netsdk.CLIENT_GetLastError()); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 下载图片, 用于修改人员信息 | |||
| * @param szFileName 需要下载的文件名 | |||
| * @param pszFileDst 存放文件路径 | |||
| */ | |||
| public static boolean downloadPersonPic(String szFileName, String pszFileDst) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_DOWNLOAD_REMOTE_FILE stuIn = new NET_IN_DOWNLOAD_REMOTE_FILE(); | |||
| // 需要下载的文件名 | |||
| stuIn.pszFileName = new NativeString(szFileName).getPointer(); | |||
| // 存放文件路径 | |||
| stuIn.pszFileDst = new NativeString(pszFileDst).getPointer(); | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_DOWNLOAD_REMOTE_FILE stuOut = new NET_OUT_DOWNLOAD_REMOTE_FILE(); | |||
| if(!LoginModule.netsdk.CLIENT_DownloadRemoteFile(LoginModule.m_hLoginHandle, stuIn, stuOut, 5000)) { | |||
| System.err.println("下载图片失败!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 显示/关闭规则库 | |||
| * @param RealPlayHandle 实时预览 | |||
| * @param bTrue 1-打开, 0-关闭 | |||
| * @return | |||
| */ | |||
| public static void renderPrivateData(LLong m_hRealPlayHandle, int bTrue) { | |||
| if(m_hRealPlayHandle.longValue() != 0) { | |||
| LoginModule.netsdk.CLIENT_RenderPrivateData(m_hRealPlayHandle, bTrue); | |||
| } | |||
| } | |||
| ////////////////////////// 查询事件对比记录 ///////////////////////// | |||
| private static LLong lFindHandle = new LLong(0); // 查找句柄 | |||
| /** | |||
| * 获取查找句柄 | |||
| * @param nChn 通道号 | |||
| * @param startTime 开始时间 | |||
| * @param endTime 结束时间 | |||
| */ | |||
| public static boolean findFile(int nChn, String startTime, String endTime) { | |||
| int type = NetSDKLib.EM_FILE_QUERY_TYPE.NET_FILE_QUERY_FACE; | |||
| /** | |||
| * 查询条件 | |||
| */ | |||
| MEDIAFILE_FACERECOGNITION_PARAM findContion = new MEDIAFILE_FACERECOGNITION_PARAM(); | |||
| // 开始时间 | |||
| String[] starts = startTime.split(" "); | |||
| findContion.stStartTime.dwYear = Integer.parseInt(starts[0].split("-")[0]); | |||
| findContion.stStartTime.dwMonth = Integer.parseInt(starts[0].split("-")[1]); | |||
| findContion.stStartTime.dwDay = Integer.parseInt(starts[0].split("-")[2]); | |||
| findContion.stStartTime.dwHour = Integer.parseInt(starts[1].split(":")[0]); | |||
| findContion.stStartTime.dwMinute = Integer.parseInt(starts[1].split(":")[1]); | |||
| findContion.stStartTime.dwSecond = Integer.parseInt(starts[1].split(":")[2]); | |||
| // 结束时间 | |||
| String[] ends = endTime.split(" "); | |||
| findContion.stEndTime.dwYear = Integer.parseInt(ends[0].split("-")[0]); | |||
| findContion.stEndTime.dwMonth = Integer.parseInt(ends[0].split("-")[1]); | |||
| findContion.stEndTime.dwDay = Integer.parseInt(ends[0].split("-")[2]); | |||
| findContion.stEndTime.dwHour = Integer.parseInt(ends[1].split(":")[0]); | |||
| findContion.stEndTime.dwMinute = Integer.parseInt(ends[1].split(":")[1]); | |||
| findContion.stEndTime.dwSecond = Integer.parseInt(ends[1].split(":")[2]); | |||
| // 通道号 | |||
| findContion.nChannelId = nChn; | |||
| /** | |||
| * 以下注释的查询条件参数,目前设备不支持,后续会逐渐增加 | |||
| */ | |||
| // // 地点,支持模糊匹配 | |||
| // String machineAddress = ""; | |||
| // System.arraycopy(machineAddress.getBytes(), 0, findContion.szMachineAddress, 0, machineAddress.getBytes().length); | |||
| // | |||
| // // 待查询报警类型 | |||
| // findContion.nAlarmType = EM_FACERECOGNITION_ALARM_TYPE.NET_FACERECOGNITION_ALARM_TYPE_ALL; | |||
| // // 人员组数 | |||
| // findContion.nGroupIdNum = 1; | |||
| // | |||
| // // 人员组ID(人脸库ID) | |||
| // String groupId = ""; | |||
| // System.arraycopy(groupId.getBytes(), 0, findContion.szGroupIdArr[0].szGroupId, 0, groupId.getBytes().length); | |||
| // | |||
| // // 人员信息扩展是否有效 | |||
| // findContion.abPersonInfoEx = 1; | |||
| // | |||
| // // 人员组ID(人脸库ID) | |||
| // System.arraycopy(groupId.getBytes(), 0, findContion.stPersonInfoEx.szGroupID, 0, groupId.getBytes().length); | |||
| findContion.write(); | |||
| lFindHandle = LoginModule.netsdk.CLIENT_FindFileEx(LoginModule.m_hLoginHandle, type, findContion.getPointer(), null, 3000); | |||
| if(lFindHandle.longValue() == 0) { | |||
| System.err.println("FindFileEx Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| findContion.read(); | |||
| return true; | |||
| } | |||
| /** | |||
| * 查询对比数据 | |||
| * @param nFindCount 每次查询的个数 | |||
| */ | |||
| public static MEDIAFILE_FACERECOGNITION_INFO[] findNextFile(int nFindCount) { | |||
| MEDIAFILE_FACERECOGNITION_INFO[] msg = new MEDIAFILE_FACERECOGNITION_INFO[nFindCount]; | |||
| for (int i = 0; i < msg.length; ++i) { | |||
| msg[i] = new NetSDKLib.MEDIAFILE_FACERECOGNITION_INFO(); | |||
| msg[i].bUseCandidatesEx = 1; | |||
| } | |||
| int MemorySize = msg[0].size() * nFindCount; | |||
| Pointer pointer = new Memory(MemorySize); | |||
| pointer.clear(MemorySize); | |||
| ToolKits.SetStructArrToPointerData(msg, pointer); | |||
| int nRetCount = LoginModule.netsdk.CLIENT_FindNextFileEx(lFindHandle, nFindCount, pointer, MemorySize, null, 3000); | |||
| ToolKits.GetPointerDataToStructArr(pointer, msg); | |||
| if (nRetCount <= 0) { | |||
| System.err.println("FindNextFileEx failed!" + ToolKits.getErrorCodePrint()); | |||
| return null; | |||
| } | |||
| MEDIAFILE_FACERECOGNITION_INFO[] retInfo = new MEDIAFILE_FACERECOGNITION_INFO[nRetCount]; | |||
| for (int i = 0; i < retInfo.length; ++i) { | |||
| retInfo[i] = new NetSDKLib.MEDIAFILE_FACERECOGNITION_INFO(); | |||
| retInfo[i] = msg[i]; | |||
| } | |||
| return retInfo; | |||
| } | |||
| public static void findCloseFile() { | |||
| if(lFindHandle.longValue() != 0) { | |||
| LoginModule.netsdk.CLIENT_FindCloseEx(lFindHandle); | |||
| lFindHandle.setValue(0); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,702 @@ | |||
| package com.netsdk.demo.module; | |||
| import java.io.UnsupportedEncodingException; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| import com.netsdk.lib.ToolKits; | |||
| public class GateModule { | |||
| // 查询句柄 | |||
| private static LLong m_lFindHandle = new LLong(0); | |||
| /** | |||
| * 订阅实时上传智能分析数据 | |||
| * @return | |||
| */ | |||
| public static LLong realLoadPic(int ChannelId, NetSDKLib.fAnalyzerDataCallBack m_AnalyzerDataCB) { | |||
| /** | |||
| * 说明: | |||
| * 通道数可以在有登录是返回的信息 m_stDeviceInfo.byChanNum 获取 | |||
| * 下列仅订阅了0通道的智能事件. | |||
| */ | |||
| int bNeedPicture = 1; // 是否需要图片 | |||
| LLong m_hAttachHandle = LoginModule.netsdk.CLIENT_RealLoadPictureEx(LoginModule.m_hLoginHandle, ChannelId, NetSDKLib.EVENT_IVS_ALL, | |||
| bNeedPicture , m_AnalyzerDataCB , null , null); | |||
| if( m_hAttachHandle.longValue() != 0 ) { | |||
| System.out.println("CLIENT_RealLoadPictureEx Success ChannelId : \n" + ChannelId); | |||
| } else { | |||
| System.err.println("CLIENT_RealLoadPictureEx Failed!" + ToolKits.getErrorCodePrint()); | |||
| return null; | |||
| } | |||
| return m_hAttachHandle; | |||
| } | |||
| /** | |||
| * 停止上传智能分析数据-图片 | |||
| */ | |||
| public static void stopRealLoadPic(LLong m_hAttachHandle) { | |||
| if (0 != m_hAttachHandle.longValue()) { | |||
| LoginModule.netsdk.CLIENT_StopLoadPic(m_hAttachHandle); | |||
| System.out.println("Stop detach IVS event"); | |||
| m_hAttachHandle.setValue(0); | |||
| } | |||
| } | |||
| ////////////////////////////////////// 卡信息的增、删、改、清空 //////////////////////////////////////// | |||
| /** | |||
| * 添加卡 | |||
| * @param cardNo 卡号 | |||
| * @param userId 用户ID | |||
| * @param cardName 卡名 | |||
| * @param cardPwd 卡密码 | |||
| * @param cardStatus 卡状态 | |||
| * @param cardType 卡类型 | |||
| * @param useTimes 使用次数 | |||
| * @param isFirstEnter 是否首卡, 1-true, 0-false | |||
| * @param isValid 是否有效, 1-true, 0-false | |||
| * @param startValidTime 有效开始时间 | |||
| * @param endValidTime 有效结束时间 | |||
| * @return true:成功 false:失败 | |||
| */ | |||
| public static boolean insertCard(String cardNo, String userId, String cardName, String cardPwd, | |||
| int cardStatus, int cardType, int useTimes, int isFirstEnter, | |||
| int isValid, String startValidTime, String endValidTime) { | |||
| /** | |||
| * 门禁卡记录集信息 | |||
| */ | |||
| NET_RECORDSET_ACCESS_CTL_CARD accessCardInfo = new NET_RECORDSET_ACCESS_CTL_CARD(); | |||
| // 卡号 | |||
| System.arraycopy(cardNo.getBytes(), 0, accessCardInfo.szCardNo, 0, cardNo.getBytes().length); | |||
| // 用户ID | |||
| System.arraycopy(userId.getBytes(), 0, accessCardInfo.szUserID, 0, userId.getBytes().length); | |||
| // 卡名(设备上显示的姓名) | |||
| try { | |||
| System.arraycopy(cardName.getBytes("GBK"), 0, accessCardInfo.szCardName, 0, cardName.getBytes("GBK").length); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 卡密码 | |||
| System.arraycopy(cardPwd.getBytes(), 0, accessCardInfo.szPsw, 0, cardPwd.getBytes().length); | |||
| //-- 设置开门权限 | |||
| accessCardInfo.nDoorNum = 2; | |||
| accessCardInfo.sznDoors[0] = 0; | |||
| accessCardInfo.sznDoors[1] = 1; | |||
| accessCardInfo.nTimeSectionNum = 2; // 与门数对应 | |||
| accessCardInfo.sznTimeSectionNo[0] = 255; // 表示第一个门全天有效 | |||
| accessCardInfo.sznTimeSectionNo[1] = 255; // 表示第二个门全天有效 | |||
| // 卡状态 | |||
| accessCardInfo.emStatus = cardStatus; | |||
| // 卡类型 | |||
| accessCardInfo.emType = cardType; | |||
| // 使用次数 | |||
| accessCardInfo.nUserTime = useTimes; | |||
| // 是否首卡 | |||
| accessCardInfo.bFirstEnter = isFirstEnter; | |||
| // 是否有效 | |||
| accessCardInfo.bIsValid = isValid; | |||
| // 有效开始时间 | |||
| String[] startTimes = startValidTime.split(" "); | |||
| accessCardInfo.stuValidStartTime.dwYear = Integer.parseInt(startTimes[0].split("-")[0]); | |||
| accessCardInfo.stuValidStartTime.dwMonth = Integer.parseInt(startTimes[0].split("-")[1]); | |||
| accessCardInfo.stuValidStartTime.dwDay = Integer.parseInt(startTimes[0].split("-")[2]); | |||
| accessCardInfo.stuValidStartTime.dwHour = Integer.parseInt(startTimes[1].split(":")[0]); | |||
| accessCardInfo.stuValidStartTime.dwMinute = Integer.parseInt(startTimes[1].split(":")[1]); | |||
| accessCardInfo.stuValidStartTime.dwSecond = Integer.parseInt(startTimes[01].split(":")[2]); | |||
| // 有效结束时间 | |||
| String[] endTimes = endValidTime.split(" "); | |||
| accessCardInfo.stuValidEndTime.dwYear = Integer.parseInt(endTimes[0].split("-")[0]); | |||
| accessCardInfo.stuValidEndTime.dwMonth = Integer.parseInt(endTimes[0].split("-")[1]); | |||
| accessCardInfo.stuValidEndTime.dwDay = Integer.parseInt(endTimes[0].split("-")[2]); | |||
| accessCardInfo.stuValidEndTime.dwHour = Integer.parseInt(endTimes[1].split(":")[0]); | |||
| accessCardInfo.stuValidEndTime.dwMinute = Integer.parseInt(endTimes[1].split(":")[1]); | |||
| accessCardInfo.stuValidEndTime.dwSecond = Integer.parseInt(endTimes[1].split(":")[2]); | |||
| /** | |||
| * 记录集操作 | |||
| */ | |||
| NET_CTRL_RECORDSET_INSERT_PARAM insert = new NET_CTRL_RECORDSET_INSERT_PARAM(); | |||
| insert.stuCtrlRecordSetInfo.emType = EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; // 记录集类型 | |||
| insert.stuCtrlRecordSetInfo.pBuf = accessCardInfo.getPointer(); | |||
| accessCardInfo.write(); | |||
| insert.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, | |||
| CtrlType.CTRLTYPE_CTRL_RECORDSET_INSERT, insert.getPointer(), 5000); | |||
| insert.read(); | |||
| accessCardInfo.read(); | |||
| if(!bRet) { | |||
| System.err.println("添加卡信息失败." + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } else { | |||
| System.out.println("添加卡信息成功,卡信息记录集编号 : " + insert.stuCtrlRecordSetResult.nRecNo); | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 修改卡信息 | |||
| * @param recordNo 记录集编号 | |||
| * @param cardNo 卡号 | |||
| * @param userId 用户ID | |||
| * @param cardName 卡名 | |||
| * @param cardPwd 卡密码 | |||
| * @param cardStatus 卡状态 | |||
| * @param cardType 卡类型 | |||
| * @param useTimes 使用次数 | |||
| * @param isFirstEnter 是否首卡, 1-true, 0-false | |||
| * @param isValid 是否有效, 1-true, 0-false | |||
| * @param startValidTime 有效开始时间 | |||
| * @param endValidTime 有效结束时间 | |||
| * @return true:成功 false:失败 | |||
| */ | |||
| public static boolean modifyCard(int recordNo, String cardNo, String userId, String cardName, String cardPwd, | |||
| int cardStatus, int cardType, int useTimes, int isFirstEnter, | |||
| int isValid, String startValidTime, String endValidTime) { | |||
| /** | |||
| * 门禁卡记录集信息 | |||
| */ | |||
| NET_RECORDSET_ACCESS_CTL_CARD accessCardInfo = new NET_RECORDSET_ACCESS_CTL_CARD(); | |||
| // 记录集编号, 修改、删除卡信息必须填写 | |||
| accessCardInfo.nRecNo = recordNo; | |||
| // 卡号 | |||
| System.arraycopy(cardNo.getBytes(), 0, accessCardInfo.szCardNo, 0, cardNo.getBytes().length); | |||
| // 用户ID | |||
| System.arraycopy(userId.getBytes(), 0, accessCardInfo.szUserID, 0, userId.getBytes().length); | |||
| // 卡名(设备上显示的姓名) | |||
| try { | |||
| System.arraycopy(cardName.getBytes("GBK"), 0, accessCardInfo.szCardName, 0, cardName.getBytes("GBK").length); | |||
| } catch (UnsupportedEncodingException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| // 卡密码 | |||
| System.arraycopy(cardPwd.getBytes(), 0, accessCardInfo.szPsw, 0, cardPwd.getBytes().length); | |||
| //-- 设置开门权限 | |||
| accessCardInfo.nDoorNum = 2; | |||
| accessCardInfo.sznDoors[0] = 0; | |||
| accessCardInfo.sznDoors[1] = 1; | |||
| accessCardInfo.nTimeSectionNum = 2; // 与门数对应 | |||
| accessCardInfo.sznTimeSectionNo[0] = 255; // 表示第一个门全天有效 | |||
| accessCardInfo.sznTimeSectionNo[1] = 255; // 表示第二个门全天有效 | |||
| // 卡状态 | |||
| accessCardInfo.emStatus = cardStatus; | |||
| // 卡类型 | |||
| accessCardInfo.emType = cardType; | |||
| // 使用次数 | |||
| accessCardInfo.nUserTime = useTimes; | |||
| // 是否首卡 | |||
| accessCardInfo.bFirstEnter = isFirstEnter; | |||
| // 是否有效 | |||
| accessCardInfo.bIsValid = isValid; | |||
| // 有效开始时间 | |||
| String[] startTimes = startValidTime.split(" "); | |||
| accessCardInfo.stuValidStartTime.dwYear = Integer.parseInt(startTimes[0].split("-")[0]); | |||
| accessCardInfo.stuValidStartTime.dwMonth = Integer.parseInt(startTimes[0].split("-")[1]); | |||
| accessCardInfo.stuValidStartTime.dwDay = Integer.parseInt(startTimes[0].split("-")[2]); | |||
| accessCardInfo.stuValidStartTime.dwHour = Integer.parseInt(startTimes[1].split(":")[0]); | |||
| accessCardInfo.stuValidStartTime.dwMinute = Integer.parseInt(startTimes[1].split(":")[1]); | |||
| accessCardInfo.stuValidStartTime.dwSecond = Integer.parseInt(startTimes[01].split(":")[2]); | |||
| // 有效结束时间 | |||
| String[] endTimes = endValidTime.split(" "); | |||
| accessCardInfo.stuValidEndTime.dwYear = Integer.parseInt(endTimes[0].split("-")[0]); | |||
| accessCardInfo.stuValidEndTime.dwMonth = Integer.parseInt(endTimes[0].split("-")[1]); | |||
| accessCardInfo.stuValidEndTime.dwDay = Integer.parseInt(endTimes[0].split("-")[2]); | |||
| accessCardInfo.stuValidEndTime.dwHour = Integer.parseInt(endTimes[1].split(":")[0]); | |||
| accessCardInfo.stuValidEndTime.dwMinute = Integer.parseInt(endTimes[1].split(":")[1]); | |||
| accessCardInfo.stuValidEndTime.dwSecond = Integer.parseInt(endTimes[1].split(":")[2]); | |||
| /** | |||
| * 记录集操作 | |||
| */ | |||
| NET_CTRL_RECORDSET_PARAM update = new NET_CTRL_RECORDSET_PARAM(); | |||
| update.emType = EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; // 记录集信息类型 | |||
| update.pBuf = accessCardInfo.getPointer(); | |||
| accessCardInfo.write(); | |||
| update.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, | |||
| CtrlType.CTRLTYPE_CTRL_RECORDSET_UPDATE, update.getPointer(), 5000); | |||
| update.read(); | |||
| accessCardInfo.read(); | |||
| if(!bRet) { | |||
| System.err.println("修改卡信息失败." + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } else { | |||
| System.out.println("修改卡信息成功 "); | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 删除卡信息(单个删除) | |||
| * @param recordNo 记录集编号 | |||
| */ | |||
| public static boolean deleteCard(int recordNo) { | |||
| /** | |||
| * 记录集操作 | |||
| */ | |||
| NET_CTRL_RECORDSET_PARAM msg = new NET_CTRL_RECORDSET_PARAM(); | |||
| msg.emType = EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; | |||
| msg.pBuf = new IntByReference(recordNo).getPointer(); | |||
| msg.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, | |||
| CtrlType.CTRLTYPE_CTRL_RECORDSET_REMOVE, msg.getPointer(), 5000); | |||
| msg.read(); | |||
| if(!bRet){ | |||
| System.err.println("删除卡信息失败." + ToolKits.getErrorCodePrint()); | |||
| } else { | |||
| System.out.println("删除卡信息成功."); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 清除所有卡信息 | |||
| */ | |||
| public static boolean clearCard() { | |||
| /** | |||
| * 记录集操作 | |||
| */ | |||
| NetSDKLib.NET_CTRL_RECORDSET_PARAM msg = new NetSDKLib.NET_CTRL_RECORDSET_PARAM(); | |||
| msg.emType = EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; // 门禁卡记录集信息类型 | |||
| msg.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, | |||
| CtrlType.CTRLTYPE_CTRL_RECORDSET_CLEAR, msg.getPointer(), 5000); | |||
| msg.read(); | |||
| if(!bRet){ | |||
| System.err.println("清空卡信息失败." + ToolKits.getErrorCodePrint()); | |||
| } else { | |||
| System.out.println("清空卡信息成功."); | |||
| } | |||
| return bRet; | |||
| } | |||
| ///////////////////////////////// 人脸的增、删、改、清空 /////////////////////////////////////// | |||
| /** | |||
| * 添加人脸 | |||
| * @param userId 用户ID | |||
| * @param memory 图片缓存 | |||
| * @return | |||
| */ | |||
| public static boolean addFaceInfo(String userId, Memory memory) { | |||
| int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_ADD; // 添加 | |||
| /** | |||
| * 入参 | |||
| */ | |||
| NET_IN_ADD_FACE_INFO stIn = new NET_IN_ADD_FACE_INFO(); | |||
| // 用户ID | |||
| System.arraycopy(userId.getBytes(), 0, stIn.szUserID, 0, userId.getBytes().length); | |||
| // 人脸照片个数 | |||
| stIn.stuFaceInfo.nFacePhoto = 1; | |||
| // 每张图片的大小 | |||
| stIn.stuFaceInfo.nFacePhotoLen[0] = (int) memory.size(); | |||
| // 人脸照片数据,大小不超过100K, 图片格式为jpg | |||
| stIn.stuFaceInfo.pszFacePhotoArr[0].pszFacePhoto = memory; | |||
| /** | |||
| * 出参 | |||
| */ | |||
| NET_OUT_ADD_FACE_INFO stOut = new NET_OUT_ADD_FACE_INFO(); | |||
| stIn.write(); | |||
| stOut.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_FaceInfoOpreate(LoginModule.m_hLoginHandle, emType, stIn.getPointer(), stOut.getPointer(), 5000); | |||
| stIn.read(); | |||
| stOut.read(); | |||
| if(bRet) { | |||
| System.out.println("添加人脸成功!"); | |||
| } else { | |||
| System.err.println("添加人脸失败!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 修改人脸 | |||
| * @param userId 用户ID | |||
| * @param memory 图片缓存 | |||
| * @return | |||
| */ | |||
| public static boolean modifyFaceInfo(String userId, Memory memory) { | |||
| int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_UPDATE; // 修改 | |||
| /** | |||
| * 入参 | |||
| */ | |||
| NET_IN_UPDATE_FACE_INFO stIn = new NET_IN_UPDATE_FACE_INFO(); | |||
| // 用户ID | |||
| System.arraycopy(userId.getBytes(), 0, stIn.szUserID, 0, userId.getBytes().length); | |||
| // 人脸照片个数 | |||
| stIn.stuFaceInfo.nFacePhoto = 1; | |||
| // 每张图片的大小 | |||
| stIn.stuFaceInfo.nFacePhotoLen[0] = (int) memory.size(); | |||
| // 人脸照片数据,大小不超过100K, 图片格式为jpg | |||
| stIn.stuFaceInfo.pszFacePhotoArr[0].pszFacePhoto = memory; | |||
| /** | |||
| * 出参 | |||
| */ | |||
| NET_OUT_UPDATE_FACE_INFO stOut = new NET_OUT_UPDATE_FACE_INFO(); | |||
| stIn.write(); | |||
| stOut.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_FaceInfoOpreate(LoginModule.m_hLoginHandle, emType, stIn.getPointer(), stOut.getPointer(), 5000); | |||
| stIn.read(); | |||
| stOut.read(); | |||
| if(bRet) { | |||
| System.out.println("修改人脸成功!"); | |||
| } else { | |||
| System.err.println("修改人脸失败!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 删除人脸(单个删除) | |||
| * @param userId 用户ID | |||
| */ | |||
| public static boolean deleteFaceInfo(String userId) { | |||
| int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_REMOVE; | |||
| /** | |||
| * 入参 | |||
| */ | |||
| NET_IN_REMOVE_FACE_INFO inRemove = new NET_IN_REMOVE_FACE_INFO(); | |||
| // 用户ID | |||
| System.arraycopy(userId.getBytes(), 0, inRemove.szUserID, 0, userId.getBytes().length); | |||
| /** | |||
| * 出参 | |||
| */ | |||
| NET_OUT_REMOVE_FACE_INFO outRemove = new NET_OUT_REMOVE_FACE_INFO(); | |||
| inRemove.write(); | |||
| outRemove.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_FaceInfoOpreate(LoginModule.m_hLoginHandle, emType, inRemove.getPointer(), outRemove.getPointer(), 5000); | |||
| inRemove.read(); | |||
| outRemove.read(); | |||
| if(bRet) { | |||
| System.out.println("删除人脸成功!"); | |||
| } else { | |||
| System.err.println("删除人脸失败!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 清除所有人脸 | |||
| */ | |||
| public static boolean clearFaceInfo() { | |||
| int emType = EM_FACEINFO_OPREATE_TYPE.EM_FACEINFO_OPREATE_CLEAR; // 清除 | |||
| /** | |||
| * 入参 | |||
| */ | |||
| NET_IN_CLEAR_FACE_INFO stIn = new NET_IN_CLEAR_FACE_INFO(); | |||
| /** | |||
| * 出参 | |||
| */ | |||
| NET_OUT_REMOVE_FACE_INFO stOut = new NET_OUT_REMOVE_FACE_INFO(); | |||
| stIn.write(); | |||
| stOut.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_FaceInfoOpreate(LoginModule.m_hLoginHandle, emType, | |||
| stIn.getPointer(), stOut.getPointer(), 5000); | |||
| stIn.read(); | |||
| stOut.read(); | |||
| if(bRet) { | |||
| System.out.println("清空人脸成功!"); | |||
| } else { | |||
| System.err.println("清空人脸失败!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 查询卡信息,获取查询句柄 | |||
| * @param cardNo 卡号,为空,查询所有的 | |||
| * @return | |||
| */ | |||
| public static boolean findCard(String cardNo,String userId) { | |||
| /** | |||
| * 查询条件 | |||
| */ | |||
| NetSDKLib.FIND_RECORD_ACCESSCTLCARD_CONDITION findCondition = new NetSDKLib.FIND_RECORD_ACCESSCTLCARD_CONDITION(); | |||
| if(!cardNo.isEmpty()) { | |||
| // 卡号查询条件是否有效 | |||
| findCondition.abCardNo = 1; | |||
| // 卡号 | |||
| System.arraycopy(cardNo.getBytes(), 0, findCondition.szCardNo, 0, cardNo.getBytes().length); | |||
| } | |||
| if(!userId.isEmpty()) { | |||
| // 用户Id查询条件是否有效 | |||
| findCondition.abUserID = 1; | |||
| // 用户Id | |||
| System.arraycopy(userId.getBytes(), 0, findCondition.szUserID, 0, cardNo.getBytes().length); | |||
| } | |||
| /** | |||
| * CLIENT_FindRecord 接口入参 | |||
| */ | |||
| NetSDKLib.NET_IN_FIND_RECORD_PARAM stIn = new NetSDKLib.NET_IN_FIND_RECORD_PARAM(); | |||
| stIn.emType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARD; | |||
| if(!cardNo.isEmpty()) { | |||
| stIn.pQueryCondition = findCondition.getPointer(); | |||
| } | |||
| /** | |||
| * CLIENT_FindRecord 接口出参 | |||
| */ | |||
| NetSDKLib.NET_OUT_FIND_RECORD_PARAM stOut = new NetSDKLib.NET_OUT_FIND_RECORD_PARAM(); | |||
| findCondition.write(); | |||
| if(!LoginModule.netsdk.CLIENT_FindRecord(LoginModule.m_hLoginHandle, stIn, stOut, 5000)) { | |||
| System.err.println("没查到卡信息!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| findCondition.read(); | |||
| m_lFindHandle = stOut.lFindeHandle; | |||
| return true; | |||
| } | |||
| /** | |||
| * 查询具体的卡信息 | |||
| * @param nFindCount 每次查询的个数 | |||
| * @return 返回具体的查询信息 | |||
| */ | |||
| public static NET_RECORDSET_ACCESS_CTL_CARD[] findNextCard(int nFindCount) { | |||
| // 用于申请内存 | |||
| NET_RECORDSET_ACCESS_CTL_CARD[] pstRecord = new NET_RECORDSET_ACCESS_CTL_CARD[nFindCount]; | |||
| for(int i = 0; i < nFindCount; i++) { | |||
| pstRecord[i] = new NET_RECORDSET_ACCESS_CTL_CARD(); | |||
| } | |||
| /** | |||
| * CLIENT_FindNextRecord 接口入参 | |||
| */ | |||
| NET_IN_FIND_NEXT_RECORD_PARAM stNextIn = new NET_IN_FIND_NEXT_RECORD_PARAM(); | |||
| stNextIn.lFindeHandle = m_lFindHandle; | |||
| stNextIn.nFileCount = nFindCount; //想查询的记录条数 | |||
| /** | |||
| * CLIENT_FindNextRecord 接口出参 | |||
| */ | |||
| NET_OUT_FIND_NEXT_RECORD_PARAM stNextOut = new NET_OUT_FIND_NEXT_RECORD_PARAM(); | |||
| stNextOut.nMaxRecordNum = nFindCount; | |||
| stNextOut.pRecordList = new Memory(pstRecord[0].dwSize * nFindCount); // 申请内存 | |||
| stNextOut.pRecordList.clear(pstRecord[0].dwSize * nFindCount); | |||
| ToolKits.SetStructArrToPointerData(pstRecord, stNextOut.pRecordList); // 将数组内存拷贝给指针 | |||
| if(LoginModule.netsdk.CLIENT_FindNextRecord(stNextIn, stNextOut, 5000)) { | |||
| if(stNextOut.nRetRecordNum == 0) { | |||
| return null; | |||
| } | |||
| ToolKits.GetPointerDataToStructArr(stNextOut.pRecordList, pstRecord); // 获取卡信息 | |||
| // 获取有用的信息 | |||
| NET_RECORDSET_ACCESS_CTL_CARD[] pstRecordEx = new NET_RECORDSET_ACCESS_CTL_CARD[stNextOut.nRetRecordNum]; | |||
| for(int i = 0; i < stNextOut.nRetRecordNum; i++) { | |||
| pstRecordEx[i] = new NET_RECORDSET_ACCESS_CTL_CARD(); | |||
| pstRecordEx[i] = pstRecord[i]; | |||
| } | |||
| return pstRecordEx; | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * 关闭查询 | |||
| */ | |||
| public static void findCardClose() { | |||
| if(m_lFindHandle.longValue() != 0) { | |||
| LoginModule.netsdk.CLIENT_FindRecordClose(m_lFindHandle); | |||
| m_lFindHandle.setValue(0); | |||
| } | |||
| } | |||
| /** | |||
| * 查询进出记录信息,获取查询句柄 | |||
| * @param time 日期,为空,查询所有的 | |||
| * @return | |||
| */ | |||
| public static boolean findRecord(NET_TIME time) { | |||
| /** | |||
| * 查询条件 | |||
| */ | |||
| NetSDKLib.FIND_RECORD_ACCESSCTLCARDREC_CONDITION_EX findCondition = new NetSDKLib.FIND_RECORD_ACCESSCTLCARDREC_CONDITION_EX(); | |||
| if(time != null){ | |||
| // 启用时间段查询是否有效 | |||
| findCondition.bTimeEnable = 1; | |||
| //开始时间 | |||
| findCondition.stStartTime.dwYear = time.dwYear; | |||
| findCondition.stStartTime.dwMonth = time.dwMonth; | |||
| findCondition.stStartTime.dwDay = time.dwDay; | |||
| //结束时间 | |||
| findCondition.stEndTime.dwYear = time.dwYear; | |||
| findCondition.stEndTime.dwMonth = time.dwMonth; | |||
| findCondition.stEndTime.dwDay = time.dwDay + 1; | |||
| } | |||
| //启用排序 | |||
| findCondition.nOrderNum = 1;//规则数 | |||
| FIND_RECORD_ACCESSCTLCARDREC_ORDER order = new FIND_RECORD_ACCESSCTLCARDREC_ORDER(); | |||
| order.emField = EM_RECORD_ACCESSCTLCARDREC_ORDER_FIELD.EM_RECORD_ACCESSCTLCARDREC_ORDER_FIELD_CREATETIME;//创建时间排序 | |||
| order.emOrderType = EM_RECORD_ORDER_TYPE.EM_RECORD_ORDER_TYPE_ASCENT;//升序 | |||
| findCondition.stuOrders = new FIND_RECORD_ACCESSCTLCARDREC_ORDER[1]; | |||
| findCondition.stuOrders[0] = order; | |||
| /** | |||
| * CLIENT_FindRecord 接口入参 | |||
| */ | |||
| NetSDKLib.NET_IN_FIND_RECORD_PARAM stIn = new NetSDKLib.NET_IN_FIND_RECORD_PARAM(); | |||
| stIn.emType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARDREC_EX; | |||
| if(time != null) { | |||
| stIn.pQueryCondition = findCondition.getPointer(); | |||
| } | |||
| /** | |||
| * CLIENT_FindRecord 接口出参 | |||
| */ | |||
| NetSDKLib.NET_OUT_FIND_RECORD_PARAM stOut = new NetSDKLib.NET_OUT_FIND_RECORD_PARAM(); | |||
| findCondition.write(); | |||
| if(!LoginModule.netsdk.CLIENT_FindRecord(LoginModule.m_hLoginHandle, stIn, stOut, 5000)) { | |||
| System.err.println("没查到开门信息!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| findCondition.read(); | |||
| m_lFindHandle = stOut.lFindeHandle; | |||
| return true; | |||
| } | |||
| /** | |||
| * 进出记录查询 | |||
| */ | |||
| /** | |||
| * 查询具体的卡信息 | |||
| * @param nFindCount 每次查询的个数 | |||
| * @return 返回具体的查询信息 | |||
| */ | |||
| public static NET_RECORDSET_ACCESS_CTL_CARDREC[] findNextRecord(int nFindCount) { | |||
| // 用于申请内存 | |||
| NET_RECORDSET_ACCESS_CTL_CARDREC[] pstRecord = new NET_RECORDSET_ACCESS_CTL_CARDREC[nFindCount]; | |||
| for(int i = 0; i < nFindCount; i++) { | |||
| pstRecord[i] = new NET_RECORDSET_ACCESS_CTL_CARDREC(); | |||
| } | |||
| /** | |||
| * CLIENT_FindNextRecord 接口入参 | |||
| */ | |||
| NET_IN_FIND_NEXT_RECORD_PARAM stNextIn = new NET_IN_FIND_NEXT_RECORD_PARAM(); | |||
| stNextIn.lFindeHandle = m_lFindHandle; | |||
| stNextIn.nFileCount = nFindCount; //想查询的记录条数 | |||
| /** | |||
| * CLIENT_FindNextRecord 接口出参 | |||
| */ | |||
| NET_OUT_FIND_NEXT_RECORD_PARAM stNextOut = new NET_OUT_FIND_NEXT_RECORD_PARAM(); | |||
| stNextOut.nMaxRecordNum = nFindCount; | |||
| stNextOut.pRecordList = new Memory(pstRecord[0].dwSize * nFindCount); // 申请内存 | |||
| stNextOut.pRecordList.clear(pstRecord[0].dwSize * nFindCount); | |||
| ToolKits.SetStructArrToPointerData(pstRecord, stNextOut.pRecordList); // 将数组内存拷贝给指针 | |||
| if(LoginModule.netsdk.CLIENT_FindNextRecord(stNextIn, stNextOut, 5000)) { | |||
| if(stNextOut.nRetRecordNum == 0) { | |||
| return null; | |||
| } | |||
| ToolKits.GetPointerDataToStructArr(stNextOut.pRecordList, pstRecord); // 获取卡信息 | |||
| // 获取有用的信息 | |||
| NET_RECORDSET_ACCESS_CTL_CARDREC[] pstRecordEx = new NET_RECORDSET_ACCESS_CTL_CARDREC[stNextOut.nRetRecordNum]; | |||
| for(int i = 0; i < stNextOut.nRetRecordNum; i++) { | |||
| pstRecordEx[i] = new NET_RECORDSET_ACCESS_CTL_CARDREC(); | |||
| pstRecordEx[i] = pstRecord[i]; | |||
| } | |||
| return pstRecordEx; | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * 关闭查询 | |||
| */ | |||
| public static void findRecordClose() { | |||
| if(m_lFindHandle.longValue() != 0) { | |||
| LoginModule.netsdk.CLIENT_FindRecordClose(m_lFindHandle); | |||
| m_lFindHandle.setValue(0); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,148 @@ | |||
| package com.netsdk.demo.module; | |||
| import java.io.File; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY; | |||
| import com.netsdk.lib.NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| /** | |||
| * 登陆接口实现 | |||
| * 主要有 :初始化、登陆、登出功能 | |||
| */ | |||
| public class LoginModule { | |||
| public static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE; | |||
| public static NetSDKLib configsdk = NetSDKLib.CONFIG_INSTANCE; | |||
| // 设备信息 | |||
| public static NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex(); | |||
| // 登陆句柄 | |||
| public static LLong m_hLoginHandle = new LLong(0); | |||
| private static boolean bInit = false; | |||
| private static boolean bLogopen = false; | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Init | |||
| * \else | |||
| * 初始化 | |||
| * \endif | |||
| */ | |||
| public static boolean init(NetSDKLib.fDisConnect disConnect, NetSDKLib.fHaveReConnect haveReConnect) { | |||
| bInit = netsdk.CLIENT_Init(disConnect, null); | |||
| if(!bInit) { | |||
| System.out.println("Initialize SDK failed"); | |||
| return false; | |||
| } | |||
| //打开日志,可选 | |||
| NetSDKLib.LOG_SET_PRINT_INFO setLog = new NetSDKLib.LOG_SET_PRINT_INFO(); | |||
| File path = new File("./sdklog/"); | |||
| if (!path.exists()) { | |||
| path.mkdir(); | |||
| } | |||
| String logPath = path.getAbsoluteFile().getParent() + "\\sdklog\\" + ToolKits.getDate() + ".log"; | |||
| setLog.nPrintStrategy = 0; | |||
| setLog.bSetFilePath = 1; | |||
| System.arraycopy(logPath.getBytes(), 0, setLog.szLogFilePath, 0, logPath.getBytes().length); | |||
| System.out.println(logPath); | |||
| setLog.bSetPrintStrategy = 1; | |||
| bLogopen = netsdk.CLIENT_LogOpen(setLog); | |||
| if(!bLogopen ) { | |||
| System.err.println("Failed to open NetSDK log"); | |||
| } | |||
| // 设置断线重连回调接口,设置过断线重连成功回调函数后,当设备出现断线情况,SDK内部会自动进行重连操作 | |||
| // 此操作为可选操作,但建议用户进行设置 | |||
| netsdk.CLIENT_SetAutoReconnect(haveReConnect, null); | |||
| //设置登录超时时间和尝试次数,可选 | |||
| int waitTime = 5000; //登录请求响应超时时间设置为5S | |||
| int tryTimes = 1; //登录时尝试建立链接1次 | |||
| netsdk.CLIENT_SetConnectTime(waitTime, tryTimes); | |||
| // 设置更多网络参数,NET_PARAM的nWaittime,nConnectTryNum成员与CLIENT_SetConnectTime | |||
| // 接口设置的登录设备超时时间和尝试次数意义相同,可选 | |||
| NetSDKLib.NET_PARAM netParam = new NetSDKLib.NET_PARAM(); | |||
| netParam.nConnectTime = 10000; // 登录时尝试建立链接的超时时间 | |||
| netParam.nGetConnInfoTime = 3000; // 设置子连接的超时时间 | |||
| netParam.nGetDevInfoTime = 3000;//获取设备信息超时时间,为0默认1000ms | |||
| netsdk.CLIENT_SetNetworkParam(netParam); | |||
| return true; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * CleanUp | |||
| * \else | |||
| * 清除环境 | |||
| * \endif | |||
| */ | |||
| public static void cleanup() { | |||
| if(bLogopen) { | |||
| netsdk.CLIENT_LogClose(); | |||
| } | |||
| if(bInit) { | |||
| netsdk.CLIENT_Cleanup(); | |||
| } | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Login Device | |||
| * \else | |||
| * 登录设备 | |||
| * \endif | |||
| */ | |||
| public static boolean login(String m_strIp, int m_nPort, String m_strUser, String m_strPassword) { | |||
| //IntByReference nError = new IntByReference(0); | |||
| //入参 | |||
| NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY pstInParam=new NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY(); | |||
| pstInParam.nPort=m_nPort; | |||
| pstInParam.szIP=m_strIp.getBytes(); | |||
| pstInParam.szPassword=m_strPassword.getBytes(); | |||
| pstInParam.szUserName=m_strUser.getBytes(); | |||
| //出参 | |||
| NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY pstOutParam=new NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY(); | |||
| pstOutParam.stuDeviceInfo=m_stDeviceInfo; | |||
| //m_hLoginHandle = netsdk.CLIENT_LoginEx2(m_strIp, m_nPort, m_strUser, m_strPassword, 0, null, m_stDeviceInfo, nError); | |||
| m_hLoginHandle=netsdk.CLIENT_LoginWithHighLevelSecurity(pstInParam, pstOutParam); | |||
| if(m_hLoginHandle.longValue() == 0) { | |||
| System.err.printf("Login Device[%s] Port[%d]Failed. %s\n", m_strIp, m_nPort, ToolKits.getErrorCodePrint()); | |||
| } else { | |||
| System.out.println("Login Success [ " + m_strIp + " ]"); | |||
| } | |||
| return m_hLoginHandle.longValue() == 0? false:true; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Logout Device | |||
| * \else | |||
| * 登出设备 | |||
| * \endif | |||
| */ | |||
| public static boolean logout() { | |||
| if(m_hLoginHandle.longValue() == 0) { | |||
| return false; | |||
| } | |||
| boolean bRet = netsdk.CLIENT_Logout(m_hLoginHandle); | |||
| if(bRet) { | |||
| m_hLoginHandle.setValue(0); | |||
| } | |||
| return bRet; | |||
| } | |||
| } | |||
| @@ -0,0 +1,206 @@ | |||
| package com.netsdk.demo.module; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| /** | |||
| * 云台控制接口实现 | |||
| * 主要有 :八个方向控制、变倍、变焦、光圈功能 | |||
| */ | |||
| public class PtzControlModule { | |||
| /** | |||
| * 向上 | |||
| */ | |||
| public static boolean ptzControlUpStart(int nChannelID, int lParam1, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_UP_CONTROL, | |||
| lParam1, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlUpEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_UP_CONTROL, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 向下 | |||
| */ | |||
| public static boolean ptzControlDownStart(int nChannelID, int lParam1, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_DOWN_CONTROL, | |||
| lParam1, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlDownEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_DOWN_CONTROL, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 向左 | |||
| */ | |||
| public static boolean ptzControlLeftStart(int nChannelID, int lParam1, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_LEFT_CONTROL, | |||
| lParam1, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlLeftEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_LEFT_CONTROL, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 向右 | |||
| */ | |||
| public static boolean ptzControlRightStart(int nChannelID, int lParam1,int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_RIGHT_CONTROL, | |||
| lParam1, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlRightEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_RIGHT_CONTROL, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 向左上 | |||
| */ | |||
| public static boolean ptzControlLeftUpStart(int nChannelID, int lParam1, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTTOP, | |||
| lParam1, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlLeftUpEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTTOP, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 向右上 | |||
| */ | |||
| public static boolean ptzControlRightUpStart(int nChannelID, int lParam1, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTTOP, | |||
| lParam1, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlRightUpEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTTOP, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 向左下 | |||
| */ | |||
| public static boolean ptzControlLeftDownStart(int nChannelID, int lParam1, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTDOWN, | |||
| lParam1, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlLeftDownEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTDOWN, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 向右下 | |||
| */ | |||
| public static boolean ptzControlRightDownStart(int nChannelID, int lParam1, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTDOWN, | |||
| lParam1, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlRightDownEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTDOWN, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 变倍+ | |||
| */ | |||
| public static boolean ptzControlZoomAddStart(int nChannelID, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_ADD_CONTROL, | |||
| 0, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlZoomAddEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_ADD_CONTROL, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 变倍- | |||
| */ | |||
| public static boolean ptzControlZoomDecStart(int nChannelID, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_DEC_CONTROL, | |||
| 0, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlZoomDecEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_DEC_CONTROL, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 变焦+ | |||
| */ | |||
| public static boolean ptzControlFocusAddStart(int nChannelID, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_ADD_CONTROL, | |||
| 0, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlFocusAddEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_ADD_CONTROL, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 变焦- | |||
| */ | |||
| public static boolean ptzControlFocusDecStart(int nChannelID, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_DEC_CONTROL, | |||
| 0, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlFocusDecEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_DEC_CONTROL, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 光圈+ | |||
| */ | |||
| public static boolean ptzControlIrisAddStart(int nChannelID, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_ADD_CONTROL, | |||
| 0, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlIrisAddEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_ADD_CONTROL, | |||
| 0, 0, 0, 1); | |||
| } | |||
| /** | |||
| * 光圈- | |||
| */ | |||
| public static boolean ptzControlIrisDecStart(int nChannelID, int lParam2) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_DEC_CONTROL, | |||
| 0, lParam2, 0, 0); | |||
| } | |||
| public static boolean ptzControlIrisDecEnd(int nChannelID) { | |||
| return LoginModule.netsdk.CLIENT_DHPTZControlEx(LoginModule.m_hLoginHandle, nChannelID, | |||
| NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_DEC_CONTROL, | |||
| 0, 0, 0, 1); | |||
| } | |||
| } | |||
| @@ -0,0 +1,51 @@ | |||
| package com.netsdk.demo.module; | |||
| import java.awt.Panel; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.sun.jna.Native; | |||
| /** | |||
| * 实时预览接口实现 | |||
| * 主要有 :开始拉流、停止拉流功能 | |||
| */ | |||
| public class RealPlayModule { | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Start RealPlay | |||
| * \else | |||
| * 开始预览 | |||
| * \endif | |||
| */ | |||
| public static LLong startRealPlay(int channel, int stream, Panel realPlayWindow) { | |||
| LLong m_hPlayHandle = LoginModule.netsdk.CLIENT_RealPlayEx(LoginModule.m_hLoginHandle, channel, Native.getComponentPointer(realPlayWindow), stream); | |||
| if(m_hPlayHandle.longValue() == 0) { | |||
| System.err.println("开始实时预览失败,错误码" + ToolKits.getErrorCodePrint()); | |||
| } else { | |||
| System.out.println("Success to start realplay"); | |||
| } | |||
| return m_hPlayHandle; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Start RealPlay | |||
| * \else | |||
| * 停止预览 | |||
| * \endif | |||
| */ | |||
| public static void stopRealPlay(LLong m_hPlayHandle) { | |||
| if(m_hPlayHandle.longValue() == 0) { | |||
| return; | |||
| } | |||
| boolean bRet = LoginModule.netsdk.CLIENT_StopRealPlayEx(m_hPlayHandle); | |||
| if(bRet) { | |||
| m_hPlayHandle.setValue(0); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,214 @@ | |||
| package com.netsdk.demo.module; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| import com.sun.jna.Memory; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| /** | |||
| * 以图搜图接口实现,跟查询人脸库里的人员信息的查找接口是一样的,入参和实现有区别 | |||
| * 目前只支持IVSS | |||
| */ | |||
| public class SearchByPictureModule { | |||
| // 查询密令 | |||
| public static int nToken = 0; | |||
| private static LLong m_FindHandle = null; | |||
| // 订阅句柄 | |||
| private static LLong attachFaceHandle = new LLong(0); | |||
| /** | |||
| * 按条件查询目标识别结果 | |||
| * @param memory 图片缓存 | |||
| * @param startTime 起始时间, 历史库需要时间,人脸库不需要时间 | |||
| * @param endTime 结束时间, 历史库需要时间,人脸库不需要时间 | |||
| * @param isHistory 是否是历史库, true-历史库; false-人脸库 | |||
| * @param nChn 通道号, 历史库需要通道号,人脸库不需要通道号 | |||
| * @param similary 相似度 | |||
| * @return 查询到的所有人员个数 | |||
| */ | |||
| public static int startFindPerson(Memory memory, | |||
| String startTime, | |||
| String endTime, | |||
| boolean isHistory, | |||
| int nChn, | |||
| String similary) { | |||
| m_FindHandle = null; | |||
| nToken = 0; | |||
| int nTotalCount = 0; | |||
| /* | |||
| * 入参, IVVS设备,查询条件只有 stuInStartFind.stPerson 里的参数有效 | |||
| */ | |||
| NET_IN_STARTFIND_FACERECONGNITION stuIn = new NET_IN_STARTFIND_FACERECONGNITION(); | |||
| // 人员信息查询条件是否有效, 并使用扩展结构体 | |||
| stuIn.bPersonExEnable = 1; | |||
| // 图片信息 | |||
| if(memory != null) { | |||
| stuIn.pBuffer = memory; | |||
| stuIn.nBufferLen = (int)memory.size(); | |||
| stuIn.stPersonInfoEx.wFacePicNum = 1; | |||
| stuIn.stPersonInfoEx.szFacePicInfo[0].dwOffSet = 0; | |||
| stuIn.stPersonInfoEx.szFacePicInfo[0].dwFileLenth = (int)memory.size(); | |||
| } | |||
| // 相似度 | |||
| if(!similary.isEmpty()) { | |||
| stuIn.stMatchOptions.nSimilarity = Integer.parseInt(similary); | |||
| } | |||
| stuIn.stFilterInfo.nGroupIdNum = 0; | |||
| stuIn.stFilterInfo.nRangeNum = 1; | |||
| if(isHistory) { // 历史库 | |||
| // 通道号 | |||
| stuIn.nChannelID = nChn; | |||
| stuIn.stFilterInfo.szRange[0] = EM_FACE_DB_TYPE.NET_FACE_DB_TYPE_HISTORY; // 待查询数据库类型,设备只支持一个 | |||
| // 开始时间 | |||
| String[] startTimeStr = startTime.split("-"); | |||
| stuIn.stFilterInfo.stStartTime.dwYear = Integer.parseInt(startTimeStr[0]); | |||
| stuIn.stFilterInfo.stStartTime.dwMonth = Integer.parseInt(startTimeStr[1]); | |||
| stuIn.stFilterInfo.stStartTime.dwDay = Integer.parseInt(startTimeStr[2]); | |||
| stuIn.stFilterInfo.stStartTime.dwHour= 0; | |||
| stuIn.stFilterInfo.stStartTime.dwMinute= 0; | |||
| stuIn.stFilterInfo.stStartTime.dwSecond= 0; | |||
| // 结束时间 | |||
| String[] endTimeStr = endTime.split("-"); | |||
| stuIn.stFilterInfo.stEndTime.dwYear = Integer.parseInt(endTimeStr[0]); | |||
| stuIn.stFilterInfo.stEndTime.dwMonth = Integer.parseInt(endTimeStr[1]); | |||
| stuIn.stFilterInfo.stEndTime.dwDay = Integer.parseInt(endTimeStr[2]); | |||
| stuIn.stFilterInfo.stEndTime.dwHour=23; | |||
| stuIn.stFilterInfo.stEndTime.dwMinute=59; | |||
| stuIn.stFilterInfo.stEndTime.dwSecond=59; | |||
| stuIn.stFilterInfo.emFaceType = EM_FACERECOGNITION_FACE_TYPE.EM_FACERECOGNITION_FACE_TYPE_ALL; | |||
| } else { // 人脸库 | |||
| stuIn.stFilterInfo.szRange[0] = EM_FACE_DB_TYPE.NET_FACE_DB_TYPE_BLACKLIST; // 待查询数据库类型,设备只支持一个 | |||
| } | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_STARTFIND_FACERECONGNITION stuOut = new NET_OUT_STARTFIND_FACERECONGNITION(); | |||
| stuIn.write(); | |||
| stuOut.write(); | |||
| if(LoginModule.netsdk.CLIENT_StartFindFaceRecognition(LoginModule.m_hLoginHandle, stuIn, stuOut, 4000)) { | |||
| m_FindHandle = stuOut.lFindHandle; | |||
| nTotalCount = stuOut.nTotalCount; | |||
| nToken = stuOut.nToken; | |||
| } else { | |||
| System.out.println("CLIENT_StartFindFaceRecognition Failed, Error:" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return nTotalCount; | |||
| } | |||
| /** | |||
| * 查找目标识别结果 | |||
| * @param beginNum 查询起始序号 | |||
| * @param nCount 当前想查询的记录条数 | |||
| * @return 返回的人员信息数组 | |||
| */ | |||
| public static CANDIDATE_INFOEX[] doFindNextPerson(int beginNum, int nCount) { | |||
| /* | |||
| *入参 | |||
| */ | |||
| NetSDKLib.NET_IN_DOFIND_FACERECONGNITION stuIn = new NetSDKLib.NET_IN_DOFIND_FACERECONGNITION(); | |||
| stuIn.lFindHandle = m_FindHandle; | |||
| stuIn.nCount = nCount; // 当前想查询的记录条数 | |||
| stuIn.nBeginNum = beginNum; // 查询起始序号 | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NetSDKLib.NET_OUT_DOFIND_FACERECONGNITION stuOut = new NetSDKLib.NET_OUT_DOFIND_FACERECONGNITION();; | |||
| stuOut.bUseCandidatesEx = 1; // 是否使用候选对象扩展结构体 | |||
| // 必须申请内存,每次查询几个,必须至少申请几个,最大申请20个 | |||
| for(int i = 0; i < nCount; i++) { | |||
| stuOut.stuCandidatesEx[i].stPersonInfo.szFacePicInfo[0].nFilePathLen = 256; | |||
| stuOut.stuCandidatesEx[i].stPersonInfo.szFacePicInfo[0].pszFilePath = new Memory(256); | |||
| } | |||
| stuIn.write(); | |||
| stuOut.write(); | |||
| if(LoginModule.netsdk.CLIENT_DoFindFaceRecognition(stuIn, stuOut, 4000)) { | |||
| stuIn.read(); | |||
| stuOut.read(); | |||
| if(stuOut.nCadidateExNum == 0) { | |||
| return null; | |||
| } | |||
| // 获取到的信息 | |||
| CANDIDATE_INFOEX[] stuCandidatesEx = new CANDIDATE_INFOEX[stuOut.nCadidateExNum]; | |||
| for(int i = 0; i < stuOut.nCadidateExNum; i++) { | |||
| stuCandidatesEx[i] = new CANDIDATE_INFOEX(); | |||
| stuCandidatesEx[i] = stuOut.stuCandidatesEx[i]; | |||
| } | |||
| return stuCandidatesEx; | |||
| } else { | |||
| System.out.println("CLIENT_DoFindFaceRecognition Failed, Error:" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * 结束查询 | |||
| */ | |||
| public static boolean doFindClosePerson() { | |||
| boolean bRet = false; | |||
| if(m_FindHandle.longValue() != 0) { | |||
| bRet = LoginModule.netsdk.CLIENT_StopFindFaceRecognition(m_FindHandle); | |||
| } | |||
| return bRet; | |||
| } | |||
| /** | |||
| * 订阅人脸查询状态 | |||
| * @param faceFindStateCb 人脸状态回调函数 | |||
| * @return | |||
| */ | |||
| public static boolean attachFaceFindState(fFaceFindState faceFindStateCb) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_FACE_FIND_STATE stuIn = new NET_IN_FACE_FIND_STATE(); | |||
| stuIn.nTokenNum = 1; | |||
| stuIn.nTokens = new IntByReference(nToken); // 查询令牌 | |||
| stuIn.cbFaceFindState = faceFindStateCb; | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_FACE_FIND_STATE stuOut = new NET_OUT_FACE_FIND_STATE(); | |||
| stuIn.write(); | |||
| attachFaceHandle = LoginModule.netsdk.CLIENT_AttachFaceFindState(LoginModule.m_hLoginHandle, stuIn, stuOut, 4000); | |||
| stuIn.read(); | |||
| if(attachFaceHandle.longValue() != 0) { | |||
| System.out.println("AttachFaceFindState Succeed!"); | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| /** | |||
| * 关闭订阅 | |||
| */ | |||
| public static void detachFaceFindState() { | |||
| if(attachFaceHandle.longValue() != 0) { | |||
| LoginModule.netsdk.CLIENT_DetachFaceFindState(attachFaceHandle); | |||
| attachFaceHandle.setValue(0); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,162 @@ | |||
| package com.netsdk.demo.module; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.sun.jna.Pointer; | |||
| import com.sun.jna.ptr.IntByReference; | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Talk Interface | |||
| * contains:start talk、stop talk and audio data callback implement class | |||
| * \else | |||
| * 语音对讲接口实现 | |||
| * 包含: 开始通话、结束通话、语音对讲的数据回调实现类 | |||
| * \endif | |||
| */ | |||
| public class TalkModule { | |||
| public static LLong m_hTalkHandle = new LLong(0); // 语音对讲句柄 | |||
| private static boolean m_bRecordStatus = false; // 是否正在录音 | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Start Talk | |||
| * \else | |||
| * 开始通话 | |||
| * \endif | |||
| */ | |||
| public static boolean startTalk(int transferType, int chn) { | |||
| // 设置语音对讲编码格式 | |||
| NetSDKLib.NETDEV_TALKDECODE_INFO talkEncode = new NetSDKLib.NETDEV_TALKDECODE_INFO(); | |||
| talkEncode.encodeType = NetSDKLib.NET_TALK_CODING_TYPE.NET_TALK_PCM; | |||
| talkEncode.dwSampleRate = 8000; | |||
| talkEncode.nAudioBit = 16; | |||
| talkEncode.nPacketPeriod = 25; | |||
| talkEncode.write(); | |||
| if(LoginModule.netsdk.CLIENT_SetDeviceMode(LoginModule.m_hLoginHandle, NetSDKLib.EM_USEDEV_MODE.NET_TALK_ENCODE_TYPE, talkEncode.getPointer())) { | |||
| System.out.println("Set Talk Encode Type Succeed!"); | |||
| } else { | |||
| System.err.println("Set Talk Encode Type Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| // 设置语音对讲喊话参数 | |||
| NetSDKLib.NET_SPEAK_PARAM speak = new NetSDKLib.NET_SPEAK_PARAM(); | |||
| speak.nMode = 0; | |||
| speak.bEnableWait = false; | |||
| speak.nSpeakerChannel = 0; | |||
| speak.write(); | |||
| if (LoginModule.netsdk.CLIENT_SetDeviceMode(LoginModule.m_hLoginHandle, NetSDKLib.EM_USEDEV_MODE.NET_TALK_SPEAK_PARAM, speak.getPointer())) { | |||
| System.out.println("Set Talk Speak Mode Succeed!"); | |||
| } else { | |||
| System.err.println("Set Talk Speak Mode Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| // 设置语音对讲是否为转发模式 | |||
| NetSDKLib.NET_TALK_TRANSFER_PARAM talkTransfer = new NetSDKLib.NET_TALK_TRANSFER_PARAM(); | |||
| talkTransfer.bTransfer = transferType; | |||
| talkTransfer.write(); | |||
| if(LoginModule.netsdk.CLIENT_SetDeviceMode(LoginModule.m_hLoginHandle, NetSDKLib.EM_USEDEV_MODE.NET_TALK_TRANSFER_MODE, talkTransfer.getPointer())) { | |||
| System.out.println("Set Talk Transfer Mode Succeed!"); | |||
| } else { | |||
| System.err.println("Set Talk Transfer Mode Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| if (talkTransfer.bTransfer == 1) { // 转发模式设置转发通道 | |||
| IntByReference nChn = new IntByReference(chn); | |||
| if(LoginModule.netsdk.CLIENT_SetDeviceMode(LoginModule.m_hLoginHandle, NetSDKLib.EM_USEDEV_MODE.NET_TALK_TALK_CHANNEL, nChn.getPointer())) { | |||
| System.out.println("Set Talk Channel Succeed!"); | |||
| } else { | |||
| System.err.println("Set Talk Channel Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| } | |||
| m_hTalkHandle = LoginModule.netsdk.CLIENT_StartTalkEx(LoginModule.m_hLoginHandle, AudioDataCB.getInstance(), null); | |||
| if(m_hTalkHandle.longValue() == 0) { | |||
| System.err.println("Start Talk Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } else { | |||
| System.out.println("Start Talk Success"); | |||
| if(LoginModule.netsdk.CLIENT_RecordStart()){ | |||
| System.out.println("Start Record Success"); | |||
| m_bRecordStatus = true; | |||
| } else { | |||
| System.err.println("Start Local Record Failed!" + ToolKits.getErrorCodePrint()); | |||
| stopTalk(); | |||
| return false; | |||
| } | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Stop Talk | |||
| * \else | |||
| * 结束通话 | |||
| * \endif | |||
| */ | |||
| public static void stopTalk() { | |||
| if(m_hTalkHandle.longValue() == 0) { | |||
| return; | |||
| } | |||
| if (m_bRecordStatus){ | |||
| LoginModule.netsdk.CLIENT_RecordStop(); | |||
| m_bRecordStatus = false; | |||
| } | |||
| if(LoginModule.netsdk.CLIENT_StopTalkEx(m_hTalkHandle)) { | |||
| m_hTalkHandle.setValue(0); | |||
| }else { | |||
| System.err.println("Stop Talk Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| } | |||
| /** | |||
| * \if ENGLISH_LANG | |||
| * Audio Data Callback | |||
| * \else | |||
| * 语音对讲的数据回调 | |||
| * \endif | |||
| */ | |||
| private static class AudioDataCB implements NetSDKLib.pfAudioDataCallBack { | |||
| private AudioDataCB() {} | |||
| private static AudioDataCB audioCallBack = new AudioDataCB(); | |||
| public static AudioDataCB getInstance() { | |||
| return audioCallBack; | |||
| } | |||
| public void invoke(LLong lTalkHandle, Pointer pDataBuf, int dwBufSize, byte byAudioFlag, Pointer dwUser){ | |||
| if(lTalkHandle.longValue() != m_hTalkHandle.longValue()) { | |||
| return; | |||
| } | |||
| if (byAudioFlag == 0) { // 将收到的本地PC端检测到的声卡数据发送给设备端 | |||
| LLong lSendSize = LoginModule.netsdk.CLIENT_TalkSendData(m_hTalkHandle, pDataBuf, dwBufSize); | |||
| if(lSendSize.longValue() != (long)dwBufSize) { | |||
| System.err.println("send incomplete" + lSendSize.longValue() + ":" + dwBufSize); | |||
| } | |||
| }else if (byAudioFlag == 1) { // 将收到的设备端发送过来的语音数据传给SDK解码播放 | |||
| LoginModule.netsdk.CLIENT_AudioDecEx(m_hTalkHandle, pDataBuf, dwBufSize); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,273 @@ | |||
| package com.netsdk.demo.module; | |||
| import java.io.IOException; | |||
| import com.netsdk.lib.ImageAlgLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.*; | |||
| public class ThermalCameraModule { | |||
| static ImageAlgLib imageAlgApi = ImageAlgLib.IMAGEALG_INSTANCE; | |||
| public static class ThermalCameraStatus { | |||
| public boolean bSearching = false; // 是否正在查找 | |||
| public int nFinderHanle; // 取到的查询句柄 | |||
| public int nTotalCount; // 符合此次查询条件的结果总条数 | |||
| public LLong hRadiometryHandle = new LLong(0); // 订阅句柄 | |||
| } | |||
| private static ThermalCameraStatus status = new ThermalCameraStatus(); | |||
| /** | |||
| * 订阅温度分布数据(热图) | |||
| */ | |||
| public static boolean radiometryAttach(int nChannel, fRadiometryAttachCB cbNotify) { | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_RADIOMETRY_ATTACH stIn = new NET_IN_RADIOMETRY_ATTACH(); | |||
| stIn.nChannel = nChannel; // 通道号 | |||
| stIn.cbNotify = cbNotify; // 回调函数 | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_RADIOMETRY_ATTACH stOut = new NET_OUT_RADIOMETRY_ATTACH(); | |||
| status.hRadiometryHandle = LoginModule.netsdk.CLIENT_RadiometryAttach(LoginModule.m_hLoginHandle, stIn, stOut, 3000); | |||
| if(status.hRadiometryHandle.longValue() == 0) { | |||
| System.err.printf("RadiometryAttach Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return status.hRadiometryHandle.longValue() != 0; | |||
| } | |||
| /** | |||
| * 获取查询总个数 | |||
| */ | |||
| public static boolean isAttaching() { | |||
| return status.hRadiometryHandle.longValue() != 0; | |||
| } | |||
| /** | |||
| * 开始获取热图数据 | |||
| */ | |||
| public static int radiometryFetch(int nChannel) { | |||
| int nStatus = -1; | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_RADIOMETRY_FETCH stIn = new NET_IN_RADIOMETRY_FETCH(); | |||
| stIn.nChannel = nChannel; // 通道号 | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_RADIOMETRY_FETCH stOut = new NET_OUT_RADIOMETRY_FETCH(); | |||
| if(!LoginModule.netsdk.CLIENT_RadiometryFetch(LoginModule.m_hLoginHandle, stIn, stOut, 3000)) { | |||
| System.err.printf("RadiometryFetch Failed!" + ToolKits.getErrorCodePrint()); | |||
| } else { | |||
| nStatus = stOut.nStatus; | |||
| } | |||
| return nStatus; | |||
| } | |||
| /** | |||
| * 处理回调数据(热图) | |||
| * @throws IOException | |||
| */ | |||
| public static boolean saveData(NET_RADIOMETRY_DATA radiometryData) throws IOException { | |||
| if (radiometryData == null) { | |||
| return false; | |||
| } | |||
| int nWidth = radiometryData.stMetaData.nWidth; | |||
| int nHeight = radiometryData.stMetaData.nHeight; | |||
| short[] pGrayImg = new short[nWidth * nHeight]; | |||
| float[] pTempForPixels = new float[nWidth * nHeight]; | |||
| if(LoginModule.netsdk.CLIENT_RadiometryDataParse(radiometryData, pGrayImg, pTempForPixels)) { | |||
| byte[] pYData = new byte[nWidth*nHeight*2]; | |||
| imageAlgApi.drcTable(pGrayImg, (short)nWidth, (short)nHeight, 0, pYData, null); | |||
| ToolKits.savePicture(pYData, "./GrayscaleMap.yuv"); | |||
| } else { | |||
| System.err.println("saveData failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 取消订阅温度分布数据 | |||
| */ | |||
| public static void radiometryDetach() { | |||
| if(status.hRadiometryHandle.longValue() != 0) { | |||
| LoginModule.netsdk.CLIENT_RadiometryDetach(status.hRadiometryHandle); | |||
| status.hRadiometryHandle.setValue(0); | |||
| } | |||
| } | |||
| /** | |||
| * 查询测温点 | |||
| */ | |||
| public static NET_RADIOMETRYINFO queryPointTemper(int nChannel, short x, short y) { | |||
| int nQueryType = NetSDKLib.NET_QUERY_DEV_RADIOMETRY_POINT_TEMPER; | |||
| // 入参 | |||
| NET_IN_RADIOMETRY_GETPOINTTEMPER stIn = new NET_IN_RADIOMETRY_GETPOINTTEMPER(); | |||
| stIn.nChannel = nChannel; | |||
| stIn.stCoordinate.nx = x; | |||
| stIn.stCoordinate.ny = y; | |||
| // 出参 | |||
| NET_OUT_RADIOMETRY_GETPOINTTEMPER stOut = new NET_OUT_RADIOMETRY_GETPOINTTEMPER(); | |||
| stIn.write(); | |||
| stOut.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_QueryDevInfo(LoginModule.m_hLoginHandle, nQueryType, stIn.getPointer(), stOut.getPointer(), null, 3000); | |||
| if(!bRet) { | |||
| System.err.printf("QueryPointTemper Failed!" + ToolKits.getErrorCodePrint()); | |||
| return null; | |||
| } | |||
| stOut.read(); | |||
| return stOut.stPointTempInfo; | |||
| } | |||
| /** | |||
| * 查询测温项 | |||
| */ | |||
| public static NET_RADIOMETRYINFO queryItemTemper(int nChannel, int nPresetId, int nRuleId, int nMeterType) { | |||
| int nQueryType = NetSDKLib.NET_QUERY_DEV_RADIOMETRY_TEMPER; | |||
| // 入参 | |||
| NET_IN_RADIOMETRY_GETTEMPER stIn = new NET_IN_RADIOMETRY_GETTEMPER(); | |||
| stIn.stCondition.nPresetId = nPresetId; | |||
| stIn.stCondition.nRuleId = nRuleId; | |||
| stIn.stCondition.nMeterType = nMeterType; // eg: NET_RADIOMETRY_METERTYPE.NET_RADIOMETRY_METERTYPE_AREA; | |||
| stIn.stCondition.nChannel = nChannel; | |||
| // 出参 | |||
| NET_OUT_RADIOMETRY_GETTEMPER stOut = new NET_OUT_RADIOMETRY_GETTEMPER(); | |||
| stIn.write(); | |||
| stOut.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_QueryDevInfo(LoginModule.m_hLoginHandle, nQueryType, stIn.getPointer(), stOut.getPointer(), null, 3000); | |||
| if(!bRet) { | |||
| System.err.printf("QueryPointTemper Failed!" + ToolKits.getErrorCodePrint()); | |||
| return null; | |||
| } | |||
| stOut.read(); | |||
| return stOut.stTempInfo; | |||
| } | |||
| /** | |||
| * 开始查询信息 | |||
| */ | |||
| public static boolean startFind(NET_IN_RADIOMETRY_STARTFIND stuIn) { | |||
| if(status.bSearching) { | |||
| stopFind(); | |||
| } | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_RADIOMETRY_STARTFIND stuOut = new NET_OUT_RADIOMETRY_STARTFIND(); | |||
| stuIn.write(); | |||
| stuOut.write(); | |||
| status.bSearching = LoginModule.netsdk.CLIENT_StartFind(LoginModule.m_hLoginHandle, | |||
| NET_FIND.NET_FIND_RADIOMETRY, stuIn.getPointer(), stuOut.getPointer(), 5000); | |||
| if (status.bSearching) { | |||
| stuOut.read(); | |||
| status.nFinderHanle = stuOut.nFinderHanle; | |||
| status.nTotalCount = stuOut.nTotalCount; | |||
| }else { | |||
| System.err.printf("startFind Failed!" + ToolKits.getErrorCodePrint()); | |||
| } | |||
| return status.bSearching; | |||
| } | |||
| /** | |||
| * 获取查询总个数 | |||
| */ | |||
| public static int getTotalCount() { | |||
| return status.nTotalCount; | |||
| } | |||
| /** | |||
| * 查询信息 | |||
| */ | |||
| public static NET_OUT_RADIOMETRY_DOFIND doFind(int nOffset, int nCount) { | |||
| if(!status.bSearching) { | |||
| System.err.printf("DoFind Failed! [need startFind]"); | |||
| return null; | |||
| } | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_RADIOMETRY_DOFIND stuIn = new NET_IN_RADIOMETRY_DOFIND(); | |||
| stuIn.nFinderHanle = status.nFinderHanle; | |||
| stuIn.nBeginNumber = nOffset; | |||
| stuIn.nCount = nCount; | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_RADIOMETRY_DOFIND stuOut = new NET_OUT_RADIOMETRY_DOFIND(); | |||
| stuIn.write(); | |||
| stuOut.write(); | |||
| if (!LoginModule.netsdk.CLIENT_DoFind(LoginModule.m_hLoginHandle, | |||
| NET_FIND.NET_FIND_RADIOMETRY, stuIn.getPointer(), stuOut.getPointer(), 5000)) { | |||
| System.err.printf("DoFind Failed!" + ToolKits.getErrorCodePrint()); | |||
| return null; | |||
| } | |||
| stuOut.read(); | |||
| return stuOut; | |||
| } | |||
| /** | |||
| * 停止查询信息 | |||
| */ | |||
| public static void stopFind() { | |||
| if(!status.bSearching) { | |||
| return; | |||
| } | |||
| /* | |||
| * 入参 | |||
| */ | |||
| NET_IN_RADIOMETRY_STOPFIND stuIn = new NET_IN_RADIOMETRY_STOPFIND(); | |||
| stuIn.nFinderHanle = status.nFinderHanle; | |||
| /* | |||
| * 出参 | |||
| */ | |||
| NET_OUT_RADIOMETRY_STOPFIND stuOut = new NET_OUT_RADIOMETRY_STOPFIND(); | |||
| stuIn.write(); | |||
| stuOut.write(); | |||
| LoginModule.netsdk.CLIENT_StopFind(LoginModule.m_hLoginHandle, | |||
| NET_FIND.NET_FIND_RADIOMETRY, stuIn.getPointer(), stuOut.getPointer(), 5000); | |||
| status.bSearching = false; | |||
| status.nFinderHanle = 0; | |||
| // status.nTotalCount = 0; | |||
| return; | |||
| } | |||
| } | |||
| @@ -0,0 +1,106 @@ | |||
| package com.netsdk.demo.module; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.NetSDKLib.LLong; | |||
| import com.netsdk.lib.ToolKits; | |||
| /** | |||
| * 智能交通接口实现 | |||
| * 主要有 :智能订阅、开闸、关闸功能 | |||
| */ | |||
| public class TrafficEventModule { | |||
| // 智能订阅句柄 | |||
| public static LLong m_hAttachHandle = new LLong(0); | |||
| /** | |||
| * 新版本开闸 | |||
| */ | |||
| public static boolean New_OpenStrobe() { | |||
| NetSDKLib.NET_CTRL_OPEN_STROBE openStrobe = new NetSDKLib.NET_CTRL_OPEN_STROBE(); | |||
| openStrobe.nChannelId = 0; | |||
| String plate = new String("浙A888888"); | |||
| System.arraycopy(plate.getBytes(), 0, openStrobe.szPlateNumber, 0, plate.getBytes().length); | |||
| openStrobe.write(); | |||
| if (LoginModule.netsdk.CLIENT_ControlDeviceEx(LoginModule.m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_CTRL_OPEN_STROBE, openStrobe.getPointer(), null, 3000)) { | |||
| System.out.println("Open Success!"); | |||
| } else { | |||
| System.err.println("Failed to Open." + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| openStrobe.read(); | |||
| return true; | |||
| } | |||
| /** | |||
| * 新版本关闸 | |||
| */ | |||
| public static void New_CloseStrobe() { | |||
| NetSDKLib.NET_CTRL_CLOSE_STROBE closeStrobe = new NetSDKLib.NET_CTRL_CLOSE_STROBE(); | |||
| closeStrobe.nChannelId = 0; | |||
| closeStrobe.write(); | |||
| if (LoginModule.netsdk.CLIENT_ControlDeviceEx(LoginModule.m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_CTRL_CLOSE_STROBE, closeStrobe.getPointer(), null, 3000)) { | |||
| System.out.println("Close Success!"); | |||
| } else { | |||
| System.err.println("Failed to Close." + ToolKits.getErrorCodePrint()); | |||
| } | |||
| closeStrobe.read(); | |||
| } | |||
| /** | |||
| * 手动抓图按钮事件 | |||
| */ | |||
| public static boolean manualSnapPicture(int chn) { | |||
| NetSDKLib.MANUAL_SNAP_PARAMETER snapParam = new NetSDKLib.MANUAL_SNAP_PARAMETER(); | |||
| snapParam.nChannel = chn; | |||
| String sequence = "11111"; // 抓图序列号,必须用数组拷贝 | |||
| System.arraycopy(sequence.getBytes(), 0, snapParam.bySequence, 0, sequence.getBytes().length); | |||
| snapParam.write(); | |||
| boolean bRet = LoginModule.netsdk.CLIENT_ControlDeviceEx(LoginModule.m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_MANUAL_SNAP, snapParam.getPointer(), null, 5000); | |||
| if (!bRet) { | |||
| System.err.println("Failed to manual snap, last error " + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } else { | |||
| System.out.println("Seccessed to manual snap"); | |||
| } | |||
| snapParam.read(); | |||
| return true; | |||
| } | |||
| /** | |||
| * 订阅实时上传智能分析数据 | |||
| * @return | |||
| */ | |||
| public static boolean attachIVSEvent(int ChannelId, NetSDKLib.fAnalyzerDataCallBack m_AnalyzerDataCB) { | |||
| /** | |||
| * 说明: | |||
| * 通道数可以在有登录是返回的信息 m_stDeviceInfo.byChanNum 获取 | |||
| * 下列仅订阅了0通道的智能事件. | |||
| */ | |||
| int bNeedPicture = 1; // 是否需要图片 | |||
| m_hAttachHandle = LoginModule.netsdk.CLIENT_RealLoadPictureEx(LoginModule.m_hLoginHandle, ChannelId, NetSDKLib.EVENT_IVS_ALL, | |||
| bNeedPicture , m_AnalyzerDataCB , null , null); | |||
| if( m_hAttachHandle.longValue() != 0 ) { | |||
| System.out.println("CLIENT_RealLoadPictureEx Success ChannelId : \n" + ChannelId); | |||
| } else { | |||
| System.err.println("CLIENT_RealLoadPictureEx Failed!" + ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 停止上传智能分析数据-图片 | |||
| */ | |||
| public static void detachIVSEvent() { | |||
| if (0 != m_hAttachHandle.longValue()) { | |||
| LoginModule.netsdk.CLIENT_StopLoadPic(m_hAttachHandle); | |||
| System.out.println("Stop detach IVS event"); | |||
| m_hAttachHandle.setValue(0); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,128 @@ | |||
| package com.netsdk.demo.module; | |||
| import com.netsdk.lib.NetSDKLib; | |||
| import com.netsdk.lib.ToolKits; | |||
| import java.util.*; | |||
| /** | |||
| * @author : 47040 | |||
| * @since : Created in 2020/7/25 17:59 | |||
| */ | |||
| public class VideoStateSummaryModule { | |||
| public static Map<Integer, NetSDKLib.LLong> getM_hAttachMap() { | |||
| return m_hAttachMap; | |||
| } | |||
| // handle map | |||
| private static Map<Integer, NetSDKLib.LLong> m_hAttachMap = new HashMap<Integer, NetSDKLib.LLong>(); | |||
| // Attach 订阅 人数统计事件 | |||
| public static boolean attachVideoStatSummary(int channel, NetSDKLib.fVideoStatSumCallBack fVideoStatSumCallBack) { | |||
| if (!m_hAttachMap.containsKey(channel)) { | |||
| NetSDKLib.NET_IN_ATTACH_VIDEOSTAT_SUM inParam = new NetSDKLib.NET_IN_ATTACH_VIDEOSTAT_SUM(); | |||
| inParam.nChannel = channel; | |||
| inParam.cbVideoStatSum = fVideoStatSumCallBack; | |||
| NetSDKLib.NET_OUT_ATTACH_VIDEOSTAT_SUM outParam = new NetSDKLib.NET_OUT_ATTACH_VIDEOSTAT_SUM(); | |||
| NetSDKLib.LLong m_hAttachHandle = LoginModule.netsdk.CLIENT_AttachVideoStatSummary(LoginModule.m_hLoginHandle, inParam, outParam, 5000); | |||
| if (m_hAttachHandle.longValue() == 0) { | |||
| System.err.printf("Attach Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| m_hAttachMap.put(channel, m_hAttachHandle); | |||
| System.out.printf("Attach Succeed at Channel %d ! AttachHandle: %d. Wait Device Notify Information\n", channel, m_hAttachHandle.longValue()); | |||
| return true; | |||
| } else { // 非 0 说明正在订阅,先退订,再返回订阅失败 | |||
| System.err.print("Attach Handle is not Zero, Please Detach First.\n"); | |||
| return false; | |||
| } | |||
| } | |||
| // Check if Channel is Attached 是否订阅通道 | |||
| public static boolean channelAttached(int channel) { | |||
| return m_hAttachMap.containsKey(channel); | |||
| } | |||
| // Detach 退订 人数统计事件 | |||
| public static boolean detachVideoStatSummary(int channel) { | |||
| if (m_hAttachMap.containsKey(channel)) { | |||
| NetSDKLib.LLong m_hAttachHandle = m_hAttachMap.get(channel); | |||
| if (m_hAttachHandle.longValue() != 0) { | |||
| if (!LoginModule.netsdk.CLIENT_DetachVideoStatSummary(m_hAttachHandle)) { | |||
| System.err.printf("Detach Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| System.out.println("Channel " + channel + ". Handle: " + m_hAttachHandle.longValue() + ". Detach Succeed!"); | |||
| m_hAttachHandle.setValue(0); | |||
| m_hAttachMap.remove(channel); | |||
| return true; | |||
| } else { | |||
| System.err.print("Attach Handle is Zero, no Need for Detach.\n"); | |||
| return false; | |||
| } | |||
| } else { | |||
| System.err.print("Attach Handle not found.\n"); | |||
| return false; | |||
| } | |||
| } | |||
| // Detach All 退订 人数统计事件 | |||
| public static void detachAllVideoStatSummary() { | |||
| Set<Integer> keySet = m_hAttachMap.keySet(); | |||
| for (Iterator<Integer> iter = keySet.iterator(); iter.hasNext(); ) { | |||
| int channel = iter.next(); | |||
| NetSDKLib.LLong m_hAttachHandle = m_hAttachMap.get(channel); | |||
| if (!LoginModule.netsdk.CLIENT_DetachVideoStatSummary(m_hAttachHandle)) { | |||
| System.err.printf("Detach Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); | |||
| } | |||
| System.out.println("Channel " + channel + ". Handle: " + m_hAttachHandle.longValue() + ". Detach Succeed!"); | |||
| iter.remove(); | |||
| } | |||
| } | |||
| // reAttach 重订 人数统计事件 | |||
| public static void reAttachAllVideoStatSummary(NetSDKLib.fVideoStatSumCallBack fVideoStatSumCallBack) { | |||
| Set<Integer> keySet = m_hAttachMap.keySet(); | |||
| for (int channel : keySet) { | |||
| NetSDKLib.LLong m_hAttachHandle = m_hAttachMap.get(channel); | |||
| if (!LoginModule.netsdk.CLIENT_DetachVideoStatSummary(m_hAttachHandle)) { | |||
| System.err.printf("Detach Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); | |||
| } | |||
| System.out.println("Channel " + channel + ". Handle: " + m_hAttachHandle.longValue() + ". Detach Succeed!"); | |||
| NetSDKLib.NET_IN_ATTACH_VIDEOSTAT_SUM inParam = new NetSDKLib.NET_IN_ATTACH_VIDEOSTAT_SUM(); | |||
| inParam.nChannel = channel; | |||
| inParam.cbVideoStatSum = fVideoStatSumCallBack; | |||
| NetSDKLib.NET_OUT_ATTACH_VIDEOSTAT_SUM outParam = new NetSDKLib.NET_OUT_ATTACH_VIDEOSTAT_SUM(); | |||
| m_hAttachHandle = LoginModule.netsdk.CLIENT_AttachVideoStatSummary(LoginModule.m_hLoginHandle, inParam, outParam, 5000); | |||
| if (m_hAttachHandle.longValue() == 0) { | |||
| System.err.printf("Attach Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); | |||
| } | |||
| m_hAttachMap.put(channel, m_hAttachHandle); | |||
| System.out.printf("Attach Succeed at Channel %d ! AttachHandle: %d. Wait Device Notify Information\n", channel, m_hAttachHandle.longValue()); | |||
| } | |||
| } | |||
| // clear OSD info | |||
| public static boolean clearVideoStateSummary(int channel) { | |||
| NetSDKLib.NET_CTRL_CLEAR_SECTION_STAT_INFO info = new NetSDKLib.NET_CTRL_CLEAR_SECTION_STAT_INFO(); | |||
| info.nChannel = channel; | |||
| info.write(); | |||
| if (!LoginModule.netsdk.CLIENT_ControlDevice(LoginModule.m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_CTRL_CLEAR_SECTION_STAT, info.getPointer(), 5000)) { | |||
| System.err.printf("Clear Video State Summary Failed!LastError = %s\n", ToolKits.getErrorCodePrint()); | |||
| return false; | |||
| } | |||
| System.out.println("Clear Video State Summary Succeed!"); | |||
| return true; | |||
| } | |||
| } | |||
| @@ -0,0 +1,93 @@ | |||
| package com.netsdk.demo.util; | |||
| import java.lang.reflect.Method; | |||
| import java.util.NoSuchElementException; | |||
| import java.util.Scanner; | |||
| import java.util.Vector; | |||
| public class CaseMenu { | |||
| public static class Item { | |||
| private Object object; | |||
| private String itemName; | |||
| private String methodName; | |||
| public Item(Object object, String itemName, String methodName) { | |||
| super(); | |||
| this.object = object; | |||
| this.itemName = itemName; | |||
| this.methodName = methodName; | |||
| } | |||
| public Object getObject() { | |||
| return object; | |||
| } | |||
| public String getItemName() { | |||
| return itemName; | |||
| } | |||
| public String getMethodName() { | |||
| return methodName; | |||
| } | |||
| } | |||
| private Vector<Item> items; | |||
| public CaseMenu() { | |||
| super(); | |||
| items = new Vector<Item>(); | |||
| } | |||
| public void addItem(Item item) { | |||
| items.add(item); | |||
| } | |||
| private void showItem() { | |||
| final String format = "%2d\t%-20s\n"; | |||
| int index = 0; | |||
| System.out.printf(format, index++, "exit App"); | |||
| for (Item item : items) { | |||
| System.out.printf(format, index++, item.getItemName()); | |||
| } | |||
| System.out.println("Please input a item index to invoke the method:"); | |||
| } | |||
| public void run() { | |||
| Scanner scanner = new Scanner(System.in); | |||
| while(true) { | |||
| showItem(); | |||
| try { | |||
| int input = Integer.parseInt(scanner.nextLine()); | |||
| if (input <= 0 ) { | |||
| System.err.println("input <= 0 || scanner.nextLine() == null"); | |||
| // scanner.close(); | |||
| // System.exit(0); | |||
| break; | |||
| } | |||
| if (input < 0 || input > items.size()) { | |||
| System.err.println("Input Error Item Index."); | |||
| continue; | |||
| } | |||
| Item item = items.get(input - 1); | |||
| Class<?> itemClass = item.getObject().getClass(); | |||
| Method method = itemClass.getMethod(item.getMethodName()); | |||
| method.invoke(item.getObject()); | |||
| } catch (NoSuchElementException e) { | |||
| // scanner.close(); | |||
| // System.exit(0); | |||
| break; | |||
| } catch (NumberFormatException e) { | |||
| System.err.println("Input Error NumberFormat."); | |||
| continue; | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| scanner.close(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,124 @@ | |||
| package com.netsdk.lib; | |||
| import org.xml.sax.Attributes; | |||
| import org.xml.sax.SAXException; | |||
| import org.xml.sax.helpers.DefaultHandler; | |||
| import javax.xml.parsers.ParserConfigurationException; | |||
| import javax.xml.parsers.SAXParser; | |||
| import javax.xml.parsers.SAXParserFactory; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.util.*; | |||
| /** | |||
| * @author 47081 | |||
| * @version 1.0 | |||
| * @description | |||
| * @date 2021/3/10 | |||
| */ | |||
| public class DynamicParseUtil { | |||
| private DynamicLibParseHandler handler; | |||
| private SAXParserFactory saxParserFactory; | |||
| private SAXParser saxParser; | |||
| /** | |||
| * 适配各系统动态库名称大小写不同,以及lib前缀造成的找不到库的问题 | |||
| * | |||
| * @param currentSystem 当前系统:win64,win32,linux64,linux32,mac64 | |||
| * @param libName 动态库名称 | |||
| * @return | |||
| */ | |||
| public String compareLibName(String currentSystem, String libName) { | |||
| String dynamicLibName = libName; | |||
| List<String> libs = handler.getLibsBySystem(currentSystem); | |||
| if (currentSystem.toLowerCase().contains("win")) { | |||
| return findLibs(libs, libName); | |||
| } | |||
| if (libName.startsWith("lib")) { | |||
| dynamicLibName = libName.substring(3); | |||
| } | |||
| return findLibs(libs, dynamicLibName); | |||
| } | |||
| private String findLibs(List<String> libs, String libName) { | |||
| for (String lib : libs) { | |||
| if (libName.equalsIgnoreCase(lib)) { | |||
| return lib; | |||
| } | |||
| } | |||
| return ""; | |||
| } | |||
| public List<String> getLibsSystem(String system) { | |||
| return handler.getLibsBySystem(system); | |||
| } | |||
| private DynamicParseUtil() throws ParserConfigurationException { | |||
| // 获取SAX分析器的工厂实例,专门负责创建SAXParser分析器 | |||
| saxParserFactory = SAXParserFactory.newInstance(); | |||
| // 获取SAXParser分析器的实例 | |||
| try { | |||
| saxParser = saxParserFactory.newSAXParser(); | |||
| handler = new DynamicLibParseHandler(); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| public DynamicParseUtil(InputStream inputSteam) | |||
| throws ParserConfigurationException, IOException, SAXException { | |||
| this(); | |||
| saxParser.parse(inputSteam, handler); | |||
| } | |||
| /** xml解析handler */ | |||
| private class DynamicLibParseHandler extends DefaultHandler { | |||
| private HashMap<String, List<String>> dynamics = new HashMap<String, List<String>>(); | |||
| private List<String> systems = | |||
| Arrays.asList("win64", "win32", "linux64", "linux32", "mac64", "linuxARM"); | |||
| private String currentDynamicSystem; | |||
| private List<String> libs; | |||
| public List<String> getLibsBySystem(String system) { | |||
| return dynamics.get(system); | |||
| } | |||
| @Override | |||
| public void startDocument() throws SAXException { | |||
| super.startDocument(); | |||
| } | |||
| @Override | |||
| public void startElement(String uri, String localName, String qName, Attributes attributes) | |||
| throws SAXException { | |||
| super.startElement(uri, localName, qName, attributes); | |||
| if (systems.contains(qName)) { | |||
| currentDynamicSystem = qName; | |||
| if (libs == null) { | |||
| libs = new ArrayList<String>(); | |||
| } | |||
| } | |||
| } | |||
| @Override | |||
| public void endElement(String uri, String localName, String qName) throws SAXException { | |||
| super.endElement(uri, localName, qName); | |||
| if (systems.contains(qName)) { | |||
| // 保存到hashmap中 | |||
| dynamics.put(currentDynamicSystem, libs); | |||
| // 清除libs | |||
| libs = null; | |||
| } | |||
| } | |||
| @Override | |||
| public void characters(char[] ch, int start, int length) throws SAXException { | |||
| super.characters(ch, start, length); | |||
| String lib = new String(ch, start, length); | |||
| if (!lib.trim().isEmpty()) { | |||
| libs.add(lib); | |||
| } | |||
| } | |||
| } | |||
| } | |||