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 jexer
.THelpWindow
;
33 import jexer
.bits
.CellAttributes
;
34 import jexer
.bits
.StringUtils
;
35 import jexer
.event
.TKeypressEvent
;
36 import jexer
.event
.TMouseEvent
;
37 import static jexer
.TKeypress
.*;
40 * TWord contains either a string to display or a clickable link.
42 public class TWord
extends TWidget
{
44 // ------------------------------------------------------------------------
45 // Constants --------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
49 // Variables --------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * The word(s) to display.
58 * Link to another Topic.
62 // ------------------------------------------------------------------------
63 // Constructors -----------------------------------------------------------
64 // ------------------------------------------------------------------------
69 * @param words the words to display
70 * @param link link to other topic, or null
72 public TWord(final String words
, final Link link
) {
74 // TWord is created by THelpText before the TParagraph is belongs to
75 // is created, so pass null as parent for now.
76 super(null, 0, 0, StringUtils
.width(words
), 1);
81 // Don't make text-only words "active".
87 // ------------------------------------------------------------------------
88 // Event handlers ---------------------------------------------------------
89 // ------------------------------------------------------------------------
92 * Handle mouse press events.
94 * @param mouse mouse button press event
97 public void onMouseDown(final TMouseEvent mouse
) {
98 if (mouse
.isMouse1()) {
100 ((THelpWindow
) getWindow()).setHelpTopic(link
.getTopic());
108 * @param keypress keystroke event
111 public void onKeypress(final TKeypressEvent keypress
) {
112 if (keypress
.equals(kbEnter
)) {
114 ((THelpWindow
) getWindow()).setHelpTopic(link
.getTopic());
119 // ------------------------------------------------------------------------
120 // TWidget ----------------------------------------------------------------
121 // ------------------------------------------------------------------------
128 CellAttributes color
= getTheme().getColor("thelpwindow.text");
130 if (isAbsoluteActive()) {
131 color
= getTheme().getColor("thelpwindow.link.active");
133 color
= getTheme().getColor("thelpwindow.link");
136 putStringXY(0, 0, words
, color
);
139 // ------------------------------------------------------------------------
140 // TWord ------------------------------------------------------------------
141 // ------------------------------------------------------------------------