package action;

import glycoMain.EnzymeProperties;
import gui.StructurePanel;

import java.awt.Color;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class ClearAction extends AbstractAction {

	JTextArea areaInput;
	JTextField file;
	JTextField id;
	ButtonGroup bgroup;
	DefaultListModel<String> list1;
	DefaultListModel<String> list2;
	JPanel jp;
	
	
	JTextArea areaOutput;
	JLabel matchingNumber;
	JButton matchUni;
	JCheckBox checkin;
	JCheckBox checkOut;
	JComboBox<String> comboIn;
	JComboBox<String> comboOut;
	JButton dispInOk;
	JButton dispOutOk;
	JCheckBox AllEnz;
	JCheckBox unknownLink;
	String[] enzyme;
	StructurePanel structurePanelInput;
	StructurePanel structurePanelOutput;
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public ClearAction(JPanel jp, JTextArea areaInput, JTextField file, JTextField id, ButtonGroup bgroup, DefaultListModel list1, DefaultListModel list2, 
			JTextArea areaOutput, JLabel matchingNumber, JButton matchUni, JCheckBox checkin, JCheckBox checkOut, JComboBox comboIn, JComboBox comboOut,
			JButton dispInOk, JButton dispOutOk, JCheckBox AllEnz, JCheckBox unknownLink, StructurePanel structurePanelInput, StructurePanel structurePanelOutput){
		this.areaInput = areaInput;
		this.structurePanelInput = structurePanelInput;
		this.structurePanelOutput = structurePanelOutput;
		this.jp = jp;
		this.file = file;
		this.id = id;
		this.bgroup = bgroup;
		this.list1 = list1;
		this.list2 = list2;
		this.areaOutput = areaOutput;
		this.matchingNumber = matchingNumber;
		this.matchUni = matchUni;
		this.checkin = checkin;
		this.checkOut = checkOut;
		this.comboIn = comboIn;
		this.comboOut = comboOut;
		this.dispInOk = dispInOk;
		this.dispOutOk = dispOutOk;
		this.AllEnz = AllEnz;
		this.unknownLink = unknownLink;	
		EnzymeProperties e = new EnzymeProperties();
		enzyme = e.getEnz_list();
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		clearAll();
	}
	
	public void clearAll(){
		
		structurePanelInput.removeAll();
		jp.remove(structurePanelInput);

		structurePanelOutput.removeAll();
		jp.remove(structurePanelOutput);
	
		areaInput.setText("");
		file.setText("");
		id.setText("");
		areaOutput.setText("");

		matchingNumber.setText("");
		matchUni.setText("Matching UnicarbKB");
		matchUni.setForeground(Color.black);

		list2.removeAllElements();

		if (unknownLink.isSelected())
			unknownLink.doClick();
		if (AllEnz.isSelected())
			AllEnz.doClick();
		list1.removeAllElements();
		for (int i=0; i<enzyme.length; i++)	{		
			list1.addElement(enzyme[i]);
		}
		comboIn.removeAllItems();
		if (checkin.isSelected()){
			checkin.doClick();
			comboIn.setVisible(false);
			dispInOk.setVisible(false);
		}
		comboOut.removeAllItems();
		if (checkOut.isSelected()){
			checkOut.doClick();
			comboOut.setVisible(false);
			dispOutOk.setVisible(false);
		}
		bgroup.clearSelection();
	}
	

}
