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
.TMouseEvent
;
10 import jexer
.event
.TResizeEvent
;
12 public class TSimpleScrollableWindow
extends TScrollableWindow
{
13 protected TPanel mainPane
;
14 private int prevHorizontal
= -1;
15 private int prevVertical
= -1;
17 public TSimpleScrollableWindow(TApplication application
, String title
,
18 int width
, int height
) {
19 this(application
, title
, width
, height
, 0, 0, 0);
22 public TSimpleScrollableWindow(TApplication application
, String title
,
23 int width
, int height
, int flags
) {
24 this(application
, title
, width
, height
, flags
, 0, 0);
27 // 0 = none (so, no scrollbar)
28 public TSimpleScrollableWindow(TApplication application
, String title
,
29 int width
, int height
, int flags
, int realWidth
, int realHeight
) {
30 super(application
, title
, width
, height
, flags
);
32 mainPane
= new TPanel(this, 0, 0, 1, 1) {
35 for (TWidget children
: mainPane
.getChildren()) {
36 int y
= children
.getY() + children
.getHeight();
37 int x
= children
.getX() + children
.getWidth();
38 boolean visible
= (y
> getVerticalValue())
39 && (x
> getHorizontalValue());
40 children
.setVisible(visible
);
46 mainPane
.setWidth(getWidth());
47 mainPane
.setHeight(getHeight());
49 setRealWidth(realWidth
);
50 setRealHeight(realHeight
);
55 * The main pane on which you can add other widgets for this scrollable
58 * @return the main pane
60 public TPanel
getMainPane() {
64 public void setRealWidth(int realWidth
) {
66 if (hScroller
!= null) {
70 if (hScroller
== null) {
71 // size/position will be fixed by placeScrollbars()
72 hScroller
= new THScroller(this, 0, 0, 10);
74 setRightValue(realWidth
);
80 public void setRealHeight(int realHeight
) {
81 if (realHeight
<= 0) {
82 if (vScroller
!= null) {
86 if (vScroller
== null) {
87 // size/position will be fixed by placeScrollbars()
88 vScroller
= new TVScroller(this, 0, 0, 10);
90 setBottomValue(realHeight
);
97 public void onResize(TResizeEvent event
) {
98 super.onResize(event
);
99 mainPane
.setWidth(getWidth());
100 mainPane
.setHeight(getHeight());
101 mainPane
.onResize(event
);
105 public void reflowData() {
107 reflowData(getHorizontalValue(), getVerticalValue());
110 protected void reflowData(int totalX
, int totalY
) {
112 mainPane
.setX(-totalX
);
113 mainPane
.setY(-totalY
);
117 public void onMouseUp(TMouseEvent mouse
) {
118 super.onMouseUp(mouse
);
120 // TODO: why? this should already be done by the scrollers
121 // it could also mean we do it twice if, somehow, it sometime works...
122 int mrx
= mouse
.getX();
123 int mry
= mouse
.getY();
125 int mx
= mouse
.getAbsoluteX();
126 int my
= mouse
.getAbsoluteY();
128 if (vScroller
!= null) {
129 mouse
.setX(mx
- vScroller
.getAbsoluteX());
130 mouse
.setY(my
- vScroller
.getAbsoluteY());
131 vScroller
.onMouseUp(mouse
);
133 if (hScroller
!= null) {
134 mouse
.setX(mx
- hScroller
.getAbsoluteX());
135 mouse
.setY(my
- hScroller
.getAbsoluteY());
136 hScroller
.onMouseUp(mouse
);
143 if (prevHorizontal
!= getHorizontalValue()
144 || prevVertical
!= getVerticalValue()) {
145 prevHorizontal
= getHorizontalValue();
146 prevVertical
= getVerticalValue();