From 72b6bd90316d58e87afbed110164cc2f203ec919 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Sun, 8 Apr 2018 14:44:38 -0400 Subject: [PATCH] #27 expose messagebox type for inputbox --- src/jexer/TApplication.java | 16 ++++++++++++++++ src/jexer/TInputBox.java | 20 ++++++++++++++++++-- src/jexer/demos/DemoMsgBoxWindow.java | 22 ++++++++++++++++++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/jexer/TApplication.java b/src/jexer/TApplication.java index 9fa64d0..7f491a5 100644 --- a/src/jexer/TApplication.java +++ b/src/jexer/TApplication.java @@ -2861,6 +2861,22 @@ public class TApplication implements Runnable { return new TInputBox(this, title, caption, text); } + /** + * Convenience function to spawn an input box. + * + * @param title window title, will be centered along the top border + * @param caption message to display. Use embedded newlines to get a + * multi-line box. + * @param text initial text to seed the field with + * @param type one of the Type constants. Default is Type.OK. + * @return the new input box + */ + public final TInputBox inputBox(final String title, final String caption, + final String text, final TInputBox.Type type) { + + return new TInputBox(this, title, caption, text, type); + } + /** * Convenience function to open a terminal window. * diff --git a/src/jexer/TInputBox.java b/src/jexer/TInputBox.java index 070f277..6ade42f 100644 --- a/src/jexer/TInputBox.java +++ b/src/jexer/TInputBox.java @@ -69,7 +69,7 @@ public class TInputBox extends TMessageBox { public TInputBox(final TApplication application, final String title, final String caption) { - this(application, title, caption, ""); + this(application, title, caption, "", Type.OK); } /** @@ -84,7 +84,23 @@ public class TInputBox extends TMessageBox { public TInputBox(final TApplication application, final String title, final String caption, final String text) { - super(application, title, caption, Type.OK, false); + this(application, title, caption, text, Type.OK); + } + + /** + * Public constructor. The input box will be centered on screen. + * + * @param application TApplication that manages this window + * @param title window title, will be centered along the top border + * @param caption message to display. Use embedded newlines to get a + * multi-line box. + * @param text initial text to seed the field with + * @param type one of the Type constants. Default is Type.OK. + */ + public TInputBox(final TApplication application, final String title, + final String caption, final String text, final Type type) { + + super(application, title, caption, type, false); for (TWidget widget: getChildren()) { if (widget instanceof TButton) { diff --git a/src/jexer/demos/DemoMsgBoxWindow.java b/src/jexer/demos/DemoMsgBoxWindow.java index 27ee790..b6c9404 100644 --- a/src/jexer/demos/DemoMsgBoxWindow.java +++ b/src/jexer/demos/DemoMsgBoxWindow.java @@ -59,7 +59,7 @@ public class DemoMsgBoxWindow extends TWindow { DemoMsgBoxWindow(final TApplication parent, final int flags) { // Construct a demo window. X and Y don't matter because it // will be centered on screen. - super(parent, "Message Boxes", 0, 0, 60, 16, flags); + super(parent, "Message Boxes", 0, 0, 64, 18, flags); int row = 1; @@ -137,7 +137,7 @@ public class DemoMsgBoxWindow extends TWindow { ); row += 2; - addLabel("Input box", 1, row); + addLabel("Input box 1", 1, row); addButton("Open &input box", 35, row, new TAction() { public void DO() { @@ -152,6 +152,24 @@ public class DemoMsgBoxWindow extends TWindow { } } ); + row += 2; + + addLabel("Input box 2", 1, row); + addButton("Cance&llable input box", 35, row, + new TAction() { + public void DO() { + TInputBox in = getApplication().inputBox("Input Box", +"This is an example of an InputBox.\n" + +"\n" + +"Note that the InputBox text can span multiple\n" + +"lines.\n" + +"This one has both OK and Cancel buttons.\n", + "some input text", TInputBox.Type.OKCANCEL); + getApplication().messageBox("Your InputBox Answer", + "You entered: " + in.getText()); + } + } + ); addButton("&Close Window", (getWidth() - 14) / 2, getHeight() - 4, new TAction() { -- 2.27.0