-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpinLoading.java
256 lines (208 loc) · 5.28 KB
/
SpinLoading.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
package com.banana.client.view.widget.components;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.IsWidget;
/**
* Loading creado: http://fgnass.github.com/spin.js
*
* @author Javier Arnáiz, javier[at]bananacampus.com
*
*/
public class SpinLoading {
private JavaScriptObject spin;
private IsWidget innerWidget;
/**
* Constructor con parametros por defecto
* @see SpinOpts
*/
public SpinLoading() {
this(new SpinOpts());
}
/**
* Construye un spin loading con las opciones especificadas por parametro
* @param opts {@link SpinOpts} opciones
*/
public SpinLoading(SpinOpts opts) {
spin = _init(opts.getLine(), opts.getLength(), opts.getWidth(),
opts.getRadius(), opts.getRotate(), opts.getColor(),
opts.getSpeed(), opts.getTrail(), opts.isShadow(),
opts.isHwaccel(), opts.getClassName(), opts.getzIndex(),
opts.getTop(), opts.getLeft());
}
/**
* Añade el cargando al widget pasado por parametros y lo añade al dom
* @param widget IsWidget
*/
public <T extends IsWidget & HasWidgets> IsWidget spin(T widget) {
// llamamos al método spin para el widget asociado
_spin(widget.asWidget().getElement());
// devolvemos un widget
Element element = Element.as(getInnerElement());
innerWidget = new FocusWidget(element) {
};
widget.add(innerWidget.asWidget());
return innerWidget;
}
/**
* Para el spin y lo elimina.
*/
public void stop() {
if (innerWidget != null) {
innerWidget.asWidget().removeFromParent();
}
_stop();
}
private native void _spin(JavaScriptObject element)/*-{
var spinner = [email protected]::spin;
spinner.spin(element);
}-*/;
private native void _stop()/*-{
var spinner = [email protected]::spin;
spinner.stop();
}-*/;
private native JavaScriptObject getInnerElement()/*-{
var spinner = [email protected]::spin;
return spinner.el;
}-*/;
private native JavaScriptObject _init(int lines, int length, int width,
int radius, int rotate, String color, double speed, double trail,
boolean shadow, boolean hwaccel, String className, double zIndex,
String top, String left) /*-{
return new $wnd.Spinner({
lines : lines,
length : length,
width : width,
radius : radius,
rotate : rotate,
color : color,
speed : speed,
trail : trail,
shadow : shadow,
hwaccel : hwaccel,
className : className,
zIndex : zIndex,
top : top,
left : left
});
}-*/;
/**
* Opciones que puede tener el spin loading
* @author Javier Arnáiz, javier[at]bananacampus.com
*
*/
public static class SpinOpts {
private int line, length, width, radius, rotate;
private String color, className, top, left;
private double zIndex, speed, trail;
private boolean shadow, hwaccel;
public SpinOpts() {
this(13, 7, 4, 10, 0, "#ffffff", "spinner", "auto", "auto", 1000, 1,
100, true, false);
}
public SpinOpts(int line, int length, int width, int radius,
int rotate, String color, String className, String top,
String left, double zIndex, double speed, double trail,
boolean shadow, boolean hwaccel) {
this.line = line;
this.length = length;
this.width = width;
this.radius = radius;
this.rotate = rotate;
this.zIndex = zIndex;
this.color = color;
this.className = className;
this.top = top;
this.left = left;
this.speed = speed;
this.trail = trail;
this.shadow = shadow;
this.hwaccel = hwaccel;
}
public int getLine() {
return line;
}
public void setLine(int line) {
this.line = line;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius = radius;
}
public int getRotate() {
return rotate;
}
public void setRotate(int rotate) {
this.rotate = rotate;
}
public double getzIndex() {
return zIndex;
}
public void setzIndex(int zIndex) {
this.zIndex = zIndex;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
public String getTop() {
return top;
}
public void setTop(String top) {
this.top = top;
}
public String getLeft() {
return left;
}
public void setLeft(String left) {
this.left = left;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public double getTrail() {
return trail;
}
public void setTrail(double trail) {
this.trail = trail;
}
public boolean isShadow() {
return shadow;
}
public void setShadow(boolean shadow) {
this.shadow = shadow;
}
public boolean isHwaccel() {
return hwaccel;
}
public void setHwaccel(boolean hwaccel) {
this.hwaccel = hwaccel;
}
}
}