KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > impl > ClippedImageImpl


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.user.client.ui.impl;
17
18 import com.google.gwt.user.client.DOM;
19 import com.google.gwt.user.client.Element;
20
21 /**
22  * Uses a combination of a clear image and a background image to clip all except
23  * a desired portion of an underlying image.
24  *
25  * Do not use this class - it is used for implementation only, and its methods
26  * may change in the future.
27  */

28 public class ClippedImageImpl {
29
30   public void adjust(Element img, String JavaDoc url, int left, int top, int width,
31                      int height) {
32     String JavaDoc style = "url(" + url + ") no-repeat " + (-left + "px ")
33         + (-top + "px");
34     DOM.setStyleAttribute(img, "background", style);
35     DOM.setStyleAttribute(img, "width", width + "px");
36     DOM.setStyleAttribute(img, "height", height + "px");
37   }
38
39   public Element createStructure(String JavaDoc url, int left, int top, int width,
40                                  int height) {
41     Element tmp = DOM.createSpan();
42     DOM.setInnerHTML(tmp, getHTML(url, left, top, width, height));
43     return DOM.getFirstChild(tmp);
44   }
45
46   public String JavaDoc getHTML(String JavaDoc url, int left, int top, int width, int height) {
47     String JavaDoc style = "width: " + width + "px; height: " + height
48         + "px; background: url(" + url + ") no-repeat " + (-left + "px ")
49         + (-top + "px");
50
51     String JavaDoc clippedImgHtml = "<img SRC='clear.cache.gif' style='"
52         + style + "' border='0'>";
53
54     return clippedImgHtml;
55   }
56 }
57
Popular Tags