2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 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
.event
.TResizeEvent
;
34 * TScrollableWindow is a convenience superclass for windows that have
37 public class TScrollableWindow
extends TWindow
implements Scrollable
{
40 * The horizontal scrollbar.
42 protected THScroller hScroller
= null;
45 * The vertical scrollbar.
47 protected TVScroller vScroller
= null;
50 * Place the scrollbars on the edge of this widget, and adjust bigChange
51 * to match the new size. This is called by onResize().
53 protected void placeScrollbars() {
54 if (hScroller
!= null) {
55 hScroller
.setY(getHeight() - 2);
56 hScroller
.setWidth(getWidth() - 3);
57 hScroller
.setBigChange(getWidth() - 3);
59 if (vScroller
!= null) {
60 vScroller
.setX(getWidth() - 2);
61 vScroller
.setHeight(getHeight() - 2);
62 vScroller
.setBigChange(getHeight() - 2);
67 * Recompute whatever data is displayed by this widget.
69 public void reflowData() {
70 // Default: nothing to do
74 * Handle window/screen resize events.
76 * @param event resize event
79 public void onResize(final TResizeEvent event
) {
80 if (event
.getType() == TResizeEvent
.Type
.WIDGET
) {
85 super.onResize(event
);
90 * Public constructor. Window will be located at (0, 0).
92 * @param application TApplication that manages this window
93 * @param title window title, will be centered along the top border
94 * @param width width of window
95 * @param height height of window
97 public TScrollableWindow(final TApplication application
, final String title
,
98 final int width
, final int height
) {
100 super(application
, title
, width
, height
);
104 * Public constructor. Window will be located at (0, 0).
106 * @param application TApplication that manages this window
107 * @param title window title, will be centered along the top border
108 * @param width width of window
109 * @param height height of window
110 * @param flags bitmask of RESIZABLE, CENTERED, or MODAL
112 public TScrollableWindow(final TApplication application
, final String title
,
113 final int width
, final int height
, final int flags
) {
115 super(application
, title
, width
, height
, flags
);
119 * Public constructor.
121 * @param application TApplication that manages this window
122 * @param title window title, will be centered along the top border
123 * @param x column relative to parent
124 * @param y row relative to parent
125 * @param width width of window
126 * @param height height of window
128 public TScrollableWindow(final TApplication application
, final String title
,
129 final int x
, final int y
, final int width
, final int height
) {
131 super(application
, title
, x
, y
, width
, height
);
135 * Public constructor.
137 * @param application TApplication that manages this window
138 * @param title window title, will be centered along the top border
139 * @param x column relative to parent
140 * @param y row relative to parent
141 * @param width width of window
142 * @param height height of window
143 * @param flags mask of RESIZABLE, CENTERED, or MODAL
145 public TScrollableWindow(final TApplication application
, final String title
,
146 final int x
, final int y
, final int width
, final int height
,
149 super(application
, title
, x
, y
, width
, height
, flags
);
153 * Get the horizontal scrollbar, or null if this Viewport does not
154 * support horizontal scrolling.
156 * @return the horizontal scrollbar
158 public THScroller
getHorizontalScroller() {
163 * Get the vertical scrollbar, or null if this Viewport does not support
164 * vertical scrolling.
166 * @return the vertical scrollbar
168 public TVScroller
getVerticalScroller() {
173 * Get the value that corresponds to being on the top edge of the
174 * vertical scroll bar.
176 * @return the scroll value
178 public int getTopValue() {
179 if (vScroller
== null) {
182 return vScroller
.getTopValue();
187 * Set the value that corresponds to being on the top edge of the
188 * vertical scroll bar.
190 * @param topValue the new scroll value
192 public void setTopValue(final int topValue
) {
193 if (vScroller
== null) {
196 vScroller
.setTopValue(topValue
);
201 * Get the value that corresponds to being on the bottom edge of the
202 * vertical scroll bar.
204 * @return the scroll value
206 public int getBottomValue() {
207 if (vScroller
== null) {
210 return vScroller
.getBottomValue();
215 * Set the value that corresponds to being on the bottom edge of the
216 * vertical scroll bar.
218 * @param bottomValue the new scroll value
220 public void setBottomValue(final int bottomValue
) {
221 if (vScroller
== null) {
224 vScroller
.setBottomValue(bottomValue
);
229 * Get current value of the vertical scroll.
231 * @return the scroll value
233 public int getVerticalValue() {
234 if (vScroller
== null) {
237 return vScroller
.getValue();
242 * Set current value of the vertical scroll.
244 * @param value the new scroll value
246 public void setVerticalValue(final int value
) {
247 if (vScroller
== null) {
250 vScroller
.setValue(value
);
255 * Get the increment for clicking on an arrow on the vertical scrollbar.
257 * @return the increment value
259 public int getVerticalSmallChange() {
260 if (vScroller
== null) {
263 return vScroller
.getSmallChange();
268 * Set the increment for clicking on an arrow on the vertical scrollbar.
270 * @param smallChange the new increment value
272 public void setVerticalSmallChange(final int smallChange
) {
273 if (vScroller
== null) {
276 vScroller
.setSmallChange(smallChange
);
281 * Get the increment for clicking in the bar between the box and an
282 * arrow on the vertical scrollbar.
284 * @return the increment value
286 public int getVerticalBigChange() {
287 if (vScroller
== null) {
290 return vScroller
.getBigChange();
295 * Set the increment for clicking in the bar between the box and an
296 * arrow on the vertical scrollbar.
298 * @param bigChange the new increment value
300 public void setVerticalBigChange(final int bigChange
) {
301 if (vScroller
== null) {
304 vScroller
.setBigChange(bigChange
);
309 * Perform a small step change up.
311 public void verticalDecrement() {
312 if (vScroller
== null) {
315 vScroller
.decrement();
320 * Perform a small step change down.
322 public void verticalIncrement() {
323 if (vScroller
== null) {
326 vScroller
.increment();
331 * Perform a big step change up.
333 public void bigVerticalDecrement() {
334 if (vScroller
== null) {
337 vScroller
.bigDecrement();
342 * Perform a big step change down.
344 public void bigVerticalIncrement() {
345 if (vScroller
== null) {
348 vScroller
.bigIncrement();
353 * Go to the top edge of the vertical scroller.
355 public void toTop() {
356 if (vScroller
== null) {
364 * Go to the bottom edge of the vertical scroller.
366 public void toBottom() {
367 if (vScroller
== null) {
370 vScroller
.toBottom();
375 * Get the value that corresponds to being on the left edge of the
376 * horizontal scroll bar.
378 * @return the scroll value
380 public int getLeftValue() {
381 if (hScroller
== null) {
384 return hScroller
.getLeftValue();
389 * Set the value that corresponds to being on the left edge of the
390 * horizontal scroll bar.
392 * @param leftValue the new scroll value
394 public void setLeftValue(final int leftValue
) {
395 if (hScroller
== null) {
398 hScroller
.setLeftValue(leftValue
);
403 * Get the value that corresponds to being on the right edge of the
404 * horizontal scroll bar.
406 * @return the scroll value
408 public int getRightValue() {
409 if (hScroller
== null) {
412 return hScroller
.getRightValue();
417 * Set the value that corresponds to being on the right edge of the
418 * horizontal scroll bar.
420 * @param rightValue the new scroll value
422 public void setRightValue(final int rightValue
) {
423 if (hScroller
== null) {
426 hScroller
.setRightValue(rightValue
);
431 * Get current value of the horizontal scroll.
433 * @return the scroll value
435 public int getHorizontalValue() {
436 if (hScroller
== null) {
439 return hScroller
.getValue();
444 * Set current value of the horizontal scroll.
446 * @param value the new scroll value
448 public void setHorizontalValue(final int value
) {
449 if (hScroller
== null) {
452 hScroller
.setValue(value
);
457 * Get the increment for clicking on an arrow on the horizontal
460 * @return the increment value
462 public int getHorizontalSmallChange() {
463 if (hScroller
== null) {
466 return hScroller
.getSmallChange();
471 * Set the increment for clicking on an arrow on the horizontal
474 * @param smallChange the new increment value
476 public void setHorizontalSmallChange(final int smallChange
) {
477 if (hScroller
== null) {
480 hScroller
.setSmallChange(smallChange
);
485 * Get the increment for clicking in the bar between the box and an
486 * arrow on the horizontal scrollbar.
488 * @return the increment value
490 public int getHorizontalBigChange() {
491 if (hScroller
== null) {
494 return hScroller
.getBigChange();
499 * Set the increment for clicking in the bar between the box and an
500 * arrow on the horizontal scrollbar.
502 * @param bigChange the new increment value
504 public void setHorizontalBigChange(final int bigChange
) {
505 if (hScroller
== null) {
508 hScroller
.setBigChange(bigChange
);
513 * Perform a small step change left.
515 public void horizontalDecrement() {
516 if (hScroller
== null) {
519 hScroller
.decrement();
524 * Perform a small step change right.
526 public void horizontalIncrement() {
527 if (hScroller
== null) {
530 hScroller
.increment();
535 * Perform a big step change left.
537 public void bigHorizontalDecrement() {
538 if (hScroller
== null) {
541 hScroller
.bigDecrement();
546 * Perform a big step change right.
548 public void bigHorizontalIncrement() {
549 if (hScroller
== null) {
552 hScroller
.bigIncrement();
557 * Go to the left edge of the horizontal scroller.
559 public void toLeft() {
560 if (hScroller
== null) {
568 * Go to the right edge of the horizontal scroller.
570 public void toRight() {
571 if (hScroller
== null) {
579 * Go to the top-left edge of the horizontal and vertical scrollers.
581 public void toHome() {
582 if (hScroller
!= null) {
585 if (vScroller
!= null) {
591 * Go to the bottom-right edge of the horizontal and vertical scrollers.
593 public void toEnd() {
594 if (hScroller
!= null) {
597 if (vScroller
!= null) {
598 vScroller
.toBottom();