1 package be
.nikiroo
.jexer
;
5 import jexer
.TScrollableWidget
;
7 import jexer
.event
.TResizeEvent
;
8 import jexer
.event
.TResizeEvent
.Type
;
10 public class TSizeConstraint
{
11 private TWidget widget
;
17 // TODO: include in the window classes I use?
19 public TSizeConstraint(TWidget widget
, Integer x1
, Integer y1
, Integer x2
,
28 public TWidget
getWidget() {
32 public Integer
getX1() {
33 if (x1
!= null && x1
< 0)
34 return widget
.getParent().getWidth() + x1
;
38 public Integer
getY1() {
39 if (y1
!= null && y1
< 0)
40 return widget
.getParent().getHeight() + y1
;
44 public Integer
getX2() {
45 if (x2
!= null && x2
<= 0)
46 return widget
.getParent().getWidth() - 2 + x2
;
50 public Integer
getY2() {
51 if (y2
!= null && y2
<= 0)
52 return widget
.getParent().getHeight() - 2 + y2
;
56 // coordinates < 0 = from the other side
57 // x2 or y2 = 0 = max size
58 // coordinate NULL = do not work on that side at all
59 static public void setSize(List
<TSizeConstraint
> sizeConstraints
, TWidget child
,
60 Integer x1
, Integer y1
, Integer x2
, Integer y2
) {
61 sizeConstraints
.add(new TSizeConstraint(child
, x1
, y1
, x2
, y2
));
64 static public void resize(List
<TSizeConstraint
> sizeConstraints
) {
65 for (TSizeConstraint sizeConstraint
: sizeConstraints
) {
66 TWidget widget
= sizeConstraint
.getWidget();
67 Integer x1
= sizeConstraint
.getX1();
68 Integer y1
= sizeConstraint
.getY1();
69 Integer x2
= sizeConstraint
.getX2();
70 Integer y2
= sizeConstraint
.getY2();
78 widget
.setWidth(x2
- widget
.getX());
80 widget
.setHeight(y2
- widget
.getY());
82 // Resize the text field
83 // TODO: why setW/setH/reflow not enough for the scrollbars?
84 widget
.onResize(new TResizeEvent(Type
.WIDGET
, widget
.getWidth(),
87 if (widget
instanceof TScrollableWidget
) {
88 ((TScrollableWidget
) widget
).reflowData();