1 package be
.nikiroo
.fanfix
.reader
.tui
;
3 import jexer
.TApplication
;
4 import jexer
.THScroller
;
6 import jexer
.TScrollableWindow
;
7 import jexer
.TVScroller
;
9 import jexer
.event
.TResizeEvent
;
11 public class TSimpleScrollableWindow
extends TScrollableWindow
{
12 protected TPanel mainPane
;
13 private int prevHorizontal
= -1;
14 private int prevVertical
= -1;
16 public TSimpleScrollableWindow(TApplication application
, String title
,
17 int width
, int height
) {
18 this(application
, title
, width
, height
, 0, 0, 0);
21 public TSimpleScrollableWindow(TApplication application
, String title
,
22 int width
, int height
, int flags
) {
23 this(application
, title
, width
, height
, flags
, 0, 0);
26 // 0 = none (so, no scrollbar)
27 public TSimpleScrollableWindow(TApplication application
, String title
,
28 int width
, int height
, int flags
, int realWidth
, int realHeight
) {
29 super(application
, title
, width
, height
, flags
);
31 mainPane
= new TPanel(this, 0, 0, 1, 1) {
34 for (TWidget children
: mainPane
.getChildren()) {
35 int y
= children
.getY() + children
.getHeight();
36 int x
= children
.getX() + children
.getWidth();
37 boolean visible
= (y
> getVerticalValue())
38 && (x
> getHorizontalValue());
39 children
.setVisible(visible
);
45 mainPane
.setWidth(getWidth());
46 mainPane
.setHeight(getHeight());
48 setRealWidth(realWidth
);
49 setRealHeight(realHeight
);
54 * The main pane on which you can add other widgets for this scrollable
57 * @return the main pane
59 public TPanel
getMainPane() {
63 public void setRealWidth(int realWidth
) {
65 if (hScroller
!= null) {
69 if (hScroller
== null) {
70 // size/position will be fixed by placeScrollbars()
71 hScroller
= new THScroller(this, 0, 0, 10);
73 hScroller
.setRightValue(realWidth
);
79 public void setRealHeight(int realHeight
) {
80 if (realHeight
<= 0) {
81 if (vScroller
!= null) {
85 if (vScroller
== null) {
86 // size/position will be fixed by placeScrollbars()
87 vScroller
= new TVScroller(this, 0, 0, 10);
89 vScroller
.setBottomValue(realHeight
);
96 public void onResize(TResizeEvent event
) {
97 super.onResize(event
);
98 mainPane
.setWidth(getWidth());
99 mainPane
.setHeight(getHeight());
100 mainPane
.onResize(event
);
104 public void reflowData() {
106 reflowData(getHorizontalValue(), getVerticalValue());
109 protected void reflowData(int totalX
, int totalY
) {
111 mainPane
.setX(-totalX
);
112 mainPane
.setY(-totalY
);
117 if (prevHorizontal
!= getHorizontalValue()
118 || prevVertical
!= getVerticalValue()) {
119 prevHorizontal
= getHorizontalValue();
120 prevVertical
= getVerticalValue();