1 package com
.googlecode
.lanterna
.gui2
.dialogs
;
3 import com
.googlecode
.lanterna
.TerminalSize
;
4 import com
.googlecode
.lanterna
.gui2
.*;
7 * Simple message dialog that displays a message and has optional selection/confirmation buttons
11 public class MessageDialog
extends DialogWindow
{
13 private MessageDialogButton result
;
18 MessageDialogButton
... buttons
) {
22 if(buttons
== null || buttons
.length
== 0) {
23 buttons
= new MessageDialogButton
[] { MessageDialogButton
.OK
};
26 Panel buttonPanel
= new Panel();
27 buttonPanel
.setLayoutManager(new GridLayout(buttons
.length
).setHorizontalSpacing(1));
28 for(final MessageDialogButton button
: buttons
) {
29 buttonPanel
.addComponent(new Button(button
.toString(), new Runnable() {
38 Panel mainPanel
= new Panel();
39 mainPanel
.setLayoutManager(
42 .setRightMarginSize(1));
43 mainPanel
.addComponent(new Label(text
));
44 mainPanel
.addComponent(new EmptySpace(TerminalSize
.ONE
));
45 buttonPanel
.setLayoutData(
46 GridLayout
.createLayoutData(
47 GridLayout
.Alignment
.END
,
48 GridLayout
.Alignment
.CENTER
,
52 setComponent(mainPanel
);
57 * @param textGUI Text GUI to add the dialog to
58 * @return The selected button's enum value
61 public MessageDialogButton
showDialog(WindowBasedTextGUI textGUI
) {
63 super.showDialog(textGUI
);
68 * Shortcut for quickly displaying a message box
69 * @param textGUI The GUI to display the message box on
70 * @param title Title of the message box
71 * @param text Main message of the message box
72 * @param buttons Buttons that the user can confirm the message box with
73 * @return Which button the user selected
75 public static MessageDialogButton
showMessageDialog(
76 WindowBasedTextGUI textGUI
,
79 MessageDialogButton
... buttons
) {
80 MessageDialogBuilder builder
= new MessageDialogBuilder()
83 if(buttons
.length
== 0) {
84 builder
.addButton(MessageDialogButton
.OK
);
86 for(MessageDialogButton button
: buttons
) {
87 builder
.addButton(button
);
89 return builder
.build().showDialog(textGUI
);