209bd1350ccef2f4a2d7464dcd0d7b2c126d86f2
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]
35 import static jexer
.TCommand
.*;
36 import static jexer
.TKeypress
.*;
39 * This is the main "demo" application window. It makes use of the TTimer,
40 * TProgressBox, TLabel, TButton, and TField widgets.
42 public class DemoMainWindow
extends TWindow
{
44 // Timer that increments a number.
47 // Timer label is updated with timer ticks.
51 * We need to override onClose so that the timer will no longer be called
52 * after we close the window. TTimers currently are completely unaware
53 * of the rest of the UI classes.
56 public void onClose() {
57 getApplication().removeTimer(timer
);
61 * Construct demo window. It will be centered on screen.
63 * @param parent the main application
65 public DemoMainWindow(final TApplication parent
) {
66 this(parent
, CENTERED
| RESIZABLE
);
69 // These are used by the timer loop. They have to be at class scope so
70 // that they can be accessed by the anonymous TAction class.
72 TProgressBar progressBar
;
77 * @param parent the main application
78 * @param flags bitmask of MODAL, CENTERED, or RESIZABLE
80 private DemoMainWindow(final TApplication parent
, final int flags
) {
81 // Construct a demo window. X and Y don't matter because it will be
82 // centered on screen.
83 super(parent
, "Demo Window", 0, 0, 64, 23, flags
);
88 addLabel("Message Boxes", 1, row
);
89 addButton("&MessageBoxes", 35, row
,
92 new DemoMsgBoxWindow(getApplication());
98 addLabel("Open me as modal", 1, row
);
99 addButton("W&indow", 35, row
,
102 new DemoMainWindow(getApplication(), MODAL
);
108 addLabel("Text fields", 1, row
);
109 addButton("Field&s", 35, row
,
112 new DemoTextFieldWindow(getApplication());
118 addLabel("Radio buttons and checkboxes", 1, row
);
119 addButton("&Checkboxes", 35, row
,
122 new DemoCheckboxWindow(getApplication());
128 addLabel("Editor window", 1, row
);
129 addButton("&1 Widget", 35, row
,
132 new DemoEditorWindow(getApplication());
136 addButton("&2 Window", 48, row
,
139 new TEditorWindow(getApplication());
145 addLabel("Text areas", 1, row
);
146 addButton("&Text", 35, row
,
149 new DemoTextWindow(getApplication());
155 addLabel("Tree views", 1, row
);
156 addButton("Tree&View", 35, row
,
160 new DemoTreeViewWindow(getApplication());
161 } catch (Exception e
) {
169 addLabel("Terminal", 1, row
);
170 addButton("Termi&nal", 35, row
,
173 getApplication().openTerminal(0, 0);
179 addLabel("Color editor", 1, row
);
180 addButton("Co&lors", 35, row
,
183 new TEditColorThemeWindow(getApplication());
189 progressBar
= addProgressBar(1, row
, 22, 0);
191 timerLabel
= addLabel("Timer", 1, row
);
192 timer
= getApplication().addTimer(250, true,
196 timerLabel
.setLabel(String
.format("Timer: %d", timerI
));
197 timerLabel
.setWidth(timerLabel
.getLabel().length());
201 timer
.setRecurring(false);
203 progressBar
.setValue(timerI
);
208 statusBar
= newStatusBar("Demo Main Window");
209 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, "Help");
210 statusBar
.addShortcutKeypress(kbF2
, cmShell
, "Shell");
211 statusBar
.addShortcutKeypress(kbF3
, cmOpen
, "Open");
212 statusBar
.addShortcutKeypress(kbF10
, cmExit
, "Exit");
216 * Method that subclasses can override to handle posted command events.
218 * @param command command event
221 public void onCommand(final TCommandEvent command
) {
222 if (command
.equals(cmOpen
)) {
224 String filename
= fileOpenBox(".");
225 if (filename
!= null) {
227 new TEditorWindow(getApplication(), new File(filename
));
228 } catch (IOException e
) {
229 messageBox("Error", "Error reading file: " +
233 } catch (IOException e
) {
234 messageBox("Error", "Error opening file dialog: " +
240 // Didn't handle it, let children get it instead
241 super.onCommand(command
);