litesoft
@ 948
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 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.client.widgets.nonpublic; import org.litesoft.commonfoundation.typeutils.*; import com.google.gwt.dom.client.*; import com.google.gwt.user.client.*; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.*; import static com.google.gwt.dom.client.Style.*; public class CommonElementHelper { public static final String LAYOUT_OVERFLOW_HIDDEN = "litesoft-LayoutOverflowHidden"; public static final String LAYOUT_OVERFLOW_AUTO = "litesoft-LayoutOverflowAuto"; public static String determineOverflowClass( boolean pHidden ) { return pHidden ? LAYOUT_OVERFLOW_HIDDEN : LAYOUT_OVERFLOW_AUTO; } public static Element setOverflowClass( Element pElement, boolean pHidden ) { return setStyleClass( pElement, determineOverflowClass( pHidden ) ); } public static Element setStyleClass( Element pElement, String pStyleClassName ) { if ( null != (pStyleClassName = Strings.noEmpty( pStyleClassName )) ) { pElement.setClassName( pStyleClassName ); } return pElement; } public static Element setTextAreaWordWrap( Element pElement, boolean pWrap ) { pElement.setPropertyString( "wrap", pWrap ? "soft" : "off" ); return setWhiteSpaceWrap( pElement, pWrap ); } public static Element setWhiteSpaceWrap( Element pElement, boolean pWrap ) { return setStyleProperty( pElement, "whiteSpace", pWrap ? "normal" : "nowrap" ); } public static boolean isWhiteSpaceWrap( Element pElement ) { return !"nowrap".equals( pElement.getPropertyString( "whiteSpace" ) ); } public static Element setDisplayTableCell( Element pElement ) { return setStyleProperty( pElement, "display", "table-cell" ); } public static Element setPositionAbsolute( Element pElement ) { pElement.getStyle().setPosition( Position.ABSOLUTE ); return pElement; } public static Element setPositionRelative( Element pElement ) { pElement.getStyle().setPosition( Position.RELATIVE ); return pElement; } public static Element setTop( Element pElement, int pPX ) { pElement.getStyle().setTop( pPX, Unit.PX ); return pElement; } public static Element setLeft( Element pElement, int pPX ) { pElement.getStyle().setLeft( pPX, Unit.PX ); return pElement; } public static Element setHeight( Element pElement, int pPX ) { pElement.getStyle().setHeight( pPX, Unit.PX ); return pElement; } public static Element setWidth( Element pElement, int pPX ) { pElement.getStyle().setWidth( pPX, Unit.PX ); return pElement; } /** * @return pParent */ public static Element appendChild( Element pParent, Element pChild ) { DOM.appendChild( pParent, pChild ); return pParent; } /** * @return pChild */ public static Element appendToParent( Element pChild, Element pParent ) { DOM.appendChild( pParent, pChild ); return pChild; } /** * @return Div */ public static Element createDiv( String pStyleClassName ) { return setStyleClass( DOM.createDiv(), pStyleClassName ); } /** * @return Table */ public static Element createTable( String pStyleClassName ) { return setStyleClass( createTable(), pStyleClassName ); } public static Element setImgSrc( Element pImg, String pUrl ) { ImageElement.as( pImg ).setSrc( pUrl ); return pImg; } public static void setTDalign( Element pTD, HasHorizontalAlignment.HorizontalAlignmentConstant pAlign ) { TableCellElement.as( pTD ).setAlign( pAlign.getTextAlignString() ); } public static void setTDvAlign( Element pTD, HasVerticalAlignment.VerticalAlignmentConstant pValign ) { TableCellElement.as( pTD ).setVAlign( pValign.getVerticalAlignString() ); } /** * @return Table */ public static Element createTable() { TableElement zElement = Document.get().createTableElement(); zElement.setBorder( 0 ); zElement.setCellSpacing( 0 ); zElement.setCellPadding( 0 ); return zElement.cast(); } /** * @return TBody */ public static Element finishTableNgetTBody( Element pTable ) { Element rv; appendChild( pTable, rv = DOM.createTBody() ); return rv; } /** * @return TR */ public static Element finishTableNgetTR( Element pTable ) { Element rv; appendChild( finishTableNgetTBody( pTable ), rv = DOM.createTR() ); return rv; } /** * @return TD */ public static Element finishTableNgetTD( Element pTable ) { Element rv; appendChild( finishTableNgetTR( pTable ), rv = DOM.createTD() ); return rv; } public static int getOffsetHeight( Element pElement ) { return pElement.getOffsetHeight(); } public static int getOffsetWidth( Element pElement ) { return pElement.getOffsetWidth(); } /** * Get the HTML tag name. * * @param element a DOM element * * @return the value of the tagName property, or null if * <code>element</code> is null */ public static native String getTagName( Element element ) /*-{ return element ? element.tagName : null; }-*/; public static DIVconstrainer createDIVconstrainer() { Element zTable = createTable(); Element zTR = finishTableNgetTR( zTable ); Element zTD = appendToParent( DOM.createTD(), zTR ); return new DIVconstrainer( zTable, zTD ); } public static void forceNoMarginOrPadding( Element pElement ) { Style zStyle = pElement.getStyle(); zStyle.setMargin( 0, Unit.PX ); zStyle.setPadding( 0, Unit.PX ); } public static void setOverflowAuto( com.google.gwt.dom.client.Element pElement ) { setOverflow( pElement, Overflow.AUTO ); } public static void setOverflowVisible( com.google.gwt.dom.client.Element pElement ) { setOverflow( pElement, Overflow.VISIBLE ); } public static void setOverflowHidden( com.google.gwt.dom.client.Element pElement ) { setOverflow( pElement, Overflow.HIDDEN ); } public static void setOverflowScroll( com.google.gwt.dom.client.Element pElement ) { setOverflow( pElement, Overflow.SCROLL ); } private static void setOverflow( com.google.gwt.dom.client.Element pElement, Overflow pToWhat ) { pElement.getStyle().setOverflow( pToWhat ); } public static void hide( com.google.gwt.dom.client.Element pElement ) { setHidden( pElement, true ); } public static void unhide( com.google.gwt.dom.client.Element pElement ) { setHidden( pElement, false ); } public static void setHidden( com.google.gwt.dom.client.Element pElement, boolean pHide ) { pElement.getStyle().setVisibility( pHide ? Visibility.HIDDEN : Visibility.VISIBLE ); } public static boolean isHidden( com.google.gwt.dom.client.Element pElement ) { return is( pElement.getStyle().getVisibility(), Visibility.HIDDEN ); } public static boolean isVisible( com.google.gwt.dom.client.Element pElement ) { return !is( pElement.getStyle().getDisplay(), Display.NONE ); } private static boolean is( String pPropertyValue, HasCssName pExpected ) { return pExpected.getCssName().equals( pPropertyValue ); } private static Element setStyleProperty( Element pElement, String pProperty, String pValue ) { pElement.getStyle().setProperty( pProperty, pValue ); return pElement; } } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/CommonElementHelper.java
Revision | Author | Commited | Message |
---|---|---|---|
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
801 Diff | GeorgeS | Wed 15 Aug, 2012 03:59:02 +0000 | |
243 Diff | GeorgeS | Sun 05 Jun, 2011 20:29:12 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |