KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > taglib > GridTag


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: GridTag.java,v 1.5 2004/03/26 16:16:12 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.taglib;
27
28 import javax.servlet.jsp.JspException JavaDoc;
29
30 /**
31  * @author Michel-Ange ANTON
32  */

33 public class GridTag extends GridTableBaseTag {
34
35 // ----------------------------------------------------- Instance Variables
36

37     private int m_iRow = 0;
38     private boolean m_bEvenRow = false;
39
40 // ----------------------------------------------------- Properties
41

42     private String JavaDoc oddStyleClass = null;
43     private String JavaDoc evenStyleClass = null;
44     private String JavaDoc globalRowStyleClass = null;
45     private int periodRow = 1;
46     private int border = 0;
47     private int cellSpacing = 0;
48     private int cellPadding = 0;
49
50     /**
51      * Return the Style Class of Odd rows
52      */

53     public String JavaDoc getOddStyleClass() {
54         return oddStyleClass;
55     }
56
57     /**
58      * Set the Style Class of Odd rows
59      *
60      * @param styleClass HTML Style Class value for Odd rows
61      */

62     public void setOddStyleClass(String JavaDoc styleClass) {
63         this.oddStyleClass = styleClass;
64     }
65
66     /**
67      * Style Class of Even rows in a table
68      */

69
70     /**
71      * Return the Style Class of Even rows
72      */

73     public String JavaDoc getEvenStyleClass() {
74         return evenStyleClass;
75     }
76
77     /**
78      * Set the styleClass of Even rows
79      *
80      * @param styleClass HTML Style Class value for Even rows
81      */

82     public void setEvenStyleClass(String JavaDoc styleClass) {
83         this.evenStyleClass = styleClass;
84     }
85
86     public int getPeriodRow() {
87         return periodRow;
88     }
89
90     public void setPeriodRow(int periodRow) {
91         this.periodRow = periodRow;
92     }
93     public void setPeriodRow(String JavaDoc p_PeriodRow) {
94         this.periodRow = Integer.parseInt(p_PeriodRow);
95     }
96
97     public int getBorder() {
98         return border;
99     }
100
101     public void setBorder(int border) {
102         this.border = border;
103     }
104
105     public int getCellSpacing() {
106         return cellSpacing;
107     }
108
109     public void setCellSpacing(int cellSpacing) {
110         this.cellSpacing = cellSpacing;
111     }
112
113     public int getCellPadding() {
114         return cellPadding;
115     }
116
117     public void setCellPadding(int cellPadding) {
118         this.cellPadding = cellPadding;
119     }
120
121     public String JavaDoc getGlobalRowStyleClass() {
122         return globalRowStyleClass;
123     }
124
125     public void setGlobalRowStyleClass(String JavaDoc globalRowStyleClass) {
126         this.globalRowStyleClass = globalRowStyleClass;
127     }
128
129 // ----------------------------------------------------- Public Methods
130

131     /**
132      * Start of Tag processing
133      *
134      * @exception JspException if a JSP exception occurs
135      */

136     public int doStartTag()
137         throws JspException JavaDoc {
138         m_bEvenRow = false;
139         m_iRow = 0;
140         return super.doStartTag();
141     }
142
143     /**
144      * Release resources after Tag processing has finished.
145      */

146     public void release() {
147         super.release();
148         m_iRow = 0;
149         m_bEvenRow = false;
150
151         oddStyleClass = null;
152         evenStyleClass = null;
153         globalRowStyleClass = null;
154         periodRow = 1;
155
156         border = 0;
157         cellSpacing = 0;
158         cellPadding = 0;
159         //border = -1;
160
//cellSpacing = -1;
161
//cellPadding = -1;
162
}
163
164 // ----------------------------------------------------- Protected Methods
165

166     /**
167      * Prepare the attributes of the HTML element
168      */

169     protected String JavaDoc prepareAttributes() throws JspException JavaDoc {
170         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
171
172         // Append "border" parameter
173
sb.append(prepareAttribute("border", border));
174         // Append "cellspacing" parameter
175
sb.append(prepareAttribute("cellspacing", cellSpacing));
176         // Append "cellpadding" parameter
177
sb.append(prepareAttribute("cellpadding", cellPadding));
178
179         // Append Event Handler details
180
sb.append(super.prepareAttributes());
181
182         return sb.toString();
183
184     }
185
186     protected String JavaDoc getRowStyle(boolean p_bChange) {
187         if (globalRowStyleClass == null) {
188             if (periodRow > 0) {
189                 if (m_iRow >= periodRow) {
190                     m_bEvenRow = !m_bEvenRow;
191                     m_iRow = 0;
192                 }
193                 m_iRow++;
194             }
195             if (p_bChange == true) {
196                 m_bEvenRow = !m_bEvenRow;
197                 m_iRow = 1;
198             }
199             if (m_bEvenRow == true) {
200                 return evenStyleClass;
201             }
202             return oddStyleClass;
203         }
204         return globalRowStyleClass;
205     }
206 }
Popular Tags