-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskManagementSystem.java
More file actions
1041 lines (899 loc) · 35.7 KB
/
taskManagementSystem.java
File metadata and controls
1041 lines (899 loc) · 35.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package taskManagementSystem;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.awt.*;
import java.awt.TrayIcon.MessageType;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Calendar;
import java.util.Date;
import com.k33ptoo.components.KButton;
import com.k33ptoo.components.KGradientPanel;
import com.toedter.calendar.*;
public class taskManagementSystem {
public taskManagementSystem (){
//Components BGCOLOR
Color compBgColor = new Color(178,176,176);
//Current Date and Time
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd ; HH:mm");
String currentDateTime = sdf.format(cal.getTime());
//Welcome Frame
JFrame wFrame = new JFrame ("Task Management System");
wFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
wFrame.setSize(860,490);
wFrame.setLocation(360, 150);
ImageIcon wpImage = new ImageIcon("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\welcomePage.png");
JLabel welcomePage = new JLabel (wpImage);
welcomePage.setBounds(-5, 0, 860, 490);
Image img =wpImage.getImage();
Image imgScale = img.getScaledInstance(welcomePage.getWidth(), welcomePage.getHeight(), Image.SCALE_SMOOTH);
ImageIcon scaledIcon = new ImageIcon (imgScale);
//welcomePage Design
KButton continues = new KButton();
continues.setText("CONTINUE");
continues.setBounds(40, 340, 270, 50);
continues.setkBorderRadius(50);
continues.setBorderPainted(false);
continues.setkStartColor(new Color(246,234,65));
continues.setkEndColor(new Color(119,0,127));
wFrame.add(continues);
welcomePage.setIcon(scaledIcon);
wFrame.add(welcomePage);
wFrame.setUndecorated(true);
//Main GUI frame
JFrame frame = new JFrame ("Task Management System");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
frame.setSize(1060,690);
frame.setLocation(250, 50);
frame.setUndecorated(true);
//Main Frame Design
ImageIcon bgImage = new ImageIcon("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\BG1.png");
JLabel bgImageContainer = new JLabel(bgImage);
bgImageContainer.setBounds(0,0,1060,720);
//Edit Task Frame Design
JLabel bgImageContainer2 = new JLabel(bgImage);
bgImageContainer2.setBounds(0,0,680,620);
//Add Task Frame Design
ImageIcon bgImage2 = new ImageIcon("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\BG2.png");
JLabel bgImageContainer3 = new JLabel(bgImage2);
bgImageContainer3.setBounds(0,0,680,620);
//Main Frame Exit Button
JButton exit = new JButton("X");
exit.setFont(new Font(null, Font.BOLD, 26));
exit.setForeground(Color.white);
exit.setBounds(1017, -7, 45, 45);
exit.setOpaque(false);
exit.setContentAreaFilled(false);
exit.setBorderPainted(false);
exit.setBorder(null);
frame.add(exit);
//Main Frame Minimize Button
JButton minimize = new JButton("_");
minimize.setFont(new Font(null, Font.BOLD, 30));
minimize.setForeground(Color.white);
minimize.setBounds(975, -23, 45, 45);
minimize.setOpaque(false);
minimize.setContentAreaFilled(false);
minimize.setBorderPainted(false);
minimize.setBorder(null);
frame.add(minimize);
//JTable Construction
DefaultTableModel model = new DefaultTableModel() { // Makes Table UNEDITABLE
@Override
public boolean isCellEditable(int row, int column) {
//all cells false
return false;
}
};
JTable table = new JTable();
table.setModel(model);
table.setPreferredScrollableViewportSize(new Dimension(720, 600));
table.setDragEnabled(false);
//Table Container
KGradientPanel panel = new KGradientPanel();
KGradientPanel panel2 = new KGradientPanel();
panel.setkBorderRadius(0);
panel2.setkBorderRadius(0);
panel.setkStartColor(new Color(72,0,85));
panel.setkEndColor(new Color(0,0,0));
panel2.setkStartColor(new Color(72,0,85));
panel2.setkEndColor(new Color(0,0,0));
panel2.setBounds(40,30,740,640);
panel2.setBackground(compBgColor);
panel.setBounds(50,40,720,620);
//ScrollPane for table
JScrollPane scrollPane = new JScrollPane(table);
table.setBackground(Color.white);
scrollPane.setColumnHeaderView(table.getTableHeader());
scrollPane.setOpaque(true);
model.addColumn("Name");
model.addColumn("Type");
model.addColumn("Due");
model.addColumn("Subject");
model.addColumn("Description");
panel.add(scrollPane, BorderLayout.CENTER);
TableColumn column;
for (int i = 0; i < 5; i++) {
column = table.getColumnModel().getColumn(i);
if (i == 4) {
column.setMinWidth(300);
column.setMaxWidth(300);
column.setPreferredWidth(300);
}
else if (i == 0) {
column.setMinWidth(120);
column.setMaxWidth(120);
column.setPreferredWidth(120);
}
else {
column.setMinWidth(100);
column.setMaxWidth(100);
column.setPreferredWidth(100);
}
}
//add Task Frame to appear
Color bgColorTaskFrame = new Color(178,176,176);
final JFrame addTaskFrame = new JFrame("Add Task");
addTaskFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
addTaskFrame.setSize(670,260);
addTaskFrame.setLocation(450,200);
addTaskFrame.getContentPane().setBackground(new Color(220,237,193));
addTaskFrame.setLayout(null);
addTaskFrame.setVisible(false);
addTaskFrame.setUndecorated(true);
//edit Task Frame to appear
final JFrame editTaskFrame = new JFrame ("Edit Task");
editTaskFrame.getContentPane().setBackground(new Color (255,211,182));
editTaskFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
editTaskFrame.setSize(670,260);
editTaskFrame.setLocation(450,200);
editTaskFrame.setLayout(null);
editTaskFrame.setVisible(false);
editTaskFrame.setUndecorated(true);
//Task History Frame to appear
final JFrame historyFrame = new JFrame ("Task History");
historyFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
historyFrame.setLayout(new BorderLayout());
historyFrame.setVisible(false);
//History Log
JLabel historyLog = new JLabel();
historyFrame.add(historyLog, BorderLayout.NORTH);
//Task Name
Color bgcomp = new Color(171,208,221);
JLabel insertName = new JLabel ("Name:");
insertName.setForeground(Color.white);
insertName.setFont(new Font("Arial", Font.BOLD,15));
insertName.setBounds(50,30,80,20);
JTextField taskName = new JTextField ();
taskName.setBounds(100,25,200,30);
taskName.setBackground(bgcomp);
//Task Type
JLabel type = new JLabel ("Type :");
type.setForeground(Color.white);
type.setFont(new Font("Arial", Font.BOLD,15));
type.setBounds(50,65,80,20);
String taskTypes[]= {"...","Assignment", "Activity", "Project", "Quiz", "Exam","Review"};
JComboBox selectType = new JComboBox(taskTypes);
selectType.setBounds(100,60,200,30);
selectType.setBackground(bgcomp);
//Date Picker
JLabel dateLabel = new JLabel("Due :");
dateLabel.setForeground(Color.white);
dateLabel.setFont(new Font("Arial", Font.BOLD,15));
dateLabel.setBounds(50,105,80,20);
JDateChooser pickDate = new JDateChooser();
pickDate.getCalendarButton().setBackground(Color.orange);
pickDate.getDateEditor().getUiComponent().setBackground(bgcomp);
pickDate.setBounds(100,100,200,30);
pickDate.setBackground(bgcomp);
//Description Input
JLabel insertDescription = new JLabel ("Description:");
insertDescription.setForeground(Color.white);
insertDescription.setFont(new Font("Arial", Font.BOLD,15));
insertDescription.setBounds(340,20,100,20);
JTextArea description = new JTextArea ();
description.setBounds(340,45,280,130);
description.setBackground(bgcomp);
//Subject Input
JLabel insertSubject = new JLabel ("Subject :");
insertSubject.setForeground(Color.white);
insertSubject.setFont(new Font("Arial", Font.BOLD,15));
insertSubject.setBounds(50,145,80,20);
JTextField subjectName = new JTextField ();
subjectName.setBounds(130,140,170,30);
subjectName.setBackground(bgcomp);
//ADD and CLOSE Button
KButton addButton = new KButton ();
addButton.setText("ADD");
addButton.setBounds(230, 200, 90, 30);
addButton.setFont(new Font("Arial", Font.BOLD,13));
KButton cancelButton = new KButton ();
cancelButton.setText("CANCEL");
cancelButton.setBounds(330, 200, 90, 30);
cancelButton.setFont(new Font("Arial", Font.BOLD,13));
//Components of editTaskButton
//Task Name2
JLabel insertName2 = new JLabel ("Name:");
insertName2.setFont(new Font("Arial", Font.BOLD,15));
insertName2.setForeground(Color.white);
insertName2.setBounds(50,30,80,20);
JTextField taskName2 = new JTextField ();
taskName2.setBounds(100,25,200,30);
taskName2.setBackground(bgcomp);
//Task Type2
JLabel type2 = new JLabel ("Type :");
type2.setFont(new Font("Arial", Font.BOLD,15));
type2.setForeground(Color.white);
type2.setBounds(50,65,80,20);
String taskTypes2[]= {"...","Assignment", "Activity", "Project", "Quiz", "Exam","Review"};
JComboBox selectType2 = new JComboBox(taskTypes);
selectType2.setBounds(100,60,200,30);
selectType2.setBackground(bgcomp);
//Date Picker2
JLabel dateLabel2 = new JLabel("Due :");
dateLabel2.setForeground(Color.white);
dateLabel2.setFont(new Font("Arial", Font.BOLD,15));
dateLabel2.setBounds(50,105,80,20);
JDateChooser pickDate2 = new JDateChooser();
pickDate2.getCalendarButton().setBackground(Color.orange);
pickDate2.getDateEditor().getUiComponent().setBackground(bgcomp);
pickDate2.setBounds(100,100,200,30);
pickDate2.setBackground(bgcomp);
//Description Input2
JLabel insertDescription2 = new JLabel ("Description:");
insertDescription2.setForeground(Color.white);
insertDescription2.setFont(new Font("Arial", Font.BOLD,15));
insertDescription2.setBounds(340,20,100,20);
JTextArea description2 = new JTextArea ();
description2.setBounds(340,45,280,130);
description2.setBackground(bgcomp);
//Subject Input2
JLabel insertSubject2 = new JLabel ("Subject :");
insertSubject2.setForeground(Color.white);
insertSubject2.setFont(new Font("Arial", Font.BOLD,15));
insertSubject2.setBounds(50,145,80,20);
JTextField subjectName2 = new JTextField ();
subjectName2.setBounds(130,140,170,30);
subjectName2.setBackground(bgcomp);
//Confirm to edit a task and close Button
KButton confirmButton = new KButton();
confirmButton.setText("EDIT");
confirmButton.setBounds(230, 200, 90, 30);
confirmButton.setFont(new Font("Arial", Font.BOLD,13));
KButton cancelButton2 = new KButton ();
cancelButton2.setText("CANCEL");
cancelButton2.setBounds(330, 200, 90, 30);
cancelButton2.setFont(new Font("Arial", Font.BOLD,13));
//Main Title
JLabel title = new JLabel ("Students' Task Management System");
title.setBounds(10, 2, 600, 30);
title.setFont(new Font("Harlow Solid Italic", Font.PLAIN, 25 ));
title.setForeground(Color.white);
//Add a Task Button
KButton addTask = new KButton();
addTask.setText("Add Task");
addTask.setkBorderRadius(50);
addTask.setBorderPainted(false);
addTask.setBounds(815, 50, 200, 50);
addTask.setkStartColor(new Color(246,234,65));
addTask.setkEndColor(new Color(119,0,127));
//Edit a Task Button
KButton editTask = new KButton ();
editTask.setText("Edit Task");
editTask.setkBorderRadius(50);
editTask.setBorderPainted(false);
editTask.setBounds(815, 110, 200, 50);
editTask.setEnabled(false);
editTask.setkStartColor(new Color(246,234,65));
editTask.setkEndColor(new Color(119,0,127));
//Delete a Task Button
KButton deleteTask = new KButton ();
deleteTask.setText("Delete Task");
deleteTask.setkBorderRadius(50);
deleteTask.setBorderPainted(false);
deleteTask.setBounds(815, 170, 200, 50);
deleteTask.setEnabled(false);
deleteTask.setkStartColor(new Color(246,234,65));
deleteTask.setkEndColor(new Color(119,0,127));
//Mark as Done Button
KButton doneTask = new KButton ();
doneTask.setText("Mark as Done");
doneTask.setkBorderRadius(50);
doneTask.setBorderPainted(false);
doneTask.setBounds(815, 230, 200, 50);
doneTask.setEnabled(false);
doneTask.setkStartColor(new Color(246,234,65));
doneTask.setkEndColor(new Color(119,0,127));
//History Button
KButton historyButton = new KButton ();
historyButton.setText("View Task History");
historyButton.setkBorderRadius(50);
historyButton.setBorderPainted(false);
historyButton.setBounds(815, 560, 200, 50);
historyButton.setkStartColor(new Color(246,234,65));
historyButton.setkEndColor(new Color(119,0,127));
//JCalendar
JLabel currentDate = new JLabel ("Current Date:");
currentDate.setForeground(Color.white);
currentDate.setBounds(800, 298, 200, 50);
currentDate.setFont(new Font("Arial", Font.ITALIC, 15 ));
JCalendar calendar = new JCalendar();
KGradientPanel calendarPanel = new KGradientPanel();
calendarPanel.setBounds(800, 340, 240, 180);
calendarPanel.setkBorderRadius(0);
calendarPanel.setkStartColor(new Color(13,181,182));
calendarPanel.setkEndColor(new Color(55,4,57));
calendarPanel.add(calendar);
//Credits
JLabel createdBy = new JLabel ();
createdBy.setForeground(Color.white);
createdBy.setBounds(870, 650, 200, 20);
createdBy.setFont(new Font("Times New Roman", Font.ITALIC, 13));
//Set Application Icon
Image icon = Toolkit.getDefaultToolkit().getImage("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\icon.png");
frame.setIconImage(icon);
historyFrame.setIconImage(icon);
//Main GUI frame components
frame.add(title);
frame.add(addTask);
frame.add(editTask);
frame.add(deleteTask);
frame.add(doneTask);
frame.add(calendarPanel);
frame.add(currentDate);
frame.add(historyButton);
frame.add(createdBy);
frame.add(panel);
frame.add(panel2);
frame.add(bgImageContainer);
//addTaskFrame components
addTaskFrame.add(insertName);
addTaskFrame.add(taskName);
addTaskFrame.add(type);
addTaskFrame.add(selectType);
addTaskFrame.add(dateLabel);
addTaskFrame.add(pickDate);
addTaskFrame.add(insertSubject);
addTaskFrame.add(subjectName);
addTaskFrame.add(description);
addTaskFrame.add(insertDescription);
addTaskFrame.add(addButton);
addTaskFrame.add(cancelButton);
addTaskFrame.add(bgImageContainer3);
//editTaskFrame components
editTaskFrame.add(insertName2);
editTaskFrame.add(taskName2);
editTaskFrame.add(type2);
editTaskFrame.add(selectType2);
editTaskFrame.add(dateLabel2);
editTaskFrame.add(pickDate2);
editTaskFrame.add(insertSubject2);
editTaskFrame.add(subjectName2);
editTaskFrame.add(description2);
editTaskFrame.add(insertDescription2);
editTaskFrame.add(confirmButton);
editTaskFrame.add(cancelButton2);
editTaskFrame.add(bgImageContainer2);
//Location of file for saving and loading data in the table
File myFile = new File("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\file.txt");
File filed = new File("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log2.txt");
//continueButton in Welcome Page
continues.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setEnabled(true);
wFrame.dispose();
addTask.doClick();
}
});
//Exit Main Frame
exit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Save Table Data to File
try {
FileWriter fw = new FileWriter(myFile);
BufferedWriter bw = new BufferedWriter (fw);
for(int i = 0; i<table.getRowCount(); i++) {
for (int j =0; j<table.getColumnCount(); j++) {
bw.write(table.getValueAt(i, j).toString() + "~");
}
bw.newLine();
}
bw.close();
fw.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
frame.dispose();
addTaskFrame.dispose();
editTaskFrame.dispose();
historyFrame.dispose();
}
});
//MiniMize Main Frame
minimize.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setState(Frame.ICONIFIED);
}
});
//when addTask is clicked it creates a new frame with new set of Components
addTask.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
addTaskFrame.setVisible(true);
}
});
//when editTask is clicked it creates a new frame with new set of Components
editTask.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
editTaskFrame.setVisible(true);
int row = table.getSelectedRow();
String taskname2 =(String) model.getValueAt(row, 0);
String subjectname2 =(String) model.getValueAt(row, 3);
String descriptions2 =(String) model.getValueAt(row, 4);
taskName2.setText(taskname2);
subjectName2.setText(subjectname2);
description2.setText(descriptions2);
}
});
//when taskHistory is clicked it creates a new frame with new set of Components
historyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
historyFrame.setVisible(true);
StringBuilder sb = new StringBuilder();
try(BufferedReader br = new BufferedReader( new FileReader("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log.txt"))) {
String line;
while((line = br.readLine()) != null) {
sb.append(line).append("<br>");
}
historyLog.setText("<html>" + sb.toString() + "<html>");
historyFrame.pack();
historyFrame.setSize(400, 700);
historyFrame.setLocation(1080, 100);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
//addButton ActionListener
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//Get Data
String TaskName = taskName.getText();
String PickDate = ((JTextField) pickDate.getDateEditor().getUiComponent()).getText();
String Description = description.getText();
String SubjectName = subjectName.getText();
int SelectTypeIndex = selectType.getSelectedIndex();
String SelectType = null;
for (int i = 0; i<8; i++) {
if (SelectTypeIndex == i) {
SelectType = taskTypes[i];
}
}
//if Empty
if (TaskName.equals("")||SelectType.equals("")||PickDate.equals("")||SubjectName.equals("")||Description.equals("")) {
JOptionPane.showMessageDialog(addTaskFrame, "Please Fill All Areas");
}
else{
//Add Data to Table
model.addRow(new Object[]{TaskName,SelectType, PickDate, SubjectName, Description });
table.getColumnModel().getColumn(2).setCellRenderer(new MyTableCellRenderer());
//Add to Log
try {
//Creates a new event log in text file
FileWriter fw = new FileWriter ("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log.txt",true);
fw.write("\n(" + currentDateTime + ") Added:\n");
fw.append(TaskName + " - " + SelectType+ "\n---------------------------------------------------------------------------------------------------------------");
fw.close();
} catch (IOException e2) {
e2.printStackTrace();
}
//Reads the new event log to update historyLog label
StringBuilder sb = new StringBuilder();
try(BufferedReader br = new BufferedReader( new FileReader("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log.txt"))) {
String line;
while((line = br.readLine()) != null) {
sb.append(line).append("<br>");
}
//Updates JLabel
historyLog.setText("<html>" + sb.toString() + "<html>");
historyFrame.pack();
historyFrame.setSize(400, 700);
historyFrame.setLocation(1080, 100);
}catch (IOException e1) {
e1.printStackTrace();
}
addTaskFrame.dispose();
pickDate.setCalendar(null);
selectType.setSelectedIndex(0);
taskName.setText("");
subjectName.setText("");
description.setText("");
}
}
});
//cancelButton ActionListener
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addTaskFrame.dispose();
cancelButton.setBackground(UIManager.getColor("control"));
cancelButton.setForeground(null);
pickDate.setCalendar(null);
selectType.setSelectedIndex(0);
taskName.setText("");
subjectName.setText("");
description.setText("");
editTask.setEnabled(false);
deleteTask.setEnabled(false);
doneTask.setEnabled(false);
}
});
//cancelButton2 ActionListener
cancelButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editTaskFrame.dispose();
cancelButton2.setBackground(UIManager.getColor("control"));
cancelButton2.setForeground(null);
pickDate2.setCalendar(null);
selectType2.setSelectedIndex(0);
taskName2.setText("");
subjectName2.setText("");
description2.setText("");
editTask.setEnabled(false);
deleteTask.setEnabled(false);
doneTask.setEnabled(false);
}
});
//JTable ActionListener to enable buttons once selected
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
editTask.setEnabled(true);
deleteTask.setEnabled(true);
doneTask.setEnabled(true);
}
});
//deleteTask Action Listener
deleteTask.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!table.getSelectionModel().isSelectionEmpty()) {
int a = JOptionPane.showConfirmDialog((Component)null, "Do you want to delete the selected task?", "Delete",JOptionPane.YES_NO_OPTION);
if(a==0) {
int row = table.getSelectedRow();
//gets task name of selected row
String name =(String) model.getValueAt(row, 0);
String type = (String) model.getValueAt(row, 1);
try {
//Creates a new event log in text file
FileWriter fw = new FileWriter ("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log.txt",true);
fw.write("\n(" + currentDateTime + ") Deleted:\n");
fw.append(name + " - " + type+ "\n---------------------------------------------------------------------------------------------------------------");
fw.close();
} catch (IOException e2) {
e2.printStackTrace();
}
//Reads the new event log to update historyLog label
StringBuilder sb = new StringBuilder();
try(BufferedReader br = new BufferedReader( new FileReader("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log.txt"))) {
String line;
while((line = br.readLine()) != null) {
sb.append(line).append("<br>");
}
//Updates JLabel
historyLog.setText("<html>" + sb.toString() + "<html>");
historyFrame.pack();
historyFrame.setSize(400, 700);
historyFrame.setLocation(1080, 100);
}catch (IOException e1) {
e1.printStackTrace();
}
model.removeRow(row);
JOptionPane.showMessageDialog(null,"Deleted Successfully","Deleted",JOptionPane.INFORMATION_MESSAGE);
editTask.setEnabled(false);
deleteTask.setEnabled(false);
doneTask.setEnabled(false);
}
}
}
});
//editTask ActionListener
confirmButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//Get Data
String TaskName2 = taskName2.getText();
String PickDate2 = ((JTextField) pickDate2.getDateEditor().getUiComponent()).getText();
String Description2 = description2.getText();
String SubjectName2 = subjectName2.getText();
int SelectTypeIndex2 = selectType2.getSelectedIndex();
int row = table.getSelectedRow();
String SelectType2 = null;
for (int i = 0; i<8; i++) {
if (SelectTypeIndex2 == i) {
SelectType2 = taskTypes[i];
}
}
//if Empty
if (TaskName2.equals("")||SelectType2.equals("")||PickDate2.equals("")||SubjectName2.equals("")||Description2.equals("")) {
JOptionPane.showMessageDialog(editTaskFrame, "Please Fill All Areas");
}
else{
//Edit Data to Table
model.removeRow(row);
model.addRow(new Object[]{TaskName2,SelectType2, PickDate2, SubjectName2, Description2 });
editTaskFrame.dispose();
pickDate2.setCalendar(null);
selectType2.setSelectedIndex(0);
taskName2.setText("");
subjectName2.setText("");
description2.setText("");
}
//gets task name of selected row
String name =(String) model.getValueAt(row, 0);
String type = (String) model.getValueAt(row, 1);
try {
//Creates a new event log in text file
FileWriter fw = new FileWriter ("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log.txt",true);
fw.write("\n(" + currentDateTime + ") Edited:\n");
fw.append(name + " - " + type+ "\n---------------------------------------------------------------------------------------------------------------");
fw.close();
} catch (IOException e2) {
e2.printStackTrace();
}
//Reads the new event log to update historyLog label
StringBuilder sb = new StringBuilder();
try(BufferedReader br = new BufferedReader( new FileReader("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log.txt"))) {
String line;
while((line = br.readLine()) != null) {
sb.append(line).append("<br>");
}
//Updates JLabel
historyLog.setText("<html>" + sb.toString() + "<html>");
historyFrame.pack();
historyFrame.setSize(400, 700);
historyFrame.setLocation(1080, 100);
}catch (IOException e1) {
e1.printStackTrace();
}
}
});
//doneTask ActionListener
doneTask.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!table.getSelectionModel().isSelectionEmpty()) {
int a = JOptionPane.showConfirmDialog((Component)null, "Mark task as finished?", "Yes",JOptionPane.YES_NO_OPTION);
if(a==0) {
int row = table.getSelectedRow();
//gets task name of selected row
String name =(String) model.getValueAt(row, 0);
String type = (String) model.getValueAt(row, 1);
try {
//Creates a new event log in text file
FileWriter fw = new FileWriter ("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log.txt",true);
fw.write("\n(" + currentDateTime + ") Finished:\n");
fw.append(name + " - " + type + "\n---------------------------------------------------------------------------------------------------------------");
fw.close();
FileWriter fw2 = new FileWriter("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log2.txt",true);
fw2.append("D");
fw2.close();
} catch (IOException e2) {
e2.printStackTrace();
}
//Reads the new event log to update historyLog label
StringBuilder sb = new StringBuilder();
try(BufferedReader br = new BufferedReader( new FileReader("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log.txt"))) {
String line;
while((line = br.readLine()) != null) {
sb.append(line).append("<br>");
}
//Updates JLabel
historyLog.setText("<html>" + sb.toString() + "<html>");
historyFrame.pack();
historyFrame.setSize(400, 700);
historyFrame.setLocation(1080, 100);
//Reads Tasks Finished
File filed = new File("C:\\Users\\danil\\eclipse-workspace\\TaskManagementSystem\\src\\taskManagementSystem\\log2.txt");
FileReader fr2 = new FileReader (filed);
BufferedReader br2 = new BufferedReader (fr2);
char[] chars = new char[(int)filed.length()];
int count = br2.read(chars);
createdBy.setText("Tasks Finished: " + count);
}catch (IOException e1) {
e1.printStackTrace();
}
model.removeRow(row);
JOptionPane.showMessageDialog(null,"Task Marked as Done","Done",JOptionPane.INFORMATION_MESSAGE);
editTask.setEnabled(false);
deleteTask.setEnabled(false);
doneTask.setEnabled(false);
}
}
}
});
//Frame listener for saving and loading table data
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
//Set Table color for dates
table.getColumnModel().getColumn(2).setCellRenderer(new MyTableCellRenderer());
//Load Table Data to File
try {
FileReader fr = new FileReader (myFile);
BufferedReader br = new BufferedReader (fr);
Object [] lines = br.lines().toArray();
for(int i =0; i<lines.length; i++) {
String [] row = lines [i].toString().split("~");
model.addRow(row);
}
br.close();
fr.close();
FileReader fr2 = new FileReader (filed);
BufferedReader br2 = new BufferedReader (fr2);
char[] chars = new char[(int)filed.length()];
int count = br2.read(chars);
createdBy.setText("Tasks Finished: " + count);;
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
@Override
public void windowClosing(WindowEvent e) {
}
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
});
//After Loading all components, set Main Frame to visible
frame.setVisible(true);
//Check If Table is Empty
try {
FileReader fr = new FileReader (filed);
BufferedReader br = new BufferedReader (fr);
FileReader fr1 = new FileReader (myFile);
BufferedReader br1 = new BufferedReader (fr1);
Object [] lines = br.lines().toArray();
Object [] lines2 = br1.lines().toArray();
if (lines.length == 0 && lines2.length == 0 ) {
wFrame.setVisible(true);
frame.setEnabled(false);
}
} catch (Exception e) {
// do nothing if exception caught
}
}
// New Class Dedicated to detecting dates, rearranging, and coloring them inside JTable and sending system notification
public class MyTableCellRenderer extends DefaultTableCellRenderer {
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d, yyyy");
private boolean notificationSent = false;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
// check if the value is a valid date in the expected format
if (value instanceof String) {
try {
LocalDate date = LocalDate.parse((String) value, formatter);
LocalDate tomorrow = LocalDate.now().plusDays(1);
LocalDate today = LocalDate.now();
// iterate over the rows to arrange them by date
for (int i = 0; i < table.getRowCount() - 1; i++) {
for (int j = i + 1; j < table.getRowCount(); j++) {
Object valueI = table.getValueAt(i, col);
Object valueJ = table.getValueAt(j, col);
if (valueI instanceof String && valueJ instanceof String) {
try {
LocalDate dateI = LocalDate.parse((String) valueI, formatter);
LocalDate dateJ = LocalDate.parse((String) valueJ, formatter);
if (dateI.isAfter(dateJ)) {
// swap the positions of the two rows
for (int k = 0; k < table.getColumnCount(); k++) {
Object temp = table.getValueAt(i, k);
table.setValueAt(table.getValueAt(j, k), i, k);
table.setValueAt(temp, j, k);
}
}
} catch (DateTimeParseException e) {
// ignore invalid dates
}
}
}
}
// highlight the row based on the date
if (date.isEqual(tomorrow)) {
setBackground(Color.YELLOW);
if (!notificationSent) {
sendNotification("Due Date Upcoming","A task has an upcoming due date");
notificationSent = true;
}
}
else if(date.isEqual(today)) {
setBackground(Color.orange);
if (!notificationSent) {
sendNotification("Task Due Today","A task is due today!");
notificationSent = true;
}
}
else if(date.isBefore(today)) {
setBackground(Color.red);