KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > panelborder > PanelBorder


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.component.panelborder;
35
36 import com.icesoft.faces.component.CSS_DEFAULT;
37 import com.icesoft.faces.component.ext.taglib.Util;
38
39 import javax.faces.component.UIComponent;
40 import javax.faces.component.html.HtmlPanelGroup;
41 import javax.faces.context.FacesContext;
42 import javax.faces.el.ValueBinding;
43 import java.util.ArrayList JavaDoc;
44 import java.util.List JavaDoc;
45
46 /**
47  * PanelBorder is a JSF component class that represent an ICEfaces border layout
48  * panel. The "north", "west", "east", "center" and "south" named facets
49  * represent the components responsible for rendering the north, west, east,
50  * center and south areas of the PanelBorder.
51  * <p/>
52  * This component extends the JSF HtmlPanelGroup component.
53  * <p/>
54  * By default this component is rendered by the "com.icesoft.faces.BorderLayout"
55  * renderer type.
56  *
57  * @version beta 1.0
58  */

59 public class PanelBorder
60         extends HtmlPanelGroup {
61     public static final String JavaDoc COMPONENT_TYPE =
62         "com.icesoft.faces.BorderLayout";
63     public static final String JavaDoc COMPONENT_FAMILY = "javax.faces.Panel";
64     public static final String JavaDoc DEFAULT_RENDERER_TYPE =
65         "com.icesoft.faces.BorderLayout";
66     
67     public static final String JavaDoc NORTH_LAYOUT = "north";
68     public static final String JavaDoc WEST_LAYOUT = "west";
69     public static final String JavaDoc CENTER_LAYOUT = "center";
70     public static final String JavaDoc EAST_LAYOUT = "east";
71     public static final String JavaDoc SOUTH_LAYOUT = "south";
72     
73     private String JavaDoc _layout = null;
74     private String JavaDoc styleClass = null;
75     private String JavaDoc style = null;
76     private String JavaDoc align = null;
77     private String JavaDoc border = null;
78     private String JavaDoc bgcolor = null;
79     private String JavaDoc cellpadding = null;
80     private String JavaDoc cellspacing = null;
81     private String JavaDoc frame = null;
82     private String JavaDoc rules = null;
83     private String JavaDoc summary = null;
84     private String JavaDoc height = null;
85     private String JavaDoc width = null;
86     private String JavaDoc dir = null;
87     private String JavaDoc lang = null;
88     private String JavaDoc title = null;
89     private String JavaDoc renderedOnUserRole = null;
90     
91     List JavaDoc defaultLayout = new ArrayList JavaDoc();
92
93     /**
94      * <p>Return the value of the <code>north</code> property.</p>
95      */

96     public UIComponent getNorth() {
97         return (UIComponent) getFacet(PanelBorder.NORTH_LAYOUT);
98     }
99
100     /**
101      * <p>Return the value of the <code>west</code> property.</p>
102      */

103     public UIComponent getWest() {
104         return (UIComponent) getFacet(PanelBorder.WEST_LAYOUT);
105     }
106
107     /**
108      * <p>Return the value of the <code>east</code> property.</p>
109      */

110     public UIComponent getEast() {
111         return (UIComponent) getFacet(PanelBorder.EAST_LAYOUT);
112     }
113
114     /**
115      * <p>Return the value of the <code>center</code> property.</p>
116      */

117     public UIComponent getCenter() {
118         return (UIComponent) getFacet(PanelBorder.CENTER_LAYOUT);
119     }
120
121     /**
122      * <p>Return the value of the <code>south</code> property.</p>
123      */

124     public UIComponent getSouth() {
125         return (UIComponent) getFacet(PanelBorder.SOUTH_LAYOUT);
126     }
127
128     /**
129      * <p>Return the value of the <code>rendered</code> property.</p>
130      */

131     public boolean isRendered() {
132         if (!Util.isRenderedOnUserRole(this)) {
133             return false;
134         }
135         return super.isRendered();
136     }
137
138     public PanelBorder() {
139         setRendererType(DEFAULT_RENDERER_TYPE);
140         defaultLayout.add(PanelBorder.NORTH_LAYOUT);
141         defaultLayout.add(PanelBorder.EAST_LAYOUT);
142         defaultLayout.add(PanelBorder.SOUTH_LAYOUT);
143         defaultLayout.add(PanelBorder.WEST_LAYOUT);
144         defaultLayout.add(PanelBorder.CENTER_LAYOUT);
145     }
146
147     /**
148      * <p>Return the value of the <code>COMPONENT_FAMILY</code> of this
149      * component.</p>
150      */

151     public String JavaDoc getFamily() {
152         return COMPONENT_FAMILY;
153     }
154
155     /**
156      * <p>Set the value of the <code>layout</code> property.</p>
157      */

158     public void setLayout(String JavaDoc layout) {
159         _layout = layout;
160     }
161
162     /**
163      * @deprecated <p>Return the value of the <code>layout</code> property.
164      * </p>
165      */

166     public String JavaDoc getLayout() {
167         if (_layout != null) {
168             return _layout;
169         }
170         ValueBinding vb = getValueBinding("layout");
171         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : "none";
172     }
173
174     /**
175      * <p>Return the value of the <code>northClass</code> property.</p>
176      */

177     public String JavaDoc getNorthClass() {
178         return Util.getQualifiedStyleClass(this,
179                               CSS_DEFAULT.PANEL_BORDER_DEFAULT_NORTH_CLASS);
180     }
181
182     /**
183      * <p>Return the value of the <code>westClass</code> property.</p>
184      */

185     public String JavaDoc getWestClass() {
186         return Util.getQualifiedStyleClass(this,
187                                CSS_DEFAULT.PANEL_BORDER_DEFAULT_WEST_CLASS);
188     }
189
190     /**
191      * <p>Return the value of the <code>eastClass</code> property.</p>
192      */

193     public String JavaDoc getEastClass() {
194         return Util.getQualifiedStyleClass(this,
195                                CSS_DEFAULT.PANEL_BORDER_DEFAULT_EAST_CLASS);
196     }
197
198     /**
199      * <p>Return the value of the <code>centerClass</code> property.</p>
200      */

201     public String JavaDoc getCenterClass() {
202         return Util.getQualifiedStyleClass(this,
203                                CSS_DEFAULT.PANEL_BORDER_DEFAULT_CENTER_CLASS);
204     }
205
206
207     /**
208      * <p>Return the value of the <code>southClass</code> property.</p>
209      */

210     public String JavaDoc getSouthClass() {
211         return Util.getQualifiedStyleClass(this,
212                                CSS_DEFAULT.PANEL_BORDER_DEFAULT_SOUTH_CLASS);
213     }
214
215     /**
216      * <p>Set the value of the <code>styleClass</code> property.</p>
217      */

218     public void setStyleClass(String JavaDoc styleClass) {
219         this.styleClass = styleClass;
220     }
221
222     /**
223      * <p>Return the value of the <code>styleClass</code> property.</p>
224      */

225     public String JavaDoc getStyleClass() {
226         return Util.getQualifiedStyleClass(this,
227                         styleClass,
228                         CSS_DEFAULT.PANEL_BORDER_DEFAULT,
229                         "styleClass");
230         
231     }
232
233     /**
234      * <p>Return the value of the <code>style</code> property.</p>
235      */

236     public String JavaDoc getStyle() {
237         if (style != null) {
238             return style;
239         }
240         ValueBinding vb = getValueBinding("style");
241         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
242     }
243
244     /**
245      * <p>Set the value of the <code>style</code> property.</p>
246      */

247     public void setStyle(String JavaDoc style) {
248         this.style = style;
249     }
250
251
252     /**
253      * <p>Gets the state of the instance as a <code>Serializable</code>
254      * Object.</p>
255      */

256     public Object JavaDoc saveState(FacesContext context) {
257         Object JavaDoc values[] = new Object JavaDoc[17];
258         values[0] = super.saveState(context);
259         values[1] = _layout;
260         values[2] = styleClass;
261         values[3] = renderedOnUserRole;
262         values[4] = align;
263         values[5] = border;
264         values[6] = bgcolor;
265         values[7] = cellpadding;
266         values[8] = cellspacing;
267         values[9] = frame;
268         values[10] = rules;
269         values[11] = summary;
270         values[12] = height;
271         values[13] = width;
272         values[14] = dir;
273         values[15] = lang;
274         values[16] = title;
275         return ((Object JavaDoc) (values));
276     }
277
278     /**
279      * <p>Perform any processing required to restore the state from the entries
280      * in the state Object.</p>
281      */

282     public void restoreState(FacesContext context, Object JavaDoc state) {
283         Object JavaDoc values[] = (Object JavaDoc[]) state;
284         super.restoreState(context, values[0]);
285         _layout = (String JavaDoc) values[1];
286         styleClass = (String JavaDoc) values[2];
287         renderedOnUserRole = (String JavaDoc) values[3];
288         align = (String JavaDoc) values[4];
289         border = (String JavaDoc) values[5];
290         bgcolor = (String JavaDoc) values[6];
291         cellpadding = (String JavaDoc) values[7];
292         cellspacing = (String JavaDoc) values[8];
293         frame = (String JavaDoc) values[9];
294         rules = (String JavaDoc) values[10];
295         summary = (String JavaDoc) values[11];
296         height = (String JavaDoc) values[12];
297         width = (String JavaDoc) values[13];
298         dir = (String JavaDoc) values[14];
299         lang = (String JavaDoc) values[15];
300         title = (String JavaDoc) values[16];
301     }
302
303     /**
304      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
305      */

306     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
307         this.renderedOnUserRole = renderedOnUserRole;
308     }
309
310     /**
311      * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
312      */

