KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > newspaper > HtmlNewspaperTable


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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.apache.myfaces.custom.newspaper;
17
18 import javax.faces.component.UIComponent;
19 import javax.faces.context.FacesContext;
20 import javax.faces.component.html.HtmlDataTable;
21
22 /**
23  * Model for a table in multiple balanced columns.
24  *
25  * @author <a HREF="mailto:jesse@odel.on.ca">Jesse Wilson</a>
26  */

27 public class HtmlNewspaperTable
28         extends HtmlDataTable
29 {
30     /** the component's renderers and type */
31     public static final String JavaDoc RENDERER_TYPE = "org.apache.myfaces.HtmlNewspaperTable";
32     public static final String JavaDoc COMPONENT_TYPE = "org.apache.myfaces.HtmlNewspaperTable";
33
34     /** the property names */
35     public static final String JavaDoc NEWSPAPER_COLUMNS_PROPERTY = "newspaperColumns";
36     public static final String JavaDoc SPACER_FACET_NAME = "spacer";
37     
38     /** the value of the column count property */
39     private int newspaperColumns = 1;
40
41     public HtmlNewspaperTable() {
42         setRendererType(RENDERER_TYPE);
43     }
44
45     /**
46      * Set the number of columns the table will be divided over.
47      */

48     public int getNewspaperColumns() {
49         return newspaperColumns;
50     }
51     public void setNewspaperColumns(int newspaperColumns) {
52         this.newspaperColumns = newspaperColumns;
53     }
54     
55     /**
56      * Gets the spacer facet, between each pair of newspaper columns.
57      */

58     public UIComponent getSpacer() {
59         return (UIComponent)getFacets().get(SPACER_FACET_NAME);
60     }
61     public void setSpacer(UIComponent spacer) {
62         getFacets().put(SPACER_FACET_NAME, spacer);
63     }
64
65     public Object JavaDoc saveState(FacesContext context) {
66         Object JavaDoc values[] = new Object JavaDoc[2];
67         values[0] = super.saveState(context);
68         values[1] = new Integer JavaDoc(newspaperColumns);
69         return values;
70     }
71     
72     public void restoreState(FacesContext context, Object JavaDoc state) {
73         Object JavaDoc values[] = (Object JavaDoc[])state;
74         super.restoreState(context, values[0]);
75         newspaperColumns = ((Integer JavaDoc)values[1]).intValue();
76     }
77 }
Popular Tags