1 /**
2 * Copyright 2005-2012 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.krad.uif.element;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.uif.component.Component;
20 import org.kuali.rice.krad.uif.util.ComponentFactory;
21 import org.kuali.rice.krad.uif.view.View;
22 import org.kuali.rice.krad.uif.widget.Help;
23
24 import java.util.List;
25
26 /**
27 * Content element that renders a HTML <code><IMG></code> tag
28 *
29 * @author Kuali Rice Team (rice.collab@kuali.org)
30 */
31 public class Image extends ContentElementBase {
32 private static final long serialVersionUID = -3911849875276940507L;
33
34 private String source;
35 private String altText;
36 private String height;
37 private String width;
38
39 private boolean captionHeaderPlacementAboveImage;
40
41 private String captionHeaderText;
42 private Header captionHeader;
43
44 private String cutlineText;
45 private Message cutlineMessage;
46
47 public Image() {
48 super();
49
50 altText = "";
51 }
52
53 /**
54 * The following initialization is performed:
55 *
56 * <ul>
57 * <li>Initializes the cutline message and caption header components if necessary</li>
58 * </ul>
59 *
60 * @see org.kuali.rice.krad.uif.component.ComponentBase#performInitialization(org.kuali.rice.krad.uif.view.View,
61 * java.lang.Object)
62 */
63 @Override
64 public void performInitialization(View view, Object model) {
65 super.performInitialization(view, model);
66
67 if ((StringUtils.isNotBlank(captionHeaderText) || (getPropertyExpression("captionHeaderText") != null)) && (
68 captionHeader == null)) {
69 captionHeader = ComponentFactory.getImageCaptionHeader();
70 view.assignComponentIds(captionHeader);
71 }
72
73 if ((StringUtils.isNotBlank(cutlineText) || (getPropertyExpression("cutlineText") != null)) && (cutlineMessage
74 == null)) {
75 cutlineMessage = ComponentFactory.getImageCutlineMessage();
76 view.assignComponentIds(cutlineMessage);
77 }
78 }
79
80 /**
81 * Performs the final lifecycle phase for this element.
82 *
83 * <p>
84 * Performs the following steps
85 * <ul>
86 * <li>Set the caption header text on the caption header</li>
87 * <li>Set the cutline text on the cutline message</li>
88 * </ul>
89 * </p>
90 *
91 * @see Component#performFinalize(org.kuali.rice.krad.uif.view.View, java.lang.Object, org.kuali.rice.krad.uif.component.Component)
92 */
93 @Override
94 public void performFinalize(View view, Object model, Component parent) {
95 super.performFinalize(view, model, parent);
96
97 if (StringUtils.isNotBlank(captionHeaderText)) {
98 captionHeader.setHeaderText(captionHeaderText);
99 }
100
101 if (StringUtils.isNotBlank(cutlineText)) {
102 cutlineMessage.setMessageText(cutlineText);
103 }
104 }
105
106 /**
107 * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
108 */
109 @Override
110 public List<Component> getComponentsForLifecycle() {
111 List<Component> components = super.getComponentsForLifecycle();
112
113 components.add(captionHeader);
114 components.add(cutlineMessage);
115
116 return components;
117 }
118
119 /**
120 * returns the URL of this image
121 *
122 * @return String containing the URL of this image.
123 */
124 public String getSource() {
125 return this.source;
126 }
127
128 /**
129 * Sets the URL of this image
130 *
131 * @param source - String representing the URL of this image
132 */
133 public void setSource(String source) {
134 this.source = source;
135 }
136
137 /**
138 * Provides alternate information for the image element
139 *
140 * <p>The altText property specifies an alternate text for an image. It is displayed by the browser
141 * if the image cannot be displayed. This is especially important for accessibility, because screen
142 * readers can't understand images, but rather will read aloud the alternative text assigned to them.
143 * <br>
144 * Some best practices:
145 * <ul>
146 * <li>spacer images, bullets, and icons should have the altText set to null or the empty string. This
147 * will prevent screen readers from announcing it.</li>
148 * <li>Make the altText message as short and succinct as possible</li>
149 * <li>Describe the content of the image and nothing more</li>
150 * </ul>
151 * </p>
152 *
153 * @return a String representing alternative information about this image
154 */
155 public String getAltText() {
156 return this.altText;
157 }
158
159 /**
160 * Sets the alternate text property for this image
161 *
162 * @param altText - a String containing the alternative information about the image
163 */
164 public void setAltText(String altText) {
165 this.altText = altText;
166 }
167
168 /**
169 * Returns the height style attribute of this image
170 *
171 * <p>
172 * The default unit of measure is pixels.<br>
173 * It is good practice to specify both the height and width attributes for an image.
174 * If these attributes are set, the space required for the image is reserved when the page is loaded.
175 * However, without these attributes, the browser does not know the size of the image. The effect will
176 * be that the page layout will change while the images load.
177 * </p>
178 *
179 * @return String containing of the height style attribute of this image
180 */
181 public String getHeight() {
182 return this.height;
183 }
184
185 /**
186 * Sets the height style attribute of the image.
187 *
188 * @param height - String containing the height of the image
189 */
190 public void setHeight(String height) {
191 this.height = height;
192 }
193
194 /**
195 * Returns the width style attribute of the image
196 *
197 * <p>
198 * The default unit of measure is pixels.<br>
199 * It is good practice to specify both the height and width attributes for an image.
200 * If these attributes are set, the space required for the image is reserved when the page is loaded.
201 * However, without these attributes, the browser does not know the size of the image. The effect will
202 * be that the page layout will change while the images load.
203 * <p>
204 *
205 * @return String containing the width of this image
206 */
207 public String getWidth() {
208 return width;
209 }
210
211 /**
212 * Sets the width style attribute of the image
213 *
214 * @param width - a String containing the width of this image
215 */
216 public void setWidth(String width) {
217 this.width = width;
218 }
219
220 /**
221 * Retrieves the caption text for this image
222 *
223 * <p>
224 * The caption text is a headline for the picture. It may be displayed either above or below the picture.
225 * </p>
226 *
227 * @return String containing the caption
228 */
229 public String getCaptionHeaderText() {
230 return captionHeaderText;
231 }
232
233 /**
234 * Sets the text displayed as of the caption for the picture
235 *
236 * @param captionHeaderText - String containing the caption text.
237 */
238 public void setCaptionHeaderText(String captionHeaderText) {
239 this.captionHeaderText = captionHeaderText;
240 }
241
242 /**
243 * Retrieves the {@link Header} component used to display the caption for this image
244 *
245 * @return Header component which wraps the caption text.
246 */
247 public Header getCaptionHeader() {
248 return captionHeader;
249 }
250
251 /**
252 * Sets the Header used to display the caption for this image
253 *
254 * @param captionHeader - Header component which wraps the caption text.
255 */
256 public void setCaptionHeader(Header captionHeader) {
257 this.captionHeader = captionHeader;
258 }
259
260 /**
261 * Retrieves the cutline text for this image
262 *
263 * <p>
264 * The cutline text give more detailed information about the picture. Generally it describes
265 * the who, what, where, when of this image.
266 * </p>
267 *
268 * @return String containing the cutline text.
269 */
270 public String getCutlineText() {
271 return cutlineText;
272 }
273
274 /**
275 * Sets the cutline text that describes this image
276 *
277 * @param cutlineText - String describing this image
278 */
279 public void setCutlineText(String cutlineText) {
280 this.cutlineText = cutlineText;
281 }
282
283 /**
284 * Gets the {@link Message} component used to display the cutline.
285 *
286 * <p>
287 * Wrapping the cutline text with a Message component allows styling of the cutline text.
288 * </p>
289 *
290 * @return Message component wrapping the cutline.
291 */
292 public Message getCutlineMessage() {
293 return cutlineMessage;
294 }
295
296 /**
297 * Sets the Message component used to display the cutline for this image
298 *
299 * @param cutlineMessage - Message
300 */
301 public void setCutlineMessage(Message cutlineMessage) {
302 this.cutlineMessage = cutlineMessage;
303 }
304
305 /**
306 * Specifies whether the image caption is to be displayed above or below the image
307 *
308 * @return true if the caption is to be displayed above the image. false if displayed below the image.
309 */
310 public boolean isCaptionHeaderPlacementAboveImage() {
311 return captionHeaderPlacementAboveImage;
312 }
313
314 /**
315 * Sets whether the image caption is to be displayed above or below the image
316 *
317 * @param captionHeaderPlacementAboveImage - true displays above image, false displays below image
318 */
319 public void setCaptionHeaderPlacementAboveImage(boolean captionHeaderPlacementAboveImage) {
320 this.captionHeaderPlacementAboveImage = captionHeaderPlacementAboveImage;
321 }
322
323 }