View Javadoc

1   /*
2    * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.gwtwidgets.client.ui;
18  
19  import org.gwtwidgets.client.ui.impl.PNGImageImpl;
20  import com.google.gwt.core.client.GWT;
21  import com.google.gwt.user.client.Event;
22  import com.google.gwt.user.client.ui.Image;
23  
24  
25  /***
26   * Image widget that overcomes PNG browser incompatabilities.
27   * Although meant for PNG images, it will work with any image
28   * format supported by the browser.  If the image file ends
29   * with ".png" or ".PNG" it will use the PNG specific routines,
30   * otherwise will use generic non-PNG specific routines.
31   * 
32   * The URL, width, and height are required at the creation of the
33   * widget, and may not be updated via the widget methogs.  Calling
34   * setUrl() will throw a RuntimeException.  This is in part due to
35   * the workarounds required for IE 5.5 and IE6.
36   * 
37   * @author rhanson
38   */
39  public class PNGImage extends Image
40  {
41      private PNGImageImpl impl;
42  
43  
44      public PNGImage (String url, int width, int height)
45      {
46          impl = (PNGImageImpl) GWT.create(PNGImageImpl.class);
47          
48          setElement(impl.createElement(url, width, height));
49          sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.ONLOAD | Event.ONERROR);
50      }
51  
52      
53      public String getUrl ()
54      {
55          return impl.getUrl(this);
56      }
57     
58      /***
59       * Should not be used. Throws RuntimeException
60       */
61      public void setUrl (String url)
62      {
63          throw new RuntimeException("Not allowed to set url for a PNG image");
64      }
65  }