001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 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, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.uif.field; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.krad.datadictionary.parse.BeanTag; 020import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 021import org.kuali.rice.krad.uif.component.Component; 022import org.kuali.rice.krad.uif.element.Header; 023import org.kuali.rice.krad.uif.element.Image; 024import org.kuali.rice.krad.uif.element.Message; 025import org.kuali.rice.krad.uif.util.LifecycleElement; 026 027/** 028 * Field that wraps an image content element. 029 * 030 * <p> 031 * Puts a <code><DIV></code> tag around an image element. This allows for labeling, styling, etc. 032 * </p> 033 * 034 * @see org.kuali.rice.krad.uif.element.Image 035 * @author Kuali Rice Team (rice.collab@kuali.org) 036 */ 037@BeanTag(name = "imageField", parent = "Uif-ImageField") 038public class ImageField extends FieldBase { 039 private static final long serialVersionUID = -7994212503770623408L; 040 041 private Image image; 042 043 public ImageField() { 044 super(); 045 } 046 047 /** 048 * PerformFinalize override - calls super, corrects the field's Label for attribute to point to this field's 049 * content 050 * 051 * @param model the model 052 * @param parent the parent component 053 */ 054 @Override 055 public void performFinalize(Object model, LifecycleElement parent) { 056 super.performFinalize(model, parent); 057 058 //determine what id to use for the for attribute of the label, if present 059 if (this.getFieldLabel() != null && this.getImage() != null && StringUtils.isNotBlank(this.getImage().getId())) { 060 this.getFieldLabel().setLabelForComponentId(this.getImage().getId()); 061 } 062 } 063 064 /** 065 * Retrieves the {@link Image} element wrapped by this field 066 * 067 * @return the Image element representing the HTML IMG element 068 */ 069 @BeanTagAttribute(type= BeanTagAttribute.AttributeType.DIRECTORBYTYPE) 070 public Image getImage() { 071 return image; 072 } 073 074 /** 075 * Sets the Image to be wrapped by this field 076 * 077 * @param image the Image element to be wrapped by this field 078 */ 079 public void setImage(Image image) { 080 this.image = image; 081 } 082 083 /** 084 * Retrieves the URL the image wrapped by this field 085 * 086 * @see org.kuali.rice.krad.uif.element.Image#getSource() 087 * @return the URL for the image 088 */ 089 @BeanTagAttribute 090 public String getSource() { 091 return image.getSource(); 092 } 093 094 /** 095 * Sets the source URL for the Image associated with this field 096 * 097 * @param source URL for the image 098 */ 099 public void setSource(String source) { 100 image.setSource(source); 101 } 102 103 /** 104 * Provides alternate information for the image element 105 * 106 * <p>The altText property specifies an alternate text for an image. It is displayed by the browser 107 * if the image cannot be displayed. This is especially important for accessibility, because screen 108 * readers can't understand images, but rather will read aloud the alternative text assigned to them. 109 * </p> 110 * 111 * @see org.kuali.rice.krad.uif.element.Image#getAltText() 112 * @return alternative information about this image 113 */ 114 @BeanTagAttribute 115 public String getAltText() { 116 return image.getAltText(); 117 } 118 119 /** 120 * Sets the alternate text attribute of the image assosiated with this field 121 * 122 * @param altText the alternative information about the image 123 */ 124 public void setAltText(String altText) { 125 image.setAltText(altText); 126 } 127 128 /** 129 * Gets the height of the image 130 * 131 * @return height 132 */ 133 @BeanTagAttribute 134 public String getHeight() { 135 return image.getHeight(); 136 } 137 138 /** 139 * Sets the height of the image 140 * 141 * @param height 142 */ 143 public void setHeight(String height) { 144 image.setHeight(height); 145 } 146 147 /** 148 * Gets the width of the image 149 * 150 * @return width 151 */ 152 @BeanTagAttribute 153 public String getWidth() { 154 return image.getWidth(); 155 } 156 157 /** 158 * Sets the width of the image 159 * 160 * @param width 161 */ 162 public void setWidth(String width) { 163 if (image != null) { 164 image.setWidth(width); 165 } 166 } 167 168 /** 169 * Gets the caption header text 170 * 171 * @return captionHeaderText 172 */ 173 @BeanTagAttribute 174 public String getCaptionHeaderText() { 175 return image.getCaptionHeaderText(); 176 } 177 178 /** 179 * Sets the caption header text 180 * 181 * @param captionHeaderText 182 */ 183 public void setCaptionHeaderText(String captionHeaderText) { 184 image.setCaptionHeaderText(captionHeaderText); 185 } 186 187 /** 188 * Gets the caption header 189 * 190 * @return captionHeader 191 */ 192 @BeanTagAttribute 193 public Header getCaptionHeader() { 194 return image.getCaptionHeader(); 195 } 196 197 /** 198 * Sets the caption header 199 * 200 * @param captionHeader 201 */ 202 public void setCaptionHeader(Header captionHeader) { 203 image.setCaptionHeader(captionHeader); 204 } 205 206 /** 207 * Gets the cutline text 208 * 209 * @return cutlineText 210 */ 211 @BeanTagAttribute 212 public String getCutlineText() { 213 return image.getCutlineText(); 214 } 215 216 /** 217 * Sets the cutline text 218 * 219 * @param cutlineText 220 */ 221 public void setCutlineText(String cutlineText) { 222 image.setCutlineText(cutlineText); 223 } 224 225 /** 226 * Gets the cutline 227 * 228 * @return cutline 229 */ 230 @BeanTagAttribute 231 public Message getCutline() { 232 return image.getCutlineMessage(); 233 } 234 235 /** 236 * Sets the cutline 237 * 238 * @param cutline 239 */ 240 public void setCutline(Message cutline) { 241 image.setCutlineMessage(cutline); 242 } 243 244 /** 245 * Gets boolen of whether the caption header is above the image 246 * 247 * @return captionHeaderAboveImage 248 */ 249 @BeanTagAttribute 250 public boolean isCaptionHeaderAboveImage() { 251 return image.isCaptionHeaderPlacementAboveImage(); 252 } 253 254 /** 255 * Sets boolen of whether the caption header is above the image 256 * 257 * @param captionHeaderAboveImage 258 */ 259 public void setCaptionHeaderAboveImage(boolean captionHeaderAboveImage) { 260 image.setCaptionHeaderPlacementAboveImage(captionHeaderAboveImage); 261 } 262}