1 package com
.googlecode
.lanterna
.gui2
.dialogs
;
3 import com
.googlecode
.lanterna
.TerminalSize
;
5 import java
.util
.ArrayList
;
6 import java
.util
.Arrays
;
10 * Dialog builder for the {@code ActionListDialog} class, use this to create instances of that class and to customize
14 public class ActionListDialogBuilder
extends AbstractDialogBuilder
<ActionListDialogBuilder
, ActionListDialog
> {
15 private TerminalSize listBoxSize
;
16 private boolean canCancel
;
17 private List
<Runnable
> actions
;
22 public ActionListDialogBuilder() {
23 super("ActionListDialogBuilder");
24 this.listBoxSize
= null;
25 this.canCancel
= true;
26 this.actions
= new ArrayList
<Runnable
>();
30 protected ActionListDialogBuilder
self() {
35 protected ActionListDialog
buildDialog() {
36 return new ActionListDialog(
45 * Sets the size of the internal {@code ActionListBox} in columns and rows, forcing scrollbars to appear if the
46 * space isn't big enough to contain all the items
47 * @param listBoxSize Size of the {@code ActionListBox}
50 public ActionListDialogBuilder
setListBoxSize(TerminalSize listBoxSize
) {
51 this.listBoxSize
= listBoxSize
;
56 * Returns the specified size of the internal {@code ActionListBox} or {@code null} if there is no size and the list
57 * box will attempt to take up enough size to draw all items
58 * @return Specified size of the internal {@code ActionListBox} or {@code null} if there is no size
60 public TerminalSize
getListBoxSize() {
65 * Sets if the dialog can be cancelled or not (default: {@code true})
66 * @param canCancel If {@code true}, the user has the option to cancel the dialog, if {@code false} there is no such
67 * button in the dialog
70 public ActionListDialogBuilder
setCanCancel(boolean canCancel
) {
71 this.canCancel
= canCancel
;
76 * Returns {@code true} if the dialog can be cancelled once it's opened
77 * @return {@code true} if the dialog can be cancelled once it's opened
79 public boolean isCanCancel() {
84 * Adds an additional action to the {@code ActionListBox} that is to be displayed when the dialog is opened
85 * @param label Label of the new action
86 * @param action Action to perform if the user selects this item
89 public ActionListDialogBuilder
addAction(final String label
, final Runnable action
) {
90 return addAction(new Runnable() {
92 public String
toString() {
104 * Adds an additional action to the {@code ActionListBox} that is to be displayed when the dialog is opened. The
105 * label of this item will be derived by calling {@code toString()} on the runnable
106 * @param action Action to perform if the user selects this item
109 public ActionListDialogBuilder
addAction(Runnable action
) {
110 this.actions
.add(action
);
115 * Adds additional actions to the {@code ActionListBox} that is to be displayed when the dialog is opened. The
116 * label of the items will be derived by calling {@code toString()} on each runnable
117 * @param actions Items to add to the {@code ActionListBox}
120 public ActionListDialogBuilder
addActions(Runnable
... actions
) {
121 this.actions
.addAll(Arrays
.asList(actions
));
126 * Returns a copy of the internal list of actions currently inside this builder that will be assigned to the
127 * {@code ActionListBox} in the dialog when built
128 * @return Copy of the internal list of actions currently inside this builder
130 public List
<Runnable
> getActions() {
131 return new ArrayList
<Runnable
>(actions
);