/* ======================================================================
   Parts Copyright 2006 University of Leeds, Oxford University, University of the Highlands and Islands.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

====================================================================== */

package org.bodington.server.resources;

import org.bodington.database.PrimaryKey;
import org.apache.log4j.Logger;


public class ImageBlockResource extends Resource
{
    private static final int DISPLAY_TITLE = 1;
    private static final int DISPLAY_DESCRIPTION = 2;
    
    private int imageblock_flags;
    private String sourceURL;
    private String altTagText;
    private String linkHREF;
    private String imageHeight;
    private String imageWidth;
    
    public int getResourceType()
    {
        return RESOURCE_IMAGEBLOCK;
    }
    
    public PrimaryKey getImageBlockId()
    {
        return getResourceId();
    }
    
    public void setImageBlockId(PrimaryKey key)
    {
        setResourceId(key);
    }
    
    public boolean isDisplayTitle()
    {
        return (imageblock_flags & DISPLAY_TITLE) != 0;
    }
    
    public void setDisplayTitle(boolean b)
    {
        if (b == isDisplayTitle())
            return;
        
        setImageBlockFlags(imageblock_flags ^ DISPLAY_TITLE);
    }
    
    public boolean isDisplayDescription()
    {
        return (imageblock_flags & DISPLAY_DESCRIPTION) != 0;
    }
    
    public void setDisplayDescription(boolean b)
    {
        if (b == isDisplayDescription())
            return;
        
        setImageBlockFlags(imageblock_flags ^ DISPLAY_DESCRIPTION);
    }
    
    public int getImageBlockFlags()
    {
        return imageblock_flags;
    }
    
    public void setImageBlockFlags( int f )
    {
        if ( f==imageblock_flags ) return;
        imageblock_flags=f;
        setUnsaved();
    }
    
    public String getSourceURL()
    {
        return sourceURL;
    }

    public void setSourceURL(String sourceURL)
    {
        if (sourceURL != null)
        {
            this.sourceURL = sourceURL;
        }
    }
    
    public String getAltTagText()
    {
        if (altTagText != null)
        {
            return altTagText;
        }
        // ideally users should be forced to set an alt tag value...
        return "";
    }

    public void setAltTagText(String altTagText)
    {
        if (altTagText != null)
        {
            this.altTagText = altTagText;
        }
    }
    
    public boolean isLink()
    {    
        return getLinkHREF() != null;
    }
    
    public String getLinkHREF()
    {
        if (linkHREF != null && linkHREF.equals(""))
        {
            return null;
        }
        
        return linkHREF;
    }

    public void setLinkHREF(String linkHREF)
    {
        this.linkHREF = linkHREF;
    }
    
    public String getImageHeight()
    {
        if (imageHeight != null && imageHeight.equals(""))
        {
            return null;
        }
        return imageHeight;
    }

    public void setImageHeight(String imageHeight)
    {
        this.imageHeight = imageHeight;
    }
    
    public String getImageWidth()
    {
        if (imageWidth != null && imageWidth.equals(""))
        {
            return null;
        }
        return imageWidth;
    }

    public void setImageWidth(String imageWidth)
    {
        this.imageWidth = imageWidth;
    }
    
}
