Change build scripts
[jvcard.git] / src / com / googlecode / lanterna / gui2 / dialogs / WaitingDialog.java
1 /*
2 * This file is part of lanterna (http://code.google.com/p/lanterna/).
3 *
4 * lanterna is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright (C) 2010-2015 Martin
18 */
19 package com.googlecode.lanterna.gui2.dialogs;
20
21 import com.googlecode.lanterna.gui2.*;
22
23 /**
24 * Dialog that displays a text message, an optional spinning indicator and an optional progress bar. There is no buttons
25 * in this dialog so it has to be explicitly closed through code.
26 * @author martin
27 */
28 public class WaitingDialog extends DialogWindow {
29 private WaitingDialog(String title, String text) {
30 super(title);
31
32 Panel mainPanel = Panels.horizontal(
33 new Label(text),
34 AnimatedLabel.createClassicSpinningLine());
35 setComponent(mainPanel);
36 }
37
38 @Override
39 public Object showDialog(WindowBasedTextGUI textGUI) {
40 showDialog(textGUI, true);
41 return null;
42 }
43
44 /**
45 * Displays the waiting dialog and optionally blocks until another thread closes it
46 * @param textGUI GUI to add the dialog to
47 * @param blockUntilClosed If {@code true}, the method call will block until another thread calls {@code close()} on
48 * the dialog, otherwise the method call returns immediately
49 */
50 public void showDialog(WindowBasedTextGUI textGUI, boolean blockUntilClosed) {
51 textGUI.addWindow(this);
52
53 if(blockUntilClosed) {
54 //Wait for the window to close, in case the window manager doesn't honor the MODAL hint
55 waitUntilClosed();
56 }
57 }
58
59 /**
60 * Creates a new waiting dialog
61 * @param title Title of the waiting dialog
62 * @param text Text to display on the waiting dialog
63 * @return Created waiting dialog
64 */
65 public static WaitingDialog createDialog(String title, String text) {
66 return new WaitingDialog(title, text);
67 }
68
69 /**
70 * Creates and displays a waiting dialog without blocking for it to finish
71 * @param textGUI GUI to add the dialog to
72 * @param title Title of the waiting dialog
73 * @param text Text to display on the waiting dialog
74 * @return Created waiting dialog
75 */
76 public static WaitingDialog showDialog(WindowBasedTextGUI textGUI, String title, String text) {
77 WaitingDialog waitingDialog = createDialog(title, text);
78 waitingDialog.showDialog(textGUI, false);
79 return waitingDialog;
80 }
81 }