package com.googlecode.lanterna.gui2.dialogs; import com.googlecode.lanterna.TerminalSize; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Dialog builder for the {@code ListSelectDialog} class, use this to create instances of that class and to customize * them * @author Martin */ public class ListSelectDialogBuilder extends AbstractDialogBuilder, ListSelectDialog> { private TerminalSize listBoxSize; private boolean canCancel; private List content; /** * Default constructor */ public ListSelectDialogBuilder() { super("ListSelectDialog"); this.listBoxSize = null; this.canCancel = true; this.content = new ArrayList(); } @Override protected ListSelectDialogBuilder self() { return this; } @Override protected ListSelectDialog buildDialog() { return new ListSelectDialog( title, description, listBoxSize, canCancel, content); } /** * Sets the size of the list box in the dialog, scrollbars will be used if there is not enough space to draw all * items. If set to {@code null}, the dialog will ask for enough space to be able to draw all items. * @param listBoxSize Size of the list box in the dialog * @return Itself */ public ListSelectDialogBuilder setListBoxSize(TerminalSize listBoxSize) { this.listBoxSize = listBoxSize; return this; } /** * Size of the list box in the dialog or {@code null} if the dialog will ask for enough space to draw all items * @return Size of the list box in the dialog or {@code null} if the dialog will ask for enough space to draw all items */ public TerminalSize getListBoxSize() { return listBoxSize; } /** * Sets if the dialog can be cancelled or not (default: {@code true}) * @param canCancel If {@code true}, the user has the option to cancel the dialog, if {@code false} there is no such * button in the dialog * @return Itself */ public ListSelectDialogBuilder setCanCancel(boolean canCancel) { this.canCancel = canCancel; return this; } /** * Returns {@code true} if the dialog can be cancelled once it's opened * @return {@code true} if the dialog can be cancelled once it's opened */ public boolean isCanCancel() { return canCancel; } /** * Adds an item to the list box at the end * @param item Item to add to the list box * @return Itself */ public ListSelectDialogBuilder addListItem(T item) { this.content.add(item); return this; } /** * Adds a list of items to the list box at the end, in the order they are passed in * @param items Items to add to the list box * @return Itself */ public ListSelectDialogBuilder addListItems(T... items) { this.content.addAll(Arrays.asList(items)); return this; } /** * Returns a copy of the list of items in the list box * @return Copy of the list of items in the list box */ public List getListItems() { return new ArrayList(content); } }