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