598ac7f0ce92f889d56a78a6b42d7f41675dad02
2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 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]
32 import static jexer
.TCommand
.*;
33 import static jexer
.TKeypress
.*;
36 * This is the main "demo" application window. It makes use of the TTimer,
37 * TProgressBox, TLabel, TButton, and TField widgets.
39 public class DemoMainWindow
extends TWindow
{
41 // Timer that increments a number.
44 // Timer label is updated with timer ticks.
48 * We need to override onClose so that the timer will no longer be called
49 * after we close the window. TTimers currently are completely unaware
50 * of the rest of the UI classes.
53 public void onClose() {
54 getApplication().removeTimer(timer
);
58 * Construct demo window. It will be centered on screen.
60 * @param parent the main application
62 public DemoMainWindow(final TApplication parent
) {
63 this(parent
, CENTERED
| RESIZABLE
);
66 // These are used by the timer loop. They have to be at class scope so
67 // that they can be accessed by the anonymous TAction class.
69 TProgressBar progressBar
;
74 * @param parent the main application
75 * @param flags bitmask of MODAL, CENTERED, or RESIZABLE
77 private DemoMainWindow(final TApplication parent
, final int flags
) {
78 // Construct a demo window. X and Y don't matter because it will be
79 // centered on screen.
80 super(parent
, "Demo Window", 0, 0, 60, 23, flags
);
85 addLabel("Message Boxes", 1, row
);
86 addButton("&MessageBoxes", 35, row
,
89 new DemoMsgBoxWindow(getApplication());
95 addLabel("Open me as modal", 1, row
);
96 addButton("W&indow", 35, row
,
99 new DemoMainWindow(getApplication(), MODAL
);
105 addLabel("Text fields", 1, row
);
106 addButton("Field&s", 35, row
,
109 new DemoTextFieldWindow(getApplication());
115 addLabel("Radio buttons and checkboxes", 1, row
);
116 addButton("&Checkboxes", 35, row
,
119 new DemoCheckboxWindow(getApplication());
125 addLabel("Editor window", 1, row
);
126 addButton("Edito&r", 35, row
,
129 new DemoEditorWindow(getApplication());
135 addLabel("Text areas", 1, row
);
136 addButton("&Text", 35, row
,
139 new DemoTextWindow(getApplication());
145 addLabel("Tree views", 1, row
);
146 addButton("Tree&View", 35, row
,
150 new DemoTreeViewWindow(getApplication());
151 } catch (Exception e
) {
159 addLabel("Terminal", 1, row
);
160 addButton("Termi&nal", 35, row
,
163 getApplication().openTerminal(0, 0);
169 addLabel("Color editor", 1, row
);
170 addButton("Co&lors", 35, row
,
173 new TEditColorThemeWindow(getApplication());
179 progressBar
= addProgressBar(1, row
, 22, 0);
181 timerLabel
= addLabel("Timer", 1, row
);
182 timer
= getApplication().addTimer(250, true,
186 timerLabel
.setLabel(String
.format("Timer: %d", timerI
));
187 timerLabel
.setWidth(timerLabel
.getLabel().length());
191 progressBar
.setValue(timerI
);
196 statusBar
= newStatusBar("Demo Main Window");
197 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, "Help");
198 statusBar
.addShortcutKeypress(kbF2
, cmShell
, "Shell");
199 statusBar
.addShortcutKeypress(kbF3
, cmOpen
, "Open");
200 statusBar
.addShortcutKeypress(kbF10
, cmExit
, "Exit");