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.utgb.client.ui;
26
27 import org.utgenome.gwt.widget.client.Style;
28
29 import com.google.gwt.user.client.ui.Composite;
30 import com.google.gwt.user.client.ui.FlexTable;
31 import com.google.gwt.user.client.ui.Label;
32
33 public class Border extends Composite {
34 public static final int UPPER = 0 << 1;
35 public static final int LOWER = 1 << 1;
36
37 protected static final int LEFT = 0;
38 protected static final int RIGHT = 1;
39
40 private final FlexTable layoutFrame = new FlexTable();
41 private final Label left = new Label();
42 private final Label center = new Label();
43 private final Label right = new Label();
44
45 private int cornerRadius;
46
47 public Border(int cornerRadius, int type, int borderFlag, String color) {
48 this(cornerRadius, type, borderFlag, color, 1f);
49 }
50
51 public Border(int cornerRadius, int type, int borderFlag, String color, float alpha) {
52 this.cornerRadius = cornerRadius;
53 assert (type == UPPER || type == LOWER);
54
55 setupWidget(type, borderFlag, color, alpha);
56 initWidget(layoutFrame);
57 }
58
59 protected void setupWidget(int type, int borderFlag, String color, float alpha) {
60 int index = 0;
61 if ((borderFlag & RoundCornerFrame.WEST) != 0)
62 layoutFrame.setWidget(0, index++, left);
63 layoutFrame.setWidget(0, index, center);
64 layoutFrame.getCellFormatter().setWidth(0, index, "100%");
65 index++;
66 if ((borderFlag & RoundCornerFrame.EAST) != 0)
67 layoutFrame.setWidget(0, index++, right);
68
69 layoutFrame.setCellPadding(0);
70 layoutFrame.setCellSpacing(0);
71 layoutFrame.setHeight(cornerRadius + "px");
72
73 left.setPixelSize(cornerRadius, cornerRadius);
74 right.setPixelSize(cornerRadius, cornerRadius);
75
76 Style.backgroundImage(center, "utgb-core/transparent?color=" + color + "&opacity=" + alpha);
77
78 Style.fontSize(center, 0);
79 center.setSize("100%", cornerRadius + "px");
80
81
82 setCorner(left, type | LEFT, cornerRadius, color, alpha);
83 setCorner(right, type | RIGHT, cornerRadius, color, alpha);
84
85 }
86
87 private void setCorner(Label l, int positionType, int cornerRadius, String color, float alpha) {
88 assert (positionType >= 0 && positionType <= 4);
89
90 int backgroundXPos = (positionType & RIGHT) != 0 ? -cornerRadius : 0;
91 int backgroundYPos = (positionType & LOWER) != 0 ? -cornerRadius : 0;
92
93 Style.backgroundImage(l, "utgb-core.roundcircle.action?color=" + color + "&size=" + cornerRadius + "&opacity=" + alpha);
94 Style.backgroundNoRepeat(l);
95 Style.backgroundPosition(l, backgroundXPos + "px " + backgroundYPos + "px");
96 Style.overflowHidden(l);
97 Style.fontSize(l, 0);
98
99 l.setPixelSize(cornerRadius, cornerRadius);
100
101 }
102
103 public void setWidth(int width) {
104 this.setWidth(width + "px");
105 }
106
107 }