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 ListSelectDialog} class, use this to create instances of that class and to customize
14 public class ListSelectDialogBuilder
<T
> extends AbstractDialogBuilder
<ListSelectDialogBuilder
<T
>, ListSelectDialog
<T
>> {
15 private TerminalSize listBoxSize
;
16 private boolean canCancel
;
17 private List
<T
> content
;
22 public ListSelectDialogBuilder() {
23 super("ListSelectDialog");
24 this.listBoxSize
= null;
25 this.canCancel
= true;
26 this.content
= new ArrayList
<T
>();
30 protected ListSelectDialogBuilder
<T
> self() {
35 protected ListSelectDialog
<T
> buildDialog() {
36 return new ListSelectDialog
<T
>(
45 * Sets the size of the list box in the dialog, scrollbars will be used if there is not enough space to draw all
46 * items. If set to {@code null}, the dialog will ask for enough space to be able to draw all items.
47 * @param listBoxSize Size of the list box in the dialog
50 public ListSelectDialogBuilder
<T
> setListBoxSize(TerminalSize listBoxSize
) {
51 this.listBoxSize
= listBoxSize
;
56 * Size of the list box in the dialog or {@code null} if the dialog will ask for enough space to draw all items
57 * @return Size of the list box in the dialog or {@code null} if the dialog will ask for enough space to draw all items
59 public TerminalSize
getListBoxSize() {
64 * Sets if the dialog can be cancelled or not (default: {@code true})
65 * @param canCancel If {@code true}, the user has the option to cancel the dialog, if {@code false} there is no such
66 * button in the dialog
69 public ListSelectDialogBuilder
<T
> setCanCancel(boolean canCancel
) {
70 this.canCancel
= canCancel
;
75 * Returns {@code true} if the dialog can be cancelled once it's opened
76 * @return {@code true} if the dialog can be cancelled once it's opened
78 public boolean isCanCancel() {
83 * Adds an item to the list box at the end
84 * @param item Item to add to the list box
87 public ListSelectDialogBuilder
<T
> addListItem(T item
) {
88 this.content
.add(item
);
93 * Adds a list of items to the list box at the end, in the order they are passed in
94 * @param items Items to add to the list box
97 public ListSelectDialogBuilder
<T
> addListItems(T
... items
) {
98 this.content
.addAll(Arrays
.asList(items
));
103 * Returns a copy of the list of items in the list box
104 * @return Copy of the list of items in the list box
106 public List
<T
> getListItems() {
107 return new ArrayList
<T
>(content
);