/Users/16484/Desktop/IA_Final_Submission_0003070061/Product/IA_Netbeans_Project/src/ia/prototype/shubha/n/MainGUI.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.prototype.shubha.n;
7
8 import java.util.*;
9 import javax.swing.JFormattedTextField;
10 import org.jdatepicker.impl.*;
11
12 /**
13 *
14 * @author 16484
15 */
16 public class MainGUI extends javax.swing.JFrame implements Runnable
17 {
18
19 /**
20 * Creates new form MainGUI
21 */
22 private ArrayList<Reminder> reminder;
23 int counter = 0;
24 JDatePanelImpl datePanel;
25 JDatePickerImpl datePicker;
26
27 /*
28 Pre conditions
29 - The application is oppened and initiated.
30 Post Conditions
31 - The applications has begun running.
32 - The calendar format for the date selection is also set up for the user to use.
33 */
34 public MainGUI() {
35
36
37 initComponents();
38
39
40 Thread T = new Thread(this);
41 T.start(); // calls the run method which will keep running in the background
42 reminder = new ArrayList <Reminder>();
43 UtilCalendarModel model = new UtilCalendarModel();
44 Properties P = new Properties();
45 P.put("text.today", "Today");
46 P.put("text.month", "Month");
47 P.put("text.Year", "Year");
48 datePanel = new JDatePanelImpl(model, P);
49 datePicker = new JDatePickerImpl(datePanel, new DateLabelFormatter());
50 //this.add(datePicker);
51 PDate.add(datePicker);
52 datePicker.setSize(150, 100);
53 addHourTime(); // Code to add hour and mins to combos
54 }
55
56 /**
57 * This method is called from within the constructor to initialize the form.
58 * WARNING: Do NOT modify this code. The content of this method is always
59 * regenerated by the Form Editor.
60 */
61 @SuppressWarnings("unchecked")
62
812
813 private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
814 System.exit(0);
815 }
816
817 private void jTabbedPane5MouseClicked(java.awt.event.MouseEvent evt) {
818 // TODO add your handling code here:
819 // get All reminders from the Database into this arrayList
820 reminder = Reminder.getAllReminders();
821 refreshDisplayTable();
822 }
823
824 private void jTabbedPane5FocusGained(java.awt.event.FocusEvent evt) {
825 // TODO add your handling code here:
826 }
827
828 private void searchTFActionPerformed(java.awt.event.ActionEvent evt) {
829 // TODO add your handling code here:
830 }
831
832 private void sortByNameButtonActionPerformed(java.awt.event.ActionEvent evt) {
833 // TODO add your handling code here:
834 }
835 /*
836 Pre conditions
837 - Sort by Name mouse is released
838 - An existing list of Reminders are presented in the table.
839 Post Conditions
840 - The list of Reminders are sorted alphabetically by name (A-Z) in the table.
841 */
842 private void sortByNameButtonMouseReleased(java.awt.event.MouseEvent evt) {
843 // TODO add your handling code here:
844 for (int i = 0; i < counter; i++) {
845 if (reminder.get(i).getName().equals("")) {
846 reminder.get(i).setName("zzz");
847 }
848 }
849 SortAndSearch sortClass = new SortAndSearch();
850 sortClass.sortByName(reminder);
851 for (int i = 0; i < counter; i++) {
852 System.out.println(reminder.get(i).getName());
853 }
854 refreshDisplayTable();
855 for (int i = 0; i < reminder.size(); i++) {
856 if (reminder.get(i).getName().equals("zzz")) {
857 reminder.get(i).setName("");
858 }
859 }
860 }
861
862 private void sortByCategoryButtonActionPerformed(java.awt.event.ActionEvent evt) {
863 // TODO add your handling code here:
864 }
865
866 /*
867 Pre conditions
868 - Sort by Category mouse is released
869 - An existing list of Reminders are presented in the table.
870 Post Conditions
871 - The list of Reminders are sorted alphabetically (A-Z) in order of the category in the table.
872 - Remidners in the same category are displayed together.
873 */
874 private void sortByCategoryButtonMouseReleased(java.awt.event.MouseEvent evt) {
875 // TODO add your handling code here:
876 for (int i = 0; i < reminder.size(); i++) {
877 if (reminder.get(i).getCategory().equals("")) {
878 reminder.get(i).setCategory("zzz");
879 }
880 }
881 SortAndSearch sortClass = new SortAndSearch();
882 sortClass.sortByCategory(reminder);
883 for (int i = 0; i < reminder.size(); i++) {
884 System.out.println(reminder.get(i).getCategory());
885 }
886 refreshDisplayTable();
887 for (int i = 0; i < reminder.size(); i++) {
888 if (reminder.get(i).getCategory().equals("zzz")) {
889 reminder.get(i).setCategory("");
890 }
891 }
892 }
893
894 private void othersRBActionPerformed(java.awt.event.ActionEvent evt) {
895 // TODO add your handling code here:
896 }
897
898 private void addReminderButtonActionPerformed(java.awt.event.ActionEvent evt) {
899 // TODO add your handling code here:
900 }
901
902 /*
903 Pre Conditions:
904 - The information for the new Reminder is filled out by the user.
905 Post Conditions:
906 - A new Reminder is created with the in input from the user, stored in the database, and can be seen in the display table.
907 */
908
909 private void addReminderButtonMouseReleased(java.awt.event.MouseEvent evt) {
910 // TODO add your handling code here:
911 String name = nameTF.getText();
912 String category;
913 if (workRB.isSelected()) {
914 category = workRB.getText();
915 } else if (personalRB.isSelected()) {
916 category = personalRB.getText();
917 } else if (legalAndBillRB.isSelected()) {
918 category = legalAndBillRB.getText();
919 } else if (meetingAndConferencesRB.isSelected()) {
920 category = meetingAndConferencesRB.getText();
921 } else {
922 category = othersRB.getText();
923 }
924
925 Calendar dt = (Calendar) datePicker.getModel().getValue();
926 // to get the time
927 int hour = Integer.parseInt(cmbHour.getSelectedItem().toString());
928 int min = Integer.parseInt(cmbMin.getSelectedItem().toString());
929 System.out.println("Hour : " + hour + " Minute: " + min);
930 //dt.setLenient(Calendar.);
931 dt.set(Calendar.HOUR_OF_DAY, hour);
932 dt.set(Calendar.MINUTE, min);
933
934 new Reminder(name, category, dt);
935
936 nameTF.setText("");
937 workRB.setSelected(false);
938 personalRB.setSelected(false);
939 legalAndBillRB.setSelected(false);
940 meetingAndConferencesRB.setSelected(false);
941 othersRB.setSelected(false);
942 nameTF.requestFocus();
943 }
944
945 private void meetingAndConferencesRBActionPerformed(java.awt.event.ActionEvent evt) {
946 // TODO add your handling code here:
947 }
948
949 private void personalRBActionPerformed(java.awt.event.ActionEvent evt) {
950 // TODO add your handling code here:
951 }
952
953 private void internationalTimeTF2ActionPerformed(java.awt.event.ActionEvent evt) {
954 // TODO add your handling code here:
955 }
956
957 private void internationalTimeTFActionPerformed(java.awt.event.ActionEvent evt) {
958 // TODO add your handling code here:
959 }
960
961 private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
962 // TODO add your handling code here:
963 }
964
965 private void timeZoneComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
966 // TODO add your handling code here:
967 }
968
969 /*
970 Pre Conditions:
971 - A new Reminder is added or a change is made to the order in the display table.
972 Post Conditions:
973 - The Reminders are displayed in the new, updated order or format.
974 */
975
976 private void refreshDisplayTable() {
977 for ( int x = 0; x<50; x++)
978 for ( int y=0;y<4;y++)
979 displayTable.setValueAt(" ", x, y);
980
981 int rowToOverWrite = 0;
982 for (int i = 0; i < reminder.size(); i++) {
983 if (reminder.get(i).getName() != "") {
984 displayTable.setValueAt(reminder.get(i).getName(), rowToOverWrite, 0);
985 Calendar date = reminder.get(i).getDateTime();
986 String dt = date.get(Calendar.DATE) + "-" + (date.get(Calendar.MONTH) + 1) + "-" + date.get(Calendar.YEAR);
987 String tm = date.get(Calendar.HOUR_OF_DAY) + ":" + date.get(Calendar.MINUTE);
988
989 System.out.println(dt + "\t" + tm);
990 displayTable.setValueAt(dt, rowToOverWrite, 1);
991 displayTable.setValueAt(tm, rowToOverWrite, 2);
992 displayTable.setValueAt(reminder.get(i).getCategory(), rowToOverWrite, 3);
993
994 rowToOverWrite++;
995 }
996 }
997 }
998
999 /**
1000 * @param args the command line arguments
1001 */
1002 public static void main(String args[]) {
1003 /* Set the Nimbus look and feel */
1004 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
1005 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
1006 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
1007 */
1008 try {
1009 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
1010 if ("Nimbus".equals(info.getName())) {
1011 javax.swing.UIManager.setLookAndFeel(info.getClassName());
1012 break;
1013 }
1014 }
1015 } catch (ClassNotFoundException ex) {
1016 java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
1017 } catch (InstantiationException ex) {
1018 java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
1019 } catch (IllegalAccessException ex) {
1020 java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
1021 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
1022 java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
1023 }
1024 //</editor-fold>
1025
1026 /* Create and display the form */
1027 java.awt.EventQueue.invokeLater(new Runnable() {
1028 public void run() {
1029 new MainGUI().setVisible(true);
1030 }
1031 });
1032 }
1033
1034 /*
1035 Pre Conditions:
1036 - The Reminder time is being selected by the user.
1037 Post Conditions:
1038 - The possible timings (in the correct forattt) are provided to the user in the GUI.
1039 */
1040
1041 private void addHourTime() {
1042 for (int i = 0; i <= 23; i++) {
1043 String str = String.format("%02d", i);
1044 cmbHour.addItem(str);
1045 }
1046 for (int i = 0; i <= 59; i++) {
1047 String str = String.format("%02d", i);
1048 cmbMin.addItem(str);
1049 }
1050
1051 }
1052
1053 @Override
1054 public void run()
1055 {
1056 while(true)
1057 {
1058 checkAndSendMail();
1059 }
1060 }
1061
1062 /*
1063 Pre Conditions:
1064 - There are existing Reminders in the program.
1065 Post Conditions:
1066 - The sends an email to the user with any Reminders for events on that day.
1067 */
1068 private void checkAndSendMail() {
1069 ArrayList<Reminder> reminders = Reminder.getTodayReminders();
1070 if ( reminders.size() != 0)
1071 {
1072 String msg = " ";
1073 for ( Reminder R : reminders )
1074 {
1075 // REMEMBER TO TURN ON "Low security App access for gmail a/c"
1076 msg += "\n Reminder : " + R.getName() + " Date :" +
1077 R.getDate() + " Time: " + R.getTime() ;
1078 }
1079
1080 SendMail.send(msg);
1081 }
1082
1083
1084 }
SAMPLE OF NETBEANS CODE
// <editor-fold defaultstate="collapsed" desc="Generated Code">
63 private void initComponents() {
64
65 categoryLabel = new javax.swing.JLabel();
101 workRB = new javax.swing.JRadioButton();
102 personalRB = new javax.swing.JRadioButton();
103 legalAndBillRB = new javax.swing.JRadioButton();
104 meetingAndConferencesRB = new javax.swing.JRadioButton();
105 enterDateLabel = new javax.swing.JLabel();
106 enterTimeLabel = new javax.swing.JLabel();
107 addReminderButton = new javax.swing.JButton();
108 othersRB = new javax.swing.JRadioButton();
109 PDate = new javax.swing.JPanel();
110 cmbMin = new javax.swing.JComboBox<>();
111 cmbHour = new javax.swing.JComboBox<>();
112 enterDateLabel1 = new javax.swing.JLabel();
113 enterDateLabel2 = new javax.swing.JLabel();
114 jPanel16 = new javax.swing.JPanel();
115 jScrollPane1 = new javax.swing.JScrollPane();
116 displayTable = new javax.swing.JTable();
117 sortByCategoryButton = new javax.swing.JButton();
118 sortByNameButton = new javax.swing.JButton();
119 searchLabel = new javax.swing.JLabel();
120 searchTF = new javax.swing.JTextField();
121 searchButton = new javax.swing.JButton();
122 menuBar = new javax.swing.JMenuBar();
123 fileMenu = new javax.swing.JMenu();
124 openMenuItem = new javax.swing.JMenuItem();
125 saveMenuItem = new javax.swing.JMenuItem();
126 saveAsMenuItem = new javax.swing.JMenuItem();
127 exitMenuItem = new javax.swing.JMenuItem();
128 editMenu = new javax.swing.JMenu();
129 cutMenuItem = new javax.swing.JMenuItem();
130 copyMenuItem = new javax.swing.JMenuItem();
131 pasteMenuItem = new javax.swing.JMenuItem();
132 deleteMenuItem = new javax.swing.JMenuItem();
133 helpMenu = new javax.swing.JMenu();
134 contentsMenuItem = new javax.swing.JMenuItem();
135 aboutMenuItem = new javax.swing.JMenuItem();
136
137 jTabbedPane2.addTab("International to Local", jPanel11);
352
353 javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
354 jPanel3.setLayout(jPanel3Layout);
355 jPanel3Layout.setHorizontalGroup(
356 jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
357 .addGroup(jPanel3Layout.createSequentialGroup()
358 .addGap(35, 35, 35)
359 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
360 .addGroup(jPanel3Layout.createSequentialGroup()
361 .addComponent(jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
362 .addContainerGap(23, Short.MAX_VALUE))
363 .addGroup(jPanel3Layout.createSequentialGroup()
364 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
365 .addComponent(selectTimeZoneLabel)
366 .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
367 .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
368 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
369 .addGroup(jPanel3Layout.createSequentialGroup()
370 .addGap(39, 39, 39)
371 .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)
372 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
373 .addComponent(addTimeButton))
374 .addGroup(jPanel3Layout.createSequentialGroup()
375 .addGap(80, 80, 80)
376 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
377 .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
378 .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
379 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
380 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
381 .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
382 .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
383 .addGap(44, 44, 44))))
384 );
385 jPanel3Layout.setVerticalGroup(
386 jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
387 .addGroup(jPanel3Layout.createSequentialGroup()
388 .addGap(19, 19, 19)
389 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
390 .addComponent(addTimeButton)
391 .addComponent(selectTimeZoneLabel)
392 .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
393 .addGap(18, 18, 18)
394 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
395 .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
396 .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
397 .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
398 .addGap(46, 46, 46)
399 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
400 .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
401 .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
402 .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
403 .addGap(31, 31, 31)
404 .addComponent(jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
405 .addContainerGap(44, Short.MAX_VALUE))
406 );
407
408 jTabbedPane1.addTab("Clock", jPanel3);
409
410 // Variables declaration - do not modify
1087 private javax.swing.JPanel PDate;
1088 private javax.swing.JMenuItem aboutMenuItem;
1089 private javax.swing.JButton addReminderButton;
1090 private javax.swing.JButton addTimeButton;
1091 private javax.swing.ButtonGroup buttonGroup1;
1092 private javax.swing.JLabel categoryLabel;
1093 private javax.swing.JComboBox<String> cmbHour;
1094 private javax.swing.JComboBox<String> cmbMin;
1095 private javax.swing.JMenuItem contentsMenuItem;
1096 private javax.swing.JMenuItem copyMenuItem;
1106 private javax.swing.JMenuItem exitMenuItem;
1142 private javax.swing.JMenuItem pasteMenuItem;
1143 private javax.swing.JRadioButton personalRB;
1144 private javax.swing.JMenuItem saveAsMenuItem;
1145 private javax.swing.JMenuItem saveMenuItem;
1146 private javax.swing.JButton searchButton;
1147 private javax.swing.JLabel searchLabel;
1148 private javax.swing.JTextField searchTF;
1149 private javax.swing.JComboBox<String> selectCountryComboBox;
1150 private javax.swing.JLabel selectCountryLabel;
1151 private javax.swing.JLabel selectTimeZoneLabel;
1152 private javax.swing.JButton sortByCategoryButton;
1153 private javax.swing.JButton sortByNameButton;
1154 private javax.swing.JComboBox<String> timeZoneComboBox;
1155 private javax.swing.JComboBox<String> timeZoneComboBox2;
1156 private javax.swing.JLabel timeZoneLabel;
1157 private javax.swing.JRadioButton workRB;
1158 // End of variables declaration
1159
1160 }
1161