29d03455577fb7204ac20133d3e94cb92159a421
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
36 class DemoMainWindow
extends TWindow
{
38 // Timer that increments a number
41 // The modal window is a more low-level example of controlling a window
42 // "from the outside". Most windows will probably subclass TWindow and
43 // do this kind of logic on their own.
44 private TWindow modalWindow;
45 private void openModalWindow() {
46 modalWindow = application.addWindow("Demo Modal Window", 0, 0,
47 58, 15, TWindow.Flag.MODAL);
48 modalWindow.addLabel("This is an example of a very braindead modal window.", 1, 1);
49 modalWindow.addLabel("Modal windows are centered by default.", 1, 2);
50 modalWindow.addButton("&Close", (modalWindow.width - 8)/2,
51 modalWindow.height - 4, &modalWindowClose);
53 private void modalWindowClose() {
54 application.closeWindow(modalWindow);
57 /// This is an example of having a button call a function.
58 private void openCheckboxWindow() {
59 new DemoCheckboxWindow(application);
62 /// We need to override onClose so that the timer will no longer be
63 /// called after we close the window. TTimers currently are completely
64 /// unaware of the rest of the UI classes.
65 override public void onClose() {
66 application.removeTimer(timer);
71 public DemoMainWindow(TApplication parent
) {
72 this(parent
, CENTERED
| RESIZABLE
);
76 public DemoMainWindow(TApplication parent
, int flags
) {
77 // Construct a demo window. X and Y don't matter because it will be
78 // centered on screen.
79 super(parent
, "Demo Window", 0, 0, 60, 23, flags
);
86 addLabel("Message Boxes", 1, row);
87 addButton("&MessageBoxes", 35, row,
89 new DemoMsgBoxWindow(application);
95 addLabel("Open me as modal", 1, row);
96 addButton("W&indow", 35, row,
98 new DemoMainWindow(application, Flag.MODAL);
104 addLabel("Variable-width text field:", 1, row);
105 addField(35, row++, 15, false, "Field text");
107 addLabel("Fixed-width text field:", 1, row);
108 addField(35, row, 15, true);
112 addLabel("Radio buttons and checkboxes", 1, row);
113 addButton("&Checkboxes", 35, row, &openCheckboxWindow);
118 addLabel("Editor window", 1, row);
119 addButton("Edito&r", 35, row,
121 new TEditor(application, 0, 0, 60, 15);
128 addLabel("Text areas", 1, row);
129 addButton("&Text", 35, row,
131 new DemoTextWindow(application);
138 addLabel("Tree views", 1, row);
139 addButton("Tree&View", 35, row,
141 new DemoTreeViewWindow(application);
149 addLabel("Terminal", 1, row);
150 addButton("Termi&nal", 35, row,
152 application.openTerminal(0, 0);
159 TProgressBar bar = addProgressBar(1, row, 22);
161 TLabel timerLabel = addLabel("Timer", 1, row);
162 timer = parent.addTimer(100,
165 auto writer = appender!dstring();
166 formattedWrite(writer, "Timer: %d", i);
167 timerLabel.text = writer.data;
168 timerLabel.width = cast(uint)timerLabel.text.length;
173 parent.repaint = true;
180 * The demo application itself.
182 class DemoApplication
extends TApplication
{
186 public DemoApplication() throws Exception
{
188 new DemoMainWindow(this);
193 * This class provides a simple demonstration of Jexer's capabilities.
199 * @param args Command line arguments
201 public static void main(String
[] args
) {
203 DemoApplication app
= new DemoApplication();
205 } catch (Exception e
) {