package action;

import glycoMain.EnzymeProperties;

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.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;
	
	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;
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public ClearAction(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){
		this.areaInput = areaInput;
		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(){
		
		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();
	}
	

}
