Newer
Older
marking / src / ui / MarkingFrame.java
Mark on 6 Jun 2014 1 KB Initial commit.
package ui;

import dao.ResultDAO;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import model.Criterion;

/**
 *
 * @author mark
 */
public class MarkingFrame extends JFrame {

	private String student;

	private final JPanel schedulePane;
	private final ResultDAO result = new ResultDAO();

	public MarkingFrame() {

		// add scroll pane to the root
		JScrollPane scrollPane = new JScrollPane();
		JPanel contentPane = new JPanel();

		scrollPane.setViewportView(contentPane);

		getContentPane().add(scrollPane, java.awt.BorderLayout.CENTER);

		// add other panes
		schedulePane = new JPanel();
		JPanel buttonPane = new JPanel();

		contentPane.setLayout(new BorderLayout());
		contentPane.add(schedulePane, BorderLayout.CENTER);
		contentPane.add(buttonPane, BorderLayout.SOUTH);

		schedulePane.setLayout(new BoxLayout(schedulePane, BoxLayout.Y_AXIS));

		// add buttons
		JButton btnSave = new JButton("Next");
		btnSave.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent ae) {
				save();
			}

		});

		buttonPane.add(btnSave);
	}

	public void addCategory(String category, List<Criterion> criteria) {
		schedulePane.add(new CategoryPanel(category, criteria));
	}

	private void save() {

		if (!result.isComplete()) {
			int res = JOptionPane.showConfirmDialog(MarkingFrame.this, "You haven't entered values for all criteria.  Are you sure you want to move on?");
			if (JOptionPane.YES_OPTION == res) {
				result.save(student);
				dispose();
			}
		} else {
			result.save(student);
			dispose();
		}
	}

	public void load(String student) {
		this.student = student;
		this.setTitle(student);
		result.load(student);
	}

	public void display() {
		this.pack();
		this.setVisible(true);
	}

}