00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 package org.objectweb.jonas.webapp.taglib;
00028
00029 import java.io.IOException;
00030 import java.util.ArrayList;
00031
00032 import javax.servlet.jsp.JspException;
00033 import javax.servlet.jsp.JspWriter;
00034
00035 public class TabsTag extends WhereAreYouTag {
00036
00037
00038
00039 private static final String s_ImageSeparator = "dot.gif";
00040
00041
00042
00043 private ArrayList m_LabelTabs = new ArrayList();
00044 private ArrayList m_HrefTabs = new ArrayList();
00045 private ArrayList m_SelectedTabs = new ArrayList();
00046 private String m_Body = null;
00047
00048
00049
00050 private int widthTab = 0;
00051 private int heightTab = 0;
00052 private String width = "100%";
00053 private String height = "";
00054 private int widthSeparator = 3;
00055 private int heightSeparator = 1;
00056 private int marginPanel = 5;
00057 private String imagesDir = null;
00058
00062 public int getWidthTab() {
00063 return widthTab;
00064 }
00065
00066 public void setWidthTab(int widthTab) {
00067 this.widthTab = widthTab;
00068 }
00069
00073 public int getHeightTab() {
00074 return heightTab;
00075 }
00076
00077 public void setHeightTab(int heightTab) {
00078 this.heightTab = heightTab;
00079 }
00080
00084 public String getWidth() {
00085 return width;
00086 }
00087
00088 public void setWidth(String width) {
00089 this.width = width;
00090 }
00091
00095 public String getHeight() {
00096 return height;
00097 }
00098
00102 public void setHeight(String height) {
00103 this.height = height;
00104 }
00105
00109 public int getWidthSeparator() {
00110 return widthSeparator;
00111 }
00112
00113 public void setWidthSeparator(int widthSeparator) {
00114 this.widthSeparator = widthSeparator;
00115 }
00116
00120 public int getHeightSeparator() {
00121 return heightSeparator;
00122 }
00123
00124 public void setHeightSeparator(int heightSeparator) {
00125 this.heightSeparator = heightSeparator;
00126 }
00127
00131 public int getMarginPanel() {
00132 return marginPanel;
00133 }
00134
00135 public void setMarginPanel(int marginPanel) {
00136 this.marginPanel = marginPanel;
00137 }
00138
00142 public String getImagesDir() {
00143 return imagesDir;
00144 }
00145
00146 public void setImagesDir(String imagesDir) {
00147 this.imagesDir = imagesDir;
00148 }
00149
00150
00151
00152 public int doStartTag()
00153 throws JspException {
00154
00155 this.m_LabelTabs.clear();
00156 this.m_HrefTabs.clear();
00157 this.m_SelectedTabs.clear();
00158 this.m_Body = null;
00159
00160 return (EVAL_BODY_BUFFERED);
00161 }
00162
00168 public int doEndTag()
00169 throws JspException {
00170 JspWriter out = pageContext.getOut();
00171 try {
00172 verifySelected();
00173 render(out);
00174 }
00175 catch (IOException e) {
00176 throw new JspException(e);
00177 }
00178 return (EVAL_PAGE);
00179 }
00180
00184 public void release() {
00185 this.m_LabelTabs.clear();
00186 this.m_HrefTabs.clear();
00187 this.m_SelectedTabs.clear();
00188 this.m_Body = null;
00189 this.width = null;
00190 this.height = null;
00191 this.imagesDir = null;
00192 }
00193
00194
00195
00204 void addTab(String ps_Label, String ps_Href, boolean ps_Selected) {
00205 m_LabelTabs.add(ps_Label);
00206 m_HrefTabs.add(ps_Href);
00207 m_SelectedTabs.add(new Boolean(ps_Selected));
00208 }
00209
00210 void setBody(String ps_Body) {
00211 m_Body = ps_Body;
00212 }
00213
00214
00215
00216 private void render(JspWriter out)
00217 throws IOException, JspException {
00218 out.println("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">");
00219 out.println("<tr>");
00220 out.println("<td>");
00221 renderTabs(out);
00222 out.println("</td>");
00223 out.println("</tr>");
00224 out.println("<tr>");
00225 out.println("<td>");
00226 renderPanel(out);
00227 out.println("</td>");
00228 out.println("</tr>");
00229 out.println("</table>");
00230 }
00231
00232 private void renderPanel(JspWriter out)
00233 throws IOException, JspException {
00234
00235 out.print("<table border=\"0\" cellspacing=\"0\" cellpadding=\"");
00236 out.print(marginPanel);
00237 out.print("\"");
00238 out.print(" width=\"");
00239 out.print(width);
00240 out.print("\"");
00241 out.println(">");
00242 out.println("<tr valign=\"top\">");
00243 out.println("<td class=\"panel\">");
00244 out.print("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"");
00245 out.print(width);
00246 out.print("\"");
00247 out.println(">");
00248 out.println("<tr valign=\"top\">");
00249 out.print("<td height=\"");
00250 out.print(height);
00251 out.println("\" class=\"panel\">");
00252 if (m_Body != null) {
00253 out.println(m_Body);
00254 }
00255 out.println("</td>");
00256 out.println("</tr>");
00257 out.println("</table>");
00258 out.println("</td>");
00259 out.println("</tr>");
00260 out.println("</table>");
00261 }
00262
00263 private void renderTabs(JspWriter out)
00264 throws IOException, JspException {
00265 int i = 0;
00266 boolean bSelected = false;
00267 StringBuffer sbLabel = null;
00268 String sImageSep = null;
00269
00270
00271 if (imagesDir != null) {
00272 sImageSep = imagesDir + "/" + s_ImageSeparator;
00273 }
00274 else if (isUsingWhere()) {
00275 sImageSep = getImagesRoot() + "/" + s_ImageSeparator;
00276 }
00277 else {
00278 sImageSep = s_ImageSeparator;
00279 }
00280
00281 try {
00282 out.println("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >");
00283 }
00284 catch (IOException ex) {
00285 }
00286
00287
00288 int n = m_LabelTabs.size();
00289 out.println("<tr>");
00290 for (i = 0; i < n; i++) {
00291
00292 sbLabel = new StringBuffer();
00293
00294 bSelected = ((Boolean) m_SelectedTabs.get(i)).booleanValue();
00295
00296 out.print("<td align=\"center\"");
00297
00298 if (widthTab > 0) {
00299 out.print(" width=\"");
00300 out.print(widthTab);
00301 out.print("\"");
00302 sbLabel.append(m_LabelTabs.get(i));
00303 }
00304 else {
00305 sbLabel.append(" ");
00306 sbLabel.append(m_LabelTabs.get(i));
00307 sbLabel.append(" ");
00308 }
00309 out.print(" class=\"");
00310 if (bSelected == true) {
00311 out.print("tabSelect");
00312 }
00313 else {
00314 out.print("tab");
00315 }
00316 out.print("\"");
00317
00318 if (heightTab > 0) {
00319 out.print(" height=\"");
00320 out.print(heightTab);
00321 out.print("\"");
00322 }
00323 out.print(">");
00324
00325
00326 if ((bSelected == true) || (m_HrefTabs.get(i).toString().length() == 0)) {
00327
00328 out.print(sbLabel.toString());
00329 }
00330 else {
00331
00332 out.print("<a href=\"");
00333 out.print(m_HrefTabs.get(i).toString());
00334 out.print("\"");
00335 out.print(" class=\"");
00336 out.print("tab");
00337 out.print("\"");
00338 out.print(">");
00339 out.print(sbLabel.toString());
00340 out.print("</a>");
00341 }
00342 out.println("</td>");
00343
00344 if (i < (n - 1)) {
00345
00346 out.print("<td");
00347 out.print(" class=\"tabSeparatorVertical\"");
00348 out.print(">");
00349
00350 out.print("<img src=\"");
00351 out.print(sImageSep);
00352 out.print("\" width=\"");
00353 out.print(widthSeparator);
00354 out.print("\" height=\"");
00355 out.print(heightSeparator);
00356 out.print("\" border=\"0\">");
00357 out.println("</td>");
00358 }
00359 }
00360 out.println("</tr>");
00361
00362
00363 out.println("<tr>");
00364 for (i = 0; i < n; i++) {
00365 bSelected = ((Boolean) m_SelectedTabs.get(i)).booleanValue();
00366
00367 out.print("<td");
00368 out.print(" class=\"");
00369 if (bSelected == true) {
00370 out.print("tabSelect");
00371 }
00372 else {
00373 out.print("tabSeparatorHorizontal");
00374 }
00375 out.print("\"");
00376 out.print(">");
00377 out.print("<img src=\"");
00378 out.print(sImageSep);
00379 out.print("\" width=\"");
00380 out.print(widthSeparator);
00381 out.print("\" height=\"");
00382 out.print(heightSeparator);
00383 out.print("\" border=\"0\">");
00384 out.println("</td>");
00385
00386
00387 if (i < (n - 1)) {
00388
00389 out.print("<td");
00390 out.print(" class=\"tabSeparatorHorizontal\"");
00391 out.print(">");
00392 out.print("<img src=\"");
00393 out.print(sImageSep);
00394 out.print("\" width=\"");
00395 out.print(widthSeparator);
00396 out.print("\" height=\"");
00397 out.print(heightSeparator);
00398 out.print("\" border=\"0\">");
00399 out.println("</td>");
00400 }
00401 }
00402
00403 out.println("</tr>");
00404 out.println("</table>");
00405 }
00406
00410 private void verifySelected() {
00411 boolean bFound = false;
00412 for (int i = 0; i < m_SelectedTabs.size(); i++) {
00413 if (bFound == true) {
00414
00415 m_SelectedTabs.set(i, new Boolean(false));
00416 }
00417 else {
00418
00419 bFound = ((Boolean) m_SelectedTabs.get(i)).booleanValue();
00420 }
00421 }
00422 if ((bFound == false) && (m_SelectedTabs.size() > 0)) {
00423 m_SelectedTabs.set(0, new Boolean(true));
00424 }
00425 }
00426 }