2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
38 * This is the main "demo" application window. It makes use of the TTimer,
39 * TProgressBox, TLabel, TButton, and TField widgets.
41 public class DemoMainWindow
extends TWindow
{
43 // Timer that increments a number.
46 // Timer label is updated with timer ticks.
50 * We need to override onClose so that the timer will no longer be called
51 * after we close the window. TTimers currently are completely unaware
52 * of the rest of the UI classes.
55 public void onClose() {
56 getApplication().removeTimer(timer
);
60 * Construct demo window. It will be centered on screen.
62 * @param parent the main application
64 public DemoMainWindow(final TApplication parent
) {
65 this(parent
, CENTERED
| RESIZABLE
);
68 // These are used by the timer loop. They have to be at class scope so
69 // that they can be accessed by the anonymous TAction class.
71 TProgressBar progressBar
;
76 * @param parent the main application
77 * @param flags bitmask of MODAL, CENTERED, or RESIZABLE
79 private DemoMainWindow(final TApplication parent
, final int flags
) {
80 // Construct a demo window. X and Y don't matter because it will be
81 // centered on screen.
82 super(parent
, "Demo Window", 0, 0, 60, 23, flags
);
88 addLabel("Message Boxes", 1, row
);
89 addButton("&MessageBoxes", 35, row
,
92 new DemoMsgBoxWindow(getApplication());
99 addLabel("Open me as modal", 1, row
);
100 addButton("W&indow", 35, row
,
103 new DemoMainWindow(getApplication(), MODAL
);
110 addLabel("Variable-width text field:", 1, row
);
111 addField(35, row
++, 15, false, "Field text");
112 addLabel("Fixed-width text field:", 1, row
);
113 addField(35, row
++, 15, true);
114 addLabel("Variable-width password:", 1, row
);
115 addPasswordField(35, row
++, 15, false);
116 addLabel("Fixed-width password:", 1, row
);
117 addPasswordField(35, row
++, 15, true, "hunter2");
121 addLabel("Radio buttons and checkboxes", 1, row
);
122 addButton("&Checkboxes", 35, row
,
125 new DemoCheckboxWindow(getApplication());
134 addLabel("Editor window", 1, row);
135 addButton("Edito&r", 35, row,
137 new TEditor(application, 0, 0, 60, 15);
145 addLabel("Text areas", 1, row
);
146 addButton("&Text", 35, row
,
149 new DemoTextWindow(getApplication());
157 addLabel("Tree views", 1, row
);
158 addButton("Tree&View", 35, row
,
161 new DemoTreeViewWindow(getApplication());
169 addLabel("Terminal", 1, row
);
170 addButton("Termi&nal", 35, row
,
173 getApplication().openTerminal(0, 0);
180 progressBar
= addProgressBar(1, row
, 22, 0);
182 timerLabel
= addLabel("Timer", 1, row
);
183 timer
= getApplication().addTimer(250, true,
187 timerLabel
.setLabel(String
.format("Timer: %d", timerI
));
188 timerLabel
.setWidth(timerLabel
.getLabel().length());
192 progressBar
.setValue(timerI
);