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