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.impl;
18  
19  import org.gwtwidgets.client.ui.PNGImage;
20  import com.google.gwt.user.client.DOM;
21  import com.google.gwt.user.client.Element;
22  
23  
24  public class PNGImageImplIE6 extends PNGImageImpl
25  {
26      private String url;
27      private boolean isPng;
28  
29      
30      public Element createElement (String url, int width, int height)
31      {
32          this.url = url;
33      
34          if (url.endsWith(".png") || url.endsWith(".PNG")) {
35              isPng = true;
36          }
37          else {
38              isPng = false;
39          }
40          
41          if (isPng) {
42              Element div = DOM.createDiv();
43              DOM.setInnerHTML(div, "<span style=\"display:inline-block;width:" + width + "px;height:" + height + "px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod='scale')\"></span>");
44  
45              return DOM.getFirstChild(div);
46          }
47          else {
48              return super.createElement(url, width, height);
49          }
50      }
51  
52      public String getUrl (PNGImage image)
53      {
54          if (isPng) {
55              return url;
56          }
57          else {
58              return super.getUrl(image);
59          }
60      }
61  
62      
63  }