Commit | Line | Data |
---|---|---|
e3dfbd23 KL |
1 | /* |
2 | * Jexer - Java Text User Interface | |
3 | * | |
4 | * License: LGPLv3 or later | |
5 | * | |
6 | * This module is licensed under the GNU Lesser General Public License | |
7 | * Version 3. Please see the file "COPYING" in this directory for more | |
8 | * information about the GNU Lesser General Public License Version 3. | |
9 | * | |
10 | * Copyright (C) 2015 Kevin Lamonte | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or | |
13 | * modify it under the terms of the GNU Lesser General Public License | |
14 | * as published by the Free Software Foundation; either version 3 of | |
15 | * the License, or (at your option) any later version. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, but | |
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | * General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU Lesser General Public | |
23 | * License along with this program; if not, see | |
24 | * http://www.gnu.org/licenses/, or write to the Free Software | |
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
26 | * 02110-1301 USA | |
27 | * | |
28 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] | |
29 | * @version 1 | |
30 | */ | |
31 | package jexer.demos; | |
32 | ||
33 | import jexer.*; | |
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. | |
3649b921 | 80 | super(parent, "Demo Window", 0, 0, 60, 24, flags); |
e3dfbd23 KL |
81 | |
82 | int row = 1; | |
83 | ||
84 | // Add some widgets | |
85 | if (!isModal()) { | |
86 | addLabel("Message Boxes", 1, row); | |
87 | addButton("&MessageBoxes", 35, row, | |
88 | new TAction() { | |
89 | public void DO() { | |
90 | new DemoMsgBoxWindow(getApplication()); | |
91 | } | |
92 | } | |
93 | ); | |
94 | } | |
95 | row += 2; | |
96 | ||
97 | addLabel("Open me as modal", 1, row); | |
98 | addButton("W&indow", 35, row, | |
99 | new TAction() { | |
100 | public void DO() { | |
101 | new DemoMainWindow(getApplication(), MODAL); | |
102 | } | |
103 | } | |
104 | ); | |
105 | ||
106 | row += 2; | |
107 | ||
108 | addLabel("Variable-width text field:", 1, row); | |
109 | addField(35, row++, 15, false, "Field text"); | |
110 | addLabel("Fixed-width text field:", 1, row); | |
111 | addField(35, row++, 15, true); | |
112 | addLabel("Variable-width password:", 1, row); | |
113 | addPasswordField(35, row++, 15, false); | |
114 | addLabel("Fixed-width password:", 1, row); | |
115 | addPasswordField(35, row++, 15, true, "hunter2"); | |
3649b921 | 116 | row += 1; |
e3dfbd23 KL |
117 | |
118 | if (!isModal()) { | |
119 | addLabel("Radio buttons and checkboxes", 1, row); | |
120 | addButton("&Checkboxes", 35, row, | |
121 | new TAction() { | |
122 | public void DO() { | |
123 | new DemoCheckboxWindow(getApplication()); | |
124 | } | |
125 | } | |
126 | ); | |
127 | } | |
128 | row += 2; | |
129 | ||
130 | /* | |
131 | if (!isModal()) { | |
132 | addLabel("Editor window", 1, row); | |
133 | addButton("Edito&r", 35, row, | |
134 | { | |
135 | new TEditor(application, 0, 0, 60, 15); | |
136 | } | |
137 | ); | |
138 | } | |
139 | row += 2; | |
140 | */ | |
141 | ||
142 | if (!isModal()) { | |
143 | addLabel("Text areas", 1, row); | |
144 | addButton("&Text", 35, row, | |
145 | new TAction() { | |
146 | public void DO() { | |
147 | new DemoTextWindow(getApplication()); | |
148 | } | |
149 | } | |
150 | ); | |
151 | } | |
152 | row += 2; | |
153 | ||
e3dfbd23 KL |
154 | if (!isModal()) { |
155 | addLabel("Tree views", 1, row); | |
156 | addButton("Tree&View", 35, row, | |
7668cb45 KL |
157 | new TAction() { |
158 | public void DO() { | |
0d47c546 KL |
159 | try { |
160 | new DemoTreeViewWindow(getApplication()); | |
161 | } catch (Exception e) { | |
162 | e.printStackTrace(); | |
163 | } | |
7668cb45 | 164 | } |
e3dfbd23 KL |
165 | } |
166 | ); | |
167 | } | |
168 | row += 2; | |
e3dfbd23 KL |
169 | |
170 | if (!isModal()) { | |
171 | addLabel("Terminal", 1, row); | |
172 | addButton("Termi&nal", 35, row, | |
173 | new TAction() { | |
174 | public void DO() { | |
175 | getApplication().openTerminal(0, 0); | |
176 | } | |
177 | } | |
178 | ); | |
179 | } | |
180 | row += 2; | |
181 | ||
3649b921 KL |
182 | if (!isModal()) { |
183 | addLabel("Color editor", 1, row); | |
184 | addButton("Co&lors", 35, row, | |
185 | new TAction() { | |
186 | public void DO() { | |
187 | new TEditColorThemeWindow(getApplication()); | |
188 | } | |
189 | } | |
190 | ); | |
191 | } | |
192 | row += 2; | |
193 | ||
e3dfbd23 KL |
194 | progressBar = addProgressBar(1, row, 22, 0); |
195 | row++; | |
196 | timerLabel = addLabel("Timer", 1, row); | |
197 | timer = getApplication().addTimer(250, true, | |
198 | new TAction() { | |
199 | ||
200 | public void DO() { | |
201 | timerLabel.setLabel(String.format("Timer: %d", timerI)); | |
202 | timerLabel.setWidth(timerLabel.getLabel().length()); | |
203 | if (timerI < 100) { | |
204 | timerI++; | |
205 | } | |
206 | progressBar.setValue(timerI); | |
207 | } | |
208 | } | |
209 | ); | |
210 | } | |
211 | } |