Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/AbstractSizeableWidget.java

Diff revisions: vs.
  @@ -1,274 +1,273 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.client.widgets.nonpublic;
3 -
4 - import org.litesoft.commonfoundation.base.*;
5 - import org.litesoft.commonfoundation.typeutils.*;
6 - import org.litesoft.core.delayed.*;
7 - import org.litesoft.logger.*;
8 - import org.litesoft.ui.*;
9 -
10 - import com.google.gwt.user.client.*;
11 - import com.google.gwt.user.client.ui.*;
12 -
13 - public abstract class AbstractSizeableWidget extends AbstractBrowserEventListenableWidget implements ISizeableWidget {
14 - public static final Logger LOGGER = LoggerFactory.getLogger( AbstractSizeableWidget.class );
15 -
16 - // AbstractSizeableHelper:
17 - //
18 - // Outer Element: A Table to Constrain the Style Elements size (Must be the get/set Element)
19 - // Style Element: Normally the Div that is sandwiched between the inner and outer tables
20 - // Inner Element: Inner most Element
21 -
22 - abstract protected AbstractSizeableHelper getHelper();
23 -
24 - /**
25 - * Override point called after the widget is effectively set-up
26 - */
27 - protected void initialize() {
28 - }
29 -
30 - @Override
31 - protected Element getStyleElement() {
32 - return getHelper().getStyleElement();
33 - }
34 -
35 - public void setSizingWorking() {
36 - }
37 -
38 - public boolean isSizingWorking() {
39 - return true;
40 - }
41 -
42 - /**
43 - * @return true if could do it (default is yes!)
44 - */
45 - public boolean setPrefferredWidth() {
46 - return true;
47 - }
48 -
49 - /**
50 - * @return true if could do it (default is yes!)
51 - */
52 - public boolean adjustWidthBy( int pDelta ) {
53 - return true;
54 - }
55 -
56 - @Override
57 - public ISizeableDimensionHelper getWidthHelper() {
58 - return getHelper().getWidthHelper();
59 - }
60 -
61 - /**
62 - * @return true if could do it (default is yes!)
63 - */
64 - public boolean setPrefferredHeight() {
65 - return true;
66 - }
67 -
68 - /**
69 - * @return true if could do it (default is yes!)
70 - */
71 - public boolean adjustHeightBy( int pDelta ) {
72 - return true;
73 - }
74 -
75 - @Override
76 - public ISizeableDimensionHelper getHeightHelper() {
77 - return getHelper().getHeightHelper();
78 - }
79 -
80 - @Override
81 - public void relayout() {
82 - Widget parent = getParent();
83 - if ( parent instanceof SizeManaged ) {
84 - ((SizeManaged) parent).relayout();
85 - } else {
86 - relayoutFromHereDown();
87 - }
88 - }
89 -
90 - public boolean relayoutFromHereDown() {
91 - if ( !isAttached() ) {
92 - return true;
93 - }
94 - // More Sizing code
95 - Element zInnerElement = getHelper().getInnerElement();
96 - int zCurInnerWidth = getWidthHelper().getDimension( zInnerElement );
97 - int zCurInnerHeight = getHeightHelper().getDimension( zInnerElement );
98 - int zCurOuterWidth = getOffsetWidth();
99 - int zCurOuterHeight = getOffsetHeight();
100 - if ( (zCurInnerWidth != 0) && (zCurInnerHeight != 0) && //
101 - (zCurOuterWidth != 0) && (zCurOuterHeight != 0) ) {
102 - if ( mRelayoutDelayedProcess != null ) {
103 - mRelayoutDelayedProcess.cancel();
104 - mRelayoutDelayedProcess = null;
105 - }
106 - setWidth( "" + zCurOuterWidth );
107 - setHeight( "" + zCurOuterHeight );
108 - distributeToChildrenChangedWidth();
109 - distributeToChildrenChangedHeight();
110 - return true;
111 - }
112 - if ( mRelayoutDelayedProcess == null ) {
113 - mRelayoutDelayedProcess = new EscalatingProcess( new DelayedProcess() {
114 - @Override
115 - public boolean process() {
116 - return relayoutFromHereDown();
117 - }
118 - } );
119 - mRelayoutDelayedProcess.schedule();
120 - }
121 - return false;
122 - }
123 -
124 - private EscalatingProcess mRelayoutDelayedProcess = null;
125 -
126 - protected void distributeToChildrenChangedWidth() {
127 - // For Overriding in Sizeables w/ children
128 - }
129 -
130 - protected void distributeToChildrenChangedHeight() {
131 - // For Overriding in Sizeables w/ children
132 - }
133 -
134 - protected void LLstretchable() {
135 - LLstretchableHorizontally();
136 - LLstretchableVertically();
137 - }
138 -
139 - public void LLstretchableVertically() {
140 - getHeightHelper().setStretchable( true );
141 - }
142 -
143 - public void LLstretchableHorizontally() {
144 - getWidthHelper().setStretchable( true );
145 - }
146 -
147 - /**
148 - * Sets the object's width. This width does not include decorations such as
149 - * border, margin, and padding.
150 - *
151 - * @param width the object's new width, in CSS units (e.g. "10px", "1em")
152 - */
153 - @Override
154 - public void setWidth( String width ) {
155 - setDimensionFromWidget( getWidthHelper(), width );
156 - }
157 -
158 - /**
159 - * Sets the object's height. This height does not include decorations such as
160 - * border, margin, and padding.
161 - *
162 - * @param height the object's new height, in CSS units (e.g. "10px", "1em")
163 - */
164 - @Override
165 - public void setHeight( String height ) {
166 - setDimensionFromWidget( getHeightHelper(), height );
167 - }
168 -
169 - /**
170 - * Sets the object's style name, removing all other styles.
171 - * <p/>
172 - * <p/>
173 - * The style name is the name referred to in CSS style rules (in HTML, this is
174 - * referred to as the element's "class"). By convention, style rules are of
175 - * the form <code>[project]-[widget]</code> (e.g. the {@link Button}
176 - * widget's style name is <code>.gwt-Button</code>).
177 - * </p>
178 - * <p/>
179 - * <p/>
180 - * For example, if a widget's style name is <code>myProject-MyWidget</code>,
181 - * then the style rule that applies to it will be
182 - * <code>.myProject-MyWidget</code>. Note the "dot" prefix -- this is
183 - * necessary because calling this method sets the underlying element's
184 - * <code>className</code> property.
185 - * </p>
186 - * <p/>
187 - * <p/>
188 - * An object may have any number of style names, which may be manipulated
189 - * using {@link #addStyleName(String)} and {@link #removeStyleName(String)}.
190 - * The attributes of all styles associated with the object will be applied to
191 - * it.
192 - * </p>
193 - *
194 - * @param style the style name to be added
195 - *
196 - * @see #addStyleName(String)
197 - * @see #removeStyleName(String)
198 - */
199 - @Override
200 - public final void setStyleName( String style ) {
201 - throw new UnsupportedOperationException( "Must use addStyleName" );
202 - }
203 -
204 - // /**
205 - // * Adds a set of events to be sunk by this object. Note that only
206 - // * {@link Widget widgets} may actually receive events, but can receive events
207 - // * from all objects contained within them.
208 - // *
209 - // * @param eventBitsToAdd a bitfield representing the set of events to be added
210 - // * to this element's event set
211 - // *
212 - // * @see com.google.gwt.user.client.Event
213 - // */
214 - // public void sinkEvents( int eventBitsToAdd )
215 - // {
216 - // Element element = getStyleElement();
217 - // DOM.sinkEvents( element, eventBitsToAdd | DOM.getEventsSunk( element ) );
218 - // }
219 - //
220 - // /**
221 - // * Removes a set of events from this object's event list.
222 - // *
223 - // * @param eventBitsToRemove a bitfield representing the set of events to be
224 - // * removed from this element's event set
225 - // *
226 - // * @see #sinkEvents
227 - // * @see com.google.gwt.user.client.Event
228 - // */
229 - // public void unsinkEvents( int eventBitsToRemove )
230 - // {
231 - // Element element = getStyleElement();
232 - // DOM.sinkEvents( element, DOM.getEventsSunk( element ) & (~eventBitsToRemove) );
233 - // }
234 -
235 - @Override
236 - public String toString() {
237 - String name = ClassName.simple( this );
238 - return name + ":" + super.toString();
239 - }
240 -
241 - public void resized() {
242 - // for overriding, called by the helper after the widget is resized at the element level
243 - }
244 -
245 - private void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, String pSize_1D ) {
246 - int zSize_1D;
247 - try {
248 - zSize_1D = parse( pSize_1D );
249 - }
250 - catch ( NumberFormatException e ) {
251 - throw new IllegalArgumentException( "Attempt to set" + pDimensionHelper.getWhat() + "( \"" + pSize_1D + "\" ) on " + getClass().getName() );
252 - }
253 - setDimensionFromWidget( pDimensionHelper, zSize_1D );
254 - }
255 -
256 - protected void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, int pSize_1D ) {
257 - pDimensionHelper.deligateSetDimensionFromWidget( pSize_1D );
258 - }
259 -
260 - public static int parse( String pSize_1D )
261 - throws NumberFormatException {
262 - String cleaned = Strings.deNull( pSize_1D ).trim();
263 - String toParse = "0" + cleaned;
264 - if ( toParse.endsWith( "px" ) ) {
265 - toParse = toParse.substring( 0, toParse.length() - 2 );
266 - }
267 - return Integer.parseInt( toParse );
268 - }
269 -
270 - protected Element addParent( Element pParent, Element pChild ) {
271 - DOM.appendChild( pParent, pChild );
272 - return pParent;
273 - }
274 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.client.widgets.nonpublic;
3 +
4 + import org.litesoft.commonfoundation.base.*;
5 + import org.litesoft.core.delayed.*;
6 + import org.litesoft.logger.*;
7 + import org.litesoft.ui.*;
8 +
9 + import com.google.gwt.user.client.*;
10 + import com.google.gwt.user.client.ui.*;
11 +
12 + public abstract class AbstractSizeableWidget extends AbstractBrowserEventListenableWidget implements ISizeableWidget {
13 + public static final Logger LOGGER = LoggerFactory.getLogger( AbstractSizeableWidget.class );
14 +
15 + // AbstractSizeableHelper:
16 + //
17 + // Outer Element: A Table to Constrain the Style Elements size (Must be the get/set Element)
18 + // Style Element: Normally the Div that is sandwiched between the inner and outer tables
19 + // Inner Element: Inner most Element
20 +
21 + abstract protected AbstractSizeableHelper getHelper();
22 +
23 + /**
24 + * Override point called after the widget is effectively set-up
25 + */
26 + protected void initialize() {
27 + }
28 +
29 + @Override
30 + protected Element getStyleElement() {
31 + return getHelper().getStyleElement();
32 + }
33 +
34 + public void setSizingWorking() {
35 + }
36 +
37 + public boolean isSizingWorking() {
38 + return true;
39 + }
40 +
41 + /**
42 + * @return true if could do it (default is yes!)
43 + */
44 + public boolean setPrefferredWidth() {
45 + return true;
46 + }
47 +
48 + /**
49 + * @return true if could do it (default is yes!)
50 + */
51 + public boolean adjustWidthBy( int pDelta ) {
52 + return true;
53 + }
54 +
55 + @Override
56 + public ISizeableDimensionHelper getWidthHelper() {
57 + return getHelper().getWidthHelper();
58 + }
59 +
60 + /**
61 + * @return true if could do it (default is yes!)
62 + */
63 + public boolean setPrefferredHeight() {
64 + return true;
65 + }
66 +
67 + /**
68 + * @return true if could do it (default is yes!)
69 + */
70 + public boolean adjustHeightBy( int pDelta ) {
71 + return true;
72 + }
73 +
74 + @Override
75 + public ISizeableDimensionHelper getHeightHelper() {
76 + return getHelper().getHeightHelper();
77 + }
78 +
79 + @Override
80 + public void relayout() {
81 + Widget parent = getParent();
82 + if ( parent instanceof SizeManaged ) {
83 + ((SizeManaged) parent).relayout();
84 + } else {
85 + relayoutFromHereDown();
86 + }
87 + }
88 +
89 + public boolean relayoutFromHereDown() {
90 + if ( !isAttached() ) {
91 + return true;
92 + }
93 + // More Sizing code
94 + Element zInnerElement = getHelper().getInnerElement();
95 + int zCurInnerWidth = getWidthHelper().getDimension( zInnerElement );
96 + int zCurInnerHeight = getHeightHelper().getDimension( zInnerElement );
97 + int zCurOuterWidth = getOffsetWidth();
98 + int zCurOuterHeight = getOffsetHeight();
99 + if ( (zCurInnerWidth != 0) && (zCurInnerHeight != 0) && //
100 + (zCurOuterWidth != 0) && (zCurOuterHeight != 0) ) {
101 + if ( mRelayoutDelayedProcess != null ) {
102 + mRelayoutDelayedProcess.cancel();
103 + mRelayoutDelayedProcess = null;
104 + }
105 + setWidth( "" + zCurOuterWidth );
106 + setHeight( "" + zCurOuterHeight );
107 + distributeToChildrenChangedWidth();
108 + distributeToChildrenChangedHeight();
109 + return true;
110 + }
111 + if ( mRelayoutDelayedProcess == null ) {
112 + mRelayoutDelayedProcess = new EscalatingProcess( new DelayedProcess() {
113 + @Override
114 + public boolean process() {
115 + return relayoutFromHereDown();
116 + }
117 + } );
118 + mRelayoutDelayedProcess.schedule();
119 + }
120 + return false;
121 + }
122 +
123 + private EscalatingProcess mRelayoutDelayedProcess = null;
124 +
125 + protected void distributeToChildrenChangedWidth() {
126 + // For Overriding in Sizeables w/ children
127 + }
128 +
129 + protected void distributeToChildrenChangedHeight() {
130 + // For Overriding in Sizeables w/ children
131 + }
132 +
133 + protected void LLstretchable() {
134 + LLstretchableHorizontally();
135 + LLstretchableVertically();
136 + }
137 +
138 + public void LLstretchableVertically() {
139 + getHeightHelper().setStretchable( true );
140 + }
141 +
142 + public void LLstretchableHorizontally() {
143 + getWidthHelper().setStretchable( true );
144 + }
145 +
146 + /**
147 + * Sets the object's width. This width does not include decorations such as
148 + * border, margin, and padding.
149 + *
150 + * @param width the object's new width, in CSS units (e.g. "10px", "1em")
151 + */
152 + @Override
153 + public void setWidth( String width ) {
154 + setDimensionFromWidget( getWidthHelper(), width );
155 + }
156 +
157 + /**
158 + * Sets the object's height. This height does not include decorations such as
159 + * border, margin, and padding.
160 + *
161 + * @param height the object's new height, in CSS units (e.g. "10px", "1em")
162 + */
163 + @Override
164 + public void setHeight( String height ) {
165 + setDimensionFromWidget( getHeightHelper(), height );
166 + }
167 +
168 + /**
169 + * Sets the object's style name, removing all other styles.
170 + * <p/>
171 + * <p/>
172 + * The style name is the name referred to in CSS style rules (in HTML, this is
173 + * referred to as the element's "class"). By convention, style rules are of
174 + * the form <code>[project]-[widget]</code> (e.g. the {@link Button}
175 + * widget's style name is <code>.gwt-Button</code>).
176 + * </p>
177 + * <p/>
178 + * <p/>
179 + * For example, if a widget's style name is <code>myProject-MyWidget</code>,
180 + * then the style rule that applies to it will be
181 + * <code>.myProject-MyWidget</code>. Note the "dot" prefix -- this is
182 + * necessary because calling this method sets the underlying element's
183 + * <code>className</code> property.
184 + * </p>
185 + * <p/>
186 + * <p/>
187 + * An object may have any number of style names, which may be manipulated
188 + * using {@link #addStyleName(String)} and {@link #removeStyleName(String)}.
189 + * The attributes of all styles associated with the object will be applied to
190 + * it.
191 + * </p>
192 + *
193 + * @param style the style name to be added
194 + *
195 + * @see #addStyleName(String)
196 + * @see #removeStyleName(String)
197 + */
198 + @Override
199 + public final void setStyleName( String style ) {
200 + throw new UnsupportedOperationException( "Must use addStyleName" );
201 + }
202 +
203 + // /**
204 + // * Adds a set of events to be sunk by this object. Note that only
205 + // * {@link Widget widgets} may actually receive events, but can receive events
206 + // * from all objects contained within them.
207 + // *
208 + // * @param eventBitsToAdd a bitfield representing the set of events to be added
209 + // * to this element's event set
210 + // *
211 + // * @see com.google.gwt.user.client.Event
212 + // */
213 + // public void sinkEvents( int eventBitsToAdd )
214 + // {
215 + // Element element = getStyleElement();
216 + // DOM.sinkEvents( element, eventBitsToAdd | DOM.getEventsSunk( element ) );
217 + // }
218 + //
219 + // /**
220 + // * Removes a set of events from this object's event list.
221 + // *
222 + // * @param eventBitsToRemove a bitfield representing the set of events to be
223 + // * removed from this element's event set
224 + // *
225 + // * @see #sinkEvents
226 + // * @see com.google.gwt.user.client.Event
227 + // */
228 + // public void unsinkEvents( int eventBitsToRemove )
229 + // {
230 + // Element element = getStyleElement();
231 + // DOM.sinkEvents( element, DOM.getEventsSunk( element ) & (~eventBitsToRemove) );
232 + // }
233 +
234 + @Override
235 + public String toString() {
236 + String name = ClassName.simple( this );
237 + return name + ":" + super.toString();
238 + }
239 +
240 + public void resized() {
241 + // for overriding, called by the helper after the widget is resized at the element level
242 + }
243 +
244 + private void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, String pSize_1D ) {
245 + int zSize_1D;
246 + try {
247 + zSize_1D = parse( pSize_1D );
248 + }
249 + catch ( NumberFormatException e ) {
250 + throw new IllegalArgumentException( "Attempt to set" + pDimensionHelper.getWhat() + "( \"" + pSize_1D + "\" ) on " + getClass().getName() );
251 + }
252 + setDimensionFromWidget( pDimensionHelper, zSize_1D );
253 + }
254 +
255 + protected void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, int pSize_1D ) {
256 + pDimensionHelper.deligateSetDimensionFromWidget( pSize_1D );
257 + }
258 +
259 + public static int parse( String pSize_1D )
260 + throws NumberFormatException {
261 + String cleaned = ConstrainTo.notNull( pSize_1D ).trim();
262 + String toParse = "0" + cleaned;
263 + if ( toParse.endsWith( "px" ) ) {
264 + toParse = toParse.substring( 0, toParse.length() - 2 );
265 + }
266 + return Integer.parseInt( toParse );
267 + }
268 +
269 + protected Element addParent( Element pParent, Element pChild ) {
270 + DOM.appendChild( pParent, pChild );
271 + return pParent;
272 + }
273 + }