/* Author: Amay Agrawal
 * Project: Bacteria Cloud
 * Mentor: Prof. Manish K Gupta
 */
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class OkActionListener implements ActionListener {

	static JComboBox<String> cb;
	static JComboBox<String> cb1;
	static JLabel label;
	static JLabel label1;
	
	static JFrame frame;
	static JPanel panel;
	static int length1000;
	
	public OkActionListener(JFrame ab,JPanel bc){
		frame = ab;
		panel = bc;
	}
	
	public OkActionListener(int gh){
		length1000 = gh;
	}
	
	public OkActionListener(JComboBox<String> clientCombo,JComboBox<String> clientCombo1){
		cb = clientCombo;
		cb1 = clientCombo1;
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		String display="";
		//System.out.println(cb.getSelectedItem().toString());
		String bc = cb.getSelectedItem().toString();
		String cd = cb1.getSelectedItem().toString();
		String fina1l = "Plasmids"+"/"+bc+".txt";
		String fina12 = "Plasmids"+"/"+bc+"1.txt";
		String fina13 = "Plasmids"+"/"+cd+".txt";
		System.out.println(fina13);
		McsActionListener m = new McsActionListener(fina1l,fina12,fina13);
		File f = new File(fina1l);
		String strline = "";
		BufferedReader br = null;
		try {
			br = new BufferedReader(new FileReader(f));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			while ((strline = br .readLine()) != null){
				display+=strline;
				System.out.println(strline);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		frame.remove(label);
//		frame.remove(label1);
		int length100001 = display.length();
		if(length100001<length1000-50){
			JOptionPane.showMessageDialog(null, "The selected plasmid don't have enough capacity to store data. Please reduce data content or try to choose another plasmid.");
			frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
		}
		frame.setLayout(new BorderLayout());
		JLabel label = new JLabel("Plasmid : "+bc);
		label.setLocation(20,320);
		label.setSize(1000, 14);
		label.setVisible(true);
		JLabel label1 = new JLabel("<html>"+display+"</html>",JLabel.CENTER);
		//label1.setLocation(20,220);
		//label1.setSize(1300, 14);
		//label1.setVisible(true);
        label1.setFont(new Font("Serif", Font.BOLD, 10));
		JScrollPane scroller = new JScrollPane(label1, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		scroller.setLocation(20,340);
		scroller.setSize(1300,50);
		scroller.setVisible(true);
		//scroller.setVerticalScrollBarPolicy(1);
		panel.add(label);
		panel.add(scroller);
		frame.getContentPane().add(panel);
		frame.validate();
        frame.repaint();
		JOptionPane.showMessageDialog(null, "You have selected "+bc+" plasmid and "+cd+" Restriction Enzyme Category.");
		//System.out.println(fina1l);
	}

}
