001package com.github.gwtbootstrap.client.ui;
002
003import com.github.gwtbootstrap.client.ui.base.HasStyle;
004import com.github.gwtbootstrap.client.ui.base.HasType;
005import com.github.gwtbootstrap.client.ui.base.IsResponsive;
006import com.github.gwtbootstrap.client.ui.base.ResponsiveHelper;
007import com.github.gwtbootstrap.client.ui.base.Style;
008import com.github.gwtbootstrap.client.ui.base.StyleHelper;
009import com.github.gwtbootstrap.client.ui.constants.Device;
010import com.github.gwtbootstrap.client.ui.constants.ImageType;
011import com.google.gwt.resources.client.ImageResource;
012import com.google.gwt.safehtml.shared.SafeUri;
013
014/**
015 * The Image class for Bootstrap style
016 * @since 2.2.1.0
017 * @author ohashi keisuke
018 */
019public class Image extends com.google.gwt.user.client.ui.Image implements
020        IsResponsive, HasStyle, HasType<ImageType> {
021
022    /**
023     * Creates an empty image.
024     */
025    public Image() {
026        super();
027        setStyleName("");
028    }
029    
030    /**
031     * Creates an image whose size and content are defined by an ImageResource.
032     * 
033     * @param resource the ImageResource to be displayed
034     */
035    public Image(ImageResource resource) {
036      super(resource);
037      setStyleName("");
038    }
039    
040    /**
041     * Creates a clipped image with a specified URL and visibility rectangle. The
042     * visibility rectangle is declared relative to the the rectangle which
043     * encompasses the entire image, which has an upper-left vertex of (0,0). The
044     * load event will be fired immediately after the object has been constructed
045     * (i.e. potentially before the image has been loaded in the browser). Since
046     * the width and height are specified explicitly by the user, this behavior
047     * will not cause problems with retrieving the width and height of a clipped
048     * image in a load event handler.
049     * 
050     * @param url the URL of the image to be displayed
051     * @param left the horizontal co-ordinate of the upper-left vertex of the
052     *          visibility rectangle
053     * @param top the vertical co-ordinate of the upper-left vertex of the
054     *          visibility rectangle
055     * @param width the width of the visibility rectangle
056     * @param height the height of the visibility rectangle
057     */
058    public Image(SafeUri url, int left, int top, int width, int height) {
059        super(url, left, top, width, height);
060        setStyleName("");
061    }
062
063    /**
064     * Creates an image with a specified URL. The load event will be fired once
065     * the image at the given URL has been retrieved by the browser.
066     * 
067     * @param url the URL of the image to be displayed
068     */
069    public Image(SafeUri url) {
070        super(url);
071        setStyleName("");
072    }
073
074    /**
075     * Creates a clipped image with a specified URL and visibility rectangle. The
076     * visibility rectangle is declared relative to the the rectangle which
077     * encompasses the entire image, which has an upper-left vertex of (0,0). The
078     * load event will be fired immediately after the object has been constructed
079     * (i.e. potentially before the image has been loaded in the browser). Since
080     * the width and height are specified explicitly by the user, this behavior
081     * will not cause problems with retrieving the width and height of a clipped
082     * image in a load event handler.
083     * 
084     * @param url the URL of the image to be displayed
085     * @param left the horizontal co-ordinate of the upper-left vertex of the
086     *          visibility rectangle
087     * @param top the vertical co-ordinate of the upper-left vertex of the
088     *          visibility rectangle
089     * @param width the width of the visibility rectangle
090     * @param height the height of the visibility rectangle
091     */
092    public Image(String url, int left, int top, int width, int height) {
093        super(url, left, top, width, height);
094        setStyleName("");
095    }
096
097    /**
098     * Creates an image with a specified URL. The load event will be fired once
099     * the image at the given URL has been retrieved by the browser.
100     * 
101     * @param url the URL of the image to be displayed
102     */
103    public Image(String url) {
104        super(url);
105        setStyleName("");
106    }
107
108    /**
109     * {@inheritDoc}
110     */
111    @Override
112    public void setShowOn(Device device) {
113        ResponsiveHelper.setShowOn(this, device);
114    }
115
116    /**
117     * {@inheritDoc}
118     */
119    @Override
120    public void setHideOn(Device device) {
121        ResponsiveHelper.setHideOn(this, device);
122    }
123
124    /**
125     * {@inheritDoc}
126     */
127    @Override
128    public void setType(ImageType style) {
129        StyleHelper.changeStyle(this, style, ImageType.class);
130    }
131
132    /**
133     * {@inheritDoc}
134     */
135    @Override
136    public void setStyle(Style style) {
137        StyleHelper.setStyle(this, style);
138    }
139
140    /**
141     * {@inheritDoc}
142     */
143    @Override
144    public void addStyle(Style style) {
145        StyleHelper.setStyle(this, style);
146    }
147
148    /**
149     * {@inheritDoc}
150     */
151    @Override
152    public void removeStyle(Style style) {
153        StyleHelper.setStyle(this, style);
154    }
155
156}