1 package com
.googlecode
.lanterna
.gui2
.dialogs
;
3 import com
.googlecode
.lanterna
.TerminalSize
;
4 import com
.googlecode
.lanterna
.gui2
.*;
9 * Dialog containing a multiple item action list box
12 public class ActionListDialog
extends DialogWindow
{
17 TerminalSize actionListPreferredSize
,
19 List
<Runnable
> actions
) {
22 if(actions
.isEmpty()) {
23 throw new IllegalStateException("ActionListDialog needs at least one item");
26 ActionListBox listBox
= new ActionListBox(actionListPreferredSize
);
27 for(final Runnable action
: actions
) {
28 listBox
.addItem(action
.toString(), new Runnable() {
37 Panel mainPanel
= new Panel();
38 mainPanel
.setLayoutManager(
41 .setRightMarginSize(1));
42 if(description
!= null) {
43 mainPanel
.addComponent(new Label(description
));
44 mainPanel
.addComponent(new EmptySpace(TerminalSize
.ONE
));
46 listBox
.setLayoutData(
47 GridLayout
.createLayoutData(
48 GridLayout
.Alignment
.FILL
,
49 GridLayout
.Alignment
.CENTER
,
53 mainPanel
.addComponent(new EmptySpace(TerminalSize
.ONE
));
56 Panel buttonPanel
= new Panel();
57 buttonPanel
.setLayoutManager(new GridLayout(2).setHorizontalSpacing(1));
58 buttonPanel
.addComponent(new Button(LocalizedString
.Cancel
.toString(), new Runnable() {
63 }).setLayoutData(GridLayout
.createLayoutData(GridLayout
.Alignment
.CENTER
, GridLayout
.Alignment
.CENTER
, true, false)));
64 buttonPanel
.setLayoutData(
65 GridLayout
.createLayoutData(
66 GridLayout
.Alignment
.END
,
67 GridLayout
.Alignment
.CENTER
,
72 setComponent(mainPanel
);
75 private void onCancel() {
80 * Helper method for immediately displaying a {@code ActionListDialog}, the method will return when the dialog is
82 * @param textGUI Text GUI the dialog should be added to
83 * @param title Title of the dialog
84 * @param description Description of the dialog
85 * @param items Items in the {@code ActionListBox}, the label will be taken from each {@code Runnable} by calling
86 * {@code toString()} on each one
88 public static void showDialog(WindowBasedTextGUI textGUI
, String title
, String description
, Runnable
... items
) {
89 ActionListDialog actionListDialog
= new ActionListDialogBuilder()
91 .setDescription(description
)
94 actionListDialog
.showDialog(textGUI
);