2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
34 * TInputBox is a system-modal dialog with an OK button and a text input
35 * field. Call it like:
40 * box = application.inputBox(title, caption);
41 * if (box.getText().equals("yes")) {
42 * ... the user entered "yes", do stuff ...
48 public final class TInputBox
extends TMessageBox
{
56 * Retrieve the answer text.
58 * @return the answer text
60 public String
getText() {
61 return field
.getText();
65 * Public constructor. The input box will be centered on screen.
67 * @param application TApplication that manages this window
68 * @param title window title, will be centered along the top border
69 * @param caption message to display. Use embedded newlines to get a
72 public TInputBox(final TApplication application
, final String title
,
73 final String caption
) {
75 this(application
, title
, caption
, "");
79 * Public constructor. The input box will be centered on screen.
81 * @param application TApplication that manages this window
82 * @param title window title, will be centered along the top border
83 * @param caption message to display. Use embedded newlines to get a
85 * @param text initial text to seed the field with
87 public TInputBox(final TApplication application
, final String title
,
88 final String caption
, final String text
) {
90 super(application
, title
, caption
, Type
.OK
, false);
92 for (TWidget widget
: getChildren()) {
93 if (widget
instanceof TButton
) {
94 widget
.setY(widget
.getY() + 2);
98 setHeight(getHeight() + 2);
99 field
= addField(1, getHeight() - 6, getWidth() - 4, false, text
);
101 // Yield to the secondary thread. When I come back from the
102 // constructor response will already be set.
103 getApplication().yield();