checkbox working
[fanfix.git] / demos / Demo1.java
CommitLineData
7d4115a5
KL
1/**
2 * Jexer - Java Text User Interface - demonstration program
3 *
4 * Version: $Id$
5 *
6 * Author: Kevin Lamonte, <a href="mailto:kevin.lamonte@gmail.com">kevin.lamonte@gmail.com</a>
7 *
8 * License: LGPLv3 or later
9 *
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
13 * License Version 3.
14 *
15 * Copyright (C) 2015 Kevin Lamonte
16 *
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.
21 *
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.
26 *
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
31 * 02110-1301 USA
32 */
2420f903 33
a06459bd 34import jexer.*;
8e688b92 35import jexer.menu.*;
a06459bd 36
7272e49f
KL
37class DemoCheckboxWindow extends TWindow {
38
39 /**
40 * Constructor
41 */
42 DemoCheckboxWindow(TApplication parent) {
43 this(parent, CENTERED | RESIZABLE);
44 }
45
46 /**
47 * Constructor
48 */
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);
53
54 int row = 1;
55
56 // Add some widgets
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);
61 row += 2;
62
63 /*
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");
68
69 addButton("&Close Window", (width - 14) / 2, height - 4,
70 {
71 application.closeWindow(this);
72 }
73
74 );
75 */
76 }
77
78}
79
80
30d336cc
KL
81class DemoMsgBoxWindow extends TWindow {
82 /*
83 private void openYNCMessageBox() {
7272e49f
KL
84 application.messageBox("Yes/No/Cancel MessageBox",
85 q"EOS
30d336cc
KL
86This is an example of a Yes/No/Cancel MessageBox.
87
88Note that the MessageBox text can span multiple
89lines.
90
91The default result (if someone hits the top-left
92close button) is CANCEL.
93EOS",
7272e49f 94 TMessageBox.Type.YESNOCANCEL);
30d336cc
KL
95 }
96
97 private void openYNMessageBox() {
7272e49f
KL
98 application.messageBox("Yes/No MessageBox",
99 q"EOS
30d336cc
KL
100This is an example of a Yes/No MessageBox.
101
102Note that the MessageBox text can span multiple
103lines.
104
105The default result (if someone hits the top-left
106close button) is NO.
107EOS",
7272e49f 108 TMessageBox.Type.YESNO);
30d336cc
KL
109 }
110
111 private void openOKCMessageBox() {
7272e49f
KL
112 application.messageBox("OK/Cancel MessageBox",
113 q"EOS
30d336cc
KL
114This is an example of a OK/Cancel MessageBox.
115
116Note that the MessageBox text can span multiple
117lines.
118
119The default result (if someone hits the top-left
120close button) is CANCEL.
121EOS",
7272e49f 122 TMessageBox.Type.OKCANCEL);
30d336cc
KL
123 }
124
125 private void openOKMessageBox() {
7272e49f
KL
126 application.messageBox("OK MessageBox",
127 q"EOS
30d336cc
KL
128This is an example of a OK MessageBox. This is the
129default MessageBox.
130
131Note that the MessageBox text can span multiple
132lines.
133
134The default result (if someone hits the top-left
135close button) is OK.
136EOS",
7272e49f 137 TMessageBox.Type.OK);
30d336cc
KL
138 }
139
140 */
141
142 /**
143 * Constructor.
144 */
145 DemoMsgBoxWindow(final TApplication parent) {
7272e49f 146 this(parent, TWindow.CENTERED | TWindow.RESIZABLE);
30d336cc
KL
147 }
148
149 /**
150 * Constructor.
151 */
152 DemoMsgBoxWindow(final TApplication parent, final int flags) {
7272e49f
KL
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);
30d336cc 156 /*
7272e49f
KL
157 uint row = 1;
158
159 // Add some widgets
160 addLabel("Default OK message box", 1, row);
161 addButton("Open O&K MB", 35, row, &openOKMessageBox);
162 row += 2;
163
164 addLabel("OK/Cancel message box", 1, row);
165 addButton("O&pen OKC MB", 35, row, &openOKCMessageBox);
166 row += 2;
167
168 addLabel("Yes/No message box", 1, row);
169 addButton("Open &YN MB", 35, row, &openYNMessageBox);
170 row += 2;
171
172 addLabel("Yes/No/Cancel message box", 1, row);
173 addButton("Ope&n YNC MB", 35, row, &openYNCMessageBox);
174 row += 2;
175
176 addLabel("Input box", 1, row);
177 addButton("Open &input box", 35, row,
178 {
179 application.inputBox("Input Box",
180 q"EOS
30d336cc
KL
181This is an example of an InputBox.
182
183Note that the InputBox text can span multiple
184lines.
185EOS",
7272e49f
KL
186 "some input text");
187 }
188 );
189
190 addButton("&Close Window", (width - 14) / 2, height - 4,
191 {
192 application.closeWindow(this);
193 }
194 );
30d336cc
KL
195 */
196 }
197}
198
199
a06459bd
KL
200class DemoMainWindow extends TWindow {
201 /*
202 // Timer that increments a number
203 private TTimer timer;
204
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() {
8e688b92
KL
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);
a06459bd
KL
216 }
217 private void modalWindowClose() {
8e688b92 218 application.closeWindow(modalWindow);
a06459bd
KL
219 }
220
a06459bd
KL
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() {
8e688b92 225 application.removeTimer(timer);
a06459bd
KL
226 }
227 */
228
fca67db0
KL
229 /**
230 * Construct demo window. It will be centered on screen.
231 */
a06459bd 232 public DemoMainWindow(TApplication parent) {
8e688b92 233 this(parent, CENTERED | RESIZABLE);
a06459bd
KL
234 }
235
fca67db0
KL
236 /**
237 * Constructor.
238 */
239 private DemoMainWindow(TApplication parent, int flags) {
8e688b92
KL
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);
a06459bd 243
8e688b92
KL
244 int row = 1;
245
246 // Add some widgets
30d336cc 247 if (!isModal()) {
8e688b92
KL
248 addLabel("Message Boxes", 1, row);
249 addButton("&MessageBoxes", 35, row,
30d336cc
KL
250 new TAction() {
251 public void DO() {
252 new DemoMsgBoxWindow(getApplication());
253 }
8e688b92
KL
254 }
255 );
256 }
257 row += 2;
258
259 addLabel("Open me as modal", 1, row);
260 addButton("W&indow", 35, row,
7272e49f
KL
261 new TAction() {
262 public void DO() {
263 new DemoMainWindow(getApplication(), MODAL);
264 }
8e688b92
KL
265 }
266 );
267
268 row += 2;
269
7272e49f 270 /*
8e688b92
KL
271 addLabel("Variable-width text field:", 1, row);
272 addField(35, row++, 15, false, "Field text");
273
274 addLabel("Fixed-width text field:", 1, row);
275 addField(35, row, 15, true);
276 row += 2;
7272e49f 277 */
8e688b92 278
7272e49f 279 if (!isModal()) {
8e688b92 280 addLabel("Radio buttons and checkboxes", 1, row);
7272e49f
KL
281 addButton("&Checkboxes", 35, row,
282 new TAction() {
283 public void DO() {
284 new DemoCheckboxWindow(getApplication(), MODAL);
285 }
286 }
287 );
8e688b92
KL
288 }
289 row += 2;
290
7272e49f
KL
291 /*
292 if (!isModal()) {
8e688b92
KL
293 addLabel("Editor window", 1, row);
294 addButton("Edito&r", 35, row,
295 {
296 new TEditor(application, 0, 0, 60, 15);
297 }
298 );
299 }
300 row += 2;
301
7272e49f 302 if (!isModal()) {
8e688b92
KL
303 addLabel("Text areas", 1, row);
304 addButton("&Text", 35, row,
305 {
306 new DemoTextWindow(application);
307 }
308 );
309 }
310 row += 2;
311
7272e49f 312 if (!isModal()) {
8e688b92
KL
313 addLabel("Tree views", 1, row);
314 addButton("Tree&View", 35, row,
315 {
316 new DemoTreeViewWindow(application);
317 }
318 );
319 }
320 row += 2;
321
7272e49f
KL
322 if (!isModal()) {
323 addLabel("Terminal", 1, row);
324 addButton("Termi&nal", 35, row,
325 {
326 application.openTerminal(0, 0);
327 }
328 );
8e688b92 329 }
7272e49f 330 row += 2;
8e688b92
KL
331
332 TProgressBar bar = addProgressBar(1, row, 22);
333 row++;
334 TLabel timerLabel = addLabel("Timer", 1, row);
335 timer = parent.addTimer(100,
336 {
337 static int i = 0;
338 auto writer = appender!dstring();
339 formattedWrite(writer, "Timer: %d", i);
340 timerLabel.text = writer.data;
341 timerLabel.width = cast(uint)timerLabel.text.length;
342 if (i < 100) {
343 i++;
344 }
345 bar.value = i;
346 parent.repaint = true;
347 }, true);
a06459bd
KL
348 */
349 }
350}
7d4115a5
KL
351
352/**
353 * The demo application itself.
354 */
355class DemoApplication extends TApplication {
2420f903
KL
356 /**
357 * Public constructor
358 */
4328bb42 359 public DemoApplication() throws Exception {
8e688b92
KL
360 super(null, null);
361 new DemoMainWindow(this);
362
8e688b92
KL
363 // Add the menus
364 addFileMenu();
365 addEditMenu();
366
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");
375
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)");
381
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)");
388
389 addWindowMenu();
390
2420f903 391 }
7d4115a5
KL
392}
393
394/**
395 * This class provides a simple demonstration of Jexer's capabilities.
396 */
397public class Demo1 {
398 /**
399 * Main entry point.
400 *
401 * @param args Command line arguments
402 */
403 public static void main(String [] args) {
8e688b92
KL
404 try {
405 DemoApplication app = new DemoApplication();
406 app.run();
407 } catch (Exception e) {
408 e.printStackTrace();
409 }
7d4115a5
KL
410 }
411
412}