Skip to content

Commit

Permalink
temporary fix for mabe02/lanterna issue 595
Browse files Browse the repository at this point in the history
  • Loading branch information
Kapral67 committed Feb 11, 2024
1 parent ec11292 commit b047607
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ demo
dev
fox
allan
.env

# research files
*[pP]layground*
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

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;
import java.util.concurrent.atomic.AtomicReference;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -89,4 +96,15 @@ Object showDialog (final @NotNull WindowBasedTextGUI textGUI) {
this.waitUntilClosed();
return null;
}

/**
* TODO: Delete this once <a href="https://github.com/mabe02/lanterna/issues/595">lantera issue #595</a> is resolved
*/
@Override
public
void close () {
super.close();
this.countDownLabel.stopAnimation();
this.spinningLine.stopAnimation();
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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}
* <p>
* 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
* <p>
* <p>
* TODO: Delete this class
* Temporary Fix for <a href="https://github.com/mabe02/lanterna/issues/595">lantera issue #595</a>
* @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 <a href="https://github.com/mabe02/lanterna/issues/595">lantera issue #595</a> is resolved
*/
@Override
public
void close () {
super.close();
this.spinningLine.stopAnimation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

1 comment on commit b047607

@Kapral67
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.