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