1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.ui.client.widgets; |
17 |
|
|
18 |
|
import com.google.gwt.dom.client.Element; |
19 |
|
import com.google.gwt.event.dom.client.BlurEvent; |
20 |
|
import com.google.gwt.event.dom.client.BlurHandler; |
21 |
|
import com.google.gwt.event.dom.client.FocusEvent; |
22 |
|
import com.google.gwt.event.dom.client.FocusHandler; |
23 |
|
import com.google.gwt.event.dom.client.MouseOutEvent; |
24 |
|
import com.google.gwt.event.dom.client.MouseOutHandler; |
25 |
|
import com.google.gwt.event.dom.client.MouseOverEvent; |
26 |
|
import com.google.gwt.event.dom.client.MouseOverHandler; |
27 |
|
import com.google.gwt.event.logical.shared.ValueChangeEvent; |
28 |
|
import com.google.gwt.user.client.ui.TextBox; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@author |
35 |
|
|
36 |
|
|
37 |
|
|
|
|
| 0% |
Uncovered Elements: 101 (101) |
Complexity: 34 |
Complexity Density: 0.54 |
|
38 |
|
public class KSTextBox extends TextBox implements HasWatermark{ |
39 |
|
private boolean hasWatermark = false; |
40 |
|
private boolean watermarkShowing = false; |
41 |
|
private String watermarkText; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
47 |
0
|
public KSTextBox() {... |
48 |
0
|
super(); |
49 |
0
|
setupDefaultStyle(); |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@param |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
57 |
0
|
public KSTextBox(Element element) {... |
58 |
0
|
super(element); |
59 |
0
|
setupDefaultStyle(); |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
66 |
0
|
private void setupDefaultStyle() {... |
67 |
0
|
addStyleName("KS-Textbox"); |
68 |
|
|
69 |
0
|
this.addBlurHandler(new BlurHandler(){ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0
|
public void onBlur(BlurEvent event) {... |
71 |
0
|
KSTextBox.this.removeStyleName("KS-Textbox-Focus"); |
72 |
|
|
73 |
|
} |
74 |
|
}); |
75 |
|
|
76 |
0
|
this.addFocusHandler(new FocusHandler(){ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0
|
public void onFocus(FocusEvent event) {... |
78 |
0
|
KSTextBox.this.addStyleName("KS-Textbox-Focus"); |
79 |
|
|
80 |
|
} |
81 |
|
}); |
82 |
|
|
83 |
0
|
this.addMouseOverHandler(new MouseOverHandler(){ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
0
|
public void onMouseOver(MouseOverEvent event) {... |
85 |
0
|
KSTextBox.this.addStyleName("KS-Textbox-Hover"); |
86 |
|
|
87 |
|
} |
88 |
|
}); |
89 |
|
|
90 |
0
|
this.addMouseOutHandler(new MouseOutHandler(){ |
91 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
0
|
public void onMouseOut(MouseOutEvent event) {... |
93 |
0
|
KSTextBox.this.removeStyleName("KS-Textbox-Hover"); |
94 |
|
|
95 |
|
} |
96 |
|
|
97 |
|
}); |
98 |
|
|
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 6 |
Complexity Density: 0.43 |
|
101 |
0
|
@Override... |
102 |
|
public void setWatermarkText(String text) { |
103 |
0
|
if(!hasWatermark){ |
104 |
0
|
hasWatermark = true; |
105 |
0
|
watermarkText = text; |
106 |
0
|
if(getText() == null || getText().isEmpty()){ |
107 |
0
|
addStyleName("watermark-text"); |
108 |
0
|
super.setText(watermarkText); |
109 |
0
|
watermarkShowing = true; |
110 |
|
} |
111 |
|
|
112 |
0
|
this.addFocusHandler(new FocusHandler(){ |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
114 |
0
|
@Override... |
115 |
|
public void onFocus(FocusEvent event) { |
116 |
0
|
if(watermarkShowing){ |
117 |
0
|
removeStyleName("watermark-text"); |
118 |
0
|
KSTextBox.super.setText(""); |
119 |
0
|
watermarkShowing = false; |
120 |
|
} |
121 |
|
} |
122 |
|
}); |
123 |
|
|
124 |
0
|
this.addBlurHandler(new BlurHandler(){ |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
126 |
0
|
@Override... |
127 |
|
public void onBlur(BlurEvent event) { |
128 |
0
|
if(getText() == null || getText().isEmpty()){ |
129 |
0
|
addStyleName("watermark-text"); |
130 |
0
|
KSTextBox.super.setText(watermarkText); |
131 |
0
|
watermarkShowing = true; |
132 |
|
} |
133 |
|
} |
134 |
|
}); |
135 |
|
} |
136 |
|
else{ |
137 |
0
|
watermarkText = text; |
138 |
0
|
if(getText() == null || getText().isEmpty()){ |
139 |
0
|
addStyleName("watermark-text"); |
140 |
0
|
KSTextBox.super.setText(watermarkText); |
141 |
0
|
watermarkShowing = true; |
142 |
|
} |
143 |
|
} |
144 |
|
} |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
146 |
0
|
@Override... |
147 |
|
public boolean hasWatermark(){ |
148 |
0
|
return hasWatermark; |
149 |
|
} |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
151 |
0
|
@Override... |
152 |
|
public boolean watermarkShowing() { |
153 |
0
|
return watermarkShowing; |
154 |
|
} |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
156 |
0
|
@Override... |
157 |
|
public String getText() { |
158 |
0
|
if(!watermarkShowing){ |
159 |
0
|
return super.getText(); |
160 |
|
} |
161 |
0
|
return null; |
162 |
|
} |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
164 |
0
|
@Override... |
165 |
|
public String getValue() { |
166 |
0
|
if(!watermarkShowing){ |
167 |
0
|
return super.getValue(); |
168 |
|
} |
169 |
0
|
return null; |
170 |
|
} |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 5 |
Complexity Density: 0.56 |
|
172 |
0
|
@Override... |
173 |
|
public void setValue(String value) { |
174 |
0
|
if(hasWatermark){ |
175 |
0
|
if(value == null || (value != null && value.isEmpty())){ |
176 |
0
|
super.setValue(watermarkText); |
177 |
0
|
addStyleName("watermark-text"); |
178 |
0
|
watermarkShowing = true; |
179 |
|
} |
180 |
|
else{ |
181 |
0
|
super.setValue(value); |
182 |
0
|
removeStyleName("watermark-text"); |
183 |
0
|
watermarkShowing = false; |
184 |
|
} |
185 |
|
} |
186 |
|
else{ |
187 |
0
|
super.setValue(value); |
188 |
|
} |
189 |
|
} |
190 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.45 |
|
191 |
0
|
@Override... |
192 |
|
public void setText(String text) { |
193 |
0
|
String oldValue = super.getText(); |
194 |
0
|
if(hasWatermark){ |
195 |
0
|
if(text == null || (text != null && text.isEmpty())){ |
196 |
0
|
super.setText(watermarkText); |
197 |
0
|
addStyleName("watermark-text"); |
198 |
0
|
watermarkShowing = true; |
199 |
|
} |
200 |
|
else{ |
201 |
0
|
super.setText(text); |
202 |
0
|
removeStyleName("watermark-text"); |
203 |
0
|
watermarkShowing = false; |
204 |
|
} |
205 |
|
} |
206 |
|
else{ |
207 |
0
|
super.setText(text); |
208 |
|
} |
209 |
0
|
ValueChangeEvent.fireIfNotEqual(this, oldValue, text); |
210 |
|
|
211 |
|
} |
212 |
|
} |