提交 | 用户 | 时间
|
ce910c
|
1 |
package com.netsdk.demo.frame.TargetRecognition; |
H |
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.Dimension; |
|
5 |
import java.awt.GridLayout; |
|
6 |
import java.awt.event.ActionEvent; |
|
7 |
import java.awt.event.ActionListener; |
|
8 |
import java.awt.event.WindowAdapter; |
|
9 |
import java.awt.event.WindowEvent; |
|
10 |
import java.io.UnsupportedEncodingException; |
|
11 |
|
|
12 |
import javax.swing.JButton; |
|
13 |
import javax.swing.JDialog; |
|
14 |
import javax.swing.JLabel; |
|
15 |
import javax.swing.JOptionPane; |
|
16 |
import javax.swing.JPanel; |
|
17 |
import javax.swing.JScrollPane; |
|
18 |
import javax.swing.JTable; |
|
19 |
import javax.swing.ListSelectionModel; |
|
20 |
import javax.swing.table.DefaultTableCellRenderer; |
|
21 |
import javax.swing.table.DefaultTableModel; |
|
22 |
|
|
23 |
import com.netsdk.common.BorderEx; |
|
24 |
import com.netsdk.common.Res; |
|
25 |
import com.netsdk.demo.module.TargetRecognitionModule; |
|
26 |
import com.netsdk.lib.NetSDKLib.*; |
|
27 |
import com.netsdk.lib.ToolKits; |
|
28 |
|
|
29 |
public class GroupOperateDialog extends JDialog{ |
|
30 |
|
|
31 |
/** |
|
32 |
* |
|
33 |
*/ |
|
34 |
private static final long serialVersionUID = 1L; |
|
35 |
|
|
36 |
// 人脸库名称 |
|
37 |
private String inputGroupName = ""; |
|
38 |
|
|
39 |
// 布控界面 |
|
40 |
public DispositionOperateDialog dispositionOperateDialog = null; |
|
41 |
|
|
42 |
// 人员操作界面 |
|
43 |
public PersonOperateDialog personOperateDialog = null; |
|
44 |
|
|
45 |
public GroupOperateDialog() { |
|
46 |
setTitle(Res.string().getGroupOperate()); |
|
47 |
setLayout(new BorderLayout()); |
|
48 |
setModal(true); |
|
49 |
pack(); |
|
50 |
setSize(650, 360); |
|
51 |
setResizable(false); |
|
52 |
setLocationRelativeTo(null); |
|
53 |
setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 |
|
54 |
|
|
55 |
GroupListPanel GroupPanel = new GroupListPanel(); |
|
56 |
GroupOperatePanel GroupOperatePanel = new GroupOperatePanel(); |
|
57 |
|
|
58 |
add(GroupPanel, BorderLayout.CENTER); |
|
59 |
add(GroupOperatePanel, BorderLayout.EAST); |
|
60 |
|
|
61 |
findGroupInfo(); |
|
62 |
|
|
63 |
addWindowListener(new WindowAdapter() { |
|
64 |
public void windowClosing(WindowEvent e) { |
|
65 |
dispose(); |
|
66 |
} |
|
67 |
}); |
|
68 |
} |
|
69 |
|
|
70 |
/* |
|
71 |
* 人脸库显示列表 |
|
72 |
*/ |
|
73 |
private class GroupListPanel extends JPanel { |
|
74 |
private static final long serialVersionUID = 1L; |
|
75 |
public GroupListPanel() { |
|
76 |
BorderEx.set(this, "", 2); |
|
77 |
setLayout(new BorderLayout()); |
|
78 |
|
|
79 |
data = new Object[20][3]; |
|
80 |
defaultTableModel = new DefaultTableModel(data, Res.string().getGroupTable()); |
|
81 |
table = new JTable(defaultTableModel) { // 列表不可编辑 |
|
82 |
private static final long serialVersionUID = 1L; |
|
83 |
@Override |
|
84 |
public boolean isCellEditable(int row, int column) { |
|
85 |
return false; |
|
86 |
} |
|
87 |
}; |
|
88 |
|
|
89 |
table.getColumnModel().getColumn(0).setPreferredWidth(80); |
|
90 |
table.getColumnModel().getColumn(1).setPreferredWidth(280); |
|
91 |
table.getColumnModel().getColumn(2).setPreferredWidth(100); |
|
92 |
|
|
93 |
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 只能选中一行 |
|
94 |
|
|
95 |
DefaultTableCellRenderer dCellRenderer = new DefaultTableCellRenderer(); |
|
96 |
dCellRenderer.setHorizontalAlignment(JLabel.CENTER); |
|
97 |
table.setDefaultRenderer(Object.class, dCellRenderer); |
|
98 |
|
|
99 |
add(new JScrollPane(table), BorderLayout.CENTER); |
|
100 |
|
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
/* |
|
105 |
* 人脸库操作 |
|
106 |
*/ |
|
107 |
private class GroupOperatePanel extends JPanel { |
|
108 |
/** |
|
109 |
* |
|
110 |
*/ |
|
111 |
private static final long serialVersionUID = 1L; |
|
112 |
public GroupOperatePanel() { |
|
113 |
BorderEx.set(this, "", 2); |
|
114 |
setLayout(new BorderLayout()); |
|
115 |
|
|
116 |
Dimension dimension = new Dimension(); |
|
117 |
dimension.width = 230; |
|
118 |
setPreferredSize(dimension); |
|
119 |
|
|
120 |
JPanel GroupPanel = new JPanel(); |
|
121 |
JPanel panel = new JPanel(); |
|
122 |
|
|
123 |
add(GroupPanel, BorderLayout.CENTER); |
|
124 |
add(panel, BorderLayout.SOUTH); |
|
125 |
|
|
126 |
/*JButton searchByPicBtn = new JButton(Res.string().getSearchByPic());*/ |
|
127 |
JButton personOperateBtn = new JButton(Res.string().getPersonOperate()); |
|
128 |
panel.setPreferredSize(new Dimension(230, 45)); |
|
129 |
panel.setLayout(new GridLayout(2, 1)); |
|
130 |
/*panel.add(searchByPicBtn);*/ |
|
131 |
panel.add(personOperateBtn); |
|
132 |
|
|
133 |
/* |
|
134 |
* 人脸库增删改, 布控、撤控 |
|
135 |
*/ |
|
136 |
JButton refreshBtn = new JButton(Res.string().getFresh()); |
|
137 |
JButton addGroupBtn = new JButton(Res.string().getAddGroup()); |
|
138 |
JButton modifyGroupBtn = new JButton(Res.string().getModifyGroup()); |
|
139 |
JButton deleteGroupBtn = new JButton(Res.string().getDelGroup()); |
|
140 |
JButton dispositionBtn = new JButton(Res.string().getDisposition() + "/" + Res.string().getDelDisposition()); |
|
141 |
|
|
142 |
GroupPanel.setLayout(new GridLayout(12, 1)); |
|
143 |
GroupPanel.add(refreshBtn); |
|
144 |
GroupPanel.add(addGroupBtn); |
|
145 |
GroupPanel.add(modifyGroupBtn); |
|
146 |
GroupPanel.add(deleteGroupBtn); |
|
147 |
GroupPanel.add(dispositionBtn); |
|
148 |
|
|
149 |
// 刷新人脸库列表 |
|
150 |
refreshBtn.addActionListener(new ActionListener() { |
|
151 |
@Override |
|
152 |
public void actionPerformed(ActionEvent arg0) { |
|
153 |
findGroupInfo(); |
|
154 |
} |
|
155 |
}); |
|
156 |
|
|
157 |
// 添加人脸库 |
|
158 |
addGroupBtn.addActionListener(new ActionListener() { |
|
159 |
|
|
160 |
@Override |
|
161 |
public void actionPerformed(ActionEvent arg0) { |
|
162 |
inputGroupName = JOptionPane.showInputDialog(GroupOperateDialog.this, |
|
163 |
Res.string().getInputGroupName(), ""); |
|
164 |
|
|
165 |
if(inputGroupName == null) { // 取消或者关闭按钮 |
|
166 |
return; |
|
167 |
} |
|
168 |
|
|
169 |
if(TargetRecognitionModule.addGroup(inputGroupName)) { |
|
170 |
JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); |
|
171 |
} else { |
|
172 |
JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
173 |
} |
|
174 |
|
|
175 |
// 更新人脸库列表 |
|
176 |
findGroupInfo(); |
|
177 |
} |
|
178 |
}); |
|
179 |
|
|
180 |
// 修改人脸库 |
|
181 |
modifyGroupBtn.addActionListener(new ActionListener() { |
|
182 |
|
|
183 |
@Override |
|
184 |
public void actionPerformed(ActionEvent arg0) { |
|
185 |
int row = -1; |
|
186 |
row = table.getSelectedRow(); //获得所选的单行 |
|
187 |
|
|
188 |
if(row < 0) { |
|
189 |
JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
190 |
return; |
|
191 |
} |
|
192 |
|
|
193 |
if(defaultTableModel.getValueAt(row, 0) == null || String.valueOf(defaultTableModel.getValueAt(row, 0)).trim().equals("")) { |
|
194 |
JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
195 |
return; |
|
196 |
} |
|
197 |
|
|
198 |
inputGroupName = JOptionPane.showInputDialog(GroupOperateDialog.this, |
|
199 |
Res.string().getInputGroupName(), String.valueOf(defaultTableModel.getValueAt(row, 1)).trim()); |
|
200 |
|
|
201 |
if(inputGroupName == null) { // 取消或者关闭按钮 |
|
202 |
return; |
|
203 |
} |
|
204 |
|
|
205 |
if(TargetRecognitionModule.modifyGroup(inputGroupName, String.valueOf(defaultTableModel.getValueAt(row, 0)).trim())) { |
|
206 |
JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); |
|
207 |
} else { |
|
208 |
JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
209 |
} |
|
210 |
|
|
211 |
// 更新人脸库列表 |
|
212 |
findGroupInfo(); |
|
213 |
} |
|
214 |
}); |
|
215 |
|
|
216 |
// 删除人脸库 |
|
217 |
deleteGroupBtn.addActionListener(new ActionListener() { |
|
218 |
|
|
219 |
@Override |
|
220 |
public void actionPerformed(ActionEvent arg0) { |
|
221 |
int row = -1; |
|
222 |
row = table.getSelectedRow(); //获得所选的单行 |
|
223 |
|
|
224 |
if(row < 0) { |
|
225 |
JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
226 |
return; |
|
227 |
} |
|
228 |
|
|
229 |
if(defaultTableModel.getValueAt(row, 0) == null || String.valueOf(defaultTableModel.getValueAt(row, 0)).trim().equals("")) { |
|
230 |
JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
231 |
return; |
|
232 |
} |
|
233 |
|
|
234 |
if(!TargetRecognitionModule.deleteGroup(String.valueOf(defaultTableModel.getValueAt(row, 0)).trim())) { |
|
235 |
JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
236 |
} else { |
|
237 |
JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); |
|
238 |
} |
|
239 |
|
|
240 |
// 更新人脸库列表 |
|
241 |
findGroupInfo(); |
|
242 |
} |
|
243 |
}); |
|
244 |
|
|
245 |
// 布控/撤控 |
|
246 |
dispositionBtn.addActionListener(new ActionListener() { |
|
247 |
|
|
248 |
@Override |
|
249 |
public void actionPerformed(ActionEvent arg0) { |
|
250 |
int row = -1; |
|
251 |
row = table.getSelectedRow(); //获得所选的单行 |
|
252 |
|
|
253 |
if(row < 0) { |
|
254 |
JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
255 |
return; |
|
256 |
} |
|
257 |
|
|
258 |
if(defaultTableModel.getValueAt(row, 0) == null || String.valueOf(defaultTableModel.getValueAt(row, 0)).trim().equals("")) { |
|
259 |
JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
260 |
return; |
|
261 |
} |
|
262 |
|
|
263 |
dispositionOperateDialog = new DispositionOperateDialog(String.valueOf(defaultTableModel.getValueAt(row, 0)).trim(), |
|
264 |
String.valueOf(defaultTableModel.getValueAt(row, 1)).trim()); |
|
265 |
dispositionOperateDialog.setVisible(true); |
|
266 |
|
|
267 |
} |
|
268 |
}); |
|
269 |
|
|
270 |
/*// 以图搜图 |
|
271 |
searchByPicBtn.addActionListener(new ActionListener() { |
|
272 |
@Override |
|
273 |
public void actionPerformed(ActionEvent arg0) { |
|
274 |
SearchByPicDialog dialog = new SearchByPicDialog(); |
|
275 |
dialog.setVisible(true); |
|
276 |
} |
|
277 |
});*/ |
|
278 |
|
|
279 |
// 人员操作 |
|
280 |
personOperateBtn.addActionListener(new ActionListener() { |
|
281 |
|
|
282 |
@Override |
|
283 |
public void actionPerformed(ActionEvent arg0) { |
|
284 |
int row = -1; |
|
285 |
row = table.getSelectedRow(); //获得所选的单行 |
|
286 |
|
|
287 |
if(row < 0) { |
|
288 |
JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
289 |
return; |
|
290 |
} |
|
291 |
|
|
292 |
if(defaultTableModel.getValueAt(row, 0) == null || String.valueOf(defaultTableModel.getValueAt(row, 0)).trim().equals("")) { |
|
293 |
JOptionPane.showMessageDialog(null, Res.string().getSelectGroup(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
294 |
return; |
|
295 |
} |
|
296 |
|
|
297 |
personOperateDialog = new PersonOperateDialog(String.valueOf(defaultTableModel.getValueAt(row, 0)).trim(), |
|
298 |
String.valueOf(defaultTableModel.getValueAt(row, 1)).trim()); |
|
299 |
personOperateDialog.setVisible(true); |
|
300 |
} |
|
301 |
}); |
|
302 |
} |
|
303 |
} |
|
304 |
|
|
305 |
/* |
|
306 |
* 查找所有人脸库 |
|
307 |
*/ |
|
308 |
private void findGroupInfo() { |
|
309 |
// 清空列表 |
|
310 |
for(int i = 0; i < 20; i++) { |
|
311 |
for(int j = 0; j < 3; j++) { |
|
312 |
defaultTableModel.setValueAt("", i, j); |
|
313 |
} |
|
314 |
} |
|
315 |
|
|
316 |
// 查询人脸库 |
|
317 |
NET_FACERECONGNITION_GROUP_INFO[] groupInfoArr = TargetRecognitionModule.findGroupInfo(""); |
|
318 |
if(groupInfoArr != null) { |
|
319 |
for(int i = 0; i < groupInfoArr.length; i++) { |
|
320 |
defaultTableModel.setValueAt(new String(groupInfoArr[i].szGroupId).trim(), i, 0); |
|
321 |
try { |
|
322 |
defaultTableModel.setValueAt(new String(groupInfoArr[i].szGroupName, "GBK").trim(), i, 1); |
|
323 |
} catch (UnsupportedEncodingException e1) { |
|
324 |
e1.printStackTrace(); |
|
325 |
} |
|
326 |
defaultTableModel.setValueAt(String.valueOf(groupInfoArr[i].nGroupSize).trim(), i, 2); |
|
327 |
} |
|
328 |
} |
|
329 |
} |
|
330 |
|
|
331 |
private Object[][] data; |
|
332 |
private DefaultTableModel defaultTableModel; |
|
333 |
private JTable table; |
|
334 |
} |