2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
41 * The demo application itself.
43 public class DemoApplication
extends TApplication
{
46 * Add all the widgets of the demo.
48 private void addAllWidgets() {
49 new DemoMainWindow(this);
55 TMenu demoMenu
= addMenu("&Demo");
56 TMenuItem item
= demoMenu
.addItem(2000, "&Checkable");
57 item
.setCheckable(true);
58 item
= demoMenu
.addItem(2001, "Disabled");
59 item
.setEnabled(false);
60 item
= demoMenu
.addItem(2002, "&Normal");
61 TSubMenu subMenu
= demoMenu
.addSubMenu("Sub-&Menu");
62 item
= demoMenu
.addItem(2010, "N&ormal A&&D");
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)");
83 * @param input an InputStream connected to the remote user, or null for
84 * System.in. If System.in is used, then on non-Windows systems it will
85 * be put in raw mode; shutdown() will (blindly!) put System.in in cooked
86 * mode. input is always converted to a Reader with UTF-8 encoding.
87 * @param output an OutputStream connected to the remote user, or null
88 * for System.out. output is always converted to a Writer with UTF-8
90 * @throws UnsupportedEncodingException if an exception is thrown when
91 * creating the InputStreamReader
93 public DemoApplication(final InputStream input
,
94 final OutputStream output
) throws UnsupportedEncodingException
{
100 * Handle menu events.
102 * @param menu menu event
103 * @return if true, the event was processed and should not be passed onto
107 public boolean onMenu(TMenuEvent menu
) {
108 if (menu
.getId() == TMenu
.MID_OPEN_FILE
) {
110 String filename
= fileOpenBox(".");
111 if (filename
!= null) {
113 File file
= new File(filename
);
114 StringBuilder fileContents
= new StringBuilder();
115 Scanner scanner
= new Scanner(file
);
116 String EOL
= System
.getProperty("line.separator");
119 while(scanner
.hasNextLine()) {
120 fileContents
.append(scanner
.nextLine() + EOL
);
122 new DemoTextWindow(this, filename
,
123 fileContents
.toString());
127 } catch (IOException e
) {
131 } catch (IOException e
) {
136 return super.onMenu(menu
);
140 * Public constructor.
142 * @param backendType one of the TApplication.BackendType values
143 * @throws Exception if TApplication can't instantiate the Backend.
145 public DemoApplication(BackendType backendType
) throws Exception
{