25
25
import java .io .IOException ;
26
26
import java .io .InputStream ;
27
27
import java .io .OutputStream ;
28
+ import java .nio .charset .StandardCharsets ;
29
+ import java .time .LocalDate ;
28
30
import java .util .regex .Matcher ;
29
31
import java .util .regex .Pattern ;
30
32
53
55
import javax .swing .border .TitledBorder ;
54
56
55
57
import org .apache .commons .io .IOUtils ;
56
- import org .joda .time .LocalDate ;
57
58
58
59
import com .imsweb .datagenerator .naaccr .NaaccrDataGeneratorOptions ;
59
60
import com .imsweb .layout .LayoutFactory ;
@@ -121,18 +122,10 @@ public StandaloneNaaccrDataGenerator() {
121
122
centerPnl .add (createControlsPanel ());
122
123
this .getContentPane ().add (centerPnl , BorderLayout .CENTER );
123
124
124
- Thread .setDefaultUncaughtExceptionHandler (new Thread .UncaughtExceptionHandler () {
125
- @ Override
126
- public void uncaughtException (Thread t , final Throwable e ) {
127
- SwingUtilities .invokeLater (new Runnable () {
128
- @ Override
129
- public void run () {
130
- String msg = "An unexpected error happened, it is recommended to close the application.\n \n Error: " + (e .getMessage () == null ? "null access" : e .getMessage ());
131
- JOptionPane .showMessageDialog (StandaloneNaaccrDataGenerator .this , msg , "Error" , JOptionPane .ERROR_MESSAGE );
132
- }
133
- });
134
- }
135
- });
125
+ Thread .setDefaultUncaughtExceptionHandler ((t , e ) -> SwingUtilities .invokeLater (() -> {
126
+ String msg = "An unexpected error happened, it is recommended to close the application.\n \n Error: " + (e .getMessage () == null ? "null access" : e .getMessage ());
127
+ JOptionPane .showMessageDialog (StandaloneNaaccrDataGenerator .this , msg , "Error" , JOptionPane .ERROR_MESSAGE );
128
+ }));
136
129
137
130
this .addComponentListener (new ComponentAdapter () {
138
131
@ Override
@@ -149,7 +142,7 @@ private static String getVersion() {
149
142
// this will make it work when running from the JAR file
150
143
try (InputStream is = Thread .currentThread ().getContextClassLoader ().getResourceAsStream ("DATA-GENERATOR-VERSION" )) {
151
144
if (is != null )
152
- version = IOUtils .readLines (is ).get (0 );
145
+ version = IOUtils .readLines (is , StandardCharsets . UTF_8 ).get (0 );
153
146
}
154
147
catch (IOException e ) {
155
148
version = null ;
@@ -158,7 +151,7 @@ private static String getVersion() {
158
151
// this will make it work when running from an IDE
159
152
if (version == null ) {
160
153
try (FileInputStream is = new FileInputStream (System .getProperty ("user.dir" ) + File .separator + "VERSION" )) {
161
- version = IOUtils .readLines (is ).get (0 );
154
+ version = IOUtils .readLines (is , StandardCharsets . UTF_8 ).get (0 );
162
155
}
163
156
catch (IOException e ) {
164
157
version = null ;
@@ -195,13 +188,10 @@ protected JPanel createOptionsPanel() {
195
188
pathPnl .add (_targetFld );
196
189
pathPnl .add (Box .createHorizontalStrut (10 ));
197
190
JButton browseBtn = new JButton ("Browse..." );
198
- browseBtn .addActionListener (new ActionListener () {
199
- @ Override
200
- public void actionPerformed (ActionEvent e ) {
201
- if (_fileChooser .showDialog (StandaloneNaaccrDataGenerator .this , "Select" ) == JFileChooser .APPROVE_OPTION ) {
202
- File file = new File (_targetFld .getText ());
203
- _targetFld .setText (new File (_fileChooser .getSelectedFile (), file .getName ()).getPath ());
204
- }
191
+ browseBtn .addActionListener (e -> {
192
+ if (_fileChooser .showDialog (StandaloneNaaccrDataGenerator .this , "Select" ) == JFileChooser .APPROVE_OPTION ) {
193
+ File file = new File (_targetFld .getText ());
194
+ _targetFld .setText (new File (_fileChooser .getSelectedFile (), file .getName ()).getPath ());
205
195
}
206
196
});
207
197
pathPnl .add (browseBtn );
@@ -215,12 +205,9 @@ public void actionPerformed(ActionEvent e) {
215
205
formatPnl .add (new JLabel ("Format:" ));
216
206
formatPnl .add (Box .createHorizontalStrut (5 ));
217
207
_formatBox = new JComboBox <>(new String [] {_FORMAT_16_ABS , _FORMAT_16_INC , _FORMAT_15_ABS , _FORMAT_15_INC });
218
- _formatBox .addActionListener (new ActionListener () {
219
- @ Override
220
- public void actionPerformed (ActionEvent e ) {
221
- if (!_targetFld .getText ().isEmpty ())
222
- _targetFld .setText (fixTargetFile ());
223
- }
208
+ _formatBox .addActionListener (e -> {
209
+ if (!_targetFld .getText ().isEmpty ())
210
+ _targetFld .setText (fixTargetFile ());
224
211
});
225
212
formatPnl .add (_formatBox );
226
213
formatPnl .add (Box .createHorizontalStrut (15 ));
@@ -229,12 +216,9 @@ public void actionPerformed(ActionEvent e) {
229
216
formatPnl .add (new JLabel ("Compression:" ));
230
217
formatPnl .add (Box .createHorizontalStrut (5 ));
231
218
_compressionBox = new JComboBox <>(new String [] {_COMPRESSION_NONE , _COMPRESSION_GZIP });
232
- _compressionBox .addActionListener (new ActionListener () {
233
- @ Override
234
- public void actionPerformed (ActionEvent e ) {
235
- if (!_targetFld .getText ().isEmpty ())
236
- _targetFld .setText (fixTargetFile ());
237
- }
219
+ _compressionBox .addActionListener (e -> {
220
+ if (!_targetFld .getText ().isEmpty ())
221
+ _targetFld .setText (fixTargetFile ());
238
222
});
239
223
formatPnl .add (_compressionBox );
240
224
filePnl .add (formatPnl );
@@ -352,79 +336,73 @@ protected JPanel createControlsPanel() {
352
336
JPanel pnl = new JPanel ();
353
337
pnl .setLayout (new FlowLayout (FlowLayout .CENTER , 0 , 0 ));
354
338
_processBtn = new JButton ("Create File" );
355
- _processBtn .addActionListener (new ActionListener () {
356
- @ Override
357
- public void actionPerformed (ActionEvent e ) {
358
-
359
- // get the target file
360
- File targetFile = new File (_targetFld .getText ());
361
- if (targetFile .exists ()) {
362
- String msg = "Target file already exists, are you sure you want to replace it?" ;
363
- int result = JOptionPane .showConfirmDialog (StandaloneNaaccrDataGenerator .this , msg , "Confirmation" , JOptionPane .YES_NO_OPTION );
364
- if (result != JOptionPane .YES_OPTION )
365
- return ;
366
- }
367
-
368
- // get the number of records
369
- String numRecsRaw = _numRecFld .getText ().trim ();
370
- if (!numRecsRaw .matches ("\\ d+" ) || numRecsRaw .length () > 8 ) {
371
- String message = "Wrong format for number of records, needs to be 1 to 8 digits." ;
372
- JOptionPane .showMessageDialog (StandaloneNaaccrDataGenerator .this , message , "Error" , JOptionPane .ERROR_MESSAGE );
339
+ _processBtn .addActionListener (e -> {
340
+
341
+ // get the target file
342
+ File targetFile = new File (_targetFld .getText ());
343
+ if (targetFile .exists ()) {
344
+ String msg = "Target file already exists, are you sure you want to replace it?" ;
345
+ int result = JOptionPane .showConfirmDialog (StandaloneNaaccrDataGenerator .this , msg , "Confirmation" , JOptionPane .YES_NO_OPTION );
346
+ if (result != JOptionPane .YES_OPTION )
373
347
return ;
374
- }
375
- int numRecords = Integer .parseInt (numRecsRaw );
376
-
377
- // get the DX year range
378
- String dxYearRaw = _dxYearFld .getText ();
379
- if (!dxYearRaw .matches ("\\ d{4}-\\ d{4}" ) && !dxYearRaw .matches ("\\ d{4}" )) {
380
- String message = "Wrong format for DX year, needs to be nnnn or nnnn-nnnn." ;
381
- JOptionPane .showMessageDialog (StandaloneNaaccrDataGenerator .this , message , "Error" , JOptionPane .ERROR_MESSAGE );
382
- return ;
383
- }
384
- int dxStart , dxEnd ;
385
- if (dxYearRaw .contains ("-" )) {
386
- dxStart = Integer .parseInt (dxYearRaw .split ("-" )[0 ]);
387
- dxEnd = Integer .parseInt (dxYearRaw .split ("-" )[1 ]);
388
- }
389
- else
390
- dxStart = dxEnd = Integer .parseInt (dxYearRaw );
391
-
392
- // get the layout ID
393
- String layoutId = getFormatIdFromLabel ((String )_formatBox .getSelectedItem ());
394
-
395
- // create the options
396
- NaaccrDataGeneratorOptions options = new NaaccrDataGeneratorOptions ();
397
- try {
398
- if (_numTumPerPatFixed .isSelected ())
399
- options .setNumTumorsPerPatient (Integer .valueOf (((String )_numTumPerPatBox .getSelectedItem ()).trim ()));
400
- options .setMinDxYear (dxStart );
401
- options .setMaxDxYear (dxEnd );
402
- String state = (String )_stateBox .getSelectedItem ();
403
- if (state .matches ("[A-Z][A-Z]" ))
404
- options .setState (state );
405
- if (_vsBox .getSelectedItem ().toString ().toLowerCase ().contains ("coc" ))
406
- options .setVitalStatusDeadValue ("0" );
407
- }
408
- catch (IllegalArgumentException exception ) {
409
- JOptionPane .showMessageDialog (StandaloneNaaccrDataGenerator .this , exception .getMessage (), "Error" , JOptionPane .ERROR_MESSAGE );
410
- return ;
411
- }
412
-
413
- // and finally, create and show a progress dialog
414
- final ProgressDialog progressDlg = new ProgressDialog (StandaloneNaaccrDataGenerator .this , targetFile , numRecords , layoutId , options );
415
- SwingUtilities .invokeLater (new Runnable () {
416
- @ Override
417
- public void run () {
418
- // show the dialog in the center of the parent window
419
- Component parent = StandaloneNaaccrDataGenerator .this ;
420
- Point center = new Point ();
421
- center .setLocation (parent .getLocationOnScreen ().x + parent .getWidth () / 2 , parent .getLocationOnScreen ().y + parent .getHeight () / 2 );
422
- progressDlg .pack ();
423
- progressDlg .setLocation (center .x - progressDlg .getWidth () / 2 , center .y - progressDlg .getHeight () / 2 );
424
- progressDlg .setVisible (true );
425
- }
426
- });
427
348
}
349
+
350
+ // get the number of records
351
+ String numRecsRaw = _numRecFld .getText ().trim ();
352
+ if (!numRecsRaw .matches ("\\ d+" ) || numRecsRaw .length () > 8 ) {
353
+ String message = "Wrong format for number of records, needs to be 1 to 8 digits." ;
354
+ JOptionPane .showMessageDialog (StandaloneNaaccrDataGenerator .this , message , "Error" , JOptionPane .ERROR_MESSAGE );
355
+ return ;
356
+ }
357
+ int numRecords = Integer .parseInt (numRecsRaw );
358
+
359
+ // get the DX year range
360
+ String dxYearRaw = _dxYearFld .getText ();
361
+ if (!dxYearRaw .matches ("\\ d{4}-\\ d{4}" ) && !dxYearRaw .matches ("\\ d{4}" )) {
362
+ String message = "Wrong format for DX year, needs to be nnnn or nnnn-nnnn." ;
363
+ JOptionPane .showMessageDialog (StandaloneNaaccrDataGenerator .this , message , "Error" , JOptionPane .ERROR_MESSAGE );
364
+ return ;
365
+ }
366
+ int dxStart , dxEnd ;
367
+ if (dxYearRaw .contains ("-" )) {
368
+ dxStart = Integer .parseInt (dxYearRaw .split ("-" )[0 ]);
369
+ dxEnd = Integer .parseInt (dxYearRaw .split ("-" )[1 ]);
370
+ }
371
+ else
372
+ dxStart = dxEnd = Integer .parseInt (dxYearRaw );
373
+
374
+ // get the layout ID
375
+ String layoutId = getFormatIdFromLabel ((String )_formatBox .getSelectedItem ());
376
+
377
+ // create the options
378
+ NaaccrDataGeneratorOptions options = new NaaccrDataGeneratorOptions ();
379
+ try {
380
+ if (_numTumPerPatFixed .isSelected ())
381
+ options .setNumTumorsPerPatient (Integer .valueOf (((String )_numTumPerPatBox .getSelectedItem ()).trim ()));
382
+ options .setMinDxYear (dxStart );
383
+ options .setMaxDxYear (dxEnd );
384
+ String state1 = (String )_stateBox .getSelectedItem ();
385
+ if (state1 .matches ("[A-Z][A-Z]" ))
386
+ options .setState (state1 );
387
+ if (_vsBox .getSelectedItem ().toString ().toLowerCase ().contains ("coc" ))
388
+ options .setVitalStatusDeadValue ("0" );
389
+ }
390
+ catch (IllegalArgumentException exception ) {
391
+ JOptionPane .showMessageDialog (StandaloneNaaccrDataGenerator .this , exception .getMessage (), "Error" , JOptionPane .ERROR_MESSAGE );
392
+ return ;
393
+ }
394
+
395
+ // and finally, create and show a progress dialog
396
+ final ProgressDialog progressDlg = new ProgressDialog (StandaloneNaaccrDataGenerator .this , targetFile , numRecords , layoutId , options );
397
+ SwingUtilities .invokeLater (() -> {
398
+ // show the dialog in the center of the parent window
399
+ Component parent1 = StandaloneNaaccrDataGenerator .this ;
400
+ Point center = new Point ();
401
+ center .setLocation (parent1 .getLocationOnScreen ().x + parent1 .getWidth () / 2 , parent1 .getLocationOnScreen ().y + parent1 .getHeight () / 2 );
402
+ progressDlg .pack ();
403
+ progressDlg .setLocation (center .x - progressDlg .getWidth () / 2 , center .y - progressDlg .getHeight () / 2 );
404
+ progressDlg .setVisible (true );
405
+ });
428
406
});
429
407
pnl .add (_processBtn );
430
408
return pnl ;
@@ -496,12 +474,7 @@ else if ("menu-about".equals(cmd)) {
496
474
Dimension screenSize = Toolkit .getDefaultToolkit ().getScreenSize ();
497
475
Point center = new Point (screenSize .width / 2 , screenSize .height / 2 );
498
476
dlg .setLocation (center .x - dlg .getWidth () / 2 , center .y - dlg .getHeight () / 2 );
499
- SwingUtilities .invokeLater (new Runnable () {
500
- @ Override
501
- public void run () {
502
- dlg .setVisible (true );
503
- }
504
- });
477
+ SwingUtilities .invokeLater (() -> dlg .setVisible (true ));
505
478
}
506
479
}
507
480
@@ -528,11 +501,6 @@ public static void main(String[] args) {
528
501
Point center = new Point (screenSize .width / 2 , screenSize .height / 2 );
529
502
frame .setLocation (center .x - frame .getWidth () / 2 , center .y - frame .getHeight () / 2 );
530
503
531
- SwingUtilities .invokeLater (new Runnable () {
532
- @ Override
533
- public void run () {
534
- frame .setVisible (true );
535
- }
536
- });
504
+ SwingUtilities .invokeLater (() -> frame .setVisible (true ));
537
505
}
538
506
}
0 commit comments