package com.dev.fbs9600_zdhj;
|
|
import java.awt.BorderLayout;
|
import java.awt.GridLayout;
|
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.util.Date;
|
import java.util.Vector;
|
|
import javax.swing.BoxLayout;
|
import javax.swing.JButton;
|
import javax.swing.JFileChooser;
|
import javax.swing.JMenuItem;
|
import javax.swing.JOptionPane;
|
import javax.swing.JPanel;
|
import javax.swing.JPopupMenu;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTextArea;
|
import javax.swing.JTextField;
|
import javax.swing.filechooser.FileFilter;
|
import javax.swing.table.DefaultTableModel;
|
|
import com.Com;
|
import com.teechart.TBarChart_fbs;
|
|
import javax.swing.JTable;
|
import javax.swing.ScrollPaneConstants;
|
import javax.swing.JLabel;
|
|
public class zdhj_page_record extends JPanel {
|
public static int LANG_TYPE_CN = 0;
|
public static int LANG_TYPE_EN = 1;
|
public static int LANG_TYPE = LANG_TYPE_CN;
|
private SPCommZDHJ SerialComm_ZDHJ = null;
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
public TBarChart_fbs m_TBarMonCommErrCntChart;
|
private JButton btn_zdhj_new_savefile;
|
private JButton btn_zdhj_start_record;
|
private JButton btn_zdhj_stop_record;
|
private JTextField tf_zdhj_save_filename;
|
private JFileChooser fc_zdhj_save_data;
|
private String filename_zdhj_save_data = "";
|
private JTextField tf_zdhj_record_state;
|
private JTextArea textArea_zdhj;
|
private JPanel panel;
|
private JScrollPane scrollPane;
|
|
private JTable table_moncomm_errcnt;
|
private Vector<String> columnVector;
|
private Vector<Vector<String>> dataRow;
|
private JLabel lblNewLabel;
|
/**
|
* Create the panel.
|
*/
|
public zdhj_page_record() {
|
setLayout(new BorderLayout(0, 0));
|
|
JPanel panel_59 = new JPanel();
|
add(panel_59, BorderLayout.NORTH);
|
panel_59.setLayout(new BoxLayout(panel_59, BoxLayout.X_AXIS));
|
|
String zdhj_title = "н¨";
|
if(LANG_TYPE_EN == LANG_TYPE) {
|
zdhj_title = "New";
|
}
|
btn_zdhj_new_savefile = new JButton(zdhj_title);
|
btn_zdhj_new_savefile.setEnabled(false);
|
btn_zdhj_new_savefile.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
fc_zdhj_save_data = new JFileChooser();
|
fc_zdhj_save_data.setFileFilter(new FileFilter() {
|
@Override
|
public boolean accept(File f) {
|
if (f.isDirectory())
|
return true;
|
|
return (f.getName().toUpperCase().endsWith(".CSV"));
|
}
|
|
@Override
|
public String getDescription() {
|
return "*.CSV";
|
}
|
});
|
int value = fc_zdhj_save_data.showSaveDialog(null);
|
if(value == JFileChooser.APPROVE_OPTION) {
|
filename_zdhj_save_data = fc_zdhj_save_data.getSelectedFile().getAbsolutePath();
|
} else {
|
filename_zdhj_save_data = "";
|
}
|
if(false == filename_zdhj_save_data.toUpperCase().endsWith(".CSV")) {
|
filename_zdhj_save_data += ".CSV";
|
}
|
|
tf_zdhj_save_filename.setText(filename_zdhj_save_data);
|
}
|
});
|
panel_59.add(btn_zdhj_new_savefile);
|
|
zdhj_title = "¿ªÊ¼";
|
if(LANG_TYPE_EN == LANG_TYPE) {
|
zdhj_title = "Start";
|
}
|
btn_zdhj_start_record = new JButton(zdhj_title);
|
btn_zdhj_start_record.setEnabled(false);
|
btn_zdhj_start_record.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
if(filename_zdhj_save_data.length() < 1) {
|
String tmp_str = "ÇëÏÈÊäÈëÒª±£´æµÄÊý¾ÝÎļþÃû!";
|
if(LANG_TYPE_EN == LANG_TYPE) {
|
tmp_str = "Please input the filename first!";
|
}
|
JOptionPane.showMessageDialog(null, tmp_str);
|
return;
|
}
|
SerialComm_ZDHJ.setAutoStartRestTest(filename_zdhj_save_data, SPCommZDHJ.ZDHJ_ResTest_Start_RegAddr, true);
|
btn_zdhj_new_savefile.setEnabled(false);
|
btn_zdhj_start_record.setEnabled(false);
|
}
|
});
|
panel_59.add(btn_zdhj_start_record);
|
|
zdhj_title = "Í£Ö¹";
|
if(LANG_TYPE_EN == LANG_TYPE) {
|
zdhj_title = "Stop";
|
}
|
btn_zdhj_stop_record = new JButton(zdhj_title);
|
btn_zdhj_stop_record.setEnabled(false);
|
btn_zdhj_stop_record.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
SerialComm_ZDHJ.setAutoStartRestTest(filename_zdhj_save_data, SPCommZDHJ.ZDHJ_ResTest_Start_RegAddr, false);
|
btn_zdhj_new_savefile.setEnabled(true);
|
btn_zdhj_start_record.setEnabled(true);
|
}
|
});
|
panel_59.add(btn_zdhj_stop_record);
|
|
tf_zdhj_save_filename = new JTextField();
|
tf_zdhj_save_filename.setEditable(false);
|
panel_59.add(tf_zdhj_save_filename);
|
tf_zdhj_save_filename.setColumns(10);
|
|
JPanel panel_60 = new JPanel();
|
add(panel_60, BorderLayout.CENTER);
|
panel_60.setLayout(new BorderLayout(0, 0));
|
|
JPanel panel_61 = new JPanel();
|
panel_60.add(panel_61, BorderLayout.NORTH);
|
panel_61.setLayout(new BorderLayout(0, 0));
|
|
tf_zdhj_record_state = new JTextField();
|
tf_zdhj_record_state.setEditable(false);
|
panel_61.add(tf_zdhj_record_state);
|
tf_zdhj_record_state.setColumns(10);
|
|
JPanel panel_81 = new JPanel();
|
panel_60.add(panel_81, BorderLayout.CENTER);
|
panel_81.setLayout(new GridLayout(2, 1, 0, 0));
|
m_TBarMonCommErrCntChart = new TBarChart_fbs(TBarChart_fbs.Bar_Type_MonSer);
|
panel_81.add(m_TBarMonCommErrCntChart);
|
|
panel = new JPanel();
|
panel_81.add(panel);
|
panel.setLayout(new BorderLayout(0, 0));
|
|
textArea_zdhj = new JTextArea();
|
JScrollPane scrollPane_1 = new JScrollPane();
|
panel.add(scrollPane_1, BorderLayout.CENTER);
|
scrollPane_1.setViewportView(textArea_zdhj);
|
|
lblNewLabel = new JLabel("\u5404\u901A\u9053\u901A\u4FE1\u9519\u8BEF\u603B\u8BA1\u6570");
|
scrollPane_1.setColumnHeaderView(lblNewLabel);
|
|
scrollPane = new JScrollPane();
|
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
panel.add(scrollPane, BorderLayout.WEST);
|
|
table_moncomm_errcnt = new JTable();
|
columnVector = new Vector<String>();
|
|
zdhj_title = "µ¥Ìå±àºÅ";
|
if(LANG_TYPE_EN == LANG_TYPE) {
|
zdhj_title = "MonNum";
|
}
|
columnVector.add(zdhj_title);
|
|
zdhj_title = "ͨÐÅ´íÎó¼ÆÊý";
|
if(LANG_TYPE_EN == LANG_TYPE) {
|
zdhj_title = "MonCommErrCount";
|
}
|
columnVector.add(zdhj_title);
|
|
dataRow = new Vector<Vector<String>>();
|
table_moncomm_errcnt.setModel(new DefaultTableModel(dataRow, columnVector));
|
MouseAdapter m_a = new MouseAdapter() {
|
public void mouseReleased(MouseEvent e) {
|
if(e.getSource() != table_moncomm_errcnt) {
|
return;
|
}
|
/*
|
int selectColumn = m_JTable.columnAtPoint(e.getPoint());
|
int selectRow = m_JTable.rowAtPoint(e.getPoint());
|
if (selectColumn == mCheckBoxColnumIndex) {
|
boolean value = (boolean) m_JTable.getValueAt(selectRow, selectColumn);
|
m_UI_Monit.m_MonLineChart.getSeries(selectRow+1).setVisible(!value);
|
}
|
*/
|
}
|
public void mousePressed(MouseEvent evt) {
|
if (evt.getButton() == MouseEvent.BUTTON3) {
|
JPopupMenu popupMenu = new JPopupMenu();
|
JMenuItem tableItem_export_data = null;
|
String it_str = "¸´ÖƵ½¼ôÌù°å";
|
if(LANG_TYPE_EN == LANG_TYPE) {
|
it_str = "Copy To Clipboard";
|
}
|
tableItem_export_data = new JMenuItem(it_str);
|
tableItem_export_data.addActionListener(new ActionListener(){
|
@Override
|
public void actionPerformed(ActionEvent arg0) {
|
Clipboard clipboard = getToolkit().getSystemClipboard();
|
String temp = "";
|
for(int c=0; c<columnVector.size(); c++) {
|
temp += columnVector.get(c) + "\t";
|
}
|
temp += "\n";
|
for(int r=0; r<dataRow.size(); r++) {
|
for(int c=0; c<columnVector.size(); c++) {
|
temp += 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_moncomm_errcnt.addMouseListener(m_a);
|
scrollPane.setViewportView(table_moncomm_errcnt);
|
/**************************************************************************/
|
|
setButttonState(false);
|
}
|
|
public void setSerialComm_ZDHJ(SPCommZDHJ sz) {
|
SerialComm_ZDHJ = sz;
|
}
|
|
public void setButttonState(boolean state) {
|
btn_zdhj_start_record.setEnabled(state);
|
btn_zdhj_stop_record.setEnabled(state);
|
btn_zdhj_new_savefile.setEnabled(state);
|
}
|
|
public void updateData() {
|
if(null != SerialComm_ZDHJ) {
|
int mon_cnt = SerialComm_ZDHJ.ZDHJ_BattCount;
|
m_TBarMonCommErrCntChart.updateChartData(TBarChart_fbs.Bar_Type_MonSer, SerialComm_ZDHJ.monCommErrCnt, mon_cnt);
|
if(dataRow.size() != mon_cnt)
|
{
|
dataRow.clear();
|
for(int n=0; n<mon_cnt; n++) {
|
Vector<String> row = new Vector<String>();
|
row.addElement(String.format("%03d", n+1));
|
row.addElement(String.format("%1.0f", SerialComm_ZDHJ.monCommErrCnt[n]));
|
dataRow.add(row);
|
}
|
} else {
|
for(int n=0; n<mon_cnt; n++) {
|
dataRow.get(n).setElementAt(String.format("%1.0f", SerialComm_ZDHJ.monCommErrCnt[n]), 1);
|
}
|
}
|
table_moncomm_errcnt.updateUI();
|
|
String str = String.format("Com1-ECnt: %d\nCom2-ECnt: %d\nCom3-ECnt: %d\nCom4-ECnt: %d\nCom5-ECnt: %d\n",
|
SerialComm_ZDHJ.MonCommErrCount[0],
|
SerialComm_ZDHJ.MonCommErrCount[1],
|
SerialComm_ZDHJ.MonCommErrCount[2],
|
SerialComm_ZDHJ.MonCommErrCount[3],
|
SerialComm_ZDHJ.MonCommErrCount[4]);
|
str += String.format("SPI-ECnt: %d\n", SerialComm_ZDHJ.SpiCommErrCount);
|
textArea_zdhj.setText(str);
|
|
if(SerialComm_ZDHJ.AutoStartResTestEn) {
|
String text_tt = "";
|
if(SerialComm_ZDHJ.AutoSaveResDataCount > 0) {
|
text_tt += "Òѱ£´æ´ÎÊý: " + SerialComm_ZDHJ.AutoSaveResDataCount
|
+ "; Éϴα£´æÊ±¼ä: " + Com.get_DTF(SerialComm_ZDHJ.AutoSaveResDataTime, Com.DTF_YMDhms)
|
+ "; ";
|
}
|
text_tt += "µÈ´ý±£´æÊý¾Ý @ " + Com.get_DTF(new Date(), Com.DTF_YMDhms);
|
tf_zdhj_record_state.setText(text_tt);
|
}
|
}
|
}
|
}
|