update roadmap
[nikiroo-utils.git] / demos / Demo1.java
CommitLineData
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
KL
34import jexer.*;
35
36class DemoMainWindow extends TWindow {
37 /*
38 // Timer that increments a number
39 private TTimer timer;
40
41 // The modal window is a more low-level example of controlling a window
42 // "from the outside". Most windows will probably subclass TWindow and
43 // do this kind of logic on their own.
44 private TWindow modalWindow;
45 private void openModalWindow() {
46 modalWindow = application.addWindow("Demo Modal Window", 0, 0,
47 58, 15, TWindow.Flag.MODAL);
48 modalWindow.addLabel("This is an example of a very braindead modal window.", 1, 1);
49 modalWindow.addLabel("Modal windows are centered by default.", 1, 2);
50 modalWindow.addButton("&Close", (modalWindow.width - 8)/2,
51 modalWindow.height - 4, &modalWindowClose);
52 }
53 private void modalWindowClose() {
54 application.closeWindow(modalWindow);
55 }
56
57 /// This is an example of having a button call a function.
58 private void openCheckboxWindow() {
59 new DemoCheckboxWindow(application);
60 }
61
62 /// We need to override onClose so that the timer will no longer be
63 /// called after we close the window. TTimers currently are completely
64 /// unaware of the rest of the UI classes.
65 override public void onClose() {
66 application.removeTimer(timer);
67 }
68 */
69
fca67db0
KL
70 /**
71 * Construct demo window. It will be centered on screen.
72 */
a06459bd
KL
73 public DemoMainWindow(TApplication parent) {
74 this(parent, CENTERED | RESIZABLE);
75 }
76
fca67db0
KL
77 /**
78 * Constructor.
79 */
80 private DemoMainWindow(TApplication parent, int flags) {
a06459bd
KL
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, 60, 23, flags);
84
fca67db0 85 /*
a06459bd
KL
86 int row = 1;
87
a06459bd
KL
88 // Add some widgets
89 if (!isModal) {
90 addLabel("Message Boxes", 1, row);
91 addButton("&MessageBoxes", 35, row,
92 {
93 new DemoMsgBoxWindow(application);
94 }
95 );
96 }
97 row += 2;
98
99 addLabel("Open me as modal", 1, row);
100 addButton("W&indow", 35, row,
101 {
102 new DemoMainWindow(application, Flag.MODAL);
103 }
104 );
105
106 row += 2;
107
108 addLabel("Variable-width text field:", 1, row);
109 addField(35, row++, 15, false, "Field text");
110
111 addLabel("Fixed-width text field:", 1, row);
112 addField(35, row, 15, true);
113 row += 2;
114
115 if (!isModal) {
116 addLabel("Radio buttons and checkboxes", 1, row);
117 addButton("&Checkboxes", 35, row, &openCheckboxWindow);
118 }
119 row += 2;
120
121 if (!isModal) {
122 addLabel("Editor window", 1, row);
123 addButton("Edito&r", 35, row,
124 {
125 new TEditor(application, 0, 0, 60, 15);
126 }
127 );
128 }
129 row += 2;
130
131 if (!isModal) {
132 addLabel("Text areas", 1, row);
133 addButton("&Text", 35, row,
134 {
135 new DemoTextWindow(application);
136 }
137 );
138 }
139 row += 2;
140
141 if (!isModal) {
142 addLabel("Tree views", 1, row);
143 addButton("Tree&View", 35, row,
144 {
145 new DemoTreeViewWindow(application);
146 }
147 );
148 }
149 row += 2;
150
151 version(Posix) {
152 if (!isModal) {
153 addLabel("Terminal", 1, row);
154 addButton("Termi&nal", 35, row,
155 {
156 application.openTerminal(0, 0);
157 }
158 );
159 }
160 row += 2;
161 }
162
163 TProgressBar bar = addProgressBar(1, row, 22);
164 row++;
165 TLabel timerLabel = addLabel("Timer", 1, row);
166 timer = parent.addTimer(100,
167 {
168 static int i = 0;
169 auto writer = appender!dstring();
170 formattedWrite(writer, "Timer: %d", i);
171 timerLabel.text = writer.data;
172 timerLabel.width = cast(uint)timerLabel.text.length;
173 if (i < 100) {
174 i++;
175 }
176 bar.value = i;
177 parent.repaint = true;
178 }, true);
179 */
180 }
181}
7d4115a5
KL
182
183/**
184 * The demo application itself.
185 */
186class DemoApplication extends TApplication {
2420f903
KL
187 /**
188 * Public constructor
189 */
4328bb42
KL
190 public DemoApplication() throws Exception {
191 super(null, null);
a06459bd 192 new DemoMainWindow(this);
fca67db0
KL
193 TWindow window2 = new DemoMainWindow(this);
194 window2.setHeight(5);
195 window2.setWidth(25);
196 window2.setX(17);
197 window2.setY(6);
2420f903 198 }
7d4115a5
KL
199}
200
201/**
202 * This class provides a simple demonstration of Jexer's capabilities.
203 */
204public class Demo1 {
205 /**
206 * Main entry point.
207 *
208 * @param args Command line arguments
209 */
210 public static void main(String [] args) {
4328bb42
KL
211 try {
212 DemoApplication app = new DemoApplication();
213 app.run();
214 } catch (Exception e) {
215 e.printStackTrace();
216 }
7d4115a5
KL
217 }
218
219}