Subversion Repository Public Repository

litesoft

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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.forms.client.components.impls.input;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.client.widgets.Button;
import org.litesoft.GWT.client.widgets.*;
import org.litesoft.GWT.client.widgets.nonpublic.*;
import org.litesoft.GWT.forms.client.components.nonpublic.*;
import org.litesoft.core.simpletypes.*;
import org.litesoft.uispecification.*;

import com.google.gwt.core.client.*;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.event.logical.shared.*;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;

public abstract class FormImageSelector extends AbstractFocusWidgetErrorableFormElement implements ISizeableWidget {
    public static final String NO_IMAGE = "common/images/misc/tmp/NotAvailable.gif";

    protected PopupPanel mPicker;

    private boolean mViewOnly;
    private SizeableDualImage mDualImage = new SizeableDualImage();
    protected Button mPickerButton = null;

    protected String mPickerButtonTooltip = "";

    private boolean mBlurring = false;
    private boolean mPicking = false;

    protected ResourceKeyNameURL mCurrentResourceKeyNameURL = null;

    protected ISizeableDimensionHelper mWidthHelper;
    protected ISizeableDimensionHelper mHeightHelper;

    public FormImageSelector( String pFieldLabel, UiFont pLabelFont, String pTooltip, boolean pViewOnly, Integer pInitialWidth, boolean pWidthNotStretchable,
                              Integer pInitialHeight, boolean pHeightNotStretchable ) {
        super( new MyFocusPanel(), pTooltip, "frmImageSelector", false );
        mViewOnly = pViewOnly;
        mWidthHelper = pWidthNotStretchable ? NullWidthHelper.INSTANCE : new StretchableWidthHelper( this );
        mHeightHelper = pHeightNotStretchable ? NullHeightHelper.INSTANCE : new StretchableHeightHelper( this );

        initialize( pFieldLabel, pLabelFont, pTooltip );

        MyFocusPanel zFocusPanel = (MyFocusPanel) mInputWidget;

        zFocusPanel.add( mDualImage );

        zFocusPanel.addMouseDownHandler( new MouseDownHandler() {
            @Override
            public void onMouseDown( MouseDownEvent event ) {
                setFocus();
            }
        } );

        if ( pInitialWidth != null ) {
            mDualImage.setImageWidth( pInitialWidth );
        }
        if ( pInitialHeight != null ) {
            mDualImage.setImageHeight( pInitialHeight );
        }

        setEnabled( true );
    }

    @Override
    public ISizeableDimensionHelper getWidthHelper() {
        return mWidthHelper;
    }

    @Override
    public ISizeableDimensionHelper getHeightHelper() {
        return mHeightHelper;
    }

