2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 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]
32 import java
.io
.IOException
;
33 import java
.util
.ResourceBundle
;
34 import java
.util
.Scanner
;
37 import jexer
.TApplication
;
39 import jexer
.event
.TMenuEvent
;
40 import jexer
.menu
.TMenu
;
43 * The demo application itself.
45 public class DesktopDemoApplication
extends TApplication
{
50 private static final ResourceBundle i18n
= ResourceBundle
.getBundle(DesktopDemoApplication
.class.getName());
52 // ------------------------------------------------------------------------
53 // Constructors -----------------------------------------------------------
54 // ------------------------------------------------------------------------
59 * @param backendType one of the TApplication.BackendType values
60 * @throws Exception if TApplication can't instantiate the Backend.
62 public DesktopDemoApplication(final BackendType backendType
) throws Exception
{
65 getBackend().setTitle(i18n
.getString("applicationTitle"));
68 // ------------------------------------------------------------------------
69 // TApplication -----------------------------------------------------------
70 // ------------------------------------------------------------------------
75 * @param menu menu event
76 * @return if true, the event was processed and should not be passed onto
80 public boolean onMenu(final TMenuEvent menu
) {
82 if (menu
.getId() == TMenu
.MID_OPEN_FILE
) {
84 String filename
= fileOpenBox(".");
85 if (filename
!= null) {
87 File file
= new File(filename
);
88 StringBuilder fileContents
= new StringBuilder();
89 Scanner scanner
= new Scanner(file
);
90 String EOL
= System
.getProperty("line.separator");
93 while (scanner
.hasNextLine()) {
94 fileContents
.append(scanner
.nextLine() + EOL
);
96 new DemoTextWindow(this, filename
,
97 fileContents
.toString());
101 } catch (IOException e
) {
105 } catch (IOException e
) {
110 return super.onMenu(menu
);
113 // ------------------------------------------------------------------------
114 // DesktopDemoApplication -------------------------------------------------
115 // ------------------------------------------------------------------------
118 * Add all the widgets of the demo.
120 private void addAllWidgets() {
128 final DesktopDemo desktop
= new DesktopDemo(this);
131 desktop
.addButton(i18n
.getString("removeHatch"), 2, 5,
134 desktop
.drawHatch
= false;
138 desktop
.addButton(i18n
.getString("showHatch"), 2, 8,
141 desktop
.drawHatch
= true;
146 final TWindow windowA
= addWindow(i18n
.getString("windowATitle"),
148 final TWindow windowB
= addWindow(i18n
.getString("windowBTitle"),
150 windowA
.addButton(i18n
.getString("showWindowB"), 2, 2,
157 windowA
.addButton(i18n
.getString("hideWindowB"), 2, 4,
164 windowA
.addButton(i18n
.getString("maximizeWindowB"), 2, 6,
171 windowA
.addButton(i18n
.getString("restoreWindowB"), 2, 8,
178 windowB
.addButton(i18n
.getString("showWindowA"), 2, 2,
185 windowB
.addButton(i18n
.getString("hideWindowA"), 2, 4,
192 windowB
.addButton(i18n
.getString("maximizeWindowA"), 2, 6,
199 windowB
.addButton(i18n
.getString("restoreWindowA"), 2, 8,
207 desktop
.addButton(i18n
.getString("showWindowB"), 25, 2,
214 desktop
.addButton(i18n
.getString("hideWindowB"), 25, 5,
221 desktop
.addButton(i18n
.getString("showWindowA"), 25, 8,
228 desktop
.addButton(i18n
.getString("hideWindowA"), 25, 11,
235 desktop
.addButton(i18n
.getString("createWindowC"), 25, 15,
238 final TWindow windowC
= desktop
.getApplication().addWindow(
239 i18n
.getString("windowCTitle"), 30, 20,
241 windowC
.addButton(i18n
.getString("closeMe"), 5, 5,
252 desktop
.addButton(i18n
.getString("enableFFM"), 25, 18,
255 DesktopDemoApplication
.this.setFocusFollowsMouse(true);
259 desktop
.addButton(i18n
.getString("disableFFM"), 25, 21,
262 DesktopDemoApplication
.this.setFocusFollowsMouse(false);