313     public String JavaDoc getRenderedOnUserRole() {
314         if (renderedOnUserRole != null) {
315             return renderedOnUserRole;
316         }
317         ValueBinding vb = getValueBinding("renderedOnUserRole");
318         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
319     }
320
321
322     public void setAlign(String JavaDoc align) {
323         this.align = align;
324     }
325
326     public void setBorder(String JavaDoc border) {
327         this.border = border;
328     }
329
330     public void setBgcolor(String JavaDoc bgcolor) {
331         this.bgcolor = bgcolor;
332     }
333
334     public void setCellpadding(String JavaDoc cellpadding) {
335         this.cellpadding = cellpadding;
336     }
337
338     public void setCellspacing(String JavaDoc cellspacing) {
339         this.cellspacing = cellspacing;
340     }
341
342     public void setFrame(String JavaDoc frame) {
343         this.frame = frame;
344     }
345
346     public void setHeight(String JavaDoc height) {
347         this.height = height;
348     }
349
350     public void setRules(String JavaDoc rules) {
351         this.rules = rules;
352     }
353
354     public void setSummary(String JavaDoc summary) {
355         this.summary = summary;
356     }
357
358     public void setWidth(String JavaDoc width) {
359         this.width = width;
360     }
361
362     public void setDir(String JavaDoc dir) {
363         this.dir = dir;
364     }
365
366     public void setLang(String JavaDoc lang) {
367         this.lang = lang;
368     }
369
370     public void setTitle(String JavaDoc title) {
371         this.title = title;
372     }
373
374     /**
375      * @return the value of align property
376      */

