package action;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.DefaultListModel;
import javax.swing.JCheckBox;

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


	DefaultListModel<String> listModel1;
	DefaultListModel<String> listModel2;
	JCheckBox allEnzCheck;
	String[] enz_list;
	
	public AllEnzymeAction( final DefaultListModel<String> listModel1, final DefaultListModel<String> listModel2, JCheckBox allEnzCheck, String[] enz_list){
		this.enz_list = enz_list;
		this.listModel1 = listModel1;
		this.listModel2 = listModel2;
		this.allEnzCheck = allEnzCheck;
		
	}
	

	  public void actionPerformed(ActionEvent e){
		  
		  if (allEnzCheck.isSelected()){
			while (!listModel1.isEmpty()){
				if (listModel2.isEmpty())
					listModel2.addElement((String) listModel1.get(0));
				else{
					String lastElement = listModel2.getElementAt(listModel2.getSize()-1);
					listModel2.addElement( lastElement +"+"+ (String) listModel1.get(0));
				}
				listModel1.remove(0);
			}
		  }
		  else{
			  for (int i=0; i<enz_list.length; i++)
				  listModel1.addElement(enz_list[i]);
			  listModel2.removeAllElements();
		  }
	}

}