X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fcom%2Fgooglecode%2Flanterna%2Fgui2%2Fdialogs%2FActionListDialog.java;fp=src%2Fcom%2Fgooglecode%2Flanterna%2Fgui2%2Fdialogs%2FActionListDialog.java;h=0000000000000000000000000000000000000000;hp=2bce743f88b060da89a792af452bec25b3e8b3e9;hb=f06c81000632cfb5f525ca458f719338f55f9f66;hpb=a73a906356c971b080c36368e71a15d87e8b8d31 diff --git a/src/com/googlecode/lanterna/gui2/dialogs/ActionListDialog.java b/src/com/googlecode/lanterna/gui2/dialogs/ActionListDialog.java deleted file mode 100644 index 2bce743..0000000 --- a/src/com/googlecode/lanterna/gui2/dialogs/ActionListDialog.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.googlecode.lanterna.gui2.dialogs; - -import com.googlecode.lanterna.TerminalSize; -import com.googlecode.lanterna.gui2.*; - -import java.util.List; - -/** - * Dialog containing a multiple item action list box - * @author Martin - */ -public class ActionListDialog extends DialogWindow { - - ActionListDialog( - String title, - String description, - TerminalSize actionListPreferredSize, - boolean canCancel, - List actions) { - - super(title); - if(actions.isEmpty()) { - throw new IllegalStateException("ActionListDialog needs at least one item"); - } - - ActionListBox listBox = new ActionListBox(actionListPreferredSize); - for(final Runnable action: actions) { - listBox.addItem(action.toString(), new Runnable() { - @Override - public void run() { - action.run(); - close(); - } - }); - } - - Panel mainPanel = new Panel(); - mainPanel.setLayoutManager( - new GridLayout(1) - .setLeftMarginSize(1) - .setRightMarginSize(1)); - if(description != null) { - mainPanel.addComponent(new Label(description)); - mainPanel.addComponent(new EmptySpace(TerminalSize.ONE)); - } - listBox.setLayoutData( - GridLayout.createLayoutData( - GridLayout.Alignment.FILL, - GridLayout.Alignment.CENTER, - true, - false)) - .addTo(mainPanel); - mainPanel.addComponent(new EmptySpace(TerminalSize.ONE)); - - if(canCancel) { - Panel buttonPanel = new Panel(); - buttonPanel.setLayoutManager(new GridLayout(2).setHorizontalSpacing(1)); - buttonPanel.addComponent(new Button(LocalizedString.Cancel.toString(), new Runnable() { - @Override - public void run() { - onCancel(); - } - }).setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.CENTER, GridLayout.Alignment.CENTER, true, false))); - buttonPanel.setLayoutData( - GridLayout.createLayoutData( - GridLayout.Alignment.END, - GridLayout.Alignment.CENTER, - false, - false)) - .addTo(mainPanel); - } - setComponent(mainPanel); - } - - private void onCancel() { - close(); - } - - /** - * Helper method for immediately displaying a {@code ActionListDialog}, the method will return when the dialog is - * closed - * @param textGUI Text GUI the dialog should be added to - * @param title Title of the dialog - * @param description Description of the dialog - * @param items Items in the {@code ActionListBox}, the label will be taken from each {@code Runnable} by calling - * {@code toString()} on each one - */ - public static void showDialog(WindowBasedTextGUI textGUI, String title, String description, Runnable... items) { - ActionListDialog actionListDialog = new ActionListDialogBuilder() - .setTitle(title) - .setDescription(description) - .addActions(items) - .build(); - actionListDialog.showDialog(textGUI); - } -}