001package org.gwtbootstrap3.client.ui;
002
003/*
004 * #%L
005 * GwtBootstrap3
006 * %%
007 * Copyright (C) 2013 - 2014 GwtBootstrap3
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023
024import org.gwtbootstrap3.client.ui.base.HasType;
025import org.gwtbootstrap3.client.ui.base.helper.StyleHelper;
026import org.gwtbootstrap3.client.ui.constants.ImageType;
027import org.gwtbootstrap3.client.ui.constants.Styles;
028
029/**
030 * An anchor that contains an image as the click action, used in Media Objects
031 *
032 * @author Joshua Godi
033 * @see org.gwtbootstrap3.client.ui.MediaList
034 */
035public class ImageAnchor extends Anchor implements HasType<ImageType> {
036    private final Image image = new Image();
037
038    /**
039     * Creates the base anchor with the image
040     */
041    public ImageAnchor() {
042        add(image);
043    }
044
045    /**
046     * {@inheritDoc}
047     */
048    @Override
049    public void setType(final ImageType type) {
050        StyleHelper.addEnumStyleName(this, type);
051    }
052
053    /**
054     * {@inheritDoc}
055     */
056    @Override
057    public ImageType getType() {
058        return ImageType.fromStyleName(getStyleName());
059    }
060
061    /**
062     * Set the image as responsive
063     *
064     * @param responsive boolean, whether or not the image has the responsive styles
065     */
066    public void setResponsive(final boolean responsive) {
067        StyleHelper.toggleStyleName(this, responsive, Styles.IMG_RESPONSIVE);
068    }
069
070    /**
071     * Set the image as a media object
072     *
073     * @param asMediaObject boolean, whether or not the image has the media object styles
074     */
075    public void setAsMediaObject(final boolean asMediaObject) {
076        StyleHelper.toggleStyleName(this, asMediaObject, Styles.MEDIA_OBJECT);
077    }
078
079    /**
080     * Set the URL of the image
081     *
082     * @param url String image url
083     */
084    public void setUrl(final String url) {
085        image.setUrl(url);
086    }
087
088    /**
089     * Gets the URL of the image
090     *
091     * @return String image url
092     */
093    public String getUrl() {
094        return image.getUrl();
095    }
096
097    /**
098     * Sets the alt text of the image
099     *
100     * @param alt String image alt text
101     */
102    public void setAlt(final String alt) {
103        image.setAltText(alt);
104    }
105
106    /**
107     * Gets the alt text of the image
108     *
109     * @return String image alt text
110     */
111    public String getAlt() {
112        return image.getAltText();
113    }
114}