View Javadoc

1   /**
2    * Copyright 2005-2013 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 Image - 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 String containing 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 - String 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 a String representing 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 - a String containing 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 String 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         image.setWidth(width);
169     }
170 
171     /**
172      * Gets the width of the image
173      *
174      * @return String width
175      */
176     @BeanTagAttribute(name="width")
177     public String getWidth() {
178         return image.getWidth();
179     }
180 
181     /**
182      * Gets the caption header text
183      *
184      * @return String captionHeaderText
185      */
186     @BeanTagAttribute(name="captionHeaderText")
187     public String getCaptionHeaderText() {
188         return image.getCaptionHeaderText();
189     }
190 
191     /**
192      * Sets the caption header text
193      *
194      * @param captionHeaderText
195      */
196     public void setCaptionHeaderText(String captionHeaderText) {
197         image.setCaptionHeaderText(captionHeaderText);
198     }
199 
200     /**
201      * Gets the caption header
202      *
203      * @return Header captionHeader
204      */
205     @BeanTagAttribute(name="captionHeader",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
206     public Header getCaptionHeader() {
207         return image.getCaptionHeader();
208     }
209 
210     /**
211      * Sets the caption header
212      *
213      * @param captionHeader
214      */
215     public void setCaptionHeader(Header captionHeader) {
216         image.setCaptionHeader(captionHeader);
217     }
218 
219     /**
220      * Gets the cutline text
221      *
222      * @return String cutlineText
223      */
224     @BeanTagAttribute(name="cutlineText")
225     public String getCutlineText() {
226         return image.getCutlineText();
227     }
228 
229     /**
230      * Sets the cutline text
231      *
232      * @param cutlineText
233      */
234     public void setCutlineText(String cutlineText) {
235         image.setCutlineText(cutlineText);
236     }
237 
238     /**
239      * Gets the cutline
240      *
241      * @return Message cutline
242      */
243     @BeanTagAttribute(name="cutline",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
244     public Message getCutline() {
245         return image.getCutlineMessage();
246     }
247 
248     /**
249      * Sets the cutline
250      *
251      * @param cutline
252      */
253     public void setCutline(Message cutline) {
254         image.setCutlineMessage(cutline);
255     }
256 
257     /**
258      * Gets boolen of whether the caption header is above the image
259      *
260      * @return boolean captionHeaderAboveImage
261      */
262     @BeanTagAttribute(name="captionHeaderAboveImage")
263     public boolean isCaptionHeaderAboveImage() {
264         return image.isCaptionHeaderPlacementAboveImage();
265     }
266 
267     /**
268      * Sets boolen of whether the caption header is above the image
269      *
270      * @param captionHeaderAboveImage
271      */
272     public void setCaptionHeaderAboveImage(boolean captionHeaderAboveImage) {
273         image.setCaptionHeaderPlacementAboveImage(captionHeaderAboveImage);
274     }
275 }