KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > PanelTag2


1 package fr.improve.struts.taglib.layout;
2
3 import java.util.ResourceBundle JavaDoc;
4
5 import javax.servlet.jsp.JspException JavaDoc;
6
7 import fr.improve.struts.taglib.layout.util.LayoutUtils;
8 import fr.improve.struts.taglib.layout.util.TagUtils;
9
10 /**
11  * Render a panel element with handles
12  * This tag can be used as is or subclassed to insert a specific content.
13  * The body/content of the panel must be the content of a table element (ie begin with a <tr> element)
14  *
15  * Method calls are:<br>
16  * <li>doStartPanel()</li>
17  * <li>doPrintTitle()</li>
18  * <li>doBeforeBody()</li>
19  * <li> - output of the tag content - </li>
20  * <li>doAfterBody()</li>
21  * @author: Jean-Noël Ribette
22  * @deprecated
23  */

24 public class PanelTag2 extends LabelledTag {
25     protected int cols = 2;
26     protected String JavaDoc width;
27     protected String JavaDoc align = "center";
28     public final static String JavaDoc CENTER = "center";
29     public final static String JavaDoc LEFT = "left";
30     public final static String JavaDoc RIGHT = "rigth";
31     
32     private ResourceBundle JavaDoc resBundle;
33 /**
34  * End the body of the panel.
35  */

36 protected void doAfterBody(StringBuffer JavaDoc buffer) {
37     buffer.append("</table></td></tr>\n");
38 }
39 /**
40  * Prepare to print HTML content in the body of the panel.
41  */

42 protected void doBeforeBody(StringBuffer JavaDoc buffer) {
43     doBeforeBody(buffer, align);
44 }
45 /**
46  * Prepare to print content in the body of the panel.
47  * @param align center/left/right
48  */

49 protected void doBeforeBody(StringBuffer JavaDoc buffer, String JavaDoc align) {
50     buffer.append("<tr><td class=");
51     buffer.append(styleClass);
52     buffer.append("><table align=" + align +" border=0>\n");
53 }
54 /**
55  * Display the end of the panel in the buffer.
56  */

57 protected void doEndPanel(StringBuffer JavaDoc buffer) throws JspException JavaDoc {
58     buffer.append("</table></td>\n");
59
60     String JavaDoc bg_width = resBundle.getString("width");
61     String JavaDoc bg_height = resBundle.getString("height");
62     
63     
64     // end of the middle line
65
buffer.append("<td width=\"");
66     buffer.append(bg_width);
67     buffer.append("\" background=\"");
68     buffer.append(resBundle.getString("right"));
69     buffer.append("\" style=\"background-repeat:repeat-y;\">&nbsp</td>");
70     buffer.append("</tr>");
71
72     // last line
73
buffer.append("<tr>");
74
75     buffer.append("<td width=\"");
76     buffer.append(bg_width);
77     buffer.append("\" height=\"");
78     buffer.append(bg_height);
79     buffer.append("\"><img SRC=\"");
80     buffer.append(resBundle.getString("bottom_LEFT"));
81     buffer.append("\"></td>");
82     
83     buffer.append("<td height=\"");
84     buffer.append(bg_height);
85     buffer.append("\" background=\"");
86     buffer.append(resBundle.getString("bottom"));
87     buffer.append("\" style=\"background-repeat:repeat-x;\">&nbsp;</td>");
88
89     buffer.append("<td width=\"");
90     buffer.append(bg_width);
91     buffer.append("\" height=\"");
92     buffer.append(bg_height);
93     buffer.append("\"><img SRC=\"");
94     buffer.append(resBundle.getString("bottom_RIGHT"));
95     buffer.append("\"></td>");
96     
97     buffer.append("</tr>");
98
99     //end table
100
buffer.append("</table>");
101 }
102 public int doEndLayoutTag() throws JspException JavaDoc {
103     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
104     doAfterBody(buffer);
105     doEndPanel(buffer);
106     TagUtils.write(pageContext, buffer.toString());
107     return EVAL_PAGE;
108 }
109 /**
110  * Insert a blank line in the body of the panel
111  */

112 protected void doPrintBlankLine(StringBuffer JavaDoc buffer) {
113     buffer.append("<tr><td colspan=" + cols + ">&nbsp</td></tr>\n");
114 }
115 /**
116  * Display the title of the panel, using the key attribute.<br>
117  * A call to this method must be done after doStartPanel() and doBeforeBody()
118  * TO REMOVE
119  */

120 protected void doPrintTitle(StringBuffer JavaDoc buffer) throws JspException JavaDoc {
121     //if (key != null || name!=null) {
122
//buffer.append("<tr><th height=16 align=center");
123
//if (styleClass != null) {
124
//buffer.append(" class=");
125
//buffer.append(styleClass);
126
//}
127
//buffer.append(">");
128
//buffer.append(getLabel());
129
//buffer.append("</th></tr>\n");
130
//}
131
}
132 /**
133  * Start to display a panel with the default alignment.
134  */

135 protected void doStartPanel(StringBuffer JavaDoc buffer) throws JspException JavaDoc {
136     doStartPanel(buffer, align);
137 }
138 /**
139  * Start to display a panel with the specified alignment.
140  * @param align left/center/right
141  */

142 protected void doStartPanel(StringBuffer JavaDoc buffer, String JavaDoc align) throws JspException JavaDoc {
143
144     String JavaDoc l_skin = LayoutUtils.getSkin(pageContext.getSession()).getCssFileName();
145     if (l_skin.endsWith(".css")) l_skin = l_skin.substring(0,l_skin.length()-4);
146     resBundle = ResourceBundle.getBundle("com.applicationservers.forum.client.struts.Layout",new java.util.Locale JavaDoc(l_skin,(styleClass==null?"":styleClass)));
147     
148     // table
149
buffer.append("<table cellspacing=0 cellpadding=0 border=0 align=");
150     buffer.append(align);
151     if (width!=null) {
152         buffer.append(" width=");
153         buffer.append(width);
154     }
155     buffer.append(">");
156
157     String JavaDoc bg_width = resBundle.getString("width");
158     String JavaDoc bg_height = resBundle.getString("height");
159     
160     // top line
161
buffer.append("<tr>");
162
163     buffer.append("<td width=\"");
164     buffer.append(bg_width);
165     buffer.append("\" height=\"");
166     buffer.append(bg_height);
167     buffer.append("\"><img SRC=\"");
168     buffer.append(resBundle.getString("top_LEFT"));
169     buffer.append("\"></td>");
170     
171     buffer.append("<td");
172
173     String JavaDoc label = getLabel();
174     if (label!=null) {
175         buffer.append("><table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" class=\"");
176         buffer.append(styleClass);
177         buffer.append("\"><tr><th class=\"");
178         buffer.append(styleClass);
179         buffer.append("\">");
180         buffer.append(getLabel());
181         buffer.append("</th></tr></table>");
182     } else {
183         buffer.append(" height=\"");
184         buffer.append(bg_height);
185         buffer.append("\" background=\"");
186         buffer.append(resBundle.getString("haut"));
187         buffer.append("\" style=\"background-repeat:repeat-x;\">&nbsp");
188     }
189     buffer.append("</td>");
190
191     buffer.append("<td width=\"");
192     buffer.append(bg_width);
193     buffer.append("\" height=\"");
194     buffer.append(bg_height);
195     buffer.append("\"><img SRC=\"");
196     buffer.append(resBundle.getString("top_RIGHT"));
197     buffer.append("\"></td>");
198     
199     buffer.append("</tr>");
200     
201     // middle
202
buffer.append("<tr>");
203
204     buffer.append("<td width=\"");
205     buffer.append(bg_width);
206     buffer.append("\" background=\"");
207     buffer.append(resBundle.getString("left"));
208     buffer.append("\" style=\"background-repeat:repeat-y;\">&nbsp</td>");
209         
210     buffer.append("<td><table cellspacing=0 cellpadding=0 border=0 width=100%>\n");
211 }
212 public int doStartLayoutTag() throws JspException JavaDoc {
213     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
214     doStartPanel(buffer);
215     doBeforeBody(buffer);
216     TagUtils.write(pageContext,buffer.toString());
217     return EVAL_BODY_INCLUDE;
218 }
219 public void release() {
220     super.release();
221     cols = 2;
222     width= null;
223     align ="center";
224 }
225 /**
226  * Set the alignment of the panel (left, center or right)
227  */

228 public void setAlign(String JavaDoc align) {
229     this.align = align;
230 }
231 /**
232  * Set the numbers of columns<br>
233  * Use when displaying the title and blank lines.
234  */

235 public void setCols(int cols) {
236     this.cols = cols;
237 }
238 /**
239  * with of the panel tables
240  * default: 100%
241  */

242 public void setWidth(String JavaDoc width) {
243     if (!width.equals("0")) this.width = width;
244     else this.width=null;
245 }
246 }
247
Popular Tags