KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsf > html > HtmlPanelGridRenderer


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2
11  * as published by the Free Software Foundation.
12  *
13  * Resin Open Source is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
16  * of NON-INFRINGEMENT. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Resin Open Source; if not, write to the
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jsf.html;
30
31 import java.io.*;
32 import java.util.*;
33
34 import javax.faces.*;
35 import javax.faces.component.*;
36 import javax.faces.component.html.*;
37 import javax.faces.context.*;
38 import javax.faces.render.*;
39
40 /**
41  * The HTML panel/grid renderer
42  */

43 class HtmlPanelGridRenderer extends Renderer
44 {
45   public static final Renderer RENDERER = new HtmlPanelGridRenderer();
46
47   /**
48    * True if the renderer is responsible for rendering the children.
49    */

50   @Override JavaDoc
51   public boolean getRendersChildren()
52   {
53     return true;
54   }
55   /**
56    * Renders the open tag for the text.
57    */

58   @Override JavaDoc
59   public void encodeBegin(FacesContext context, UIComponent component)
60     throws IOException
61   {
62     ResponseWriter out = context.getResponseWriter();
63
64     String JavaDoc bgcolor = null;
65     int border = -1;
66     String JavaDoc cellpadding = null;
67     String JavaDoc cellspacing = null;
68     String JavaDoc dir = null;
69     String JavaDoc frame = null;
70     String JavaDoc lang = null;
71     String JavaDoc onclick = null;
72     String JavaDoc ondblclick = null;
73     String JavaDoc onkeydown = null;
74     String JavaDoc onkeypress = null;
75     String JavaDoc onkeyup = null;
76     String JavaDoc onmousedown = null;
77     String JavaDoc onmousemove = null;
78     String JavaDoc onmouseout = null;
79     String JavaDoc onmouseover = null;
80     String JavaDoc onmouseup = null;
81     String JavaDoc rules = null;
82     String JavaDoc style = null;
83     String JavaDoc styleClass = null;
84     String JavaDoc summary = null;
85     String JavaDoc title = null;
86     String JavaDoc width = null;
87     
88     if (component instanceof HtmlPanelGrid) {
89       HtmlPanelGrid html = (HtmlPanelGrid) component;
90
91       bgcolor = html.getBgcolor();
92       border = html.getBorder();
93       cellpadding = html.getCellpadding();
94       cellspacing = html.getCellspacing();
95       dir = html.getDir();
96       frame = html.getFrame();
97       lang = html.getLang();
98       onclick = html.getOnclick();
99       ondblclick = html.getOndblclick();
100       onkeydown = html.getOnkeydown();
101       onkeypress = html.getOnkeypress();
102       onkeyup = html.getOnkeyup();
103       onmousedown = html.getOnmousedown();
104       onmousemove = html.getOnmousemove();
105       onmouseout = html.getOnmouseout();
106       onmouseover = html.getOnmouseover();
107       onmouseup = html.getOnmouseup();
108       rules = html.getRules();
109       style = html.getStyle();
110       styleClass = html.getStyleClass();
111       summary = html.getSummary();
112       title = html.getTitle();
113       width = html.getWidth();
114     }
115     else {
116       Map<String JavaDoc,Object JavaDoc> attrMap = component.getAttributes();
117     
118       bgcolor = (String JavaDoc) attrMap.get("bgcolor");
119       style = (String JavaDoc) attrMap.get("style");
120       styleClass = (String JavaDoc) attrMap.get("styleClass");
121     }
122
123     out.startElement("table", component);
124
125     if (bgcolor != null)
126       out.writeAttribute("bgcolor", bgcolor, "bgcolor");
127
128     if (border >= 0)
129       out.writeAttribute("border", border, "border");
130
131     if (cellpadding != null)
132       out.writeAttribute("cellpadding", cellpadding, "cellpadding");
133
134     if (cellspacing != null)
135       out.writeAttribute("cellspacing", cellspacing, "cellspacing");
136     
137     if (dir != null)
138       out.writeAttribute("dir", dir, "dir");
139     
140     if (frame != null)
141       out.writeAttribute("frame", frame, "frame");
142     
143     if (lang != null)
144       out.writeAttribute("lang", lang, "lang");
145     
146     if (onclick != null)
147       out.writeAttribute("onclick", onclick, "onclick");
148     
149     if (ondblclick != null)
150       out.writeAttribute("ondblclick", ondblclick, "ondblclick");
151     
152     if (onkeydown != null)
153       out.writeAttribute("onkeydown", onkeydown, "onkeydown");
154     
155     if (onkeypress != null)
156       out.writeAttribute("onkeypress", onkeypress, "onkeypress");
157     
158     if (onkeyup != null)
159       out.writeAttribute("onkeyup", onkeyup, "onkeyup");
160     
161     if (onmousedown != null)
162       out.writeAttribute("onmousedown", onmousedown, "onmousedown");
163     
164     if (onmousemove != null)
165       out.writeAttribute("onmousemove", onmousemove, "onmousemove");
166     
167     if (onmouseout != null)
168       out.writeAttribute("onmouseout", onmouseout, "onmouseout");
169     
170     if (onmouseover != null)
171       out.writeAttribute("onmouseover", onmouseover, "onmouseover");
172     
173     if (onmouseup != null)
174       out.writeAttribute("onmouseup", onmouseup, "onmouseup");
175     
176     if (rules != null)
177       out.writeAttribute("rules", rules, "rules");
178     
179     if (style != null)
180       out.writeAttribute("style", style, "style");
181     
182     if (styleClass != null)
183       out.writeAttribute("class", styleClass, "styleClass");
184     
185     if (summary != null)
186       out.writeAttribute("summary", summary, "summary");
187     
188     if (title != null)
189       out.writeAttribute("title", title, "title");
190     
191     if (width != null)
192       out.writeAttribute("width", width, "width");
193   }
194
195
196   /**
197    * Renders the content for the component.
198    */

199   @Override JavaDoc
200   public void encodeChildren(FacesContext context, UIComponent component)
201     throws IOException
202   {
203     ResponseWriter out = context.getResponseWriter();
204
205     int columns = 0;
206     
207     if (component instanceof HtmlPanelGrid) {
208       HtmlPanelGrid html = (HtmlPanelGrid) component;
209
210       columns = html.getColumns();
211     }
212     else {
213       Map<String JavaDoc,Object JavaDoc> attrMap = component.getAttributes();
214     
215       columns = (Integer JavaDoc) attrMap.get("columns");
216     }
217
218     int size = component.getChildCount();
219     if (size == 0)
220       return;
221     
222     if (columns < 1)
223       columns = 1;
224
225     List<UIComponent> children = component.getChildren();
226     int count = 0;
227
228     for (int i = 0; i < size; i++) {
229       UIComponent child = children.get(i);
230
231       if (! child.isRendered())
232     continue;
233
234       if (count % columns == 0) {
235     if (count > 0) {
236       out.endElement("tr");
237     }
238
239     out.startElement("tr", child);
240       }
241
242       count++;
243
244       out.startElement("td", child);
245       child.encodeBegin(context);
246       child.encodeChildren(context);
247       child.encodeEnd(context);
248       out.endElement("td");
249     }
250
251     if (count > 0)
252       out.endElement("tr");
253   }
254
255   /**
256    * Renders the closing tag for the component.
257    */

258   @Override JavaDoc
259   public void encodeEnd(FacesContext context, UIComponent component)
260     throws IOException
261   {
262     ResponseWriter out = context.getResponseWriter();
263
264     out.endElement("table");
265   }
266
267   public String JavaDoc toString()
268   {
269     return "HtmlPanelGridRenderer[]";
270   }
271 }
272
Popular Tags