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 list_model_battgroup; private JList list_battgroup_name; private DefaultListModel list_model_testfile; private JList list_testfile_name; private JTable table_ntm_data; private Vector tb_columnVector = new Vector(); private Vector> tb_dataRow = new Vector>(); 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(); list_model_testfile = new DefaultListModel(); 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(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(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 al_fbo_data = new ArrayList(); 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(); 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>(); for(int n=0; n row = new Vector(); 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= Comm_NTM.mDatablockCnt) { if(null == parseOpenDir) { parseOpenDir = new JFileChooser(); parseOpenDir.setSelectedFile(new File("ntm.FBO")); } openAndShowFboData(parseOpenDir.getSelectedFile().getAbsolutePath(), Comm_NTM.getSelectFilePathName()); } } } }