001 /*
002 * Copyright 2006 Mat Gessel <mat.gessel@gmail.com>
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 */
016 package asquare.gwt.tk.client.ui;
017
018 import asquare.gwt.tk.client.util.DomUtil;
019
020 import com.google.gwt.user.client.ui.Image;
021
022 /**
023 * An icon is an image which requires its dimensions be specifed at construction
024 * time. Useful for static layouts.
025 */
026 public class Icon extends Image
027 {
028 /**
029 * Creates a new Icon sized in pixels.
030 *
031 * @param url the url of the image
032 * @param width the width in pixels
033 * @param height the height in pixels
034 */
035 public Icon(String url, int width, int height)
036 {
037 this(url, width + "px", height + "px");
038 }
039
040 /**
041 * Creates a new Icon sized in CSS measurements.
042 *
043 * @param url the url of the image
044 * @param width the width in CSS measurements
045 * @param height the height in CSS measurements
046 */
047 public Icon(String url, String width, String height)
048 {
049 super(url);
050 setWidth(width);
051 setHeight(height);
052 }
053
054 /**
055 * Gets the CSS width of the underlying element.
056 *
057 * @return the width in CSS measurements
058 */
059 public int getWidth()
060 {
061 return DomUtil.getIntAttribute(this, "width");
062 }
063
064 /**
065 * Gets the CSS height of the underlying element.
066 *
067 * @return the height in CSS measurements
068 */
069 public int getHeight()
070 {
071 return DomUtil.getIntAttribute(this, "height");
072 }
073 }