1270dae10ed81ca88bf9f93a444739efc1901002
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 * Construct demo window. It will be centered on screen.
73 public DemoMainWindow(TApplication parent
) {
74 this(parent
, CENTERED
| RESIZABLE
);
80 private DemoMainWindow(TApplication parent
, int flags
) {
81 // Construct a demo window. X and Y don't matter because it will be
82 // centered on screen.
83 super(parent
, "Demo Window", 0, 0, 60, 23, flags
);
90 addLabel("Message Boxes", 1, row);
91 addButton("&MessageBoxes", 35, row,
93 new DemoMsgBoxWindow(application);
99 addLabel("Open me as modal", 1, row);
100 addButton("W&indow", 35, row,
102 new DemoMainWindow(application, Flag.MODAL);
108 addLabel("Variable-width text field:", 1, row);
109 addField(35, row++, 15, false, "Field text");
111 addLabel("Fixed-width text field:", 1, row);
112 addField(35, row, 15, true);
116 addLabel("Radio buttons and checkboxes", 1, row);
117 addButton("&Checkboxes", 35, row, &openCheckboxWindow);
122 addLabel("Editor window", 1, row);
123 addButton("Edito&r", 35, row,
125 new TEditor(application, 0, 0, 60, 15);
132 addLabel("Text areas", 1, row);
133 addButton("&Text", 35, row,
135 new DemoTextWindow(application);
142 addLabel("Tree views", 1, row);
143 addButton("Tree&View", 35, row,
145 new DemoTreeViewWindow(application);
153 addLabel("Terminal", 1, row);
154 addButton("Termi&nal", 35, row,
156 application.openTerminal(0, 0);
163 TProgressBar bar = addProgressBar(1, row, 22);
165 TLabel timerLabel = addLabel("Timer", 1, row);
166 timer = parent.addTimer(100,
169 auto writer = appender!dstring();
170 formattedWrite(writer, "Timer: %d", i);
171 timerLabel.text = writer.data;
172 timerLabel.width = cast(uint)timerLabel.text.length;
177 parent.repaint = true;
184 * The demo application itself.
186 class DemoApplication
extends TApplication
{
190 public DemoApplication() throws Exception
{
192 new DemoMainWindow(this);
193 TWindow window2
= new DemoMainWindow(this);
194 window2
.setHeight(5);
195 window2
.setWidth(25);
202 * This class provides a simple demonstration of Jexer's capabilities.
208 * @param args Command line arguments
210 public static void main(String
[] args
) {
212 DemoApplication app
= new DemoApplication();
214 } catch (Exception e
) {