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
{
45 * Add all the widgets of the demo.
47 private void addAllWidgets() {
48 new DemoMainWindow(this);
54 TMenu demoMenu
= addMenu("&Demo");
55 TMenuItem item
= demoMenu
.addItem(2000, "&Checkable");
56 item
.setCheckable(true);
57 item
= demoMenu
.addItem(2001, "Disabled");
58 item
.setEnabled(false);
59 item
= demoMenu
.addItem(2002, "&Normal");
60 TSubMenu subMenu
= demoMenu
.addSubMenu("Sub-&Menu");
61 item
= demoMenu
.addItem(2010, "N&ormal A&&D");
62 item
= demoMenu
.addItem(2050, "Co&lors...");
64 item
= subMenu
.addItem(2000, "&Checkable (sub)");
65 item
.setCheckable(true);
66 item
= subMenu
.addItem(2001, "Disabled (sub)");
67 item
.setEnabled(false);
68 item
= subMenu
.addItem(2002, "&Normal (sub)");
70 subMenu
= subMenu
.addSubMenu("Sub-&Menu");
71 item
= subMenu
.addItem(2000, "&Checkable (sub)");
72 item
.setCheckable(true);
73 item
= subMenu
.addItem(2001, "Disabled (sub)");
74 item
.setEnabled(false);
75 item
= subMenu
.addItem(2002, "&Normal (sub)");
77 if (getScreen() instanceof SwingTerminal
) {
78 TMenu swingMenu
= addMenu("Swin&g");
79 item
= swingMenu
.addItem(3000, "&Bigger +2");
80 item
= swingMenu
.addItem(3001, "&Smaller -2");
90 * @param input an InputStream connected to the remote user, or null for
91 * System.in. If System.in is used, then on non-Windows systems it will
92 * be put in raw mode; shutdown() will (blindly!) put System.in in cooked
93 * mode. input is always converted to a Reader with UTF-8 encoding.
94 * @param output an OutputStream connected to the remote user, or null
95 * for System.out. output is always converted to a Writer with UTF-8
97 * @throws UnsupportedEncodingException if an exception is thrown when
98 * creating the InputStreamReader
100 public DemoApplication(final InputStream input
,
101 final OutputStream output
) throws UnsupportedEncodingException
{
102 super(input
, output
);
105 getBackend().setTitle("Jexer Demo Application");
109 * Public constructor.
111 * @param input the InputStream underlying 'reader'. Its available()
112 * method is used to determine if reader.read() will block or not.
113 * @param reader a Reader connected to the remote user.
114 * @param writer a PrintWriter connected to the remote user.
115 * @param setRawMode if true, set System.in into raw mode with stty.
116 * This should in general not be used. It is here solely for Demo3,
117 * which uses System.in.
118 * @throws IllegalArgumentException if input, reader, or writer are null.
120 public DemoApplication(final InputStream input
, final Reader reader
,
121 final PrintWriter writer
, final boolean setRawMode
) {
122 super(input
, reader
, writer
, setRawMode
);
125 getBackend().setTitle("Jexer Demo Application");
129 * Public constructor.
131 * @param input the InputStream underlying 'reader'. Its available()
132 * method is used to determine if reader.read() will block or not.
133 * @param reader a Reader connected to the remote user.
134 * @param writer a PrintWriter connected to the remote user.
135 * @throws IllegalArgumentException if input, reader, or writer are null.
137 public DemoApplication(final InputStream input
, final Reader reader
,
138 final PrintWriter writer
) {
140 this(input
, reader
, writer
, false);
144 * Public constructor.
146 * @param backend a Backend that is already ready to go.
148 public DemoApplication(final Backend backend
) {
155 * Handle menu events.
157 * @param menu menu event
158 * @return if true, the event was processed and should not be passed onto
162 public boolean onMenu(final TMenuEvent menu
) {
164 if (menu
.getId() == 3000) {
166 assert (getScreen() instanceof SwingTerminal
);
167 SwingTerminal terminal
= (SwingTerminal
) getScreen();
168 terminal
.setFontSize(terminal
.getFontSize() + 2);
171 if (menu
.getId() == 3001) {
173 assert (getScreen() instanceof SwingTerminal
);
174 SwingTerminal terminal
= (SwingTerminal
) getScreen();
175 terminal
.setFontSize(terminal
.getFontSize() - 2);
179 if (menu
.getId() == 2050) {
180 new TEditColorThemeWindow(this);
184 if (menu
.getId() == TMenu
.MID_OPEN_FILE
) {
186 String filename
= fileOpenBox(".");
187 if (filename
!= null) {
189 new TEditorWindow(this, new File(filename
));
190 } catch (IOException e
) {
194 } catch (IOException e
) {
199 return super.onMenu(menu
);
203 * Public constructor.
205 * @param backendType one of the TApplication.BackendType values
206 * @throws Exception if TApplication can't instantiate the Backend.
208 public DemoApplication(final BackendType backendType
) throws Exception
{
211 getBackend().setTitle("Jexer Demo Application");