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]
36 import jexer
.backend
.Backend
;
37 import jexer
.backend
.SwingTerminal
;
40 * The demo application itself.
42 public class DemoApplication
extends TApplication
{
44 // ------------------------------------------------------------------------
45 // Constructors -----------------------------------------------------------
46 // ------------------------------------------------------------------------
51 * @param input an InputStream connected to the remote user, or null for
52 * System.in. If System.in is used, then on non-Windows systems it will
53 * be put in raw mode; shutdown() will (blindly!) put System.in in cooked
54 * mode. input is always converted to a Reader with UTF-8 encoding.
55 * @param output an OutputStream connected to the remote user, or null
56 * for System.out. output is always converted to a Writer with UTF-8
58 * @throws UnsupportedEncodingException if an exception is thrown when
59 * creating the InputStreamReader
61 public DemoApplication(final InputStream input
,
62 final OutputStream output
) throws UnsupportedEncodingException
{
66 getBackend().setTitle("Jexer Demo Application");
72 * @param input the InputStream underlying 'reader'. Its available()
73 * method is used to determine if reader.read() will block or not.
74 * @param reader a Reader connected to the remote user.
75 * @param writer a PrintWriter connected to the remote user.
76 * @param setRawMode if true, set System.in into raw mode with stty.
77 * This should in general not be used. It is here solely for Demo3,
78 * which uses System.in.
79 * @throws IllegalArgumentException if input, reader, or writer are null.
81 public DemoApplication(final InputStream input
, final Reader reader
,
82 final PrintWriter writer
, final boolean setRawMode
) {
83 super(input
, reader
, writer
, setRawMode
);
86 getBackend().setTitle("Jexer Demo Application");
92 * @param input the InputStream underlying 'reader'. Its available()
93 * method is used to determine if reader.read() will block or not.
94 * @param reader a Reader connected to the remote user.
95 * @param writer a PrintWriter connected to the remote user.
96 * @throws IllegalArgumentException if input, reader, or writer are null.
98 public DemoApplication(final InputStream input
, final Reader reader
,
99 final PrintWriter writer
) {
101 this(input
, reader
, writer
, false);
105 * Public constructor.
107 * @param backend a Backend that is already ready to go.
109 public DemoApplication(final Backend backend
) {
116 * Public constructor.
118 * @param backendType one of the TApplication.BackendType values
119 * @throws Exception if TApplication can't instantiate the Backend.
121 public DemoApplication(final BackendType backendType
) throws Exception
{
124 getBackend().setTitle("Jexer Demo Application");
127 // ------------------------------------------------------------------------
128 // TApplication -----------------------------------------------------------
129 // ------------------------------------------------------------------------
132 * Handle menu events.
134 * @param menu menu event
135 * @return if true, the event was processed and should not be passed onto
139 public boolean onMenu(final TMenuEvent menu
) {
141 if (menu
.getId() == 3000) {
143 assert (getScreen() instanceof SwingTerminal
);
144 SwingTerminal terminal
= (SwingTerminal
) getScreen();
145 terminal
.setFontSize(terminal
.getFontSize() + 2);
148 if (menu
.getId() == 3001) {
150 assert (getScreen() instanceof SwingTerminal
);
151 SwingTerminal terminal
= (SwingTerminal
) getScreen();
152 terminal
.setFontSize(terminal
.getFontSize() - 2);
156 if (menu
.getId() == 2050) {
157 new TEditColorThemeWindow(this);
161 if (menu
.getId() == TMenu
.MID_OPEN_FILE
) {
163 String filename
= fileOpenBox(".");
164 if (filename
!= null) {
166 new TEditorWindow(this, new File(filename
));
167 } catch (IOException e
) {
171 } catch (IOException e
) {
176 return super.onMenu(menu
);
179 // ------------------------------------------------------------------------
180 // DemoApplication --------------------------------------------------------
181 // ------------------------------------------------------------------------
184 * Add all the widgets of the demo.
186 private void addAllWidgets() {
187 new DemoMainWindow(this);
193 TMenu demoMenu
= addMenu("&Demo");
194 TMenuItem item
= demoMenu
.addItem(2000, "&Checkable");
195 item
.setCheckable(true);
196 item
= demoMenu
.addItem(2001, "Disabled");
197 item
.setEnabled(false);
198 item
= demoMenu
.addItem(2002, "&Normal");
199 TSubMenu subMenu
= demoMenu
.addSubMenu("Sub-&Menu");
200 item
= demoMenu
.addItem(2010, "N&ormal A&&D");
201 item
= demoMenu
.addItem(2050, "Co&lors...");
203 item
= subMenu
.addItem(2000, "&Checkable (sub)");
204 item
.setCheckable(true);
205 item
= subMenu
.addItem(2001, "Disabled (sub)");
206 item
.setEnabled(false);
207 item
= subMenu
.addItem(2002, "&Normal (sub)");
209 subMenu
= subMenu
.addSubMenu("Sub-&Menu");
210 item
= subMenu
.addItem(2000, "&Checkable (sub)");
211 item
.setCheckable(true);
212 item
= subMenu
.addItem(2001, "Disabled (sub)");
213 item
.setEnabled(false);
214 item
= subMenu
.addItem(2002, "&Normal (sub)");
216 if (getScreen() instanceof SwingTerminal
) {
217 TMenu swingMenu
= addMenu("Swin&g");
218 item
= swingMenu
.addItem(3000, "&Bigger +2");
219 item
= swingMenu
.addItem(3001, "&Smaller -2");