Commit | Line | Data |
---|---|---|
e3dfbd23 KL |
1 | /* |
2 | * Jexer - Java Text User Interface | |
3 | * | |
e16dda65 | 4 | * The MIT License (MIT) |
e3dfbd23 | 5 | * |
a2018e99 | 6 | * Copyright (C) 2017 Kevin Lamonte |
e3dfbd23 | 7 | * |
e16dda65 KL |
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: | |
e3dfbd23 | 14 | * |
e16dda65 KL |
15 | * The above copyright notice and this permission notice shall be included in |
16 | * all copies or substantial portions of the Software. | |
e3dfbd23 | 17 | * |
e16dda65 KL |
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. | |
e3dfbd23 KL |
25 | * |
26 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] | |
27 | * @version 1 | |
28 | */ | |
29 | package jexer.demos; | |
30 | ||
31 | import jexer.*; | |
2ce6dab2 KL |
32 | import static jexer.TCommand.*; |
33 | import static jexer.TKeypress.*; | |
e3dfbd23 KL |
34 | |
35 | /** | |
36 | * This is the main "demo" application window. It makes use of the TTimer, | |
37 | * TProgressBox, TLabel, TButton, and TField widgets. | |
38 | */ | |
7668cb45 | 39 | public class DemoMainWindow extends TWindow { |
e3dfbd23 KL |
40 | |
41 | // Timer that increments a number. | |
42 | private TTimer timer; | |
43 | ||
44 | // Timer label is updated with timer ticks. | |
45 | TLabel timerLabel; | |
46 | ||
47 | /** | |
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. | |
51 | */ | |
52 | @Override | |
53 | public void onClose() { | |
54 | getApplication().removeTimer(timer); | |
55 | } | |
56 | ||
57 | /** | |
58 | * Construct demo window. It will be centered on screen. | |
59 | * | |
60 | * @param parent the main application | |
61 | */ | |
62 | public DemoMainWindow(final TApplication parent) { | |
63 | this(parent, CENTERED | RESIZABLE); | |
64 | } | |
65 | ||
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. | |
68 | int timerI = 0; | |
69 | TProgressBar progressBar; | |
70 | ||
71 | /** | |
72 | * Constructor. | |
73 | * | |
74 | * @param parent the main application | |
75 | * @param flags bitmask of MODAL, CENTERED, or RESIZABLE | |
76 | */ | |
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. | |
71a389c9 | 80 | super(parent, "Demo Window", 0, 0, 64, 23, flags); |
e3dfbd23 KL |
81 | |
82 | int row = 1; | |
83 | ||
84 | // Add some widgets | |
2ce6dab2 KL |
85 | addLabel("Message Boxes", 1, row); |
86 | addButton("&MessageBoxes", 35, row, | |
87 | new TAction() { | |
88 | public void DO() { | |
89 | new DemoMsgBoxWindow(getApplication()); | |
e3dfbd23 | 90 | } |
2ce6dab2 KL |
91 | } |
92 | ); | |
e3dfbd23 KL |
93 | row += 2; |
94 | ||
95 | addLabel("Open me as modal", 1, row); | |
96 | addButton("W&indow", 35, row, | |
97 | new TAction() { | |
98 | public void DO() { | |
99 | new DemoMainWindow(getApplication(), MODAL); | |
100 | } | |
101 | } | |
102 | ); | |
e3dfbd23 KL |
103 | row += 2; |
104 | ||
2ce6dab2 KL |
105 | addLabel("Text fields", 1, row); |
106 | addButton("Field&s", 35, row, | |
107 | new TAction() { | |
108 | public void DO() { | |
109 | new DemoTextFieldWindow(getApplication()); | |
110 | } | |
111 | } | |
112 | ); | |
113 | row += 2; | |
e3dfbd23 | 114 | |
2ce6dab2 KL |
115 | addLabel("Radio buttons and checkboxes", 1, row); |
116 | addButton("&Checkboxes", 35, row, | |
117 | new TAction() { | |
118 | public void DO() { | |
119 | new DemoCheckboxWindow(getApplication()); | |
e3dfbd23 | 120 | } |
2ce6dab2 KL |
121 | } |
122 | ); | |
e3dfbd23 KL |
123 | row += 2; |
124 | ||
12b55d76 | 125 | addLabel("Editor window", 1, row); |
71a389c9 | 126 | addButton("&1 Widget", 35, row, |
12b55d76 KL |
127 | new TAction() { |
128 | public void DO() { | |
129 | new DemoEditorWindow(getApplication()); | |
e3dfbd23 | 130 | } |
12b55d76 KL |
131 | } |
132 | ); | |
71a389c9 KL |
133 | addButton("&2 Window", 48, row, |
134 | new TAction() { | |
135 | public void DO() { | |
136 | new TEditorWindow(getApplication()); | |
137 | } | |
138 | } | |
139 | ); | |
e3dfbd23 | 140 | row += 2; |
e3dfbd23 | 141 | |
2ce6dab2 KL |
142 | addLabel("Text areas", 1, row); |
143 | addButton("&Text", 35, row, | |
144 | new TAction() { | |
145 | public void DO() { | |
146 | new DemoTextWindow(getApplication()); | |
e3dfbd23 | 147 | } |
2ce6dab2 KL |
148 | } |
149 | ); | |
e3dfbd23 KL |
150 | row += 2; |
151 | ||
2ce6dab2 KL |
152 | addLabel("Tree views", 1, row); |
153 | addButton("Tree&View", 35, row, | |
154 | new TAction() { | |
155 | public void DO() { | |
156 | try { | |
157 | new DemoTreeViewWindow(getApplication()); | |
158 | } catch (Exception e) { | |
159 | e.printStackTrace(); | |
7668cb45 | 160 | } |
e3dfbd23 | 161 | } |
2ce6dab2 KL |
162 | } |
163 | ); | |
e3dfbd23 | 164 | row += 2; |
e3dfbd23 | 165 | |
2ce6dab2 KL |
166 | addLabel("Terminal", 1, row); |
167 | addButton("Termi&nal", 35, row, | |
168 | new TAction() { | |
169 | public void DO() { | |
170 | getApplication().openTerminal(0, 0); | |
e3dfbd23 | 171 | } |
2ce6dab2 KL |
172 | } |
173 | ); | |
e3dfbd23 KL |
174 | row += 2; |
175 | ||
2ce6dab2 KL |
176 | addLabel("Color editor", 1, row); |
177 | addButton("Co&lors", 35, row, | |
178 | new TAction() { | |
179 | public void DO() { | |
180 | new TEditColorThemeWindow(getApplication()); | |
3649b921 | 181 | } |
2ce6dab2 KL |
182 | } |
183 | ); | |
3649b921 KL |
184 | row += 2; |
185 | ||
e3dfbd23 KL |
186 | progressBar = addProgressBar(1, row, 22, 0); |
187 | row++; | |
188 | timerLabel = addLabel("Timer", 1, row); | |
189 | timer = getApplication().addTimer(250, true, | |
190 | new TAction() { | |
191 | ||
192 | public void DO() { | |
193 | timerLabel.setLabel(String.format("Timer: %d", timerI)); | |
194 | timerLabel.setWidth(timerLabel.getLabel().length()); | |
195 | if (timerI < 100) { | |
196 | timerI++; | |
197 | } | |
198 | progressBar.setValue(timerI); | |
199 | } | |
200 | } | |
201 | ); | |
2ce6dab2 KL |
202 | |
203 | statusBar = newStatusBar("Demo Main Window"); | |
204 | statusBar.addShortcutKeypress(kbF1, cmHelp, "Help"); | |
205 | statusBar.addShortcutKeypress(kbF2, cmShell, "Shell"); | |
206 | statusBar.addShortcutKeypress(kbF3, cmOpen, "Open"); | |
207 | statusBar.addShortcutKeypress(kbF10, cmExit, "Exit"); | |
e3dfbd23 KL |
208 | } |
209 | } |