package ui;
import dao.ResultDAO;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import model.Criterion;
public class CategoryPanel extends JPanel {
	public CategoryPanel(String category, List<Criterion> criteria) {
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		JLabel categoryHeading = new JLabel(category);
		Font headingFont = categoryHeading.getFont();
		headingFont = headingFont.deriveFont(Font.BOLD, (float) headingFont.getSize() + 3);
		categoryHeading.setFont(headingFont);
		// wrapping the heading label in a panel to force the box layout to make it full width
		JPanel headerPnl = new JPanel(new BorderLayout());
		headerPnl.add(categoryHeading, BorderLayout.CENTER);
		this.add(headerPnl);
		// add a some vertical padding
		this.add(Box.createVerticalStrut(5));
		ResultDAO dao = new ResultDAO();
		for (Criterion criterion : criteria) {
			CriterionPanel criterionEditor = new CriterionPanel(criterion);
			this.add(criterionEditor);
			this.add(Box.createVerticalStrut(15));
			dao.addEditor(criterion, criterionEditor);
		}
		// add a horizontal line for seperating categories
		JSeparator sep = new JSeparator();
		sep.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.add(sep);
		this.add(Box.createHorizontalStrut(5));
	}
}