|
@@ -10,83 +10,68 @@ |
10 |
10 |
|
|
11 |
11 |
|
import static com.google.gwt.dom.client.Style.*; |
12 |
12 |
|
|
13 |
|
- |
public class CommonElementHelper |
14 |
|
- |
{ |
|
13 |
+ |
public class CommonElementHelper { |
15 |
14 |
|
public static final String LAYOUT_OVERFLOW_HIDDEN = "litesoft-LayoutOverflowHidden"; |
16 |
15 |
|
public static final String LAYOUT_OVERFLOW_AUTO = "litesoft-LayoutOverflowAuto"; |
17 |
16 |
|
|
18 |
|
- |
public static String determineOverflowClass( boolean pHidden ) |
19 |
|
- |
{ |
|
17 |
+ |
public static String determineOverflowClass( boolean pHidden ) { |
20 |
18 |
|
return pHidden ? LAYOUT_OVERFLOW_HIDDEN : LAYOUT_OVERFLOW_AUTO; |
21 |
19 |
|
} |
22 |
20 |
|
|
23 |
|
- |
public static Element setOverflowClass( Element pElement, boolean pHidden ) |
24 |
|
- |
{ |
|
21 |
+ |
public static Element setOverflowClass( Element pElement, boolean pHidden ) { |
25 |
22 |
|
return setStyleClass( pElement, determineOverflowClass( pHidden ) ); |
26 |
23 |
|
} |
27 |
24 |
|
|
28 |
|
- |
public static Element setStyleClass( Element pElement, String pStyleClassName ) |
29 |
|
- |
{ |
30 |
|
- |
if ( null != (pStyleClassName = Strings.noEmpty( pStyleClassName )) ) |
31 |
|
- |
{ |
|
25 |
+ |
public static Element setStyleClass( Element pElement, String pStyleClassName ) { |
|
26 |
+ |
if ( null != (pStyleClassName = Strings.noEmpty( pStyleClassName )) ) { |
32 |
27 |
|
pElement.setClassName( pStyleClassName ); |
33 |
28 |
|
} |
34 |
29 |
|
return pElement; |
35 |
30 |
|
} |
36 |
31 |
|
|
37 |
|
- |
public static Element setTextAreaWordWrap( Element pElement, boolean pWrap ) |
38 |
|
- |
{ |
|
32 |
+ |
public static Element setTextAreaWordWrap( Element pElement, boolean pWrap ) { |
39 |
33 |
|
pElement.setPropertyString( "wrap", pWrap ? "soft" : "off" ); |
40 |
34 |
|
return setWhiteSpaceWrap( pElement, pWrap ); |
41 |
35 |
|
} |
42 |
36 |
|
|
43 |
|
- |
public static Element setWhiteSpaceWrap( Element pElement, boolean pWrap ) |
44 |
|
- |
{ |
|
37 |
+ |
public static Element setWhiteSpaceWrap( Element pElement, boolean pWrap ) { |
45 |
38 |
|
return setStyleProperty( pElement, "whiteSpace", pWrap ? "normal" : "nowrap" ); |
46 |
39 |
|
} |
47 |
40 |
|
|
48 |
|
- |
public static boolean isWhiteSpaceWrap( Element pElement ) |
49 |
|
- |
{ |
|
41 |
+ |
public static boolean isWhiteSpaceWrap( Element pElement ) { |
50 |
42 |
|
return !"nowrap".equals( pElement.getPropertyString( "whiteSpace" ) ); |
51 |
43 |
|
} |
52 |
44 |
|
|
53 |
|
- |
public static Element setDisplayTableCell( Element pElement ) |
54 |
|
- |
{ |
|
45 |
+ |
public static Element setDisplayTableCell( Element pElement ) { |
55 |
46 |
|
return setStyleProperty( pElement, "display", "table-cell" ); |
56 |
47 |
|
} |
57 |
48 |
|
|
58 |
|
- |
public static Element setPositionAbsolute( Element pElement ) |
59 |
|
- |
{ |
|
49 |
+ |
public static Element setPositionAbsolute( Element pElement ) { |
60 |
50 |
|
pElement.getStyle().setPosition( Position.ABSOLUTE ); |
61 |
51 |
|
return pElement; |
62 |
52 |
|
} |
63 |
53 |
|
|
64 |
|
- |
public static Element setPositionRelative( Element pElement ) |
65 |
|
- |
{ |
|
54 |
+ |
public static Element setPositionRelative( Element pElement ) { |
66 |
55 |
|
pElement.getStyle().setPosition( Position.RELATIVE ); |
67 |
56 |
|
return pElement; |
68 |
57 |
|
} |
69 |
58 |
|
|
70 |
|
- |
public static Element setTop( Element pElement, int pPX ) |
71 |
|
- |
{ |
|
59 |
+ |
public static Element setTop( Element pElement, int pPX ) { |
72 |
60 |
|
pElement.getStyle().setTop( pPX, Unit.PX ); |
73 |
61 |
|
return pElement; |
74 |
62 |
|
} |
75 |
63 |
|
|
76 |
|
- |
public static Element setLeft( Element pElement, int pPX ) |
77 |
|
- |
{ |
|
64 |
+ |
public static Element setLeft( Element pElement, int pPX ) { |
78 |
65 |
|
pElement.getStyle().setLeft( pPX, Unit.PX ); |
79 |
66 |
|
return pElement; |
80 |
67 |
|
} |
81 |
68 |
|
|
82 |
|
- |
public static Element setHeight( Element pElement, int pPX ) |
83 |
|
- |
{ |
|
69 |
+ |
public static Element setHeight( Element pElement, int pPX ) { |
84 |
70 |
|
pElement.getStyle().setHeight( pPX, Unit.PX ); |
85 |
71 |
|
return pElement; |
86 |
72 |
|
} |
87 |
73 |
|
|
88 |
|
- |
public static Element setWidth( Element pElement, int pPX ) |
89 |
|
- |
{ |
|
74 |
+ |
public static Element setWidth( Element pElement, int pPX ) { |
90 |
75 |
|
pElement.getStyle().setWidth( pPX, Unit.PX ); |
91 |
76 |
|
return pElement; |
92 |
77 |
|
} |
|
@@ -94,8 +79,7 @@ |
94 |
79 |
|
/** |
95 |
80 |
|
* @return pParent |
96 |
81 |
|
*/ |
97 |
|
- |
public static Element appendChild( Element pParent, Element pChild ) |
98 |
|
- |
{ |
|
82 |
+ |
public static Element appendChild( Element pParent, Element pChild ) { |
99 |
83 |
|
DOM.appendChild( pParent, pChild ); |
100 |
84 |
|
return pParent; |
101 |
85 |
|
} |
|
@@ -103,8 +87,7 @@ |
103 |
87 |
|
/** |
104 |
88 |
|
* @return pChild |
105 |
89 |
|
*/ |
106 |
|
- |
public static Element appendToParent( Element pChild, Element pParent ) |
107 |
|
- |
{ |
|
90 |
+ |
public static Element appendToParent( Element pChild, Element pParent ) { |
108 |
91 |
|
DOM.appendChild( pParent, pChild ); |
109 |
92 |
|
return pChild; |
110 |
93 |
|
} |
|
@@ -112,40 +95,34 @@ |
112 |
95 |
|
/** |
113 |
96 |
|
* @return Div |
114 |
97 |
|
*/ |
115 |
|
- |
public static Element createDiv( String pStyleClassName ) |
116 |
|
- |
{ |
|
98 |
+ |
public static Element createDiv( String pStyleClassName ) { |
117 |
99 |
|
return setStyleClass( DOM.createDiv(), pStyleClassName ); |
118 |
100 |
|
} |
119 |
101 |
|
|
120 |
102 |
|
/** |
121 |
103 |
|
* @return Table |
122 |
104 |
|
*/ |
123 |
|
- |
public static Element createTable( String pStyleClassName ) |
124 |
|
- |
{ |
|
105 |
+ |
public static Element createTable( String pStyleClassName ) { |
125 |
106 |
|
return setStyleClass( createTable(), pStyleClassName ); |
126 |
107 |
|
} |
127 |
108 |
|
|
128 |
|
- |
public static Element setImgSrc( Element pImg, String pUrl ) |
129 |
|
- |
{ |
|
109 |
+ |
public static Element setImgSrc( Element pImg, String pUrl ) { |
130 |
110 |
|
ImageElement.as( pImg ).setSrc( pUrl ); |
131 |
111 |
|
return pImg; |
132 |
112 |
|
} |
133 |
113 |
|
|
134 |
|
- |
public static void setTDalign( Element pTD, HasHorizontalAlignment.HorizontalAlignmentConstant pAlign ) |
135 |
|
- |
{ |
|
114 |
+ |
public static void setTDalign( Element pTD, HasHorizontalAlignment.HorizontalAlignmentConstant pAlign ) { |
136 |
115 |
|
TableCellElement.as( pTD ).setAlign( pAlign.getTextAlignString() ); |
137 |
116 |
|
} |
138 |
117 |
|
|
139 |
|
- |
public static void setTDvAlign( Element pTD, HasVerticalAlignment.VerticalAlignmentConstant pValign ) |
140 |
|
- |
{ |
|
118 |
+ |
public static void setTDvAlign( Element pTD, HasVerticalAlignment.VerticalAlignmentConstant pValign ) { |
141 |
119 |
|
TableCellElement.as( pTD ).setVAlign( pValign.getVerticalAlignString() ); |
142 |
120 |
|
} |
143 |
121 |
|
|
144 |
122 |
|
/** |
145 |
123 |
|
* @return Table |
146 |
124 |
|
*/ |
147 |
|
- |
public static Element createTable() |
148 |
|
- |
{ |
|
125 |
+ |
public static Element createTable() { |
149 |
126 |
|
TableElement zElement = Document.get().createTableElement(); |
150 |
127 |
|
zElement.setBorder( 0 ); |
151 |
128 |
|
zElement.setCellSpacing( 0 ); |
|
@@ -156,8 +133,7 @@ |
156 |
133 |
|
/** |
157 |
134 |
|
* @return TBody |
158 |
135 |
|
*/ |
159 |
|
- |
public static Element finishTableNgetTBody( Element pTable ) |
160 |
|
- |
{ |
|
136 |
+ |
public static Element finishTableNgetTBody( Element pTable ) { |
161 |
137 |
|
Element rv; |
162 |
138 |
|
appendChild( pTable, rv = DOM.createTBody() ); |
163 |
139 |
|
return rv; |
|
@@ -166,8 +142,7 @@ |
166 |
142 |
|
/** |
167 |
143 |
|
* @return TR |
168 |
144 |
|
*/ |
169 |
|
- |
public static Element finishTableNgetTR( Element pTable ) |
170 |
|
- |
{ |
|
145 |
+ |
public static Element finishTableNgetTR( Element pTable ) { |
171 |
146 |
|
Element rv; |
172 |
147 |
|
appendChild( finishTableNgetTBody( pTable ), rv = DOM.createTR() ); |
173 |
148 |
|
return rv; |
|
@@ -176,20 +151,17 @@ |
176 |
151 |
|
/** |
177 |
152 |
|
* @return TD |
178 |
153 |
|
*/ |
179 |
|
- |
public static Element finishTableNgetTD( Element pTable ) |
180 |
|
- |
{ |
|
154 |
+ |
public static Element finishTableNgetTD( Element pTable ) { |
181 |
155 |
|
Element rv; |
182 |
156 |
|
appendChild( finishTableNgetTR( pTable ), rv = DOM.createTD() ); |
183 |
157 |
|
return rv; |
184 |
158 |
|
} |
185 |
159 |
|
|
186 |
|
- |
public static int getOffsetHeight( Element pElement ) |
187 |
|
- |
{ |
|
160 |
+ |
public static int getOffsetHeight( Element pElement ) { |
188 |
161 |
|
return pElement.getOffsetHeight(); |
189 |
162 |
|
} |
190 |
163 |
|
|
191 |
|
- |
public static int getOffsetWidth( Element pElement ) |
192 |
|
- |
{ |
|
164 |
+ |
public static int getOffsetWidth( Element pElement ) { |
193 |
165 |
|
return pElement.getOffsetWidth(); |
194 |
166 |
|
} |
195 |
167 |
|
|
|
@@ -199,84 +171,70 @@ |
199 |
171 |
|
* @param element a DOM element |
200 |
172 |
|
* |
201 |
173 |
|
* @return the value of the tagName property, or null if |
202 |
|
- |
* <code>element</code> is null |
|
174 |
+ |
* <code>element</code> is null |
203 |
175 |
|
*/ |
204 |
176 |
|
public static native String getTagName( Element element ) /*-{ |
205 |
177 |
|
return element ? element.tagName : null; |
206 |
178 |
|
}-*/; |
207 |
179 |
|
|
208 |
|
- |
public static DIVconstrainer createDIVconstrainer() |
209 |
|
- |
{ |
|
180 |
+ |
public static DIVconstrainer createDIVconstrainer() { |
210 |
181 |
|
Element zTable = createTable(); |
211 |
182 |
|
Element zTR = finishTableNgetTR( zTable ); |
212 |
183 |
|
Element zTD = appendToParent( DOM.createTD(), zTR ); |
213 |
184 |
|
return new DIVconstrainer( zTable, zTD ); |
214 |
185 |
|
} |
215 |
186 |
|
|
216 |
|
- |
public static void forceNoMarginOrPadding( Element pElement ) |
217 |
|
- |
{ |
|
187 |
+ |
public static void forceNoMarginOrPadding( Element pElement ) { |
218 |
188 |
|
Style zStyle = pElement.getStyle(); |
219 |
189 |
|
zStyle.setMargin( 0, Unit.PX ); |
220 |
190 |
|
zStyle.setPadding( 0, Unit.PX ); |
221 |
191 |
|
} |
222 |
192 |
|
|
223 |
|
- |
public static void setOverflowAuto( com.google.gwt.dom.client.Element pElement ) |
224 |
|
- |
{ |
|
193 |
+ |
public static void setOverflowAuto( com.google.gwt.dom.client.Element pElement ) { |
225 |
194 |
|
setOverflow( pElement, Overflow.AUTO ); |
226 |
195 |
|
} |
227 |
196 |
|
|
228 |
|
- |
public static void setOverflowVisible( com.google.gwt.dom.client.Element pElement ) |
229 |
|
- |
{ |
|
197 |
+ |
public static void setOverflowVisible( com.google.gwt.dom.client.Element pElement ) { |
230 |
198 |
|
setOverflow( pElement, Overflow.VISIBLE ); |
231 |
199 |
|
} |
232 |
200 |
|
|
233 |
|
- |
public static void setOverflowHidden( com.google.gwt.dom.client.Element pElement ) |
234 |
|
- |
{ |
|
201 |
+ |
public static void setOverflowHidden( com.google.gwt.dom.client.Element pElement ) { |
235 |
202 |
|
setOverflow( pElement, Overflow.HIDDEN ); |
236 |
203 |
|
} |
237 |
204 |
|
|
238 |
|
- |
public static void setOverflowScroll( com.google.gwt.dom.client.Element pElement ) |
239 |
|
- |
{ |
|
205 |
+ |
public static void setOverflowScroll( com.google.gwt.dom.client.Element pElement ) { |
240 |
206 |
|
setOverflow( pElement, Overflow.SCROLL ); |
241 |
207 |
|
} |
242 |
208 |
|
|
243 |
|
- |
private static void setOverflow( com.google.gwt.dom.client.Element pElement, Overflow pToWhat ) |
244 |
|
- |
{ |
|
209 |
+ |
private static void setOverflow( com.google.gwt.dom.client.Element pElement, Overflow pToWhat ) { |
245 |
210 |
|
pElement.getStyle().setOverflow( pToWhat ); |
246 |
211 |
|
} |
247 |
212 |
|
|
248 |
|
- |
public static void hide( com.google.gwt.dom.client.Element pElement ) |
249 |
|
- |
{ |
|
213 |
+ |
public static void hide( com.google.gwt.dom.client.Element pElement ) { |
250 |
214 |
|
setHidden( pElement, true ); |
251 |
215 |
|
} |
252 |
216 |
|
|
253 |
|
- |
public static void unhide( com.google.gwt.dom.client.Element pElement ) |
254 |
|
- |
{ |
|
217 |
+ |
public static void unhide( com.google.gwt.dom.client.Element pElement ) { |
255 |
218 |
|
setHidden( pElement, false ); |
256 |
219 |
|
} |
257 |
220 |
|
|
258 |
|
- |
public static void setHidden( com.google.gwt.dom.client.Element pElement, boolean pHide ) |
259 |
|
- |
{ |
|
221 |
+ |
public static void setHidden( com.google.gwt.dom.client.Element pElement, boolean pHide ) { |
260 |
222 |
|
pElement.getStyle().setVisibility( pHide ? Visibility.HIDDEN : Visibility.VISIBLE ); |
261 |
223 |
|
} |
262 |
224 |
|
|
263 |
|
- |
public static boolean isHidden( com.google.gwt.dom.client.Element pElement ) |
264 |
|
- |
{ |
|
225 |
+ |
public static boolean isHidden( com.google.gwt.dom.client.Element pElement ) { |
265 |
226 |
|
return is( pElement.getStyle().getVisibility(), Visibility.HIDDEN ); |
266 |
227 |
|
} |
267 |
228 |
|
|
268 |
|
- |
public static boolean isVisible( com.google.gwt.dom.client.Element pElement ) |
269 |
|
- |
{ |
|
229 |
+ |
public static boolean isVisible( com.google.gwt.dom.client.Element pElement ) { |
270 |
230 |
|
return !is( pElement.getStyle().getDisplay(), Display.NONE ); |
271 |
231 |
|
} |
272 |
232 |
|
|
273 |
|
- |
private static boolean is( String pPropertyValue, HasCssName pExpected ) |
274 |
|
- |
{ |
|
233 |
+ |
private static boolean is( String pPropertyValue, HasCssName pExpected ) { |
275 |
234 |
|
return pExpected.getCssName().equals( pPropertyValue ); |
276 |
235 |
|
} |
277 |
236 |
|
|
278 |
|
- |
private static Element setStyleProperty( Element pElement, String pProperty, String pValue ) |
279 |
|
- |
{ |
|
237 |
+ |
private static Element setStyleProperty( Element pElement, String pProperty, String pValue ) { |
280 |
238 |
|
pElement.getStyle().setProperty( pProperty, pValue ); |
281 |
239 |
|
return pElement; |
282 |
240 |
|
} |