Commit | Line | Data |
---|---|---|
7d4115a5 KL |
1 | /** |
2 | * Jexer - Java Text User Interface - demonstration program | |
3 | * | |
4 | * Version: $Id$ | |
5 | * | |
6 | * Author: Kevin Lamonte, <a href="mailto:kevin.lamonte@gmail.com">kevin.lamonte@gmail.com</a> | |
7 | * | |
8 | * License: LGPLv3 or later | |
9 | * | |
10 | * Copyright: This module is licensed under the GNU Lesser General | |
11 | * Public License Version 3. Please see the file "COPYING" in this | |
12 | * directory for more information about the GNU Lesser General Public | |
13 | * License Version 3. | |
14 | * | |
15 | * Copyright (C) 2015 Kevin Lamonte | |
16 | * | |
17 | * This program is free software; you can redistribute it and/or | |
18 | * modify it under the terms of the GNU Lesser General Public License | |
19 | * as published by the Free Software Foundation; either version 3 of | |
20 | * the License, or (at your option) any later version. | |
21 | * | |
22 | * This program is distributed in the hope that it will be useful, but | |
23 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
25 | * General Public License for more details. | |
26 | * | |
27 | * You should have received a copy of the GNU Lesser General Public | |
28 | * License along with this program; if not, see | |
29 | * http://www.gnu.org/licenses/, or write to the Free Software | |
30 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
31 | * 02110-1301 USA | |
32 | */ | |
2420f903 | 33 | |
a06459bd | 34 | import jexer.*; |
8e688b92 | 35 | import jexer.menu.*; |
a06459bd KL |
36 | |
37 | class DemoMainWindow extends TWindow { | |
38 | /* | |
39 | // Timer that increments a number | |
40 | private TTimer timer; | |
41 | ||
42 | // The modal window is a more low-level example of controlling a window | |
43 | // "from the outside". Most windows will probably subclass TWindow and | |
44 | // do this kind of logic on their own. | |
45 | private TWindow modalWindow; | |
46 | private void openModalWindow() { | |
8e688b92 KL |
47 | modalWindow = application.addWindow("Demo Modal Window", 0, 0, |
48 | 58, 15, TWindow.Flag.MODAL); | |
49 | modalWindow.addLabel("This is an example of a very braindead modal window.", 1, 1); | |
50 | modalWindow.addLabel("Modal windows are centered by default.", 1, 2); | |
51 | modalWindow.addButton("&Close", (modalWindow.width - 8)/2, | |
52 | modalWindow.height - 4, &modalWindowClose); | |
a06459bd KL |
53 | } |
54 | private void modalWindowClose() { | |
8e688b92 | 55 | application.closeWindow(modalWindow); |
a06459bd KL |
56 | } |
57 | ||
58 | /// This is an example of having a button call a function. | |
59 | private void openCheckboxWindow() { | |
8e688b92 | 60 | new DemoCheckboxWindow(application); |
a06459bd KL |
61 | } |
62 | ||
63 | /// We need to override onClose so that the timer will no longer be | |
64 | /// called after we close the window. TTimers currently are completely | |
65 | /// unaware of the rest of the UI classes. | |
66 | override public void onClose() { | |
8e688b92 | 67 | application.removeTimer(timer); |
a06459bd KL |
68 | } |
69 | */ | |
70 | ||
fca67db0 KL |
71 | /** |
72 | * Construct demo window. It will be centered on screen. | |
73 | */ | |
a06459bd | 74 | public DemoMainWindow(TApplication parent) { |
8e688b92 | 75 | this(parent, CENTERED | RESIZABLE); |
a06459bd KL |
76 | } |
77 | ||
fca67db0 KL |
78 | /** |
79 | * Constructor. | |
80 | */ | |
81 | private DemoMainWindow(TApplication parent, int flags) { | |
8e688b92 KL |
82 | // Construct a demo window. X and Y don't matter because it will be |
83 | // centered on screen. | |
84 | super(parent, "Demo Window", 0, 0, 60, 23, flags); | |
a06459bd | 85 | |
fca67db0 | 86 | /* |
8e688b92 KL |
87 | int row = 1; |
88 | ||
89 | // Add some widgets | |
90 | if (!isModal) { | |
91 | addLabel("Message Boxes", 1, row); | |
92 | addButton("&MessageBoxes", 35, row, | |
93 | { | |
94 | new DemoMsgBoxWindow(application); | |
95 | } | |
96 | ); | |
97 | } | |
98 | row += 2; | |
99 | ||
100 | addLabel("Open me as modal", 1, row); | |
101 | addButton("W&indow", 35, row, | |
102 | { | |
103 | new DemoMainWindow(application, Flag.MODAL); | |
104 | } | |
105 | ); | |
106 | ||
107 | row += 2; | |
108 | ||
109 | addLabel("Variable-width text field:", 1, row); | |
110 | addField(35, row++, 15, false, "Field text"); | |
111 | ||
112 | addLabel("Fixed-width text field:", 1, row); | |
113 | addField(35, row, 15, true); | |
114 | row += 2; | |
115 | ||
116 | if (!isModal) { | |
117 | addLabel("Radio buttons and checkboxes", 1, row); | |
118 | addButton("&Checkboxes", 35, row, &openCheckboxWindow); | |
119 | } | |
120 | row += 2; | |
121 | ||
122 | if (!isModal) { | |
123 | addLabel("Editor window", 1, row); | |
124 | addButton("Edito&r", 35, row, | |
125 | { | |
126 | new TEditor(application, 0, 0, 60, 15); | |
127 | } | |
128 | ); | |
129 | } | |
130 | row += 2; | |
131 | ||
132 | if (!isModal) { | |
133 | addLabel("Text areas", 1, row); | |
134 | addButton("&Text", 35, row, | |
135 | { | |
136 | new DemoTextWindow(application); | |
137 | } | |
138 | ); | |
139 | } | |
140 | row += 2; | |
141 | ||
142 | if (!isModal) { | |
143 | addLabel("Tree views", 1, row); | |
144 | addButton("Tree&View", 35, row, | |
145 | { | |
146 | new DemoTreeViewWindow(application); | |
147 | } | |
148 | ); | |
149 | } | |
150 | row += 2; | |
151 | ||
152 | version(Posix) { | |
153 | if (!isModal) { | |
154 | addLabel("Terminal", 1, row); | |
155 | addButton("Termi&nal", 35, row, | |
156 | { | |
157 | application.openTerminal(0, 0); | |
158 | } | |
159 | ); | |
160 | } | |
161 | row += 2; | |
162 | } | |
163 | ||
164 | TProgressBar bar = addProgressBar(1, row, 22); | |
165 | row++; | |
166 | TLabel timerLabel = addLabel("Timer", 1, row); | |
167 | timer = parent.addTimer(100, | |
168 | { | |
169 | static int i = 0; | |
170 | auto writer = appender!dstring(); | |
171 | formattedWrite(writer, "Timer: %d", i); | |
172 | timerLabel.text = writer.data; | |
173 | timerLabel.width = cast(uint)timerLabel.text.length; | |
174 | if (i < 100) { | |
175 | i++; | |
176 | } | |
177 | bar.value = i; | |
178 | parent.repaint = true; | |
179 | }, true); | |
a06459bd KL |
180 | */ |
181 | } | |
182 | } | |
7d4115a5 KL |
183 | |
184 | /** | |
185 | * The demo application itself. | |
186 | */ | |
187 | class DemoApplication extends TApplication { | |
2420f903 KL |
188 | /** |
189 | * Public constructor | |
190 | */ | |
4328bb42 | 191 | public DemoApplication() throws Exception { |
8e688b92 KL |
192 | super(null, null); |
193 | new DemoMainWindow(this); | |
194 | ||
195 | // TEMPORARY | |
196 | TWindow window2 = new DemoMainWindow(this); | |
fca67db0 KL |
197 | window2.setHeight(5); |
198 | window2.setWidth(25); | |
199 | window2.setX(17); | |
200 | window2.setY(6); | |
8e688b92 KL |
201 | // TEMPORARY |
202 | ||
203 | // Add the menus | |
204 | addFileMenu(); | |
205 | addEditMenu(); | |
206 | ||
207 | TMenu demoMenu = addMenu("&Demo"); | |
208 | TMenuItem item = demoMenu.addItem(2000, "&Checkable"); | |
209 | item.setCheckable(true); | |
210 | item = demoMenu.addItem(2001, "Disabled"); | |
211 | item.setEnabled(false); | |
212 | item = demoMenu.addItem(2002, "&Normal"); | |
213 | TSubMenu subMenu = demoMenu.addSubMenu("Sub-&Menu"); | |
214 | item = demoMenu.addItem(2010, "N&ormal A&&D"); | |
215 | ||
216 | item = subMenu.addItem(2000, "&Checkable (sub)"); | |
217 | item.setCheckable(true); | |
218 | item = subMenu.addItem(2001, "Disabled (sub)"); | |
219 | item.setEnabled(false); | |
220 | item = subMenu.addItem(2002, "&Normal (sub)"); | |
221 | ||
222 | subMenu = subMenu.addSubMenu("Sub-&Menu"); | |
223 | item = subMenu.addItem(2000, "&Checkable (sub)"); | |
224 | item.setCheckable(true); | |
225 | item = subMenu.addItem(2001, "Disabled (sub)"); | |
226 | item.setEnabled(false); | |
227 | item = subMenu.addItem(2002, "&Normal (sub)"); | |
228 | ||
229 | addWindowMenu(); | |
230 | ||
2420f903 | 231 | } |
7d4115a5 KL |
232 | } |
233 | ||
234 | /** | |
235 | * This class provides a simple demonstration of Jexer's capabilities. | |
236 | */ | |
237 | public class Demo1 { | |
238 | /** | |
239 | * Main entry point. | |
240 | * | |
241 | * @param args Command line arguments | |
242 | */ | |
243 | public static void main(String [] args) { | |
8e688b92 KL |
244 | try { |
245 | DemoApplication app = new DemoApplication(); | |
246 | app.run(); | |
247 | } catch (Exception e) { | |
248 | e.printStackTrace(); | |
249 | } | |
7d4115a5 KL |
250 | } |
251 | ||
252 | } |