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 DemoCheckboxWindow
extends TWindow
{
42 DemoCheckboxWindow(TApplication parent
) {
43 this(parent
, CENTERED
| RESIZABLE
);
49 DemoCheckboxWindow(TApplication parent
, int flags
) {
50 // Construct a demo window. X and Y don't matter because it
51 // will be centered on screen.
52 super(parent
, "Radiobuttons and Checkboxes", 0, 0, 60, 15, flags
);
57 addLabel("Check box example 1", 1, row
);
58 addCheckbox(35, row
++, "Checkbox 1", false);
59 addLabel("Check box example 2", 1, row
);
60 addCheckbox(35, row
++, "Checkbox 2", true);
64 auto group = addRadioGroup(1, row, "Group 1");
65 group.addRadioButton("Radio option 1");
66 group.addRadioButton("Radio option 2");
67 group.addRadioButton("Radio option 3");
69 addButton("&Close Window", (width - 14) / 2, height - 4,
71 application.closeWindow(this);
81 class DemoMsgBoxWindow
extends TWindow
{
83 private void openYNCMessageBox() {
84 application.messageBox("Yes/No/Cancel MessageBox",
86 This is an example of a Yes/No/Cancel MessageBox.
88 Note that the MessageBox text can span multiple
91 The default result (if someone hits the top-left
92 close button) is CANCEL.
94 TMessageBox.Type.YESNOCANCEL);
97 private void openYNMessageBox() {
98 application.messageBox("Yes/No MessageBox",
100 This is an example of a Yes/No MessageBox.
102 Note that the MessageBox text can span multiple
105 The default result (if someone hits the top-left
108 TMessageBox.Type.YESNO);
111 private void openOKCMessageBox() {
112 application.messageBox("OK/Cancel MessageBox",
114 This is an example of a OK/Cancel MessageBox.
116 Note that the MessageBox text can span multiple
119 The default result (if someone hits the top-left
120 close button) is CANCEL.
122 TMessageBox.Type.OKCANCEL);
125 private void openOKMessageBox() {
126 application.messageBox("OK MessageBox",
128 This is an example of a OK MessageBox. This is the
131 Note that the MessageBox text can span multiple
134 The default result (if someone hits the top-left
137 TMessageBox.Type.OK);
145 DemoMsgBoxWindow(final TApplication parent
) {
146 this(parent
, TWindow
.CENTERED
| TWindow
.RESIZABLE
);
152 DemoMsgBoxWindow(final TApplication parent
, final int flags
) {
153 // Construct a demo window. X and Y don't matter because it
154 // will be centered on screen.
155 super(parent
, "Message Boxes", 0, 0, 60, 15, flags
);
160 addLabel("Default OK message box", 1, row);
161 addButton("Open O&K MB", 35, row, &openOKMessageBox);
164 addLabel("OK/Cancel message box", 1, row);
165 addButton("O&pen OKC MB", 35, row, &openOKCMessageBox);
168 addLabel("Yes/No message box", 1, row);
169 addButton("Open &YN MB", 35, row, &openYNMessageBox);
172 addLabel("Yes/No/Cancel message box", 1, row);
173 addButton("Ope&n YNC MB", 35, row, &openYNCMessageBox);
176 addLabel("Input box", 1, row);
177 addButton("Open &input box", 35, row,
179 application.inputBox("Input Box",
181 This is an example of an InputBox.
183 Note that the InputBox text can span multiple
190 addButton("&Close Window", (width - 14) / 2, height - 4,
192 application.closeWindow(this);
200 class DemoMainWindow
extends TWindow
{
202 // Timer that increments a number
203 private TTimer timer;
205 // The modal window is a more low-level example of controlling a window
206 // "from the outside". Most windows will probably subclass TWindow and
207 // do this kind of logic on their own.
208 private TWindow modalWindow;
209 private void openModalWindow() {
210 modalWindow = application.addWindow("Demo Modal Window", 0, 0,
211 58, 15, TWindow.Flag.MODAL);
212 modalWindow.addLabel("This is an example of a very braindead modal window.", 1, 1);
213 modalWindow.addLabel("Modal windows are centered by default.", 1, 2);
214 modalWindow.addButton("&Close", (modalWindow.width - 8)/2,
215 modalWindow.height - 4, &modalWindowClose);
217 private void modalWindowClose() {
218 application.closeWindow(modalWindow);
221 /// We need to override onClose so that the timer will no longer be
222 /// called after we close the window. TTimers currently are completely
223 /// unaware of the rest of the UI classes.
224 override public void onClose() {
225 application.removeTimer(timer);
230 * Construct demo window. It will be centered on screen.
232 public DemoMainWindow(TApplication parent
) {
233 this(parent
, CENTERED
| RESIZABLE
);
239 private DemoMainWindow(TApplication parent
, int flags
) {
240 // Construct a demo window. X and Y don't matter because it will be
241 // centered on screen.
242 super(parent
, "Demo Window", 0, 0, 60, 23, flags
);
248 addLabel("Message Boxes", 1, row
);
249 addButton("&MessageBoxes", 35, row
,
252 new DemoMsgBoxWindow(getApplication());
259 addLabel("Open me as modal", 1, row
);
260 addButton("W&indow", 35, row
,
263 new DemoMainWindow(getApplication(), MODAL
);
271 addLabel("Variable-width text field:", 1, row);
272 addField(35, row++, 15, false, "Field text");
274 addLabel("Fixed-width text field:", 1, row);
275 addField(35, row, 15, true);
280 addLabel("Radio buttons and checkboxes", 1, row
);
281 addButton("&Checkboxes", 35, row
,
284 new DemoCheckboxWindow(getApplication(), MODAL
);
293 addLabel("Editor window", 1, row);
294 addButton("Edito&r", 35, row,
296 new TEditor(application, 0, 0, 60, 15);
303 addLabel("Text areas", 1, row);
304 addButton("&Text", 35, row,
306 new DemoTextWindow(application);
313 addLabel("Tree views", 1, row);
314 addButton("Tree&View", 35, row,
316 new DemoTreeViewWindow(application);
323 addLabel("Terminal", 1, row);
324 addButton("Termi&nal", 35, row,
326 application.openTerminal(0, 0);
332 TProgressBar bar = addProgressBar(1, row, 22);
334 TLabel timerLabel = addLabel("Timer", 1, row);
335 timer = parent.addTimer(100,
338 auto writer = appender!dstring();
339 formattedWrite(writer, "Timer: %d", i);
340 timerLabel.text = writer.data;
341 timerLabel.width = cast(uint)timerLabel.text.length;
346 parent.repaint = true;
353 * The demo application itself.
355 class DemoApplication
extends TApplication
{
359 public DemoApplication() throws Exception
{
361 new DemoMainWindow(this);
367 TMenu demoMenu
= addMenu("&Demo");
368 TMenuItem item
= demoMenu
.addItem(2000, "&Checkable");
369 item
.setCheckable(true);
370 item
= demoMenu
.addItem(2001, "Disabled");
371 item
.setEnabled(false);
372 item
= demoMenu
.addItem(2002, "&Normal");
373 TSubMenu subMenu
= demoMenu
.addSubMenu("Sub-&Menu");
374 item
= demoMenu
.addItem(2010, "N&ormal A&&D");
376 item
= subMenu
.addItem(2000, "&Checkable (sub)");
377 item
.setCheckable(true);
378 item
= subMenu
.addItem(2001, "Disabled (sub)");
379 item
.setEnabled(false);
380 item
= subMenu
.addItem(2002, "&Normal (sub)");
382 subMenu
= subMenu
.addSubMenu("Sub-&Menu");
383 item
= subMenu
.addItem(2000, "&Checkable (sub)");
384 item
.setCheckable(true);
385 item
= subMenu
.addItem(2001, "Disabled (sub)");
386 item
.setEnabled(false);
387 item
= subMenu
.addItem(2002, "&Normal (sub)");
395 * This class provides a simple demonstration of Jexer's capabilities.
401 * @param args Command line arguments
403 public static void main(String
[] args
) {
405 DemoApplication app
= new DemoApplication();
407 } catch (Exception e
) {