litesoft
@ 947
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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
// 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 org.litesoft.core.delayed.*; import org.litesoft.logger.*; import org.litesoft.ui.*; import com.google.gwt.user.client.*; import com.google.gwt.user.client.ui.*; public abstract class AbstractSizeableWidget extends AbstractBrowserEventListenableWidget implements ISizeableWidget { public static final Logger LOGGER = LoggerFactory.getLogger( AbstractSizeableWidget.class ); // AbstractSizeableHelper: // // Outer Element: A Table to Constrain the Style Elements size (Must be the get/set Element) // Style Element: Normally the Div that is sandwiched between the inner and outer tables // Inner Element: Inner most Element abstract protected AbstractSizeableHelper getHelper(); /** * Override point called after the widget is effectively set-up */ protected void initialize() { } @Override protected Element getStyleElement() { return getHelper().getStyleElement(); } public void setSizingWorking() { } public boolean isSizingWorking() { return true; } /** * @return true if could do it (default is yes!) */ public boolean setPrefferredWidth() { return true; } /** * @return true if could do it (default is yes!) */ public boolean adjustWidthBy( int pDelta ) { return true; } @Override public ISizeableDimensionHelper getWidthHelper() { return getHelper().getWidthHelper(); } /** * @return true if could do it (default is yes!) */ public boolean setPrefferredHeight() { return true; } /** * @return true if could do it (default is yes!) */ public boolean adjustHeightBy( int pDelta ) { return true; } @Override public ISizeableDimensionHelper getHeightHelper() { return getHelper().getHeightHelper(); } @Override public void relayout() { Widget parent = getParent(); if ( parent instanceof SizeManaged ) { ((SizeManaged) parent).relayout(); } else { relayoutFromHereDown(); } } public boolean relayoutFromHereDown() { if ( !isAttached() ) { return true; } // More Sizing code Element zInnerElement = getHelper().getInnerElement(); int zCurInnerWidth = getWidthHelper().getDimension( zInnerElement ); int zCurInnerHeight = getHeightHelper().getDimension( zInnerElement ); int zCurOuterWidth = getOffsetWidth(); int zCurOuterHeight = getOffsetHeight(); if ( (zCurInnerWidth != 0) && (zCurInnerHeight != 0) && // (zCurOuterWidth != 0) && (zCurOuterHeight != 0) ) { if ( mRelayoutDelayedProcess != null ) { mRelayoutDelayedProcess.cancel(); mRelayoutDelayedProcess = null; } setWidth( "" + zCurOuterWidth ); setHeight( "" + zCurOuterHeight ); distributeToChildrenChangedWidth(); distributeToChildrenChangedHeight(); return true; } if ( mRelayoutDelayedProcess == null ) { mRelayoutDelayedProcess = new EscalatingProcess( new DelayedProcess() { @Override public boolean process() { return relayoutFromHereDown(); } } ); mRelayoutDelayedProcess.schedule(); } return false; } private EscalatingProcess mRelayoutDelayedProcess = null; protected void distributeToChildrenChangedWidth() { // For Overriding in Sizeables w/ children } protected void distributeToChildrenChangedHeight() { // For Overriding in Sizeables w/ children } protected void LLstretchable() { LLstretchableHorizontally(); LLstretchableVertically(); } public void LLstretchableVertically() { getHeightHelper().setStretchable( true ); } public void LLstretchableHorizontally() { getWidthHelper().setStretchable( true ); } /** * Sets the object's width. This width does not include decorations such as * border, margin, and padding. * * @param width the object's new width, in CSS units (e.g. "10px", "1em") */ @Override public void setWidth( String width ) { setDimensionFromWidget( getWidthHelper(), width ); } /** * Sets the object's height. This height does not include decorations such as * border, margin, and padding. * * @param height the object's new height, in CSS units (e.g. "10px", "1em") */ @Override public void setHeight( String height ) { setDimensionFromWidget( getHeightHelper(), height ); } /** * Sets the object's style name, removing all other styles. * <p/> * <p/> * The style name is the name referred to in CSS style rules (in HTML, this is * referred to as the element's "class"). By convention, style rules are of * the form <code>[project]-[widget]</code> (e.g. the {@link Button} * widget's style name is <code>.gwt-Button</code>). * </p> * <p/> * <p/> * For example, if a widget's style name is <code>myProject-MyWidget</code>, * then the style rule that applies to it will be * <code>.myProject-MyWidget</code>. Note the "dot" prefix -- this is * necessary because calling this method sets the underlying element's * <code>className</code> property. * </p> * <p/> * <p/> * An object may have any number of style names, which may be manipulated * using {@link #addStyleName(String)} and {@link #removeStyleName(String)}. * The attributes of all styles associated with the object will be applied to * it. * </p> * * @param style the style name to be added * * @see #addStyleName(String) * @see #removeStyleName(String) */ @Override public final void setStyleName( String style ) { throw new UnsupportedOperationException( "Must use addStyleName" ); } // /** // * Adds a set of events to be sunk by this object. Note that only // * {@link Widget widgets} may actually receive events, but can receive events // * from all objects contained within them. // * // * @param eventBitsToAdd a bitfield representing the set of events to be added // * to this element's event set // * // * @see com.google.gwt.user.client.Event // */ // public void sinkEvents( int eventBitsToAdd ) // { // Element element = getStyleElement(); // DOM.sinkEvents( element, eventBitsToAdd | DOM.getEventsSunk( element ) ); // } // // /** // * Removes a set of events from this object's event list. // * // * @param eventBitsToRemove a bitfield representing the set of events to be // * removed from this element's event set // * // * @see #sinkEvents // * @see com.google.gwt.user.client.Event // */ // public void unsinkEvents( int eventBitsToRemove ) // { // Element element = getStyleElement(); // DOM.sinkEvents( element, DOM.getEventsSunk( element ) & (~eventBitsToRemove) ); // } @Override public String toString() { String name = Objects.justClassName( getClass().getName() ); return name + ":" + super.toString(); } public void resized() { // for overriding, called by the helper after the widget is resized at the element level } private void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, String pSize_1D ) { int zSize_1D; try { zSize_1D = parse( pSize_1D ); } catch ( NumberFormatException e ) { throw new IllegalArgumentException( "Attempt to set" + pDimensionHelper.getWhat() + "( \"" + pSize_1D + "\" ) on " + getClass().getName() ); } setDimensionFromWidget( pDimensionHelper, zSize_1D ); } protected void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, int pSize_1D ) { pDimensionHelper.deligateSetDimensionFromWidget( pSize_1D ); } public static int parse( String pSize_1D ) throws NumberFormatException { String cleaned = Strings.deNull( pSize_1D ).trim(); String toParse = "0" + cleaned; if ( toParse.endsWith( "px" ) ) { toParse = toParse.substring( 0, toParse.length() - 2 ); } return Integer.parseInt( toParse ); } protected Element addParent( Element pParent, Element pChild ) { DOM.appendChild( pParent, pChild ); return pParent; } } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/AbstractSizeableWidget.java
Revision | Author | Commited | Message |
---|---|---|---|
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 |
811 Diff | GeorgeS | Sat 18 Aug, 2012 13:45:18 +0000 | |
802 Diff | GeorgeS | Wed 15 Aug, 2012 04:04:47 +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 |
23 Diff | GeorgeS | Wed 24 Feb, 2010 00:34:32 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |