DELL
2025-04-28 e6eb7fb0af366e370f125668d62e89eb0004f517
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
package com.dev.ntm;
 
import javax.swing.JPanel;
 
import java.awt.GridLayout;
 
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
 
import com.dev.ntm.cmd.NTM_Cmd;
import com.dev.ntm.data.fbo.FboData;
import com.dev.ntm.data.fbo.FboDataInf;
 
import java.awt.BorderLayout;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Vector;
 
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.filechooser.FileFilter;
import javax.swing.JProgressBar;
 
public class ntm_page_datamanage extends JPanel {
    private SPCommNTM Comm_NTM = null;
    private ntm_page_datamanage_chart panel_fboDataChart;
    private DefaultListModel<String> list_model_battgroup;
    private JList<String> list_battgroup_name;
    private DefaultListModel<String> list_model_testfile;
    private JList<String> list_testfile_name;
    private JTable table_ntm_data;
    private Vector<String> tb_columnVector = new Vector<String>();
    private Vector<Vector<String>> tb_dataRow = new Vector<Vector<String>>();
    
    private JButton btn_getfilename;
    private JProgressBar pgb_getfile;
    private JPanel panel_filelist;
    private JFileChooser parseOpenDir;
    private JFileChooser parseSaveDir;
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
 
    /**
     * Create the panel.
     */
    public ntm_page_datamanage() {
        setLayout(new BorderLayout(0, 0));
        
        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        add(tabbedPane);
        
        JPanel panel_datatable = new JPanel();
        panel_datatable.setLayout(new BorderLayout(0, 0));
        
        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        panel_datatable.add(scrollPane);
        
        table_ntm_data = new JTable();
        table_ntm_data.setColumnSelectionAllowed(true);
        table_ntm_data.setShowVerticalLines(false);
        table_ntm_data.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// ÉèÖÃtableÄÚÈݾÓÖÐ
        tcr.setHorizontalAlignment(JLabel.CENTER);
        table_ntm_data.setDefaultRenderer(Object.class, tcr);
        MouseAdapter m_a = new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                if(e.getSource() != table_ntm_data) {
                    return;
                }
            }
            public void mousePressed(MouseEvent evt) {
                if (evt.getButton() == MouseEvent.BUTTON3) {
                    JPopupMenu popupMenu = new JPopupMenu();
                        JMenuItem tableItem_export_data = null;
                    
                    tableItem_export_data = new JMenuItem("¸´ÖƵ½¼ôÌù°å");
                    tableItem_export_data.addActionListener(new ActionListener(){
                        @Override
                        public void actionPerformed(ActionEvent arg0) {
                            Clipboard clipboard = getToolkit().getSystemClipboard();
                            String temp = "";
                            for(int c=0; c<tb_columnVector.size(); c++)
                            {
                                temp += tb_columnVector.get(c) + "\t";
                            }
                            temp += "\n";
                            for(int r=0; r<tb_dataRow.size(); r++)
                            {
                                for(int c=0; c<tb_columnVector.size(); c++)
                                {
                                    temp += tb_dataRow.get(r).get(c) + "\t";
                                }
                                temp += "\n";
                            }
                            StringSelection text = new StringSelection(temp);
                            clipboard.setContents(text, null);
                        }
                    });
                    popupMenu.add(tableItem_export_data);
                    popupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
                  }
            }
        };
        
        table_ntm_data.addMouseListener(m_a);
        scrollPane.setViewportView(table_ntm_data);
        
        list_model_battgroup = new DefaultListModel<String>();
        
        list_model_testfile = new DefaultListModel<String>();
        
        panel_filelist = new JPanel();
        add(panel_filelist, BorderLayout.WEST);
        panel_filelist.setLayout(new BorderLayout(0, 0));
        
        panel_fboDataChart = new ntm_page_datamanage_chart(panel_filelist);
        tabbedPane.addTab("\u76F4\u89C2\u56FE\u5F62", null, panel_fboDataChart, null);
        tabbedPane.addTab("\u6570\u636E\u8868\u683C", null, panel_datatable, null);
        JPanel panel_7 = new JPanel();
        panel_filelist.add(panel_7, BorderLayout.NORTH);
        
        JButton btnNewButton = new JButton("\u83B7\u53D6\u7535\u6C60\u7EC4");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(null == Comm_NTM) {
                    return;
                }
                list_model_battgroup.clear();
                list_model_testfile.clear();
                pgb_getfile.setValue(0);
                ByteBuffer bf1 = ByteBuffer.allocate(2);
                bf1.put((byte) (0));
                bf1.put((byte) (0));
                bf1.position(0);
                Comm_NTM.setCommCmd(NTM_Cmd.CMD_GetBattGroupNames, bf1, null);
            }
        });
        panel_7.setLayout(new GridLayout(0, 3, 0, 0));
        panel_7.add(btnNewButton);
        
        btn_getfilename = new JButton("\u83B7\u53D6\u6587\u4EF6\u540D");
        btn_getfilename.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(null == Comm_NTM) {
                    return;
                }
                
                int batt_index = list_battgroup_name.getSelectedIndex();
                if(batt_index < 0) {
                    JOptionPane.showMessageDialog(null, "ÇëÏÈÑ¡Ôñµç³Ø×é!");
                    return;
                }
                
                pgb_getfile.setValue(0);
                ByteBuffer bf1 = ByteBuffer.allocate(4);
                Comm_NTM.mSetBattGroupNameindex = batt_index;
                bf1.put((byte) (Comm_NTM.mSetBattGroupNameindex/256));
                bf1.put((byte) (Comm_NTM.mSetBattGroupNameindex%256));
                bf1.put((byte) (0));
                bf1.put((byte) (0));
                bf1.position(0);
                Comm_NTM.setCommCmd(NTM_Cmd.CMD_GetTestFileNames, bf1, null);
            }
        });
        panel_7.add(btn_getfilename);
        
        JButton btnNewButton_2 = new JButton("\u8BFB\u53D6\u6570\u636E");
        btnNewButton_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                if(null == Comm_NTM) {
                    return;
                }
                if(list_model_battgroup.getSize() < 1) {
                    return;
                }
                
                int batt_index = list_battgroup_name.getSelectedIndex();
                if(batt_index < 0) {
                    JOptionPane.showMessageDialog(null, "ÇëÏÈÑ¡Ôñµç³Ø×éÃû!");
                    return;
                }
                
                int file_index = list_testfile_name.getSelectedIndex();
                if(file_index < 0) {
                    JOptionPane.showMessageDialog(null, "ÇëÏÈÑ¡ÔñÊý¾ÝÎļþÃû!");
                    return;
                }
                String filepath = list_battgroup_name.getSelectedValue() + "/" 
                                    + list_testfile_name.getSelectedValue();
                Comm_NTM.setSelectFilePathName(filepath);
                
                pgb_getfile.setValue(0);
                ByteBuffer bf1 = ByteBuffer.allocate(2);
                bf1.put((byte) (0));
                bf1.put((byte) (0));
                bf1.position(0);
                
                ByteBuffer bf2 = null;
                try {
                    bf2 = ByteBuffer.wrap(filepath.getBytes("utf-8"));
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                bf2.position(0);
                Comm_NTM.setCommCmd(NTM_Cmd.CMD_GetTestFile, bf1, bf2);
            }
        });
        panel_7.add(btnNewButton_2);
        
        JButton btnNewButton_1 = new JButton("\u6253\u5F00\u6587\u4EF6");
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                if(null == parseOpenDir) {
                    parseOpenDir = new JFileChooser();
                }
                
                parseOpenDir.setFileSelectionMode(JFileChooser.FILES_ONLY);
                 parseOpenDir.setFileFilter(new FileFilter() {
                     @Override
                     public boolean accept(File f) {
                         if (f.isDirectory())
                             return true;
                         
                         return f.getName().toUpperCase().endsWith(".FBO");
                     }
                     
                     @Override
                     public String getDescription() {
                         return "*.FBO";
                     }
                 });
                 parseOpenDir.setDialogTitle("´ò¿ªÎļþ");
                 if(JFileChooser.APPROVE_OPTION == parseOpenDir.showOpenDialog(null)) {
                     openAndShowFboData(parseOpenDir.getSelectedFile().getAbsolutePath(),
                                         parseOpenDir.getSelectedFile().getAbsolutePath());
                 }
            }
        });
        panel_7.add(btnNewButton_1);
        
        JButton btnNewButton_3 = new JButton("\u53E6\u5B58\u4E3A");
        btnNewButton_3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(null == parseOpenDir) {
                    JOptionPane.showMessageDialog(null, "No FBO file is opened, please open FBO file first!");
                    return;
                }
                String src_file = parseOpenDir.getSelectedFile().getAbsolutePath();
                if(false == src_file.toUpperCase().endsWith("FBO")) {
                    JOptionPane.showMessageDialog(null, "No FBO file is open, please open FBO file first!");
                    return;
                }
                
                if(null == parseSaveDir) {
                    parseSaveDir = new JFileChooser();
                }
                parseSaveDir.setFileFilter(new FileFilter() {
                     @Override
                     public boolean accept(File f) {
                         if (f.isDirectory())
                             return true;
                         
                         return f.getName().toUpperCase().endsWith(".FBO");
                     }
                     
                     @Override
                     public String getDescription() {
                         return "*.FBO";
                     }
                 });
                
                parseSaveDir.setDialogTitle("±£´æÎļþ");
                 if(JFileChooser.APPROVE_OPTION == parseSaveDir.showSaveDialog(null)) {
                     File file = parseSaveDir.getSelectedFile();
                     if (false == file.getPath().toUpperCase().endsWith(".FBO")) {
                         file = new File(file.getPath()+".FBO");
                     }
                     if(file.exists()) {
                         JOptionPane.showMessageDialog(null, file.getAbsolutePath() + " is already exist!");
                        return;
                     }
                     try {
                        Files.copy(parseOpenDir.getSelectedFile().toPath(), file.toPath());
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                 }
            }
        });
        panel_7.add(btnNewButton_3);
        
        JPanel panel_8 = new JPanel();
        panel_filelist.add(panel_8, BorderLayout.CENTER);
        panel_8.setLayout(new GridLayout(0, 1, 0, 0));
        
        JScrollPane scrollPane_1 = new JScrollPane();
        panel_8.add(scrollPane_1);
        scrollPane_1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        list_battgroup_name = new JList<String>(list_model_battgroup);
        list_battgroup_name.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent arg0) {
                if(list_battgroup_name.getSelectedIndex() < 0) {
                    return;
                }
                btn_getfilename.doClick();
            }
        });
        scrollPane_1.setViewportView(list_battgroup_name);
        
        JLabel lblNewLabel = new JLabel("\u7535\u6C60\u7EC4\u540D\u79F0");
        lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
        scrollPane_1.setColumnHeaderView(lblNewLabel);
        
        JScrollPane scrollPane_2 = new JScrollPane();
        scrollPane_2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        panel_8.add(scrollPane_2);
        list_testfile_name = new JList<String>(list_model_testfile);
        scrollPane_2.setViewportView(list_testfile_name);
        
        JLabel lblNewLabel_1 = new JLabel("\u5145\u653E\u7535\u6570\u636E");
        lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
        scrollPane_2.setColumnHeaderView(lblNewLabel_1);
        
        pgb_getfile = new JProgressBar();
        pgb_getfile.setStringPainted(true);
        panel_filelist.add(pgb_getfile, BorderLayout.SOUTH);
 
    }
    
    public void setComm_NTM(SPCommNTM sz) {
        Comm_NTM = sz;
    }
    
    public void openAndShowFboData(String file_name, String file_addr_name) {
        File f = new File(file_name);
        FboDataInf data_inf = new FboDataInf();
        ArrayList<FboData> al_fbo_data = new ArrayList<FboData>();
        FboData.checkFboFile(f, data_inf, al_fbo_data);
        panel_fboDataChart.putAndShowFBOData(file_addr_name, data_inf, al_fbo_data);
        
        tb_columnVector.clear();
        tb_columnVector = new Vector<String>();
        tb_columnVector.add("±àºÅ");
        tb_columnVector.add("²âÊÔʱ¼ä(H:M:S)");
        tb_columnVector.add("ÔÚÏßµçѹ(V)");
        tb_columnVector.add("×é¶Ëµçѹ(V)");
        tb_columnVector.add("²âÊÔµçÁ÷(A)");
        tb_columnVector.add("ÒѲâÈÝÁ¿(AH)");
        for(int n=0; n<data_inf.BattSum; n++) {
            tb_columnVector.add("#" + (n+1));
        }
        
        tb_dataRow.clear();
        tb_dataRow = new Vector<Vector<String>>();
        for(int n=0; n<al_fbo_data.size(); n++) {
            FboData fd = al_fbo_data.get(n);
            Vector<String> row = new Vector<String>();
            row.addElement(String.format("%d", n+1));
            row.addElement(String.format("%02d:%02d:%02d", fd.m_TestTime.hour,
                                            fd.m_TestTime.minute,fd.m_TestTime.second));
            row.addElement(String.format("%1.1f", fd.OnlineVol));
            row.addElement(String.format("%1.1f", fd.SumVoltage));
            row.addElement(String.format("%1.1f", fd.SumCurrent));
            row.addElement(String.format("%1.1f", fd.AllCap));
            for(int id=0; id<fd.BattSum; id++) {
                row.addElement(String.format("%1.3f", fd.SingleVol[id]));
            }
            tb_dataRow.add(row);
        }
        
        table_ntm_data.setModel(new DefaultTableModel(tb_dataRow, tb_columnVector));
        table_ntm_data.updateUI();
    }
    
    public void updateData() {
        if(null == Comm_NTM) {
            return;
        }
        
        if(NTM_Cmd.CMD_GetBattGroupNames == Comm_NTM.dt_cmd_ack) {
            Comm_NTM.setCommCmdAck(NTM_Cmd.CMD_NULL);
            
            list_model_battgroup.clear();
            for(int n=0; n<Comm_NTM.mBattGroupNames.size(); n++) {
                list_model_battgroup.addElement(Comm_NTM.mBattGroupNames.get(n));
            }
            pgb_getfile.setMinimum(0);
            pgb_getfile.setMaximum(Comm_NTM.mBattGroupNameCnt);
            pgb_getfile.setValue(Comm_NTM.mReadBattGroupNameindex);
            pgb_getfile.setString("»ñÈ¡µç³Ø×éÃû: " + Comm_NTM.mReadBattGroupNameindex + "/" + Comm_NTM.mBattGroupNameCnt);
        } else if (NTM_Cmd.CMD_GetTestFileNames == Comm_NTM.dt_cmd_ack) {
            Comm_NTM.setCommCmdAck(NTM_Cmd.CMD_NULL);
            
            list_model_testfile.clear();
            for(int n=0; n<Comm_NTM.mTestFiles.size(); n++) {
                list_model_testfile.addElement(Comm_NTM.mTestFiles.get(n));
            }
            
            pgb_getfile.setMinimum(0);
            pgb_getfile.setMaximum(Comm_NTM.mTestFileCnt);
            pgb_getfile.setValue(Comm_NTM.mReadTestFileindex);
            pgb_getfile.setString("»ñÈ¡ÎļþÃû: " + Comm_NTM.mReadTestFileindex + "/" + Comm_NTM.mTestFileCnt);
        } else if (NTM_Cmd.CMD_GetTestFile == Comm_NTM.dt_cmd_ack) {
            Comm_NTM.setCommCmdAck(NTM_Cmd.CMD_NULL);
            
            pgb_getfile.setMinimum(0);
            pgb_getfile.setMaximum(Comm_NTM.mDatablockCnt);
            pgb_getfile.setValue(Comm_NTM.mDatablockIndex);
            pgb_getfile.setString("»ñÈ¡Êý¾Ý: " + Comm_NTM.mDatablockIndex + "/" + Comm_NTM.mDatablockCnt);
            
            if(Comm_NTM.mDatablockIndex >= Comm_NTM.mDatablockCnt) {
                if(null == parseOpenDir) {
                    parseOpenDir = new JFileChooser();
                    parseOpenDir.setSelectedFile(new File("ntm.FBO"));
                }
                openAndShowFboData(parseOpenDir.getSelectedFile().getAbsolutePath(), 
                                    Comm_NTM.getSelectFilePathName());
            }
        }
    }
}