377     public String JavaDoc getAlign() {
378         if (align != null) {
379             return align;
380         }
381         ValueBinding vb = getValueBinding("align");
382         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
383     }
384
385     /**
386      * @return the value of border property
387      */

388     public String JavaDoc getBorder() {
389         if (border != null) {
390             return border;
391         }
392         ValueBinding vb = getValueBinding("border");
393         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
394     }
395
396     /**
397      * @return the value of bgcolor property
398      */

399     public String JavaDoc getBgcolor() {
400         if (bgcolor != null) {
401             return bgcolor;
402         }
403         ValueBinding vb = getValueBinding("bgcolor");
404         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
405     }
406
407     /**
408      * @return the value of cellpadding property
409      */

410     public String JavaDoc getCellpadding() {
411         if (cellpadding != null) {
412             return cellpadding;
413         }
414         ValueBinding vb = getValueBinding("cellpadding");
415         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
416     }
417
418     /**
419      * @return the value of cellspacing property
420      */

421     public String JavaDoc getCellspacing() {
422         if (cellspacing != null) {
423             return cellspacing;
424         }
425         ValueBinding vb = getValueBinding("cellspacing");
426         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
427     }
428
429     /**
430      * @return the value of frame property
431      */

432     public String JavaDoc getFrame() {
433         if (frame != null) {
434             return frame;
435         }
436         ValueBinding vb = getValueBinding("frame");
437         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
438     }
439
440     /**
441      * @return the value of rules property
442      */

