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", 20, 14);
73 final TWindow windowB
= addWindow("Window B", 20, 14);
74 windowA
.addButton("&Show Window B", 2, 2,
81 windowA
.addButton("H&ide Window B", 2, 4,
88 windowB
.addButton("&Show Window A", 2, 2,
95 windowB
.addButton("H&ide Window A", 2, 4,
103 desktop
.addButton("&Show Window B", 25, 2,
110 desktop
.addButton("H&ide Window B", 25, 5,
117 desktop
.addButton("Sh&ow Window A", 25, 8,
124 desktop
.addButton("Hid&e Window A", 25, 11,
136 * Handle menu events.
138 * @param menu menu event
139 * @return if true, the event was processed and should not be passed onto
143 public boolean onMenu(final TMenuEvent menu
) {
145 if (menu
.getId() == TMenu
.MID_OPEN_FILE
) {
147 String filename
= fileOpenBox(".");
148 if (filename
!= null) {
150 File file
= new File(filename
);
151 StringBuilder fileContents
= new StringBuilder();
152 Scanner scanner
= new Scanner(file
);
153 String EOL
= System
.getProperty("line.separator");
156 while (scanner
.hasNextLine()) {
157 fileContents
.append(scanner
.nextLine() + EOL
);
159 new DemoTextWindow(this, filename
,
160 fileContents
.toString());
164 } catch (IOException e
) {
168 } catch (IOException e
) {
173 return super.onMenu(menu
);
177 * Public constructor.
179 * @param backendType one of the TApplication.BackendType values
180 * @throws Exception if TApplication can't instantiate the Backend.
182 public DesktopDemoApplication(final BackendType backendType
) throws Exception
{
185 getBackend().setTitle("Jexer Demo Application");