Subversion Repository Public Repository

litesoft

Diff Revisions 748 vs 749 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/Spacer.java

Diff revisions: vs.
  @@ -1,59 +1,110 @@
1 - // This Source Code is in the Public Domain per: http://litesoft.org/License.txt
2 - package org.litesoft.GWT.client.widgets;
3 -
4 - import org.litesoft.GWT.client.widgets.nonpublic.*;
5 -
6 - import com.google.gwt.user.client.*;
7 -
8 - public class Spacer extends AbstractBrowserEventListenableWidget
9 - {
10 - private String mHeightSet = null;
11 - private String mWidthSet = null;
12 -
13 - public Spacer()
14 - {
15 - setElement( DOM.createImg() );
16 - CommonElementHelper.setImgSrc( getElement(), TransparentImage.URL );
17 - //noinspection GWTStyleCheck
18 - setStyleName( "LayoutSpacer" );
19 - }
20 -
21 - public Spacer( int pWidthAndHeight )
22 - {
23 - this();
24 - width( pWidthAndHeight );
25 - height( pWidthAndHeight );
26 - }
27 -
28 - /**
29 - * Calling this method eliminates the ability to set width via css class
30 - */
31 - public Spacer width( int pPixels )
32 - {
33 - String newWidth = "" + pPixels;
34 - if ( !newWidth.equals( mWidthSet ) )
35 - {
36 - setWidth( mWidthSet = newWidth );
37 - }
38 - return (mHeightSet != null) ? this : height( 1 );
39 - }
40 -
41 - /**
42 - * Calling this method eliminates the ability to set height via css class
43 - */
44 - public Spacer height( int pPixels )
45 - {
46 - String newHeight = "" + pPixels;
47 - if ( !newHeight.equals( mHeightSet ) )
48 - {
49 - setHeight( mHeightSet = newHeight );
50 - }
51 - return (mWidthSet != null) ? this : width( 1 );
52 - }
53 -
54 - public Spacer style( String pStyle )
55 - {
56 - addStyleName( pStyle );
57 - return this;
58 - }
59 - }
1 + package org.litesoft.GWT.client.widgets;
2 +
3 + import org.litesoft.core.util.*;
4 +
5 + import com.google.gwt.dom.client.Style.*;
6 + import com.google.gwt.user.client.ui.*;
7 +
8 + public class Spacer extends Composite
9 + {
10 + private static final String BLANK_TEXT = " ";
11 +
12 + public Spacer( int pWidth, int pHeight )
13 + {
14 + HTML widget = new HTML( BLANK_TEXT );
15 + widget.getElement().getStyle().setOverflow( Overflow.HIDDEN );
16 + initWidget( widget );
17 + //noinspection GWTStyleCheck
18 + setStyleName( "LayoutSpacer" );
19 +
20 + width( pWidth );
21 + height( pHeight );
22 + }
23 +
24 + public Spacer( int pWidthAndHeight )
25 + {
26 + this( pWidthAndHeight, pWidthAndHeight );
27 + }
28 +
29 + public Spacer()
30 + {
31 + this( 1 );
32 + }
33 +
34 + /**
35 + * add a style "classname", and allow chaining calls.
36 + *
37 + * @param pStyle "classname"
38 + *
39 + * @return this
40 + */
41 + public Spacer style( String pStyle )
42 + {
43 + if ( null != (pStyle = UtilsCommon.noEmpty( pStyle )) )
44 + {
45 + addStyleName( pStyle );
46 + }
47 + return this;
48 + }
49 +
50 + /**
51 + * Set the width, and allow chaining calls.
52 + */
53 + public Spacer width( String pWidth )
54 + {
55 + if ( pWidth != null )
56 + {
57 + setWidth( pWidth );
58 + }
59 + return this;
60 + }
61 +
62 + /**
63 + * Set the height, and allow chaining calls.
64 + */
65 + public Spacer height( String pHeight )
66 + {
67 + if ( pHeight != null )
68 + {
69 + setHeight( pHeight );
70 + }
71 + return this;
72 + }
73 +
74 + /**
75 + * Set the width & height, and allow chaining calls.
76 + */
77 + public Spacer size( String pSize )
78 + {
79 + return width( pSize ).height( pSize );
80 + }
81 +
82 + /**
83 + * Set the width, and allow chaining calls.
84 + */
85 + public Spacer width( int pWidth )
86 + {
87 + return width( convertSizePositive( pWidth ) );
88 + }
89 +
90 + /**
91 + * Set the height, and allow chaining calls.
92 + */
93 + public Spacer height( int pHeight )
94 + {
95 + return height( convertSizePositive( pHeight ) );
96 + }
97 +
98 + /**
99 + * Set the width & height, and allow chaining calls.
100 + */
101 + public Spacer size( int pSize )
102 + {
103 + return size( convertSizePositive( pSize ) );
104 + }
105 +
106 + private static String convertSizePositive( int pSize )
107 + {
108 + return (pSize > 0) ? String.valueOf( pSize ) : null;
109 + }
110 + }