View Javadoc
1   /**
2    * Copyright 2005-2016 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.field;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  import org.kuali.rice.krad.uif.component.Component;
22  import org.kuali.rice.krad.uif.element.Header;
23  import org.kuali.rice.krad.uif.element.Image;
24  import org.kuali.rice.krad.uif.element.Message;
25  import org.kuali.rice.krad.uif.view.View;
26  
27  import java.util.List;
28  
29  /**
30   * Field that wraps an image content element.
31   *
32   * <p>
33   * Puts a <code>&lt;DIV&gt;</code> tag around an image element. This allows for labeling, styling, etc.
34   * </p>
35   *
36   * @see org.kuali.rice.krad.uif.element.Image
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  @BeanTag(name = "imageField-bean", parent = "Uif-ImageField")
40  public class ImageField extends FieldBase {
41      private static final long serialVersionUID = -7994212503770623408L;
42  
43      private Image image;
44  
45      public ImageField() {
46          super();
47      }
48  
49      /**
50       * PerformFinalize override - calls super, corrects the field's Label for attribute to point to this field's
51       * content
52       *
53       * @param view the view
54       * @param model the model
55       * @param parent the parent component
56       */
57      @Override
58      public void performFinalize(View view, Object model, Component parent) {
59          super.performFinalize(view, model, parent);
60  
61          //determine what id to use for the for attribute of the label, if present
62          if (this.getFieldLabel() != null && this.getImage() != null && StringUtils.isNotBlank(this.getImage().getId())) {
63              this.getFieldLabel().setLabelForComponentId(this.getImage().getId());
64          }
65      }
66  
67      /**
68       * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
69       */
70      @Override
71      public List<Component> getComponentsForLifecycle() {
72          List<Component> components = super.getComponentsForLifecycle();
73  
74          components.add(image);
75  
76          return components;
77      }
78  
79      /**
80       * Retrieves the {@link Image} element wrapped by this field
81       *
82       * @return the Image element representing the HTML IMG element
83       */
84      @BeanTagAttribute(name="image",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
85      public Image getImage() {
86          return image;
87      }
88  
89      /**
90       * Sets the Image to be wrapped by this field
91       *
92       * @param image the Image element to be wrapped by this field
93       */
94      public void setImage(Image image) {
95          this.image = image;
96      }
97  
98      /**
99       * 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 }