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
{
43 // ------------------------------------------------------------------------
44 // Constructors -----------------------------------------------------------
45 // ------------------------------------------------------------------------
50 * @param backendType one of the TApplication.BackendType values
51 * @throws Exception if TApplication can't instantiate the Backend.
53 public DesktopDemoApplication(final BackendType backendType
) throws Exception
{
56 getBackend().setTitle("Jexer Demo Application");
59 // ------------------------------------------------------------------------
60 // TApplication -----------------------------------------------------------
61 // ------------------------------------------------------------------------
66 * @param menu menu event
67 * @return if true, the event was processed and should not be passed onto
71 public boolean onMenu(final TMenuEvent menu
) {
73 if (menu
.getId() == TMenu
.MID_OPEN_FILE
) {
75 String filename
= fileOpenBox(".");
76 if (filename
!= null) {
78 File file
= new File(filename
);
79 StringBuilder fileContents
= new StringBuilder();
80 Scanner scanner
= new Scanner(file
);
81 String EOL
= System
.getProperty("line.separator");
84 while (scanner
.hasNextLine()) {
85 fileContents
.append(scanner
.nextLine() + EOL
);
87 new DemoTextWindow(this, filename
,
88 fileContents
.toString());
92 } catch (IOException e
) {
96 } catch (IOException e
) {
101 return super.onMenu(menu
);
104 // ------------------------------------------------------------------------
105 // DesktopDemoApplication -------------------------------------------------
106 // ------------------------------------------------------------------------
109 * Add all the widgets of the demo.
111 private void addAllWidgets() {
119 final DesktopDemo desktop
= new DesktopDemo(this);
122 desktop
.addButton("&Remove HATCH", 2, 5,
125 desktop
.drawHatch
= false;
129 desktop
.addButton("&Show HATCH", 2, 8,
132 desktop
.drawHatch
= true;
137 final TWindow windowA
= addWindow("Window A", 25, 14);
138 final TWindow windowB
= addWindow("Window B", 25, 14);
139 windowA
.addButton("&Show Window B", 2, 2,
146 windowA
.addButton("H&ide Window B", 2, 4,
153 windowA
.addButton("&Maximize Window B", 2, 6,
160 windowA
.addButton("&Restore Window B", 2, 8,
167 windowB
.addButton("&Show Window A", 2, 2,
174 windowB
.addButton("H&ide Window A", 2, 4,
181 windowB
.addButton("&Maximize Window A", 2, 6,
188 windowB
.addButton("&Restore Window A", 2, 8,
196 desktop
.addButton("S&how Window B", 25, 2,
203 desktop
.addButton("H&ide Window B", 25, 5,
210 desktop
.addButton("Sh&ow Window A", 25, 8,
217 desktop
.addButton("Hid&e Window A", 25, 11,
224 desktop
.addButton("&Create Window C", 25, 15,
227 final TWindow windowC
= desktop
.getApplication().addWindow(
228 "Window C", 30, 20, TWindow
.NOCLOSEBOX
);
229 windowC
.addButton("&Close Me", 5, 5,
240 desktop
.addButton("Enable focusFollowsMouse", 25, 18,
243 DesktopDemoApplication
.this.setFocusFollowsMouse(true);
247 desktop
.addButton("Disable focusFollowsMouse", 25, 21,
250 DesktopDemoApplication
.this.setFocusFollowsMouse(false);