C:\Users\Man\Desktop\IA_FinaL_Submission_000307-0092\Product\IA_Netbeans_Project\src\ia\man\Planner.java
  1 /*
  2  * To change this license header, choose License Headers in Project Properties.
  3  * To change this template file, choose Tools | Templates
  4  * and open the template in the editor.
  5  */
  6 package ia.man;
  7 
  8 import java.awt.BorderLayout;
  9 import java.awt.Color;
 10 import java.awt.Component;
 11 import java.awt.Dimension;
 12 import java.awt.Toolkit;
 13 import java.io.BufferedReader;
 14 import java.io.BufferedWriter;
 15 import java.io.File;
 16 import java.io.FileNotFoundException;
 17 import java.io.FileReader;
 18 import java.io.FileWriter;
 19 import java.io.IOException;
 20 import static java.lang.System.in;
 21 import java.text.DateFormat;
 22 import java.text.SimpleDateFormat;
 23 import java.time.DayOfWeek;
 24 import java.time.LocalDate;
 25 import java.time.YearMonth;
 26 import java.time.format.DateTimeFormatter;
 27 import java.time.format.TextStyle;
 28 import java.time.temporal.WeekFields;
 29 import java.util.Date;
 30 import java.util.Locale;
 31 import java.util.Objects;
 32 import java.util.logging.Level;
 33 import java.util.logging.Logger;
 34 import javax.swing.BorderFactory;
 35 import javax.swing.ButtonGroup;
 36 import javax.swing.JButton;
 37 import javax.swing.JFrame;
 38 import javax.swing.JLabel;
 39 import javax.swing.JOptionPane;
 40 import javax.swing.JPanel;
 41 import javax.swing.JScrollPane;
 42 import javax.swing.JTable;
 43 import javax.swing.ListSelectionModel;
 44 import javax.swing.SwingConstants;
 45 import javax.swing.UIManager;
 46 import javax.swing.UnsupportedLookAndFeelException;
 47 import javax.swing.WindowConstants;
 48 import javax.swing.event.ListSelectionListener;
 49 import javax.swing.table.DefaultTableCellRenderer;
 50 import javax.swing.table.DefaultTableModel;
 51 import javax.swing.table.JTableHeader;
 52 
 53 /**
 54  *
 55  * @author 14868
 56  */
 57 
 58 public class Planner extends javax.swing.JFrame {
 59 
 60     /**
 61      * Creates new form Planner
 62      */
 63     User iUser = new User();
 64     
 65     private Planner() {
 66         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
 67     }
 68     
 69     public Planner(String id,String user,String email,String pass) {
 70         
 71         initComponents();
 72         
 73         iUser.AssingValue(id, user, email, pass);
 74         
 75         Toolkit toolkit = getToolkit();
 76         Dimension size = toolkit.getScreenSize();
 77         setLocation(size.width/2 - getWidth()/2, size.height/2 - getHeight()/2);
 78         
 79         setDefaultCloseOperation(Register.DISPOSE_ON_CLOSE); //Close only this form
 80         
 81         ButtonGroup rgroup = new ButtonGroup();
 82         rgroup.add(trivialRadioButton);
 83         rgroup.add(moderateRadioButton);
 84         rgroup.add(urgentRadioButton);
 85         
 86         monthTable.setDefaultRenderer(LocalDate.class, new CalendarTableRenderer());
 87         monthTable.setRowHeight(30);  
 88         
 89         tbTaskList.getColumnModel().getColumn(0).setMaxWidth(50);
 90         tbTaskList.getColumnModel().getColumn(0).setMinWidth(50);
 91         tbTaskList.getColumnModel().getColumn(0).setWidth(50);
 92         tbTaskList.getColumnModel().getColumn(0).setPreferredWidth(50);  
 93         
 94         tbTaskList.getColumnModel().getColumn(7).setMaxWidth(0);
 95         tbTaskList.getColumnModel().getColumn(7).setMinWidth(0);
 96         tbTaskList.getColumnModel().getColumn(7).setWidth(0);
 97         tbTaskList.getColumnModel().getColumn(7).setPreferredWidth(0);  
 98         
 99         updateMonthView(realLocalDate);
100         
101         LocalDate ld = (LocalDate) monthTable.getValueAt(monthTable.getSelectedRow(), monthTable.getSelectedColumn());
102         DateFormat dateFormat = new SimpleDateFormat("MM-dd");
103         DateFormat yearFormat = new SimpleDateFormat("yyyy");
104         Date date = new Date();
105         
106         String year = yearFormat.format(date);
107         int bc_year = Integer.parseInt(year) - 543;
108          
109         String Current_Date = String.valueOf(bc_year) + "-" + dateFormat.format(date); 
110         
111         lblDate.setText(Current_Date);
112         getTask(Current_Date);
113         
114         txtId.setVisible(false);
115         
116     }
117 
424     private void trivialRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                   
425         // TODO add your handling code here:
426     }                                                  
427 
428     private void dateTFActionPerformed(java.awt.event.ActionEvent evt) {                                       
429         // TODO add your handling code here:
430     }                                      
431 
432     private void addTaskButtonMouseClicked(java.awt.event.MouseEvent evt) {                                           
433         try {
434             addTask();
435         } catch (IOException ex) {
436             Logger.getLogger(Planner.class.getName()).log(Level.SEVERE, null, ex);
437         }
438     }                                          
439 
440     private void prevMouseClicked(java.awt.event.MouseEvent evt) {                                  
441       // TODO add your handling code here:
442       updateMonthView(getCurrentLocalDate().minusMonths(1));
443     }                                 
444 
445     private void nextMouseClicked(java.awt.event.MouseEvent evt) {                                  
446         // TODO add your handling code here:
447         updateMonthView(getCurrentLocalDate().plusMonths(1));
448     }                                 
449 
450     private void monthTableMouseClicked(java.awt.event.MouseEvent evt) {                                        
451         // TODO add your handling code here:
452         
453         LocalDate ld = (LocalDate) monthTable.getValueAt(monthTable.getSelectedRow(), monthTable.getSelectedColumn());
454         lblDate.setText(ld.toString());
455         dateTF.setText(ld.toString());
456         getTask(ld.toString());
457         
458     }                                       
459 
460     private void tbTaskListMouseClicked(java.awt.event.MouseEvent evt) {                                        
461         // TODO add your handling code here:
462         
463         String ID = tbTaskList.getValueAt(tbTaskList.getSelectedRow(),7).toString();
464         getTaskbyID(ID);
465         
466     }                                       
467 
468     private void deleteButtonMouseClicked(java.awt.event.MouseEvent evt) {                                          
469         try {
470             deleteTask();
471         } catch (IOException ex) {
472             Logger.getLogger(Planner.class.getName()).log(Level.SEVERE, null, ex);
473         }
474     }                                         
475 
476     private void finishedTaskButtonMouseClicked(java.awt.event.MouseEvent evt) {                                                
477         try {
478             finishTask();
479         } catch (IOException ex) {
480             Logger.getLogger(Planner.class.getName()).log(Level.SEVERE, null, ex);
481         }
482     }                                               
483 
484     /*
485      * @param args the command line arguments
486      */
487     public final LocalDate realLocalDate = LocalDate.now();
488     //private final JLabel dateLabel = new JLabel(realLocalDate.toString(), SwingConstants.CENTER);
489     private final JLabel monthLabel = new JLabel("", SwingConstants.CENTER);
490     //private final JTable monthTable = new JTable();
491     private LocalDate currentLocalDate;
492 
493     public LocalDate getCurrentLocalDate() {
494       return currentLocalDate;
495     }
496 
497     public void updateMonthView(LocalDate localDate) {
498       currentLocalDate = localDate;
499       monthLabel.setText(localDate.format(DateTimeFormatter.ofPattern("YYYY / MM").withLocale(Locale.getDefault())));
500       monthTable.setModel(new CalendarViewTableModel(localDate));
501     }
502 
503     private void tbTaskList(String[][] data, String[] header) {
504         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
505     }
506 
507     private class CalendarTableRenderer extends DefaultTableCellRenderer {
508       @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focused, int row, int column) {
509         super.getTableCellRendererComponent(table, value, selected, focused, row, column);
510         setHorizontalAlignment(SwingConstants.CENTER);
511         if (value instanceof LocalDate) {
512           LocalDate d = (LocalDate) value;
513           setText(Objects.toString(d.getDayOfMonth()));
514           if (YearMonth.from(d).equals(YearMonth.from(getCurrentLocalDate()))) {
515             setForeground(Color.BLACK);
516           } else {
517             setForeground(Color.GRAY);
518           }
519           DayOfWeek dow = d.getDayOfWeek();
520           if (d.isEqual(realLocalDate)) {
521             setBackground(new Color(220, 255, 220));
522           } else if (dow == DayOfWeek.SUNDAY) {
523             setBackground(new Color(255, 220, 220));
524           } else if (dow == DayOfWeek.SATURDAY) {
525             setBackground(new Color(220, 220, 255));
526           } else {
527             setBackground(Color.WHITE);
528           }
529         }
530         return this;
531       }
532     }
533     
534     public static void main(String args[]) {
535         /* Set the Nimbus look and feel */
536         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
537         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
538          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
539          */
540         try {
541             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
542                 if ("Nimbus".equals(info.getName())) {
543                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
544                     break;
545                 }
546             }
547         } catch (ClassNotFoundException ex) {
548             java.util.logging.Logger.getLogger(Planner.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
549         } catch (InstantiationException ex) {
550             java.util.logging.Logger.getLogger(Planner.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
551         } catch (IllegalAccessException ex) {
552             java.util.logging.Logger.getLogger(Planner.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
553         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
554             java.util.logging.Logger.getLogger(Planner.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
555         }
556         //</editor-fold>
557         //</editor-fold>
558 
559         /* Create and display the form */
560         java.awt.EventQueue.invokeLater(new Runnable() {
561             public void run() {
562                 new Planner().setVisible(true);
563             }
564         });
565       
566     }
567     
568     public void addTask() throws FileNotFoundException, IOException{
569         
570         String path = "Planner.txt";
571         
572         String urgency = "";
573         
574         if(trivialRadioButton.isSelected()){
575             urgency = "Trivial";
576         }else if(moderateRadioButton.isSelected()){
577             urgency = "Moderate";
578         }else if(urgentRadioButton.isSelected()){
579             urgency = "Urgent";
580         }
581         
582         String taskRegister = addTaskTF.getText();
583         String dateOfTask = dateTF.getText();
584         
585         int timeStart = timeFromComboBox.getSelectedIndex();
586         int timeEnd = timeToComboBox.getSelectedIndex();
587                 
588         BufferedReader reader = new BufferedReader(new FileReader("Planner.txt"));
589         int id = 0;
590         while (reader.readLine() != null) id++;
591         id += 1;
592         reader.close();
593         
594         File file = new File(path);
595             FileWriter writer;
596             try {               
597                     writer = new FileWriter(file, true);  //True = Append to file, false = Overwrite
598                     writer.write(String.valueOf(id));
599                     writer.write("|");
600                     writer.write(iUser.getID());
601                     writer.write("|");
602                     writer.write(dateOfTask);
603                     writer.write("|");
604                     writer.write(String.valueOf(timeStart));
605                     writer.write("|");
606                     writer.write(String.valueOf(timeEnd));
607                     writer.write("|");
608                     writer.write(urgency);
609                     writer.write("|");
610                     writer.write(taskRegister);
611                     writer.write("|");
612                     writer.write("No");
613                     
614 //                    writer.write("|"); // tab seperates the different components
615 //                    writer.write(emailRegister);
616 //                    writer.write("|");
617 //                    writer.write(passwordRegister);
618                    writer.write("\n");
619                     writer.close();
620                     System.out.println("Write success!");
621                     
622                     int m = JOptionPane.showConfirmDialog(
623                         null,
624                         "Save Complete",
625                         "Alert",
626                     JOptionPane.YES_NO_OPTION);
627                     
628                     //String Current_Date = String.valueOf(bc_year) + "-" + dateFormat.format(date); 
629                     //lblDate.setText(Current_Date);
630                     getTask(dateOfTask);
631                     
632                 } catch (IOException e) {
633                     // TODO Auto-generated catch block
634                     e.printStackTrace();
635                 }
636     }
637     
638     
639     public void getTask(String pDate)
640     {
641 
642         String path = "Planner.txt";
643         
644         File file = new File(path);
645         
646         String line = null,
647                id = null, 
648                userId = null,  
649                date = null,
650                startTime = null,
651                endTime = null,
652                urgency = null,
653                task_name = null,
654                status = null;
655                
656         try {
657           
658             BufferedReader br = new BufferedReader(new FileReader(file));
659             DefaultTableModel model = (DefaultTableModel)tbTaskList.getModel();
660             model.setRowCount(0);
661             
662             int i = 0;
663             while ((line = br.readLine()) != null) 
664             {
665                 
666                 String[] array = line.split("\\|"); 
667                 
668                 id = array[0];
669                 userId = array[1];
670                 date = array[2];
671                 
672                 startTime = getTimeComboBox(Integer.parseInt(array[3]));
673                 endTime = getTimeComboBox(Integer.parseInt(array[4]));
674                 
675                 urgency = array[5];
676                 task_name = array[6];
677                 status = array[7];
678                 
679                 if(date.equals(pDate))
680                 {
681                     model.addRow(new Object[0]);
682                     model.setValueAt(i+1, i, 0);
683                     model.setValueAt(date, i, 1);
684                     model.setValueAt(startTime, i, 2);
685                     model.setValueAt(endTime, i, 3);
686                     model.setValueAt(urgency, i, 4);
687                     model.setValueAt(task_name, i, 5);
688                     model.setValueAt(status, i, 6);
689                     model.setValueAt(id, i, 7);
690                     
691                     i++;
692                 }
693                 
694                 array = null;
695                 
696             }
697             
698             br.close();
699             
700         } catch (IOException e) {
701             e.printStackTrace();
702         }
703         
704     }
705     
706     
707     public void getTaskbyID(String ID)
708     {
709 
710         String path = "Planner.txt";
711         
712         File file = new File(path);
713         
714         Boolean trivialVal = false,
715                 moderateVal = false,
716                 urgentVal = false;
717         
718         String line = null,
719                id = null, 
720                userId = null,  
721                date = null,
722                urgency = null,
723                task_name = null,
724                status = null;
725                
726         int    startTime = 0,
727                endTime = 0;
728                 
729         try {
730           
731             BufferedReader br = new BufferedReader(new FileReader(file));
732 
733             while ((line = br.readLine()) != null) 
734             {
735                 
736                 String[] array = line.split("\\|"); 
737                 
738                 id = array[0];
739                 userId = array[1];
740                 date = array[2];
741                 startTime = Integer.parseInt(array[3]);
742                 endTime = Integer.parseInt(array[4]);
743                 urgency = array[5];
744                 task_name = array[6];
745                 status = array[7];
746                 
747                 
748                 if(id.equals(ID))
749                 {
750                     txtId.setText(id);
751                     addTaskTF.setText(task_name);
752                     dateTF.setText(date);
753                     
754                     if(urgency.equals("Trivial"))
755                     {
756                         trivialVal = true;
757                     } 
758                     else if(urgency.equals("Moderate"))
759                     {
760                         moderateVal = true;
761                     } 
762                     else 
763                     {
764                         urgentVal = true;
765                     }
766         
767                     trivialRadioButton.setSelected(trivialVal);
768                     moderateRadioButton.setSelected(moderateVal);
769                     urgentRadioButton.setSelected(urgentVal);
770                     timeFromComboBox.setSelectedIndex(startTime);
771                     timeToComboBox.setSelectedIndex(endTime);
772                     
773                 }
774                 
775                 array = null;
776                 
777             }
778             
779             br.close();
780             
781         } catch (IOException e) {
782             // TODO Auto-generated catch block
783             e.printStackTrace();
784         }
785         
786     }
787     
788     
789     public String getTimeComboBox(int id)
790     {
791         String timeReturn = "";
792         
793         String[] array = {
794                           "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", 
795                           "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00",
796                           "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", 
797                           "21:00", "22:00", "23:00"
798                          };
799 
800         timeReturn = array[id];
801         return timeReturn;
802     }
803     
804     
805     public void deleteTask() throws IOException
806     {
807         String line = null,
808                id = null;
809         
810         String pFileOld = "Planner.txt";
811         String pFileTemp = "Planner_temp.txt";
812         
813         id = txtId.getText();
814         
815         int n = JOptionPane.showConfirmDialog(
816             null,
817             "Delete Task ?",
818             "Alert",
819             JOptionPane.YES_NO_OPTION);
820         
821         if(n==0)
822         {
823             File FileOld = new File(pFileOld);
824             File FileTemp = new File(pFileTemp);
825             BufferedWriter bw = new BufferedWriter( new FileWriter(FileTemp) );
826             BufferedReader br = new BufferedReader( new FileReader(FileOld) );
827             while((line = br.readLine()) != null) 
828             {  
829                 String[] arrFile = line.split("\\|"); 
830                 
831                 if(!arrFile[0].equals(id)) 
832                 {
833                     bw.write(line);     
834                     bw.flush();
835                     bw.newLine();
836                 }
837             }
838             
839             bw.close();
840             br.close(); 
841             
842             FileOld.delete();
843             boolean success = FileTemp.renameTo(FileOld);
844         }
845         
846         getTask(lblDate.getText());
847         
848     }
849     
850     
851     public void finishTask() throws IOException
852     {
853         String line = null,
854                id = null;
855         
856         String pFileOld = "Planner.txt";
857         String pFileTemp = "Planner_temp.txt";
858         
859         id = txtId.getText();
860         
861         String urgency = "";
862         
863         if(trivialRadioButton.isSelected()){
864             urgency = "Trivial";
865         }else if(moderateRadioButton.isSelected()){
866             urgency = "Moderate";
867         }else if(urgentRadioButton.isSelected()){
868             urgency = "Urgent";
869         }
870         
871         String taskRegister = addTaskTF.getText();
872         String dateOfTask = dateTF.getText();
873         
874         int timeStart = timeFromComboBox.getSelectedIndex();
875         int timeEnd = timeToComboBox.getSelectedIndex();   
876         
877         int n = JOptionPane.showConfirmDialog(
878             null,
879             "Finish Task ?",
880             "Alert",
881             JOptionPane.YES_NO_OPTION);
882         //System.out.print(n); // Use n for response
883         
884         if(n==0)
885         {
886             File FileOld = new File(pFileOld);
887             File FileTemp = new File(pFileTemp);
888             
889             BufferedWriter bw = new BufferedWriter( new FileWriter(FileTemp) );
890             BufferedReader br = new BufferedReader( new FileReader(FileOld) );
891             
892             while((line = br.readLine()) != null) 
893             {   
894                 String[] arrFile = line.split("\\|"); 
895                 
896                 if(arrFile[0].equals(id)) 
897                 {
898                     bw.write(id+"|"+iUser.getID()+"|"+dateOfTask+"|"+String.valueOf(timeStart)+"|"+String.valueOf(timeEnd)+"|"+urgency+"|"+taskRegister+"|Yes");
899                 }
900                 else
901                 {
902                     bw.write(line);     
903                 }                       
904                 bw.flush();
905                 bw.newLine();
906             }
907             
908             bw.close();
909             br.close(); 
910             
911             FileOld.delete();
912             boolean success = FileTemp.renameTo(FileOld);
913             
914             getTask(lblDate.getText());
915 
916         }
917     }
918     
919     
920     // Variables declaration - do not modify                     
921     private javax.swing.JButton addTaskButton;
922     private javax.swing.JTextField addTaskTF;
923     private javax.swing.JLabel dateLabel;
924     private javax.swing.JTextField dateTF;
925     private javax.swing.JButton deleteButton;
926     private javax.swing.JButton finishedTaskButton;
927     private javax.swing.JPanel jPanel1;
928     private javax.swing.JPanel jPanel2;
929     private javax.swing.JScrollPane jScrollPane1;
930     private javax.swing.JScrollPane jScrollPane2;
931     private javax.swing.JLabel lblDate;
932     private javax.swing.JRadioButton moderateRadioButton;
933     private javax.swing.JTable monthTable;
934     private javax.swing.JButton next;
935     private javax.swing.JPanel p;
936     private javax.swing.JButton prev;
937     private javax.swing.JTable tbTaskList;
938     private javax.swing.JComboBox<String> timeFromComboBox;
939     private javax.swing.JLabel timeLabel;
940     private javax.swing.JLabel timeLabel1;
941     private javax.swing.JComboBox<String> timeToComboBox;
942     private javax.swing.JRadioButton trivialRadioButton;
943     private javax.swing.JTextField txtId;
944     private javax.swing.JLabel urgencyLabel;
945     private javax.swing.JRadioButton urgentRadioButton;
946     // End of variables declaration                   
947 }
948 
949 
950 class CalendarViewTableModel extends DefaultTableModel {
951     
952   private final LocalDate startDate;
953   private final WeekFields weekFields = WeekFields.of(Locale.getDefault());
954 
955   protected CalendarViewTableModel(LocalDate date) {
956     super();
957     LocalDate firstDayOfMonth = YearMonth.from(date).atDay(1); // date.with(TemporalAdjusters.firstDayOfMonth());
958     // int dowv = firstDayOfMonth.get(WeekFields.SUNDAY_START.dayOfWeek()) - 1;
959     int dowv = firstDayOfMonth.get(weekFields.dayOfWeek()) - 1;
960     startDate = firstDayOfMonth.minusDays(dowv);
961   }
962 
963   @Override public Class<?> getColumnClass(int column) {
964     return LocalDate.class;
965   }
966 
967   @Override public String getColumnName(int column) {
968     return weekFields.getFirstDayOfWeek().plus(column)
969       .getDisplayName(TextStyle.SHORT_STANDALONE, Locale.getDefault());
970   }
971 
972   @Override public int getRowCount() {
973     return 6;
974   }
975 
976   @Override public int getColumnCount() {
977     return 7;
978   }
979 
980   @Override public Object getValueAt(int row, int column) {
981     return startDate.plusDays(row * getColumnCount() + column);
982   }
983 
984   @Override public boolean isCellEditable(int row, int column) {
985     return false;
986   }
987   
988 }
989 
990 
991 
992 
SAMPLE OF NETBEANS GENERATED CODE 118 /** 119 * This method is called from within the constructor to initialize the form. 120 * WARNING: Do NOT modify this code. The content of this method is always 121 * regenerated by the Form Editor. 122 */ 123 @SuppressWarnings("unchecked") 124 // <editor-fold defaultstate="collapsed" desc="Generated Code"> 125 private void initComponents() { 126 127 p = new javax.swing.JPanel(); 128 prev = new javax.swing.JButton(); 129 next = new javax.swing.JButton(); 130 jScrollPane1 = new javax.swing.JScrollPane(); 131 monthTable = new javax.swing.JTable(); 132 lblDate = new javax.swing.JLabel(); 133 jPanel1 = new javax.swing.JPanel(); 134 jScrollPane2 = new javax.swing.JScrollPane(); 135 tbTaskList = new javax.swing.JTable(); 136 jPanel2 = new javax.swing.JPanel(); 137 addTaskTF = new javax.swing.JTextField(); 138 urgencyLabel = new javax.swing.JLabel(); 139 trivialRadioButton = new javax.swing.JRadioButton(); 140 moderateRadioButton = new javax.swing.JRadioButton(); 141 urgentRadioButton = new javax.swing.JRadioButton(); 142 timeLabel = new javax.swing.JLabel(); 143 timeFromComboBox = new javax.swing.JComboBox<>(); 144 timeToComboBox = new javax.swing.JComboBox<>(); 145 dateLabel = new javax.swing.JLabel(); 146 dateTF = new javax.swing.JTextField(); 147 finishedTaskButton = new javax.swing.JButton(); 148 addTaskButton = new javax.swing.JButton(); 149 timeLabel1 = new javax.swing.JLabel(); 150 deleteButton = new javax.swing.JButton(); 151 txtId = new javax.swing.JTextField(); 152 153 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 154 155 prev.setText("<"); 156 prev.addMouseListener(new java.awt.event.MouseAdapter() { 157 public void mouseClicked(java.awt.event.MouseEvent evt) { 158 prevMouseClicked(evt); 159 } 160 }); 161 162 next.setText(">"); 163 next.addMouseListener(new java.awt.event.MouseAdapter() { 164 public void mouseClicked(java.awt.event.MouseEvent evt) { 165 nextMouseClicked(evt); 166 } 167 }); 168 169 monthTable.setModel(new javax.swing.table.DefaultTableModel( 170 new Object [][] { 171 {null, null, null, null}, 172 {null, null, null, null}, 173 {null, null, null, null}, 174 {null, null, null, null} 175 }, 176 new String [] { 177 "Title 1", "Title 2", "Title 3", "Title 4" 178 } 179 )); 180 monthTable.addMouseListener(new java.awt.event.MouseAdapter() { 181 public void mouseClicked(java.awt.event.MouseEvent evt) { 182 monthTableMouseClicked(evt); 183 } 184 }); 185 jScrollPane1.setViewportView(monthTable); 186 187 lblDate.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); 188 lblDate.setText("jLabel1"); 189 190 tbTaskList.setModel(new javax.swing.table.DefaultTableModel( 191 new Object [][] { 192 {null, null, null, null, null, null, null, null}, 193 {null, null, null, null, null, null, null, null}, 194 {null, null, null, null, null, null, null, null}, 195 {null, null, null, null, null, null, null, null} 196 }, 197 new String [] { 198 "No", "Date", "Time from", "Time to", "Urgency", "Task Name", "Done?", "ID" 199 } 200 ) { 201 boolean[] canEdit = new boolean [] { 202 true, true, true, true, true, true, true, false 203 }; 204 205 public boolean isCellEditable(int rowIndex, int columnIndex) { 206 return canEdit [columnIndex]; 207 } 208 }); 209 tbTaskList.addMouseListener(new java.awt.event.MouseAdapter() { 210 public void mouseClicked(java.awt.event.MouseEvent evt) { 211 tbTaskListMouseClicked(evt); 212 } 213 }); 214 jScrollPane2.setViewportView(tbTaskList); 215 216 javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 217 jPanel1.setLayout(jPanel1Layout); 218 jPanel1Layout.setHorizontalGroup( 219 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 220 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() 221 .addContainerGap(20, Short.MAX_VALUE) 222 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 668, javax.swing.GroupLayout.PREFERRED_SIZE) 223 .addContainerGap()) 224 ); 225 jPanel1Layout.setVerticalGroup( 226 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 227 .addGroup(jPanel1Layout.createSequentialGroup() 228 .addContainerGap() 229 .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE) 230 .addGap(16, 16, 16)) 231 ); 232 233 addTaskTF.setText("Add Task Here"); 234 235 urgencyLabel.setText("Urgency"); 236 237 trivialRadioButton.setText("Trivial"); 238 trivialRadioButton.addActionListener(new java.awt.event.ActionListener() { 239 public void actionPerformed(java.awt.event.ActionEvent evt) { 240 trivialRadioButtonActionPerformed(evt); 241 } 242 }); 243 244 moderateRadioButton.setText("Moderate"); 245 246 urgentRadioButton.setText("Urgent"); 247 248 timeLabel.setText("Start Time"); 249 250 timeFromComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00" })); 251 252 timeToComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00" })); 253 254 dateLabel.setText("Date"); 255 256 dateTF.setText("yy-mm-dd"); 257 dateTF.addActionListener(new java.awt.event.ActionListener() { 258 public void actionPerformed(java.awt.event.ActionEvent evt) { 259 dateTFActionPerformed(evt); 260 } 261 }); 262 263 finishedTaskButton.setText("Finished"); 264 finishedTaskButton.addMouseListener(new java.awt.event.MouseAdapter() { 265 public void mouseClicked(java.awt.event.MouseEvent evt) { 266 finishedTaskButtonMouseClicked(evt); 267 } 268 }); 269 270 addTaskButton.setText("Add"); 271 addTaskButton.addMouseListener(new java.awt.event.MouseAdapter() { 272 public void mouseClicked(java.awt.event.MouseEvent evt) { 273 addTaskButtonMouseClicked(evt); 274 } 275 }); 276 277 timeLabel1.setText("End Time"); 278 279 deleteButton.setText("Delete"); 280 deleteButton.addMouseListener(new java.awt.event.MouseAdapter() { 281 public void mouseClicked(java.awt.event.MouseEvent evt) { 282 deleteButtonMouseClicked(evt); 283 } 284 }); 285 286 javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); 287 jPanel2.setLayout(jPanel2Layout); 288 jPanel2Layout.setHorizontalGroup( 289 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 290 .addGroup(jPanel2Layout.createSequentialGroup() 291 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 292 .addGroup(jPanel2Layout.createSequentialGroup() 293 .addComponent(addTaskButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE) 294 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 295 .addComponent(deleteButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 296 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 297 .addComponent(finishedTaskButton, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)) 298 .addGroup(jPanel2Layout.createSequentialGroup() 299 .addComponent(dateLabel) 300 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 301 .addComponent(dateTF, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)) 302 .addGroup(jPanel2Layout.createSequentialGroup() 303 .addComponent(timeLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE) 304 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 305 .addComponent(timeToComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)) 306 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() 307 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 308 .addGroup(jPanel2Layout.createSequentialGroup() 309 .addComponent(timeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 310 .addGap(30, 30, 30)) 311 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() 312 .addComponent(urgencyLabel) 313 .addGap(108, 108, 108))) 314 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 315 .addComponent(trivialRadioButton) 316 .addComponent(urgentRadioButton) 317 .addComponent(timeFromComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE) 318 .addComponent(moderateRadioButton))) 319 .addComponent(addTaskTF)) 320 .addContainerGap()) 321 ); 322 jPanel2Layout.setVerticalGroup( 323 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 324 .addGroup(jPanel2Layout.createSequentialGroup() 325 .addContainerGap() 326 .addComponent(addTaskTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 327 .addGap(14, 14, 14) 328 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 329 .addComponent(urgencyLabel) 330 .addComponent(trivialRadioButton)) 331 .addGap(1, 1, 1) 332 .addComponent(moderateRadioButton) 333 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 334 .addComponent(urgentRadioButton) 335 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 336 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 337 .addComponent(timeFromComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 338 .addComponent(timeLabel)) 339 .addGap(7, 7, 7) 340 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 341 .addComponent(timeLabel1) 342 .addComponent(timeToComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 343 .addGap(21, 21, 21) 344 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 345 .addComponent(dateLabel) 346 .addComponent(dateTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 347 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 348 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 349 .addComponent(finishedTaskButton) 350 .addComponent(addTaskButton) 351 .addComponent(deleteButton)) 352 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 353 ); 354 355 javax.swing.GroupLayout pLayout = new javax.swing.GroupLayout(p); 356 p.setLayout(pLayout); 357 pLayout.setHorizontalGroup( 358 pLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 359 .addGroup(pLayout.createSequentialGroup() 360 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 361 .addGap(0, 0, Short.MAX_VALUE)) 362 .addGroup(pLayout.createSequentialGroup() 363 .addGap(22, 22, 22) 364 .addGroup(pLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 365 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE) 366 .addGroup(pLayout.createSequentialGroup() 367 .addComponent(prev) 368 .addGap(18, 18, 18) 369 .addComponent(lblDate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 370 .addGap(18, 18, 18) 371 .addComponent(next))) 372 .addGap(18, 18, 18) 373 .addGroup(pLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 374 .addGroup(pLayout.createSequentialGroup() 375 .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE) 376 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 377 .addGroup(pLayout.createSequentialGroup() 378 .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 379 .addGap(16, 16, 16)))) 380 ); 381 pLayout.setVerticalGroup( 382 pLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 383 .addGroup(pLayout.createSequentialGroup() 384 .addGroup(pLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 385 .addGroup(pLayout.createSequentialGroup() 386 .addContainerGap() 387 .addGroup(pLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) 388 .addComponent(prev, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 389 .addGroup(pLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 390 .addComponent(next, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 391 .addComponent(lblDate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) 392 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 393 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE) 394 .addGap(0, 0, Short.MAX_VALUE)) 395 .addGroup(pLayout.createSequentialGroup() 396 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 397 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 398 .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) 399 .addGap(18, 18, 18) 400 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 401 .addContainerGap()) 402 ); 403 404 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 405 getContentPane().setLayout(layout); 406 layout.setHorizontalGroup( 407 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 408 .addGroup(layout.createSequentialGroup() 409 .addGap(19, 19, 19) 410 .addComponent(p, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 411 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 412 ); 413 layout.setVerticalGroup( 414 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 415 .addGroup(layout.createSequentialGroup() 416 .addContainerGap() 417 .addComponent(p, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 418 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 419 ); 420 421 pack(); 422 }// </editor-fold> 423