/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

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

/**
 *
 * @author mryu
 */
public class GraderMasterPanel extends javax.swing.JPanel {

    /**
     * Creates new form NewGraderUI
     */
    public GraderMasterPanel() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        courseTabbedPane = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        gradeBookTable = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        statsTable = new javax.swing.JTable();
        trendGraphsPanel = new javax.swing.JPanel();
        quickMenuPanel = new javax.swing.JPanel();
        addNewButton = new javax.swing.JButton();
        selectCategoryCombo = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jComboBox2 = new javax.swing.JComboBox();
        jButton3 = new javax.swing.JButton();

        gradeBookTable.addMouseListener(tableMouseListener);
        gradeBookTable.getTableHeader().addMouseListener(headerMouseListener);
        gradeBookTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Name", "ID", "Capstone", "Final Exam", "Percent", "Letter"},
                {"John Doe", "00000001", 0, 0, "0%", "F"},
                {"Jane Doe", "00000002", 0, 0, "0%", "F"}
            },
            new String [] {
                "Student", "Student", "Project", "Test", "Grade", "Grade"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Object.class,
                java.lang.Object.class, java.lang.Object.class,
                java.lang.Object.class, java.lang.Object.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
       jScrollPane1.setViewportView(gradeBookTable);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
       jPanel3.setLayout(jPanel3Layout);
       jPanel3Layout.setHorizontalGroup(
             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(jPanel3Layout.createSequentialGroup()
                         .addContainerGap()
                         .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 726, Short.MAX_VALUE)
                         .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                  .addContainerGap())
        );

       statsTable.setModel(new javax.swing.table.DefaultTableModel(
             new Object[][]{
                   {"Median", "", 0, 0, "0%", "F"},
                   {"Mean", "", 0, 0, "0%", "F"},
                   {"Min", "", 0, 0, "0%", "F"},
                   {"Max", "", 0, 0, "0%", "F"},
             },
             new String[]{
                   "Statistics", "", "Project", "Test",
                   "Percent Grade", " Letter Grade"
            }
        ));
       jScrollPane2.setViewportView(statsTable);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
       jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                  .addComponent(jScrollPane2)
                  .addContainerGap())
        );
       jPanel4Layout.setVerticalGroup(
             jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                         .addContainerGap()
                         .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                         .addContainerGap())
        );

       trendGraphsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Trend Graphs"));

        javax.swing.GroupLayout trendGraphsPanelLayout = new javax.swing.GroupLayout(trendGraphsPanel);
        trendGraphsPanel.setLayout(trendGraphsPanelLayout);
        trendGraphsPanelLayout.setHorizontalGroup(
              trendGraphsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGap(0, 151, Short.MAX_VALUE)
        );
        trendGraphsPanelLayout.setVerticalGroup(
              trendGraphsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGap(0, 0, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
       jPanel2.setLayout(jPanel2Layout);
       jPanel2Layout.setHorizontalGroup(
             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(jPanel2Layout.createSequentialGroup()
                         .addContainerGap()
                         .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                               .addGroup(jPanel2Layout.createSequentialGroup()
                                     .addGap(6, 6, 6)
                                     .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                               .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addComponent(trendGraphsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                         .addContainerGap())
        );
       jPanel2Layout.setVerticalGroup(
             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(jPanel2Layout.createSequentialGroup()
                         .addContainerGap()
                         .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                               .addComponent(trendGraphsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                               .addGroup(jPanel2Layout.createSequentialGroup()
                                     .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                     .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                         .addContainerGap())
       );

       courseTabbedPane.addTab("(Untitled Course)", jPanel2);

       quickMenuPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Quick Menu"));

       addNewButton.setText("Add New");
       addNewButton.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
             addNewButtonActionPerformed(evt);
            }
        });

        selectCategoryCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Category ..." }));
        selectCategoryCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
               selectCategoryComboActionPerformed(evt);
            }
        });

        jButton2.setText("Publish Grades");

       jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Seletect Target ...", "to Students", "to School" }));
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });

       jButton3.setText("View Assignment Submissions");
       jButton3.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout quickMenuPanelLayout = new javax.swing.GroupLayout(quickMenuPanel);
        quickMenuPanel.setLayout(quickMenuPanelLayout);
        quickMenuPanelLayout.setHorizontalGroup(
              quickMenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(quickMenuPanelLayout.createSequentialGroup()
                          .addComponent(addNewButton)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                          .addComponent(selectCategoryCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addGap(45, 45, 45)
                          .addComponent(jButton2)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                          .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                          .addComponent(jButton3)
                          .addContainerGap())
        );
        quickMenuPanelLayout.setVerticalGroup(
              quickMenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, quickMenuPanelLayout.createSequentialGroup()
                          .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                          .addGroup(quickMenuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(addNewButton)
                                .addComponent(selectCategoryCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton2)
                                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton3))
                          .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(courseTabbedPane, javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(quickMenuPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(quickMenuPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(courseTabbedPane)
                  .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void selectCategoryComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectCategoryComboActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_selectCategoryComboActionPerformed

    private void addNewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addNewButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_addNewButtonActionPerformed

    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed




    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addNewButton;
    private javax.swing.JTabbedPane courseTabbedPane;
    private javax.swing.JTable gradeBookTable;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel quickMenuPanel;
    private javax.swing.JComboBox selectCategoryCombo;
    private javax.swing.JTable statsTable;
    private javax.swing.JPanel trendGraphsPanel;
    // End of variables declaration//GEN-END:variables


   private static final int ASMT_ROW = 0;

   private static final int NAME_COL = 0;
   private static final int EMPL_ID_COL = 1;
   private static final int PROJ_COL = 2;
   private static final int TEST_COL = 3;

   private JPopupMenu contextMenu = new JPopupMenu("Context Menu");

   /* Listener to respond to mouse clicks on the table */
   private MouseAdapter tableMouseListener = new MouseAdapter()
   {
      public void mouseReleased(MouseEvent ev)
      {
         // obtain the selected cell coordinates
         int col = gradeBookTable.columnAtPoint(ev.getPoint());
         int row = gradeBookTable.rowAtPoint(ev.getPoint());
         // Is it a right mouse click?
         if (SwingUtilities.isRightMouseButton(ev))
         {
            // System.out.println("right click");
            // System.out.println("row, col = " + row + ", " + col);
            if (row == ASMT_ROW && (col == PROJ_COL || col == TEST_COL)) {
               contextMenu = new JPopupMenu("Context: Assignment");
               for (JMenuItem item : new AssignmentMenuItems().
                     getContextMenuItems()) {
                  contextMenu.add(item);
               }
               contextMenu.show(ev.getComponent(), ev.getX(), ev.getY());
            }
            else if (row != ASMT_ROW && (col == NAME_COL ||
                  col == EMPL_ID_COL)) {
               contextMenu = new JPopupMenu("Context: Student");
               for (JMenuItem item : new StudentMenuItems().
                     getContextMenuItems()) {
                  contextMenu.add(item);
               }
               contextMenu.show(ev.getComponent(), ev.getX(), ev.getY());
            }
         }
         repaint();
      }
   };

   /* Listener to respond to mouse clicks on the table */
   private MouseAdapter headerMouseListener = new MouseAdapter()
   {
      public void mouseReleased(MouseEvent ev)
      {
         // obtain the selected cell coordinates
         int col = gradeBookTable.columnAtPoint(ev.getPoint());
         // Is it a right mouse click?
         if (SwingUtilities.isRightMouseButton(ev))
         {
            if (col == PROJ_COL || col == TEST_COL) {
               contextMenu = new JPopupMenu("Context: Category");
               for (JMenuItem item : new AssignmentMenuItems().
                     getCategoryContextMenuItems()) {
                  contextMenu.add(item);
               }
               contextMenu.show(ev.getComponent(), ev.getX(), ev.getY());
            }
         }
         repaint();
      }
   };
}