ee2bca1ef35993df63dfe9255461cbf0ca1ae8c4
[fanfix.git] / src / jexer / demos / DemoMsgBoxWindow.java
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 // Constructors -----------------------------------------------------------
42 // ------------------------------------------------------------------------
43
44 /**
45 * Constructor.
46 *
47 * @param parent the main application
48 */
49 DemoMsgBoxWindow(final TApplication parent) {
50 this(parent, TWindow.CENTERED | TWindow.RESIZABLE);
51 }
52
53 /**
54 * Constructor.
55 *
56 * @param parent the main application
57 * @param flags bitmask of MODAL, CENTERED, or RESIZABLE
58 */
59 DemoMsgBoxWindow(final TApplication parent, final int flags) {
60 // Construct a demo window. X and Y don't matter because it
61 // will be centered on screen.
62 super(parent, "Message Boxes", 0, 0, 64, 18, flags);
63
64 int row = 1;
65
66 // Add some widgets
67 addLabel("Default OK message box", 1, row);
68 addButton("Open O&K MB", 35, row,
69 new TAction() {
70 public void DO() {
71 getApplication().messageBox("OK MessageBox",
72 "This is an example of a OK MessageBox. This is the\n" +
73 "default MessageBox.\n" +
74 "\n" +
75 "Note that the MessageBox text can span multiple\n" +
76 "lines.\n" +
77 "\n" +
78 "The default result (if someone hits the top-left\n" +
79 "close button) is OK.\n",
80 TMessageBox.Type.OK);
81 }
82 }
83 );
84 row += 2;
85
86 addLabel("OK/Cancel message box", 1, row);
87 addButton("O&pen OKC MB", 35, row,
88 new TAction() {
89 public void DO() {
90 getApplication().messageBox("OK/Cancel MessageBox",
91 "This is an example of a OK/Cancel MessageBox.\n" +
92 "\n" +
93 "Note that the MessageBox text can span multiple\n" +
94 "lines.\n" +
95 "\n" +
96 "The default result (if someone hits the top-left\n" +
97 "close button) is CANCEL.\n",
98 TMessageBox.Type.OKCANCEL);
99 }
100 }
101 );
102 row += 2;
103
104 addLabel("Yes/No message box", 1, row);
105 addButton("Open &YN MB", 35, row,
106 new TAction() {
107 public void DO() {
108 getApplication().messageBox("Yes/No MessageBox",
109 "This is an example of a Yes/No MessageBox.\n" +
110 "\n" +
111 "Note that the MessageBox text can span multiple\n" +
112 "lines.\n" +
113 "\n" +
114 "The default result (if someone hits the top-left\n" +
115 "close button) is NO.\n",
116 TMessageBox.Type.YESNO);
117 }
118 }
119 );
120 row += 2;
121
122 addLabel("Yes/No/Cancel message box", 1, row);
123 addButton("Ope&n YNC MB", 35, row,
124 new TAction() {
125 public void DO() {
126 getApplication().messageBox("Yes/No/Cancel MessageBox",
127 "This is an example of a Yes/No/Cancel MessageBox.\n" +
128 "\n" +
129 "Note that the MessageBox text can span multiple\n" +
130 "lines.\n" +
131 "\n" +
132 "The default result (if someone hits the top-left\n" +
133 "close button) is CANCEL.\n",
134 TMessageBox.Type.YESNOCANCEL);
135 }
136 }
137 );
138 row += 2;
139
140 addLabel("Input box 1", 1, row);
141 addButton("Open &input box", 35, row,
142 new TAction() {
143 public void DO() {
144 TInputBox in = getApplication().inputBox("Input Box",
145 "This is an example of an InputBox.\n" +
146 "\n" +
147 "Note that the InputBox text can span multiple\n" +
148 "lines.\n",
149 "some input text");
150 getApplication().messageBox("Your InputBox Answer",
151 "You entered: " + in.getText());
152 }
153 }
154 );
155 row += 2;
156
157 addLabel("Input box 2", 1, row);
158 addButton("Cance&llable input box", 35, row,
159 new TAction() {
160 public void DO() {
161 TInputBox in = getApplication().inputBox("Input Box",
162 "This is an example of an InputBox.\n" +
163 "\n" +
164 "Note that the InputBox text can span multiple\n" +
165 "lines.\n" +
166 "This one has both OK and Cancel buttons.\n",
167 "some input text", TInputBox.Type.OKCANCEL);
168 getApplication().messageBox("Your InputBox Answer",
169 "You entered: " + in.getText() + " and pressed " +
170 in.getResult());
171 }
172 }
173 );
174
175 addButton("&Close Window", (getWidth() - 14) / 2, getHeight() - 4,
176 new TAction() {
177 public void DO() {
178 getApplication().closeWindow(DemoMsgBoxWindow.this);
179 }
180 }
181 );
182
183 statusBar = newStatusBar("Message boxes");
184 statusBar.addShortcutKeypress(kbF1, cmHelp, "Help");
185 statusBar.addShortcutKeypress(kbF2, cmShell, "Shell");
186 statusBar.addShortcutKeypress(kbF3, cmOpen, "Open");
187 statusBar.addShortcutKeypress(kbF10, cmExit, "Exit");
188 }
189 }