| 1 | /* |
| 2 | * Jexer - Java Text User Interface |
| 3 | * |
| 4 | * The MIT License (MIT) |
| 5 | * |
| 6 | * Copyright (C) 2017 Kevin Lamonte |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 9 | * copy of this software and associated documentation files (the "Software"), |
| 10 | * to deal in the Software without restriction, including without limitation |
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 12 | * and/or sell copies of the Software, and to permit persons to whom the |
| 13 | * Software is furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 24 | * DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] |
| 27 | * @version 1 |
| 28 | */ |
| 29 | package jexer.demos; |
| 30 | |
| 31 | import jexer.*; |
| 32 | import static jexer.TCommand.*; |
| 33 | import static jexer.TKeypress.*; |
| 34 | |
| 35 | /** |
| 36 | * This window demonstates the TMessageBox and TInputBox widgets. |
| 37 | */ |
| 38 | public class DemoMsgBoxWindow extends TWindow { |
| 39 | |
| 40 | /** |
| 41 | * Constructor. |
| 42 | * |
| 43 | * @param parent the main application |
| 44 | */ |
| 45 | DemoMsgBoxWindow(final TApplication parent) { |
| 46 | this(parent, TWindow.CENTERED | TWindow.RESIZABLE); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Constructor. |
| 51 | * |
| 52 | * @param parent the main application |
| 53 | * @param flags bitmask of MODAL, CENTERED, or RESIZABLE |
| 54 | */ |
| 55 | DemoMsgBoxWindow(final TApplication parent, final int flags) { |
| 56 | // Construct a demo window. X and Y don't matter because it |
| 57 | // will be centered on screen. |
| 58 | super(parent, "Message Boxes", 0, 0, 60, 16, flags); |
| 59 | |
| 60 | int row = 1; |
| 61 | |
| 62 | // Add some widgets |
| 63 | addLabel("Default OK message box", 1, row); |
| 64 | addButton("Open O&K MB", 35, row, |
| 65 | new TAction() { |
| 66 | public void DO() { |
| 67 | getApplication().messageBox("OK MessageBox", |
| 68 | "This is an example of a OK MessageBox. This is the\n" + |
| 69 | "default MessageBox.\n" + |
| 70 | "\n" + |
| 71 | "Note that the MessageBox text can span multiple\n" + |
| 72 | "lines.\n" + |
| 73 | "\n" + |
| 74 | "The default result (if someone hits the top-left\n" + |
| 75 | "close button) is OK.\n", |
| 76 | TMessageBox.Type.OK); |
| 77 | } |
| 78 | } |
| 79 | ); |
| 80 | row += 2; |
| 81 | |
| 82 | addLabel("OK/Cancel message box", 1, row); |
| 83 | addButton("O&pen OKC MB", 35, row, |
| 84 | new TAction() { |
| 85 | public void DO() { |
| 86 | getApplication().messageBox("OK/Cancel MessageBox", |
| 87 | "This is an example of a OK/Cancel MessageBox.\n" + |
| 88 | "\n" + |
| 89 | "Note that the MessageBox text can span multiple\n" + |
| 90 | "lines.\n" + |
| 91 | "\n" + |
| 92 | "The default result (if someone hits the top-left\n" + |
| 93 | "close button) is CANCEL.\n", |
| 94 | TMessageBox.Type.OKCANCEL); |
| 95 | } |
| 96 | } |
| 97 | ); |
| 98 | row += 2; |
| 99 | |
| 100 | addLabel("Yes/No message box", 1, row); |
| 101 | addButton("Open &YN MB", 35, row, |
| 102 | new TAction() { |
| 103 | public void DO() { |
| 104 | getApplication().messageBox("Yes/No MessageBox", |
| 105 | "This is an example of a Yes/No MessageBox.\n" + |
| 106 | "\n" + |
| 107 | "Note that the MessageBox text can span multiple\n" + |
| 108 | "lines.\n" + |
| 109 | "\n" + |
| 110 | "The default result (if someone hits the top-left\n" + |
| 111 | "close button) is NO.\n", |
| 112 | TMessageBox.Type.YESNO); |
| 113 | } |
| 114 | } |
| 115 | ); |
| 116 | row += 2; |
| 117 | |
| 118 | addLabel("Yes/No/Cancel message box", 1, row); |
| 119 | addButton("Ope&n YNC MB", 35, row, |
| 120 | new TAction() { |
| 121 | public void DO() { |
| 122 | getApplication().messageBox("Yes/No/Cancel MessageBox", |
| 123 | "This is an example of a Yes/No/Cancel MessageBox.\n" + |
| 124 | "\n" + |
| 125 | "Note that the MessageBox text can span multiple\n" + |
| 126 | "lines.\n" + |
| 127 | "\n" + |
| 128 | "The default result (if someone hits the top-left\n" + |
| 129 | "close button) is CANCEL.\n", |
| 130 | TMessageBox.Type.YESNOCANCEL); |
| 131 | } |
| 132 | } |
| 133 | ); |
| 134 | row += 2; |
| 135 | |
| 136 | addLabel("Input box", 1, row); |
| 137 | addButton("Open &input box", 35, row, |
| 138 | new TAction() { |
| 139 | public void DO() { |
| 140 | TInputBox in = getApplication().inputBox("Input Box", |
| 141 | "This is an example of an InputBox.\n" + |
| 142 | "\n" + |
| 143 | "Note that the InputBox text can span multiple\n" + |
| 144 | "lines.\n", |
| 145 | "some input text"); |
| 146 | getApplication().messageBox("Your InputBox Answer", |
| 147 | "You entered: " + in.getText()); |
| 148 | } |
| 149 | } |
| 150 | ); |
| 151 | |
| 152 | addButton("&Close Window", (getWidth() - 14) / 2, getHeight() - 4, |
| 153 | new TAction() { |
| 154 | public void DO() { |
| 155 | getApplication().closeWindow(DemoMsgBoxWindow.this); |
| 156 | } |
| 157 | } |
| 158 | ); |
| 159 | |
| 160 | statusBar = newStatusBar("Message boxes"); |
| 161 | statusBar.addShortcutKeypress(kbF1, cmHelp, "Help"); |
| 162 | statusBar.addShortcutKeypress(kbF2, cmShell, "Shell"); |
| 163 | statusBar.addShortcutKeypress(kbF3, cmOpen, "Open"); |
| 164 | statusBar.addShortcutKeypress(kbF10, cmExit, "Exit"); |
| 165 | } |
| 166 | } |