/* Author: Amay Agrawal
 * Project: Bacteria Cloud
 * Mentor: Prof. Manish K Gupta
 */
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Ellipse2D;
import java.io.*;

import javax.swing.JFrame;
import javax.swing.JPanel;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.*;

public class Circle2 extends JFrame
{
	static String final1;
	static String finalstring;
	static int ghj=0;
	//int arr[] = {24,29,187,229,233,375,410,566,626,651,716,832,939,974,1359,1369,1425,1426,1446,1581,1664,1672,2002,2066,2117,2220,2227,2246,2296,2357,2473,2889,3366,3538,3611,3736,3846,4170,4286}; 
    //String arr1[] = {"ClaI","HindIII","EcoRV","NheI","BmtI","BamHI","SgrAI","SphI","EcoNI","SalI","PshAI","BpmI","EagI","NruI",
    	//	          "BsmI","StyI","BsoBI","BmeT110I","MscI","Bpu10I","BspEI","BsaBI","BpmI","PvuII","PfoI","PflFI","BsaAI","BstZ17I","NdeI","BspQI","AflIII","AlwNI","AhdI","AseI","PstI","PvuI","ScaI","SspI","ZraI"};
	//int length = arr.length;
	
	public Circle2(String x,String y){final1=x;finalstring=y;}
	int count=0;
	int counter5=0;
	int counter6=0;
	int counter7=0;
	public void Circle21()
	{
		
		 this.getContentPane().setBackground(Color.black);
		setTitle("Bacteria Plasmid Storage System");
		setSize(1300,1200);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
	}
	
	
	//@Override
	public void paint(Graphics gg)
	{
		if(ghj<=1){
        	ghj++;
        super.paint(gg);
        }
		//super.paint(gg);
		String line10 = final1;
		System.out.println(line10);
		BufferedReader bufferedReader = null;
		String[] parts =line10.split("/");
		System.out.println(parts[1]);
		String line11 ="";
		for(int i=0;i<parts[1].length();i++){
			if(parts[1].charAt(i)=='.'){
				break;
			}
			else{
				line11+=parts[1].charAt(i);
			}
		}
		try {
			bufferedReader = new BufferedReader(new FileReader(line10));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String line;
		int tocount1=0;
		int tocount2=0;
		int tocount3=0;
		int tocount4=0;
		int tocount5=0;
		int tocount6=0;
		System.out.println("ddd "+final1);
		System.out.println(finalstring);
		String parts5[] = finalstring.split(" ");
		if(parts5.length==6){
			tocount1=Integer.parseInt(parts5[1]);
			tocount2=Integer.parseInt(parts5[2]);
			tocount3=Integer.parseInt(parts5[4]);
			tocount4=Integer.parseInt(parts5[5]);
			
		}
		else{
			tocount1=Integer.parseInt(parts5[1]);
			tocount2=Integer.parseInt(parts5[2]);
			tocount3=Integer.parseInt(parts5[4]);
			tocount4=Integer.parseInt(parts5[5]);
			tocount5=Integer.parseInt(parts5[7]);
			tocount6=Integer.parseInt(parts5[8]);
		}
		try {
			while ((line = bufferedReader.readLine()) != null){
				counter6++;
				//System.out.println("sdjkjk "+counter6);
				Graphics2D g = (Graphics2D) gg;
				g.setColor(Color.white);
				g.setFont(new Font("Times new Roman",Font.PLAIN,24));
				g.drawString("Plasmid ("+line11+") ",540,80);
				g.setFont(new Font("Times new Roman",Font.PLAIN,18));
				g.drawString(line11, 550, 375);
				g.drawString("length ("+line.length()+") bp",550,400);
				double u = 300*Math.cos(Math.toRadians((1/line.length())*360));
				double v = 300*Math.sin(Math.toRadians((1/line.length())*360));

				float w = (float) u;
				float e = (float) v;
 
				g.drawString("start", 625+w, 400+e );
				if(parts5.length==6){
					g.setColor(Color.cyan);
					g.drawString("cyan = "+parts5[0],550,425);
					g.drawString(parts5[0]+" = ( "+parts5[1]+" bp - "+parts5[2]+" bp )", 900, 600);
					g.setColor(Color.yellow);
					g.drawString("yellow = "+parts5[3],550,450);
					g.drawString(parts5[3]+" = ( "+parts5[4]+" bp - "+parts5[5]+" bp )", 900, 625);
					g.setColor(Color.red);
					g.drawString("red = other",550,475);
				}
				else if (parts5.length==9){
					g.setColor(Color.cyan);
					g.drawString("cyan = "+parts5[0],550,425);
					g.drawString(parts5[0]+" = ( "+parts5[1]+" bp - "+parts5[2]+" bp )", 900, 600);
					g.setColor(Color.yellow);
					g.drawString("yellow = "+parts5[3],550,450);
					g.drawString(parts5[3]+" = ( "+parts5[4]+" bp - "+parts5[5]+" bp )", 900, 625);
					g.setColor(Color.red);
					g.drawString("red = "+parts5[6],550,475);
					g.drawString(parts5[6]+" = ( "+parts5[7]+" bp - "+parts5[8]+" bp )", 900, 650);
					g.setColor(Color.white);
					g.drawString("white = other ",550,500);
				}
				for(int i=0;i<line.length();i++){
					if(parts5.length==6){
					counter5++;
					char abcd = line.charAt(i);
					if(counter5>=tocount1 && counter5<=tocount2){
						//g.setBackground(Color.YELLOW);
						g.setColor(Color.CYAN);
						//String check = Integer.toString(arr[i]);
						String check1 = Character.toString(abcd);
						double z = counter5;
						double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
						double y = 300*Math.sin(Math.toRadians((z/line.length())*360));

						float a = (float) x;
						float b = (float) y;
						
						/* Construct a shape and draw it */
						Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
						g.draw(shape);
						//g.fill(shape);
						//g.drawString(check1,600+ a, 400+b);
						
					}
					
					else if(counter5 >= tocount3 && counter5 <= tocount4){
						//g.setBackground(Color.YELLOW);
						g.setColor(Color.yellow);
						//String check = Integer.toString(arr[i]);
						String check1 = Character.toString(abcd);
						double z = counter5;
						double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
						double y = 300*Math.sin(Math.toRadians((z/line.length())*360));
						
						float a = (float) x;
						float b = (float) y;

						/* Construct a shape and draw it */
						Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
						g.draw(shape);
						//g.fill(shape);
						//g.drawString(check1,600+ a, 400+b);
					}
					
					else {
						//g.setBackground(Color.YELLOW);
						g.setColor(Color.red);
						//String check = Integer.toString(arr[i]);
						String check1 = Character.toString(abcd);
						double z = counter5;
						double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
						double y = 300*Math.sin(Math.toRadians((z/line.length())*360));
						
						float a = (float) x;
						float b = (float) y;

						/* Construct a shape and draw it */
						Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
						g.draw(shape);
						//g.fill(shape);
						//g.drawString(check1,600+ a, 400+b);
					}
					
				}
				else if(parts5.length==9){
					counter5++;
					char abcd = line.charAt(i);
					if(counter5>=tocount1 && counter5 <=tocount2){
						//g.setBackground(Color.YELLOW);
						g.setColor(Color.CYAN);
						//String check = Integer.toString(arr[i]);
						String check1 = Character.toString(abcd);
						double z = counter5;
						double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
						double y = 300*Math.sin(Math.toRadians((z/line.length())*360));

						float a = (float) x;
						float b = (float) y;
						
						/* Construct a shape and draw it */
						Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
						g.draw(shape);
						//g.fill(shape);
						//g.drawString(check1,600+ a, 400+b);
						
					}
					
					else if(counter5 >= tocount3 && counter5 <= tocount4){
						//g.setBackground(Color.YELLOW);
						g.setColor(Color.yellow);
						//String check = Integer.toString(arr[i]);
						String check1 = Character.toString(abcd);
						double z = counter5;
						double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
						double y = 300*Math.sin(Math.toRadians((z/line.length())*360));
						
						float a = (float) x;
						float b = (float) y;

						/* Construct a shape and draw it */
						Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
						g.draw(shape);
						//g.fill(shape);
						//g.drawString(check1,600+ a, 400+b);
					}
					
					else if(counter5>=tocount5 && counter5<=tocount6){
						//g.setBackground(Color.YELLOW);
						g.setColor(Color.red);
						//String check = Integer.toString(arr[i]);
						String check1 = Character.toString(abcd);
						double z = counter5;
						double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
						double y = 300*Math.sin(Math.toRadians((z/line.length())*360));
						
						float a = (float) x;
						float b = (float) y;

						/* Construct a shape and draw it */
						Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
						g.draw(shape);
						//g.fill(shape);
						//g.drawString(check1,600+ a, 400+b);
					}
					else{
						//g.setBackground(Color.YELLOW);
						g.setColor(Color.WHITE);
						//String check = Integer.toString(arr[i]);
						String check1 = Character.toString(abcd);
						double z = counter5;
						double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
						double y = 300*Math.sin(Math.toRadians((z/line.length())*360));
						
						float a = (float) x;
						float b = (float) y;

						/* Construct a shape and draw it */
						Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
						g.draw(shape);
						//g.fill(shape);
						//g.drawString(check1,600+ a, 400+b);
					}
				}
				}
				counter5=0;
				if(counter6 >= 1)
					break;
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
	/* Enable anti-aliasing and pure stroke */
	//g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	//g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

	}

	public void amay()
	{
		
		Circle21();
		
		this.paint(null);
		
	}
}