    /**
     * 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 );
    }

    protected void setPicker( PopupPanel pPicker ) {
        (mPicker = pPicker).addCloseHandler( new CloseHandler<PopupPanel>() {
            @Override
            public void onClose( CloseEvent<PopupPanel> event ) {
                pickerClosed( event.isAutoClosed() );
            }
        } );
    }

    @Override
    public void simulateUserTextEntry( String pText ) {
        throw new UnsupportedOperationException( "simulateUserTextEntry on '" + mFieldLabel + "' to:" + pText ); //todo...
    }

    @Override
    public void publishAnyPendingChanges() {
        if ( hidePicker() || mBlurring ) {
            mPicking = false;
            processDefferredBlur();
        }
        super.publishAnyPendingChanges();
    }

    @Override
    public void onFocus( FocusEvent event ) // FocusPanel / Button
    {
        if ( mBlurring ) {
            mBlurring = false;
        } else {
            super.onFocus( event );
        }
    }

    @Override
    public void onBlur( BlurEvent event ) // FocusPanel / Button
    {
        mBlurring = true;
        defferBlur();
    }

    protected void processDefferredBlur() {
        if ( mBlurring && !mPicking ) {
            mBlurring = false;
            super.onBlur( null );
        }
    }

    protected void defferBlur() {
        Scheduler.get().scheduleDeferred( new Command() {
            @Override
            public void execute() {
                processDefferredBlur();
            }
        } );
    }

    protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop ) {
        mBlurring = mPicking = true;
        setFocus();
        LLshowPicker( new PointXY( pAbsoluteLeft, pAbsoluteTop ) );
    }

    protected void LLshowPicker( PointXY pPointXY ) {
        mPicker.setPopupPositionAndShow( new PopupPanelVisiblePositionCallBack( mPicker, //
                                                                                pPointXY.getX(), pPointXY.getY() ) );
    }

    protected boolean hidePicker() {
        boolean rv = mPicking;
        if ( mPicking ) {
            mPicker.hide();
        }
        return rv;
    }

    protected void pickerClosed( boolean autoClosed ) {
        if ( !autoClosed ) {
            setFocus();
        }
        mPicking = false;
        defferBlur();
    }

    public boolean isViewOnly() {
        return mViewOnly;
    }

    @Override
    protected int buildComponentPanel( String pLabel, UiFont pLabelFont ) {
        int zUniqueID = super.buildComponentPanel( pLabel, pLabelFont );
        if ( !mViewOnly ) {
            mInnerHTMLpanel.add( mPickerButton = createPickerButton(), "imgPick_" + zUniqueID );
            mPickerButton.addFocusHandler( this );
            mPickerButton.addBlurHandler( this );
        }

        return zUniqueID;
    }

    @Override
    protected String buildInputRow( String pTrId, String pInputId, int pUniqueID ) {
        String zAdditionalInputCell = mViewOnly ? "" : "<td valign='top'><div class='litesoft-PickerButtonContainer' id='imgPick_" + pUniqueID + "'></div></td>";
        return buildInputRowWithOptionalCell( pTrId, pInputId, zAdditionalInputCell );
    }

    @Override
    protected String buildInputRowWithOptionalCell( String pTrId, String pInputId, String pAdditionalInputCell ) {
        return "<tr class='litesoft-FormComponentInputRow'><td id='" + pInputId + "'></td>" + "<td valign='top'>" +
               "<table cellpadding='0' cellspacing='0'><tr id='" + pTrId + "'>" + pAdditionalInputCell + "</tr></table></td></tr>";
    }

    @Override
    protected void addIndicator( String pTrId ) {
        if ( !mViewOnly ) {
            mInnerHTMLpanel.add( mIndicatorTd = new IndicatorTd(), pTrId );
        }
    }

    protected Button createPickerButton() {
        mPickerButton = PickerButton.factory( "litesoft-IconImagePickerButton" ).create();
        mPickerButton.setTabIndex( -1 );

        mPickerButton.addClickHandler( new ClickHandler() {
            @Override
            public void onClick( ClickEvent event ) {
                int absoluteLeft = mPickerButton.getAbsoluteLeft();
                int absoluteTop = mPickerButton.getAbsoluteTop();
                showPicker( absoluteLeft, absoluteTop );
            }
        } );

        return mPickerButton;
    }

    public ResourceKeyNameURL getCurrentResourceKeyNameURL() {
        return mCurrentResourceKeyNameURL;
    }

    public void setCurrentResourceKeyNameURL( ResourceKeyNameURL pNewResourceKeyNameURL ) {
        if ( null == (mCurrentResourceKeyNameURL = pNewResourceKeyNameURL) ) {
            mDualImage.setUrl( NO_IMAGE, "No Image", null );
        } else {
            mDualImage.setUrl( mCurrentResourceKeyNameURL.getURL(), "" + mCurrentResourceKeyNameURL.getValue(), //
                               new Command() {
                                   @Override
                                   public void execute() {
                                       if ( UtilsGwt.wasAltKeyDownOnCurrentEvent() ) {
                                           UtilsGwt.windowOpen( mDualImage.getUrl(), "", "" );
                                       }
                                   }
                               } );
        }
        fireChangeListeners();
    }

    @Override
    public void setEnabled( boolean pEnabled ) {
        if ( mPickerButton != null ) {
            mPickerButton.setEnabled( pEnabled );
        }
    }

    @Override
    public void relayout() {
    }

    private static class MyFocusPanel extends FocusPanel implements IFocusWidget {
        private boolean mEnabled = true;

        @Override
        public boolean isEnabled() {
            return mEnabled;
        }

        @Override
        public void setEnabled( boolean pEnabled ) {
            mEnabled = pEnabled;
        }
    }

    protected static class NullWidthHelper extends AbstractWidthHelper {
        public static final NullWidthHelper INSTANCE = new NullWidthHelper();

        private NullWidthHelper() {
            super( false );
        }
    }

    protected static class NullHeightHelper extends AbstractWidthHelper {
        public static final NullWidthHelper INSTANCE = new NullWidthHelper();

        private NullHeightHelper() {
            super( false );
        }
    }

    private void setDimensionFromWidget( ISizeableDimensionHelper pDimensionHelper, String pSize_1D ) {
        int zSize_1D;
        try {
            zSize_1D = AbstractSizeableWidget.parse( pSize_1D );
        }
        catch ( NumberFormatException e ) {
            throw new IllegalArgumentException( "Attempt to set" + pDimensionHelper.getWhat() + "( \"" + pSize_1D + "\" ) on " + getClass().getName() );
        }
        pDimensionHelper.deligateSetDimensionFromWidget( zSize_1D );
    }

    private static abstract class AbstractHeightHelper extends AbstractDimensionHelper {
        protected AbstractHeightHelper( boolean pStretchable ) {
            super( pStretchable, HeightDimensionHelper.INSTANCE );
        }
    }

    private static abstract class AbstractWidthHelper extends AbstractDimensionHelper {
        protected AbstractWidthHelper( boolean pStretchable ) {
            super( pStretchable, WidthDimensionHelper.INSTANCE );
        }
    }

    private static class StretchableHeightHelper extends AbstractHeightHelper {
        public static final int DUAL_IMAGE_OVERHEAD = 9;

        private FormImageSelector mOurWidget;

        public StretchableHeightHelper( FormImageSelector pOurWidget ) {
            super( true );
            mOurWidget = pOurWidget;
        }

        @Override
        public void setDimension( int pDimension ) {
            setDimension( mOurWidget, pDimension );
        }

        @Override
        public int getDimension() {
            return getDimension( mOurWidget );
        }

        @Override
        public int getDimensionMaxShrinkability() {
            return getDimension( mOurWidget.mDualImage ) - DUAL_IMAGE_OVERHEAD;
        }

        @Override
        public int getDecorationSize() {
            return getDimension() - getDimension( mOurWidget.mDualImage );
        }

        @Override
        public void deligateSetDimensionFromWidget( int pDimension ) {
            pDimension -= getDecorationSize();
            if ( pDimension > DUAL_IMAGE_OVERHEAD ) {
                setDimension( mOurWidget.mDualImage, pDimension );
            }
        }
    }

    private static class StretchableWidthHelper extends AbstractWidthHelper {
        public static final int DUAL_IMAGE_OVERHEAD = 9;

        private FormImageSelector mOurWidget;

        public StretchableWidthHelper( FormImageSelector pOurWidget ) {
            super( true );
            mOurWidget = pOurWidget;
        }

        @Override
        public void setDimension( int pDimension ) {
            setDimension( mOurWidget, pDimension );
        }

        @Override
        public int getDimension() {
            return getDimension( mOurWidget );
        }

        @Override
        public int getDimensionMaxShrinkability() {
            return getDimension( mOurWidget.mDualImage ) - DUAL_IMAGE_OVERHEAD;
        }

        @Override
        public int getDecorationSize() {
            return getDimension() - getDimension( mOurWidget.mDualImage );
        }

        @Override
        public void deligateSetDimensionFromWidget( int pDimension ) {
            pDimension -= getDecorationSize();
            if ( pDimension > DUAL_IMAGE_OVERHEAD ) {
                setDimension( mOurWidget.mDualImage, pDimension );
            }
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/forms/client/components/impls/input/FormImageSelector.java

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

390 Diff Diff GeorgeS picture GeorgeS Sun 14 Aug, 2011 19:33:48 +0000
154 Diff Diff GeorgeS picture GeorgeS Tue 22 Mar, 2011 20:46:40 +0000
144 Diff Diff GeorgeS picture GeorgeS Mon 14 Mar, 2011 03:42:34 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

23 Diff Diff GeorgeS picture GeorgeS Wed 24 Feb, 2010 00:34:32 +0000
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000