Commit | Line | Data |
---|---|---|
e3dfbd23 KL |
1 | /* |
2 | * Jexer - Java Text User Interface | |
3 | * | |
e16dda65 | 4 | * The MIT License (MIT) |
e3dfbd23 | 5 | * |
e16dda65 | 6 | * Copyright (C) 2016 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.*; | |
e3dfbd23 KL |
32 | |
33 | /** | |
34 | * This is the main "demo" application window. It makes use of the TTimer, | |
35 | * TProgressBox, TLabel, TButton, and TField widgets. | |
36 | */ | |
7668cb45 | 37 | public class DemoMainWindow extends TWindow { |
e3dfbd23 KL |
38 | |
39 | // Timer that increments a number. | |
40 | private TTimer timer; | |
41 | ||
42 | // Timer label is updated with timer ticks. | |
43 | TLabel timerLabel; | |
44 | ||
45 | /** | |
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. | |
49 | */ | |
50 | @Override | |
51 | public void onClose() { | |
52 | getApplication().removeTimer(timer); | |
53 | } | |
54 | ||
55 | /** | |
56 | * Construct demo window. It will be centered on screen. | |
57 | * | |
58 | * @param parent the main application | |
59 | */ | |
60 | public DemoMainWindow(final TApplication parent) { | |
61 | this(parent, CENTERED | RESIZABLE); | |
62 | } | |
63 | ||
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. | |
66 | int timerI = 0; | |
67 | TProgressBar progressBar; | |
68 | ||
69 | /** | |
70 | * Constructor. | |
71 | * | |
72 | * @param parent the main application | |
73 | * @param flags bitmask of MODAL, CENTERED, or RESIZABLE | |
74 | */ | |
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. | |
3649b921 | 78 | super(parent, "Demo Window", 0, 0, 60, 24, flags); |
e3dfbd23 KL |
79 | |
80 | int row = 1; | |
81 | ||
82 | // Add some widgets | |
83 | if (!isModal()) { | |
84 | addLabel("Message Boxes", 1, row); | |
85 | addButton("&MessageBoxes", 35, row, | |
86 | new TAction() { | |
87 | public void DO() { | |
88 | new DemoMsgBoxWindow(getApplication()); | |
89 | } | |
90 | } | |
91 | ); | |
92 | } | |
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 | ); | |
103 | ||
104 | row += 2; | |
105 | ||
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"); | |
3649b921 | 114 | row += 1; |
e3dfbd23 KL |
115 | |
116 | if (!isModal()) { | |
117 | addLabel("Radio buttons and checkboxes", 1, row); | |
118 | addButton("&Checkboxes", 35, row, | |
119 | new TAction() { | |
120 | public void DO() { | |
121 | new DemoCheckboxWindow(getApplication()); | |
122 | } | |
123 | } | |
124 | ); | |
125 | } | |
126 | row += 2; | |
127 | ||
128 | /* | |
129 | if (!isModal()) { | |
130 | addLabel("Editor window", 1, row); | |
131 | addButton("Edito&r", 35, row, | |
132 | { | |
133 | new TEditor(application, 0, 0, 60, 15); | |
134 | } | |
135 | ); | |
136 | } | |
137 | row += 2; | |
138 | */ | |
139 | ||
140 | if (!isModal()) { | |
141 | addLabel("Text areas", 1, row); | |
142 | addButton("&Text", 35, row, | |
143 | new TAction() { | |
144 | public void DO() { | |
145 | new DemoTextWindow(getApplication()); | |
146 | } | |
147 | } | |
148 | ); | |
149 | } | |
150 | row += 2; | |
151 | ||
e3dfbd23 KL |
152 | if (!isModal()) { |
153 | addLabel("Tree views", 1, row); | |
154 | addButton("Tree&View", 35, row, | |
7668cb45 KL |
155 | new TAction() { |
156 | public void DO() { | |
0d47c546 KL |
157 | try { |
158 | new DemoTreeViewWindow(getApplication()); | |
159 | } catch (Exception e) { | |
160 | e.printStackTrace(); | |
161 | } | |
7668cb45 | 162 | } |
e3dfbd23 KL |
163 | } |
164 | ); | |
165 | } | |
166 | row += 2; | |
e3dfbd23 KL |
167 | |
168 | if (!isModal()) { | |
169 | addLabel("Terminal", 1, row); | |
170 | addButton("Termi&nal", 35, row, | |
171 | new TAction() { | |
172 | public void DO() { | |
173 | getApplication().openTerminal(0, 0); | |
174 | } | |
175 | } | |
176 | ); | |
177 | } | |
178 | row += 2; | |
179 | ||
3649b921 KL |
180 | if (!isModal()) { |
181 | addLabel("Color editor", 1, row); | |
182 | addButton("Co&lors", 35, row, | |
183 | new TAction() { | |
184 | public void DO() { | |
185 | new TEditColorThemeWindow(getApplication()); | |
186 | } | |
187 | } | |
188 | ); | |
189 | } | |
190 | row += 2; | |
191 | ||
e3dfbd23 KL |
192 | progressBar = addProgressBar(1, row, 22, 0); |
193 | row++; | |
194 | timerLabel = addLabel("Timer", 1, row); | |
195 | timer = getApplication().addTimer(250, true, | |
196 | new TAction() { | |
197 | ||
198 | public void DO() { | |
199 | timerLabel.setLabel(String.format("Timer: %d", timerI)); | |
200 | timerLabel.setWidth(timerLabel.getLabel().length()); | |
201 | if (timerI < 100) { | |
202 | timerI++; | |
203 | } | |
204 | progressBar.setValue(timerI); | |
205 | } | |
206 | } | |
207 | ); | |
208 | } | |
209 | } |