X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fcom%2Fgooglecode%2Flanterna%2Fgui2%2Fdialogs%2FTextInputDialogBuilder.java;fp=src%2Fcom%2Fgooglecode%2Flanterna%2Fgui2%2Fdialogs%2FTextInputDialogBuilder.java;h=0000000000000000000000000000000000000000;hp=36edb142e37d0c86e568cd68f210bc0881929d4c;hb=f06c81000632cfb5f525ca458f719338f55f9f66;hpb=a73a906356c971b080c36368e71a15d87e8b8d31 diff --git a/src/com/googlecode/lanterna/gui2/dialogs/TextInputDialogBuilder.java b/src/com/googlecode/lanterna/gui2/dialogs/TextInputDialogBuilder.java deleted file mode 100644 index 36edb14..0000000 --- a/src/com/googlecode/lanterna/gui2/dialogs/TextInputDialogBuilder.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.googlecode.lanterna.gui2.dialogs; - -import com.googlecode.lanterna.TerminalSize; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Dialog builder for the {@code TextInputDialog} class, use this to create instances of that class and to customize - * them - * @author Martin - */ -public class TextInputDialogBuilder extends AbstractDialogBuilder { - private String initialContent; - private TerminalSize textBoxSize; - private TextInputDialogResultValidator validator; - private boolean passwordInput; - - /** - * Default constructor - */ - public TextInputDialogBuilder() { - super("TextInputDialog"); - this.initialContent = ""; - this.textBoxSize = null; - this.validator = null; - this.passwordInput = false; - } - - @Override - protected TextInputDialogBuilder self() { - return this; - } - - protected TextInputDialog buildDialog() { - TerminalSize size = textBoxSize; - if ((initialContent == null || initialContent.trim().equals("")) && size == null) { - size = new TerminalSize(40, 1); - } - return new TextInputDialog( - title, - description, - size, - initialContent, - validator, - passwordInput); - } - - /** - * Sets the initial content the dialog will have - * @param initialContent Initial content the dialog will have - * @return Itself - */ - public TextInputDialogBuilder setInitialContent(String initialContent) { - this.initialContent = initialContent; - return this; - } - - /** - * Returns the initial content the dialog will have - * @return Initial content the dialog will have - */ - public String getInitialContent() { - return initialContent; - } - - /** - * Sets the size of the text box the dialog will have - * @param textBoxSize Size of the text box the dialog will have - * @return Itself - */ - public TextInputDialogBuilder setTextBoxSize(TerminalSize textBoxSize) { - this.textBoxSize = textBoxSize; - return this; - } - - /** - * Returns the size of the text box the dialog will have - * @return Size of the text box the dialog will have - */ - public TerminalSize getTextBoxSize() { - return textBoxSize; - } - - /** - * Sets the validator that will be attached to the text box in the dialog - * @param validator Validator that will be attached to the text box in the dialog - * @return Itself - */ - public TextInputDialogBuilder setValidator(TextInputDialogResultValidator validator) { - this.validator = validator; - return this; - } - - /** - * Returns the validator that will be attached to the text box in the dialog - * @return validator that will be attached to the text box in the dialog - */ - public TextInputDialogResultValidator getValidator() { - return validator; - } - - /** - * Helper method that assigned a validator to the text box the dialog will have which matches the pattern supplied - * @param pattern Pattern to validate the text box - * @param errorMessage Error message to show when the pattern doesn't match - * @return Itself - */ - public TextInputDialogBuilder setValidationPattern(final Pattern pattern, final String errorMessage) { - return setValidator(new TextInputDialogResultValidator() { - @Override - public String validate(String content) { - Matcher matcher = pattern.matcher(content); - if(!matcher.matches()) { - if(errorMessage == null) { - return "Invalid input"; - } - return errorMessage; - } - return null; - } - }); - } - - /** - * Sets if the text box the dialog will have contains a password and should be masked (default: {@code false}) - * @param passwordInput {@code true} if the text box should be password masked, {@code false} otherwise - * @return Itself - */ - public TextInputDialogBuilder setPasswordInput(boolean passwordInput) { - this.passwordInput = passwordInput; - return this; - } - - /** - * Returns {@code true} if the text box the dialog will have contains a password and should be masked - * @return {@code true} if the text box the dialog will have contains a password and should be masked - */ - public boolean isPasswordInput() { - return passwordInput; - } -}