7735b055b80062cdb5d7a79c98b376315029c271
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);
63 TRadioGroup group
= addRadioGroup(1, row
, "Group 1");
64 group
.addRadioButton("Radio option 1");
65 group
.addRadioButton("Radio option 2");
66 group
.addRadioButton("Radio option 3");
68 addButton("&Close Window", (getWidth() - 14) / 2, getHeight() - 4,
71 DemoCheckboxWindow
.this.getApplication().closeWindow(DemoCheckboxWindow
.this);
80 class DemoMsgBoxWindow
extends TWindow
{
82 private void openYNCMessageBox() {
83 application.messageBox("Yes/No/Cancel MessageBox",
85 This is an example of a Yes/No/Cancel MessageBox.
87 Note that the MessageBox text can span multiple
90 The default result (if someone hits the top-left
91 close button) is CANCEL.
93 TMessageBox.Type.YESNOCANCEL);
96 private void openYNMessageBox() {
97 application.messageBox("Yes/No MessageBox",
99 This is an example of a Yes/No MessageBox.
101 Note that the MessageBox text can span multiple
104 The default result (if someone hits the top-left
107 TMessageBox.Type.YESNO);
110 private void openOKCMessageBox() {
111 application.messageBox("OK/Cancel MessageBox",
113 This is an example of a OK/Cancel MessageBox.
115 Note that the MessageBox text can span multiple
118 The default result (if someone hits the top-left
119 close button) is CANCEL.
121 TMessageBox.Type.OKCANCEL);
124 private void openOKMessageBox() {
125 application.messageBox("OK MessageBox",
127 This is an example of a OK MessageBox. This is the
130 Note that the MessageBox text can span multiple
133 The default result (if someone hits the top-left
136 TMessageBox.Type.OK);
144 DemoMsgBoxWindow(final TApplication parent
) {
145 this(parent
, TWindow
.CENTERED
| TWindow
.RESIZABLE
);
151 DemoMsgBoxWindow(final TApplication parent
, final int flags
) {
152 // Construct a demo window. X and Y don't matter because it
153 // will be centered on screen.
154 super(parent
, "Message Boxes", 0, 0, 60, 15, flags
);
159 addLabel("Default OK message box", 1, row);
160 addButton("Open O&K MB", 35, row, &openOKMessageBox);
163 addLabel("OK/Cancel message box", 1, row);
164 addButton("O&pen OKC MB", 35, row, &openOKCMessageBox);
167 addLabel("Yes/No message box", 1, row);
168 addButton("Open &YN MB", 35, row, &openYNMessageBox);
171 addLabel("Yes/No/Cancel message box", 1, row);
172 addButton("Ope&n YNC MB", 35, row, &openYNCMessageBox);
175 addLabel("Input box", 1, row);
176 addButton("Open &input box", 35, row,
178 application.inputBox("Input Box",
180 This is an example of an InputBox.
182 Note that the InputBox text can span multiple
189 addButton("&Close Window", (width - 14) / 2, height - 4,
191 application.closeWindow(this);
199 class DemoMainWindow
extends TWindow
{
200 // Timer that increments a number
201 private TTimer timer
;
203 // Timer label is updated with timerrr ticks
207 // The modal window is a more low-level example of controlling a window
208 // "from the outside". Most windows will probably subclass TWindow and
209 // do this kind of logic on their own.
210 private TWindow modalWindow;
211 private void openModalWindow() {
212 modalWindow = application.addWindow("Demo Modal Window", 0, 0,
213 58, 15, TWindow.Flag.MODAL);
214 modalWindow.addLabel("This is an example of a very braindead modal window.", 1, 1);
215 modalWindow.addLabel("Modal windows are centered by default.", 1, 2);
216 modalWindow.addButton("&Close", (modalWindow.width - 8)/2,
217 modalWindow.height - 4, &modalWindowClose);
219 private void modalWindowClose() {
220 application.closeWindow(modalWindow);
225 * We need to override onClose so that the timer will no longer be called
226 * after we close the window. TTimers currently are completely unaware
227 * of the rest of the UI classes.
230 public void onClose() {
231 getApplication().removeTimer(timer
);
235 * Construct demo window. It will be centered on screen.
237 public DemoMainWindow(TApplication parent
) {
238 this(parent
, CENTERED
| RESIZABLE
);
242 TProgressBar progressBar
;
247 private DemoMainWindow(TApplication parent
, int flags
) {
248 // Construct a demo window. X and Y don't matter because it will be
249 // centered on screen.
250 super(parent
, "Demo Window", 0, 0, 60, 23, flags
);
256 addLabel("Message Boxes", 1, row
);
257 addButton("&MessageBoxes", 35, row
,
260 new DemoMsgBoxWindow(getApplication());
267 addLabel("Open me as modal", 1, row
);
268 addButton("W&indow", 35, row
,
271 new DemoMainWindow(getApplication(), MODAL
);
278 addLabel("Variable-width text field:", 1, row
);
279 addField(35, row
++, 15, false, "Field text");
281 addLabel("Fixed-width text field:", 1, row
);
282 addField(35, row
, 15, true);
286 addLabel("Radio buttons and checkboxes", 1, row
);
287 addButton("&Checkboxes", 35, row
,
290 new DemoCheckboxWindow(getApplication());
299 addLabel("Editor window", 1, row);
300 addButton("Edito&r", 35, row,
302 new TEditor(application, 0, 0, 60, 15);
309 addLabel("Text areas", 1, row);
310 addButton("&Text", 35, row,
312 new DemoTextWindow(application);
319 addLabel("Tree views", 1, row);
320 addButton("Tree&View", 35, row,
322 new DemoTreeViewWindow(application);
329 addLabel("Terminal", 1, row);
330 addButton("Termi&nal", 35, row,
332 application.openTerminal(0, 0);
339 progressBar
= addProgressBar(1, row
, 22, 0);
341 timerLabel
= addLabel("Timer", 1, row
);
342 timer
= getApplication().addTimer(100, true,
346 timerLabel
.setText(String
.format("Timer: %d", timerI
));
347 timerLabel
.setWidth(timerLabel
.getText().length());
351 progressBar
.setValue(timerI
);
352 DemoMainWindow
.this.setRepaint();
360 * The demo application itself.
362 class DemoApplication
extends TApplication
{
366 public DemoApplication() throws Exception
{
368 new DemoMainWindow(this);
374 TMenu demoMenu
= addMenu("&Demo");
375 TMenuItem item
= demoMenu
.addItem(2000, "&Checkable");
376 item
.setCheckable(true);
377 item
= demoMenu
.addItem(2001, "Disabled");
378 item
.setEnabled(false);
379 item
= demoMenu
.addItem(2002, "&Normal");
380 TSubMenu subMenu
= demoMenu
.addSubMenu("Sub-&Menu");
381 item
= demoMenu
.addItem(2010, "N&ormal A&&D");
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)");
389 subMenu
= subMenu
.addSubMenu("Sub-&Menu");
390 item
= subMenu
.addItem(2000, "&Checkable (sub)");
391 item
.setCheckable(true);
392 item
= subMenu
.addItem(2001, "Disabled (sub)");
393 item
.setEnabled(false);
394 item
= subMenu
.addItem(2002, "&Normal (sub)");
402 * This class provides a simple demonstration of Jexer's capabilities.
408 * @param args Command line arguments
410 public static void main(String
[] args
) {
412 DemoApplication app
= new DemoApplication();
414 } catch (Exception e
) {