|
@@ -1,6 +1,7 @@ |
1 |
1 |
|
package org.litesoft.sandbox.csapp.client.widgets; |
2 |
2 |
|
|
3 |
3 |
|
import com.google.gwt.dom.client.*; |
|
4 |
+ |
import com.google.gwt.user.client.Element; |
4 |
5 |
|
import com.google.gwt.user.client.*; |
5 |
6 |
|
import com.google.gwt.user.client.ui.*; |
6 |
7 |
|
|
|
@@ -15,6 +16,7 @@ |
15 |
16 |
|
|
16 |
17 |
|
private String servletPath; |
17 |
18 |
|
private Timer timer; |
|
19 |
+ |
private boolean sized = false; |
18 |
20 |
|
|
19 |
21 |
|
public UploadWidget() |
20 |
22 |
|
{ |
|
@@ -23,25 +25,14 @@ |
23 |
25 |
|
|
24 |
26 |
|
public UploadWidget( ButtonBase illusionaryClickWidget ) |
25 |
27 |
|
{ |
26 |
|
- |
sizingWidget = createDivConstrainer( illusionaryClickWidget ); |
27 |
|
- |
initWidget( createStylingDiv( "UploadWidget", createDivConstrainer( createFlowPanel( sizingWidget, viewPort ) ) ) ); |
|
28 |
+ |
sizingWidget = createConstrainer( illusionaryClickWidget ); |
|
29 |
+ |
initWidget( createStylingDiv( "UploadWidget", createConstrainer( createFlowPanel( sizingWidget, viewPort ) ) ) ); |
28 |
30 |
|
|
29 |
31 |
|
//<div style="display: block; width: 100px; height: 20px; overflow: hidden;"> |
30 |
32 |
|
//<button style="width: 110px; height: 30px; position: relative; top: -5px; left: -5px;"><a href="javascript: void(0)">Upload File</a></button> |
31 |
33 |
|
//<input type="file" id="upload_input" name="upload" style="font-size: 50px; width: 120px; opacity: 0; filter:alpha(opacity: 0); position: relative; top: -40px;; left: -20px" /> |
32 |
34 |
|
//</div> |
33 |
35 |
|
|
34 |
|
- |
upload.setName( "UploadWidget" + instance++ ); |
35 |
|
- |
upload.getElement().setAttribute( "size", "1" ); |
36 |
|
- |
// upload.setSize( "400px", "400px" ); |
37 |
|
- |
// upload.getElement().getStyle().setFontSize( 200, Style.Unit.PX ); |
38 |
|
- |
// upload.getElement().getStyle().setOpacity( 0 ); // Todo: Verify Opacity & IE! |
39 |
|
- |
upload.getElement().getStyle().setCursor( Style.Cursor.POINTER ); |
40 |
|
- |
|
41 |
|
- |
// Because we're going to add a FileUpload widget, we'll need to set the |
42 |
|
- |
// form to use the POST method, and multipart MIME encoding. |
43 |
|
- |
formPanel.setEncoding( FormPanel.ENCODING_MULTIPART ); |
44 |
|
- |
formPanel.setMethod( FormPanel.METHOD_POST ); |
45 |
36 |
|
formPanel.addSubmitCompleteHandler( new FormPanel.SubmitCompleteHandler() |
46 |
37 |
|
{ |
47 |
38 |
|
@Override |
|
@@ -88,6 +79,7 @@ |
88 |
79 |
|
@Override |
89 |
80 |
|
public void run() |
90 |
81 |
|
{ |
|
82 |
+ |
sized = sized || size(); |
91 |
83 |
|
String filename = noEmpty( upload.getFilename() ); |
92 |
84 |
|
if ( filename != null ) |
93 |
85 |
|
{ |
|
@@ -98,6 +90,18 @@ |
98 |
90 |
|
}).scheduleRepeating( 250 ); |
99 |
91 |
|
} |
100 |
92 |
|
|
|
93 |
+ |
private boolean size() |
|
94 |
+ |
{ |
|
95 |
+ |
int width = sizingWidget.getOffsetWidth(); |
|
96 |
+ |
int height = sizingWidget.getOffsetHeight(); |
|
97 |
+ |
if ( (width < 16) || (height < 16) ) |
|
98 |
+ |
{ |
|
99 |
+ |
return false; |
|
100 |
+ |
} |
|
101 |
+ |
viewPort.setSize( width + "px", height + "px" ); |
|
102 |
+ |
return true; |
|
103 |
+ |
} |
|
104 |
+ |
|
101 |
105 |
|
private void resetUploadWidget() |
102 |
106 |
|
{ |
103 |
107 |
|
upload.setEnabled( true ); |
|
@@ -147,11 +151,11 @@ |
147 |
151 |
|
resetUploadWidget(); |
148 |
152 |
|
} |
149 |
153 |
|
|
150 |
|
- |
private static Widget createDivConstrainer( Widget widget ) |
|
154 |
+ |
private static Widget createConstrainer( Widget widget ) |
151 |
155 |
|
{ |
152 |
|
- |
HorizontalPanel divConstrainer = new HorizontalPanel(); |
153 |
|
- |
divConstrainer.add( widget ); |
154 |
|
- |
return divConstrainer; |
|
156 |
+ |
HorizontalPanel constrainer = new HorizontalPanel(); |
|
157 |
+ |
constrainer.add( widget ); |
|
158 |
+ |
return constrainer; |
155 |
159 |
|
} |
156 |
160 |
|
|
157 |
161 |
|
private static Widget createStylingDiv( String styleName, Widget widget ) |
|
@@ -174,34 +178,55 @@ |
174 |
178 |
|
private static SimplePanel createViewPort( Widget widget ) |
175 |
179 |
|
{ |
176 |
180 |
|
SimplePanel viewPort = new SimplePanel(); |
177 |
|
- |
Style style = viewPort.getElement().getStyle(); |
|
181 |
+ |
Element element = viewPort.getElement(); |
|
182 |
+ |
Style style = element.getStyle(); |
178 |
183 |
|
style.setPosition( Style.Position.ABSOLUTE ); |
|
184 |
+ |
style.setLeft( 0, Style.Unit.PX ); |
|
185 |
+ |
style.setTop( 0, Style.Unit.PX ); |
179 |
186 |
|
style.setOverflow( Style.Overflow.HIDDEN ); |
180 |
187 |
|
viewPort.setWidget( widget ); |
|
188 |
+ |
viewPort.setSize( "1px", "1px" ); |
181 |
189 |
|
return viewPort; |
182 |
190 |
|
} |
183 |
191 |
|
|
184 |
192 |
|
private static SimplePanel createFormFloater( Widget widget ) |
185 |
193 |
|
{ |
186 |
194 |
|
SimplePanel panel = new SimplePanel(); |
|
195 |
+ |
panel.setSize( "1000px", "400px" ); |
187 |
196 |
|
Style style = panel.getElement().getStyle(); |
188 |
|
- |
style.setRight( 0, Style.Unit.PX ); |
189 |
|
- |
style.setTop( 0, Style.Unit.PX ); |
190 |
|
- |
panel.setWidget( widget ); |
|
197 |
+ |
style.setPosition( Style.Position.RELATIVE ); |
|
198 |
+ |
style.setLeft( -600, Style.Unit.PX ); |
|
199 |
+ |
style.setTop( -5, Style.Unit.PX ); |
|
200 |
+ |
panel.setWidget( createConstrainer( widget ) ); |
191 |
201 |
|
return panel; |
192 |
202 |
|
} |
193 |
203 |
|
|
194 |
204 |
|
private static FormPanel createFormPanel( FileUpload upload ) |
195 |
205 |
|
{ |
196 |
206 |
|
FormPanel form = new FormPanel(); |
197 |
|
- |
form.getElement().getStyle().setMargin( 0, Style.Unit.PX ); |
198 |
207 |
|
form.add( upload ); |
|
208 |
+ |
Style style = form.getElement().getStyle(); |
|
209 |
+ |
style.setMargin( 0, Style.Unit.PX ); |
|
210 |
+ |
style.setPadding( 0, Style.Unit.PX ); |
|
211 |
+ |
// Because we're going to add a FileUpload widget, we'll need to set the |
|
212 |
+ |
// form to use the POST method, and multipart MIME encoding. |
|
213 |
+ |
form.setEncoding( FormPanel.ENCODING_MULTIPART ); |
|
214 |
+ |
form.setMethod( FormPanel.METHOD_POST ); |
199 |
215 |
|
return form; |
200 |
216 |
|
} |
201 |
217 |
|
|
202 |
|
- |
|
203 |
218 |
|
private static FileUpload createFileUploadWidget() |
204 |
219 |
|
{ |
205 |
|
- |
return new FileUpload(); |
|
220 |
+ |
FileUpload upload = new FileUpload(); |
|
221 |
+ |
upload.setName( "UploadWidget" + instance++ ); |
|
222 |
+ |
upload.getElement().setAttribute( "size", "1" ); |
|
223 |
+ |
upload.setSize( "1000px", "400px" ); |
|
224 |
+ |
Style style = upload.getElement().getStyle(); |
|
225 |
+ |
style.setMargin( 0, Style.Unit.PX ); |
|
226 |
+ |
style.setPadding( 0, Style.Unit.PX ); |
|
227 |
+ |
style.setBorderWidth( 0, Style.Unit.PX ); |
|
228 |
+ |
style.setFontSize( 200, Style.Unit.PX ); |
|
229 |
+ |
style.setOpacity( 0 ); // Tested w/ FireFox & IE8! |
|
230 |
+ |
return upload; |
206 |
231 |
|
} |
207 |
232 |
|
} |