net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java Source code

Java tutorial

Introduction

Here is the source code for net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.liuxuan.device.VACVBS;

import com.google.common.base.Charsets;
import com.google.common.base.Strings;
import com.google.common.io.Files;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileSystemView;
import net.liuxuan.UI.component.ExtensionFileFilter;
import net.liuxuan.device.w3330.KalmanFilterHolder;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleAnchor;
import org.jfree.ui.TextAnchor;

/**
 *
 * @author Moses
 */
public class JIF_DrawChart_vacvbs extends net.liuxuan.UI.JIFUI {

    private static JIF_DrawChart_vacvbs myInstance; //thisJFrame singleton

    public static JIF_DrawChart_vacvbs getInstance(net.liuxuan.UI.DataHolder.DataHolder _datas) {
        if (myInstance == null) {
            myInstance = new JIF_DrawChart_vacvbs();
        }
        myInstance.datas = _datas;
        return myInstance;
    }

    TimeSeriesCollection trcollection;
    TimeSeriesCollection trcollection2;
    TimeSeries ts_LP;
    TimeSeries ts_HP;
    TimeSeries ts_humidity;
    TimeSeries ts_temprature;
    TimeSeries ts_time;
    TimeSeries ts_num;
    TimeSeries ts_reserved1;
    TimeSeries ts_reserved2;
    TimeSeries ts_reserved3;
    //    ArrayList<Double> fittingdata = new ArrayList<Double>();
    //    ArrayList<Long> times = new ArrayList<Long>();
    VACVBSInfoMetaData vbsinfodata = null;
    ArrayList<VACVBSMetaData> metadatas = new ArrayList<VACVBSMetaData>();

    int dropinterval = 30;//??? 

    double[] filterds = new double[10];
    int filterpoint = 0;
    //    XYSeries xyseries = new XYSeries("Random Data");
    //    XYSeriesCollection xyseriesCollection1 = new XYSeriesCollection(xyseries);
    ChartPanel chartPanel;

    /**
     * Creates new form JIF_DrawChart
     */
    private JIF_DrawChart_vacvbs() {
        initComponents();
        //        init();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel_Show = new javax.swing.JPanel();
        jPanel_Control = new javax.swing.JPanel();
        jButtonOpen = new javax.swing.JButton();
        jCheckBox_LP = new javax.swing.JCheckBox();
        jCheckBox_HP = new javax.swing.JCheckBox();
        jCheckBox_Temprature = new javax.swing.JCheckBox();
        jCheckBox_humidity = new javax.swing.JCheckBox();
        jCheckBox_num = new javax.swing.JCheckBox();
        jCheckBox_time = new javax.swing.JCheckBox();
        jCheckBox_reserved1 = new javax.swing.JCheckBox();
        jFormattedTextField_temp = new javax.swing.JFormattedTextField();
        jCheckBox_reserved2 = new javax.swing.JCheckBox();
        jCheckBox_reserved3 = new javax.swing.JCheckBox();
        jButton_tidy = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);

        org.jdesktop.layout.GroupLayout jPanel_ShowLayout = new org.jdesktop.layout.GroupLayout(jPanel_Show);
        jPanel_Show.setLayout(jPanel_ShowLayout);
        jPanel_ShowLayout.setHorizontalGroup(jPanel_ShowLayout
                .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(0, 884, Short.MAX_VALUE));
        jPanel_ShowLayout.setVerticalGroup(jPanel_ShowLayout
                .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(0, 520, Short.MAX_VALUE));

