package tools;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;

import main.ChronoPanel;

import signals.Signals;

public class VertLines {

	private int Xstart, Xend, startNum, endNum;
	private Signals s;
	
	public VertLines(Signals s, int Xstart, int Xend, int startNum, int endNum){
		this.s=s;
		this.Xstart=Xstart;
		this.Xend=Xend;
		this.startNum=startNum;
		this.endNum=endNum;
	}
	
	public void draw(Graphics g, ChronoPanel chrono){
		Graphics2D g2 = (Graphics2D)g;
		float dash1[] = {5.0f};
		Stroke dashed = new BasicStroke(1.0f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER,10.0f,dash1, 0.0f);
		g2.setStroke(dashed);
		g2.setColor(new Color(150,150,150));
		
		for (int index=0; index<=(Xend-Xstart)/s.widthUnit; index++){
			boolean inTimeLapse=false;
			
			// Test if there is a time lapse (to avoid drawing into it)
			for (int i=0; i<chrono.nbrTimeLapse; i++){
				for (int j=0; j<3; j++){
					if ((Xstart+index*s.widthUnit)-Signals.leftSpace>chrono.timeLapse[i][0] && (Xstart+index*s.widthUnit)-Signals.leftSpace<chrono.timeLapse[i][3]) inTimeLapse=true;
				}
			}
			
			if (!inTimeLapse){
				// Rising edge
				if (s.wave[index]==0 && s.wave[index+1]==1) g.drawLine(Xstart+index*s.widthUnit, (startNum+1)*(Signals.Yspace+Signals.heightUnit), Xstart+index*s.widthUnit, endNum*(Signals.Yspace+Signals.heightUnit)+5);
			}
		}
		
		g2.setColor(Color.black);
		g2.setStroke(new BasicStroke(1));
	}
}
