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
.List
;
36 * TParagraph contains a reflowable collection of TWords, some of which are
39 public class TParagraph
extends TWidget
{
41 // ------------------------------------------------------------------------
42 // Constants --------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
46 // Variables --------------------------------------------------------------
47 // ------------------------------------------------------------------------
50 * Topic text and links converted to words.
52 private List
<TWord
> words
;
55 * If true, add one row to height as a paragraph separator. Note package
58 boolean separator
= true;
60 // ------------------------------------------------------------------------
61 // Constructors -----------------------------------------------------------
62 // ------------------------------------------------------------------------
67 * @param parent parent widget
68 * @param words the pieces of the paragraph to display
70 public TParagraph(final THelpText parent
, final List
<TWord
> words
) {
72 // Set parent and window
73 super(parent
, 0, 0, parent
.getWidth() - 1, 1);
76 for (TWord word
: words
) {
77 word
.setParent(this, false);
83 // ------------------------------------------------------------------------
84 // TWidget ----------------------------------------------------------------
85 // ------------------------------------------------------------------------
87 // ------------------------------------------------------------------------
88 // TParagraph -------------------------------------------------------------
89 // ------------------------------------------------------------------------
92 * Reposition the words in this paragraph to reflect the new width, and
93 * set the paragraph height.
95 public void reflowData() {
98 for (TWord word
: words
) {
99 if (x
+ word
.getWidth() >= getWidth()) {
105 x
+= word
.getWidth() + 1;
115 * Try to select a previous link.
117 * @return true if there was a previous link in this paragraph to select
119 public boolean up() {
120 if (words
.size() == 0) {
123 if (getActiveChild() == this) {
124 // No selectable links
127 TWord firstWord
= null;
128 TWord lastWord
= null;
129 for (TWord word
: words
) {
130 if (word
.isEnabled()) {
131 if (firstWord
== null) {
137 if (getActiveChild() == firstWord
) {
145 * Try to select a next link.
147 * @return true if there was a next link in this paragraph to select
149 public boolean down() {
150 if (words
.size() == 0) {
153 if (getActiveChild() == this) {
154 // No selectable links
157 TWord firstWord
= null;
158 TWord lastWord
= null;
159 for (TWord word
: words
) {
160 if (word
.isEnabled()) {
161 if (firstWord
== null) {
167 if (getActiveChild() == lastWord
) {