diff --git a/.gitignore b/.gitignore index b53cd0c2..83a27f92 100644 --- a/.gitignore +++ b/.gitignore @@ -73,6 +73,7 @@ demo dev fox allan +.env # research files *[pP]layground* diff --git a/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/PickerDialogRefreshUtility.java b/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/PickerDialogRefreshUtility.java index ce41ab59..7d12063d 100644 --- a/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/PickerDialogRefreshUtility.java +++ b/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/PickerDialogRefreshUtility.java @@ -2,7 +2,6 @@ import com.googlecode.lanterna.TerminalSize; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; -import com.googlecode.lanterna.gui2.dialogs.WaitingDialog; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; @@ -10,6 +9,7 @@ import org.familydirectory.assets.ddb.models.member.MemberRecord; import org.familydirectory.sdk.adminclient.AdminClientTui; import org.familydirectory.sdk.adminclient.utility.lanterna.RefreshableListSelectDialog; +import org.familydirectory.sdk.adminclient.utility.lanterna.WaitingDialog; import org.familydirectory.sdk.adminclient.utility.pickers.model.PickerModel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/lanterna/EnhancedWaitingDialog.java b/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/lanterna/EnhancedWaitingDialog.java index fe131fcf..e29279b8 100644 --- a/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/lanterna/EnhancedWaitingDialog.java +++ b/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/lanterna/EnhancedWaitingDialog.java @@ -41,8 +41,13 @@ public final class EnhancedWaitingDialog extends DialogWindow { private static final long MILLIS_IN_SEC = 1000L; + @NotNull private static final String FORMAT_TEXT = "Please Wait for %d Seconds"; private final long seconds; + @NotNull + private final AnimatedLabel countDownLabel; + @NotNull + private final AnimatedLabel spinningLine; public EnhancedWaitingDialog (final @NotNull String title, final long seconds) { @@ -52,7 +57,9 @@ class EnhancedWaitingDialog extends DialogWindow { throw new IllegalArgumentException("seconds must be 1 or greater"); } this.seconds = seconds; - this.setComponent(Panels.horizontal(this.getCountDownLabel(), AnimatedLabel.createClassicSpinningLine())); + this.countDownLabel = this.getCountDownLabel(); + this.spinningLine = AnimatedLabel.createClassicSpinningLine(); + this.setComponent(Panels.horizontal(this.countDownLabel, this.spinningLine)); } @NotNull @@ -89,4 +96,15 @@ Object showDialog (final @NotNull WindowBasedTextGUI textGUI) { this.waitUntilClosed(); return null; } + + /** + * TODO: Delete this once lantera issue #595 is resolved + */ + @Override + public + void close () { + super.close(); + this.countDownLabel.stopAnimation(); + this.spinningLine.stopAnimation(); + } } diff --git a/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/lanterna/WaitingDialog.java b/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/lanterna/WaitingDialog.java new file mode 100644 index 00000000..95ee2986 --- /dev/null +++ b/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/lanterna/WaitingDialog.java @@ -0,0 +1,118 @@ +/* + * This file is part of lanterna (https://github.com/mabe02/lanterna). + * + * lanterna is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Copyright (C) 2010-2020 Martin Berglund + */ +package org.familydirectory.sdk.adminclient.utility.lanterna; + +import com.googlecode.lanterna.gui2.AnimatedLabel; +import com.googlecode.lanterna.gui2.Label; +import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.Panels; +import com.googlecode.lanterna.gui2.WindowBasedTextGUI; +import com.googlecode.lanterna.gui2.dialogs.DialogWindow; +import org.jetbrains.annotations.NotNull; + +/** + * {@link com.googlecode.lanterna.gui2.dialogs.WaitingDialog} + *

+ * Dialog that displays a text message, an optional spinning indicator and an optional progress bar. There is no buttons + * in this dialog so it has to be explicitly closed through code. + * + * @author martin + *

+ *

+ * TODO: Delete this class + * Temporary Fix for lantera issue #595 + * @author Maxwell Kapral + */ +public final +class WaitingDialog extends DialogWindow { + @NotNull + private final AnimatedLabel spinningLine; + + private + WaitingDialog (final String title, final String text) { + super(title); + + this.spinningLine = AnimatedLabel.createClassicSpinningLine(); + final Panel mainPanel = Panels.horizontal(new Label(text), this.spinningLine); + this.setComponent(mainPanel); + } + + /** + * Creates and displays a waiting dialog without blocking for it to finish + * + * @param textGUI GUI to add the dialog to + * @param title Title of the waiting dialog + * @param text Text to display on the waiting dialog + * + * @return Created waiting dialog + */ + public static + WaitingDialog showDialog (final WindowBasedTextGUI textGUI, final String title, final String text) { + final WaitingDialog waitingDialog = createDialog(title, text); + waitingDialog.showDialog(textGUI, false); + return waitingDialog; + } + + /** + * Creates a new waiting dialog + * + * @param title Title of the waiting dialog + * @param text Text to display on the waiting dialog + * + * @return Created waiting dialog + */ + public static + WaitingDialog createDialog (final String title, final String text) { + return new WaitingDialog(title, text); + } + + /** + * Displays the waiting dialog and optionally blocks until another thread closes it + * + * @param textGUI GUI to add the dialog to + * @param blockUntilClosed If {@code true}, the method call will block until another thread calls {@code close()} on + * the dialog, otherwise the method call returns immediately + */ + public + void showDialog (final WindowBasedTextGUI textGUI, final boolean blockUntilClosed) { + textGUI.addWindow(this); + + if (blockUntilClosed) { + //Wait for the window to close, in case the window manager doesn't honor the MODAL hint + this.waitUntilClosed(); + } + } + + @Override + public + Object showDialog (final WindowBasedTextGUI textGUI) { + this.showDialog(textGUI, true); + return null; + } + + /** + * TODO: Delete this once lantera issue #595 is resolved + */ + @Override + public + void close () { + super.close(); + this.spinningLine.stopAnimation(); + } +} \ No newline at end of file diff --git a/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/pickers/model/PickerModel.java b/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/pickers/model/PickerModel.java index 4561ef3a..80b3069a 100644 --- a/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/pickers/model/PickerModel.java +++ b/AdminClient/src/main/java/org/familydirectory/sdk/adminclient/utility/pickers/model/PickerModel.java @@ -95,7 +95,7 @@ void close () { public final boolean isClosed () { - if (!this.isAlive() && !this.isClosed.get()) { + if (!(this.isAlive() || this.isClosed.get())) { this.isClosed.set(true); } return this.isClosed.get();