5d74d7df94ae7198d83760572edb358c32201eb3
2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2016 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
34 * This is the main "demo" application window. It makes use of the TTimer,
35 * TProgressBox, TLabel, TButton, and TField widgets.
37 public class DemoMainWindow
extends TWindow
{
39 // Timer that increments a number.
42 // Timer label is updated with timer ticks.
46 * We need to override onClose so that the timer will no longer be called
47 * after we close the window. TTimers currently are completely unaware
48 * of the rest of the UI classes.
51 public void onClose() {
52 getApplication().removeTimer(timer
);
56 * Construct demo window. It will be centered on screen.
58 * @param parent the main application
60 public DemoMainWindow(final TApplication parent
) {
61 this(parent
, CENTERED
| RESIZABLE
);
64 // These are used by the timer loop. They have to be at class scope so
65 // that they can be accessed by the anonymous TAction class.
67 TProgressBar progressBar
;
72 * @param parent the main application
73 * @param flags bitmask of MODAL, CENTERED, or RESIZABLE
75 private DemoMainWindow(final TApplication parent
, final int flags
) {
76 // Construct a demo window. X and Y don't matter because it will be
77 // centered on screen.
78 super(parent
, "Demo Window", 0, 0, 60, 24, flags
);
84 addLabel("Message Boxes", 1, row
);
85 addButton("&MessageBoxes", 35, row
,
88 new DemoMsgBoxWindow(getApplication());
95 addLabel("Open me as modal", 1, row
);
96 addButton("W&indow", 35, row
,
99 new DemoMainWindow(getApplication(), MODAL
);
106 addLabel("Variable-width text field:", 1, row
);
107 addField(35, row
++, 15, false, "Field text");
108 addLabel("Fixed-width text field:", 1, row
);
109 addField(35, row
++, 15, true);
110 addLabel("Variable-width password:", 1, row
);
111 addPasswordField(35, row
++, 15, false);
112 addLabel("Fixed-width password:", 1, row
);
113 addPasswordField(35, row
++, 15, true, "hunter2");
117 addLabel("Radio buttons and checkboxes", 1, row
);
118 addButton("&Checkboxes", 35, row
,
121 new DemoCheckboxWindow(getApplication());
130 addLabel("Editor window", 1, row);
131 addButton("Edito&r", 35, row,
133 new TEditor(application, 0, 0, 60, 15);
141 addLabel("Text areas", 1, row
);
142 addButton("&Text", 35, row
,
145 new DemoTextWindow(getApplication());
153 addLabel("Tree views", 1, row
);
154 addButton("Tree&View", 35, row
,
158 new DemoTreeViewWindow(getApplication());
159 } catch (Exception e
) {
169 addLabel("Terminal", 1, row
);
170 addButton("Termi&nal", 35, row
,
173 getApplication().openTerminal(0, 0);
181 addLabel("Color editor", 1, row
);
182 addButton("Co&lors", 35, row
,
185 new TEditColorThemeWindow(getApplication());
192 progressBar
= addProgressBar(1, row
, 22, 0);
194 timerLabel
= addLabel("Timer", 1, row
);
195 timer
= getApplication().addTimer(250, true,
199 timerLabel
.setLabel(String
.format("Timer: %d", timerI
));
200 timerLabel
.setWidth(timerLabel
.getLabel().length());
204 progressBar
.setValue(timerI
);