5d5485a83fe4fb529bc751bcecb23cb30d2cb777
2 * Jexer - Java Text User Interface - demonstration program
6 * Author: Kevin Lamonte, <a href="mailto:kevin.lamonte@gmail.com">kevin.lamonte@gmail.com</a>
8 * License: LGPLv3 or later
10 * Copyright: This module is licensed under the GNU Lesser General
11 * Public License Version 3. Please see the file "COPYING" in this
12 * directory for more information about the GNU Lesser General Public
15 * Copyright (C) 2015 Kevin Lamonte
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public License
19 * as published by the Free Software Foundation; either version 3 of
20 * the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this program; if not, see
29 * http://www.gnu.org/licenses/, or write to the Free Software
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
37 class DemoMsgBoxWindow
extends TWindow
{
39 private void openYNCMessageBox() {
40 application.messageBox("Yes/No/Cancel MessageBox",
42 This is an example of a Yes/No/Cancel MessageBox.
44 Note that the MessageBox text can span multiple
47 The default result (if someone hits the top-left
48 close button) is CANCEL.
50 TMessageBox.Type.YESNOCANCEL);
53 private void openYNMessageBox() {
54 application.messageBox("Yes/No MessageBox",
56 This is an example of a Yes/No MessageBox.
58 Note that the MessageBox text can span multiple
61 The default result (if someone hits the top-left
64 TMessageBox.Type.YESNO);
67 private void openOKCMessageBox() {
68 application.messageBox("OK/Cancel MessageBox",
70 This is an example of a OK/Cancel MessageBox.
72 Note that the MessageBox text can span multiple
75 The default result (if someone hits the top-left
76 close button) is CANCEL.
78 TMessageBox.Type.OKCANCEL);
81 private void openOKMessageBox() {
82 application.messageBox("OK MessageBox",
84 This is an example of a OK MessageBox. This is the
87 Note that the MessageBox text can span multiple
90 The default result (if someone hits the top-left
101 DemoMsgBoxWindow(final TApplication parent
) {
102 this(parent
, TWindow
.CENTERED
| TWindow
.RESIZABLE
);
108 DemoMsgBoxWindow(final TApplication parent
, final int flags
) {
109 // Construct a demo window. X and Y don't matter because it
110 // will be centered on screen.
111 super(parent
, "Message Boxes", 0, 0, 60, 15, flags
);
116 addLabel("Default OK message box", 1, row);
117 addButton("Open O&K MB", 35, row, &openOKMessageBox);
120 addLabel("OK/Cancel message box", 1, row);
121 addButton("O&pen OKC MB", 35, row, &openOKCMessageBox);
124 addLabel("Yes/No message box", 1, row);
125 addButton("Open &YN MB", 35, row, &openYNMessageBox);
128 addLabel("Yes/No/Cancel message box", 1, row);
129 addButton("Ope&n YNC MB", 35, row, &openYNCMessageBox);
132 addLabel("Input box", 1, row);
133 addButton("Open &input box", 35, row,
135 application.inputBox("Input Box",
137 This is an example of an InputBox.
139 Note that the InputBox text can span multiple
146 addButton("&Close Window", (width - 14) / 2, height - 4,
148 application.closeWindow(this);
156 class DemoMainWindow
extends TWindow
{
158 // Timer that increments a number
159 private TTimer timer;
161 // The modal window is a more low-level example of controlling a window
162 // "from the outside". Most windows will probably subclass TWindow and
163 // do this kind of logic on their own.
164 private TWindow modalWindow;
165 private void openModalWindow() {
166 modalWindow = application.addWindow("Demo Modal Window", 0, 0,
167 58, 15, TWindow.Flag.MODAL);
168 modalWindow.addLabel("This is an example of a very braindead modal window.", 1, 1);
169 modalWindow.addLabel("Modal windows are centered by default.", 1, 2);
170 modalWindow.addButton("&Close", (modalWindow.width - 8)/2,
171 modalWindow.height - 4, &modalWindowClose);
173 private void modalWindowClose() {
174 application.closeWindow(modalWindow);
177 /// This is an example of having a button call a function.
178 private void openCheckboxWindow() {
179 new DemoCheckboxWindow(application);
182 /// We need to override onClose so that the timer will no longer be
183 /// called after we close the window. TTimers currently are completely
184 /// unaware of the rest of the UI classes.
185 override public void onClose() {
186 application.removeTimer(timer);
191 * Construct demo window. It will be centered on screen.
193 public DemoMainWindow(TApplication parent
) {
194 this(parent
, CENTERED
| RESIZABLE
);
200 private DemoMainWindow(TApplication parent
, int flags
) {
201 // Construct a demo window. X and Y don't matter because it will be
202 // centered on screen.
203 super(parent
, "Demo Window", 0, 0, 60, 23, flags
);
209 addLabel("Message Boxes", 1, row
);
210 addButton("&MessageBoxes", 35, row
,
213 new DemoMsgBoxWindow(getApplication());
221 addLabel("Open me as modal", 1, row);
222 addButton("W&indow", 35, row,
224 new DemoMainWindow(application, Flag.MODAL);
230 addLabel("Variable-width text field:", 1, row);
231 addField(35, row++, 15, false, "Field text");
233 addLabel("Fixed-width text field:", 1, row);
234 addField(35, row, 15, true);
238 addLabel("Radio buttons and checkboxes", 1, row);
239 addButton("&Checkboxes", 35, row, &openCheckboxWindow);
244 addLabel("Editor window", 1, row);
245 addButton("Edito&r", 35, row,
247 new TEditor(application, 0, 0, 60, 15);
254 addLabel("Text areas", 1, row);
255 addButton("&Text", 35, row,
257 new DemoTextWindow(application);
264 addLabel("Tree views", 1, row);
265 addButton("Tree&View", 35, row,
267 new DemoTreeViewWindow(application);
275 addLabel("Terminal", 1, row);
276 addButton("Termi&nal", 35, row,
278 application.openTerminal(0, 0);
285 TProgressBar bar = addProgressBar(1, row, 22);
287 TLabel timerLabel = addLabel("Timer", 1, row);
288 timer = parent.addTimer(100,
291 auto writer = appender!dstring();
292 formattedWrite(writer, "Timer: %d", i);
293 timerLabel.text = writer.data;
294 timerLabel.width = cast(uint)timerLabel.text.length;
299 parent.repaint = true;
306 * The demo application itself.
308 class DemoApplication
extends TApplication
{
312 public DemoApplication() throws Exception
{
314 new DemoMainWindow(this);
320 TMenu demoMenu
= addMenu("&Demo");
321 TMenuItem item
= demoMenu
.addItem(2000, "&Checkable");
322 item
.setCheckable(true);
323 item
= demoMenu
.addItem(2001, "Disabled");
324 item
.setEnabled(false);
325 item
= demoMenu
.addItem(2002, "&Normal");
326 TSubMenu subMenu
= demoMenu
.addSubMenu("Sub-&Menu");
327 item
= demoMenu
.addItem(2010, "N&ormal A&&D");
329 item
= subMenu
.addItem(2000, "&Checkable (sub)");
330 item
.setCheckable(true);
331 item
= subMenu
.addItem(2001, "Disabled (sub)");
332 item
.setEnabled(false);
333 item
= subMenu
.addItem(2002, "&Normal (sub)");
335 subMenu
= subMenu
.addSubMenu("Sub-&Menu");
336 item
= subMenu
.addItem(2000, "&Checkable (sub)");
337 item
.setCheckable(true);
338 item
= subMenu
.addItem(2001, "Disabled (sub)");
339 item
.setEnabled(false);
340 item
= subMenu
.addItem(2002, "&Normal (sub)");
348 * This class provides a simple demonstration of Jexer's capabilities.
354 * @param args Command line arguments
356 public static void main(String
[] args
) {
358 DemoApplication app
= new DemoApplication();
360 } catch (Exception e
) {