1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.gwt.widget.client;
26
27 import com.google.gwt.user.client.ui.Composite;
28 import com.google.gwt.user.client.ui.FlexTable;
29 import com.google.gwt.user.client.ui.Label;
30
31
32
33
34
35
36
37 public class HorizontalBorder extends Composite {
38 public static final int UPPER = 0 << 1;
39 public static final int LOWER = 1 << 1;
40
41 protected static final int LEFT = 0;
42 protected static final int RIGHT = 1;
43
44 private final FlexTable layoutFrame = new FlexTable();
45 private final Label left = new Label();
46 private final Label center = new Label();
47 private final Label right = new Label();
48
49 private int cornerRadius;
50
51
52
53
54
55
56
57
58
59 public HorizontalBorder(int cornerRadius, int type, int borderFlag, String color) {
60 this.cornerRadius = cornerRadius;
61 assert (type == UPPER || type == LOWER);
62
63 setupWidget(type, borderFlag, color);
64 initWidget(layoutFrame);
65 }
66
67 protected void setupWidget(int type, int borderFlag, String color) {
68 int index = 0;
69 if ((borderFlag & FrameBorder.WEST) != 0)
70 layoutFrame.setWidget(0, index++, left);
71 layoutFrame.setWidget(0, index, center);
72 layoutFrame.getCellFormatter().setWidth(0, index, "100%");
73 index++;
74 if ((borderFlag & FrameBorder.EAST) != 0)
75 layoutFrame.setWidget(0, index++, right);
76
77 layoutFrame.setCellPadding(0);
78 layoutFrame.setCellSpacing(0);
79 layoutFrame.setHeight(cornerRadius + "px");
80
81 left.setPixelSize(cornerRadius, cornerRadius);
82 right.setPixelSize(cornerRadius, cornerRadius);
83
84 Style.backgroundColor(center, color);
85 Style.fontSize(center, 0);
86 center.setSize("100%", cornerRadius + "px");
87
88
89 setCorner(left, type | LEFT, cornerRadius, color);
90 setCorner(right, type | RIGHT, cornerRadius, color);
91
92 }
93
94 private void setCorner(Label label, int positionType, int cornerRadius, String color) {
95 assert (positionType >= 0 && positionType <= 4);
96
97 int backgroundXPos = (positionType & RIGHT) != 0 ? -cornerRadius : 0;
98 int backgroundYPos = (positionType & LOWER) != 0 ? -cornerRadius : 0;
99
100 Style.backgroundImage(label, "theme/default/rc" + cornerRadius + ((positionType & LOWER) != 0 ? "d" : "") + ".png");
101 Style.backgroundNoRepeat(label);
102 Style.backgroundPosition(label, backgroundXPos + "px " + backgroundYPos + "px");
103 Style.overflowHidden(label);
104 Style.fontSize(label, 0);
105
106 label.setPixelSize(cornerRadius, cornerRadius);
107
108 }
109
110 public void setWidth(int width) {
111 this.setWidth(width + "px");
112 }
113
114 }