Skip to content

Commit

Permalink
Reformat to 100 line length
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Nov 18, 2023
1 parent 6f151ec commit 5b3c785
Show file tree
Hide file tree
Showing 1,345 changed files with 13,606 additions and 42,347 deletions.
184 changes: 39 additions & 145 deletions src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,16 @@ public class JabRefDialogService implements DialogService {
// Snackbar dialog maximum size
public static final int DIALOG_SIZE_LIMIT = 300;

private static final Duration TOAST_MESSAGE_DISPLAY_TIME = Duration.millis(
3000
);
private static final Logger LOGGER = LoggerFactory.getLogger(
JabRefDialogService.class
);
private static final Duration TOAST_MESSAGE_DISPLAY_TIME = Duration.millis(3000);
private static final Logger LOGGER = LoggerFactory.getLogger(JabRefDialogService.class);

private final Window mainWindow;

public JabRefDialogService(Window mainWindow) {
this.mainWindow = mainWindow;
}

private FXDialog createDialog(
AlertType type,
String title,
String content
) {
private FXDialog createDialog(AlertType type, String title, String content) {
FXDialog alert = new FXDialog(type, title, true);
alert.setHeaderText(null);
alert.setContentText(content);
Expand Down Expand Up @@ -111,9 +103,7 @@ private FXDialog createDialogWithOptOut(
protected Node createDetailsButton() {
CheckBox optOut = new CheckBox();
optOut.setText(optOutMessage);
optOut.setOnAction(e ->
optOutAction.accept(optOut.isSelected())
);
optOut.setOnAction(e -> optOutAction.accept(optOut.isSelected()));
return optOut;
}
}
Expand All @@ -139,10 +129,7 @@ public static String shortenDialogMessage(String dialogMessage) {
return (
dialogMessage.substring(
0,
Math.min(
dialogMessage.length(),
JabRefDialogService.DIALOG_SIZE_LIMIT
)
Math.min(dialogMessage.length(), JabRefDialogService.DIALOG_SIZE_LIMIT)
) +
"..."
).trim();
Expand All @@ -156,20 +143,11 @@ public <T> Optional<T> showChoiceDialogAndWait(
T defaultChoice,
Collection<T> choices
) {
ChoiceDialog<T> choiceDialog = new ChoiceDialog<>(
defaultChoice,
choices
);
ChoiceDialog<T> choiceDialog = new ChoiceDialog<>(defaultChoice, choices);
((Stage) choiceDialog.getDialogPane().getScene().getWindow()).getIcons()
.add(IconTheme.getJabRefImage());
ButtonType okButtonType = new ButtonType(
okButtonLabel,
ButtonBar.ButtonData.OK_DONE
);
choiceDialog
.getDialogPane()
.getButtonTypes()
.setAll(ButtonType.CANCEL, okButtonType);
ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE);
choiceDialog.getDialogPane().getButtonTypes().setAll(ButtonType.CANCEL, okButtonType);
choiceDialog.setHeaderText(title);
choiceDialog.setTitle(title);
choiceDialog.setContentText(content);
Expand All @@ -178,10 +156,7 @@ public <T> Optional<T> showChoiceDialogAndWait(
}

@Override
public Optional<String> showInputDialogAndWait(
String title,
String content
) {
public Optional<String> showInputDialogAndWait(String title, String content) {
TextInputDialog inputDialog = new TextInputDialog();
inputDialog.setHeaderText(title);
inputDialog.setContentText(content);
Expand Down Expand Up @@ -230,11 +205,7 @@ public void showErrorDialogAndWait(String message, Throwable exception) {
}

@Override
public void showErrorDialogAndWait(
String title,
String content,
Throwable exception
) {
public void showErrorDialogAndWait(String title, String content, Throwable exception) {
ExceptionDialog exceptionDialog = new ExceptionDialog(exception);
exceptionDialog.setHeaderText(title);
exceptionDialog.setContentText(content);
Expand All @@ -255,10 +226,7 @@ public void showErrorDialogAndWait(String message) {
@Override
public boolean showConfirmationDialogAndWait(String title, String content) {
FXDialog alert = createDialog(AlertType.CONFIRMATION, title, content);
return alert
.showAndWait()
.filter(buttonType -> buttonType == ButtonType.OK)
.isPresent();
return alert.showAndWait().filter(buttonType -> buttonType == ButtonType.OK).isPresent();
}

@Override
Expand All @@ -268,15 +236,9 @@ public boolean showConfirmationDialogAndWait(
String okButtonLabel
) {
FXDialog alert = createDialog(AlertType.CONFIRMATION, title, content);
ButtonType okButtonType = new ButtonType(
okButtonLabel,
ButtonBar.ButtonData.OK_DONE
);
ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE);
alert.getButtonTypes().setAll(ButtonType.CANCEL, okButtonType);
return alert
.showAndWait()
.filter(buttonType -> buttonType == okButtonType)
.isPresent();
return alert.showAndWait().filter(buttonType -> buttonType == okButtonType).isPresent();
}

@Override
Expand All @@ -287,19 +249,10 @@ public boolean showConfirmationDialogAndWait(
String cancelButtonLabel
) {
FXDialog alert = createDialog(AlertType.CONFIRMATION, title, content);
ButtonType okButtonType = new ButtonType(
okButtonLabel,
ButtonBar.ButtonData.OK_DONE
);
ButtonType cancelButtonType = new ButtonType(
cancelButtonLabel,
ButtonBar.ButtonData.NO
);
ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE);
ButtonType cancelButtonType = new ButtonType(cancelButtonLabel, ButtonBar.ButtonData.NO);
alert.getButtonTypes().setAll(okButtonType, cancelButtonType);
return alert
.showAndWait()
.filter(buttonType -> buttonType == okButtonType)
.isPresent();
return alert.showAndWait().filter(buttonType -> buttonType == okButtonType).isPresent();
}

@Override
Expand All @@ -317,10 +270,7 @@ public boolean showConfirmationDialogWithOptOutAndWait(
optOutAction
);
alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO);
return alert
.showAndWait()
.filter(buttonType -> buttonType == ButtonType.YES)
.isPresent();
return alert.showAndWait().filter(buttonType -> buttonType == ButtonType.YES).isPresent();
}

@Override
Expand All @@ -339,19 +289,10 @@ public boolean showConfirmationDialogWithOptOutAndWait(
optOutMessage,
optOutAction
);
ButtonType okButtonType = new ButtonType(
okButtonLabel,
ButtonBar.ButtonData.YES
);
ButtonType cancelButtonType = new ButtonType(
cancelButtonLabel,
ButtonBar.ButtonData.NO
);
ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.YES);
ButtonType cancelButtonType = new ButtonType(cancelButtonLabel, ButtonBar.ButtonData.NO);
alert.getButtonTypes().setAll(okButtonType, cancelButtonType);
return alert
.showAndWait()
.filter(buttonType -> buttonType == okButtonType)
.isPresent();
return alert.showAndWait().filter(buttonType -> buttonType == okButtonType).isPresent();
}

@Override
Expand Down Expand Up @@ -382,23 +323,16 @@ public Optional<ButtonType> showCustomDialogAndWait(
}

@Override
public <R> Optional<R> showCustomDialogAndWait(
javafx.scene.control.Dialog<R> dialog
) {
public <R> Optional<R> showCustomDialogAndWait(javafx.scene.control.Dialog<R> dialog) {
if (dialog.getOwner() == null) {
dialog.initOwner(mainWindow);
}
return dialog.showAndWait();
}

@Override
public Optional<String> showPasswordDialogAndWait(
String title,
String header,
String content
) {
javafx.scene.control.Dialog<String> dialog =
new javafx.scene.control.Dialog<>();
public Optional<String> showPasswordDialogAndWait(String title, String header, String content) {
javafx.scene.control.Dialog<String> dialog = new javafx.scene.control.Dialog<>();
dialog.setTitle(title);
dialog.setHeaderText(header);

Expand All @@ -410,10 +344,7 @@ public Optional<String> showPasswordDialogAndWait(
dialog.setTitle(title);
dialog.getDialogPane().setContent(box);

dialog
.getDialogPane()
.getButtonTypes()
.addAll(ButtonType.CANCEL, ButtonType.OK);
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK);
dialog.setResultConverter(dialogButton -> {
if (dialogButton == ButtonType.OK) {
return passwordField.getText();
Expand All @@ -424,27 +355,18 @@ public Optional<String> showPasswordDialogAndWait(
}

@Override
public <V> void showProgressDialog(
String title,
String content,
Task<V> task
) {
public <V> void showProgressDialog(String title, String content, Task<V> task) {
ProgressDialog progressDialog = new ProgressDialog(task);
progressDialog.setHeaderText(null);
progressDialog.setTitle(title);
progressDialog.setContentText(content);
progressDialog.setGraphic(null);
((Stage) progressDialog
.getDialogPane()
.getScene()
.getWindow()).getIcons()
((Stage) progressDialog.getDialogPane().getScene().getWindow()).getIcons()
.add(IconTheme.getJabRefImage());
progressDialog.setOnCloseRequest(evt -> task.cancel());
DialogPane dialogPane = progressDialog.getDialogPane();
dialogPane.getButtonTypes().add(ButtonType.CANCEL);
Button cancelButton = (Button) dialogPane.lookupButton(
ButtonType.CANCEL
);
Button cancelButton = (Button) dialogPane.lookupButton(ButtonType.CANCEL);
cancelButton.setOnAction(evt -> {
task.cancel();
progressDialog.close();
Expand All @@ -460,10 +382,7 @@ public <V> Optional<ButtonType> showBackgroundProgressDialogAndWait(
StateManager stateManager
) {
TaskProgressView<Task<?>> taskProgressView = new TaskProgressView<>();
EasyBind.bindContent(
taskProgressView.getTasks(),
stateManager.getBackgroundTasks()
);
EasyBind.bindContent(taskProgressView.getTasks(), stateManager.getBackgroundTasks());
taskProgressView.setRetainTasks(false);
taskProgressView.setGraphicFactory(BackgroundTask::getIcon);

Expand Down Expand Up @@ -512,9 +431,7 @@ public void notify(String message) {
// TODO: Change to a notification overview instead of event log when that is available. The event log is not that user friendly (different purpose).
.text(
"(" +
Localization.lang(
"Check the event log to see all notifications"
) +
Localization.lang("Check the event log to see all notifications") +
")" +
"\n\n" +
message
Expand All @@ -530,9 +447,7 @@ public void notify(String message) {
}

@Override
public Optional<Path> showFileSaveDialog(
FileDialogConfiguration fileDialogConfiguration
) {
public Optional<Path> showFileSaveDialog(FileDialogConfiguration fileDialogConfiguration) {
FileChooser chooser = getConfiguredFileChooser(fileDialogConfiguration);
File file = chooser.showSaveDialog(mainWindow);
Optional
Expand All @@ -542,9 +457,7 @@ public Optional<Path> showFileSaveDialog(
}

@Override
public Optional<Path> showFileOpenDialog(
FileDialogConfiguration fileDialogConfiguration
) {
public Optional<Path> showFileOpenDialog(FileDialogConfiguration fileDialogConfiguration) {
FileChooser chooser = getConfiguredFileChooser(fileDialogConfiguration);
File file = chooser.showOpenDialog(mainWindow);
Optional
Expand All @@ -557,9 +470,7 @@ public Optional<Path> showFileOpenDialog(
public Optional<Path> showDirectorySelectionDialog(
DirectoryDialogConfiguration directoryDialogConfiguration
) {
DirectoryChooser chooser = getConfiguredDirectoryChooser(
directoryDialogConfiguration
);
DirectoryChooser chooser = getConfiguredDirectoryChooser(directoryDialogConfiguration);
File file = chooser.showDialog(mainWindow);
return Optional.ofNullable(file).map(File::toPath);
}
Expand All @@ -586,19 +497,11 @@ private DirectoryChooser getConfiguredDirectoryChooser(
return chooser;
}

private FileChooser getConfiguredFileChooser(
FileDialogConfiguration fileDialogConfiguration
) {
private FileChooser getConfiguredFileChooser(FileDialogConfiguration fileDialogConfiguration) {
FileChooser chooser = new FileChooser();
chooser
.getExtensionFilters()
.addAll(fileDialogConfiguration.getExtensionFilters());
chooser.setSelectedExtensionFilter(
fileDialogConfiguration.getDefaultExtension()
);
chooser.setInitialFileName(
fileDialogConfiguration.getInitialFileName()
);
chooser.getExtensionFilters().addAll(fileDialogConfiguration.getExtensionFilters());
chooser.setSelectedExtensionFilter(fileDialogConfiguration.getDefaultExtension());
chooser.setInitialFileName(fileDialogConfiguration.getInitialFileName());
fileDialogConfiguration
.getInitialDirectory()
.map(Path::toFile)
Expand All @@ -612,20 +515,11 @@ public boolean showPrintDialog(PrinterJob job) {
}

@Override
public Optional<Path> showFileOpenFromArchiveDialog(Path archivePath)
throws IOException {
try (
FileSystem zipFile = FileSystems.newFileSystem(
archivePath,
(ClassLoader) null
)
) {
public Optional<Path> showFileOpenFromArchiveDialog(Path archivePath) throws IOException {
try (FileSystem zipFile = FileSystems.newFileSystem(archivePath, (ClassLoader) null)) {
return new ZipFileChooser(zipFile).showAndWait();
} catch (NoClassDefFoundError exc) {
throw new IOException(
"Could not instantiate ZIP-archive reader.",
exc
);
throw new IOException("Could not instantiate ZIP-archive reader.", exc);
}
}

Expand Down
Loading

0 comments on commit 5b3c785

Please sign in to comment.