package br;

import java.awt.Dimension;  
import javax.swing.JPanel;  
import javax.swing.JList.DropLocation;

import org.jfree.chart.*;  
import org.jfree.chart.plot.PlotOrientation;  
import org.jfree.data.xy.*;  
import org.jfree.ui.ApplicationFrame;   
import org.jfree.ui.RefineryUtilities;

public class AutoVetores extends ApplicationFrame{
	
		static XYSeries xyseries;
		    
	   public AutoVetores(String s){
	       super(s);
	   }
	   
	   public void mostrarTela(){
		   XYDataset xydataset = createDataset();  
	       JFreeChart jfreechart = createChart(xydataset);  
	       ChartPanel chartpanel = new ChartPanel(jfreechart);  
	       chartpanel.setPreferredSize(new Dimension(500, 270));  
	       setContentPane(chartpanel);
	       
		   this.pack();  
	       RefineryUtilities.centerFrameOnScreen(this);  
	       this.setVisible(true);
	   }
	
	   public void addValueXYseries(float y, boolean apaga){
		   if (xyseries == null || apaga){
			   xyseries = new XYSeries("valores analgicos");
		   }else{
			   xyseries.add(xyseries.getItemCount(), y);
		   }
	   }
	   
	   private static JFreeChart createChart(XYDataset xydataset){  
	       JFreeChart jfreechart = ChartFactory.createXYLineChart("Dados analgicos", "tempo", "amplitude", xydataset, PlotOrientation.VERTICAL, true, true, false);  
	       return jfreechart;  
	   }  
	 
	
	   private static XYDataset createDataset(){
	 
		   XYSeriesCollection xy = new XYSeriesCollection();  
		   xy.addSeries(xyseries);  
	    
		   return xy;  
	   }  
	
	   
	   public static JPanel createDemoPanel(){  
	       JFreeChart jfreechart = createChart(createDataset());  
	       return new ChartPanel(jfreechart);  
	   }
}
