KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > samples > components > components > AreaComponent


1 /*
2  * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or
5  * without modification, are permitted provided that the following
6  * conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * - Redistribution in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials
14  * provided with the distribution.
15  *
16  * Neither the name of Sun Microsystems, Inc. or the names of
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * This software is provided "AS IS," without a warranty of any
21  * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
22  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
24  * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
25  * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
26  * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
27  * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
28  * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
29  * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
30  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
31  * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
32  * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
33  *
34  * You acknowledge that this software is not designed, licensed or
35  * intended for use in the design, construction, operation or
36  * maintenance of any nuclear facility.
37  */

38
39 package org.apache.cocoon.faces.samples.components.components;
40
41
42 import org.apache.cocoon.faces.samples.components.model.ImageArea;
43
44 import javax.faces.component.UIOutput;
45 import javax.faces.context.FacesContext;
46
47 /**
48  * <p>{@link AreaComponent} is a JavaServer Faces component that represents
49  * a particular hotspot in a client-side image map defined by our parent
50  * {@link MapComponent}. The <code>valueRef</code> property (if present)
51  * must point at a JavaBean of type <code>org.apache.cocoon.faces.samples.components.model.ImageArea</code>;
52  * if not present, an <code>ImageArea</code> instance will be synthesized
53  * from the values of the <code>alt</code>, <code>coords</code>, and
54  * <code>shape</code> properties, and assigned to the <code>value</code>
55  * property.</p>
56  */

57
58 public class AreaComponent extends UIOutput {
59
60
61     // ------------------------------------------------------ Instance Variables
62

63
64     private String JavaDoc alt = null;
65     private String JavaDoc coords = null;
66     private String JavaDoc shape = null;
67     private String JavaDoc targetImage = null;
68
69
70
71     // -------------------------------------------------------------- Properties
72

73
74     /**
75      * <p>Return the alternate text for our synthesized {@link ImageArea}.</p>
76      */

77     public String JavaDoc getAlt() {
78         return (this.alt);
79     }
80
81
82     /**
83      * <p>Set the alternate text for our synthesized {@link ImageArea}.</p>
84      *
85      * @param alt The new alternate text
86      */

87     public void setAlt(String JavaDoc alt) {
88         this.alt = alt;
89     }
90
91
92     /**
93      * <p>Return the hotspot coordinates for our synthesized {@link ImageArea}.
94      * </p>
95      */

96     public String JavaDoc getCoords() {
97         return (this.coords);
98     }
99
100
101     /**
102      * <p>Set the hotspot coordinates for our synthesized {@link ImageArea}.</p>
103      *
104      * @param coords The new coordinates
105      */

106     public void setCoords(String JavaDoc coords) {
107         this.coords = coords;
108     }
109
110
111     /**
112      * <p>Return the shape for our synthesized {@link ImageArea}.</p>
113      */

114     public String JavaDoc getShape() {
115         return (this.shape);
116     }
117
118
119     /**
120      * <p>Set the shape for our synthesized {@link ImageArea}.</p>
121      *
122      * @param shape The new shape (default, rect, circle, poly)
123      */

124     public void setShape(String JavaDoc shape) {
125         this.shape = shape;
126     }
127
128
129     /**
130      * <p>Set the image that is the target of this <code>AreaComponent</code>.</p>
131      *
132      * @return the target image of this area component.
133      */

134     public String JavaDoc getTargetImage() {
135         return targetImage;
136     }
137
138
139     /**
140      * <p>Set the image that is the target of this <code>AreaComponent</code>.</p>
141      *
142      * @param targetImage the ID of the target of this <code>AreaComponent</code>
143      */

144     public void setTargetImage(String JavaDoc targetImage) {
145         this.targetImage = targetImage;
146     }
147
148
149     /**
150      * <p>Return the component family for this component.</p>
151      */

152     public String JavaDoc getFamily() {
153
154         return ("Area");
155
156     }
157
158     // -------------------------------------------------------- UIOutput Methods
159

160
161     /**
162      * <p>Synthesize and return an {@link ImageArea} bean for this hotspot,
163      * if there is no <code>valueRef</code> property on this component.</p>
164      */

165     public Object JavaDoc getValue() {
166
167         if (super.getValue() == null) {
168             setValue(new ImageArea(getAlt(), getCoords(), getShape()));
169         }
170         return (super.getValue());
171
172     }
173
174
175     // ----------------------------------------------------- StateHolder Methods
176

177
178     /**
179      * <p>Return the state to be saved for this component.</p>
180      *
181      * @param context <code>FacesContext</code> for the current request
182      */

183
184     public Object JavaDoc saveState(FacesContext context) {
185         Object JavaDoc values[] = new Object JavaDoc[5];
186         values[0] = super.saveState(context);
187         values[1] = alt;
188         values[2] = coords;
189         values[3] = shape;
190         values[4] = targetImage;
191         return (values);
192     }
193
194
195     /**
196      * <p>Restore the state for this component.</p>
197      *
198      * @param context <code>FacesContext</code> for the current request
199      * @param state State to be restored
200      *
201      * @throws IOException if an input/output error occurs
202      */

203     public void restoreState(FacesContext context, Object JavaDoc state) {
204         Object JavaDoc values[] = (Object JavaDoc[]) state;
205         super.restoreState(context, values[0]);
206         alt = (String JavaDoc) values[1];
207         coords = (String JavaDoc) values[2];
208         shape = (String JavaDoc) values[3];
209         targetImage = (String JavaDoc) values[4];
210     }
211
212
213 }
214
Popular Tags