| 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 | */ |
| 33 | |
| 34 | import jexer.*; |
| 35 | |
| 36 | class 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 | |
| 70 | /// Constructor |
| 71 | public DemoMainWindow(TApplication parent) { |
| 72 | this(parent, CENTERED | RESIZABLE); |
| 73 | } |
| 74 | |
| 75 | /// Constructor |
| 76 | public DemoMainWindow(TApplication parent, int flags) { |
| 77 | // Construct a demo window. X and Y don't matter because it will be |
| 78 | // centered on screen. |
| 79 | super(parent, "Demo Window", 0, 0, 60, 23, flags); |
| 80 | |
| 81 | int row = 1; |
| 82 | |
| 83 | /* |
| 84 | // Add some widgets |
| 85 | if (!isModal) { |
| 86 | addLabel("Message Boxes", 1, row); |
| 87 | addButton("&MessageBoxes", 35, row, |
| 88 | { |
| 89 | new DemoMsgBoxWindow(application); |
| 90 | } |
| 91 | ); |
| 92 | } |
| 93 | row += 2; |
| 94 | |
| 95 | addLabel("Open me as modal", 1, row); |
| 96 | addButton("W&indow", 35, row, |
| 97 | { |
| 98 | new DemoMainWindow(application, Flag.MODAL); |
| 99 | } |
| 100 | ); |
| 101 | |
| 102 | row += 2; |
| 103 | |
| 104 | addLabel("Variable-width text field:", 1, row); |
| 105 | addField(35, row++, 15, false, "Field text"); |
| 106 | |
| 107 | addLabel("Fixed-width text field:", 1, row); |
| 108 | addField(35, row, 15, true); |
| 109 | row += 2; |
| 110 | |
| 111 | if (!isModal) { |
| 112 | addLabel("Radio buttons and checkboxes", 1, row); |
| 113 | addButton("&Checkboxes", 35, row, &openCheckboxWindow); |
| 114 | } |
| 115 | row += 2; |
| 116 | |
| 117 | if (!isModal) { |
| 118 | addLabel("Editor window", 1, row); |
| 119 | addButton("Edito&r", 35, row, |
| 120 | { |
| 121 | new TEditor(application, 0, 0, 60, 15); |
| 122 | } |
| 123 | ); |
| 124 | } |
| 125 | row += 2; |
| 126 | |
| 127 | if (!isModal) { |
| 128 | addLabel("Text areas", 1, row); |
| 129 | addButton("&Text", 35, row, |
| 130 | { |
| 131 | new DemoTextWindow(application); |
| 132 | } |
| 133 | ); |
| 134 | } |
| 135 | row += 2; |
| 136 | |
| 137 | if (!isModal) { |
| 138 | addLabel("Tree views", 1, row); |
| 139 | addButton("Tree&View", 35, row, |
| 140 | { |
| 141 | new DemoTreeViewWindow(application); |
| 142 | } |
| 143 | ); |
| 144 | } |
| 145 | row += 2; |
| 146 | |
| 147 | version(Posix) { |
| 148 | if (!isModal) { |
| 149 | addLabel("Terminal", 1, row); |
| 150 | addButton("Termi&nal", 35, row, |
| 151 | { |
| 152 | application.openTerminal(0, 0); |
| 153 | } |
| 154 | ); |
| 155 | } |
| 156 | row += 2; |
| 157 | } |
| 158 | |
| 159 | TProgressBar bar = addProgressBar(1, row, 22); |
| 160 | row++; |
| 161 | TLabel timerLabel = addLabel("Timer", 1, row); |
| 162 | timer = parent.addTimer(100, |
| 163 | { |
| 164 | static int i = 0; |
| 165 | auto writer = appender!dstring(); |
| 166 | formattedWrite(writer, "Timer: %d", i); |
| 167 | timerLabel.text = writer.data; |
| 168 | timerLabel.width = cast(uint)timerLabel.text.length; |
| 169 | if (i < 100) { |
| 170 | i++; |
| 171 | } |
| 172 | bar.value = i; |
| 173 | parent.repaint = true; |
| 174 | }, true); |
| 175 | */ |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * The demo application itself. |
| 181 | */ |
| 182 | class DemoApplication extends TApplication { |
| 183 | /** |
| 184 | * Public constructor |
| 185 | */ |
| 186 | public DemoApplication() throws Exception { |
| 187 | super(null, null); |
| 188 | new DemoMainWindow(this); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * This class provides a simple demonstration of Jexer's capabilities. |
| 194 | */ |
| 195 | public class Demo1 { |
| 196 | /** |
| 197 | * Main entry point. |
| 198 | * |
| 199 | * @param args Command line arguments |
| 200 | */ |
| 201 | public static void main(String [] args) { |
| 202 | try { |
| 203 | DemoApplication app = new DemoApplication(); |
| 204 | app.run(); |
| 205 | } catch (Exception e) { |
| 206 | e.printStackTrace(); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | } |