package edu.school.groups;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import net.miginfocom.swing.MigLayout;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.AbstractListModel;
import javax.swing.ButtonGroup;
import javax.swing.ListSelectionModel;
import javax.swing.border.MatteBorder;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import java.awt.Button;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
 * Информатика, 8 клас, издателство Просвета, 2017
 * Автори: Светла Бойчева, Николина Николова, Елиза Стефанова, Антон Денев
 * Урок 3.4.1.3. Списъчно поле
 * Задача: След приема на ученици в профил „Информатика“
 * в 8. клас, те трябва да се разделят на две групи — А и Б за обучението
 * си по предмета. За да бъдат двете групи равнопоставени,
 * училището решило да използва списъка от класирането и последователно
 * да записва първия ученик от него в група А, втория — в група Б, третия — в А и
 * т.н. всеки нечетен пореден номер — в група А, а всеки четен — в група Б.
 * Създайте приложение Groups с ГПИ, което показва списъка на приетите ученици. 
 * Приложението трябва да позволява на потребителя да избере групата, от която се
 * интересува, и да извежда списък на учениците, записани в нея.
 * 
 * Вариант 0. Допълнете решението!
 */

public class GroupsForm extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GroupsForm frame = new GroupsForm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public GroupsForm() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setForeground(new Color(0, 102, 153));
		contentPane.setBackground(new Color(255, 255, 204));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new MigLayout("", "[grow][][grow]", "[][][grow][]"));
		
		JLabel lblProfile = new JLabel("\u041F\u0440\u043E\u0444\u0438\u043B \"\u0418\u043D\u0444\u043E\u0440\u043C\u0430\u0442\u0438\u043A\u0430\"");
		lblProfile.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblProfile.setForeground(new Color(0, 102, 102));
		contentPane.add(lblProfile, "flowx,cell 0 0");
		
		JRadioButton rbtnGroupA = new JRadioButton("\u0413\u0440\u0443\u043F\u0430 \u0410");
		rbtnGroupA.setSelected(true);
		contentPane.add(rbtnGroupA, "flowx,cell 1 0");
		
		
		JRadioButton rbtnGroupB = new JRadioButton("\u0413\u0440\u0443\u043F\u0430 \u0411");
		contentPane.add(rbtnGroupB, "cell 2 0");
		
		JLabel lblListOfStudents = new JLabel("\u0421\u043F\u0438\u0441\u044A\u043A \u043D\u0430 \u0443\u0447\u0435\u043D\u0438\u0446\u0438\u0442\u0435");
		lblListOfStudents.setForeground(new Color(0, 102, 102));
		lblListOfStudents.setFont(new Font("Tahoma", Font.BOLD, 12));
		contentPane.add(lblListOfStudents, "cell 0 1");
		
		Button btnChoose = new Button("\u0418\u0437\u0431\u0435\u0440\u0438");
		btnChoose.setForeground(new Color(204, 204, 255));
		btnChoose.setBackground(new Color(0, 102, 102));
		contentPane.add(btnChoose, "cell 2 1,alignx right");
		
		JScrollPane scrlPaneStudents = new JScrollPane();
		scrlPaneStudents.setViewportBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
		contentPane.add(scrlPaneStudents, "cell 0 2,grow");
		
		JList<String> lstStudents = new JList<String>();
		lstStudents.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		lstStudents.setModel(new AbstractListModel<String>() {
			private static final long serialVersionUID = 1L;
			String[] values = new String[] {"\u0418\u0432\u0430\u043D\u0430 \u041F\u0435\u0442\u0440\u043E\u0432\u0430", "\u0421\u0442\u043E\u044F\u043D \u0410\u043B\u0435\u043A\u0441\u0430\u043D\u0434\u0440\u043E\u0432", "\u0418\u0432\u0435\u043B\u0438\u043D\u0430 \u041F\u0430\u0432\u043B\u043E\u0432\u0430", "\u041C\u0430\u043A\u0441\u0438\u043C \u0410\u0442\u0430\u043D\u0430\u0441\u043E\u0432", "\u0410\u043D\u0442\u043E\u043D \u0414\u0438\u043C\u0438\u0442\u0440\u043E\u0432", "\u041C\u0438\u0440\u0435\u043B\u0430 \u041D\u0438\u043A\u043E\u043B\u043E\u0432\u0430", "\u0411\u043E\u044F\u043D \u0421\u0442\u043E\u0435\u0432", "\u041C\u0430\u0440\u0438\u043D \u041F\u043E\u043F\u043E\u0432", "\u041A\u0430\u0442\u0435\u0440\u0438\u043D\u0430 \u041D\u0438\u043D\u043E\u0432\u0430", "\u0410\u043D\u0442\u043E\u043D \u0410\u043D\u0442\u043E\u043D\u043E\u0432", "\u041C\u0430\u0440\u0438\u0435\u043B\u0430 \u041D\u0438\u043A\u043E\u043B\u0430\u0435\u0432\u0430", "\u041D\u0438\u043A\u043E\u043B\u0430 \u0420\u0443\u0441\u0435\u0432", "\u041F\u0435\u0442\u044A\u0440 \u0414\u0438\u043C\u043E\u0432"};
			public int getSize() {
				return values.length;
			}
			public String getElementAt(int index) {
				return values[index];
			}
		});
		scrlPaneStudents.setViewportView(lstStudents);
		
		ButtonGroup btnGrGroupChosen = new ButtonGroup();
		btnGrGroupChosen.add(rbtnGroupA);
		btnGrGroupChosen.add(rbtnGroupB);
		
		JScrollPane scrlPaneGroup = new JScrollPane();
		contentPane.add(scrlPaneGroup, "cell 1 2 2 1,grow");
		
		JTextArea txaGroup = new JTextArea();
		scrlPaneGroup.setViewportView(txaGroup);
		
		Button btnExit = new Button("\u0418\u0437\u0445\u043E\u0434");
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		btnExit.setBackground(new Color(153, 0, 51));
		btnExit.setForeground(new Color(204, 204, 204));
		contentPane.add(btnExit, "cell 2 3,alignx right");;
	}

}
