-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.java
More file actions
789 lines (665 loc) · 35.7 KB
/
Window.java
File metadata and controls
789 lines (665 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
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.filechooser.FileNameExtensionFilter;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ChaseCarnaroli
*/
public class Window extends javax.swing.JFrame {
/**
* Creates new form Window
*/
public Window() {
initComponents();
addNameTextFieldListener();
setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
viewButtonGroup = new javax.swing.ButtonGroup();
textField1 = new java.awt.TextField();
groupsPanel = new javax.swing.JPanel();
groupComboBox = new javax.swing.JComboBox<>();
addGroupButton = new javax.swing.JButton();
renameGroupButton = new javax.swing.JButton();
removeGroupButton = new javax.swing.JButton();
editRosterButton = new javax.swing.JButton();
rosterDisplayPane = new javax.swing.JScrollPane();
rosterDisplay = new javax.swing.JList<>();
addPersonPane = new javax.swing.JPanel();
addPersonButton = new javax.swing.JButton();
nameTextField = new javax.swing.JTextField();
listPanel = new javax.swing.JPanel();
listDisplayPane = new javax.swing.JScrollPane();
listDisplay = new javax.swing.JTextArea();
listWarningLabel = new javax.swing.JLabel();
generateListButton = new javax.swing.JButton();
listRadioButton = new javax.swing.JRadioButton();
targetRadioButton = new javax.swing.JRadioButton();
viewTypeLabel = new javax.swing.JLabel();
numberRadioButton = new javax.swing.JRadioButton();
showGroupCheckBox = new javax.swing.JCheckBox();
jMenuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
saveItem = new javax.swing.JMenuItem();
restartItem = new javax.swing.JMenuItem();
helpItem = new javax.swing.JMenu();
howToUseItem = new javax.swing.JMenuItem();
reportIssueItem = new javax.swing.JMenuItem();
sourceCodeItem = new javax.swing.JMenuItem();
textField1.setText("textField1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Random List Generator");
setMinimumSize(new java.awt.Dimension(910, 535));
setPreferredSize(new java.awt.Dimension(910, 535));
setSize(getMinimumSize());
groupsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Group Manager"));
groupComboBox.setEnabled(false);
groupComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
groupComboBoxActionPerformed(evt);
}
});
addGroupButton.setText("Add Group");
addGroupButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addGroupButtonActionPerformed(evt);
}
});
renameGroupButton.setText("Rename Group");
renameGroupButton.setEnabled(false);
renameGroupButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
renameGroupButtonActionPerformed(evt);
}
});
removeGroupButton.setText("Remove Group");
removeGroupButton.setEnabled(false);
removeGroupButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removeGroupButtonActionPerformed(evt);
}
});
editRosterButton.setText("Edit Roster");
editRosterButton.setEnabled(false);
editRosterButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editRosterButtonActionPerformed(evt);
}
});
rosterDisplayPane.setBorder(javax.swing.BorderFactory.createLineBorder(javax.swing.UIManager.getDefaults().getColor("TextArea.inactiveForeground")));
rosterDisplay.setBorder(javax.swing.BorderFactory.createTitledBorder("Group Roster"));
rosterDisplay.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N
rosterDisplay.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
rosterDisplay.setEnabled(false);
rosterDisplayPane.setViewportView(rosterDisplay);
addPersonPane.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
addPersonButton.setText("Add Person");
addPersonButton.setEnabled(false);
addPersonButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addPersonButtonActionPerformed(evt);
}
});
nameTextField.setForeground(new java.awt.Color(153, 153, 153));
nameTextField.setText("Enter Name");
nameTextField.setEnabled(false);
nameTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nameTextFieldActionPerformed(evt);
}
});
javax.swing.GroupLayout addPersonPaneLayout = new javax.swing.GroupLayout(addPersonPane);
addPersonPane.setLayout(addPersonPaneLayout);
addPersonPaneLayout.setHorizontalGroup(
addPersonPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(addPersonPaneLayout.createSequentialGroup()
.addContainerGap()
.addComponent(nameTextField)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(addPersonButton, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
addPersonPaneLayout.setVerticalGroup(
addPersonPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, addPersonPaneLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(addPersonPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(addPersonButton)
.addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
javax.swing.GroupLayout groupsPanelLayout = new javax.swing.GroupLayout(groupsPanel);
groupsPanel.setLayout(groupsPanelLayout);
groupsPanelLayout.setHorizontalGroup(
groupsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, groupsPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(groupsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(addPersonPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(rosterDisplayPane)
.addGroup(groupsPanelLayout.createSequentialGroup()
.addGroup(groupsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(groupComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(groupsPanelLayout.createSequentialGroup()
.addComponent(editRosterButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(renameGroupButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(groupsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(removeGroupButton, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
.addComponent(addGroupButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap())
);
groupsPanelLayout.setVerticalGroup(
groupsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(groupsPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(groupsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(groupComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(addGroupButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(groupsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(removeGroupButton)
.addComponent(editRosterButton)
.addComponent(renameGroupButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rosterDisplayPane, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(addPersonPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
listPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("List"));
listDisplayPane.setBorder(javax.swing.BorderFactory.createLineBorder(javax.swing.UIManager.getDefaults().getColor("TextArea.inactiveForeground")));
listDisplayPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
listDisplayPane.setViewportBorder(javax.swing.BorderFactory.createTitledBorder("List Display"));
listDisplayPane.setEnabled(false);
listDisplay.setEditable(false);
listDisplay.setColumns(20);
listDisplay.setLineWrap(true);
listDisplay.setRows(5);
listDisplay.setWrapStyleWord(true);
listDisplayPane.setViewportView(listDisplay);
listWarningLabel.setFont(new java.awt.Font("Lucida Grande", 2, 10)); // NOI18N
listWarningLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
listWarningLabel.setText("<html><div style='text-align: center;'> Sometimes 2 people from the same group may be placed next to each other in the list.<BR> When this happens, a warning message will be displayed.<BR><BR></div></html>");
generateListButton.setText("Generate Random List");
generateListButton.setEnabled(false);
generateListButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
generateListButtonActionPerformed(evt);
}
});
viewButtonGroup.add(listRadioButton);
listRadioButton.setText("List");
listRadioButton.setEnabled(false);
listRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
listRadioButtonActionPerformed(evt);
}
});
viewButtonGroup.add(targetRadioButton);
targetRadioButton.setText("Target");
targetRadioButton.setEnabled(false);
targetRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
targetRadioButtonActionPerformed(evt);
}
});
viewTypeLabel.setFont(new java.awt.Font("Lucida Grande", 0, 14)); // NOI18N
viewTypeLabel.setText("View Type:");
viewButtonGroup.add(numberRadioButton);
numberRadioButton.setSelected(true);
numberRadioButton.setText("Number");
numberRadioButton.setEnabled(false);
numberRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
numberRadioButtonActionPerformed(evt);
}
});
showGroupCheckBox.setText("Show Group");
showGroupCheckBox.setEnabled(false);
showGroupCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
showGroupCheckBoxActionPerformed(evt);
}
});
javax.swing.GroupLayout listPanelLayout = new javax.swing.GroupLayout(listPanel);
listPanel.setLayout(listPanelLayout);
listPanelLayout.setHorizontalGroup(
listPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(listPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(listPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(listPanelLayout.createSequentialGroup()
.addComponent(showGroupCheckBox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(viewTypeLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(numberRadioButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(listRadioButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(targetRadioButton))
.addComponent(listWarningLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(listPanelLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(generateListButton)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(listDisplayPane))
.addContainerGap())
);
listPanelLayout.setVerticalGroup(
listPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(listPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(generateListButton, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(listPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(viewTypeLabel)
.addComponent(listRadioButton)
.addComponent(numberRadioButton)
.addComponent(showGroupCheckBox)
.addComponent(targetRadioButton))
.addGap(9, 9, 9)
.addComponent(listDisplayPane)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(listWarningLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
fileMenu.setText("File");
saveItem.setText("Save");
saveItem.setEnabled(false);
saveItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveItemActionPerformed(evt);
}
});
fileMenu.add(saveItem);
restartItem.setText("Restart");
restartItem.setEnabled(false);
restartItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
restartItemActionPerformed(evt);
}
});
fileMenu.add(restartItem);
jMenuBar.add(fileMenu);
helpItem.setText("Help");
howToUseItem.setText("How to Use");
howToUseItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
howToUseItemActionPerformed(evt);
}
});
helpItem.add(howToUseItem);
reportIssueItem.setText("Report Issue");
reportIssueItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
reportIssueItemActionPerformed(evt);
}
});
helpItem.add(reportIssueItem);
sourceCodeItem.setText("Source Code");
sourceCodeItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sourceCodeItemActionPerformed(evt);
}
});
helpItem.add(sourceCodeItem);
jMenuBar.add(helpItem);
setJMenuBar(jMenuBar);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(groupsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(4, 4, 4)
.addComponent(listPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(listPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(groupsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
setSize(new java.awt.Dimension(908, 557));
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
private void removeGroupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeGroupButtonActionPerformed
controller.removeGroupClicked();
}//GEN-LAST:event_removeGroupButtonActionPerformed
private void addPersonButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPersonButtonActionPerformed
if(!hintTextDisplayed){controller.addPerson(nameTextField.getText());}
resetNameTextField();
}//GEN-LAST:event_addPersonButtonActionPerformed
private void listRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listRadioButtonActionPerformed
controller.setSelectedViewType(ListViewType.LIST);
}//GEN-LAST:event_listRadioButtonActionPerformed
private void targetRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_targetRadioButtonActionPerformed
controller.setSelectedViewType(ListViewType.TARGET);
}//GEN-LAST:event_targetRadioButtonActionPerformed
private void reportIssueItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reportIssueItemActionPerformed
controller.openWebsite("https://github.com/ChaseC99/RandomCircularListGenerator/issues/new");
}//GEN-LAST:event_reportIssueItemActionPerformed
private void nameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_nameTextFieldActionPerformed
private void addGroupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addGroupButtonActionPerformed
controller.addGroupClicked();
}//GEN-LAST:event_addGroupButtonActionPerformed
private void groupComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groupComboBoxActionPerformed
controller.setSelectedGroup(getSelectedComboBoxGroup());
}//GEN-LAST:event_groupComboBoxActionPerformed
private void sourceCodeItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sourceCodeItemActionPerformed
controller.openWebsite("https://github.com/ChaseC99/RandomCircularListGenerator");
}//GEN-LAST:event_sourceCodeItemActionPerformed
private void renameGroupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_renameGroupButtonActionPerformed
controller.renameGroupClicked();
}//GEN-LAST:event_renameGroupButtonActionPerformed
private void editRosterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editRosterButtonActionPerformed
controller.editRosterClicked();
}//GEN-LAST:event_editRosterButtonActionPerformed
private void generateListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateListButtonActionPerformed
controller.generateListClicked();
}//GEN-LAST:event_generateListButtonActionPerformed
private void numberRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numberRadioButtonActionPerformed
controller.setSelectedViewType(ListViewType.NUMBER);
}//GEN-LAST:event_numberRadioButtonActionPerformed
private void showGroupCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showGroupCheckBoxActionPerformed
controller.showGroupChecked(showGroupCheckBox.isSelected());
}//GEN-LAST:event_showGroupCheckBoxActionPerformed
private void restartItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restartItemActionPerformed
controller.resetClicked();
}//GEN-LAST:event_restartItemActionPerformed
private void saveItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveItemActionPerformed
controller.saveClicked();
}//GEN-LAST:event_saveItemActionPerformed
private void howToUseItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_howToUseItemActionPerformed
controller.openWebsite("https://youtu.be/64j0xa_kzUQ");
}//GEN-LAST:event_howToUseItemActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
// Create and display the form
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Window().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addGroupButton;
private javax.swing.JButton addPersonButton;
private javax.swing.JPanel addPersonPane;
private javax.swing.JButton editRosterButton;
private javax.swing.JMenu fileMenu;
private javax.swing.JButton generateListButton;
private javax.swing.JComboBox<Group> groupComboBox;
private javax.swing.JPanel groupsPanel;
private javax.swing.JMenu helpItem;
private javax.swing.JMenuItem howToUseItem;
private javax.swing.JMenuBar jMenuBar;
private javax.swing.JTextArea listDisplay;
private javax.swing.JScrollPane listDisplayPane;
private javax.swing.JPanel listPanel;
private javax.swing.JRadioButton listRadioButton;
private javax.swing.JLabel listWarningLabel;
private javax.swing.JTextField nameTextField;
private javax.swing.JRadioButton numberRadioButton;
private javax.swing.JButton removeGroupButton;
private javax.swing.JButton renameGroupButton;
private javax.swing.JMenuItem reportIssueItem;
private javax.swing.JMenuItem restartItem;
private javax.swing.JList<Person> rosterDisplay;
private javax.swing.JScrollPane rosterDisplayPane;
private javax.swing.JMenuItem saveItem;
private javax.swing.JCheckBox showGroupCheckBox;
private javax.swing.JMenuItem sourceCodeItem;
private javax.swing.JRadioButton targetRadioButton;
private java.awt.TextField textField1;
private javax.swing.ButtonGroup viewButtonGroup;
private javax.swing.JLabel viewTypeLabel;
// End of variables declaration//GEN-END:variables
// MY ADDITIONAL CODE, NOT GENERATED BY NETBEANS //
/* Controller code */
// Variable to represent the Controller
private Controller controller;
// Sets the controller for the Window
public void setController(Controller controller){
this.controller = controller;
}
/* UI Buttons code */
// Enables or disables all the componets, except the addGroupButton
// post: the components are enabled or disabled
public void enableComponents(boolean enable){
groupComboBox.setEnabled(enable);
editRosterButton.setEnabled(enable);
renameGroupButton.setEnabled(enable);
removeGroupButton.setEnabled(enable);
rosterDisplay.setEnabled(enable);
nameTextField.setEnabled(enable);
addPersonButton.setEnabled(enable);
generateListButton.setEnabled(enable);
showGroupCheckBox.setEnabled(enable);
targetRadioButton.setEnabled(enable);
listRadioButton.setEnabled(enable);
numberRadioButton.setEnabled(enable);
listDisplayPane.setEnabled(enable);
listDisplay.setEnabled(enable);
saveItem.setEnabled(enable);
restartItem.setEnabled(enable);
}
// Enables or disables all the components, including the addGroupButton
// post: the UI is enabled or diabled
public void enableUI(boolean enable){
addGroupButton.setEnabled(enable);
enableComponents(enable);
}
/* nameTextField code */
/* additional functionality is given to the nameTextField
* - hint text is added, which says "Enter Name"
* - when clicked on, hint text disapears
* - when resetNameTextField is called, hint text reappears
*/
// nameTextField variables
private boolean hintTextDisplayed = true; // Represents whether or not the hint text is displayed
private boolean addNameFocused = false; // Represents whether or not the textField is focused
// Adds FocuseListener and ActionListener to the text field
private void addNameTextFieldListener() {
// Adds focus listener to the textField
nameTextField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
/* When the text field is selected,
* if the hint text is displayed,
* then the text field is cleared, the color is set to black
* and hintTextDisplayed is set to false
*/
if(hintTextDisplayed){
nameTextField.setText("");
nameTextField.setForeground(Color.black);
hintTextDisplayed = false;
}
addNameFocused = true;
}
@Override
public void focusLost(FocusEvent e) {
/* When the text field is deselected,
* if the text field is empty,
* the hint text is put back in the text field
*/
if(nameTextField.getText().length() == 0){
resetNameTextField();
}
addNameFocused = false;
}
});
// Adds action listener to the textField
nameTextField.addActionListener(new ActionListener() {
/* When the enter key is pressed, this method is called
* If the textField is focused, then addPersonButtonAction is called
* It then focuses on addPersonButton so textField can reset
*/
@Override
public void actionPerformed(ActionEvent e) {
if(addNameFocused)
{
addPersonButtonActionPerformed(null); // calls addPersonButton
addPersonButton.requestFocus(); // focus leaves textField and goes to addPersonButton
}
}
});
}
// Resets the text field and displays hint text
// post: hint text is displayed and hintTextDisplayed is set to true
private void resetNameTextField() {
nameTextField.setText("Enter Name");
nameTextField.setForeground(new Color(153, 153, 153));
hintTextDisplayed = true;
}
/* groupComboBox code */
// post: group is added to comboBox and set as selected item
public void addGroupToComboBox(Group group){
groupComboBox.addItem(group);
groupComboBox.setSelectedItem(group);
}
// post: group is removed from the comboBox
public void removeGroupFromComboBox(int index){
groupComboBox.removeItemAt(index);
}
// I tried to use .getSelectedItem() but that returned an Obj, not Group
// So instead I had to use .getItemAt(.getSelectedIndex()) because that returned Group
// post: returns the selected group from the comboBox
public Group getSelectedComboBoxGroup(){
int index = groupComboBox.getSelectedIndex();
if (index == -1){
return null;
} else {
return groupComboBox.getItemAt(index);
}
}
/* PopUp Menus code */
// displays JOptionPane asking user if user wants to delete group
// post: returns true if yes is selected, else returns false
public boolean removeGroupPopUp(Group selectedGroup){
// Open JOptionPane, asking if user wants to delete group
int response = JOptionPane.showConfirmDialog(this, "Are you sure you want to remove '" + selectedGroup.toString() + "'?", "Remove Group", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if(response == JOptionPane.YES_OPTION){
return true;
} else {
return false;
}
}
// displays JOptionPane prompting user to input a group name
// post: returns the group name, null if cancel was clicked
public String addGroupPopUp(){
String groupName = JOptionPane.showInputDialog("Enter Group Name:");
return groupName;
}
// displays JOptionPane prompting user to change a group's name
// post: returns the new group name, null if cancel was clicked
public String renameGroupPopUp(String originalName){
String newName = JOptionPane.showInputDialog("Enter new name for '" + originalName +"':", originalName);
return newName;
}
// displays JOptionPane asking user if user wants to reset the program
// post: returns true if yes is selected, else returns false
public boolean resetPopUp(){
// Open JOptionPane, asking if user wants to reset the program
int response = JOptionPane.showConfirmDialog(this, "Are you sure you want to reset the program?\nAll groups will be removed and the list display will be cleared.\n\nThis cannot be undone!", "Remove Group", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if(response == JOptionPane.YES_OPTION){
return true;
} else {
return false;
}
}
// display EditRosterPopUp prompting the user to update the roster
public void editRosterPopUp(Group group){
// Generate EditRosterPopUp, the popup does the rest of the work
EditRosterPopUp popUp = new EditRosterPopUp(this, controller);
}
// display error message, telling user each group must have at least one person
public void generateListErrorPopUp(){
JOptionPane.showMessageDialog(this, "One or more groups contain no people.\nPlease make sure all groups have at least one person.", "Error - Empty Group", JOptionPane.ERROR_MESSAGE);
}
// display error message, telling user that the group must have a name
public void invalidGroupNamePopUp(){
JOptionPane.showMessageDialog(this, "Groups must have a name.\nPlease enter something for the group name.", "Invalid Group Name", JOptionPane.ERROR_MESSAGE);
}
public void saveErrorNoListPopUp(){
JOptionPane.showMessageDialog(this, "There is currently no list to save.\nPlease click \"Generate Random List\" and try again.", "No List - Cannot Save", JOptionPane.ERROR_MESSAGE);
}
// display JFileChooser to save a file
// post: returns the saved file, null if canceled
public File fileChooserPopUp(){
// Create JFileChooser
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new FileNameExtensionFilter("Text Files", "txt", "text")); // set file filter
fileChooser.setSelectedFile(new File("list.txt")); // set default file name
// Prompt user to save the file
int response = fileChooser.showSaveDialog(this); // generate save file dialog
// If the user saves a file, proceed, otherwise return null
if(response == JFileChooser.APPROVE_OPTION){
// Get saved file from fileChooser
File savedFile = fileChooser.getSelectedFile();
// Check to make sure file ends with ".txt"
String fileName = savedFile.getAbsolutePath();
if(!fileName.endsWith(".txt") ){
savedFile = new File(fileName + ".txt");
}
return savedFile;
} else {
return null;
}
}
/* Roster Display code */
// updates display to inputed list and updates title border to the group name
public void updateRosterDisplay(){
Group selectedGroup = controller.getSelectedGroup();
if(selectedGroup == null){
rosterDisplay.setListData(new Person[0]);
rosterDisplay.setBorder(BorderFactory.createTitledBorder("Group Roster"));
} else {
rosterDisplay.setListData(selectedGroup.getRosterAsArray());
rosterDisplay.setBorder(BorderFactory.createTitledBorder(selectedGroup.getGroupName() + " Roster"));
}
}
/* List Display code */
// sets the text of listDisplay
public void updateListDisplay(String text){
listDisplay.setText(text);
}
/* Reset code */
// resets UI
// post: the UI looks like how it does when it first launced
public void reset(){
updateRosterDisplay();
updateListDisplay("");
groupComboBox.removeAllItems();
showGroupCheckBox.setSelected(false);
enableComponents(false);
}
}