1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.layout;
21
22 public class Box {
23
24 private Position position;
25 private Dimension dimension;
26
27 public Box(Position position, Dimension dimension) {
28 this.position = position;
29 this.dimension = dimension;
30 }
31
32 public Box(String string) {
33 int comma = string.indexOf(',');
34 if (comma >= 0) {
35 comma = string.indexOf(',', comma + 1);
36 if (comma >= 0) {
37 position = new Position(string.substring(0, comma));
38 dimension = new Dimension(string.substring(comma + 1));
39 return;
40 }
41 }
42 throw new IllegalArgumentException("Can't parse to a box: '" + string + "'");
43 }
44
45
46
47
48 public Measure getRight() {
49 return position.getLeft().add(dimension.getWidth());
50 }
51
52
53
54
55 public Measure getBottom() {
56 return position.getTop().add(dimension.getHeight());
57 }
58
59 public Measure getLeft() {
60 return position.getLeft();
61 }
62
63 public void setLeft(Measure left) {
64 position.setLeft(left);
65 }
66
67 public Measure getTop() {
68 return position.getTop();
69 }
70
71 public void setTop(Measure top) {
72 position.setTop(top);
73 }
74
75 public Measure getWidth() {
76 return dimension.getWidth();
77 }
78
79 public void setWidth(Measure width) {
80 dimension.setWidth(width);
81 }
82
83 public Measure getHeight() {
84 return dimension.getHeight();
85 }
86
87 public void setHeight(Measure height) {
88 dimension.setHeight(height);
89 }
90
91 @Override
92 public String toString() {
93 return new StringBuilder().append(position).append(',').append(dimension).toString();
94 }
95 }