Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -1,123 +1,123 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.client.widgets;
3 -
4 - import org.litesoft.GWT.client.*;
5 - import org.litesoft.GWT.client.widgets.nonpublic.*;
6 - import org.litesoft.commonfoundation.typeutils.*;
7 - import org.litesoft.core.delayed.*;
8 - import org.litesoft.logger.*;
9 -
10 - import com.google.gwt.dom.client.*;
11 - import com.google.gwt.user.client.*;
12 - import com.google.gwt.user.client.ui.*;
13 -
14 - public class OurImage extends Image implements OnBrowserEventListenable {
15 - public static final Logger LOGGER = LoggerFactory.getLogger( OurImage.class );
16 -
17 - private String mUrl;
18 -
19 - public OurImage() {
20 - }
21 -
22 - public OurImage( String pUrl ) {
23 - super( pUrl );
24 - mUrl = pUrl;
25 - }
26 -
27 - public OurImage size( int pWidth, int pHeight ) {
28 - setWidth( pWidth );
29 - setHeight( pHeight );
30 - return this;
31 - }
32 -
33 - /**
34 - * Set Height of the image in pixels.
35 - *
36 - * @see <a href="http://www.w3.org/TR/1999/REC-html401-19991224/struct/objects.html#adef-height-IMG">W3C HTML Specification</a>
37 - */
38 - public void setHeight( int pPixels ) {
39 - getImageElement().setHeight( pPixels );
40 - }
41 -
42 - /**
43 - * Set Width of the image in pixels.
44 - *
45 - * @see <a href="http://www.w3.org/TR/1999/REC-html401-19991224/struct/objects.html#adef-width-IMG">W3C HTML Specification</a>
46 - */
47 - public void setWidth( int pPixels ) {
48 - getImageElement().setWidth( pPixels );
49 - }
50 -
51 - /**
52 - * This should have been protected in Image.java
53 - */
54 - protected ImageElement getImageElement() {
55 - return getElement().cast();
56 - }
57 -
58 - @Override
59 - public String getUrl() {
60 - return mUrl;
61 - }
62 -
63 - @Override
64 - public void setUrl( String pUrl ) {
65 - mUrl = Strings.deNull( pUrl ).trim();
66 - // Stupid GWT & IE thing at:
67 - // ImageSrcIE6
68 - // at line: 64
69 - // todo: remove try/catch when Either GWT or IE is fixed
70 - try {
71 - super.setUrl( pUrl );
72 - }
73 - catch ( Throwable e ) {
74 - LOGGER.warn.log( e, "OurImage.setUrl(), ignoring exception" );
75 - }
76 - String zElementURL = DOM.getElementProperty( getElement(), "src" );
77 - String zActualURL = super.getUrl();
78 - if ( !Objects.areNonArraysEqual( zActualURL, zElementURL ) ) {
79 - LOGGER.warn.log( "OurImage.setUrl( '", mUrl, "' ), Actual ( '", zActualURL, "' ) , Element ( '", zElementURL, "' )" );
80 - TimedRunnableManager.INSTANCE.runIn( new TimedRunnable() {
81 - @Override
82 - public Again runOnce() {
83 - setUrl( mUrl );
84 - return null;
85 - }
86 - }, 100 );
87 - }
88 - }
89 -
90 - private OnBrowserEventListener mListener = null;
91 -
92 - @Override
93 - public Widget getOnBrowserEventListenableWidget() {
94 - return this;
95 - }
96 -
97 - @Override
98 - public OnBrowserEventListener getOnBrowserEventListener() {
99 - return mListener;
100 - }
101 -
102 - @Override
103 - public void setOnBrowserEventListener( int pEventBitsToAdd, OnBrowserEventListener pListener ) {
104 - if ( null != (mListener = pListener) ) {
105 - sinkEvents( pEventBitsToAdd );
106 - }
107 - }
108 -
109 - @Override
110 - public void clearOnBrowserEventListener() {
111 - mListener = null;
112 - }
113 -
114 - @Override
115 - public void onBrowserEvent( Event event ) {
116 - if ( mListener != null ) {
117 - if ( mListener.onBrowserEvent( event ) ) {
118 - return;
119 - }
120 - }
121 - super.onBrowserEvent( event );
122 - }
123 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.client.widgets;
3 +
4 + import org.litesoft.GWT.client.*;
5 + import org.litesoft.GWT.client.widgets.nonpublic.*;
6 + import org.litesoft.commonfoundation.base.*;
7 + import org.litesoft.core.delayed.*;
8 + import org.litesoft.logger.*;
9 +
10 + import com.google.gwt.dom.client.*;
11 + import com.google.gwt.user.client.*;
12 + import com.google.gwt.user.client.ui.*;
13 +
14 + public class OurImage extends Image implements OnBrowserEventListenable {
15 + public static final Logger LOGGER = LoggerFactory.getLogger( OurImage.class );
16 +
17 + private String mUrl;
18 +
19 + public OurImage() {
20 + }
21 +
22 + public OurImage( String pUrl ) {
23 + super( pUrl );
24 + mUrl = pUrl;
25 + }
26 +
27 + public OurImage size( int pWidth, int pHeight ) {
28 + setWidth( pWidth );
29 + setHeight( pHeight );
30 + return this;
31 + }
32 +
33 + /**
34 + * Set Height of the image in pixels.
35 + *
36 + * @see <a href="http://www.w3.org/TR/1999/REC-html401-19991224/struct/objects.html#adef-height-IMG">W3C HTML Specification</a>
37 + */
38 + public void setHeight( int pPixels ) {
39 + getImageElement().setHeight( pPixels );
40 + }
41 +
42 + /**
43 + * Set Width of the image in pixels.
44 + *
45 + * @see <a href="http://www.w3.org/TR/1999/REC-html401-19991224/struct/objects.html#adef-width-IMG">W3C HTML Specification</a>
46 + */
47 + public void setWidth( int pPixels ) {
48 + getImageElement().setWidth( pPixels );
49 + }
50 +
51 + /**
52 + * This should have been protected in Image.java
53 + */
54 + protected ImageElement getImageElement() {
55 + return getElement().cast();
56 + }
57 +
58 + @Override
59 + public String getUrl() {
60 + return mUrl;
61 + }
62 +
63 + @Override
64 + public void setUrl( String pUrl ) {
65 + mUrl = ConstrainTo.notNull( pUrl ).trim();
66 + // Stupid GWT & IE thing at:
67 + // ImageSrcIE6
68 + // at line: 64
69 + // todo: remove try/catch when Either GWT or IE is fixed
70 + try {
71 + super.setUrl( pUrl );
72 + }
73 + catch ( Throwable e ) {
74 + LOGGER.warn.log( e, "OurImage.setUrl(), ignoring exception" );
75 + }
76 + String zElementURL = DOM.getElementProperty( getElement(), "src" );
77 + String zActualURL = super.getUrl();
78 + if ( !Currently.areEqual( zActualURL, zElementURL ) ) {
79 + LOGGER.warn.log( "OurImage.setUrl( '", mUrl, "' ), Actual ( '", zActualURL, "' ) , Element ( '", zElementURL, "' )" );
80 + TimedRunnableManager.INSTANCE.runIn( new TimedRunnable() {
81 + @Override
82 + public Again runOnce() {
83 + setUrl( mUrl );
84 + return null;
85 + }
86 + }, 100 );
87 + }
88 + }
89 +
90 + private OnBrowserEventListener mListener = null;
91 +
92 + @Override
93 + public Widget getOnBrowserEventListenableWidget() {
94 + return this;
95 + }
96 +
97 + @Override
98 + public OnBrowserEventListener getOnBrowserEventListener() {
99 + return mListener;
100 + }
101 +
102 + @Override
103 + public void setOnBrowserEventListener( int pEventBitsToAdd, OnBrowserEventListener pListener ) {
104 + if ( null != (mListener = pListener) ) {
105 + sinkEvents( pEventBitsToAdd );
106 + }
107 + }
108 +
109 + @Override
110 + public void clearOnBrowserEventListener() {
111 + mListener = null;
112 + }
113 +
114 + @Override
115 + public void onBrowserEvent( Event event ) {
116 + if ( mListener != null ) {
117 + if ( mListener.onBrowserEvent( event ) ) {
118 + return;
119 + }
120 + }
121 + super.onBrowserEvent( event );
122 + }
123 + }