Subversion Repository Public Repository

litesoft

Diff Revisions 948 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/impls/input/FormImageSelector.java

Diff revisions: vs.
  @@ -1,395 +1,395 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.forms.client.components.impls.input;
3 -
4 - import org.litesoft.GWT.client.*;
5 - import org.litesoft.GWT.client.widgets.Button;
6 - import org.litesoft.GWT.client.widgets.*;
7 - import org.litesoft.GWT.client.widgets.nonpublic.*;
8 - import org.litesoft.GWT.forms.client.components.nonpublic.*;
9 - import org.litesoft.core.simpletypes.*;
10 - import org.litesoft.uispecification.*;
11 -
12 - import com.google.gwt.core.client.*;
13 - import com.google.gwt.event.dom.client.*;
14 - import com.google.gwt.event.logical.shared.*;
15 - import com.google.gwt.user.client.*;
16 - import com.google.gwt.user.client.ui.*;
17 -
18 - public abstract class FormImageSelector extends AbstractFocusWidgetErrorableFormElement implements ISizeableWidget {
19 - public static final String NO_IMAGE = "common/images/misc/tmp/NotAvailable.gif";
20 -
21 - protected PopupPanel mPicker;
22 -
23 - private boolean mViewOnly;
24 - private SizeableDualImage mDualImage = new SizeableDualImage();
25 - protected Button mPickerButton = null;
26 -
27 - protected String mPickerButtonTooltip = "";
28 -
29 - private boolean mBlurring = false;
30 - private boolean mPicking = false;
31 -
32 - protected ResourceKeyNameURL mCurrentResourceKeyNameURL = null;
33 -
34 - protected ISizeableDimensionHelper mWidthHelper;
35 - protected ISizeableDimensionHelper mHeightHelper;
36 -
37 - public FormImageSelector( String pFieldLabel, UiFont pLabelFont, String pTooltip, boolean pViewOnly, Integer pInitialWidth, boolean pWidthNotStretchable,
38 - Integer pInitialHeight, boolean pHeightNotStretchable ) {
39 - super( new MyFocusPanel(), pTooltip, "frmImageSelector", false );
40 - mViewOnly = pViewOnly;
41 - mWidthHelper = pWidthNotStretchable ? NullWidthHelper.INSTANCE : new StretchableWidthHelper( this );
42 - mHeightHelper = pHeightNotStretchable ? NullHeightHelper.INSTANCE : new StretchableHeightHelper( this );
43 -
44 - initialize( pFieldLabel, pLabelFont, pTooltip );
45 -
46 - MyFocusPanel zFocusPanel = (MyFocusPanel) mInputWidget;
47 -
48 - zFocusPanel.add( mDualImage );
49 -
50 - zFocusPanel.addMouseDownHandler( new MouseDownHandler() {
51 - @Override
52 - public void onMouseDown( MouseDownEvent event ) {
53 - setFocus();
54 - }
55 - } );
56 -
57 - if ( pInitialWidth != null ) {
58 - mDualImage.setImageWidth( pInitialWidth );
59 - }
60 - if ( pInitialHeight != null ) {
61 - mDualImage.setImageHeight( pInitialHeight );
62 - }
63 -
64 - setEnabled( true );
65 - }
66 -
67 - @Override
68 - public ISizeableDimensionHelper getWidthHelper() {
69 - return mWidthHelper;
70 - }
71 -
72 - @Override
73 - public ISizeableDimensionHelper getHeightHelper() {
74 - return mHeightHelper;
75 - }
76 -
77 - /**
78 - * Sets the object's width. This width does not include decorations such as
79 - * border, margin, and padding.
80 - *
81 - * @param width the object's new width, in CSS units (e.g. "10px", "1em")
82 - */
83 - @Override
84 - public void setWidth( String width ) {
85 - setDimensionFromWidget( getWidthHelper(), width );
86 - }
87 -
88 - /**
89 - * Sets the object's height. This height does not include decorations such as
90 - * border, margin, and padding.
91 - *
92 - * @param height the object's new height, in CSS units (e.g. "10px", "1em")
93 - */
94 - @Override
95 - public void setHeight( String height ) {
96 - setDimensionFromWidget( getHeightHelper(), height );
97 - }
98 -
99 - protected void setPicker( PopupPanel pPicker ) {
100 - (mPicker = pPicker).addCloseHandler( new CloseHandler<PopupPanel>() {
101 - @Override
102 - public void onClose( CloseEvent<PopupPanel> event ) {
103 - pickerClosed( event.isAutoClosed() );
104 - }
105 - } );
106 - }
107 -
108 - @Override
109 - public void simulateUserTextEntry( String pText ) {
110 - throw new UnsupportedOperationException( "simulateUserTextEntry on '" + mFieldLabel + "' to:" + pText ); //todo...
111 - }
112 -
113 - @Override
114 - public void publishAnyPendingChanges() {
115 - if ( hidePicker() || mBlurring ) {
116 - mPicking = false;
117 - processDefferredBlur();
118 - }
119 - super.publishAnyPendingChanges();
120 - }
121 -
122 - @Override
123 - public void onFocus( FocusEvent event ) // FocusPanel / Button
124 - {
125 - if ( mBlurring ) {
126 - mBlurring = false;
127 - } else {
128 - super.onFocus( event );
129 - }
130 - }
131 -
132 - @Override
133 - public void onBlur( BlurEvent event ) // FocusPanel / Button
134 - {
135 - mBlurring = true;
136 - defferBlur();
137 - }
138 -
139 - protected void processDefferredBlur() {
140 - if ( mBlurring && !mPicking ) {
141 - mBlurring = false;
142 - super.onBlur( null );
143 - }
144 - }
145 -
146 - protected void defferBlur() {
147 - Scheduler.get().scheduleDeferred( new Command() {
148 - @Override
149 - public void execute() {
150 - processDefferredBlur();
151 - }
152 - } );
153 - }
154 -
155 - protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop ) {
156 - mBlurring = mPicking = true;
157 - setFocus();
158 - LLshowPicker( new PointXY( pAbsoluteLeft, pAbsoluteTop ) );
159 - }
160 -
161 - protected void LLshowPicker( PointXY pPointXY ) {
162 - mPicker.setPopupPositionAndShow( new PopupPanelVisiblePositionCallBack( mPicker, //
163 - pPointXY.getX(), pPointXY.getY() ) );
164 - }
165 -
166 - protected boolean hidePicker() {
167 - boolean rv = mPicking;
168 - if ( mPicking ) {
169 - mPicker.hide();
170 - }
171 - return rv;
172 - }
173 -
174 - protected void pickerClosed( boolean autoClosed ) {
175 - if ( !autoClosed ) {
176 - setFocus();
177 - }
178 - mPicking = false;
179 - defferBlur();
180 - }
181 -
182 - public boolean isViewOnly() {
183 - return mViewOnly;
184 - }
185 -
186 - @Override
187 - protected int buildComponentPanel( String pLabel, UiFont pLabelFont ) {
188 - int zUniqueID = super.buildComponentPanel( pLabel, pLabelFont );
189 - if ( !mViewOnly ) {
190 - mInnerHTMLpanel.add( mPickerButton = createPickerButton(), "imgPick_" + zUniqueID );
191 - mPickerButton.addFocusHandler( this );
192 - mPickerButton.addBlurHandler( this );
193 - }
194 -
195 - return zUniqueID;
196 - }
197 -
198 - @Override
199 - protected String buildInputRow( String pTrId, String pInputId, int pUniqueID ) {
200 - String zAdditionalInputCell = mViewOnly ? "" : "<td valign='top'><div class='litesoft-PickerButtonContainer' id='imgPick_" + pUniqueID + "'></div></td>";
201 - return buildInputRowWithOptionalCell( pTrId, pInputId, zAdditionalInputCell );
202 - }
203 -
204 - @Override
205 - protected String buildInputRowWithOptionalCell( String pTrId, String pInputId, String pAdditionalInputCell ) {
206 - return "<tr class='litesoft-FormComponentInputRow'><td id='" + pInputId + "'></td>" + "<td valign='top'>" +
207 - "<table cellpadding='0' cellspacing='0'><tr id='" + pTrId + "'>" + pAdditionalInputCell + "</tr></table></td></tr>";
208 - }
209 -
210 - @Override
211 - protected void addIndicator( String pTrId ) {
212 - if ( !mViewOnly ) {
213 - mInnerHTMLpanel.add( mIndicatorTd = new IndicatorTd(), pTrId );
214 - }
215 - }
216 -
217 - protected Button createPickerButton() {
218 - mPickerButton = PickerButton.factory( "litesoft-IconImagePickerButton" ).create();
219 - mPickerButton.setTabIndex( -1 );
220 -
221 - mPickerButton.addClickHandler( new ClickHandler() {
222 - @Override
223 - public void onClick( ClickEvent event ) {
224 - int absoluteLeft = mPickerButton.getAbsoluteLeft();
225 - int absoluteTop = mPickerButton.getAbsoluteTop();
226 - showPicker( absoluteLeft, absoluteTop );
227 - }
228 - } );
229 -
230 - return mPickerButton;
231 - }
232 -
233 - public ResourceKeyNameURL getCurrentResourceKeyNameURL() {
234 - return mCurrentResourceKeyNameURL;
235 - }
236 -
237 - public void setCurrentResourceKeyNameURL( ResourceKeyNameURL pNewResourceKeyNameURL ) {
238 - if ( null == (mCurrentResourceKeyNameURL = pNewResourceKeyNameURL) ) {
239 - mDualImage.setUrl( NO_IMAGE, "No Image", null );
240 - } else {
241 - mDualImage.setUrl( mCurrentResourceKeyNameURL.getURL(), "" + mCurrentResourceKeyNameURL.getValue(), //
242 - new Command() {
243 - @Override
244 - public void execute() {
245 - if ( UtilsGwt.wasAltKeyDownOnCurrentEvent() ) {
246 - UtilsGwt.windowOpen( mDualImage.getUrl(), "", "" );
247 - }
248 - }
249 - } );
250 - }
251 - fireChangeListeners();
252 - }
253 -
254 - @Override
255 - public void setEnabled( boolean pEnabled ) {
256 - if ( mPickerButton != null ) {
257 - mPickerButton.setEnabled( pEnabled );
258 - }
259 - }
260 -
261 - @Override
262 - public void relayout() {
263 - }
264 -
265 - private static class MyFocusPanel extends FocusPanel implements IFocusWidget {
266 - private boolean mEnabled = true;
267 -
268 - @Override
269 - public boolean isEnabled() {
270 - return mEnabled;
271 - }
272 -
273 - @Override
274 - public void setEnabled( boolean pEnabled ) {
275 - mEnabled = pEnabled;
276 - }
277 - }
278 -
279 - protected static class NullWidthHelper extends AbstractWidthHelper {
280 - public static final NullWidthHelper INSTANCE = new NullWidthHelper();
281 -
282 - private NullWidthHelper() {
283 - super( false );
284 - }
285 - }
286 -
287 - protected static class NullHeightHelper extends AbstractWidthHelper {
288 - public static final NullWidthHelper INSTANCE = new NullWidthHelper();
289 -
290 - private NullHeightHelper() {
291 - super( false );
292 - }
293 - }
294 -
295 - private void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, String pSize_1D ) {
296 - int zSize_1D;
297 - try {
298 - zSize_1D = AbstractSizeableWidget.parse( pSize_1D );
299 - }
300 - catch ( NumberFormatException e ) {
301 - throw new IllegalArgumentException( "Attempt to set" + pDimensionHelper.getWhat() + "( \"" + pSize_1D + "\" ) on " + getClass().getName() );
302 - }
303 - pDimensionHelper.deligateSetDimensionFromWidget( zSize_1D );
304 - }
305 -
306 - private static abstract class AbstractHeightHelper extends AbstractDimensionHelper {
307 - protected AbstractHeightHelper( boolean pStretchable ) {
308 - super( pStretchable, HeightDimensionHelper.INSTANCE );
309 - }
310 - }
311 -
312 - private static abstract class AbstractWidthHelper extends AbstractDimensionHelper {
313 - protected AbstractWidthHelper( boolean pStretchable ) {
314 - super( pStretchable, WidthDimensionHelper.INSTANCE );
315 - }
316 - }
317 -
318 - private static class StretchableHeightHelper extends AbstractHeightHelper {
319 - public static final int DUAL_IMAGE_OVERHEAD = 9;
320 -
321 - private FormImageSelector mOurWidget;
322 -
323 - public StretchableHeightHelper( FormImageSelector pOurWidget ) {
324 - super( true );
325 - mOurWidget = pOurWidget;
326 - }
327 -
328 - @Override
329 - public void setDimension( int pDimension ) {
330 - setDimension( mOurWidget, pDimension );
331 - }
332 -
333 - @Override
334 - public int getDimension() {
335 - return getDimension( mOurWidget );
336 - }
337 -
338 - @Override
339 - public int getDimensionMaxShrinkability() {
340 - return getDimension( mOurWidget.mDualImage ) - DUAL_IMAGE_OVERHEAD;
341 - }
342 -
343 - @Override
344 - public int getDecorationSize() {
345 - return getDimension() - getDimension( mOurWidget.mDualImage );
346 - }
347 -
348 - @Override
349 - public void deligateSetDimensionFromWidget( int pDimension ) {
350 - pDimension -= getDecorationSize();
351 - if ( pDimension > DUAL_IMAGE_OVERHEAD ) {
352 - setDimension( mOurWidget.mDualImage, pDimension );
353 - }
354 - }
355 - }
356 -
357 - private static class StretchableWidthHelper extends AbstractWidthHelper {
358 - public static final int DUAL_IMAGE_OVERHEAD = 9;
359 -
360 - private FormImageSelector mOurWidget;
361 -
362 - public StretchableWidthHelper( FormImageSelector pOurWidget ) {
363 - super( true );
364 - mOurWidget = pOurWidget;
365 - }
366 -
367 - @Override
368 - public void setDimension( int pDimension ) {
369 - setDimension( mOurWidget, pDimension );
370 - }
371 -
372 - @Override
373 - public int getDimension() {
374 - return getDimension( mOurWidget );
375 - }
376 -
377 - @Override
378 - public int getDimensionMaxShrinkability() {
379 - return getDimension( mOurWidget.mDualImage ) - DUAL_IMAGE_OVERHEAD;
380 - }
381 -
382 - @Override
383 - public int getDecorationSize() {
384 - return getDimension() - getDimension( mOurWidget.mDualImage );
385 - }
386 -
387 - @Override
388 - public void deligateSetDimensionFromWidget( int pDimension ) {
389 - pDimension -= getDecorationSize();
390 - if ( pDimension > DUAL_IMAGE_OVERHEAD ) {
391 - setDimension( mOurWidget.mDualImage, pDimension );
392 - }
393 - }
394 - }
395 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.forms.client.components.impls.input;
3 +
4 + import org.litesoft.GWT.client.*;
5 + import org.litesoft.GWT.client.widgets.Button;
6 + import org.litesoft.GWT.client.widgets.*;
7 + import org.litesoft.GWT.client.widgets.nonpublic.*;
8 + import org.litesoft.GWT.forms.client.components.nonpublic.*;
9 + import org.litesoft.core.simpletypes.*;
10 + import org.litesoft.uispecification.*;
11 +
12 + import com.google.gwt.core.client.*;
13 + import com.google.gwt.event.dom.client.*;
14 + import com.google.gwt.event.logical.shared.*;
15 + import com.google.gwt.user.client.*;
16 + import com.google.gwt.user.client.ui.*;
17 +
18 + public abstract class FormImageSelector extends AbstractFocusWidgetErrorableFormElement implements ISizeableWidget {
19 + public static final String NO_IMAGE = "common/images/misc/tmp/NotAvailable.gif";
20 +
21 + protected PopupPanel mPicker;
22 +
23 + private boolean mViewOnly;
24 + private SizeableDualImage mDualImage = new SizeableDualImage();
25 + protected Button mPickerButton = null;
26 +
27 + protected String mPickerButtonTooltip = "";
28 +
29 + private boolean mBlurring = false;
30 + private boolean mPicking = false;
31 +
32 + protected ResourceKeyNameURL mCurrentResourceKeyNameURL = null;
33 +
34 + protected ISizeableDimensionHelper mWidthHelper;
35 + protected ISizeableDimensionHelper mHeightHelper;
36 +
37 + public FormImageSelector( String pFieldLabel, UiFont pLabelFont, String pTooltip, boolean pViewOnly, Integer pInitialWidth, boolean pWidthNotStretchable,
38 + Integer pInitialHeight, boolean pHeightNotStretchable ) {
39 + super( new MyFocusPanel(), pTooltip, "frmImageSelector", false );
40 + mViewOnly = pViewOnly;
41 + mWidthHelper = pWidthNotStretchable ? NullWidthHelper.INSTANCE : new StretchableWidthHelper( this );
42 + mHeightHelper = pHeightNotStretchable ? NullHeightHelper.INSTANCE : new StretchableHeightHelper( this );
43 +
44 + initialize( pFieldLabel, pLabelFont, pTooltip );
45 +
46 + MyFocusPanel zFocusPanel = (MyFocusPanel) mInputWidget;
47 +
48 + zFocusPanel.add( mDualImage );
49 +
50 + zFocusPanel.addMouseDownHandler( new MouseDownHandler() {
51 + @Override
52 + public void onMouseDown( MouseDownEvent event ) {
53 + setFocus();
54 + }
55 + } );
56 +
57 + if ( pInitialWidth != null ) {
58 + mDualImage.setImageWidth( pInitialWidth );
59 + }
60 + if ( pInitialHeight != null ) {
61 + mDualImage.setImageHeight( pInitialHeight );
62 + }
63 +
64 + setEnabled( true );
65 + }
66 +
67 + @Override
68 + public ISizeableDimensionHelper getWidthHelper() {
69 + return mWidthHelper;
70 + }
71 +
72 + @Override
73 + public ISizeableDimensionHelper getHeightHelper() {
74 + return mHeightHelper;
75 + }
76 +
77 + /**
78 + * Sets the object's width. This width does not include decorations such as
79 + * border, margin, and padding.
80 + *
81 + * @param width the object's new width, in CSS units (e.g. "10px", "1em")
82 + */
83 + @Override
84 + public void setWidth( String width ) {
85 + setDimensionFromWidget( getWidthHelper(), width );
86 + }
87 +
88 + /**
89 + * Sets the object's height. This height does not include decorations such as
90 + * border, margin, and padding.
91 + *
92 + * @param height the object's new height, in CSS units (e.g. "10px", "1em")
93 + */
94 + @Override
95 + public void setHeight( String height ) {
96 + setDimensionFromWidget( getHeightHelper(), height );
97 + }
98 +
99 + protected void setPicker( PopupPanel pPicker ) {
100 + (mPicker = pPicker).addCloseHandler( new CloseHandler<PopupPanel>() {
101 + @Override
102 + public void onClose( CloseEvent<PopupPanel> event ) {
103 + pickerClosed( event.isAutoClosed() );
104 + }
105 + } );
106 + }
107 +
108 + @Override
109 + public void simulateUserTextEntry( String pText ) {
110 + throw new UnsupportedOperationException( "simulateUserTextEntry on '" + mFieldLabel + "' to:" + pText ); //todo...
111 + }
112 +
113 + @Override
114 + public void publishAnyPendingChanges() {
115 + if ( hidePicker() || mBlurring ) {
116 + mPicking = false;
117 + processDefferredBlur();
118 + }
119 + super.publishAnyPendingChanges();
120 + }
121 +
122 + @Override
123 + public void onFocus( FocusEvent event ) // FocusPanel / Button
124 + {
125 + if ( mBlurring ) {
126 + mBlurring = false;
127 + } else {
128 + super.onFocus( event );
129 + }
130 + }
131 +
132 + @Override
133 + public void onBlur( BlurEvent event ) // FocusPanel / Button
134 + {
135 + mBlurring = true;
136 + defferBlur();
137 + }
138 +
139 + protected void processDefferredBlur() {
140 + if ( mBlurring && !mPicking ) {
141 + mBlurring = false;
142 + super.onBlur( null );
143 + }
144 + }
145 +
146 + protected void defferBlur() {
147 + Scheduler.get().scheduleDeferred( new Command() {
148 + @Override
149 + public void execute() {
150 + processDefferredBlur();
151 + }
152 + } );
153 + }
154 +
155 + protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop ) {
156 + mBlurring = mPicking = true;
157 + setFocus();
158 + LLshowPicker( new PointXY( pAbsoluteLeft, pAbsoluteTop ) );
159 + }
160 +
161 + protected void LLshowPicker( PointXY pPointXY ) {
162 + mPicker.setPopupPositionAndShow( new PopupPanelVisiblePositionCallBack( mPicker, //
163 + pPointXY.getX(), pPointXY.getY() ) );
164 + }
165 +
166 + protected boolean hidePicker() {
167 + boolean rv = mPicking;
168 + if ( mPicking ) {
169 + mPicker.hide();
170 + }
171 + return rv;
172 + }
173 +
174 + protected void pickerClosed( boolean autoClosed ) {
175 + if ( !autoClosed ) {
176 + setFocus();
177 + }
178 + mPicking = false;
179 + defferBlur();
180 + }
181 +
182 + public boolean isViewOnly() {
183 + return mViewOnly;
184 + }
185 +
186 + @Override
187 + protected int buildComponentPanel( String pLabel, UiFont pLabelFont ) {
188 + int zUniqueID = super.buildComponentPanel( pLabel, pLabelFont );
189 + if ( !mViewOnly ) {
190 + mInnerHTMLpanel.add( mPickerButton = createPickerButton(), "imgPick_" + zUniqueID );
191 + mPickerButton.addFocusHandler( this );
192 + mPickerButton.addBlurHandler( this );
193 + }
194 +
195 + return zUniqueID;
196 + }
197 +
198 + @Override
199 + protected String buildInputRow( String pTrId, String pInputId, int pUniqueID ) {
200 + String zAdditionalInputCell = mViewOnly ? "" : "<td valign='top'><div class='litesoft-PickerButtonContainer' id='imgPick_" + pUniqueID + "'></div></td>";
201 + return buildInputRowWithOptionalCell( pTrId, pInputId, zAdditionalInputCell );
202 + }
203 +
204 + @Override
205 + protected String buildInputRowWithOptionalCell( String pTrId, String pInputId, String pAdditionalInputCell ) {
206 + return "<tr class='litesoft-FormComponentInputRow'><td id='" + pInputId + "'></td>" + "<td valign='top'>" +
207 + "<table cellpadding='0' cellspacing='0'><tr id='" + pTrId + "'>" + pAdditionalInputCell + "</tr></table></td></tr>";
208 + }
209 +
210 + @Override
211 + protected void addIndicator( String pTrId ) {
212 + if ( !mViewOnly ) {
213 + mInnerHTMLpanel.add( mIndicatorTd = new IndicatorTd(), pTrId );
214 + }
215 + }
216 +
217 + protected Button createPickerButton() {
218 + mPickerButton = PickerButton.factory( "litesoft-IconImagePickerButton" ).create();
219 + mPickerButton.setTabIndex( -1 );
220 +
221 + mPickerButton.addClickHandler( new ClickHandler() {
222 + @Override
223 + public void onClick( ClickEvent event ) {
224 + int absoluteLeft = mPickerButton.getAbsoluteLeft();
225 + int absoluteTop = mPickerButton.getAbsoluteTop();
226 + showPicker( absoluteLeft, absoluteTop );
227 + }
228 + } );
229 +
230 + return mPickerButton;
231 + }
232 +
233 + public ResourceKeyNameURL getCurrentResourceKeyNameURL() {
234 + return mCurrentResourceKeyNameURL;
235 + }
236 +
237 + public void setCurrentResourceKeyNameURL( ResourceKeyNameURL pNewResourceKeyNameURL ) {
238 + if ( null == (mCurrentResourceKeyNameURL = pNewResourceKeyNameURL) ) {
239 + mDualImage.setUrl( NO_IMAGE, "No Image", null );
240 + } else {
241 + mDualImage.setUrl( mCurrentResourceKeyNameURL.getURL(), "" + mCurrentResourceKeyNameURL.getValue(), //
242 + new Command() {
243 + @Override
244 + public void execute() {
245 + if ( UtilsGwt.wasAltKeyDownOnCurrentEvent() ) {
246 + UtilsGwt.windowOpen( mDualImage.getUrl(), "", "" );
247 + }
248 + }
249 + } );
250 + }
251 + fireChangeListeners();
252 + }
253 +
254 + @Override
255 + public void setEnabled( boolean pEnabled ) {
256 + if ( mPickerButton != null ) {
257 + mPickerButton.setEnabled( pEnabled );
258 + }
259 + }
260 +
261 + @Override
262 + public void relayout() {
263 + }
264 +
265 + private static class MyFocusPanel extends FocusPanel implements IFocusWidget {
266 + private boolean mEnabled = true;
267 +
268 + @Override
269 + public boolean isEnabled() {
270 + return mEnabled;
271 + }
272 +
273 + @Override
274 + public void setEnabled( boolean pEnabled ) {
275 + mEnabled = pEnabled;
276 + }
277 + }
278 +
279 + protected static class NullWidthHelper extends AbstractWidthHelper {
280 + public static final NullWidthHelper INSTANCE = new NullWidthHelper();
281 +
282 + private NullWidthHelper() {
283 + super( false );
284 + }
285 + }
286 +
287 + protected static class NullHeightHelper extends AbstractWidthHelper {
288 + public static final NullWidthHelper INSTANCE = new NullWidthHelper();
289 +
290 + private NullHeightHelper() {
291 + super( false );
292 + }
293 + }
294 +
295 + private void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, String pSize_1D ) {
296 + int zSize_1D;
297 + try {
298 + zSize_1D = AbstractSizeableWidget.parse( pSize_1D );
299 + }
300 + catch ( NumberFormatException e ) {
301 + throw new IllegalArgumentException( "Attempt to set" + pDimensionHelper.getWhat() + "( \"" + pSize_1D + "\" ) on " + getClass().getName() );
302 + }
303 + pDimensionHelper.deligateSetDimensionFromWidget( zSize_1D );
304 + }
305 +
306 + private static abstract class AbstractHeightHelper extends AbstractDimensionHelper {
307 + protected AbstractHeightHelper( boolean pStretchable ) {
308 + super( pStretchable, HeightDimensionHelper.INSTANCE );
309 + }
310 + }
311 +
312 + private static abstract class AbstractWidthHelper extends AbstractDimensionHelper {
313 + protected AbstractWidthHelper( boolean pStretchable ) {
314 + super( pStretchable, WidthDimensionHelper.INSTANCE );
315 + }
316 + }
317 +
318 + private static class StretchableHeightHelper extends AbstractHeightHelper {
319 + public static final int DUAL_IMAGE_OVERHEAD = 9;
320 +
321 + private FormImageSelector mOurWidget;
322 +
323 + public StretchableHeightHelper( FormImageSelector pOurWidget ) {
324 + super( true );
325 + mOurWidget = pOurWidget;
326 + }
327 +
328 + @Override
329 + public void setDimension( int pDimension ) {
330 + setDimension( mOurWidget, pDimension );
331 + }
332 +
333 + @Override
334 + public int getDimension() {
335 + return getDimension( mOurWidget );
336 + }
337 +
338 + @Override
339 + public int getDimensionMaxShrinkability() {
340 + return getDimension( mOurWidget.mDualImage ) - DUAL_IMAGE_OVERHEAD;
341 + }
342 +
343 + @Override
344 + public int getDecorationSize() {
345 + return getDimension() - getDimension( mOurWidget.mDualImage );
346 + }
347 +
348 + @Override
349 + public void deligateSetDimensionFromWidget( int pDimension ) {
350 + pDimension -= getDecorationSize();
351 + if ( pDimension > DUAL_IMAGE_OVERHEAD ) {
352 + setDimension( mOurWidget.mDualImage, pDimension );
353 + }
354 + }
355 + }
356 +
357 + private static class StretchableWidthHelper extends AbstractWidthHelper {
358 + public static final int DUAL_IMAGE_OVERHEAD = 9;
359 +
360 + private FormImageSelector mOurWidget;
361 +
362 + public StretchableWidthHelper( FormImageSelector pOurWidget ) {
363 + super( true );
364 + mOurWidget = pOurWidget;
365 + }
366 +
367 + @Override
368 + public void setDimension( int pDimension ) {
369 + setDimension( mOurWidget, pDimension );
370 + }
371 +
372 + @Override
373 + public int getDimension() {
374 + return getDimension( mOurWidget );
375 + }
376 +
377 + @Override
378 + public int getDimensionMaxShrinkability() {
379 + return getDimension( mOurWidget.mDualImage ) - DUAL_IMAGE_OVERHEAD;
380 + }
381 +
382 + @Override
383 + public int getDecorationSize() {
384 + return getDimension() - getDimension( mOurWidget.mDualImage );
385 + }
386 +
387 + @Override
388 + public void deligateSetDimensionFromWidget( int pDimension ) {
389 + pDimension -= getDecorationSize();
390 + if ( pDimension > DUAL_IMAGE_OVERHEAD ) {
391 + setDimension( mOurWidget.mDualImage, pDimension );
392 + }
393 + }
394 + }
395 + }