443     public String JavaDoc getRules() {
444         if (rules != null) {
445             return rules;
446         }
447         ValueBinding vb = getValueBinding("rules");
448         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
449     }
450
451     /**
452      * @return the value of summary property
453      */

454     public String JavaDoc getSummary() {
455         if (summary != null) {
456             return summary;
457         }
458         ValueBinding vb = getValueBinding("summary");
459         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
460     }
461
462     /**
463      * @return the value of height property
464      */

465     public String JavaDoc getHeight() {
466         if (height != null) {
467             return height;
468         }
469         ValueBinding vb = getValueBinding("height");
470         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
471     }
472
473     /**
474      * @return the value of width property
475      */

476     public String JavaDoc getWidth() {
477         if (width != null) {
478             return width;
479         }
480         ValueBinding vb = getValueBinding("width");
481         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
482     }
483
484     /**
485      * @return the value of dir property
486      */

487     public String JavaDoc getDir() {
488         if (dir != null) {
489             return dir;
490         }
491         ValueBinding vb = getValueBinding("dir");
492         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
493     }
494
495     /**
496      * @return the value of lang property
497      */

498     public String JavaDoc getLang() {
499         if (lang != null) {
500             return lang;
501         }
502         ValueBinding vb = getValueBinding("lang");
503         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
504     }
505
506     /**
507      * @return the value of title property
508      */