        jPanel_Control.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jButtonOpen.setText("");
        jButtonOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOpenActionPerformed(evt);
            }
        });

        jCheckBox_LP.setSelected(true);
        jCheckBox_LP.setText("LP");
        jCheckBox_LP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_LPActionPerformed(evt);
            }
        });

        jCheckBox_HP.setSelected(true);
        jCheckBox_HP.setText("HP");
        jCheckBox_HP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_HPActionPerformed(evt);
            }
        });

        jCheckBox_Temprature.setSelected(true);
        jCheckBox_Temprature.setText("Temprature");
        jCheckBox_Temprature.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_TempratureActionPerformed(evt);
            }
        });

        jCheckBox_humidity.setSelected(true);
        jCheckBox_humidity.setText("humidity");
        jCheckBox_humidity.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_humidityActionPerformed(evt);
            }
        });

        jCheckBox_num.setSelected(true);
        jCheckBox_num.setText("num");
        jCheckBox_num.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_numActionPerformed(evt);
            }
        });

        jCheckBox_time.setText("time");
        jCheckBox_time.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_timeActionPerformed(evt);
            }
        });

        jCheckBox_reserved1.setText("reserved1");
        jCheckBox_reserved1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_reserved1ActionPerformed(evt);
            }
        });

        jFormattedTextField_temp.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance())));
        jFormattedTextField_temp.setText("30");

        jCheckBox_reserved2.setText("reserved2");
        jCheckBox_reserved2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_reserved2ActionPerformed(evt);
            }
        });

        jCheckBox_reserved3.setText("reserved3");
        jCheckBox_reserved3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_reserved3ActionPerformed(evt);
            }
        });

        jButton_tidy.setText("Tidy");
        jButton_tidy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_tidyActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel_ControlLayout = new org.jdesktop.layout.GroupLayout(jPanel_Control);
        jPanel_Control.setLayout(jPanel_ControlLayout);
        jPanel_ControlLayout.setHorizontalGroup(jPanel_ControlLayout
                .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel_ControlLayout.createSequentialGroup().addContainerGap().add(jButtonOpen).add(18, 18, 18)
                        .add(jCheckBox_LP).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jCheckBox_HP).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jCheckBox_Temprature).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jCheckBox_humidity).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jCheckBox_num).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jCheckBox_time).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jCheckBox_reserved1).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jCheckBox_reserved2).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jCheckBox_reserved3).add(29, 29, 29)
                        .add(jFormattedTextField_temp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18).add(jButton_tidy)
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        jPanel_ControlLayout.setVerticalGroup(jPanel_ControlLayout
                .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel_ControlLayout.createSequentialGroup().addContainerGap()
                        .add(jPanel_ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(jButtonOpen).add(jCheckBox_LP).add(jCheckBox_HP).add(jCheckBox_Temprature)
                                .add(jCheckBox_humidity).add(jCheckBox_num).add(jCheckBox_time)
                                .add(jCheckBox_reserved1)
                                .add(jFormattedTextField_temp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jCheckBox_reserved2).add(jCheckBox_reserved3).add(jButton_tidy))
                        .addContainerGap(14, Short.MAX_VALUE)));

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel_Control,
                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)
                .add(jPanel_Show, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                        .add(jPanel_Show, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(jPanel_Control,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
                                org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
                                org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOpenActionPerformed
        openFiletoCurve();
    }//GEN-LAST:event_jButtonOpenActionPerformed

    private void jCheckBox_LPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_LPActionPerformed
        if (jCheckBox_LP.isSelected()) {
            trcollection.addSeries(ts_LP);
        } else {
            trcollection.removeSeries(ts_LP);
        }
    }//GEN-LAST:event_jCheckBox_LPActionPerformed

    private void jCheckBox_HPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_HPActionPerformed
        if (jCheckBox_HP.isSelected()) {
            trcollection.addSeries(ts_HP);
        } else {
            trcollection.removeSeries(ts_HP);
        }
    }//GEN-LAST:event_jCheckBox_HPActionPerformed

    private void jCheckBox_TempratureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_TempratureActionPerformed
        if (jCheckBox_Temprature.isSelected()) {
            trcollection2.addSeries(ts_temprature);
        } else {
            trcollection2.removeSeries(ts_temprature);
        }
    }//GEN-LAST:event_jCheckBox_TempratureActionPerformed

    private void jCheckBox_humidityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_humidityActionPerformed
        if (jCheckBox_humidity.isSelected()) {
            trcollection2.addSeries(ts_humidity);
        } else {
            trcollection2.removeSeries(ts_humidity);
        }
    }//GEN-LAST:event_jCheckBox_humidityActionPerformed

    private void jCheckBox_numActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_numActionPerformed
        if (jCheckBox_num.isSelected()) {
            trcollection2.addSeries(ts_num);
        } else {
            trcollection2.removeSeries(ts_num);
        }
    }//GEN-LAST:event_jCheckBox_numActionPerformed

    private void jCheckBox_timeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_timeActionPerformed
        if (jCheckBox_time.isSelected()) {
            trcollection2.addSeries(ts_time);
        } else {
            trcollection2.removeSeries(ts_time);
        }
    }//GEN-LAST:event_jCheckBox_timeActionPerformed

    private void jCheckBox_reserved1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_reserved1ActionPerformed
        if (jCheckBox_reserved1.isSelected()) {
            trcollection2.addSeries(ts_reserved1);
        } else {
            trcollection2.removeSeries(ts_reserved1);
        }
    }//GEN-LAST:event_jCheckBox_reserved1ActionPerformed

    private void jCheckBox_reserved2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_reserved2ActionPerformed
        if (jCheckBox_reserved2.isSelected()) {
            trcollection2.addSeries(ts_reserved2);
        } else {
            trcollection2.removeSeries(ts_reserved2);
        }
    }//GEN-LAST:event_jCheckBox_reserved2ActionPerformed

    private void jCheckBox_reserved3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_reserved3ActionPerformed
        if (jCheckBox_reserved3.isSelected()) {
            trcollection2.addSeries(ts_reserved3);
        } else {
            trcollection2.removeSeries(ts_reserved3);
        }
    }//GEN-LAST:event_jCheckBox_reserved3ActionPerformed

    private void jButton_tidyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_tidyActionPerformed
        Runtime rn = Runtime.getRuntime();
        Process p = null;
        //        File f= new File("others/exe/VBS-data-export.exe");
        //        System.out.println(f.getAbsolutePath());
        try {
            p = rn.exec("\"others/exe/VBS-data-export.exe\"");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Error exec!");
        }
    }//GEN-LAST:event_jButton_tidyActionPerformed

    public void openFiletoCurve() throws NumberFormatException {
        String tempstr = jFormattedTextField_temp.getText();
        int tempint = Integer.parseInt(tempstr);
        dropinterval = tempint;

        //??
        //??0?1
        filterds = new double[dropinterval];

        SimpleDateFormat sdfx = new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss]");
        //        String content;
        String fileContent = null;

        JFileChooser jfc = initFileChooser();
        int result = jfc.showOpenDialog(this); // ""?
        if (result == JFileChooser.APPROVE_OPTION) {
            //            String filepath = jfc.getSelectedFile().getAbsolutePath();
            if (jfc.getSelectedFile() == null) {
                //
                System.out.println("!!");
                return;
            }
            try {
                fileContent = Files.toString(jfc.getSelectedFile(), Charsets.ISO_8859_1);

            } catch (IOException ex) {
                Logger.getLogger(JIF_DrawChart_vacvbs.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            System.out.println("!!");
            return;
        }

        //??,dropinterval
        parseFileToDataStructure(fileContent, dropinterval);

        if (metadatas.size() == 0) {
            System.out.println("?");
            return;
        } else {
            chartPanel.getChart().setTitle("" + jfc.getSelectedFile().getName());
            System.out.println("" + jfc.getSelectedFile().getName());
            System.out.println(String.format("?%d", metadatas.size()));
        }

        //===============kalman?
        clearChart();//?

        tsNotifyFalse();//?

        //??
        for (int i = 0; i < metadatas.size(); i++) {
            VACVBSMetaData data = metadatas.get(i);

            ts_LP.addOrUpdate(new Millisecond(data.date1), data.LP);
            ts_HP.addOrUpdate(new Millisecond(data.date1), data.HP);
            ts_temprature.addOrUpdate(new Millisecond(data.date1), data.Temprature);
            //??100??100
            ts_humidity.addOrUpdate(new Millisecond(data.date1), data.Humidity);
            //25????25
            ts_num.addOrUpdate(new Millisecond(data.date1), data.num);
            //38????38
            ts_time.addOrUpdate(new Millisecond(data.date1), data.Time);
            //?
            //status 1?? 2 ? 3 4 5?? 6 7?? 8 9? 0 
            ts_reserved1.addOrUpdate(new Millisecond(data.date1), data.reserved1);
            ts_reserved2.addOrUpdate(new Millisecond(data.date1), data.reserved2);
            ts_reserved3.addOrUpdate(new Millisecond(data.date1), data.reserved3);
        }

        tsNotifyTrue();//
    }

    private void chartDrawHerizonLine(VACVBSMetaData data, Color color, String Labelstr) {
        XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
        final Marker start = new ValueMarker(0);
        start.setPaint(color);
        start.setLabel(Labelstr);
        start.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
        start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
        start.setLabelPaint(color);
        plot.addRangeMarker(start);
    }

    private void chartDrawVerticalLine(VACVBSMetaData data, Color color, String Labelstr) {
        XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
        final Marker start = new ValueMarker(data.date1.getTime());
        start.setPaint(color);
        start.setLabel(Labelstr);
        start.setLabelAnchor(RectangleAnchor.TOP_LEFT);
        start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
        start.setLabelPaint(color);
        plot.addDomainMarker(start);
    }

    private void tsNotifyTrue() {
        ts_LP.setNotify(true);
        ts_HP.setNotify(true);
        ts_humidity.setNotify(true);
        ts_temprature.setNotify(true);
        ts_num.setNotify(true);
        ts_time.setNotify(true);
        ts_reserved1.setNotify(true);
        ts_reserved2.setNotify(true);
        ts_reserved3.setNotify(true);
    }

    private void tsNotifyFalse() {
        ts_LP.setNotify(false);
        ts_HP.setNotify(false);
        ts_humidity.setNotify(false);
        ts_temprature.setNotify(false);
        ts_num.setNotify(false);
        ts_time.setNotify(false);
        ts_reserved1.setNotify(false);
        ts_reserved2.setNotify(false);
        ts_reserved3.setNotify(false);
    }

    private void clearChart() {
        //        String[] sa = (String[]) fileContentStringList.toArray(new String[fileContentStringList.size()]);
        ((XYPlot) chartPanel.getChart().getPlot()).clearDomainMarkers();
        ((XYPlot) chartPanel.getChart().getPlot()).clearRangeMarkers();
        ts_LP.clear();
        ts_HP.clear();
        ts_humidity.clear();
        ts_temprature.clear();
        ts_num.clear();
        ts_time.clear();
        ts_reserved1.clear();
        ts_reserved2.clear();
        ts_reserved3.clear();
    }

    protected JFileChooser initFileChooser() {
        ExtensionFileFilter filter = new ExtensionFileFilter("log,txt", true, true);
        filter.setDescription("?");
        JFileChooser jfc = new JFileChooser();
        FileSystemView fsv = FileSystemView.getFileSystemView();
        //?
        jfc.setCurrentDirectory(fsv.getHomeDirectory());
        jfc.setDialogTitle("?");
        jfc.setMultiSelectionEnabled(false);
        jfc.setDialogType(JFileChooser.OPEN_DIALOG);
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);//JFileChooser.FILES_AND_DIRECTORIES
        jfc.setFileFilter(filter);
        return jfc;
    }

    @Override
    public void init() {
        initChart();
    }

    /**
     * ?jfreechart
     */
    public void initChart() {
        ts_LP = new TimeSeries("LowPressure", Millisecond.class);
        ts_HP = new TimeSeries("HighPressure", Millisecond.class);
        ts_humidity = new TimeSeries("Humidity", Millisecond.class);
        ts_temprature = new TimeSeries("Temperature", Millisecond.class);
        ts_time = new TimeSeries("TestTime", Millisecond.class);
        ts_num = new TimeSeries("num", Millisecond.class);
        ts_reserved1 = new TimeSeries("reserved1", Millisecond.class);
        ts_reserved2 = new TimeSeries("reserved2", Millisecond.class);
        ts_reserved3 = new TimeSeries("reserved3", Millisecond.class);
        trcollection = new TimeSeriesCollection(ts_LP);

        trcollection.addSeries(ts_HP);

        trcollection2 = new TimeSeriesCollection(ts_humidity);

        trcollection2.addSeries(ts_temprature);

        //        trcollection2.addSeries(ts_num);
        //        trcollection2.addSeries(ts_time);
        //trcollection2.addSeries(ts_reserved1);
        //trcollection2.addSeries(ts_reserved2);
        //trcollection2.addSeries(ts_reserved3);

        //        timeseriescopylist.add(getTimeSeries(3).createCopy(0, getTimeSeries(3).getItemCount() - 1));
        JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "Time(s)", "PPM", trcollection,
                true, true, false);
        XYPlot xyplot = jfreechart.getXYPlot();

        xyplot.setDomainCrosshairVisible(true);
        xyplot.setRangeCrosshairVisible(true);

        Font fs = new Font("", Font.BOLD, 14);
        Font fs2 = new Font("", Font.BOLD, 12);

        XYLineAndShapeRenderer line0render = (XYLineAndShapeRenderer) xyplot.getRenderer(0);

        Color purple = new Color(139, 0, 255);

        line0render.setSeriesPaint(0, Color.blue);
        line0render.setSeriesPaint(1, Color.green);
        line0render.setSeriesPaint(2, Color.red);
        line0render.setSeriesPaint(3, purple);

        //        line0render.setSeriesPaint(3, Color.ORANGE);
        XYLineAndShapeRenderer line1render = new XYLineAndShapeRenderer();
        Color Rosered = new Color(230, 28, 100);
        line1render.setSeriesPaint(0, Color.cyan);
        line1render.setSeriesPaint(1, Rosered);
        line1render.setSeriesPaint(2, Color.orange);
        line1render.setSeriesPaint(3, Color.yellow);
        line1render.setBaseShapesVisible(false);
        xyplot.setRenderer(1, line1render);

        //??
        ValueAxis valueaxis = xyplot.getDomainAxis();

        //
        valueaxis.setLabelFont(fs);

        //
        valueaxis.setTickLabelFont(fs2);

        ValueAxis valueaxis2 = new NumberAxis("");
        valueaxis2.setLabelFont(fs);
        valueaxis2.setTickLabelFont(fs2);

        xyplot.setRangeAxis(1, valueaxis2);
        xyplot.setDataset(1, trcollection2);
        xyplot.mapDatasetToRangeAxis(1, 1);

        //??
        valueaxis.setAutoRange(true);
        //?? 7days
        //                valueaxis.setFixedAutoRange(604800000D);
        valueaxis = xyplot.getRangeAxis();

        valueaxis.setLabelFont(new Font("", Font.BOLD, 14));
        valueaxis.setLabelPaint(line0render.getSeriesPaint(0));
        valueaxis2.setLabelPaint(line1render.getSeriesPaint(0));

        jfreechart.getTitle().setFont(new Font("", Font.BOLD, 20));//
        jfreechart.getLegend().setItemFont(new Font("", Font.ITALIC, 15));
        xyplot.getRenderer(0).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
                new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
        xyplot.getRenderer(1).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
                new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
        chartPanel = new ChartPanel(jfreechart);

        initChartMenu();
        //        chartPanel.getPopupMenu().add(jmenuitem2);
        //        chartPanel.getPopupMenu().getPopupMenuListeners();

        chartPanel.setSize(950, 620);
        chartPanel.setPreferredSize(new Dimension(950, 620));
        jPanel_Show.add(chartPanel, BorderLayout.CENTER);
    }

    /**
     * ????
     */
    public void initChartMenu() {
        GetPointAction action = new GetPointAction();
        JMenu fx = new JMenu("?");
        JMenuItem jmenuitem_select1 = new JMenuItem("");
        jmenuitem_select1.addActionListener(action);
        fx.add(jmenuitem_select1);
        JMenuItem jmenuitem_select2 = new JMenuItem("");
        jmenuitem_select2.addActionListener(action);
        fx.add(jmenuitem_select2);
        JMenuItem jmenuitem_avg = new JMenuItem("?");
        jmenuitem_avg.addActionListener(action);
        fx.add(jmenuitem_avg);
        JMenuItem jmenuitem_parse = new JMenuItem("?");
        jmenuitem_parse.addActionListener(action);
        fx.add(jmenuitem_parse);

        JMenuItem jmenuitem_compute = new JMenuItem("?");
        jmenuitem_compute.addActionListener(action);
        fx.add(jmenuitem_compute);

        JMenuItem jmenuitem_zz1 = new JMenuItem("1");
        jmenuitem_zz1.addActionListener(action);
        fx.add(jmenuitem_zz1);
        JMenuItem jmenuitem_zz2 = new JMenuItem("2");
        jmenuitem_zz2.addActionListener(action);
        fx.add(jmenuitem_zz2);
        chartPanel.getPopupMenu().add(fx);

        JMenu bx = new JMenu("");

        JMenuItem jmenuitem7 = new JMenuItem("");
        jmenuitem7.addActionListener(action);
        bx.add(jmenuitem7);
        JMenuItem jmenuitem9 = new JMenuItem("");
        jmenuitem9.addActionListener(action);
        bx.add(jmenuitem9);
        JMenuItem jmenuitem10 = new JMenuItem("");
        jmenuitem10.addActionListener(action);
        bx.add(jmenuitem10);

        chartPanel.getPopupMenu().add(bx);
    }

    /**
     * ??
     *
     * @param inlist List
     * @param second  
     */
    private void parseFileToDataStructure(String fileContent, long second) {
        Gson gson = new Gson();
        vbsinfodata = gson.fromJson(fileContent, VACVBSInfoMetaData.class);
        metadatas = vbsinfodata.datas;
    }

    private Date chartstarttime;
    private Date chartendtime;
    private VACVBSMetaData startdata;
    private VACVBSMetaData enddata;
    VACcompute cp = new VACcompute();

    /**
     * ???
     */
    class GetPointAction implements ActionListener { //???

        @Override
        public void actionPerformed(ActionEvent event) {

            String command = event.getActionCommand();
            //            System.out.println(command);

            //            int x = (int) chartPanel.getMousePosition().getX();
            //            int y = (int) chartPanel.getMousePosition().getY();
            XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
            double XValue = plot.getDomainCrosshairValue();
            double YValue = plot.getRangeCrosshairValue();

            Date date = new Date((long) XValue);

            if (command.equals("")) {
                chartstarttime = date;
                System.out.println(String.format(
                        "[%1$tY/%1$tm/%1$te %1$tH:%1$tM:%1$tS %1$tL],%2$f", date,
                        YValue));
                for (int i = 0; i < metadatas.size(); i++) {
                    VACVBSMetaData da = metadatas.get(i);
                    if (da.date1.getTime() == date.getTime()) {
                        startdata = da;
                        if (enddata != null) {
                            cp.jFormattedTextField_VAC_deltaT.setValue(enddata.Time - startdata.Time);
                            cp.jFormattedTextField_VAC_deltaPstart.setValue(startdata.LP);
                            cp.jFormattedTextField_VAC_deltaPend.setValue(enddata.LP);
                            cp.jFormattedTextField_VAC_kuosanP1.setValue(enddata.LP);
                            cp.jFormattedTextField_VAC_kuosanP2.setValue(startdata.LP);
                            cp.jFormattedTextField_VAC_kuosanT1.setValue(enddata.Time);
                            cp.jFormattedTextField_VAC_kuosanT2.setValue(startdata.Time);
                        }

                        break;
                    }
                }
            } else if (command.equals("")) {
                chartendtime = date;
                System.out.println(String.format(
                        "[%1$tY/%1$tm/%1$te %1$tH:%1$tM:%1$tS %1$tL],%2$f", date,
                        YValue));
                for (int i = 0; i < metadatas.size(); i++) {
                    VACVBSMetaData da = metadatas.get(i);
                    if (da.date1.getTime() == date.getTime()) {
                        enddata = da;
                        if (startdata != null) {
                            cp.jFormattedTextField_VAC_deltaT.setValue(enddata.Time - startdata.Time);
                            cp.jFormattedTextField_VAC_deltaPstart.setValue(startdata.LP);
                            cp.jFormattedTextField_VAC_deltaPend.setValue(enddata.LP);
                            cp.jFormattedTextField_VAC_kuosanP1.setValue(enddata.LP);
                            cp.jFormattedTextField_VAC_kuosanP2.setValue(startdata.LP);
                            cp.jFormattedTextField_VAC_kuosanT1.setValue(enddata.Time);
                            cp.jFormattedTextField_VAC_kuosanT2.setValue(startdata.Time);
                        }
                        break;
                    }
                }
            } else if (command.equals("?")) {
                double total = 0;
                int totalcount = 0;
                long start = chartstarttime.getTime();
                long end = chartendtime.getTime();
                for (int i = 0; i < metadatas.size(); i++) {
                    VACVBSMetaData da = metadatas.get(i);
                    long time = da.date1.getTime();
                    if (time >= start && time <= end) {
                        total += da.LP;
                        totalcount++;
                    }
                    if (time > end) {
                        System.out.println("LP?" + total / totalcount);
                        break;
                    }
                }
            } else if (command.equals("?")) {
                long start = chartstarttime.getTime();
                long end = chartendtime.getTime();
                if (end < start) {
                    System.out.println("?");
                }

                double total = 0;
                int totalcount = 0;
                long start2 = start;
                long end2 = end;
                long distance = end - start;

                SimpleDateFormat sdfx = new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss]");
                for (int i = 0; i < metadatas.size(); i++) {
                    VACVBSMetaData da = metadatas.get(i);
                    long time = da.date1.getTime();
                    if (time >= start2 && time <= end2) {
                        //?
                        total += da.LP;
                        totalcount++;
                    } else if (time > end2) {
                        //??
                        //
                        System.out.println(String.format(" %s  %s,LP?%.4f",
                                sdfx.format(new Date(start2)), sdfx.format(new Date(end2)), total / totalcount));
                        //                        System.out.println("wppm?" + total / totalcount + ",?" + total2 / totalcount);
                        //?
                        total = da.LP;
                        totalcount = 1;
                        start2 = time;
                        end2 = start2 + distance;
                        //                        break;
                    } else if (i == metadatas.size() - 1) {
                        System.out.println(String.format(" %s  %s,LP?%.4f",
                                sdfx.format(new Date(start2)), sdfx.format(da.date1), total / totalcount));
                    }
                }

            } else if (command.equals("?")) {
                if (startdata == null || enddata == null) {
                    System.out.println("");
                    return;
                }
                if (enddata.Time < startdata.Time) {
                    System.out.println("?");
                    return;
                }

                cp.jFormattedTextField_VAC_V.setValue(20.2389d);
                cp.jFormattedTextField_VAC_S.setValue(0.002827d);
                cp.jFormattedTextField_VAC_T.setValue(enddata.Temprature);
                cp.jFormattedTextField_VAC_T0.setValue(273d);
                cp.jFormattedTextField_VAC_P0.setValue(101325d);
                cp.jFormattedTextField_VAC_P1.setValue(1.01000d);
                cp.jFormattedTextField_VAC_P2.setValue(0.00000d);
                cp.jFormattedTextField_VAC_deltaT.setValue(enddata.Time - startdata.Time);
                cp.jFormattedTextField_VAC_deltaPstart.setValue(startdata.LP);
                cp.jFormattedTextField_VAC_deltaPend.setValue(enddata.LP);
                double amount = 3;
                try {
                    amount = Double.parseDouble(vbsinfodata.SampleAmount.trim());
                } catch (Exception e) {
                    amount = 3;
                }
                cp.jFormattedTextField_VAC_n.setValue(amount);
                double thickness = 125;
                try {
                    thickness = Double.parseDouble(vbsinfodata.Thickness.trim());
                } catch (Exception e) {
                    thickness = 125;
                }
                cp.jFormattedTextField_VAC_d.setValue(thickness);
                cp.jFormattedTextField_VAC_kuosanP1.setValue(enddata.LP);
                cp.jFormattedTextField_VAC_kuosanP2.setValue(startdata.LP);
                cp.jFormattedTextField_VAC_kuosanT1.setValue(enddata.Time);
                cp.jFormattedTextField_VAC_kuosanT2.setValue(startdata.Time);
                cp.setVisible(true);
            } else if (command.equals("")) {
                //                plot.getRangeMarkers(Layer.FOREGROUND);
                String s = JOptionPane.showInputDialog("?");
                final Marker start = new ValueMarker(YValue);
                start.setPaint(Color.GREEN);
                start.setLabel(String.format("%s,%.4f", s, YValue));
                start.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
                start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
                start.setLabelPaint(Color.red);
                plot.addRangeMarker(start);
            } else if (command.equals("")) {
                //                plot.getRangeMarkers(Layer.FOREGROUND);
                String s = JOptionPane.showInputDialog("?");
                final Marker start = new ValueMarker(XValue);
                start.setPaint(Color.GREEN);
                start.setLabel(String.format("%s", s, XValue));

                start.setLabelAnchor(RectangleAnchor.CENTER);
                start.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
                start.setLabelPaint(Color.red);
                plot.addDomainMarker(start);
            } else if (command.equals("")) {
                int k = JOptionPane.showConfirmDialog(null, "?");
                if (k == JOptionPane.YES_OPTION) {
                    plot.clearDomainMarkers();
                    plot.clearRangeMarkers();
                }
            } else if (command.equals("1")) {
                ValueAxis valueaxis = plot.getRangeAxis(0);
                System.out.println(valueaxis.getLabel());
                ;
                String s = JOptionPane.showInputDialog("??");
                if (Strings.isNullOrEmpty(s)) {
                    //donothing
                    valueaxis.setLabel("PPM");
                } else {
                    valueaxis.setLabel(s);
                    //                    valueaxis.setLabelPaint(Color.BLUE);
                }
                s = JOptionPane.showInputDialog("?");
                if (Strings.isNullOrEmpty(s)) {
                    return;
                }
                double lower = Double.parseDouble(s);
                s = JOptionPane.showInputDialog("?");
                if (Strings.isNullOrEmpty(s)) {
                    return;
                }
                double upper = Double.parseDouble(s);
                valueaxis.setRange(lower, upper);
            } else if (command.equals("2")) {
                ValueAxis valueaxis2 = plot.getRangeAxis(1);

                String s = JOptionPane.showInputDialog("??");
                if (Strings.isNullOrEmpty(s)) {
                    //donothing
                    valueaxis2.setLabel("");
                } else {
                    valueaxis2.setLabel(s);
                }

                s = JOptionPane.showInputDialog("?");
                if (Strings.isNullOrEmpty(s)) {
                    return;
                }
                double lower = Double.parseDouble(s);
                s = JOptionPane.showInputDialog("?");
                if (Strings.isNullOrEmpty(s)) {
                    return;
                }
                double upper = Double.parseDouble(s);
                valueaxis2.setRange(lower, upper);

            } else {

            }

            //            System.out.println(chartPanel.getMousePosition().getX());
            //            System.out.println(chartPanel.getMousePosition().getY());
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonOpen;
    private javax.swing.JButton jButton_tidy;
    private javax.swing.JCheckBox jCheckBox_HP;
    private javax.swing.JCheckBox jCheckBox_LP;
    private javax.swing.JCheckBox jCheckBox_Temprature;
    private javax.swing.JCheckBox jCheckBox_humidity;
    private javax.swing.JCheckBox jCheckBox_num;
    private javax.swing.JCheckBox jCheckBox_reserved1;
    private javax.swing.JCheckBox jCheckBox_reserved2;
    private javax.swing.JCheckBox jCheckBox_reserved3;
    private javax.swing.JCheckBox jCheckBox_time;
    private javax.swing.JFormattedTextField jFormattedTextField_temp;
    private javax.swing.JPanel jPanel_Control;
    private javax.swing.JPanel jPanel_Show;
    // End of variables declaration//GEN-END:variables

}