Commit | Line | Data |
---|---|---|
e3dfbd23 KL |
1 | /* |
2 | * Jexer - Java Text User Interface | |
3 | * | |
e16dda65 | 4 | * The MIT License (MIT) |
e3dfbd23 | 5 | * |
a69ed767 | 6 | * Copyright (C) 2019 Kevin Lamonte |
e3dfbd23 | 7 | * |
e16dda65 KL |
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: | |
e3dfbd23 | 14 | * |
e16dda65 KL |
15 | * The above copyright notice and this permission notice shall be included in |
16 | * all copies or substantial portions of the Software. | |
e3dfbd23 | 17 | * |
e16dda65 KL |
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. | |
e3dfbd23 KL |
25 | * |
26 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] | |
27 | * @version 1 | |
28 | */ | |
29 | package jexer.demos; | |
30 | ||
a69ed767 KL |
31 | import java.util.ResourceBundle; |
32 | ||
33 | import jexer.TAction; | |
34 | import jexer.TApplication; | |
35 | import jexer.TText; | |
36 | import jexer.TWidget; | |
37 | import jexer.TWindow; | |
38 | import jexer.event.TResizeEvent; | |
39 | import jexer.menu.TMenu; | |
2ce6dab2 KL |
40 | import static jexer.TCommand.*; |
41 | import static jexer.TKeypress.*; | |
e3dfbd23 KL |
42 | |
43 | /** | |
44 | * This window demonstates the TText, THScroller, and TVScroller widgets. | |
45 | */ | |
7668cb45 | 46 | public class DemoTextWindow extends TWindow { |
e3dfbd23 | 47 | |
a69ed767 KL |
48 | /** |
49 | * Translated strings. | |
50 | */ | |
51 | private static final ResourceBundle i18n = ResourceBundle.getBundle(DemoTextWindow.class.getName()); | |
52 | ||
43ad7b6c KL |
53 | // ------------------------------------------------------------------------ |
54 | // Variables -------------------------------------------------------------- | |
55 | // ------------------------------------------------------------------------ | |
56 | ||
e3dfbd23 KL |
57 | /** |
58 | * Hang onto my TText so I can resize it with the window. | |
59 | */ | |
60 | private TText textField; | |
61 | ||
43ad7b6c KL |
62 | // ------------------------------------------------------------------------ |
63 | // Constructors ----------------------------------------------------------- | |
64 | // ------------------------------------------------------------------------ | |
65 | ||
a043164f KL |
66 | /** |
67 | * Public constructor makes a text window out of any string. | |
68 | * | |
69 | * @param parent the main application | |
70 | * @param title the text string | |
71 | * @param text the text string | |
72 | */ | |
73 | public DemoTextWindow(final TApplication parent, final String title, | |
74 | final String text) { | |
75 | ||
7657ad8c KL |
76 | super(parent, title, 0, 0, 44, 22, RESIZABLE); |
77 | textField = addText(text, 1, 3, 40, 16); | |
78 | ||
a69ed767 | 79 | addButton(i18n.getString("left"), 1, 1, new TAction() { |
7657ad8c KL |
80 | public void DO() { |
81 | textField.leftJustify(); | |
82 | } | |
83 | }); | |
84 | ||
a69ed767 | 85 | addButton(i18n.getString("center"), 10, 1, new TAction() { |
7657ad8c KL |
86 | public void DO() { |
87 | textField.centerJustify(); | |
88 | } | |
89 | }); | |
90 | ||
a69ed767 | 91 | addButton(i18n.getString("right"), 21, 1, new TAction() { |
7657ad8c KL |
92 | public void DO() { |
93 | textField.rightJustify(); | |
94 | } | |
95 | }); | |
96 | ||
a69ed767 | 97 | addButton(i18n.getString("full"), 31, 1, new TAction() { |
7657ad8c KL |
98 | public void DO() { |
99 | textField.fullJustify(); | |
100 | } | |
101 | }); | |
2ce6dab2 | 102 | |
a69ed767 KL |
103 | statusBar = newStatusBar(i18n.getString("statusBar")); |
104 | statusBar.addShortcutKeypress(kbF1, cmHelp, | |
105 | i18n.getString("statusBarHelp")); | |
106 | statusBar.addShortcutKeypress(kbF2, cmShell, | |
107 | i18n.getString("statusBarShell")); | |
108 | statusBar.addShortcutKeypress(kbF3, cmOpen, | |
109 | i18n.getString("statusBarOpen")); | |
110 | statusBar.addShortcutKeypress(kbF10, cmExit, | |
111 | i18n.getString("statusBarExit")); | |
a043164f | 112 | } |
efb7af1f | 113 | |
e3dfbd23 KL |
114 | /** |
115 | * Public constructor. | |
116 | * | |
117 | * @param parent the main application | |
118 | */ | |
119 | public DemoTextWindow(final TApplication parent) { | |
a69ed767 | 120 | this(parent, i18n.getString("windowTitle"), |
e3dfbd23 KL |
121 | "This is an example of a reflowable text field. Some example text follows.\n" + |
122 | "\n" + | |
efb7af1f KL |
123 | "Notice that some menu items should be disabled when this window has focus.\n" + |
124 | "\n" + | |
7657ad8c | 125 | "This library implements a text-based windowing system loosely " + |
dd459b43 | 126 | "reminiscent of Borland's [Turbo " + |
7657ad8c KL |
127 | "Vision](http://en.wikipedia.org/wiki/Turbo_Vision) library. For those " + |
128 | "wishing to use the actual C++ Turbo Vision library, see [Sergio " + | |
129 | "Sigala's updated version](http://tvision.sourceforge.net/) that runs " + | |
e3dfbd23 KL |
130 | "on many more platforms.\n" + |
131 | "\n" + | |
7657ad8c | 132 | "This library is licensed MIT. See the file LICENSE for the full license " + |
e16dda65 | 133 | "for the details.\n"); |
a043164f | 134 | |
e3dfbd23 KL |
135 | } |
136 | ||
43ad7b6c KL |
137 | // ------------------------------------------------------------------------ |
138 | // TWindow ---------------------------------------------------------------- | |
139 | // ------------------------------------------------------------------------ | |
140 | ||
e3dfbd23 KL |
141 | /** |
142 | * Handle window/screen resize events. | |
143 | * | |
144 | * @param event resize event | |
145 | */ | |
146 | @Override | |
147 | public void onResize(final TResizeEvent event) { | |
148 | if (event.getType() == TResizeEvent.Type.WIDGET) { | |
149 | // Resize the text field | |
56661844 KL |
150 | TResizeEvent textSize = new TResizeEvent(TResizeEvent.Type.WIDGET, |
151 | event.getWidth() - 4, event.getHeight() - 6); | |
152 | textField.onResize(textSize); | |
e3dfbd23 KL |
153 | return; |
154 | } | |
155 | ||
156 | // Pass to children instead | |
157 | for (TWidget widget: getChildren()) { | |
158 | widget.onResize(event); | |
159 | } | |
160 | } | |
e3dfbd23 | 161 | |
efb7af1f KL |
162 | /** |
163 | * Play with menu items. | |
164 | */ | |
165 | public void onFocus() { | |
166 | getApplication().enableMenuItem(2001); | |
167 | getApplication().disableMenuItem(TMenu.MID_SHELL); | |
168 | getApplication().disableMenuItem(TMenu.MID_EXIT); | |
169 | } | |
170 | ||
171 | /** | |
172 | * Called by application.switchWindow() when another window gets the | |
173 | * focus. | |
174 | */ | |
175 | public void onUnfocus() { | |
176 | getApplication().disableMenuItem(2001); | |
177 | getApplication().enableMenuItem(TMenu.MID_SHELL); | |
178 | getApplication().enableMenuItem(TMenu.MID_EXIT); | |
179 | } | |
180 | ||
181 | } |