db327081100e416db1f6395682ee887cc0d34f48
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
{
201 // Timer that increments a number
202 private TTimer timer
;
204 // Timer label is updated with timerrr ticks
208 // The modal window is a more low-level example of controlling a window
209 // "from the outside". Most windows will probably subclass TWindow and
210 // do this kind of logic on their own.
211 private TWindow modalWindow;
212 private void openModalWindow() {
213 modalWindow = application.addWindow("Demo Modal Window", 0, 0,
214 58, 15, TWindow.Flag.MODAL);
215 modalWindow.addLabel("This is an example of a very braindead modal window.", 1, 1);
216 modalWindow.addLabel("Modal windows are centered by default.", 1, 2);
217 modalWindow.addButton("&Close", (modalWindow.width - 8)/2,
218 modalWindow.height - 4, &modalWindowClose);
220 private void modalWindowClose() {
221 application.closeWindow(modalWindow);
226 * We need to override onClose so that the timer will no longer be called
227 * after we close the window. TTimers currently are completely unaware
228 * of the rest of the UI classes.
231 public void onClose() {
232 getApplication().removeTimer(timer
);
236 * Construct demo window. It will be centered on screen.
238 public DemoMainWindow(TApplication parent
) {
239 this(parent
, CENTERED
| RESIZABLE
);
243 TProgressBar progressBar
;
248 private DemoMainWindow(TApplication parent
, int flags
) {
249 // Construct a demo window. X and Y don't matter because it will be
250 // centered on screen.
251 super(parent
, "Demo Window", 0, 0, 60, 23, flags
);
257 addLabel("Message Boxes", 1, row
);
258 addButton("&MessageBoxes", 35, row
,
261 new DemoMsgBoxWindow(getApplication());
268 addLabel("Open me as modal", 1, row
);
269 addButton("W&indow", 35, row
,
272 new DemoMainWindow(getApplication(), MODAL
);
280 addLabel("Variable-width text field:", 1, row);
281 addField(35, row++, 15, false, "Field text");
283 addLabel("Fixed-width text field:", 1, row);
284 addField(35, row, 15, true);
289 addLabel("Radio buttons and checkboxes", 1, row
);
290 addButton("&Checkboxes", 35, row
,
293 new DemoCheckboxWindow(getApplication());
302 addLabel("Editor window", 1, row);
303 addButton("Edito&r", 35, row,
305 new TEditor(application, 0, 0, 60, 15);
312 addLabel("Text areas", 1, row);
313 addButton("&Text", 35, row,
315 new DemoTextWindow(application);
322 addLabel("Tree views", 1, row);
323 addButton("Tree&View", 35, row,
325 new DemoTreeViewWindow(application);
332 addLabel("Terminal", 1, row);
333 addButton("Termi&nal", 35, row,
335 application.openTerminal(0, 0);
342 progressBar
= addProgressBar(1, row
, 22, 0);
344 timerLabel
= addLabel("Timer", 1, row
);
345 timer
= getApplication().addTimer(100, true,
349 timerLabel
.setText(String
.format("Timer: %d", timerI
));
350 timerLabel
.setWidth(timerLabel
.getText().length());
354 progressBar
.setValue(timerI
);
355 DemoMainWindow
.this.setRepaint();
363 * The demo application itself.
365 class DemoApplication
extends TApplication
{
369 public DemoApplication() throws Exception
{
371 new DemoMainWindow(this);
377 TMenu demoMenu
= addMenu("&Demo");
378 TMenuItem item
= demoMenu
.addItem(2000, "&Checkable");
379 item
.setCheckable(true);
380 item
= demoMenu
.addItem(2001, "Disabled");
381 item
.setEnabled(false);
382 item
= demoMenu
.addItem(2002, "&Normal");
383 TSubMenu subMenu
= demoMenu
.addSubMenu("Sub-&Menu");
384 item
= demoMenu
.addItem(2010, "N&ormal A&&D");
386 item
= subMenu
.addItem(2000, "&Checkable (sub)");
387 item
.setCheckable(true);
388 item
= subMenu
.addItem(2001, "Disabled (sub)");
389 item
.setEnabled(false);
390 item
= subMenu
.addItem(2002, "&Normal (sub)");
392 subMenu
= subMenu
.addSubMenu("Sub-&Menu");
393 item
= subMenu
.addItem(2000, "&Checkable (sub)");
394 item
.setCheckable(true);
395 item
= subMenu
.addItem(2001, "Disabled (sub)");
396 item
.setEnabled(false);
397 item
= subMenu
.addItem(2002, "&Normal (sub)");
405 * This class provides a simple demonstration of Jexer's capabilities.
411 * @param args Command line arguments
413 public static void main(String
[] args
) {
415 DemoApplication app
= new DemoApplication();
417 } catch (Exception e
) {