package transformation.su_transformationplugin.listeners;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JCheckBox;

public class CheckBoxListener implements ActionListener {
	
	Component[] components;
	
	/**
	 * Stores references for the components of a panel showing partial association tags
	 * 
	 * @param components Components of the panel containing checkboxes
	 */
	public CheckBoxListener(Component[] components) {
		this.components = components;
	}

	@Override
	/**
	 * If a checkbox is selected, this method de-selects all other checkboxes
	 */
	public void actionPerformed(ActionEvent action) {
	
		for (Component component : components) {
			JCheckBox checkBox = (JCheckBox) component;
			
			if (checkBox.isSelected() && checkBox != action.getSource()) {
				checkBox.setSelected(false);
			}
		}

	}

}
