潘志宝
5 天以前 6d75723f3e3bd43895db2470bc5fabb2314dbe8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
package com.iailab.netsdk.demo.frame.TargetRecognition;
 
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.iailab.netsdk.common.BorderEx;
import com.iailab.netsdk.common.Res;
import com.iailab.netsdk.demo.module.TargetRecognitionModule;
import com.iailab.netsdk.lib.NetSDKLib.*;
import com.iailab.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(TargetRecognitionModule.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(TargetRecognitionModule.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(!TargetRecognitionModule.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 = TargetRecognitionModule.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;
}