TabsTag.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * Initial developer(s): Michel-Ange ANTON
00022  * --------------------------------------------------------------------------
00023  * $Id: TabsTag.java,v 1.5 2003/06/20 17:15:42 antonma Exp $
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 // ----------------------------------------------------- Constants
00038 
00039     private static final String s_ImageSeparator = "dot.gif";
00040 
00041 // ----------------------------------------------------- Instance Variables
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 // ------------------------------------------------------------- Properties
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 // --------------------------------------------------------- Public Methods
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 // -------------------------------------------------------- Package Methods
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 // ------------------------------------------------------ Private Methods
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         // Render the panel of this element
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         // Prepare image separator
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         // Render the beginning of this element
00281         try {
00282             out.println("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >");
00283         }
00284         catch (IOException ex) {
00285         }
00286 
00287         // Render each defined label tab
00288         int n = m_LabelTabs.size();
00289         out.println("<tr>");
00290         for (i = 0; i < n; i++) {
00291             // Init Label display
00292             sbLabel = new StringBuffer();
00293             // Detect selected tab
00294             bSelected = ((Boolean) m_SelectedTabs.get(i)).booleanValue();
00295             // Display begin tag
00296             out.print("<td align=\"center\"");
00297             // Display width tab and prepare label
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("&nbsp;");
00306                 sbLabel.append(m_LabelTabs.get(i));
00307                 sbLabel.append("&nbsp;");
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             // Height tab
00318             if (heightTab > 0) {
00319                 out.print(" height=\"");
00320                 out.print(heightTab);
00321                 out.print("\"");
00322             }
00323             out.print(">");
00324 
00325             // Display label
00326             if ((bSelected == true) || (m_HrefTabs.get(i).toString().length() == 0)) {
00327                 // Simple label
00328                 out.print(sbLabel.toString());
00329             }
00330             else {
00331                 // Link label
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                 // Separator Part
00346                 out.print("<td");
00347                 out.print(" class=\"tabSeparatorVertical\"");
00348                 out.print(">");
00349                 // Image
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         // Render underline
00363         out.println("<tr>");
00364         for (i = 0; i < n; i++) {
00365             bSelected = ((Boolean) m_SelectedTabs.get(i)).booleanValue();
00366             // Label Line Part
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             // Last tab ?
00387             if (i < (n - 1)) {
00388                 // Separator Line Part
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         // Display end tag
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                 // unselect all next if one is found
00415                 m_SelectedTabs.set(i, new Boolean(false));
00416             }
00417             else {
00418                 // detect the first selected
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 }

Generated on Tue Feb 15 15:05:34 2005 for JOnAS by  doxygen 1.3.9.1