@@ -65,24 +65,16 @@ public class JabRefDialogService implements DialogService {
65
65
// Snackbar dialog maximum size
66
66
public static final int DIALOG_SIZE_LIMIT = 300 ;
67
67
68
- private static final Duration TOAST_MESSAGE_DISPLAY_TIME = Duration .millis (
69
- 3000
70
- );
71
- private static final Logger LOGGER = LoggerFactory .getLogger (
72
- JabRefDialogService .class
73
- );
68
+ private static final Duration TOAST_MESSAGE_DISPLAY_TIME = Duration .millis (3000 );
69
+ private static final Logger LOGGER = LoggerFactory .getLogger (JabRefDialogService .class );
74
70
75
71
private final Window mainWindow ;
76
72
77
73
public JabRefDialogService (Window mainWindow ) {
78
74
this .mainWindow = mainWindow ;
79
75
}
80
76
81
- private FXDialog createDialog (
82
- AlertType type ,
83
- String title ,
84
- String content
85
- ) {
77
+ private FXDialog createDialog (AlertType type , String title , String content ) {
86
78
FXDialog alert = new FXDialog (type , title , true );
87
79
alert .setHeaderText (null );
88
80
alert .setContentText (content );
@@ -111,9 +103,7 @@ private FXDialog createDialogWithOptOut(
111
103
protected Node createDetailsButton () {
112
104
CheckBox optOut = new CheckBox ();
113
105
optOut .setText (optOutMessage );
114
- optOut .setOnAction (e ->
115
- optOutAction .accept (optOut .isSelected ())
116
- );
106
+ optOut .setOnAction (e -> optOutAction .accept (optOut .isSelected ()));
117
107
return optOut ;
118
108
}
119
109
}
@@ -139,10 +129,7 @@ public static String shortenDialogMessage(String dialogMessage) {
139
129
return (
140
130
dialogMessage .substring (
141
131
0 ,
142
- Math .min (
143
- dialogMessage .length (),
144
- JabRefDialogService .DIALOG_SIZE_LIMIT
145
- )
132
+ Math .min (dialogMessage .length (), JabRefDialogService .DIALOG_SIZE_LIMIT )
146
133
) +
147
134
"..."
148
135
).trim ();
@@ -156,20 +143,11 @@ public <T> Optional<T> showChoiceDialogAndWait(
156
143
T defaultChoice ,
157
144
Collection <T > choices
158
145
) {
159
- ChoiceDialog <T > choiceDialog = new ChoiceDialog <>(
160
- defaultChoice ,
161
- choices
162
- );
146
+ ChoiceDialog <T > choiceDialog = new ChoiceDialog <>(defaultChoice , choices );
163
147
((Stage ) choiceDialog .getDialogPane ().getScene ().getWindow ()).getIcons ()
164
148
.add (IconTheme .getJabRefImage ());
165
- ButtonType okButtonType = new ButtonType (
166
- okButtonLabel ,
167
- ButtonBar .ButtonData .OK_DONE
168
- );
169
- choiceDialog
170
- .getDialogPane ()
171
- .getButtonTypes ()
172
- .setAll (ButtonType .CANCEL , okButtonType );
149
+ ButtonType okButtonType = new ButtonType (okButtonLabel , ButtonBar .ButtonData .OK_DONE );
150
+ choiceDialog .getDialogPane ().getButtonTypes ().setAll (ButtonType .CANCEL , okButtonType );
173
151
choiceDialog .setHeaderText (title );
174
152
choiceDialog .setTitle (title );
175
153
choiceDialog .setContentText (content );
@@ -178,10 +156,7 @@ public <T> Optional<T> showChoiceDialogAndWait(
178
156
}
179
157
180
158
@ Override
181
- public Optional <String > showInputDialogAndWait (
182
- String title ,
183
- String content
184
- ) {
159
+ public Optional <String > showInputDialogAndWait (String title , String content ) {
185
160
TextInputDialog inputDialog = new TextInputDialog ();
186
161
inputDialog .setHeaderText (title );
187
162
inputDialog .setContentText (content );
@@ -230,11 +205,7 @@ public void showErrorDialogAndWait(String message, Throwable exception) {
230
205
}
231
206
232
207
@ Override
233
- public void showErrorDialogAndWait (
234
- String title ,
235
- String content ,
236
- Throwable exception
237
- ) {
208
+ public void showErrorDialogAndWait (String title , String content , Throwable exception ) {
238
209
ExceptionDialog exceptionDialog = new ExceptionDialog (exception );
239
210
exceptionDialog .setHeaderText (title );
240
211
exceptionDialog .setContentText (content );
@@ -255,10 +226,7 @@ public void showErrorDialogAndWait(String message) {
255
226
@ Override
256
227
public boolean showConfirmationDialogAndWait (String title , String content ) {
257
228
FXDialog alert = createDialog (AlertType .CONFIRMATION , title , content );
258
- return alert
259
- .showAndWait ()
260
- .filter (buttonType -> buttonType == ButtonType .OK )
261
- .isPresent ();
229
+ return alert .showAndWait ().filter (buttonType -> buttonType == ButtonType .OK ).isPresent ();
262
230
}
263
231
264
232
@ Override
@@ -268,15 +236,9 @@ public boolean showConfirmationDialogAndWait(
268
236
String okButtonLabel
269
237
) {
270
238
FXDialog alert = createDialog (AlertType .CONFIRMATION , title , content );
271
- ButtonType okButtonType = new ButtonType (
272
- okButtonLabel ,
273
- ButtonBar .ButtonData .OK_DONE
274
- );
239
+ ButtonType okButtonType = new ButtonType (okButtonLabel , ButtonBar .ButtonData .OK_DONE );
275
240
alert .getButtonTypes ().setAll (ButtonType .CANCEL , okButtonType );
276
- return alert
277
- .showAndWait ()
278
- .filter (buttonType -> buttonType == okButtonType )
279
- .isPresent ();
241
+ return alert .showAndWait ().filter (buttonType -> buttonType == okButtonType ).isPresent ();
280
242
}
281
243
282
244
@ Override
@@ -287,19 +249,10 @@ public boolean showConfirmationDialogAndWait(
287
249
String cancelButtonLabel
288
250
) {
289
251
FXDialog alert = createDialog (AlertType .CONFIRMATION , title , content );
290
- ButtonType okButtonType = new ButtonType (
291
- okButtonLabel ,
292
- ButtonBar .ButtonData .OK_DONE
293
- );
294
- ButtonType cancelButtonType = new ButtonType (
295
- cancelButtonLabel ,
296
- ButtonBar .ButtonData .NO
297
- );
252
+ ButtonType okButtonType = new ButtonType (okButtonLabel , ButtonBar .ButtonData .OK_DONE );
253
+ ButtonType cancelButtonType = new ButtonType (cancelButtonLabel , ButtonBar .ButtonData .NO );
298
254
alert .getButtonTypes ().setAll (okButtonType , cancelButtonType );
299
- return alert
300
- .showAndWait ()
301
- .filter (buttonType -> buttonType == okButtonType )
302
- .isPresent ();
255
+ return alert .showAndWait ().filter (buttonType -> buttonType == okButtonType ).isPresent ();
303
256
}
304
257
305
258
@ Override
@@ -317,10 +270,7 @@ public boolean showConfirmationDialogWithOptOutAndWait(
317
270
optOutAction
318
271
);
319
272
alert .getButtonTypes ().setAll (ButtonType .YES , ButtonType .NO );
320
- return alert
321
- .showAndWait ()
322
- .filter (buttonType -> buttonType == ButtonType .YES )
323
- .isPresent ();
273
+ return alert .showAndWait ().filter (buttonType -> buttonType == ButtonType .YES ).isPresent ();
324
274
}
325
275
326
276
@ Override
@@ -339,19 +289,10 @@ public boolean showConfirmationDialogWithOptOutAndWait(
339
289
optOutMessage ,
340
290
optOutAction
341
291
);
342
- ButtonType okButtonType = new ButtonType (
343
- okButtonLabel ,
344
- ButtonBar .ButtonData .YES
345
- );
346
- ButtonType cancelButtonType = new ButtonType (
347
- cancelButtonLabel ,
348
- ButtonBar .ButtonData .NO
349
- );
292
+ ButtonType okButtonType = new ButtonType (okButtonLabel , ButtonBar .ButtonData .YES );
293
+ ButtonType cancelButtonType = new ButtonType (cancelButtonLabel , ButtonBar .ButtonData .NO );
350
294
alert .getButtonTypes ().setAll (okButtonType , cancelButtonType );
351
- return alert
352
- .showAndWait ()
353
- .filter (buttonType -> buttonType == okButtonType )
354
- .isPresent ();
295
+ return alert .showAndWait ().filter (buttonType -> buttonType == okButtonType ).isPresent ();
355
296
}
356
297
357
298
@ Override
@@ -382,23 +323,16 @@ public Optional<ButtonType> showCustomDialogAndWait(
382
323
}
383
324
384
325
@ Override
385
- public <R > Optional <R > showCustomDialogAndWait (
386
- javafx .scene .control .Dialog <R > dialog
387
- ) {
326
+ public <R > Optional <R > showCustomDialogAndWait (javafx .scene .control .Dialog <R > dialog ) {
388
327
if (dialog .getOwner () == null ) {
389
328
dialog .initOwner (mainWindow );
390
329
}
391
330
return dialog .showAndWait ();
392
331
}
393
332
394
333
@ Override
395
- public Optional <String > showPasswordDialogAndWait (
396
- String title ,
397
- String header ,
398
- String content
399
- ) {
400
- javafx .scene .control .Dialog <String > dialog =
401
- new javafx .scene .control .Dialog <>();
334
+ public Optional <String > showPasswordDialogAndWait (String title , String header , String content ) {
335
+ javafx .scene .control .Dialog <String > dialog = new javafx .scene .control .Dialog <>();
402
336
dialog .setTitle (title );
403
337
dialog .setHeaderText (header );
404
338
@@ -410,10 +344,7 @@ public Optional<String> showPasswordDialogAndWait(
410
344
dialog .setTitle (title );
411
345
dialog .getDialogPane ().setContent (box );
412
346
413
- dialog
414
- .getDialogPane ()
415
- .getButtonTypes ()
416
- .addAll (ButtonType .CANCEL , ButtonType .OK );
347
+ dialog .getDialogPane ().getButtonTypes ().addAll (ButtonType .CANCEL , ButtonType .OK );
417
348
dialog .setResultConverter (dialogButton -> {
418
349
if (dialogButton == ButtonType .OK ) {
419
350
return passwordField .getText ();
@@ -424,27 +355,18 @@ public Optional<String> showPasswordDialogAndWait(
424
355
}
425
356
426
357
@ Override
427
- public <V > void showProgressDialog (
428
- String title ,
429
- String content ,
430
- Task <V > task
431
- ) {
358
+ public <V > void showProgressDialog (String title , String content , Task <V > task ) {
432
359
ProgressDialog progressDialog = new ProgressDialog (task );
433
360
progressDialog .setHeaderText (null );
434
361
progressDialog .setTitle (title );
435
362
progressDialog .setContentText (content );
436
363
progressDialog .setGraphic (null );
437
- ((Stage ) progressDialog
438
- .getDialogPane ()
439
- .getScene ()
440
- .getWindow ()).getIcons ()
364
+ ((Stage ) progressDialog .getDialogPane ().getScene ().getWindow ()).getIcons ()
441
365
.add (IconTheme .getJabRefImage ());
442
366
progressDialog .setOnCloseRequest (evt -> task .cancel ());
443
367
DialogPane dialogPane = progressDialog .getDialogPane ();
444
368
dialogPane .getButtonTypes ().add (ButtonType .CANCEL );
445
- Button cancelButton = (Button ) dialogPane .lookupButton (
446
- ButtonType .CANCEL
447
- );
369
+ Button cancelButton = (Button ) dialogPane .lookupButton (ButtonType .CANCEL );
448
370
cancelButton .setOnAction (evt -> {
449
371
task .cancel ();
450
372
progressDialog .close ();
@@ -460,10 +382,7 @@ public <V> Optional<ButtonType> showBackgroundProgressDialogAndWait(
460
382
StateManager stateManager
461
383
) {
462
384
TaskProgressView <Task <?>> taskProgressView = new TaskProgressView <>();
463
- EasyBind .bindContent (
464
- taskProgressView .getTasks (),
465
- stateManager .getBackgroundTasks ()
466
- );
385
+ EasyBind .bindContent (taskProgressView .getTasks (), stateManager .getBackgroundTasks ());
467
386
taskProgressView .setRetainTasks (false );
468
387
taskProgressView .setGraphicFactory (BackgroundTask ::getIcon );
469
388
@@ -512,9 +431,7 @@ public void notify(String message) {
512
431
// TODO: Change to a notification overview instead of event log when that is available. The event log is not that user friendly (different purpose).
513
432
.text (
514
433
"(" +
515
- Localization .lang (
516
- "Check the event log to see all notifications"
517
- ) +
434
+ Localization .lang ("Check the event log to see all notifications" ) +
518
435
")" +
519
436
"\n \n " +
520
437
message
@@ -530,9 +447,7 @@ public void notify(String message) {
530
447
}
531
448
532
449
@ Override
533
- public Optional <Path > showFileSaveDialog (
534
- FileDialogConfiguration fileDialogConfiguration
535
- ) {
450
+ public Optional <Path > showFileSaveDialog (FileDialogConfiguration fileDialogConfiguration ) {
536
451
FileChooser chooser = getConfiguredFileChooser (fileDialogConfiguration );
537
452
File file = chooser .showSaveDialog (mainWindow );
538
453
Optional
@@ -542,9 +457,7 @@ public Optional<Path> showFileSaveDialog(
542
457
}
543
458
544
459
@ Override
545
- public Optional <Path > showFileOpenDialog (
546
- FileDialogConfiguration fileDialogConfiguration
547
- ) {
460
+ public Optional <Path > showFileOpenDialog (FileDialogConfiguration fileDialogConfiguration ) {
548
461
FileChooser chooser = getConfiguredFileChooser (fileDialogConfiguration );
549
462
File file = chooser .showOpenDialog (mainWindow );
550
463
Optional
@@ -557,9 +470,7 @@ public Optional<Path> showFileOpenDialog(
557
470
public Optional <Path > showDirectorySelectionDialog (
558
471
DirectoryDialogConfiguration directoryDialogConfiguration
559
472
) {
560
- DirectoryChooser chooser = getConfiguredDirectoryChooser (
561
- directoryDialogConfiguration
562
- );
473
+ DirectoryChooser chooser = getConfiguredDirectoryChooser (directoryDialogConfiguration );
563
474
File file = chooser .showDialog (mainWindow );
564
475
return Optional .ofNullable (file ).map (File ::toPath );
565
476
}
@@ -586,19 +497,11 @@ private DirectoryChooser getConfiguredDirectoryChooser(
586
497
return chooser ;
587
498
}
588
499
589
- private FileChooser getConfiguredFileChooser (
590
- FileDialogConfiguration fileDialogConfiguration
591
- ) {
500
+ private FileChooser getConfiguredFileChooser (FileDialogConfiguration fileDialogConfiguration ) {
592
501
FileChooser chooser = new FileChooser ();
593
- chooser
594
- .getExtensionFilters ()
595
- .addAll (fileDialogConfiguration .getExtensionFilters ());
596
- chooser .setSelectedExtensionFilter (
597
- fileDialogConfiguration .getDefaultExtension ()
598
- );
599
- chooser .setInitialFileName (
600
- fileDialogConfiguration .getInitialFileName ()
601
- );
502
+ chooser .getExtensionFilters ().addAll (fileDialogConfiguration .getExtensionFilters ());
503
+ chooser .setSelectedExtensionFilter (fileDialogConfiguration .getDefaultExtension ());
504
+ chooser .setInitialFileName (fileDialogConfiguration .getInitialFileName ());
602
505
fileDialogConfiguration
603
506
.getInitialDirectory ()
604
507
.map (Path ::toFile )
@@ -612,20 +515,11 @@ public boolean showPrintDialog(PrinterJob job) {
612
515
}
613
516
614
517
@ Override
615
- public Optional <Path > showFileOpenFromArchiveDialog (Path archivePath )
616
- throws IOException {
617
- try (
618
- FileSystem zipFile = FileSystems .newFileSystem (
619
- archivePath ,
620
- (ClassLoader ) null
621
- )
622
- ) {
518
+ public Optional <Path > showFileOpenFromArchiveDialog (Path archivePath ) throws IOException {
519
+ try (FileSystem zipFile = FileSystems .newFileSystem (archivePath , (ClassLoader ) null )) {
623
520
return new ZipFileChooser (zipFile ).showAndWait ();
624
521
} catch (NoClassDefFoundError exc ) {
625
- throw new IOException (
626
- "Could not instantiate ZIP-archive reader." ,
627
- exc
628
- );
522
+ throw new IOException ("Could not instantiate ZIP-archive reader." , exc );
629
523
}
630
524
}
631
525
0 commit comments