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 import com.google.gwt.user.client.ui.SimplePanel;
33 import com.google.gwt.user.client.ui.Widget;
34 import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
35
36
37
38
39
40
41
42 public class RoundCornerFrame extends Composite {
43 private final FlexTable layoutFrame = new FlexTable();
44 private Border upperFrame;
45 private VerticalBar westBar;
46 private final FlexTable contentFrame = new FlexTable();
47 private SimplePanel panel = new SimplePanel();
48 private VerticalBar eastBar;
49 private Border lowerFrame;
50
51 public static final int NORTH = 1;
52 public static final int EAST = 1 << 1;
53 public static final int WEST = 1 << 2;
54 public static final int SOUTH = 1 << 3;
55 public static final int BORDER_FULL = NORTH | EAST | WEST | SOUTH;
56
57 private float alpha = 1f;
58 private int borderFlag;
59 private int cornerRadius;
60 private String borderColor;
61
62 public RoundCornerFrame(String color) {
63 this(color, 0.9f, 4);
64 }
65
66 public RoundCornerFrame(String color, float alpha, int borderWidth) {
67 this(color, alpha, borderWidth, BORDER_FULL);
68 }
69
70 public RoundCornerFrame(String color, float alpha, int borderWidth, int borderFlag) {
71 assert (borderFlag <= BORDER_FULL);
72
73 this.borderFlag = borderFlag;
74 this.cornerRadius = borderWidth;
75 this.borderColor = color;
76 this.alpha = alpha;
77
78 drawFrame();
79
80 initWidget(layoutFrame);
81 }
82
83 @Override
84 public void setWidget(Widget w) {
85 panel.setWidget(w);
86 }
87
88 public void setBorderWidth(int borderWidth) {
89 this.cornerRadius = borderWidth;
90 drawFrame();
91 }
92
93 private void drawFrame() {
94 layoutFrame.clear();
95 contentFrame.clear();
96
97 layoutFrame.setPixelSize(1, 1);
98
99 upperFrame = new Border(cornerRadius, Border.UPPER, borderFlag, borderColor, alpha);
100 lowerFrame = new Border(cornerRadius, Border.LOWER, borderFlag, borderColor, alpha);
101 westBar = new VerticalBar(cornerRadius, borderColor, alpha);
102 eastBar = new VerticalBar(cornerRadius, borderColor, alpha);
103
104 layoutFrame.setCellPadding(0);
105 layoutFrame.setCellSpacing(0);
106
107 contentFrame.setCellPadding(0);
108 contentFrame.setCellSpacing(0);
109 contentFrame.setSize("100%", "100%");
110
111 if ((borderFlag & NORTH) != 0) {
112 layoutFrame.setWidget(0, 0, upperFrame);
113 }
114
115 layoutFrame.setWidget(1, 0, contentFrame);
116 if ((borderFlag & WEST) != 0) {
117 contentFrame.setWidget(0, 0, westBar);
118 }
119
120 contentFrame.setWidget(0, 1, panel);
121 Style.semiTransparentBackground(panel, borderColor, alpha);
122
123 contentFrame.getCellFormatter().setWidth(0, 1, "100%");
124 if ((borderFlag & EAST) != 0) {
125 contentFrame.setWidget(0, 2, eastBar);
126 }
127
128 if ((borderFlag & SOUTH) != 0) {
129 layoutFrame.setWidget(2, 0, lowerFrame);
130 }
131
132 CellFormatter cf = layoutFrame.getCellFormatter();
133 cf.setHeight(0, 0, cornerRadius + "px");
134 cf.setHeight(1, 0, "100%");
135 cf.setWidth(1, 0, "100%");
136 cf.setHeight(2, 0, cornerRadius + "px");
137
138 }
139
140 public void setFrameColor(String color, float alpha) {
141 this.borderColor = color;
142 this.alpha = alpha;
143 drawFrame();
144 }
145
146 static class VerticalBar extends Label {
147 public VerticalBar(int radius, String color, float alpha) {
148 this.setSize(radius + "px", "100%");
149 Style.fontSize(this, 0);
150 Style.semiTransparentBackground(this, color, alpha);
151 }
152 }
153
154 }