| 1 | /* |
| 2 | * Jexer - Java Text User Interface |
| 3 | * |
| 4 | * License: LGPLv3 or later |
| 5 | * |
| 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. |
| 9 | * |
| 10 | * Copyright (C) 2015 Kevin Lamonte |
| 11 | * |
| 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. |
| 16 | * |
| 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. |
| 21 | * |
| 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 |
| 26 | * 02110-1301 USA |
| 27 | * |
| 28 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] |
| 29 | * @version 1 |
| 30 | */ |
| 31 | package jexer.demos; |
| 32 | |
| 33 | import jexer.*; |
| 34 | import jexer.event.*; |
| 35 | import jexer.menu.*; |
| 36 | |
| 37 | /** |
| 38 | * This window demonstates the TMessageBox and TInputBox widgets. |
| 39 | */ |
| 40 | public class DemoMsgBoxWindow extends TWindow { |
| 41 | |
| 42 | /** |
| 43 | * Constructor. |
| 44 | * |
| 45 | * @param parent the main application |
| 46 | */ |
| 47 | DemoMsgBoxWindow(final TApplication parent) { |
| 48 | this(parent, TWindow.CENTERED | TWindow.RESIZABLE); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Constructor. |
| 53 | * |
| 54 | * @param parent the main application |
| 55 | * @param flags bitmask of MODAL, CENTERED, or RESIZABLE |
| 56 | */ |
| 57 | DemoMsgBoxWindow(final TApplication parent, final int flags) { |
| 58 | // Construct a demo window. X and Y don't matter because it |
| 59 | // will be centered on screen. |
| 60 | super(parent, "Message Boxes", 0, 0, 60, 15, flags); |
| 61 | |
| 62 | int row = 1; |
| 63 | |
| 64 | // Add some widgets |
| 65 | addLabel("Default OK message box", 1, row); |
| 66 | addButton("Open O&K MB", 35, row, |
| 67 | new TAction() { |
| 68 | public void DO() { |
| 69 | getApplication().messageBox("OK MessageBox", |
| 70 | "This is an example of a OK MessageBox. This is the\n" + |
| 71 | "default MessageBox.\n" + |
| 72 | "\n" + |
| 73 | "Note that the MessageBox text can span multiple\n" + |
| 74 | "lines.\n" + |
| 75 | "\n" + |
| 76 | "The default result (if someone hits the top-left\n" + |
| 77 | "close button) is OK.\n", |
| 78 | TMessageBox.Type.OK); |
| 79 | } |
| 80 | } |
| 81 | ); |
| 82 | row += 2; |
| 83 | |
| 84 | addLabel("OK/Cancel message box", 1, row); |
| 85 | addButton("O&pen OKC MB", 35, row, |
| 86 | new TAction() { |
| 87 | public void DO() { |
| 88 | getApplication().messageBox("OK/Cancel MessageBox", |
| 89 | "This is an example of a OK/Cancel MessageBox.\n" + |
| 90 | "\n" + |
| 91 | "Note that the MessageBox text can span multiple\n" + |
| 92 | "lines.\n" + |
| 93 | "\n" + |
| 94 | "The default result (if someone hits the top-left\n" + |
| 95 | "close button) is CANCEL.\n", |
| 96 | TMessageBox.Type.OKCANCEL); |
| 97 | } |
| 98 | } |
| 99 | ); |
| 100 | row += 2; |
| 101 | |
| 102 | addLabel("Yes/No message box", 1, row); |
| 103 | addButton("Open &YN MB", 35, row, |
| 104 | new TAction() { |
| 105 | public void DO() { |
| 106 | getApplication().messageBox("Yes/No MessageBox", |
| 107 | "This is an example of a Yes/No MessageBox.\n" + |
| 108 | "\n" + |
| 109 | "Note that the MessageBox text can span multiple\n" + |
| 110 | "lines.\n" + |
| 111 | "\n" + |
| 112 | "The default result (if someone hits the top-left\n" + |
| 113 | "close button) is NO.\n", |
| 114 | TMessageBox.Type.YESNO); |
| 115 | } |
| 116 | } |
| 117 | ); |
| 118 | row += 2; |
| 119 | |
| 120 | addLabel("Yes/No/Cancel message box", 1, row); |
| 121 | addButton("Ope&n YNC MB", 35, row, |
| 122 | new TAction() { |
| 123 | public void DO() { |
| 124 | getApplication().messageBox("Yes/No/Cancel MessageBox", |
| 125 | "This is an example of a Yes/No/Cancel MessageBox.\n" + |
| 126 | "\n" + |
| 127 | "Note that the MessageBox text can span multiple\n" + |
| 128 | "lines.\n" + |
| 129 | "\n" + |
| 130 | "The default result (if someone hits the top-left\n" + |
| 131 | "close button) is CANCEL.\n", |
| 132 | TMessageBox.Type.YESNOCANCEL); |
| 133 | } |
| 134 | } |
| 135 | ); |
| 136 | row += 2; |
| 137 | |
| 138 | addLabel("Input box", 1, row); |
| 139 | addButton("Open &input box", 35, row, |
| 140 | new TAction() { |
| 141 | public void DO() { |
| 142 | TInputBox in = getApplication().inputBox("Input Box", |
| 143 | "This is an example of an InputBox.\n" + |
| 144 | "\n" + |
| 145 | "Note that the InputBox text can span multiple\n" + |
| 146 | "lines.\n", |
| 147 | "some input text"); |
| 148 | getApplication().messageBox("Your InputBox Answer", |
| 149 | "You entered: " + in.getText()); |
| 150 | } |
| 151 | } |
| 152 | ); |
| 153 | |
| 154 | addButton("&Close Window", (getWidth() - 14) / 2, getHeight() - 4, |
| 155 | new TAction() { |
| 156 | public void DO() { |
| 157 | getApplication().closeWindow(DemoMsgBoxWindow.this); |
| 158 | } |
| 159 | } |
| 160 | ); |
| 161 | } |
| 162 | } |
| 163 | |