509     public String JavaDoc getTitle() {
510         if (title != null) {
511             return title;
512         }
513         ValueBinding vb = getValueBinding("title");
514         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
515     }
516
517
518     private boolean renderCenter = true;
519     private boolean renderCenterSet = false;
520
521     public boolean isRenderCenter() {
522         if (getLayout().endsWith(PanelBorder.CENTER_LAYOUT)) {
523             return false;
524         }
525         if (getLayout().equalsIgnoreCase(PanelBorderRenderer.DEFAULT_LAYOUT)) {
526             return true;
527         }
528         if (this.renderCenterSet) {
529             return (this.renderCenter);
530         }
531         ValueBinding vb = getValueBinding("renderCenter");
532         if (vb != null) {
533             return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
534         } else {
535             return (this.renderCenter);
536         }
537     }
538
539     public void setRenderCenter(boolean renderCenter) {
540         if (renderCenter != this.renderCenter) {
541             this.renderCenter = renderCenter;
542         }
543         this.renderCenterSet = true;
544     }
545
546
547     private boolean renderEast = true;
548     private boolean renderEastSet = false;
549
550     public boolean isRenderEast() {
551         if (getLayout().endsWith(PanelBorder.EAST_LAYOUT) ||
552             getLayout().equalsIgnoreCase(PanelBorderRenderer.CENTER_ONLY)) {
553             return false;
554         }
555         if (getLayout().equalsIgnoreCase(PanelBorderRenderer.DEFAULT_LAYOUT)) {
556             return true;
557         }
558         if (this.renderEastSet) {
559             return (this.renderEast);
560         }
561         ValueBinding vb = getValueBinding("renderEast");
562         if (vb != null) {
563             return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
564         } else {
565             return (this.renderEast);
566         }
567     }
568
569     public void setRenderEast(boolean renderEast) {
570         if (renderEast != this.renderEast) {
571             this.renderEast = renderEast;
572         }
573         this.renderEastSet = true;
574     }
575
576     private boolean renderNorth = true;
577     private boolean renderNorthSet = false;
578
579     public boolean isRenderNorth() {
580         if (getLayout().endsWith(PanelBorder.NORTH_LAYOUT) ||
581             getLayout().equalsIgnoreCase(PanelBorderRenderer.CENTER_ONLY)) {
582             return false;
583         }
584         if (getLayout().equalsIgnoreCase(PanelBorderRenderer.DEFAULT_LAYOUT)) {
585             return true;
586         }
587         if (this.renderNorthSet) {
588             return (this.renderNorth);
589         }
590         ValueBinding vb = getValueBinding("renderNorth");
591         if (vb != null) {
592             return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
593         } else {
594             return (this.renderNorth);
595         }
596     }
597
598     public void setRenderNorth(boolean renderNorth) {
599         if (renderNorth != this.renderNorth) {
600             this.renderNorth = renderNorth;
601         }
602         this.renderNorthSet = true;
603     }
604
605     private boolean renderSouth = true;
606     private boolean renderSouthSet = false;
607
608     public boolean isRenderSouth() {
609         if (getLayout().endsWith(PanelBorder.SOUTH_LAYOUT) ||
610             getLayout().equalsIgnoreCase(PanelBorderRenderer.CENTER_ONLY)) {
611             return false;
612         }
613         if (getLayout().equalsIgnoreCase(PanelBorderRenderer.DEFAULT_LAYOUT)) {
614             return true;
615         }
616         if (this.renderSouthSet) {
617             return (this.renderSouth);
618         }
619         ValueBinding vb = getValueBinding("renderSouth");
620         if (vb != null) {
621             return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
622         } else {
623             return (this.renderSouth);
624         }
625     }
626
627     public void setRenderSouth(boolean renderSouth) {
628         if (renderSouth != this.renderSouth) {
629             this.renderSouth = renderSouth;
630         }
631         this.renderSouthSet = true;
632     }
633
634     private boolean renderWest = true;
635     private boolean renderWestSet = false;
636
637     public boolean isRenderWest() {
638         if (getLayout().endsWith(PanelBorder.WEST_LAYOUT) ||
639             getLayout().equalsIgnoreCase(PanelBorderRenderer.CENTER_ONLY)) {
640             return false;
641         }
642         if (getLayout().equalsIgnoreCase(PanelBorderRenderer.DEFAULT_LAYOUT)) {
643             return true;
644         }
645         if (this.renderWestSet) {
646             return (this.renderWest);
647         }
648         ValueBinding vb = getValueBinding("renderWest");
649         if (vb != null) {
650             return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
651         } else {
652             return (this.renderWest);
653         }
654     }
655
656     public void setRenderWest(boolean renderWest) {
657         if (renderWest != this.renderWest) {
658             this.renderWest = renderWest;
659         }
660         this.renderWestSet = true;
661     }
662
663     public List JavaDoc getLayoutAsList() {
664
665         if (isRenderCenter()) {
666             if (!defaultLayout.contains(PanelBorder.CENTER_LAYOUT)) {
667                 defaultLayout.add(PanelBorder.CENTER_LAYOUT);
668             }
669         } else {
670             defaultLayout.remove(PanelBorder.CENTER_LAYOUT);
671         }
672         if (isRenderEast()) {
673             if (!defaultLayout.contains(PanelBorder.EAST_LAYOUT)) {
674                 defaultLayout.add(PanelBorder.EAST_LAYOUT);
675             }
676         } else {
677             defaultLayout.remove(PanelBorder.EAST_LAYOUT);
678         }
679         if (isRenderNorth()) {
680             if (!defaultLayout.contains(PanelBorder.NORTH_LAYOUT)) {
681                 defaultLayout.add(PanelBorder.NORTH_LAYOUT);
682             }
683         } else {
684             defaultLayout.remove(PanelBorder.NORTH_LAYOUT);
685         }
686         if (isRenderSouth()) {
687             if (!defaultLayout.contains(PanelBorder.SOUTH_LAYOUT)) {
688                 defaultLayout.add(PanelBorder.SOUTH_LAYOUT);
689             }
690         } else {
691             defaultLayout.remove(PanelBorder.SOUTH_LAYOUT);
692         }
693         if (isRenderWest()) {
694             if (!defaultLayout.contains(PanelBorder.WEST_LAYOUT)) {
695                 defaultLayout.add(PanelBorder.WEST_LAYOUT);
696             }
697         } else {
698             defaultLayout.remove(PanelBorder.WEST_LAYOUT);
699         }
700
701         return defaultLayout;
702     }
703
704
705 }
706
Popular Tags