4c7f631d042ba2f43295e486bfb1afd285709a58
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 DemoMainWindow
extends TWindow
{
39 // Timer that increments a number
42 // The modal window is a more low-level example of controlling a window
43 // "from the outside". Most windows will probably subclass TWindow and
44 // do this kind of logic on their own.
45 private TWindow modalWindow;
46 private void openModalWindow() {
47 modalWindow = application.addWindow("Demo Modal Window", 0, 0,
48 58, 15, TWindow.Flag.MODAL);
49 modalWindow.addLabel("This is an example of a very braindead modal window.", 1, 1);
50 modalWindow.addLabel("Modal windows are centered by default.", 1, 2);
51 modalWindow.addButton("&Close", (modalWindow.width - 8)/2,
52 modalWindow.height - 4, &modalWindowClose);
54 private void modalWindowClose() {
55 application.closeWindow(modalWindow);
58 /// This is an example of having a button call a function.
59 private void openCheckboxWindow() {
60 new DemoCheckboxWindow(application);
63 /// We need to override onClose so that the timer will no longer be
64 /// called after we close the window. TTimers currently are completely
65 /// unaware of the rest of the UI classes.
66 override public void onClose() {
67 application.removeTimer(timer);
72 * Construct demo window. It will be centered on screen.
74 public DemoMainWindow(TApplication parent
) {
75 this(parent
, CENTERED
| RESIZABLE
);
81 private DemoMainWindow(TApplication parent
, int flags
) {
82 // Construct a demo window. X and Y don't matter because it will be
83 // centered on screen.
84 super(parent
, "Demo Window", 0, 0, 60, 23, flags
);
91 addLabel("Message Boxes", 1, row);
92 addButton("&MessageBoxes", 35, row,
94 new DemoMsgBoxWindow(application);
100 addLabel("Open me as modal", 1, row);
101 addButton("W&indow", 35, row,
103 new DemoMainWindow(application, Flag.MODAL);
109 addLabel("Variable-width text field:", 1, row);
110 addField(35, row++, 15, false, "Field text");
112 addLabel("Fixed-width text field:", 1, row);
113 addField(35, row, 15, true);
117 addLabel("Radio buttons and checkboxes", 1, row);
118 addButton("&Checkboxes", 35, row, &openCheckboxWindow);
123 addLabel("Editor window", 1, row);
124 addButton("Edito&r", 35, row,
126 new TEditor(application, 0, 0, 60, 15);
133 addLabel("Text areas", 1, row);
134 addButton("&Text", 35, row,
136 new DemoTextWindow(application);
143 addLabel("Tree views", 1, row);
144 addButton("Tree&View", 35, row,
146 new DemoTreeViewWindow(application);
154 addLabel("Terminal", 1, row);
155 addButton("Termi&nal", 35, row,
157 application.openTerminal(0, 0);
164 TProgressBar bar = addProgressBar(1, row, 22);
166 TLabel timerLabel = addLabel("Timer", 1, row);
167 timer = parent.addTimer(100,
170 auto writer = appender!dstring();
171 formattedWrite(writer, "Timer: %d", i);
172 timerLabel.text = writer.data;
173 timerLabel.width = cast(uint)timerLabel.text.length;
178 parent.repaint = true;
185 * The demo application itself.
187 class DemoApplication
extends TApplication
{
191 public DemoApplication() throws Exception
{
193 new DemoMainWindow(this);
196 TWindow window2
= new DemoMainWindow(this);
197 window2
.setHeight(5);
198 window2
.setWidth(25);
207 TMenu demoMenu
= addMenu("&Demo");
208 TMenuItem item
= demoMenu
.addItem(2000, "&Checkable");
209 item
.setCheckable(true);
210 item
= demoMenu
.addItem(2001, "Disabled");
211 item
.setEnabled(false);
212 item
= demoMenu
.addItem(2002, "&Normal");
213 TSubMenu subMenu
= demoMenu
.addSubMenu("Sub-&Menu");
214 item
= demoMenu
.addItem(2010, "N&ormal A&&D");
216 item
= subMenu
.addItem(2000, "&Checkable (sub)");
217 item
.setCheckable(true);
218 item
= subMenu
.addItem(2001, "Disabled (sub)");
219 item
.setEnabled(false);
220 item
= subMenu
.addItem(2002, "&Normal (sub)");
222 subMenu
= subMenu
.addSubMenu("Sub-&Menu");
223 item
= subMenu
.addItem(2000, "&Checkable (sub)");
224 item
.setCheckable(true);
225 item
= subMenu
.addItem(2001, "Disabled (sub)");
226 item
.setEnabled(false);
227 item
= subMenu
.addItem(2002, "&Normal (sub)");
235 * This class provides a simple demonstration of Jexer's capabilities.
241 * @param args Command line arguments
243 public static void main(String
[] args
) {
245 DemoApplication app
= new DemoApplication();
247 } catch (Exception e
) {