2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 Kevin Lamonte
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
39 * The demo application itself.
41 public class DesktopDemoApplication
extends TApplication
{
44 * Add all the widgets of the demo.
46 private void addAllWidgets() {
54 final DesktopDemo desktop
= new DesktopDemo(this);
57 desktop
.addButton("&Remove HATCH", 2, 5,
60 desktop
.drawHatch
= false;
64 desktop
.addButton("&Show HATCH", 2, 8,
67 desktop
.drawHatch
= true;
72 final TWindow windowA
= addWindow("Window A", 25, 14);
73 final TWindow windowB
= addWindow("Window B", 25, 14);
74 windowA
.addButton("&Show Window B", 2, 2,
81 windowA
.addButton("H&ide Window B", 2, 4,
88 windowA
.addButton("&Maximize Window B", 2, 6,
95 windowA
.addButton("&Restore Window B", 2, 8,
102 windowB
.addButton("&Show Window A", 2, 2,
109 windowB
.addButton("H&ide Window A", 2, 4,
116 windowB
.addButton("&Maximize Window A", 2, 6,
123 windowB
.addButton("&Restore Window A", 2, 8,
131 desktop
.addButton("S&how Window B", 25, 2,
138 desktop
.addButton("H&ide Window B", 25, 5,
145 desktop
.addButton("Sh&ow Window A", 25, 8,
152 desktop
.addButton("Hid&e Window A", 25, 11,
159 desktop
.addButton("&Create Window C", 25, 15,
162 desktop
.getApplication().addWindow("Window C",
172 * Handle menu events.
174 * @param menu menu event
175 * @return if true, the event was processed and should not be passed onto
179 public boolean onMenu(final TMenuEvent menu
) {
181 if (menu
.getId() == TMenu
.MID_OPEN_FILE
) {
183 String filename
= fileOpenBox(".");
184 if (filename
!= null) {
186 File file
= new File(filename
);
187 StringBuilder fileContents
= new StringBuilder();
188 Scanner scanner
= new Scanner(file
);
189 String EOL
= System
.getProperty("line.separator");
192 while (scanner
.hasNextLine()) {
193 fileContents
.append(scanner
.nextLine() + EOL
);
195 new DemoTextWindow(this, filename
,
196 fileContents
.toString());
200 } catch (IOException e
) {
204 } catch (IOException e
) {
209 return super.onMenu(menu
);
213 * Public constructor.
215 * @param backendType one of the TApplication.BackendType values
216 * @throws Exception if TApplication can't instantiate the Backend.
218 public DesktopDemoApplication(final BackendType backendType
) throws Exception
{
221 getBackend().setTitle("Jexer Demo Application");