-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.java
1115 lines (988 loc) · 51.9 KB
/
GUI.java
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
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* This class inherits the Java Swing framework as per online library documentation
*/
public class GUI extends javax.swing.JFrame {
private JFrame frame;
private List<Project> projects;
private List<FilmProject> filmProjects;
private JComboBox<String> locationFilterComboBox;
private JComboBox<String> venueSizeFilterComboBox;
private List<MusicProject> musicProjects;
private List<TheaterProject> theaterProjects;
private List<TVProject> tvProjects;
private JTable tableFilmProjects;
private JTable tableMusicProjects;
private JTable tableTheaterProjects;
private JTable tableTVProjects;
private JTable tableProjects;
private static JPanel tableAllProjectsPanel;
private static JPanel tableFilmProjectsPanel;
private static JPanel tableTheaterProjectsPanel;
private static JPanel tableMusicProjectsPanel;
private static JPanel tableTVProjectsPanel;
private JPanel tablesPanel;
private JTextArea summaryTextArea;
/**
* Class Constructor
* @param projects
* @param filmProjects
* @param musicProjects
* @param theaterProjects
* @param tvProjects
*/
public GUI(List<Project> projects, List<FilmProject> filmProjects,
List<MusicProject> musicProjects, List<TheaterProject> theaterProjects,
List<TVProject> tvProjects) {
this.projects = projects;
this.filmProjects = filmProjects;
this.musicProjects = musicProjects;
this.theaterProjects = theaterProjects;
this.tvProjects = tvProjects;
SwingUtilities.invokeLater(() -> {
try {
// Set the look and feel
// This is used for determining the design of the GUI
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
createAndShowGUI();
});
}
/**
* This method is responsible for the main body of the GUI and the
* triggering of button actions as relevant
*/
private void createAndShowGUI() {
// Create and configure the main GUI frame (the GUI window)
JFrame frame = new JFrame("Scotia Visual Productions - Projects");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1200, 600);
frame.setLocationRelativeTo(null); // Centre the GUI frame on the desktop screen
// Create and configure the content panel
// This panel is the base which will hold all other panels and components
JPanel contentPanel = new JPanel(new BorderLayout());
contentPanel.setBackground(new Color(18, 30, 49)); // Navy blue
contentPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
// Create and configure the side menu panel
JPanel sideMenuPanel = new JPanel(new GridLayout(5, 1, 0, 10));
sideMenuPanel.setBackground(new Color(32, 53, 84)); // Dark blue
sideMenuPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
// Create menu options based on Project Types
String[] menuOptions = {"All", "Film", "Theater", "Music", "TV"};
// loop through button options and determine its actions
for (String option : menuOptions) {
JButton button = new JButton(option);
button.setForeground(Color.WHITE); // Set text colour to white
button.setBackground(new Color(32, 53, 84)); // Dark blue
button.addActionListener(e -> { // action of each button
// Action to perform when project type button option is clicked
// When clicked, table with relevant dataset is selected and made available
// as well as summary text is created based on filters
if(option.equals("Film")) {
setSelectedTablePanel(tableFilmProjectsPanel);
summaryText(locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
}
else if(option.equals("Theater")) {
setSelectedTablePanel(tableTheaterProjectsPanel);
summaryText(locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
}
else if(option.equals("Music")) {
setSelectedTablePanel(tableMusicProjectsPanel);
summaryText(locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
}
else if(option.equals("TV")) {
setSelectedTablePanel(tableTVProjectsPanel);
summaryText(locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
}
else if(option.equals("All")) {
setSelectedTablePanel(tableAllProjectsPanel);
summaryText(locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
}
summaryText(locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
JOptionPane.showMessageDialog(frame, "Data filtered to: " + option, "Project Type Selected", JOptionPane.INFORMATION_MESSAGE);
});
sideMenuPanel.add(button);
}
// Add side menu panel to content panel
contentPanel.add(sideMenuPanel, BorderLayout.WEST);
// Create and configure the filter side menu
JPanel filterPanel = new JPanel(new GridLayout(10, 1, 0, 10));
filterPanel.setBackground(new Color(32, 53, 84)); // Dark blue
filterPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
// Add a text identifying menu as Filters to improve user friendliness
JLabel filtersLabel = new JLabel("Filters", SwingConstants.CENTER);
filtersLabel.setForeground(Color.WHITE);
Font boldFont = filtersLabel.getFont().deriveFont(Font.BOLD);
filtersLabel.setFont(boldFont);
filtersLabel.setBorder(BorderFactory.createLineBorder(Color.WHITE));
// Create label and dropdown for Location filter
JLabel locationLabel = new JLabel("Location");
locationLabel.setForeground(Color.WHITE);
// Options on the dropdown
String[] locationOptions = {"All", "Aberdeen","Berlin","Chicago","Dunfermline",
"Edinburgh","Glasgow","Inverness","Los Angeles","New York","Paris",
"Stirling","Toronto", "Vienna"};
locationFilterComboBox = new JComboBox<>();
for (String option : locationOptions) {
locationFilterComboBox.addItem(option);
}
// Create label and dropdown for Venue Size filter
JLabel venueSizeLabel = new JLabel("Venue Size");
venueSizeLabel.setForeground(Color.WHITE);
// Options of venue sizes
String[] venueSizeOptions = {"All", "Small", "Medium", "Large"};
venueSizeFilterComboBox = new JComboBox<>();
for (String option : venueSizeOptions) {
venueSizeFilterComboBox.addItem(option);
}
// Creation of a button to save and apply selected filters
// Filters will not be applied until this button is selected
// Once selected, the tables are updated with the relevant filtering
JButton applyFiltersBtn = new JButton("Apply Filters");
applyFiltersBtn.setForeground(Color.WHITE); // Set text colour to white
applyFiltersBtn.setBackground(new Color(32, 53, 84)); // Dark blue
applyFiltersBtn.addActionListener(e -> {
tableFilmProjects = createTable("Update", "Film", locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
tableMusicProjects = createTable("Update", "Music", locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
tableTheaterProjects = createTable("Update", "Theater", locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
tableTVProjects = createTable("Update", "TV", locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
tableProjects = createTable("Update", "All", locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
});
// Create empty label to be used as a space (design purposes only)
JLabel spaceLabel = new JLabel("");
// Button option to add a new project to the dataset
// Once this button is selected, a pop-up box appears with fields to be filled
JButton newRecordBtn = new JButton("Add new project");
newRecordBtn.setForeground(Color.WHITE); // Set text colour to white
newRecordBtn.setBackground(new Color(32, 53, 84)); // Dark blue
newRecordBtn.addActionListener(e-> {
// Create a JPanel to hold the form components
JPanel formPanel = new JPanel(new GridLayout(0, 2, 5, 5));
// Add text field into Form Panel for Project ID
formPanel.add(new JLabel("Project ID:"));
JTextField projectIDField = new JTextField();
formPanel.add(projectIDField);
// Add text field for Project Name
formPanel.add(new JLabel("Project Name:"));
JTextField projectNameField = new JTextField();
formPanel.add(projectNameField);
// Add dropdown field for Project Type
formPanel.add(new JLabel("Project Type:"));
String[] projectTypes = {"Film", "Music", "Theater", "TV"};
JComboBox<String> projectTypeComboBox = new JComboBox<>(projectTypes);
formPanel.add(projectTypeComboBox);
// Creation of optional fields and text labels
// This would refer to the fields exclusive to each project type
// Refer to UML Diagram for further information
JTextField filmFormatField = new JTextField();
JLabel filmFormat = new JLabel("Film Format:");
JTextField theaterPlaywrightField = new JTextField();
JLabel theaterPlaywright = new JLabel("Theater Playwright:");
JTextField musicGenreField = new JTextField();
formPanel.add(new JLabel("Project Cost (£):"));
JTextField projectCost = new JTextField();
formPanel.add(projectCost);
JLabel musicGenre = new JLabel("Music Genre:");
JTextField tvNetworkField = new JTextField();
JLabel tvNetwork = new JLabel("TV Network:");
// Add text field for date
formPanel.add(new JLabel("Project Date (dd/MM/yyyy):"));
JTextField projectDate = new JTextField();
formPanel.add(projectDate);
// Add dropdown field for Project Location
formPanel.add(new JLabel("Project Location:"));
String[] projectLocations = Arrays.copyOfRange(locationOptions, 1, locationOptions.length);
JComboBox<String> projectLocationComboBox = new JComboBox<>(projectLocations);
formPanel.add(projectLocationComboBox);
// Add field for Cost to customer
formPanel.add(new JLabel("Cost to Customer (£):"));
JTextField projectCostToCustomer = new JTextField();
formPanel.add(projectCostToCustomer);
// Add dropdown field for Venue Size
formPanel.add(new JLabel("Project Type:"));
String[] venueSizes = {"Small", "Medium", "Large"};
JComboBox<String> venueSizeComboBox = new JComboBox<>(venueSizes);
formPanel.add(venueSizeComboBox);
// Add int field for Duration
formPanel.add(new JLabel("Project Duration:"));
SpinnerModel projectDurationSpinnerModel = new SpinnerNumberModel(1,1,48,1); // Set initial value as 1, min value as 1, max value as 48, and step
JSpinner projectDurationSpinner = new JSpinner(projectDurationSpinnerModel);
formPanel.add(projectDurationSpinner);
// Add dropdown for Duration Unit
formPanel.add(new JLabel("Duration Unit:"));
String[] durationUnitOptions = {"hours", "days"};
JComboBox<String> durationUnitComboBox = new JComboBox<>(durationUnitOptions);
formPanel.add(durationUnitComboBox);
// Placeholder on forms where optional fields will be located
// This is used for design purposes only, facilitating the appearance of optional
// fields conditional to project type selected
JLabel placeholderField = new JLabel("");
formPanel.add(placeholderField);
// Action to be performed once a project type has been selected.
// For each project type, the relevant optional field should appear.
// Accounting for potential modifications, it also removes fields from other types
// that are not applicable for the scenario.
projectTypeComboBox.addActionListener(event -> {
String selectedType = (String) projectTypeComboBox.getSelectedItem();
if (selectedType.equals("Film")) {
formPanel.add(filmFormat);
formPanel.add(filmFormatField);
formPanel.remove(placeholderField);
formPanel.remove(theaterPlaywrightField);
formPanel.remove(theaterPlaywright);
formPanel.remove(musicGenre);
formPanel.remove(musicGenreField);
formPanel.remove(tvNetwork);
formPanel.remove(tvNetworkField);
}
else if (selectedType.equals("Theater")) {
formPanel.add(theaterPlaywright);
formPanel.add(theaterPlaywrightField);
formPanel.remove(placeholderField);
formPanel.remove(filmFormatField);
formPanel.remove(filmFormat);
formPanel.remove(musicGenre);
formPanel.remove(musicGenreField);
formPanel.remove(tvNetwork);
formPanel.remove(tvNetworkField);
}
else if (selectedType.equals("Music")) {
formPanel.add(musicGenre);
formPanel.add(musicGenreField);
formPanel.remove(placeholderField);
formPanel.remove(filmFormatField);
formPanel.remove(filmFormat);
formPanel.remove(theaterPlaywrightField);
formPanel.remove(theaterPlaywright);
formPanel.remove(tvNetwork);
formPanel.remove(tvNetworkField);
}
else if (selectedType.equals("TV")) {
formPanel.add(tvNetwork);
formPanel.add(tvNetworkField);
formPanel.remove(placeholderField);
formPanel.remove(filmFormatField);
formPanel.remove(filmFormat);
formPanel.remove(theaterPlaywrightField);
formPanel.remove(theaterPlaywright);
formPanel.remove(musicGenre);
formPanel.remove(musicGenreField);
}
formPanel.revalidate();
formPanel.repaint();
}
);
// Show the pop-up dialog with the form for new project record creation
int result = JOptionPane.showConfirmDialog(frame, formPanel, "New Project Record", JOptionPane.OK_CANCEL_OPTION);
// Set action triggered by user clicking on Ok button
// Action to capture the values of the fields, save in local variables
// and trigger the creation of the new record within the relevant
// Java classes.
// Field types are casted and parsed as required when saving to relevant variables
if (result == JOptionPane.OK_OPTION) {
String projectID = projectIDField.getText();
String projectName = projectNameField.getText();
String type = (String) projectTypeComboBox.getSelectedItem();
// Parse the date field from String to Date
Date projectDateVal = Calendar.getInstance().getTime();
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
projectDateVal = dateFormat.parse(projectDate.getText());
} catch (ParseException ex) {
// Handle the case where the input date format is incorrect
// For example, display an error message to the user
System.err.println("Invalid date format. Please enter date in dd/MM/yyyy format.");
}
String location = (String) projectLocationComboBox.getSelectedItem();
double projectCostVal = Double.parseDouble(projectCost.getText());
double projectCostToCost = Double.parseDouble(projectCostToCustomer.getText());
String venueSize = (String) venueSizeComboBox.getSelectedItem();
int projectDuration = (int) projectDurationSpinner.getValue();
String durationUnit = (String) durationUnitComboBox.getSelectedItem();
String optionalField;
// Define which field is the optional field for each project type case
if(type.equals("Film")) {optionalField = filmFormatField.getText();
}else if (type.equals("Music")) {
optionalField = musicGenreField.getText();}else if (
type.equals("Theater")) {
optionalField = theaterPlaywrightField.getText();} else {
optionalField = tvNetworkField.getText();
}
// Call method to create a new project
createNewProject(projectID, projectName, type, projectDateVal, location,
projectCostVal, projectCostToCost, venueSize, projectDuration,
durationUnit, optionalField);
}
});
// Add all the filter fields and buttons (Apply filters and Create new record) to
// the filter panel
filterPanel.add(filtersLabel);
filterPanel.add(locationLabel);
filterPanel.add(locationFilterComboBox);
filterPanel.add(venueSizeLabel);
filterPanel.add(venueSizeFilterComboBox);
filterPanel.add(spaceLabel);
filterPanel.add(applyFiltersBtn);
filterPanel.add(newRecordBtn);
// Save filter panel in the right hand side of the window
contentPanel.add(filterPanel, BorderLayout.EAST);
// Create and configure the footer panel
JPanel footerPanel = new JPanel(new BorderLayout());
footerPanel.setBackground(new Color(32, 53, 84)); // Dark blue
footerPanel.setBorder(new EmptyBorder(5, 10, 5, 10));
// Create and configure the footer label
JLabel footerLabel = new JLabel("© 2024 isaqueiros", SwingConstants.CENTER); // Footer text with my own customisation :)
footerLabel.setForeground(Color.WHITE); // Set text colour to white
footerPanel.add(footerLabel, BorderLayout.CENTER); // centralise text in the footer
// Add footer panel to content panel in the end of the window
contentPanel.add(footerPanel, BorderLayout.SOUTH);
// Create and configure the buttons panel which have option of Projects Data and Summary
JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 5));
buttonsPanel.setBackground(new Color(18, 30, 49)); // Navy blue
// Create and configure the "Projects Data" button
JButton projectsDataButton = new JButton("Projects Data");
projectsDataButton.setForeground(Color.WHITE);
projectsDataButton.setBackground(new Color(32, 53, 84)); // Dark blue
projectsDataButton.setPreferredSize(new Dimension(400, 30));
projectsDataButton.addActionListener(e -> {
// Show table panel when "Projects Data" button is clicked
tableAllProjectsPanel.setVisible(true);
});
// Create and configure the "Summary" button
// Once clicked, the summary opens a pop-up window with produced text based
// on dataset and selected filters.
JButton summaryButton = new JButton("Summary");
summaryButton.setForeground(Color.WHITE);
summaryTextArea = new JTextArea();
summaryButton.setBackground(new Color(32, 53, 84)); // Dark blue
summaryButton.setPreferredSize(new Dimension(400, 30));
summaryButton.addActionListener(e -> {
// Initialise a JTextArea if not existant and update summary text
if (summaryTextArea == null) {
summaryTextArea.setLineWrap(true);
summaryTextArea.setWrapStyleWord(true);
summaryTextArea.setEditable(false);
}
// Generate the summary text based on filters
// Text is generated with summaryText method
summaryText(locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
// Create the pop-up window with the summary text
JScrollPane scrollPane = new JScrollPane(summaryTextArea);
scrollPane.setPreferredSize(new Dimension(400, 200));
JOptionPane.showMessageDialog(frame, scrollPane, "Summary", JOptionPane.INFORMATION_MESSAGE);
});
// Add buttons Summary and Data to the buttons panel
buttonsPanel.add(projectsDataButton);
buttonsPanel.add(summaryButton);
// Create and configure the table panel to store the All Projects table
tableAllProjectsPanel = new JPanel(new BorderLayout());
tableAllProjectsPanel.setBackground(new Color(18, 30, 49)); // Navy blue
// Create and configure the table for all Projects
tableProjects = createTable("Create", "All", locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
JScrollPane scrollPaneAllProjects = new JScrollPane(tableProjects);
tableAllProjectsPanel.add(scrollPaneAllProjects, BorderLayout.CENTER);
tableAllProjectsPanel.setVisible(true);
// Create and configure the table panel to store Film Projects table
tableFilmProjectsPanel = new JPanel(new BorderLayout());
tableFilmProjectsPanel.setBackground(new Color(18, 30, 49)); // Navy blue
// Create and configure the table for Film Projects
tableFilmProjects = createTable("Create", "Film", locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
JScrollPane scrollPaneFilmProjects = new JScrollPane(tableFilmProjects);
tableFilmProjectsPanel.add(scrollPaneFilmProjects, BorderLayout.CENTER);
// Create and configure the table panel to store Theater Projects table
tableTheaterProjectsPanel = new JPanel(new BorderLayout());
tableTheaterProjectsPanel.setBackground(new Color(18, 30, 49)); // Navy blue
// Create and configure the table for Theater Projects
tableTheaterProjects = createTable("Create", "Theater", locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
JScrollPane scrollPaneTheaterProjects = new JScrollPane(tableTheaterProjects);
tableTheaterProjectsPanel.add(scrollPaneTheaterProjects, BorderLayout.CENTER);
// Create and configure the table panel to store Music Projects table
tableMusicProjectsPanel = new JPanel(new BorderLayout());
tableMusicProjectsPanel.setBackground(new Color(18, 30, 49)); // Navy blue
// Create and configure the table for Music Projects
tableMusicProjects = createTable("Create", "Music", locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
JScrollPane scrollPaneMusicProjects = new JScrollPane(tableMusicProjects);
tableMusicProjectsPanel.add(scrollPaneMusicProjects, BorderLayout.CENTER);
// Create and configure the table panel to store TV Projects table
tableTVProjectsPanel = new JPanel(new BorderLayout());
tableTVProjectsPanel.setBackground(new Color(18, 30, 49)); // Navy blue
// Create and configure the table for TV Projects
tableTVProjects = createTable("Create", "TV", locationFilterComboBox.getSelectedItem().toString(),
venueSizeFilterComboBox.getSelectedItem().toString());
JScrollPane scrollPanelTVProjects = new JScrollPane(tableTVProjects);
tableTVProjectsPanel.add(scrollPanelTVProjects, BorderLayout.CENTER);
// Create a panel to hold the current table based on filters
// Note: this setting is controlled via the Filters triggers
tablesPanel = new JPanel(new GridLayout(0, 1));
// Add table panels to the all projects panel
tablesPanel.add(tableAllProjectsPanel);
// Add table and button panel to content panel, which is the main space in
// the GUI window
contentPanel.add(buttonsPanel, BorderLayout.NORTH); // display at the top
contentPanel.add(tablesPanel, BorderLayout.CENTER); // display centrally
// Add content panel to the frame (window)
frame.add(contentPanel);
// Set the frame as visible
frame.setVisible(true);
}
/**
* Method creates or updates tables based on selected filters and project type
* @param action
* @param typeOfProject
* @param selectedLocation
* @param selectedVenueSize
* @return
*/
private JTable createTable(String action, String typeOfProject,
String selectedLocation, String selectedVenueSize) {
DefaultTableModel model;
if(typeOfProject.equals("Film")) {
// Define column names
String[] columnNamesFilm = {"Project ID", "Project Name", "Project Type", "Project Date", "Project Location",
"Project Cost", "Price to Customer", "Size of Venue", "Duration", "Duration Unit", "Format"};
// Create table structure with column names and 0 rows if action requested
// by method call is to create (other option: Update)
if(action.equals("Create")) {
model = new DefaultTableModel(columnNamesFilm, 0);
}
else { // if action is Update, capture existing model and reset but don't create a new instance
model = (DefaultTableModel) tableFilmProjects.getModel();
model.setRowCount(0);
}
// Populate table model with project data based on project type passed
// FIlters consider all the three options of filters in the GUI
for (FilmProject project : filmProjects) {
if(project.getProjectType().equals(typeOfProject) && (
selectedLocation.equals("All") || project.getProjectLocation().equals(
selectedLocation)) && (selectedVenueSize.equals(
"All") || project.getSizeOfVenue().equals(
selectedVenueSize))) {
SimpleDateFormat newDateFormat = new SimpleDateFormat("dd/MM/yyyy");
String formattedDate = newDateFormat.format(project.getProjectDate());
Object[] rowData = {
project.getProjectId(),
project.getProjectName(),
project.getProjectType(),
formattedDate,
project.getProjectLocation(),
project.getProjectCost(),
project.getProjectPriceToCustomer(),
project.getSizeOfVenue(),
project.getProjectDuration(),
project.getDurationUnit(),
project.getFormat()
};
model.addRow(rowData);
}
}
}
else if(typeOfProject.equals("Music")) {
// Define column names
String[] columnNamesMusic = {"Project ID", "Project Name", "Project Type", "Project Date", "Project Location",
"Project Cost", "Price to Customer", "Size of Venue", "Duration", "Duration Unit", "Genre"};
// Create table with column names and 0 rows
if(action.equals("Create")) {
model = new DefaultTableModel(columnNamesMusic, 0);
}
else { // if action is Update, capture existing model and reset
model = (DefaultTableModel) tableMusicProjects.getModel();
model.setRowCount(0);
}
// Populate table model with music project data
for (MusicProject project : musicProjects) {
if(project.getProjectType().equals(typeOfProject) && (
selectedLocation.equals("All") || project.getProjectLocation().equals(
selectedLocation)) && (selectedVenueSize.equals(
"All") || project.getSizeOfVenue().equals(
selectedVenueSize))) {
SimpleDateFormat newDateFormat = new SimpleDateFormat("dd/MM/yyyy");
String formattedDate = newDateFormat.format(project.getProjectDate());
Object[] rowData = {
project.getProjectId(),
project.getProjectName(),
project.getProjectType(),
formattedDate,
project.getProjectLocation(),
project.getProjectCost(),
project.getProjectPriceToCustomer(),
project.getSizeOfVenue(),
project.getProjectDuration(),
project.getDurationUnit(),
project.getGenre()
};
model.addRow(rowData);
}
}
}
else if(typeOfProject.equals("Theater") ) {
// Define column names
String[] columnNamesTheater = {"Project ID", "Project Name", "Project Type", "Project Date", "Project Location",
"Project Cost", "Price to Customer", "Size of Venue", "Duration", "Duration Unit", "Playwright"};
// Create table with column names and 0 rows
if(action.equals("Create")) {
model = new DefaultTableModel(columnNamesTheater, 0);
}
else { // if action is Update, capture existing model and reset
model = (DefaultTableModel) tableTheaterProjects.getModel();
model.setRowCount(0);
}
// Populate table model with theater project data
for (TheaterProject project : theaterProjects) {
if(project.getProjectType().equals(typeOfProject) && (
selectedLocation.equals("All") || project.getProjectLocation().equals(
selectedLocation)) && (selectedVenueSize.equals(
"All") || project.getSizeOfVenue().equals(
selectedVenueSize))) {
SimpleDateFormat newDateFormat = new SimpleDateFormat("dd/MM/yyyy");
String formattedDate = newDateFormat.format(project.getProjectDate());
Object[] rowData = {
project.getProjectId(),
project.getProjectName(),
project.getProjectType(),
formattedDate,
project.getProjectLocation(),
project.getProjectCost(),
project.getProjectPriceToCustomer(),
project.getSizeOfVenue(),
project.getProjectDuration(),
project.getDurationUnit(),
project.getPlaywright()
};
model.addRow(rowData);
}
}
}
else if(typeOfProject.equals("TV")) {
// Define column names
String[] columnNamesTV = {"Project ID", "Project Name", "Project Type", "Project Date", "Project Location",
"Project Cost", "Price to Customer", "Size of Venue", "Duration", "Duration Unit", "Network"};
// Create table with column names and 0 rows
if(action.equals("Create")) {
model = new DefaultTableModel(columnNamesTV, 0);
}
else { // if action is Update, capture existing model and reset
model = (DefaultTableModel) tableTVProjects.getModel();
model.setRowCount(0);
}
// Populate table model with TV project data
for (TVProject project : tvProjects) {
if(project.getProjectType().equals(typeOfProject) && (
selectedLocation.equals("All") || project.getProjectLocation().equals(
selectedLocation)) && (selectedVenueSize.equals(
"All") || project.getSizeOfVenue().equals(
selectedVenueSize))) {
SimpleDateFormat newDateFormat = new SimpleDateFormat("dd/MM/yyyy");
String formattedDate = newDateFormat.format(project.getProjectDate());
Object[] rowData = {
project.getProjectId(),
project.getProjectName(),
project.getProjectType(),
formattedDate,
project.getProjectLocation(),
project.getProjectCost(),
project.getProjectPriceToCustomer(),
project.getSizeOfVenue(),
project.getProjectDuration(),
project.getDurationUnit(),
project.getNetwork()
};
model.addRow(rowData);
}
}
}
else if (typeOfProject.equals("All")) {
// Define column names
String[] columnNames = {"Project ID", "Project Name", "Project Type", "Project Date", "Project Location",
"Project Cost", "Price to Customer", "Size of Venue", "Duration", "Duration Unit"};
// Create table with column names and 0 rows
if(action.equals("Create")) {
model = new DefaultTableModel(columnNames, 0);
}
else { // if action is Update, capture existing model and reset
model = (DefaultTableModel) tableProjects.getModel();
model.setRowCount(0);
}
// Populate table model with all project data
for (Project project : projects) {
if((selectedLocation.equals("All") || project.getProjectLocation(
).equals(selectedLocation)) && (selectedVenueSize.equals(
"All") || project.getSizeOfVenue().equals(
selectedVenueSize))) {
SimpleDateFormat newDateFormat = new SimpleDateFormat("dd/MM/yyyy");
String formattedDate = newDateFormat.format(project.getProjectDate());
Object[] rowData = {
project.getProjectId(),
project.getProjectName(),
project.getProjectType(),
formattedDate,
project.getProjectLocation(),
project.getProjectCost(),
project.getProjectPriceToCustomer(),
project.getSizeOfVenue(),
project.getProjectDuration(),
project.getDurationUnit()
};
model.addRow(rowData);
}
}
}
else { // Use case if new project type is added via Excel
// Define column names
String[] columnNames = {"Project ID", "Project Name", "Project Type", "Project Date", "Project Location",
"Project Cost", "Price to Customer", "Size of Venue", "Duration", "Duration Unit"};
// Create table with column names and 0 rows
if(action.equals("Create")) {
model = new DefaultTableModel(columnNames, 0);
}
else { // if action is Update, capture existing model and reset
model = (DefaultTableModel) tableProjects.getModel();
model.setRowCount(0);
}
// Populate table model with project data
for (Project project : projects) {
if(project.getProjectType().equals(
typeOfProject) && (selectedLocation.equals(
"All") || project.getProjectLocation().equals(
selectedLocation)) && (selectedVenueSize.equals(
"All") || project.getSizeOfVenue().equals(
selectedVenueSize))) {
SimpleDateFormat newDateFormat = new SimpleDateFormat("dd/MM/yyyy");
String formattedDate = newDateFormat.format(project.getProjectDate());
Object[] rowData = {
project.getProjectId(),
project.getProjectName(),
project.getProjectType(),
formattedDate,
project.getProjectLocation(),
project.getProjectCost(),
project.getProjectPriceToCustomer(),
project.getSizeOfVenue(),
project.getProjectDuration(),
project.getDurationUnit()
};
model.addRow(rowData);
}
}}
// Create and return JTable with populated table model based on filters
return new JTable(model);
}
/**
* Based on Project Type filter together with location and venue size filters,
* generates financial summary of projects, including cost, revenue, profit and
* workload.
* @param selectedLocation
* @param selectedVenueSize
*/
private void summaryText(String selectedLocation, String selectedVenueSize) {
String summary = "Summary produced based on filters where Project Type is ";
DecimalFormat df = new DecimalFormat("#,##0.00");
// Based on the current filters and what table is visible within the tablesPanel
if(tableAllProjectsPanel.getParent()==tablesPanel) { // uses GUI components hierarchy to check if table is within tablesPanel
summary += "All";
if(!selectedLocation.equals("All")) {
summary += ",\nProject Location is: "+selectedLocation;
}
if(!selectedVenueSize.equals("All")) {
summary += "\nand Venue Size is: "+selectedVenueSize;
}
summary += "\n\n";
// Trackers
int projectsCount = 0;
double projectCost = 0.0;
double projectValue = 0.0;
int hours = 0;
int days = 0;
// loop through the projects to update trackers with count and sums as relevant
for (Project project : projects) {
if((selectedLocation.equals("All") || project.getProjectLocation(
).equals(selectedLocation)) && (selectedVenueSize.equals(
"All") || project.getSizeOfVenue().equals(
selectedVenueSize))) {
projectsCount += 1;
projectCost += project.getProjectCost();
projectValue += project.getProjectPriceToCustomer();
if(project.getDurationUnit().equals("hours")) {
hours += project.getProjectDuration();
} else if (project.getDurationUnit().equals("days")) {
days += project.getProjectDuration();
}
}
}
double profit = projectValue - projectCost;
double workload = days + (hours/24);
// Text to be generated with values of trackers
summary += "Scotia Visual Productions has produced a total of "+ Integer.toString(
projectsCount)+" projects.\n"
+ "The cost of the projects has sum to £"+
df.format(projectCost)+" and\nhas generated a revenue of £"+
df.format(projectValue)+".\nBased on this performance, "
+ "the business has achieved £"+df.format(profit)+"\nin profit.\n"
+"The "+ Integer.toString(projectsCount)+" projects required "+
df.format(workload)+" days of work.";
}
else if(tableFilmProjectsPanel.getParent()==tablesPanel) {
summary += "Film";
if(!selectedLocation.equals("All")) {
summary += ",\nProject Location is: "+selectedLocation;
}
if(!selectedVenueSize.equals("All")) {
summary += "\nand Venue Size is: "+selectedVenueSize;
}
summary += "\n\n";
int projectsCount = 0;
double projectCost = 0.0;
double projectValue = 0.0;
int hours = 0;
int days = 0;
for (FilmProject project : filmProjects) {
if((selectedLocation.equals("All") || project.getProjectLocation(
).equals(selectedLocation)) && (selectedVenueSize.equals(
"All") || project.getSizeOfVenue().equals(
selectedVenueSize))) {
projectsCount += 1;
projectCost += project.getProjectCost();
projectValue += project.getProjectPriceToCustomer();
if(project.getDurationUnit().equals("hours")) {
hours += project.getProjectDuration();
} else if (project.getDurationUnit().equals("days")) {
days += project.getProjectDuration();
}
}
}
double profit = projectValue - projectCost;
double workload = days + (hours/24);
summary += "Scotia Visual Productions has produced a total of "+ Integer.toString(
projectsCount)+" Film projects.\n"
+ "The cost of the projects has sum to £"+
df.format(projectCost)+" and\nhas generated a revenue of £"+
df.format(projectValue)+".\nBased on this performance, "
+ "the business has achieved £"+df.format(profit)+"\nin profit.\n"
+"The "+ Integer.toString(projectsCount)+" projects required "+
df.format(workload)+" days of work.";
}
else if(tableTheaterProjectsPanel.getParent()==tablesPanel) {
summary += "Theater";
if(!selectedLocation.equals("All")) {
summary += ",\nProject Location is: "+selectedLocation;
}
if(!selectedVenueSize.equals("All")) {
summary += "\nand Venue Size is: "+selectedVenueSize;
}
summary += "\n\n";
int projectsCount = 0;
double projectCost = 0.0;
double projectValue = 0.0;
int hours = 0;
int days = 0;
for (TheaterProject project : theaterProjects) {
if((selectedLocation.equals("All") || project.getProjectLocation(
).equals(selectedLocation)) && (selectedVenueSize.equals(
"All") || project.getSizeOfVenue().equals(
selectedVenueSize))) {
projectsCount += 1;
projectCost += project.getProjectCost();
projectValue += project.getProjectPriceToCustomer();
if(project.getDurationUnit().equals("hours")) {
hours += project.getProjectDuration();
} else if (project.getDurationUnit().equals("days")) {
days += project.getProjectDuration();
}
}
}
double profit = projectValue - projectCost;
double workload = days + (hours/24);
summary += "Scotia Visual Productions has produced a total of "+ Integer.toString(
projectsCount)+" Theater projects.\n"
+ "The cost of the projects has sum to £"+
df.format(projectCost)+" and\nhas generated a revenue of £"+
df.format(projectValue)+".\nBased on this performance, "
+ "the business has achieved £"+df.format(profit)+"\nin profit.\n"
+"The "+ Integer.toString(projectsCount)+" projects required "+
df.format(workload)+" days of work.";
;
}
else if(tableMusicProjectsPanel.getParent()==tablesPanel) {
summary += "Music";
if(!selectedLocation.equals("All")) {
summary += ",\nProject Location is: "+selectedLocation;
}
if(!selectedVenueSize.equals("All")) {
summary += "\nand Venue Size is: "+selectedVenueSize;
}
summary += "\n\n";
int projectsCount = 0;
double projectCost = 0.0;
double projectValue = 0.0;
int hours = 0;
int days = 0;
for (MusicProject project : musicProjects) {
if((selectedLocation.equals("All") || project.getProjectLocation(
).equals(selectedLocation)) && (selectedVenueSize.equals(
"All") || project.getSizeOfVenue().equals(
selectedVenueSize))) {
projectsCount += 1;
projectCost += project.getProjectCost();
projectValue += project.getProjectPriceToCustomer();
if(project.getDurationUnit().equals("hours")) {
hours += project.getProjectDuration();
} else if (project.getDurationUnit().equals("days")) {
days += project.getProjectDuration();
}
}
}
double profit = projectValue - projectCost;
double workload = days + (hours/24);
summary += "Scotia Visual Productions has produced a total of "+ Integer.toString(
projectsCount)+" Music projects.\n"
+ "The cost of the projects has sum to £"+
df.format(projectCost)+" and\nhas generated a revenue of £"+
df.format(projectValue)+".\nBased on this performance, "
+ "the business has achieved £"+df.format(profit)+"\nin profit.\n"
+"The "+ Integer.toString(projectsCount)+" projects required "+
df.format(workload)+" days of work.";
}
else if(tableTVProjectsPanel.getParent()==tablesPanel) {
summary += "TV";
if(!selectedLocation.equals("All")) {
summary += ",\nProject Location is: "+selectedLocation;
}
if(!selectedVenueSize.equals("All")) {
summary += "\nand Venue Size is: "+selectedVenueSize;
}
summary += "\n\n";