package gradertool.gradebook;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * NewClassDisplay
 */
public class ImportDisplay extends JFrame {
   /**
    * Construct this, per the design explained in the class comment.
    */
   public ImportDisplay() {
      JPanel outerBox = new JPanel();
      Box topBox = Box.createVerticalBox();
      Box buttonBox = Box.createHorizontalBox();
      Box nameBox = Box.createHorizontalBox();
      Box periodBox = Box.createHorizontalBox();
      Box listBox = Box.createHorizontalBox();
      
      topBox.setPreferredSize(new Dimension(400, 200));
      
      setContentPane(outerBox);
      
      buttonBox.setAlignmentX(Component.RIGHT_ALIGNMENT);
      nameBox.setAlignmentX(Component.RIGHT_ALIGNMENT);
      periodBox.setAlignmentX(Component.RIGHT_ALIGNMENT);
      listBox.setAlignmentX(Component.RIGHT_ALIGNMENT);
      
      // set up name box
      JLabel nameLabel = new JLabel("Class Name:  ");
      JTextField nameTextField = new JTextField();
      nameLabel.setForeground(Color.black);
      
      nameTextField.setPreferredSize(new Dimension(200, 25));
      
      nameBox.add(nameLabel);
      nameBox.add(nameTextField);
      nameBox.add(Box.createHorizontalStrut(50));
      
      // set up period box
      JLabel periodLabel = new JLabel("Period:  ");
      JComboBox periodComboBox = new JComboBox();
      periodLabel.setForeground(Color.black);
      periodComboBox.addItem("Winter 2013");
      periodComboBox.addItem("Fall 2012");
      periodComboBox.addItem("Summer 2012");
      periodComboBox.addItem("Spring 2012");
      periodComboBox.addItem("Winter 2012");
      periodComboBox.addItem("Fall 2011");
      
      periodComboBox.setPreferredSize(new Dimension(200, 25));
      
      periodBox.add(periodLabel);
      periodBox.add(periodComboBox);
      periodBox.add(Box.createHorizontalStrut(50));
      
      // set up list box
      JLabel listLabel = new JLabel("Classes:  ");
      DefaultListModel list = new DefaultListModel();
      list.addElement("CSC 308-01");
      list.addElement("CSC 308-02");
      list.addElement("CSC 308-03");
      list.addElement("CSC 308-04");
      list.addElement("CSC 101-01");
      list.addElement("CSC 101-02");
      JList classList = new JList(list);
      
      listBox.setPreferredSize(new Dimension(300, 150));
      
      listBox.add(listLabel);
      listBox.add(new JScrollPane(classList));
      
      // set up buttons box (left to right)
      Button buttonCancel = new Button("Cancel");
      buttonCancel.setMaximumSize(new Dimension(100, 35));
      buttonBox.add(buttonCancel);
      
      Button buttonImport = new Button("Import");
      buttonImport.setMaximumSize(new Dimension(100, 35));
      buttonBox.add(buttonImport);
      
      // set up login box (top to bottom)
      topBox.add(Box.createVerticalStrut(5));
      topBox.add(nameBox);
      topBox.add(Box.createVerticalStrut(5));
      topBox.add(periodBox);
      topBox.add(Box.createVerticalStrut(5));
      topBox.add(listBox);
      topBox.add(Box.createVerticalStrut(5));
      topBox.add(buttonBox);
      topBox.add(Box.createVerticalStrut(5));
      
      
      
      // set up outer box (top to bottom)
      outerBox.add(Box.createHorizontalStrut(20));
      outerBox.add(topBox);
      
      setTitle("Import Class");
      
      cancelButtonAction(buttonCancel);
      importButtonAction(buttonImport);
      
      pack();
   }

   /**
    * Add the 'Cancel' button.
    */
   protected void cancelButtonAction(Button buttonCancel) {
      buttonCancel.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            NewClassUI newClassUI = new NewClassUI();
            newClassUI.getNewClassDisplay().setVisible(true);
            setVisible(false);
         }
      });
   }

   /**
    * Add the 'Import' button.
    */
   protected void importButtonAction(Button buttonImport) {
      buttonImport.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            NewClassUI newClassUI = new NewClassUI();
            newClassUI.getSISDisplay().setVisible(true);
            setVisible(false);
            
            newClassUI.getSISDisplay().start();
         }
      });
   }
}