2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 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]
31 import java
.util
.ResourceBundle
;
33 import jexer
.bits
.CellAttributes
;
34 import jexer
.event
.TResizeEvent
;
35 import jexer
.help
.THelpText
;
36 import jexer
.help
.Topic
;
41 public class THelpWindow
extends TWindow
{
46 private static final ResourceBundle i18n
= ResourceBundle
.getBundle(THelpWindow
.class.getName());
48 // ------------------------------------------------------------------------
49 // Constants --------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 // Default help topic keys. Note package private access.
53 static String HELP_HELP
= "Help On Help";
55 // ------------------------------------------------------------------------
56 // Variables --------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 * The help text window.
62 private THelpText helpText
;
65 * The "Contents" button.
67 private TButton contentsButton
;
72 private TButton indexButton
;
75 * The "Previous" button.
77 private TButton previousButton
;
82 private TButton closeButton
;
85 * The X position for the buttons.
87 private int buttonOffset
= 14;
89 // ------------------------------------------------------------------------
90 // Constructors -----------------------------------------------------------
91 // ------------------------------------------------------------------------
96 * @param application TApplication that manages this window
97 * @param topic the topic to start on
99 public THelpWindow(final TApplication application
, final String topic
) {
100 this (application
, application
.helpFile
.getTopic(topic
));
104 * Public constructor.
106 * @param application TApplication that manages this window
107 * @param topic the topic to start on
109 public THelpWindow(final TApplication application
, final Topic topic
) {
110 super(application
, i18n
.getString("windowTitle"),
111 1, 1, 78, 22, CENTERED
| RESIZABLE
);
113 setMinimumWindowHeight(16);
114 setMinimumWindowWidth(30);
116 helpText
= new THelpText(this, topic
, 1, 1,
117 getWidth() - buttonOffset
- 4, getHeight() - 4);
122 previousButton
= addButton(i18n
.getString("previousButton"),
123 getWidth() - buttonOffset
, 4,
126 if (application
.helpTopics
.size() > 1) {
127 Topic previous
= application
.helpTopics
.remove(
128 application
.helpTopics
.size() - 2);
129 application
.helpTopics
.remove(application
.
130 helpTopics
.size() - 1);
131 setHelpTopic(previous
);
136 contentsButton
= addButton(i18n
.getString("contentsButton"),
137 getWidth() - buttonOffset
, 6,
140 setHelpTopic(application
.helpFile
.getTableOfContents());
144 indexButton
= addButton(i18n
.getString("indexButton"),
145 getWidth() - buttonOffset
, 8,
148 setHelpTopic(application
.helpFile
.getIndex());
152 closeButton
= addButton(i18n
.getString("closeButton"),
153 getWidth() - buttonOffset
, 10,
156 // Don't copy anything, just close the window.
157 THelpWindow
.this.close();
161 // Save this for last: make the close button default action.
162 activate(closeButton
);
167 * Public constructor.
169 * @param application TApplication that manages this window
171 public THelpWindow(final TApplication application
) {
172 this(application
, HELP_HELP
);
175 // ------------------------------------------------------------------------
176 // Event handlers ---------------------------------------------------------
177 // ------------------------------------------------------------------------
180 * Handle window/screen resize events.
182 * @param event resize event
185 public void onResize(final TResizeEvent event
) {
186 if (event
.getType() == TResizeEvent
.Type
.WIDGET
) {
188 previousButton
.setX(getWidth() - buttonOffset
);
189 contentsButton
.setX(getWidth() - buttonOffset
);
190 indexButton
.setX(getWidth() - buttonOffset
);
191 closeButton
.setX(getWidth() - buttonOffset
);
193 helpText
.setDimensions(1, 1, getWidth() - buttonOffset
- 4,
195 helpText
.onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
196 helpText
.getWidth(), helpText
.getHeight()));
200 super.onResize(event
);
204 // ------------------------------------------------------------------------
205 // TWindow ----------------------------------------------------------------
206 // ------------------------------------------------------------------------
209 * Retrieve the background color.
211 * @return the background color
214 public final CellAttributes
getBackground() {
215 return getTheme().getColor("thelpwindow.background");
219 * Retrieve the border color.
221 * @return the border color
224 public CellAttributes
getBorder() {
226 return getTheme().getColor("thelpwindow.windowmove");
228 return getTheme().getColor("thelpwindow.background");
232 * Retrieve the color used by the window movement/sizing controls.
234 * @return the color used by the zoom box, resize bar, and close box
237 public CellAttributes
getBorderControls() {
238 return getTheme().getColor("thelpwindow.border");
241 // ------------------------------------------------------------------------
242 // THelpWindow ------------------------------------------------------------
243 // ------------------------------------------------------------------------
246 * Set the topic to display.
248 * @param topic the topic to display
250 public void setHelpTopic(final String topic
) {
251 setHelpTopic(getApplication().helpFile
.getTopic(topic
));
255 * Set the topic to display.
257 * @param topic the topic to display
259 private void setHelpTopic(final Topic topic
) {
260 boolean separator
= true;
261 if ((topic
== getApplication().helpFile
.getTableOfContents())
262 || (topic
== getApplication().helpFile
.getIndex())
267 getApplication().helpTopics
.add(topic
);
268 helpText
.setTopic(topic
, separator
);